
The Business Process Management (BPM) application programming interfaces (APIs) allow you to customize and enhance the way you use business processes and execute tasks.
This document describes how to use the BPM APIs to build your own task worklist while still using the Web Dynpro task execution UI to work on tasks.
For a detailed description of the BPM public APIs, see http://help.sap.com/javadocs.
You have added the necessary dependencies to development component tc/bpem/facade/ear (public part api) in software component BPEM-FACADE and to tc/je/sdo21/api in software component ENGFACADE .
The following steps explain how to query the tasks.
TaskAbstractOwnerCriteria ownerCriteria = new TaskAbstractOwnerCriteria(); TaskAbstractFetchCriteria statusCriteria = new TaskAbstractFilterCriteria(TaskAbstractFilterProperty.STATUS, Status.READY, Status.RESERVED, Status.IN_PROGRESS); TaskAbstractFetchCriteria priorityCriteria = new TaskAbstractFilterCriteria(TaskAbstractFilterProperty.PRIORITY, Priority.VERY_HIGH, Priority.HIGH);
Custom attributes for tasks can be defined in the process composer. For more information, see Defining Custom Attributes for Tasks.
When retrieving the task items, the caller can specify certain criteria based on existing custom attributes that need to be fulfilled in addition to the aforementioned criteria.
The value of the custom attribute 'orderID' of the type String should be "4711" or "4712".
The value of the custom attribute 'deliveryDate' of type Date should be before December 31, 2014.
TaskAbstractCustomAttributesFilterCriteria orderIdCriteria = new
TaskAbstractCustomAttributesValueFilterCriteria("orderId", "4711", "4712");TaskAbstractCustomAttributesFilterCriteria deliveryDateCriteria = new
TaskAbstractCustomAttributesRangeFilterCriteria("deliveryDate",
TaskAbstractCustomAttributeDateFilterType.DATE, null, new Date(2014, 11, 31));The value of the custom attribute 'orderID' of the type String should be "4711" or "4712".
The value of the custom attribute 'deliveryDate' of type Date should be before December 31, 2014.
TaskAbstractCustomAttributesOrFilterCriteria orderIdOrCustomerId = new TaskAbstractCustomAttributesOrFilterCriteria(orderIdCriteria, deliveryDateCriteria);
If you use the 'orderIDOrCustomerId' variable instead of the 'orderIdCriteria' and 'deliveryDateCriteria' variables in the resulting query (see step 3), the two criteria will be connected with 'or' instead of 'and'.
TaskInstanceManager taskInstanceManager = BPMFactory.getTaskInstanceManager(); List<TaskAbstract> tasks = taskInstanceManager.getTaskAbstracts(null, ownerCriteria, statusCriteria, priorityCriteria, orderIdCriteria, deliveryDateCriteria);
Custom attributes help users to take appropriate steps and decisions on tasks by providing relevant business context information. These custom attributes for tasks are defined in the process composer. For more information, see Defining Custom Attributes for Tasks .
To make these custom attributes visible in the user's task worklist, perform the following steps:
Retrieve the TaskDefinitionManager.
TaskDefinitionManager taskDefinitionManager = BPMFactory.getTaskDefinitionManager();
TaskDefinition is a basic representation of a task definition. One task definition of a task model is active; this means that tasks are instantiated from this definition.
Get the list of task custom attribute definitions for the TaskDefinition.
TaskDefinition . getCustomAttributeDefinitions()
Retrieve the TaskModelManager.
TaskModelManager taskModelManager = BPMFactory.getTaskModelManager();
The task model is an abstract representation of a task instance. Every task model has one or more task definitions.
Descriptor to specify query criteria for getting TaskAbstract(s):
TaskAbstractQueryCriteria
Marker descriptor to get custom attribute values of TaskAbstract while querying using TaskInstanceManager, TaskDefinitionManager, or TaskModelManager:
TaskAbstractCustomAttributesCriteria
To get the custom attribute values, use the following TaskAbstract method:
public java.util.Map<java.lang.String,java.lang.Object> getCustomAttributeValues()
To get the task definition ID, use the following TaskAbstract method:
public java.net.URI getDefinitionId()
To get the task model ID, use the following TaskAbstract method:
public java.net.URI getModelId()
To get custom attribute definitions, use the following methods of CustomAttributeDefinition:
getName
Returns the name of the custom attribute.
getType
Returns the type of the custom attribute.
getLabel
Returns the label of the custom attribute, which is translated based on the logged-in user's java.util.Locale.
The BPM public API provides a method that retrieves the task initiator. You can use this method to display the task initiator in the task worklist. Users can then already see in their task list who initiated their tasks without having to open the tasks.
public IUser getTaskInitiator();
IAuthentication auth = UMFactory.getAuthenticator();
IUser user = auth.forceLoggedInUser(request,response);
TaskInstanceManager taskInstanceManager = null;
try {
taskInstanceManager = BPMFactory.getTaskInstanceManager();
//Task statuses we are interested in
Set<Status> statuses = new HashSet<Status>();
statuses.add(Status.READY);
statuses.add(Status.CREATED);
statuses.add(Status.IN_PROGRESS);
statuses.add(Status.RESERVED);
Set<TaskAbstract> taskAbstracts = taskInstanceManager.getMyTaskAbstracts(statuses);
for(TaskAbstract ta : taskAbstracts) {
IUser taskInitiator = ta.getTaskInitiator();
}
}catch (BPMException e) {
// handle exception
}
TaskAbstract task = tasks.get(0) URI taskInstanceID = task.getID();
URL taskExecutionURL = taskInstanceManager.generateTaskExecutionUrl(taskInstanceId);
To complete a task, the current active user must have claimed the task. Claiming the task also prevents other potential owners of the task from completing it.
taskInstanceManager.claim(taskInstanceID);
taskInstanceManager.release(taskInstanceID);
IUser newOwner = ...; taskInstanceManager.delegate(taskInstanceID, newOwner);
In the task worklist, you can provide a link to a graphical representation of the process instance that triggered the task. To provide such a process instance visualization, you use the TaskInstanceManager.
ProcessInstanceManager processInstanceManager = BPMFactory.getProcessInstanceManager(); ProcessInstance processInstance = processInstanceManager.getProcessInstanceForTaskInstanceId(taskInstanceID); URI processInstanceID = processInstance.getID(); URL visualizationUI = processInstanceManager.generateProcessInstanceVisualizationURL(processInstanceID);
Priority priority = Priority.VERY_HIGH; taskInstanceManager.setPriority(taskInstanceID, priority);
The BPM Public API provides a complete method accepting a custom action as a parameter. Using the following method, you can complete a task with one of the defined custom actions for this task definition.
public void complete(URI taskInstanceId, DataObject taskOutputData) throws BPMException
Use the following method of the TaskDefinition interface to get all custom action definitions for a given task definition:
public List<CustomActionDefinition> getCustomActionDefinitions();
To fetch the custom action details, use the following methods of the CustomActionDefinition class:
getName()
Returns the name of the custom action.
getLabel()
Returns the label of the custom action, which is translated based on the logged-in user's java.util.Locale.
getDescription()
Returns the detailed description of the custom action, which is translated based on the logged-in user's java.util.Locale.