Friday, October 9, 2015

Performing operations with BPMN 2.0-Service Task

BPMN 2.0 is a standard / language to execute workflows.  Just like WS-BPEL ,BPMN can be used to create a process model, that contains a series of activities to be executed. In WSO2- BPS 3.5.0 release, bpmn suppport is introduced, which uses Activiti as the engine. To get a general idea on how/when bpmn can be used, you could go through

In this blog post, we will look at how to execute the services introduced by Activiti within a service task of our own. Service task is a type of task provided in bpmn, which is simply a java class. In a practical scenario, a service task is used to perform actions such as reassigning a user for a task, creating new tasks, delegating tasks etc. These operations can be done quite easily with the services provided by Activiti. [1] [2]

Let us take an example. We have a certain task (approve vacation request) that is assigned to admin user by default, and if he does not complete his task within a given time duration ( 2 days   ) we are going to assign it to another user.  In order to get this working with bpmn, you need to address below points.

1. Include a time out on "approve vacation request"task. : TimeBoundary Event
2. On time out call a service task to perform the delegation :  Service Task

Therefore , you would need to process your model with something similar like below.

Now that you have the basic model designed, let us look into the next level of details.  So in this scenario your "Approve Vacation Request" tasks main configs-> assignee would be set to 'admin'.Also you can set the duration of your timeBoundaryEvent. In your service task you need to address these points.

1. Get  the task with the task name as "Approve Vacation Request" and  is assigned to a user named 'admin'.
2.  Delegate that queried task to a new user. (Here you can pass the new user directly, or you could pass a form variable with execution.getVariable() )

Following is a sample  service task written to execute above points.  Here we are using methods provided by the TaskService Of Activit[1], so you would need to create an instance of the TaskService first.

  • Next by using this taskService, we are creating a query that search for  a task with the relevant task name ,and that is assigned/(or is a task candidate) to a user called admin.
  • Then we get the queried task list, and for each available task we would set the new assignee by executing method setAssignee().

As you can see it is a matter of fact getting to know the available services/ methods of activiti ,and you could create your own service task that could automate many processes easily. If you need to deploy this sample, other than deploying the .bar file in BPS management console, you need to create the jar of the service task and add it to <product_home>/repository/components/lib folder.


No comments:

Post a Comment