Showing posts with label BPEL4People. Show all posts
Showing posts with label BPEL4People. Show all posts

Saturday, May 25, 2013

HumanTask Event Listeners - WSO2 BPS


HumanTask engine comes with a humantask event generator. These task events are generated when a task goes trough a state transition. An event contains details about tasks and its state transition. So by writing a custom event listener to these events, a developer can easily enhance the HumanTask engine's functionalities.

What developer can do with a task event listener.
  • Can do custom java code/ web service invocations.
  • Can retrieve task information. 
  • Developer free to implement their own logic depending on their requirement.

Sample Event Listener.

EventListener class should implement HumanTaskEventListener class and onEvent method. See following sample code.


How to deploy a custom listener to WSO2 BPS

  1. Build a jar file of including your listener.
  2. Copy it into /repository/components/lib. Where is the root directory of BPS server.
  3. Uncomment TaskEventListeners in HumanTask configuration file (/repository/conf/humantask.xml) and give your Event Listener class name for ClassName.
  4. eg:
    Note: you can have multiple listener classes.
  5. Start BPS.
  6. Execute a task.

Escalating a human task with WSO2 BPS.

This Post describes, how to you can define a deadline within a human task. For this I am going to extend WSO2 BPS Claim Approval Task sample.

Prerequisite

  • If you haven't tried the sample yet, try it first. So you get better idea about how human task works.
  • Download WSO2 BPS 3.0.0 +
  • an Text Editor.

Note: You can find more information about humantask deadlines and timeouts under section 4.9 in humatask specification. 

What I am going to do in this sample ...

In this sample, I have set deadline time duration for 5 minuets after task creation. The escalation is defined such a way that, if the claimed amount is less than 10000 and task not started within 5 minutes, then notify task's potential owners that current claim approval task is overdue.

Steps to Modify WSO2 BPS Claim Approval Task sample


1)  Setup BPS as mentioned in sample page.

Deploy BPEL package. Creates Roles and Users. But do not deploy humantask package ClaimsApprovalTask.zip since we are going to modify it in next steps.

2) Modify ClaimsApprovalTask.ht

Unzip ClaimsApprovalTask.zip and Add following deadline definition (i.e <htd:deadlines>) inside ApproveClaim task definition (i.e. <htd:task "ApproveClaim"> ) in ClaimsApprovalTask.ht


3) Replace ClaimsApprovalTaskService.wsdl

I did slight changes to wsdl file for this sample. So replace ClaimsApprovalTaskService.wsdl with this file.

4) Deploy Sample

Create new zip file including all files.(modified and unmodified) and deploy it in BPS.
( you can find modified sample from here )

5) Send a Sample Request.

After deployment, send a sample request (like given in sample page). You can see task is created under clerk login. Do not start the human task.

6) Wait 5 mins.

After 5 mins, deadline will be executed. As a result this, a notification is generated and sent to the clerk. Clerk can view notification under Home -> Human Tasks -> Notifications.