In order to explain how to use SAW APIs, you can consider the following Business Process use case, where a user wants to do the following tasks:
Create a task.
A task is a unit of execution that requires human interaction. The task id created in this use case is 4ce71ee0:11420e51eca:-6388.
Check out the task.
The user name in this use case is CPina.
Modify and save (execute) the task attributes.
Complete the task.
Create a test class. For example, TestClient.java in this use case.
Ensure that the WorkflowConfig.Properties file is in classpath. The sample WorkflowConfig.properties file is shown below:
# the business process to use. sawworkflowimplclass = The SAW Workflow Implementation class to use. For example, com.sun.saw.impls.jcaps.JCAPSWorkflow # Properties that are needed by the JCAPS Implementation of SAW. com.sun.saw.impls.jcaps.JCAPSWorkflow.appserverhost = machine name or IP where Sun Java Composite Application Platform Suite business process is running. For example, abc.india.sun.com com.sun.saw.impls.jcaps.JCAPSWorkflow.iiopserverport = Port on which the IIOP lookup for the EJB happens. For example, 18002 com.sun.saw.impls.jcaps.JCAPSWorkflow.appserverusername = Administrator user name. For example, Administrator com.sun.saw.impls.jcaps.JCAPSWorkflow.appserverpassword = Administrator password. For example, STC com.sun.saw.impls.jcaps.JCAPSWorkflow.contextfactory = The context factory. For example, com.sun.jndi.cosnaming.CNCtxFactory com.sun.saw.impls.jcaps.JCAPSWorkflow.serviceJndi = The JNDI look up name. For example, WorkflowService |
Add the following code to your test class, to check out a task.
private com.sun.saw.vo.OutputVO checkoutTasks (String userId,java.util.List taskIdList,Workflow workflowImpl) throws com.sun.saw.WorkflowException { com.sun.saw.vo.CheckoutTaskVO checkoutTaskVO = new com.sun.saw.vo.CheckoutTaskVO(); checkoutTaskVO.setTaskIdList(taskIdList); checkoutTaskVO.setUserId(userId); com.sun.saw.vo.OutputVO outputVO = null; outputVO = workflowImpl.checkoutTasks(checkoutTaskVO); return outputVO; } //Call the above method from the main(). For example public static void main(String args) { TestClient client = new TestClient(); List taskIdList = new ArrayList(); taskIdList.add("4ce71ee0:11420e51eca:-6388"); Workflow workflowImpl = this.getWorkflowImpl(); try { client.checkoutTasks("CPina", taskIdList,workflowImpl); } catch (com.sun.saw.WorkflowException e) { e.printStackTrace(); } } private com.sun.saw.Workflow getWorkflowImpl() throws com.sun.saw.WorkflowException{ // This assumes that the property file is there in classpath. com.sun.saw.Workflow workflow = null; com.sun.saw.WorkflowFactory workflowFactory = WorkflowFactory.getInstance(); workflow = workflowFactory.getWorkflowInstance(); return workflow; } |
The above code does the following functions:
The main() calls the getWorkflowImpl() to get the reference of the SAW Workflow Implementation object, which is JCAPSWorkflow class.
The getWorkflowImpl() gets reference to the WorkflowFactory, and calls the getWorkflowInstance() on the factory.
The factory looks for the WorkflowConfig.properties in the classpath, reads the sawworkflowimplclass key and instantiates that.
The main() then calls the checkoutTasks() passing the userId, taskIdList and the appropriate workflowImpl object.
The checkoutTasks() constructs the CheckoutTaskVO object and sets taskIdList and UserId into the CheckoutTaskVO.
Invokes the checkoutTasks() on the SAW Workflow Implementation object, which is on JCAPSWorkflow class.
Invokes the checkoutTasks() on the Sun Java Composite Application Platform Workflow Service that is running as an Enterprise Java Beans (EJB) and does the actual checking out of the task.
The task is then marked as "checked out" by CPina.
To modify the attributes of a task, call the saveTasks() on the appropriate SAW Workflow Implementation object. Add the following code to your class:
private com.sun.saw.vo.OutputVO saveTasks(String userId,java.util.List taskIdList, String output,java.util.Map customAttributesMap,com.sun.saw.Workflow workflowImpl) throws com.sun.saw.WorkflowException { com.sun.saw.vo.OutputVO outputVO = null; com.sun.saw.vo.SaveTaskVO saveTaskVO = new com.sun.saw.vo.SaveTaskVO (); saveTaskVO.setTaskIdList(taskIdList); saveTaskVO.setUserId(userId); saveTaskVO.setOutput(output); saveTaskVO.setCustomAttributesMap(customAttributesMap); // key is fn, value is the dynamicParamVO. outputVO = workflowImpl.saveTasks(saveTaskVO); return outputVO; } //Call the above method from your main(). For example: client.saveTasks("CPina", taskIdList,"output",null,workflowImpl); |
The output gets saved as a task attribute.
Once you check out a task and modify the attributes, you may want to mark the status of a task as completed. This marking is called completing a task.
To complete a task, add the following method to a class:
private com.sun.saw.vo.OutputVO completeTasks(String userId,java.util.List taskIdList, com.sun.saw.Workflow workflowImpl) throws com.sun.saw.WorkflowException { com.sun.saw.vo.OutputVO outputVO = null; com.sun.saw.vo.CompleteTaskVO completeTaskVO = new com.sun.saw.vo.CompleteTaskVO(); completeTaskVO.setTaskIdList(taskIdList); completeTaskVO.setUserId(userId); outputVO = workflowImpl.completeTasks(completeTaskVO); return outputVO; } //Call the above method from your main(). For example,. client.completeTasks("CPina", taskIdList,workflowImpl); |
The task is marked as completed.
To get tasks, add the following method to a class:
public com.sun.saw.vo.OutputVO getTasks(String startDate,String endDate,java.util.List taskIdList,java.util.List userIdList, java.util.List taskStatusList,java.util.List groupIdList,String userId,int startRecord, int recordsPerPage,com.sun.saw.Workflow workflowImpl) throws com.sun.saw.WorkflowException { com.sun.saw.vo.FilterTaskVO filterTaskVO = new com.sun.saw.vo.FilterTaskVO(); filterTaskVO.setStartDate(startDate); filterTaskVO.setEndDate(endDate); filterTaskVO.setTaskIdList(taskIdList); filterTaskVO.setUserIdList(userIdList); filterTaskVO.setTaskStatusList(taskStatusList); filterTaskVO.setGroupIdList(groupIdList); filterTaskVO.setUserId(userId); filterTaskVO.setStartRecord(startRecord); filterTaskVO.setRecordsPerPage(recordsPerPage); OutputVO outputVO = workflowImpl.getTasks(filterTaskVO); //System.out.println(outputVO.getTaskVOList().size()); return outputVO; } //Call the above method from your main(). For example,. client.getTasks(null, null, null, null, null, null,userId,1,10,workflowImpl); |