Introduction to Building Clients for Workflow Services
When creating a Java client application to call Human Workflow service, ensure that JRF is running on the same environment as the Java client application.
To build a simple worklist application:
The typical sequence of calls when building a simple worklist application is as follows.
- Get a handle to
IWorklistServiceClientfromWorkflowServiceClientFactory. - Get a handle to
ITaskQueryServicefromIWorklistServiceClient. - Authenticate a user by passing a username and password to the authenticate method on
ITaskQueryService. Get a handle toIWorkflowContext. - Query the list of tasks using
ITaskQueryService. - Get a handle to
ITaskServicefromIWorklistServiceClient. - Iterate over the list of tasks returned, performing actions on the tasks using
ITaskService.
The code sample below demonstrates how to build a client for workflow services. A
list of all tasks assigned to jstein is queried. A task whose outcome has not
been set is approved.
try
{
//Create JAVA WorflowServiceClient
IWorkflowServiceClient wfSvcClient = WorkflowServiceClientFactory.getWorkflowServiceClient(
WorkflowServiceClientFactory.REMOTE_CLIENT);
//Get the task query service
ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();
//Login as jstein
IWorkflowContext ctx = querySvc.authenticate("jstein","welcome1".toCharArry(),null);
//Set up list of columns to query
List queryColumns = new ArrayList();
queryColumns.add("TASKID");
queryColumns.add("TASKNUMBER");
queryColumns.add("TITLE");
queryColumns.add("OUTCOME");
//Query a list of tasks assigned to jstein
List tasks = querySvc.queryTasks(ctx,
queryColumns,
null, //Do not query additional info
ITaskQueryService.AssignmentFilter.MY,
null, //No keywords
null, //No custom predicate
null, //No special ordering
0, //Do not page the query result
0);
//Get the task service
ITaskService taskSvc = wfSvcClient.getTaskService();
//Loop over the tasks, outputting task information, and approving any
//tasks whose outcome has not been set...
for(int i = 0 ; i < tasks.size() ; i ++)
{
Task task = (Task)tasks.get(i);
int taskNumber = task.getSystemAttributes().getTaskNumber();
String title = task.getTitle();
String taskId = task.getSystemAttributes().getTaskId();
String outcome = task.getSystemAttributes().getOutcome();
if(outcome == null)
{
outcome = "APPROVE";
taskSvc.updateTaskOutcome(ctx,taskId,outcome);
}
System.out.println("Task #"+taskNumber+" ("+title+") is "+outcome);
}
}
catch (Exception e)
{
//Handle any exceptions raised here...
System.out.println("Caught workflow exception: "+e.getMessage());
}