(WID/WPS) Ad-hoc Task Creation


This post shows the code for creating the ad-hoc task template & task on the fly:


To create the task template :


try{
javax.naming.Context ctx = new javax.naming.InitialContext();
com.ibm.task.api.LocalHumanTaskManagerHome localHumanTaskManagerHome = (com.ibm.task.api.LocalHumanTaskManagerHome)ctx.lookup("local:ejb/com/ibm/task/api/HumanTaskManagerHome");


com.ibm.task.api.LocalHumanTaskManager taskManager = localHumanTaskManagerHome.create();


// Modelling of HumanTask at runtime
// ClientTaskfactory is used to create a resourceset that contains definition for a newly created Task Model


ClientTaskFactory factory = ClientTaskFactory.newInstance();
ResourceSet bundle = factory.createResourceSet();


// load the wsdl definition
Definition definition = factory.loadWSDLDefinition(bundle, "Customer.wsdl");
PortType portType = definition.getPortType(new QName(definition.getTargetNamespace(),"Customer"));
Operation operation = portType.getOperation("info", (String) null, (String) null);


TTask task = factory.createTTask(bundle, TTaskKinds.HTASK_LITERAL, "Ad-hoc-Sample", new UTCDate( "2012-02-28T00:00:00" ), "http://adhoctask", portType, operation);


//Task Name : Ad-hoc-Sample & namespace : http://adhoctask
TaskModel taskModel = ClientTaskFactory.createTaskModel( bundle );


ValidationProblem[] validationProblems = taskModel.validate();


if (validationProblems.length == 0) {
System.out.println("No Validation problems");
TKTID template = taskManager.createTaskTemplate(taskModel, "AccessHumanTask");
//APPLIC_NAME : AccessHumanTask (The Module name)


System.out.println(" Template created ");
}

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


Note :

  • Above code should run once as we can not create the same template more than once.
  • This template survives server bounce.
  • Customer.wsdl should be at runtime (Export as jar & keep in server-lib or put in shared lib)

To create the instance of the task :

TKIID tkiid = taskManager.createTask("Ad-hoc-Sample", "http://adhoctask");
ClientObjectWrapper cow = taskManager.createInputMessage(tkiid);
DataObject dataObject = (DataObject) cow.getObject();
dataObject.setString("input","<<Your Input>>");
taskManager.startTask(tkiid, cow, null);

No comments:

Post a Comment