Page 1 of 2

SOLVED Append Workflow Comments to File Metadata

PostPosted:Thu Feb 18, 2016 11:34 pm
by alexwgordon
Hi All,

I'm working on a workflow and it has some collaboration aspects to it. The users will use the Comment Section above the Workflow Form to make notes back and forth. I was wondering if it is possible, once the file is approved, can the list of comments be appended to the file somehow? If so that would be great. Thanks in advance!

Re: Append Workflow Comments to File Somehow

PostPosted:Sat Feb 20, 2016 11:05 am
by jllort
We are talking about PDF files ? ( the mime type of the documents is important, because is not the same, if you want for all mime I suggest forget the idea, for the most commons can be done ). Basically you need to openning the file and attach pages at the end or write lines ( depending the mime type format ).

Re: Append Workflow Comments to File Somehow

PostPosted:Sat Feb 20, 2016 4:56 pm
by alexwgordon
I am talking about all mime types. But I should clarify that I don't want to add the comments into[\b] the file, I just want to add it to the metadata. Possibly to the history or in the notes of the file. Does that make sense?

Re: Append Workflow Comments to File Somehow

PostPosted:Wed Feb 24, 2016 11:23 am
by jllort
Then the comment field should going into the forms.xml defintion and in transaction store as a note or into metadata field.

Re: Append Workflow Comments to File Somehow

PostPosted:Thu Mar 03, 2016 6:22 pm
by alexwgordon
what method can I use to extract the comments and inject them into a metadata field / note?

Re: Append Workflow Comments to File Somehow

PostPosted:Mon Mar 07, 2016 10:58 am
by jllort
You can get the field from the transaction view ( see http://docs.openkm.com/kcenter/view/wfg ... ercise.htm ) and about saving value into metadata field take a look at http://docs.openkm.com/apidoc/com/okm/6 ... Group.html ( I suggest the method setPropertiesSimple(String token, String nodeId, String grpName, Map<String,String> properties) )

Re: Append Workflow Comments to File Somehow

PostPosted:Fri Mar 18, 2016 8:04 pm
by alexwgordon
hi jllort, so after looking at the links you posted, I'm still not sure how to retrieve the Comments themselves. I'm not sure which method to use nor if I should be doing a getVariable. I tried a getVariable("comments") but came back as null. I think if you could help me to understand that much, I could figure the rest out. See the attached image for the comments I'm referring to at the bottom of the picture. Thanks!

Re: Append Workflow Comments to File Somehow

PostPosted:Tue Mar 22, 2016 11:35 am
by pavila
In short, you have two kinds of comments:

- Comments handled by the workflow engine, which can be accesses from the workflow info (See attached screenshot) which appears in the administration part under the "Comments" section. These comments can be obtained this way:
Code: Select all
processInstance.rootToken.comments
- Comments in forms.xml, which you have to handle and eventually store in database or as document notes. These comments appears as process instance variables.

For the sake of simplicity, we have already remove the first one from OpenKM Professional. And because you don't have any opportunity of intercepting them and use them for any purpose you want.

Re: Append Workflow Comments to File Somehow

PostPosted:Wed Mar 23, 2016 2:05 am
by alexwgordon
Thanks jlllort, that's exactly what I was looking for! However, when I try
Code: Select all
ProcessInstance.rootToken.comments
I'm getting an error that rootToken is not visible or if I use the getRootToken() method, it says it's not a static method. I think this may be my inexperience causing my mistake.

Okay, so if the first instance of comments is going to be removed, you're only going to have the comments as process variables in future revisions? What would be the easiest way to show ALL the comments to the user throughout the workflow in that case (especially as more comments come in)?

Thanks!

Re: Append Workflow Comments to File Somehow

PostPosted:Wed Mar 23, 2016 8:19 am
by pavila
Yes, because it's not an static method. You have to get the ProcessInstance object instance (For example OKMWorkflow.getInstance().getProcessInstance(token, procInsId)) and then getRootToken().

Re: Append Workflow Comments to File Somehow

PostPosted:Fri Mar 25, 2016 11:58 pm
by alexwgordon
Hi Pavilia,

Thanks for your input! I'm getting myself very confused. I only know Java informally so some of these things are outside of my knowledge at the moment. I'm trying to utilize the OKMWorkflow.getInstance.getProcessInstance(token, processInstanceId), but I'm running into how to obtain the token and the processInstanceId. Can you help point me in the right direction here? I'm getting overwhelmed with all these different methods and classes right now. Thanks!

Re: Append Workflow Comments to File Metadata

PostPosted:Thu Mar 31, 2016 1:46 pm
by alexwgordon
Hi jllort and pavilia!

So far I know i need to get
Code: Select all
OKMWorkflow.getInstance().getProcessInstance(token,processInstanceId)
getRootToken()
processInstance.rootToken.comments
But how do I get the token and processInstanceId? Would really appreciate your help! Thanks! :)

Re: Append Workflow Comments to File Metadata

PostPosted:Wed Apr 06, 2016 7:20 am
by pavila
The authentication token can be obtained this way:
Code: Select all
DbSessionManager.getInstance().getSystemToken()
The processInstanceId can be obtained from the ExecutionContext.

Re: Append Workflow Comments to File Metadata

PostPosted:Fri Apr 08, 2016 10:29 pm
by alexwgordon
Okay, thank you guys so much for your help. Got it working now. It's probably coded poorly, but here is my final results:
Code: Select all
package com.openkm.workflow.approval;

import java.util.Calendar;
import java.util.Formatter;
import java.util.List;
import java.util.Locale;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import com.openkm.api.*;
import com.openkm.bean.workflow.Comment;
import com.openkm.module.db.stuff.DbSessionManager;
import java.lang.String;


public class getNotes implements ActionHandler {
	
	private static final long serialVersionUID = 1L;
	
	public void execute(ExecutionContext context) throws Exception {
		
		String token = DbSessionManager.getInstance().getSystemToken();
		Long processInstanceId = context.getProcessInstance().getId();
		List< Comment > commEX = OKMWorkflow.getInstance().getProcessInstance(token, processInstanceId).getRootToken().getComments();
		String uuid = (String) context.getContextInstance().getVariable("uuid");
		String commentString = "";
		StringBuilder sb = new StringBuilder();
		Formatter formatter = new Formatter(sb, Locale.US);
		
		int i = 0;
		while ( i < commEX.size() )
		{
			String mess = commEX.get(i).getMessage();
			String act = commEX.get(i).getActorId();
			Calendar now = commEX.get(i).getTime();
			int year = now.get(Calendar.YEAR);
			int month = now.get(Calendar.MONTH)+1;
			int day = now.get(Calendar.DAY_OF_MONTH);
			int hour = now.get(Calendar.HOUR_OF_DAY);
			int minute = now.get(Calendar.MINUTE);
			commentString = formatter.format("%d.%02d.%02d %02d:%02d - %s - %s%n", year, month, day, hour, minute, act, mess).toString();
			i++;
		}
		formatter.close();
		OKMPropertyGroup.getInstance().setPropertySimple(token, uuid, "okg:commentHistory", "okp:reviewerCommentArea", commentString);
    }
}

Re: SOLVED Append Workflow Comments to File Metadata

PostPosted:Wed Dec 06, 2017 8:15 pm
by dferguson
I am trying to implement something very similar, however when I try to reused alexwgordon's code I get a bunch of broken items.

First it cannot resolve the following imports...
Screenshot from 2017-12-06 15-13-33.png
Screenshot from 2017-12-06 15-13-33.png (13.3 KiB) Viewed 4627 times
Edit: Found solution here...

viewtopic.php?t=7399

However, I am not certain I want to go down this path just to get an "approval" comment attached to a document. Surely there is an easier way to implement a document review and approval process that would be traceable...