Thursday, May 2, 2013

How to implement your own task UI on top of WSO2 BPS Human Task Engine


Human Tasks is a specification which helps us define tasks performed by human beings. From an SOA point of view, we can view a Human Task as a service implemented by a human being.

WSO2 Business process server (WSO2 BPS ) 3.0.0 version includes an evolving initial implementation of a Human Task Engine. It provides the basic human tasks functionality such as the ability to define human tasks and notifications, timer events and escalations, and the people assignments.

Also within its implementation, WSO2 BPS provides its own task UI. However, as this task UI is included within the Administrative console of the server, we do not encourage one to use it. Instead, what we expect from a serious human tasks user is to build his own task ui using what ever the user interface implementation methodology that is used within the organization. This could be done using technologies such as JSP, PHP ect. As long as you have a way of sending out soap messages, you can build your own task ui. In the following section, I will describe how to build your own task UI.

In order to  implement your own task UI, you need to understand how the Human task engine works.
A human task package will include at least one WSDL file which defines the ‘task service’ which is the service implemented by human being. In order to create a task, this task service should be invoked by an external party. This external party can either be an external web service invoker or a bpel process using Bpel4People extension activity.  When a task instance is created, it will have its own unique task id which will be returned to the task invoker. Additionally, this task id can be obtained by using the simpleQuery operation which returns a list of tasks. When your perform operations on the task, this unique task id is used to identify the specific task instance among the many task instances residing within the task engine.

Human Task specification describes the human tasks client api in detail in Chapter 7 Programming interfaces. [1] http://docs.oasis-open.org/bpel4people/ws-humantask-1.1-spec-cs-01.html

WSO2 BPS human tasks implementation also implements the same API. In order to successfully call this task client api, first we need to find out the admin service interface for it.

Step1.

Go to carbon.xml located in <BPS_HOME>/repository/conf/ directory.

Change the setting <HideAdminServiceWSDLs>true</HideAdminServiceWSDLs> to false.
<HideAdminServiceWSDLs>false</HideAdminServiceWSDLs>

Now start the bps server with option –DosgiConsole.

Once the server is fully started, enter to go to osgi console.

Now type listAdminServices in osgi console.

osgi> listAdminServices

This will list down all admin services.

Our interested endpoint is

HumanTaskClientAPIAdmin,https://<ip>:9443/services/HumanTaskClientAPIAdmin/

Usually, when you try ?wsdl on this endpoint, the wsdl will appear. However, there is an issue with the HumanTaskClientApi WSDL. Hence please download the wsdls from following location. http://people.wso2.com/~nandika/htwsdl/

Step2.

Create a soap ui project from the human_task_api.wsdl. Your soap ui project will show the task operations available as following.

image

Now, we can use this soapui client to query the human task client api to obtain the necessary information about tasks. By this method, we can explore the available operations to build our own custom ui.
However, this service is an authenticated service. Therefore, first you need to obtain the session cookie returned by the authentication admin login request and set it as an http header in the soap ui. Please refer to my previous blog on how to set the session cookie.


Step 3.

Do the authentication admin login request and copy the returned session cookie.

image

Using the session cookie, send the simple query request with Filter ALL_TASKS to obtain a list of all tasks.
Use the following soap message for that.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://docs.oasis-open.org/ns/bpel4people/ws-humantask/api/200803" xmlns:ns1="http://docs.oasis-open.org/ns/bpel4people/ws-humantask/types/200803">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:simpleQuery>
         <ns:simpleQueryInput>
            <ns1:simpleQueryCategory>ALL_TASKS</ns1:simpleQueryCategory>
         </ns:simpleQueryInput>
      </ns:simpleQuery>
   </soapenv:Body>
</soapenv:Envelope>

This should return a list of currently available tasks.

image

Now iterate though the task list and use load task method with the task id to load individual tasks.
Use following soap message.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://docs.oasis-open.org/ns/bpel4people/ws-humantask/api/200803">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:loadTask xmlns:ns="http://docs.oasis-open.org/ns/bpel4people/ws-humantask/api/200803">
         <ns:identifier>8405</ns:identifier>
      </ns:loadTask>
   </soapenv:Body>
</soapenv:Envelope>

This would return all information about the given task.

image

After you have obtained this data, you can use operations such as start, stop , claim, complete ect with the task id and corresponding xml message.

For example, start task request would look like the following.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://docs.oasis-open.org/ns/bpel4people/ws-humantask/api/200803">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:start xmlns:ns="http://docs.oasis-open.org/ns/bpel4people/ws-humantask/api/200803">
         <ns:identifier>8405</ns:identifier>
      </ns:start>
   </soapenv:Body>
</soapenv:Envelope>

Additionally, you can refer to the human task ui jsp pages of BPS to get more details.
https://svn.wso2.org/repos/wso2/carbon/platform/branches/4.0.0/components/business-processes/humantask/org.wso2.carbon.humantask.ui/4.0.5/src/main/resources/web/humantask