Simulating an Order Approval Process
The following example demonstrates creating a business process scenario to simulate an order approval process. The Production Manager invokes an order approval process where it is possible to set the product ID. Additionally, an admin user of the Production Division can set the quantity to order and the unit price of the product. The quantity and the unit price are used to calculate the total cost. If the total cost is above 100,000, the order will have to be approved by an admin user from the Production Division before the order email is dispatched to the Purchasing Division. Alternatively, if the cost is below 100,000, the order email is dispatched to the Purchasing Division without approval.
Before you begin,
- Download the product installer from here, and run the installer.
Let's call the installation location of your product the <EI_HOME> directory. This is located in a place specific to your OS as shown below:OS Home directory Mac OS /Library/WSO2/EnterpriseIntegrator/6.6.0
Windows C:\Program Files\WSO2\EnterpriseIntegrator\6.6.0\
Ubuntu /usr/lib/wso2/EnterpriseIntegrator/6.6.0
CentOS /usr/lib64/EnterpriseIntegrator/6.6.0
Select the relevant WSO2 Integration Studio based on your operating system and download it from here.
The path to this folder is referred to as<EI_TOOLING>
throughout this tutorial.Getting an error message? See the troubleshooting tips given under Installing WSO2 Integration Studio.
Let's get started! This tutorial includes the following sections:
Creating the artifacts
Follow the steps below to create the requires artifacts.
- Create a new BPMN project named OrderApprovalBPMN. For instructions, see Creating a BPMN Project .
Create a BPMN Diagram named OrderApproval .bpmn. For instructions, see Creating the BPMN Diagram .
- Click anywhere on the canvas, go to the Properties tab, and fill in the following details:
Id :orderApproval
Name :Order Approval Process
Namespace :http://wso2.org/bpmn/orderApproval
- To implement the order approval process, drag and drop a StartEvent element, two UserTask elements, a MailTask element and a End Event element on the canvas.
- For each artifact, in the Properties tab, select General and enter the corresponding names as Fill Order Form, Approve Order and Order Product as shown below.
According to the business logic in this example, the Start Event should trigger the Fill Order Form User Task. Therefore, in the Connection tab, select Sequence Flow, and connect the Start Event to the Fill Order Form User Task.
Hover your mouse over the Fill Order Form task and click on the Exclusive Gateway icon.
The diamond shape with a cross in the middle implies an Exclusive Gateway. This is used to add the condition logic statements. The condition statement should implement the logic that if the total cost calculated from the quantity and unit price is above 100,000 a user task has to be executed. Else, the mail task has to be executed.
- Use the Sequence Flow to connect the other artifacts as shown below.
Configuring the artifacts
After the diagram has been constructed, you must configure the properties of each element to implement the business logic.
Configuring the Start Event
Follow the steps below to configure the Start Event.
Click on the Start Event and set the following values in the General section of the Properties tab.
Id:
fillOrderDetails
Name:
Enter Order Details
Click the Start Event and click Form in the Properties tab.
This is to create a form to get the order details (i.e., the product ID) from the manager who invokes the process.
- Click the New button, enter the below details to create a productID field and click OK.
Id: productID
Name: Product Id
Type: string
Variable: productID
Configuring the User Tasks
Now, you can configure the Fill Order Form User Task, which is a Claimable Task. An administrator of the Production Division can claim and complete the form.
Click on the Fill Order Form User Task and set
fillOrderForm
as the ID in the General section of the Properties tab.Click Main Config in the Properties tab and enter admin as the value of the Candidate Group.
Since there is no specific user to assign the task, an admin user from the Goods Division can claim the task and execute it. This allows any administrator under the Goods Division to claim and complete the task.
Click Form in the Properties tab, click New each time and add the values in the below table. This creates the form that the employee needs to fill with the
productID
,quantity
andunitPrice
fields.productID quantity unitPrice Id productID quantity unitPrice Name Product ID Quantity Unit Price Type string long double Variable productID quantity unitPrice Once the above fields are added to the form, the table in your Form should look similar to the following:
Now that you have configured your Fill Order Form User Task, you can identify the two flows: the default flow and conditional flow. Follow the steps below to assign the default flow.
- Click on the Sequence Flow arrow, which connects the Exclusive Gateway to the Mail Task.
- Set
orderProductFlow
as the value of the Id property. - To set
orderProductFlow
as the default flow, do the following.- Click on the Exclusive Gateway.
- Click the General tab in the Properties pane and select
orderProductFlow
in the drop down to assign it.
- Click on the Sequence Flow arrow, which connects the Exclusive Gateway to the Mail Task.
To assign the Conditional flow, click on the Sequence Flow arrow, which connects the Exclusive Gateway to the Approve Order User Task. In the Main Config section of the Properties tab, enter the following value as the Condition:
${(quantity*unitPrice) > 100000}
This is for calculating the total cost and checking if it exceeds 100,000. If it does, it will take the conditional flow.
You have now configured the conditional flow. If the total cost exceeds 100,000, the flow is directed to the Approve Order User Task.To configure the Approve Order User Task, do the following.
Click on the Approve Order User Task.
In the General section of the Properties tab, enter
approveOrderFlow
as the Id.In the Main Config section, set the Candidate Group as
admin
. This enables anyone from the order approval group to claim and complete the task.To allow the approver to view the order details, create a form to display the Product ID, Quantity and Unit Price. To do this, navigate to the Form section in the Properties tab and create the fields as shown below.
productID quantity unitPrice Id productID quantity unitPrice Name Product ID Quantity Unit Price Type string long double Variable productID quantity unitPrice Readable true true true
Configuring the Mail Task
To configure the Mail Task, do the following.
Click on the Order Product Mail Task and enter o
rderProduct
as the Id in the General section of the Properties tab.- In the Main Config section of the Properties tab, fill the respective fields (i.e., To, From, Subject).
- In the Non-HTML field of the Main Config section, enter
Order ${quantity} of ${productID} at the rate of ${unitPrice}
. The variable will be used to create the mail body. Copy the following JAR files into the
<EI_HOME>/lib
directory and restart the Business Process profile server instance.In the
<EI_HOME>/wso2/business-process/conf/
file, add the following properties under theactiviti.xml
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
property as shown below, to enable the Gmail configurations.Replace the
mailServerHost
andmailServerPort
property values as follows:<property name="mailServerHost" value="smtp.gmail.com"/> <property name="mailServerPort" value="587"/>
Add the following properties:
<property name="mailServerDefaultFrom" value="<ENTER_A_VALID_SMTP_EMAIL_ADDRESS>"/> <property name="mailServerUseTLS" value="true"/> <property name="mailServerUsername" value="<ENTER_A_VALID_SMTP_EMAIL_ADDRESS>"/> <property name="mailServerPassword" value="<ENTER_THE_EMAIL_PASSWORD>"/>
The model is now complete as the necessary logic has been applied.
Deploying the artifacts
- For instructions on creating the deployable artifacts, see Creating the deployable archive.
- For instructions on deploying them, see Deploying BPMN artifacts.
Testing the output
Follow the steps below to test the output.
If you have not started the business profile previously, make sure to start it.
- Log in to the BPMN-explorer at https://localhost:9445/bpmn-explorer using
admin
for both the username and password. - Click PROCESSES in the top menu, and click the Start option of the Order Approval Process.
- Enter a value for the Product Id and click Start. This creates a Claimable Task.
- Click TASKS in the top menu, and then click Claimable Tasks.
- Click on the new Claimable Task.
- Click Claim Task on the next Fill Order Form screen.
Enter values for the Quantity and Unit Price to get a total value (i.e.,
Quantity * Unit Price
), which is less than 100,000, and click Complete Task.
You view the claimable task being completed and removed from the TASKS list, since the total value you entered (i.e.,Quantity * Unit Price
) is less than 100,000.Click TASKS → COMPLETED TASKS to view the completed task.
Also, you will receive an email to the recipient email address you defined.
- Follow the above steps again by entering values for the Quantity and Unit Price to get a total value (i.e.,
Quantity * Unit Price
), which is more than 100,000. - Click TASKS → CLAIMABLE TASKS. Since you are logged in as the administrator, you view the Claimable Task, which is created for the administrator to approve the order.
- Click on the Task and click Complete Task to approve the order.
- Click on the task, click Claim Task, and then click Complete Task.
You will receive an email to the recipient email address you defined.