This post gives the code for creating, claiming & completing the task.
LocalHumanTaskManager taskManager = null;
String name = null;
QueryResultSet instances = null;
try {
Context context = new javax.naming.InitialContext();
System.out.println("Lookup...started");
LocalHumanTaskManagerHome taskHome = (LocalHumanTaskManagerHome) context.lookup("java:comp/env/ejb/LocalHumanTaskManagerHome");
LocalHumanTaskManagerHome taskHome = (LocalHumanTaskManagerHome) context.lookup("local:ejb/com/ibm/task/api/HumanTaskManagerHome");
System.out.println("Lookup...success");
taskManager = taskHome.create();
System.out.println("Accessing local interface...success");
//String taskName = "MyHumanTask"; // Invocation Task
String taskName = "StandAloneHT"; // To-doTask
String taskNamespace = "http://HTModule";
TKIID tkiid = taskManager.createTask(taskName, taskNamespace);
Task task = taskManager.getTask(tkiid);
ClientObjectWrapper cow = taskManager.createInputMessage(tkiid);
DataObject dataObject = (DataObject) cow.getObject();
dataObject.setString("input1","<<Your Input>>");
taskManager.startTask(tkiid, cow, null);
//Signature of the startTask method :
//void startTask(TKIID tkiid, ClientObjectWrapper input, ReplyHandlerWrapper replyHandler)
//Asynchronously executes a previously created task using the task instance ID.
//Task can be of any type.
//Alternate way of calling a task :
//ClientObjectWrapper cow2= taskManager.callTask(tkiid, cow);
// Signature of the callTask method :
//ClientObjectWrapper callTask(TKIID tkiid, ClientObjectWrapper input)
//Synchronously executes a previously created invocation task instance using the task instance ID.
//Task should not be of To-Do type.
System.out.println("TKIID : "+tkiid);
//Claiming the task :
taskManager.claim(tkiid);
System.out.println("Claimed the task");
//Creating output for completing the task :
ClientObjectWrapper output = taskManager.createOutputMessage(tkiid);
DataObject outDataObject = (DataObject) output.getObject();
outDataObject.setString("output1","909090");
taskManager.complete(tkiid, output);
System.out.println("Completed the task");
//System.out.println("OUTPUT : "+((DataObject)cow2.getObject()).getString("output1")); If called Synchronously.
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getClass());
}
Lookup in Green is used in a JSP while in Red is used in Java component.
Red Scenario :
In the above example "MyHumanTask" is an Invocation Task (Human----Service) & "StandAloneHT" is a To-Do Task.
LocalHumanTaskManager taskManager = null;
String name = null;
QueryResultSet instances = null;
try {
Context context = new javax.naming.InitialContext();
System.out.println("Lookup...started");
LocalHumanTaskManagerHome taskHome = (LocalHumanTaskManagerHome) context.lookup("java:comp/env/ejb/LocalHumanTaskManagerHome");
LocalHumanTaskManagerHome taskHome = (LocalHumanTaskManagerHome) context.lookup("local:ejb/com/ibm/task/api/HumanTaskManagerHome");
System.out.println("Lookup...success");
taskManager = taskHome.create();
System.out.println("Accessing local interface...success");
//String taskName = "MyHumanTask"; // Invocation Task
String taskName = "StandAloneHT"; // To-doTask
String taskNamespace = "http://HTModule";
TKIID tkiid = taskManager.createTask(taskName, taskNamespace);
Task task = taskManager.getTask(tkiid);
ClientObjectWrapper cow = taskManager.createInputMessage(tkiid);
DataObject dataObject = (DataObject) cow.getObject();
dataObject.setString("input1","<<Your Input>>");
taskManager.startTask(tkiid, cow, null);
//Signature of the startTask method :
//void startTask(TKIID tkiid, ClientObjectWrapper input, ReplyHandlerWrapper replyHandler)
//Asynchronously executes a previously created task using the task instance ID.
//Task can be of any type.
//Alternate way of calling a task :
//ClientObjectWrapper cow2= taskManager.callTask(tkiid, cow);
// Signature of the callTask method :
//ClientObjectWrapper callTask(TKIID tkiid, ClientObjectWrapper input)
//Synchronously executes a previously created invocation task instance using the task instance ID.
//Task should not be of To-Do type.
System.out.println("TKIID : "+tkiid);
//Claiming the task :
taskManager.claim(tkiid);
System.out.println("Claimed the task");
//Creating output for completing the task :
ClientObjectWrapper output = taskManager.createOutputMessage(tkiid);
DataObject outDataObject = (DataObject) output.getObject();
outDataObject.setString("output1","909090");
taskManager.complete(tkiid, output);
System.out.println("Completed the task");
//System.out.println("OUTPUT : "+((DataObject)cow2.getObject()).getString("output1")); If called Synchronously.
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getClass());
}
Lookup in Green is used in a JSP while in Red is used in Java component.
Red Scenario :
In the above example "MyHumanTask" is an Invocation Task (Human----Service) & "StandAloneHT" is a To-Do Task.
Assembly Diagram |
Interface (Used as an interface for Todo Task & as a reference for Invocation Task) |
No comments:
Post a Comment