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 allpackage 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 allpackage 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