Sun Java System Portal Server 7.2 Developer's Guide

Sample Scenario

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:

Checking out a Task

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:

Modifying Attributes of a Task

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.

Completing a Task

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.

Getting a Task

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);