Wednesday, 18 June 2014

Human Task

Many end-to-end business processes require human interactions with the process. For
example, humans may be needed for approvals, exception management, or
performing activities required to advance the business process. The human workflow
component provides the following features:
■ Human interactions with processes, including assignment and routing of tasks to
the correct users or groups
■ Deadlines, escalations, notifications, and other features required for ensuring the
timely performance of a task (human activity)
■ Presentation of tasks to end users through a variety of mechanisms, including a
worklist application (Oracle BPM Worklist)
■ Organization, filtering, prioritization, and other features required for end users to
productively perform their tasks
■ Reports, reassignments, load balancing, and other features required by supervisors
and business owners to manage the performance of tasks



■ A BPEL process invokes a special activity of the human task type when it needs a
human to perform a task.
■ This creates a task in the human task service component. The process waits for the
task to complete. It is also possible for the process to watch for other callbacks
from the task and react to them.
■ There is metadata associated with the task that is used by the human task service
component to manage the lifecycle of the task. This includes specification of the
following:
                   – Who performs the task. If multiple people are required to perform the task,
                       what is the order?
                   – Who are the other stakeholders?
                   – When must the task be completed?
                  – How do users perform the task, what information is presented to them, what
                     are they expected to provide, and what actions can they take?
■ The human task service component uses an identity directory, such as LDAP, to
determine people’s roles and privileges.
■ The human task service component presents tasks to users through a variety of
channels, including the following:
               – Oracle BPM Worklist, a role-based application that supports the concept of
                   supervisors and process owners, and provides functionality for finding,
                   organizing, managing, and performing tasks.
               – Worklist functionality is also available as portlets that can be exposed in an
                   enterprise portal.
               – Notifications can be sent by email, phone, SMS, and other channels. Email
                  notifications can be actionable, enabling users to perform actions on the task
                  from within the email client without connecting to Oracle BPM Worklist or
                  Oracle WebLogic Server.
 Now I am going exploring HT with following use case.

Send PO details to a person from a BPEL program who can then approve or reject the PO
  • Start by creating a composite containing an asynchronous BPEL process



  • Modify the xsd as follows:

                  Add two elements poAmount and PODescription in the process element and rename                             the result to approvalStatus in the processResponse element.
  • Add a human task activity in the composite.xml
 

  • Double click on the human task to open the Task Definition editor and specify the following settings :                                                                                                                                                          Using the expression builder button on the right, enter 'Approve Order' for Title and click on OK. You will see <%'Approve Order'%> entered as the value.Enter Manual approval task for purchase orders in the Description field.
        Select Data tab and enter Order in the Parameters field.
    • Use the green plus sign to open the Add Task Parameter dialog. Select Element and then browse for the process element in BPEL.xsd. 
    • Select the Editable via worklist option. (This is optional and only so that you can see the functionality. Our application does not need to edit the payload.)
                        

Click on OK.
      Select Assignment tab, double-click on the box in the diagram.
In the Edit Participant Type dialog, specify the following:
Type: Single
Label: Order Approver

               Use the green plus sign next to Participant Names to add a user:

                            i. Set the Identification Type to User (already set)
                           ii. Set Data Type to By Name (already set)
                          iii. In the Value field, enter weblogic (no quotes)



  Click OK. JDeveloper closes the Add a Human Task dialog and displays the ApproveOrder task page.
Normally you would browse for users set in the server. However, in your current installation, you haven't yet created any users other than the default weblogic user.


Save and close the Task Definition editor and return to the composite
Calling the Human Task from BPEL
Now that the Human Task is defined, you can add an activity in your BPEL process that references the task and invokes the Human Task service at that point in the process. In JDeveloper, this looks like a single BPEL activity but is really a set of activities within a BPEL Scope activity to assign the input, invoke the service, and assign the output data.
1. Double-click on the BPEL component to open the BPEL designer.
2. Drag a Human Task into the process


Double click the HumanTask1 activity.  The Create a Human Task dialog opens. Select ManualPOApproval from the Task Definition drop-down. This action automatically creates a service interface to the Human Task service that you created. In BPEL, a partnerLink appears for the service reference.
Select the BPEL variable to pass the input parameter by clicking on the […] button on the right of process.

Click on OK.
You will have two new activities in your BPEL process: a Human Task and a Switch activity. The Human Task activity handles getting the approval (or rejection) from users using a work list application. The Switch activity can then be used to evaluate the results from the Human Task, for example, what to do if it's approved and or what to do if it's rejected.



Remove the three assign activities and replace them with new assign activities. 
Add Assign_Rejected to the REJECTED branch



In otherwise branch add a copy operation to assign ‘No Result’ to outputVariable
 
Creating the task form for task details
The Task is an ADF form that is created in a separate project. You create a JSF project to manage the task form and point it to the task file you create in your composite.
When you want a default form that includes the task payload and actions you just defined in the task definition, this is a simple one-click operation. For this lab, you want the default form. Complete the following:
1.In the BPEL process (not the composite), right-click on the human task ManualPOApproval and select Open Component Editor. 
 

2. Select Auto-generate task form. From the toolbar
 3. Enter a project name ApproveTaskDetails for your task form and select OK.
 
4. Stand back and watch the magic (it may look like nothing is happening at first but be patient   and don't touch anything). You can watch your disk activity light. 
5. The project is created and all of the artifacts needed for the form start to show up there. The  Task Flow diagram will open and then the task form itself. When you see the task form  TaskDetails1.jspx page open with the payload form elements, the form is created. Click on the Save all button and close the task form and task flow windows.


6.In the Application navigation pane, you see lots of files listed in the new task form project and the pane may be scrolled to the right. Scroll the pane to the top and left and close the folders for the ApproveTaskDetails project to clean up the navigation view and allow you to see your composite project files again. 
7.Now that you have created the form, you have the option to customize the form but for this lab, you can jump ahead to the next section to deploy and test. 

Deploying and testing the application

  1. Right click the Composite HumanTaskDemo.  Select Deploy.
  2. In deployment Action, choose that you want to deploy to an Application server
 
    

Click Next
  1. On Deploy Configuration, click Next
  2. Select the Taskflow project
  3. Select Application Server and the partition in the subsequent steps and deploy.


Open EM and enter some value


As usual, the Response tab won't show any results as this is a one-way invocation with no reply or callback.
Click on Launch Flow Trace to see the details of the message flow for this instance of your composite. Alternatively, click on the latest instance from the composite page. You'll notice the status for ManualPOApproval is still Running. It is waiting for the human task to be processed.
     

  Now it is time to "change hats" and log on to the Worklist application as a customer service    representative to approve the task. Using a browser, open http://hostname:portnumber/integration/worklistapp (use the correct port for your installation).

Double Click on the most recent task.  It will open in another window.


Click on Approve button.  This will  move the notification out of the queue and if we check in the EM, the BPEL process would have completed