2. Gunakan oracle.bpel.services.bpm.common.IBPMContext dan process instance id untuk mendapatkan task-task yang terdapat pada process instance dari process instance id
IBPMContext ctx = processUtils_.getBPMContext();
// Navigate to the process
IProcessInstance processInstance = processUtils_.getBPMServiceClient().getInstanceQueryService().getProcessInstance(ctx,
processInstanceId);
// Find the task(s) for the process. This search is through the TaskQueryService with a predicate that
// constrains the search based on process instance id
List<task> tasks = processUtils_.findTasksForProcess(ctx, null, null, null, processInstanceId);
for (Task processTask : tasks) {
String taskState = processTask.getSystemAttributes().getState();
//iterate until task state is not COMPLETED
if ( !taskState.equals(ProcessUtils.STATE_COMPLETED) && nextOutcome != null) {
// if next outcome is set we also want to advance the next task.
//this is to setup the process query sample
String taskName = processTask.getSystemAttributes().getTaskDefinitionName();
if (taskName != null && taskName.equals(taskNameParameter)) {
int taskNumber = processTask.getSystemAttributes().getTaskNumber();
String taskId = processTask.getSystemAttributes().getTaskId();
Task task = processUtils_.findTaskById(ctx, taskId);
//Updating task
task.setPayloadAsElement(payload);
processUtils_.updateTask(ctx, task);
//Updating outcome for task
processUtils_.updateTaskOutcome(ctx, task.getSystemAttributes().getTaskId(), nextOutcome);
Thread.sleep(5000);
return "Success";
}else{
return "Not update task, taskName not equals " + taskNameParameter;
}
}
}
return "No task to process";
public static void main(String[] args) {
BPMServiceClientFactory cf =
ProcessUtils.getServiceClientFactory("user2","welcome1","t3://localhost:7878");
ProcessUtils processUtils = new ProcessUtils(cf);
TaskClient client = new TaskClient(processUtils);
try {
String processInstanceId = "10001";
String response = client.updateTask(processInstanceId, null, "ApproveLeaveTask","REJECT");
System.out.println(response);
} catch (WorkflowException e) {
e.printStackTrace();
} catch (JAXBException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
Code ini terinspirasi dari java.net.
Semoga bermanfaat. Cheers!!!
No comments:
Post a Comment