Working with Human Tasks
Introduction
This Sample demonstrates how to add a People activity to an existing BPEL Process. It is based upon the Human Approval Completed Orchestration project template which is included with the ActiveVOS Designer. The Human Approval Completed project is the completed version of the Human Approval sample. Both project templates (as well as others) are accessible in the ActiveVOS Designer by creating a new orchestration project and selecting a sample template on the second page of the new orchestration project dialog.
The Human Approval demonstrated how to replace an existing Web Service invoke activity with a People activity. In this case both activities were based on the same Web Service interface. This sample differs because it will demonstrate how to create a new interface (in the form of a WSDL file) for the task rather than reusing an existing interface.
ActiveVOS Designer will help you automatically generate a WSDL from your schemas or sample input/output messages.
Process Overview
This sample will demonstrate how to add a human activity to an existing process. In this example, we’ve decided to add a step requiring manager approval of any loans denied by a Loan Representative. For this, we will test the outcome of the ReviewLoan human activity. If the Loan Representative denies the loan, a task is created for a Manager to review the loan rejection and override it if deemed appropriate.
Project Setup and Review
We will begin by creating a new orchestration project based on
the
Human Approval Completed orchestration project template.
Create a new Orchestration Project
- Select File>New>Orchestration Project.
- Enter a name for your project and click Next.
- Under ActiveVOS Samples select the Human
Approval
Completed sample template.
- Press Finish.
Review the Human Approval Completed process
Once the project opens in your workspace we highly recommend
that
you review the project contents and deploy and test the project using
the instructions in the cheatsheet that opened when the project was
created. These instructions will walk you through starting
the
Embedded Server, deploying the loan and partner processes, running the
process on the server and how to claim and complete the human task.
After you have reviewed the sample we can start preparing the
project for the additional People activity and human
task. To start off we'll need to define a new interface for the human
task. We'll let the ActiveVOS Designer generate the WSDL
interface using two
new sample messages; one message for the task input and the second
message
to define the task output.
Create the Task Input sample data file
The first step is preparing a message to use as the task input.
- Select the sample-data folder and create a new XML File named ManagerRequest.xml.
- Paste in the following text and save and close the file.
<loan:ManagerRequest xmlns:loan="http://schemas.active-endpoints.com/sample/LoanRequest/2009/06/ManagerApproval.xsd">
<loan:loanProcessRequest>
<loan:loanType>string value</loan:loanType>
<loan:firstName>string value</loan:firstName>
<loan:lastName>string value</loan:lastName>
<loan:dayPhone>string value</loan:dayPhone>
<loan:nightPhone>string value</loan:nightPhone>
<loan:socialSecurityNumber>string value</loan:socialSecurityNumber>
<loan:amountRequested>12345</loan:amountRequested>
<loan:loanDescription>string value</loan:loanDescription>
<loan:responseEmail>string value</loan:responseEmail>
</loan:loanProcessRequest>
<loan:loanApprovalResponse>
<loan:responseToLoanRequest>string value</loan:responseToLoanRequest>
<loan:responseDescription>string value</loan:responseDescription>
<loan:rejectionReason>
<loan:reason>string value</loan:reason>
<loan:description>string value</loan:description>
</loan:rejectionReason>
</loan:loanApprovalResponse>
</loan:ManagerRequest>
Create the Task Output sample data file
It is now time to prepare the task output.
- Select the sample-data folder and create a new XML File named ManagerResponse.xml.
- Paste in the following text and save and close the file.
<loan:ManagerResponse xmlns:loan="http://schemas.active-endpoints.com/sample/LoanRequest/2009/06/ManagerApproval.xsd">
<loan:responseToLoanRequest>string value</loan:responseToLoanRequest>
<loan:responseDescription>string value</loan:responseDescription>
</loan:ManagerResponse>
Update the process
Generate the WSDL for the new task
In this section we're going to do two things:
- Generate a WSDL to define the new task interface
- Assign this task to the loanmgrs
human task participant group
We can easily accomplish both items using the Participants
view. The participants view displays all service consumers,
partner service providers and human task participants for a
process.
- Open the loanProcessHumanCompleted.bpel process.
- Switch to the Participants view and expand the Human Task Participants section.
- Right click on the loanmgrs participants and select New Human Task
- Enter a value of ManagerApproval for the Task Name
- Press the Generate Interface... button

- Choose Request-Response for the operation and Using Sample XML for the Input and Output definitions:

- Press Next
- Expand the project folders and select the ManagerRequest.xml sample message that you created earlier. This will be used to define the input message for the task:

- Press Next.
- Expand the project folders and select the ManagerResponse.xml sample message that you created earlier. This will be used to define the output message for the task:

- Press Next
- Set the values for the Port Type, Operation and Target Namespace based on the image below:

- Press Next.
- Select the wsdl folder in the project and accept the default value of ManagerApproval.wsdl for the file name.

- Press Finish.
- The WSDL has now been created but we want to assign it to the loanmgrs human task participant. To do this expand the ManagerApproval Port Type and select the ManagerApproval operation as shown below:

- Press OK.
- Now the Participants view will show the new ManagerApproval task under the loanmgrs participant:

Review and Update the ManagerApproval.wsdl
In this section we're going to review the WSDL that was
generated
and make any changes that we desire. In our example we modify
the generated WSDL slightly to limit the choices that a loan
manager can provide when completing a task. The advantage of
making this change will become apparent when we review the task
presentation. Rather than allowing the loan manager to enter
any
value a drop down list containing only valid choices will be displayed.
- Open the ManagerApproval.wsdl file.
- Locate the element definition for the responseToLoanRequest and change its type from "xs:string" to "loan:ResponseValue"
- Add the following definition for the ResponseValue:
-
<xs:simpleType name="ResponseValue">
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="approved" />
<xs:enumeration value="declined" />
</xs:restriction>
</xs:simpleType>
- The changed fragment of your schema should look similar to this:

- Save and close the file.
Set the properties for the task
Now that we have a task interface defined we can set
additional
properties about the task.
- In the Outline view for the process expand the Human
Interactions
/ Tasks section and select the ManagerApproval Task.
- Select the Properties view
- Select the Presentation tab and enter values for the Display Name and subject similar to below:

- Select the Assignment tab and make sure that the Potential Owners and Business Administrator roles are both set to Logical People group with a value of loanmgrs as shown below. This ensures that the managers identified as approvers can carry out the task of approving and also administering the tasks:

- Select the Renderings tab, press the Create XSL... button, accept the default values:

Use the task in a new People Activity
We're going to use the task defined in the previous section in a new People activity. However, we are only going to execute this new activity if the loan was declined by the loan rep. The objective of this section, and the next, is to implement the logic in the following image by adding an If activity to invoke the new ManagerApproval people activity followed by an Assign activity that will map the results of the manager's approval to the process output. The detailed instructions for implementing this logic follow the image.
- Add a new If activity after the ReviewLoan activity.
- Set the following expression for the If activity:
- Add a sequence container inside the If activity.
- Add a People activity inside the sequence container.
- Select the People activity and then the Properties view to view the properties.
- In the Properties view for the People activity select the People Activity tab and set the properties as shown below:

- Select the Input tab, set the Assignment to XQuery, move the slider bar to the far right and press the Builder... button

- Replace the contents with the following:
- Select the Output tab and create a new Single Variable and name it ManagerResponse:

- The Output tab should look like this:


<mgrReq:loanProcessRequest>
<mgrReq:loanType>{ $creditInformation/loan:loanType/text() }</mgrReq:loanType>
<mgrReq:firstName>{ $creditInformation/loan:firstName/text() }</mgrReq:firstName>
<mgrReq:lastName>{ $creditInformation/loan:lastName/text() }</mgrReq:lastName>
<mgrReq:dayPhone>{ $creditInformation/loan:dayPhone/text() }</mgrReq:dayPhone>
<mgrReq:nightPhone>{ $creditInformation/loan:nightPhone/text() }</mgrReq:nightPhone>
<mgrReq:socialSecurityNumber>{ $creditInformation/loan:socialSecurityNumber/text() }</mgrReq:socialSecurityNumber>
<mgrReq:amountRequested>{ $creditInformation/loan:amountRequested/text() }</mgrReq:amountRequested>
<mgrReq:loanDescription>{ $creditInformation/loan:loanDescription/text() }</mgrReq:loanDescription>
<mgrReq:responseEmail>{ $creditInformation/loan:responseEmail/text() }</mgrReq:responseEmail>
</mgrReq:loanProcessRequest>
<mgrReq:loanApprovalResponse>
<mgrReq:responseToLoanRequest>{ $approve-task/loan:responseToLoanRequest/text() }</mgrReq:responseToLoanRequest>
<mgrReq:responseDescription>{ $approve-task/loan:responseDescription/text() }</mgrReq:responseDescription>
<mgrReq:rejectionReason>
<mgrReq:reason>{ $approve-task/loan:rejectionReason/loan:reason/text() }</mgrReq:reason>
<mgrReq:description>{ $approve-task/loan:rejectionReason/loan:description/text() }</mgrReq:description>
</mgrReq:rejectionReason>
</mgrReq:loanApprovalResponse>
</mgrReq:ManagerRequest>
Map the Task output to the process output
The final change we are going to make is to map the output
from the
human task to the required output for the process.
- Add a new Assign activity inside the sequence after the ManagerApproval activity.
- Create a new copy operation with the following properties:
- Source:
- Type: Expression
- Press the Expression Builder... button
- Change the Expression Language to XQuery
- Paste in the following expression:
<loan:responseToLoanRequest>{ $ManagerResponse/types1:responseToLoanRequest/text() }</loan:responseToLoanRequest>
<loan:responseDescription>{ $ManagerResponse/types1:responseDescription/text() }</loan:responseDescription>
</loan:loanApprovalResponse>
- Target:
- Type: Variable
- Variable: approve-task
- Your Copy Operation should look similar to this:

- Press OK twice to complete the dialog.
- Save the process. The changes to the process are now complete.
At this point you may notice that the .bunit files in the test
folder
contain errors. This is expected since these test cases no
longer
match the loanProcessHumanCompleted process that we just
changed. Since this sample is not concerned with simulating
the
process we can safely delete the files in this folder. Feel
free
to create new bunit tests. The Human Approval orchestration
project template documentation and the help system are both valuable
resources containing information on this topic.
Deploy the process
Once you have made all the changes to the process we can
deploy it
and run it on the server. However, since we added new
resources
to the project (ManagerApproval.wsdl and the task rendering style
sheets) we'll need to update the deployment descriptor so that these
resources get deployed to the server.
- In the Project Explorer view expand the deploy folder and open the loanProcessHumanCompleted.pdd file
- Press OK when presented with the dialog indicating that the process has changed:

- Save the PDD.
- Start the Embedded Sever
- Right
click on the pdd file in the Project Explorer and select Export to
recreate the BPR file and deploy it to the embedded server.
- Make sure that you have the Replace existing resources checkbox checked.
- You'll also want to replace the bprd file since it also
contains the new project resources.

- Press Finish.
Test the process
The steps for testing the process are similar to the steps
defined
in the Human Approval Completed cheatsheet and documentation.
Please refer to those instructions for more detail. An
overview
of the steps are listed here:
- Use the Web Services Explorer to start a new process instance.
- Log in to the Task Inbox as a Loan Representative, claim the task, decline the loan, save and complete the task.
- Log in to the Task Inbox as a Loan Manager, claim the task, approve or decline the loan, save and complete the task.
- Review the process details in the ActiveVOS Admin Console.
Start the process
- Open the Web Services Explorer, select the WSDL icon in the toolbar and use the following URL to retrieve the WSDL that defines the process: http://localhost:8080/active-bpel/services/LoanProcessHumanCompletedService?wsdl
- Select the Request operation
- Press the Source link replace the soap:body with the contents of all but the first line of the creditInfo_Jones15001.xml file in the project's sample-data folder.

- Press Go to start the process.
Claim the first Loan Representative task
- Log in to the inbox using the following credentials:
- User: loanrep1
- Password: loanrep1
- Claim and start the task
- Set the Loan Response to: Declined and enter a Rejection Reason as shown below:

- Save the task.
- Complete and confirm the completed task.
Claim the Loan Manager's task
- Log out of the inbox
- Log in to the inbox using the following credentials:
- User: loanmgr1
- Password: loanmgr1
- Claim and start the task
- Set the Output to set the ResponeToLoanRequest to either "approved" or "declined" from the drop down
- Add a value to the ResponseDescription element in the Output section. Here is an example:

- Save the task.
- Complete and confirm the completed task.
Review the process in the list of Active Processes.
You can review the state of the process by selecting it from
the
list of Active Processes on the ActiveVOS Console. The
following
image shows the loanProcessHumanCompleted with process ID of 3001
completed successfully. You can select the process name or id
to
drill in to the process for more details.

Summary
This sample described how to add a new Human Task and People
activity to an existing process. The WSDL for the task
interface
was generated automatically by the ActiveVOS Designer based on sample
input and output messages that we created ourselves. After
making
a slight modification to the WSDL we updated the task properties and
used the task in a new People activity. Since new resources
were
added to the process we allowed the ActiveVOS Designer to automatically
update the deployment descriptor file to keep it in sync with the BPEL
process. Finally we deployed and tested the process live on the
Embedded Server.
