(WID/WPS) Querying Business Process & Human Task

LocalBusinessFlowManagerHome bfmHome = null;
InitialContext context = new InitialContext();
bfmHome = (LocalBusinessFlowManagerHome) context.lookup("local:ejb/com/ibm/bpe/api/BusinessFlowManagerHome");
LocalBusinessFlowManager flowManager = bfmHome.create();


String processTemplate = "MyProcess";
String selectClause = "DISTINCT ACTIVITY.AIID";
String whereClause = "PROCESS_TEMPLATE.NAME = '" + processTemplate+ "'";


QueryResultSet result = flowManager.query(selectClause, whereClause, (String) null,(Integer) null, (TimeZone) null);
System.out.println("\n > query(), result size: " + result.size());


if (result.size() == 0) 
{
System.exit(0);
}


while (result.next()) 
{
AIID aiid = (AIID) result.getOID(1);
System.out.println("AIID : " + aiid.toString());
ActivityInstanceData aid = flowManager.getActivityInstance(aiid);
System.out.println("App Name " + aid.getApplicationName());
System.out.println("Display Name " + aid.getDisplayName());
System.out.println("ProcessTemplate Name "+ aid.getProcessTemplateName());


// Below code is for human task only :

flowManager.claim( aiid ); // For Claiming the humantask
flowManager.createWorkItem( aiid, WorkItemData.REASON_READER, "admin");
flowManager.createWorkItem( aiid, WorkItemData.REASON_EDITOR, "admin");
System.out.println( "Created Work Item ");


// transfer this  EDITOR -workItem from admin to harish
flowManager.transferWorkItem( aiid, WorkItemData.REASON_EDITOR, "admin", "harish");
System.out.println( "Transferred Work Item");


flowManager.deleteWorkItem( aiid, WorkItemData.REASON_READER, "admin");
flowManager.deleteWorkItem( aiid, WorkItemData.REASON_EDITOR, "harish");
System.out.println( "Deleted Work Item");
}


// To work with input & output of Human Task

ClientObjectWrapper input =  flowManager.claim( aiid );
DataObject activityInput = null ;
if ( input.getObject()!= null && input.getObject() instanceof DataObject )
{
activityInput = (DataObject)input.getObject();
System.out.println("activity Input:in : "+activityInput.getString("in"));
 }


// To Complete
ActivityInstanceData activity = flowManager.getActivityInstance(aiid);
ClientObjectWrapper output = flowManager.createMessage(aiid, activity.getOutputMessageTypeName());
DataObject myMessage = null ;
if ( output.getObject()!= null && output.getObject() instanceof DataObject )
{
myMessage = (DataObject)output.getObject();
myMessage.setString("out","output is this");
}
flowManager.complete(aiid, output);

No comments:

Post a Comment