Page 1 of 1

Update document META data with <node> - ActionHandler

PostPosted:Sat Nov 07, 2020 7:44 am
by aruname
Dear Team

My environment
Code: Select all
Application: OpenKM Community version 6.3.9 (build e57b626)
OS Server: Redhat Linux 7 - Red Hat Enterprise Linux Server release 7.9 (Maipo)
Development: OpenKM-ComPorDev - Other Linux (64 bit) (on Oracle Virtual Box 6.1)
Configuration details:

Metadata config
defined : Group Name: okg:technology -> okp:technology.type
User profile:
1) General [tab] , Misc [section] -> Workflows field added with this "reviewDocument"
2) General [tab] , Wizard [section] -> Metadata groups field added with this "Technology"

Me too followed thread viewtopic.php?f=4&t=20139&start=15 and did some work..

but got stuck

Step 1: followed all mentioned points in above mentioned thread (having (ova in VM) installed as development environment)
Step 2: created a workflow with simple reviewer -> send back to "creator"--> resubmit workflow using "swimlane" and "initiator" (works great)
Step 3: thought of updating document metadata --> empty <node> without any action works fine

But simple system.out in <node> implementing ActionHandler class hangs

Pls help

Thanks

Re: Update document META data with <node> - ActionHandler

PostPosted:Sat Nov 07, 2020 8:31 am
by aruname
In catalina.out - server show the System.out message
Code: Select all
[size=150]Invoice has been canceled[/size]
2020-11-07 12:43:06,917 [http-nio-0.0.0.0-8080-exec-7] INFO  c.o.util.FormUtils$LocalResolver - resolveEntity(publicId=-//OpenKM//DTD Workflow Forms 2.4//EN, systemId=http://www.openkm.com/dtd/workflow-forms-2.4.dtd) => /home/openkm/tomcat-8.5.34/webapps/OpenKM/WEB-INF/classes/dtd/workflow-forms-2.4.dtd
But the node control doesn't move afterwards

Re: Update document META data with <node> - ActionHandler

PostPosted:Sat Nov 07, 2020 8:35 am
by aruname
The process definition
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>

<process-definition  xmlns=""  name="reviewDocument">

	<swimlane name="initiator"></swimlane>

	<start-state name="start">
		<task swimlane="initiator"></task>
		<transition to="updateSubmitStatus"></transition>
	</start-state>


	<node name="updateSubmitStatus">
		<action class="com.openkm.workflow.action.InvoiceCancelationAction"></action>
		<transition to="reviewer"></transition>
	</node>

	<task-node name="reviewer">
		<task>
			<assignment actor-id="pawan"></assignment>
		</task>
		<transition to="updateReviewStatus" name="accept"></transition>
		<transition to="creator" name="sendBack"></transition>
	</task-node>

	<node name="updateReviewStatus">
		<action class="com.openkm.workflow.action.InvoiceCancelationAction"></action>
		<transition to="end"></transition>
	</node>

	<task-node name="creator">
		<task swimlane="initiator"></task>
		<transition to="reviewer" name="reSubmit"></transition>
	</task-node>


	<end-state name="end"></end-state>


</process-definition>

Re: Update document META data with <node> - ActionHandler

PostPosted:Sat Nov 07, 2020 8:40 am
by aruname
The class I used in node - for testing the working of nodes with Handler invocation in my environment


note:- Below class is from example exercise wf4
Code: Select all
package com.openkm.workflow.action;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

public class InvoiceCancelationAction implements ActionHandler {
	private static final long serialVersionUID = 1L;

	@Override
	public void execute(ExecutionContext executionContext) throws Exception {
		System.out.println("Invoice has been canceled");
	}
}

Re: Update document META data with <node> - ActionHandler

PostPosted:Sat Nov 07, 2020 9:00 am
by aruname
Workflow hung image

https://bit.ly/3ldwqWo

Re: Update document META data with <node> - ActionHandler

PostPosted:Sat Nov 07, 2020 9:16 am
by aruname
Dear Team

Even i deployed example workflow "wf4" (part of worflow-course); even that getting stuck at <<node>>

I mean, the system.out is displayed in catalina.log ; but the workflow control doesn't move after that (hungs)

https://bit.ly/32oCx2x

In case if required; please find the wf4.par (the deployable)

https://bit.ly/3mW3gLE

thanks

Re: Update document META data with <node> - ActionHandler

PostPosted:Tue Nov 10, 2020 7:52 am
by aruname
Dear Team

Oops, finally I figured out my mistake, in my ActionHandler implementation class, I missed the below code at the end.
Code: Select all
// Go to next node
executionContext.getToken().signal();
Anyway for the completion; will work on other code part and put fwd the fully code; may be use full for some other.

Give me some time.

Thanks

Re: Update document META data with <node> - ActionHandler

PostPosted:Fri Nov 13, 2020 1:17 pm
by pavila
Please, attach the whole project zipped. It's the best way to get support.

Regards.

Re: Update document META data with <node> - ActionHandler

PostPosted:Sat Nov 21, 2020 6:35 am
by aruname
Hi Pavila

Yes, I could achieve what I want, find code below (may be useful for someone)

Pls find entire project code

shorturl.at/cdmKW


What requirement got addressed here

1. Simple workflow, with only reviewer (no approval step - u can add). Reviewer may accept or send back to creator the workflow
2. System to maintain meta data structure with Status, Date and user short comment (MessageUpdate.java)
Code: Select all
package com.openkm.workflow.metadata;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import com.openkm.api.OKMRepository;
import com.openkm.api.OKMPropertyGroup;
import com.openkm.bean.form.FormElement;
import com.openkm.bean.form.Input;
import com.openkm.bean.form.Select;
import com.openkm.bean.form.Option;
import java.util.Calendar;
import java.util.List;
import java.text.SimpleDateFormat;

public class MessageUpdate implements ActionHandler {

	private static final long serialVersionUID = 1L;
	public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";

	/**
	 This class update meta data of the document involved in work flow, this sets
	 1) Document Status
	 2) Date time 
	 3) User comment (the latest comment of the work flow user)
	 */
	@Override
	public void execute(ExecutionContext executionContext) throws Exception {
		String uuid = null;
		String path = null;

		try {
			uuid = (String) executionContext.getContextInstance().getVariable("uuid");
			path = OKMRepository.getInstance().getNodePath(null, uuid);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("User do have access to this document ... error");
		}

		String nodeName = executionContext.getNode().getName();
		Input usrInput;
		String DocStatus = "Initial";
		//
		// Hard coding the Document meta group name 
		//
		String grpName = "okg:sysinternal";
		//
		// Get the work flow user short comment and set the document status variable
		//
		if (nodeName.equals("submitted")) {
			DocStatus = "Submitted";
			usrInput = (Input) executionContext.getContextInstance().getVariable("comment");
		} else if (nodeName.equals("verified")) {
			DocStatus = "Verified";
			usrInput = (Input) executionContext.getContextInstance().getVariable("revcomment");
		} else if (nodeName.equals("resubmitted")) {
			DocStatus = "Pending";
			usrInput = (Input) executionContext.getContextInstance().getVariable("comment");
		} else if (nodeName.equals("sendback")) {
			DocStatus = "Pending";
			usrInput = (Input) executionContext.getContextInstance().getVariable("revcomment");
		} else if (nodeName.equals("approved")) {
			DocStatus = "Approved";
			usrInput = (Input) executionContext.getContextInstance().getVariable("revcomment");
		} else {
			DocStatus = "Pending";
			usrInput = (Input) executionContext.getContextInstance().getVariable("comment");
		}
		// Submitted
		// Verified
		// Approved
		// Pending
		
		//
		// Get current system date time
		//

		Calendar cal = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);

		String currentDateTime = (String) sdf.format(cal.getTime());
		String comment = "Submitted by dflt";

		if (usrInput != null) {
			comment = (String) usrInput.getValue();
		}

		System.out.println("uuid: " + uuid);
		System.out.println("Path: " + path);
		System.out.println("User Comment: " + comment);
		System.out.println("Current DateTime: " + currentDateTime);
		System.out.println("Flow at node: " + nodeName);

		//
		// Use Token only for communication from outside; for in line work flow
		// just represent it as ¨null¨
		//
		// String systemToken = DbSessionManager.getInstance().getSystemToken();
		//

		try {

			System.out.println("Before checking OKMProGrp existince for using addgroup");

			if (OKMPropertyGroup.getInstance().hasGroup(null, path, grpName)) {
				// Do nothing
			} else {
				System.out.println("Not having group!!! adding group: " + grpName);
				//
				// Adds an empty meta data group okg:sysinternal to a node
				//
				OKMPropertyGroup.getInstance().addGroup(null, path, grpName);
			}

			String lv_col1 = "okp:sysinternal.docstatus";
			String lv_col2 = "okp:sysinternal.actiondate";
			String lv_col3 = "okp:sysinternal.comment";
			/*
			 * For debug purpose
			 * 
			 * System.out.println("Before OKMProGrp settings");
			 * System.out.println("===========================");
			 * System.out.println("Path: "+ path);
			 * System.out.println("Group Name: "+ grpName);
			 * System.out.println(" Col-1>: "+ lv_col1);
			 * System.out.println(" Col-2>: "+ lv_col2);
			 * System.out.println(" Col-3>: "+ lv_col3);
			 * System.out.println("===========================");
			 */

			if (OKMPropertyGroup.getInstance().hasGroup(null, path, grpName)) {
				System.out.println("Group << " + grpName + " >> found..");
				// create an instance
				OKMPropertyGroup.getInstance();

				// print existing for debug purpose
				/*
				 * List<FormElement> fElements3 =
				 * OKMPropertyGroup.getInstance().getProperties(null,
				 * path,grpName); for (FormElement fElement3 : fElements3) {
				 * System.out.print("Label: "+fElement3.getLabel());
				 * System.out.println("  Value: "+fElement3.getName());
				 * System.out.println("===========================");
				 * System.out.println("  String: "+fElement3.toString());
				 * System.out.println("==========================="); if
				 * (fElement3.getName().equals(lv_col1)) { Select name =
				 * (Select) fElement3; List<Option> dElements =
				 * name.getOptions(); for (Option dElement : dElements) {
				 * System.out.println("Element Label: "+dElement.getLabel());
				 * System.out.println("Element Value: "+dElement.getValue());
				 * System.out.println("Element Select: "+dElement.isSelected());
				 * } } }
				 */

				// Set values

				List<FormElement> fElements = OKMPropertyGroup.getInstance().getProperties(null, path, grpName);
				for (FormElement fElement : fElements) {
					if (fElement.getName().equals(lv_col1)) {
						//
						// Since "okp:sysinternal.docstatus" is of type Select, you have use (Select) class to set the values
						//
						Select name = (Select) fElement;
						List<Option> dElements = name.getOptions();
						for (Option dElement : dElements) {
							if (dElement.getLabel().equals(DocStatus)) {
								dElement.setValue(DocStatus);
								dElement.setSelected(true);
							} else {
								dElement.setSelected(false);
							}
						}
						name.setValue(DocStatus);
						name.setOptions(dElements);
					} else if (fElement.getName().equals(lv_col2)) {
						Input name = (Input) fElement;
						name.setValue(currentDateTime);
					} else if (fElement.getName().equals(lv_col3)) {
						Input name = (Input) fElement;
						if (comment.length() < 100) {
							name.setValue(comment.substring(0, comment.length()));
						} else if (comment != null) {
							name.setValue(comment.substring(0, 100));
						}
					}
				}
				//
				// Set Properties element
				//
				OKMPropertyGroup.getInstance().setProperties(null, path, grpName, fElements);
				//
				// Confirm - for debug purpose
				//
				/*
				 * List<FormElement> fElements2 =
				 * OKMPropertyGroup.getInstance().getProperties(null,
				 * path,grpName); for (FormElement fElement2 : fElements2) {
				 * System.out.print("Label: "+fElement2.getLabel());
				 * System.out.println("  Value: "+fElement2.getName());
				 * System.out.println("===========================");
				 * System.out.println("  String: "+fElement2.toString());
				 * System.out.println("==========================="); }
				 */
			} else {
				System.out.println("Specified << " + grpName + " >> group not found");
			}

			System.out.println("After OKMProGrp setProperties");

		} catch (Exception e) {
			e.printStackTrace();
		}

		// Got to next Node
		executionContext.getToken().signal();
	}

}
3. On final step the workflow to store all comments under document notes (workflowStoreNotes.java)
Code: Select all
package com.openkm.workflow.notes;

import java.util.Formatter;
import java.util.Locale;
//import com.openkm.api.OKMRepository;
import com.openkm.api.OKMWorkflow;
import com.openkm.api.OKMNote;
import com.openkm.bean.Note;
import com.openkm.bean.workflow.Comment;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import java.util.Calendar;
import java.util.List;

public class workflowStoreNotes implements ActionHandler {

	private static final long serialVersionUID = 1L;

	@Override
	public void execute(ExecutionContext executionContext) throws Exception {
		String uuid = null;
		//String path = null;
		System.out.println("At Store Notes - Before - Get uuid");

		try {
			uuid = (String) executionContext.getContextInstance().getVariable("uuid");
			//path = OKMRepository.getInstance().getNodePath(null, uuid);
			System.out.println("Uuid: "+uuid);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("User do have access to this document ... error");
		}
		
		try {
			System.out.println("Before process instance id");
			Long processInstanceId = executionContext.getProcessInstance().getId();
			System.out.println("Before get comment from OKMWorkflow...");
			List<Comment> commEX = OKMWorkflow.getInstance().getProcessInstance(null, processInstanceId).getRootToken().getComments();
			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("<<Comment[%d]>> Date: %d-%02d-%02d %02d:%02d - User: %s - Comment: %s%n",i , year, month, day, hour, minute, act, mess).toString();
						i++;
					}
					formatter.close();
					
					if (commentString.equals(null) || commentString.equals(""))
					{
						// no comment
					}
					else
					{
						System.out.println(commentString);
						// Set complete work flow comments to notes
						try {
							System.out.println("Before Add comment OKMNote add...");
							Note note = OKMNote.getInstance().add(null, uuid, commentString);
							System.out.println("User comment string added..");
						}
						catch (Exception e) {
							e.printStackTrace();
							System.out.println("User do have access to this document ... error");
						}
					}
						
			
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("User do have access to this document ... error");
		}
		
		
	// Got to next Node
		executionContext.getToken().signal();
	}
}
Thanks
Arunachalam

Re: Update document META data with <node> - ActionHandler

PostPosted:Wed Nov 25, 2020 8:04 am
by pavila
I don't fully understand what you want. According to the inicial message, the problem was:
ActionHandler class hangs
And according to another messge this problem was solver. So, I don't know what do you want me to do.

Re: Update document META data with <node> - ActionHandler

PostPosted:Wed Nov 25, 2020 1:24 pm
by aruname
Sorry

Problem solved

Thanks
Arunachalam