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.
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/orderApprovalTo 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.
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:
fillOrderDetailsName:
Enter Order Details
Click the Start Event and click Form in the Properties tab.
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
fillOrderFormas 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.
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,quantityandunitPricefields.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
orderProductFlowas the value of the Id property.To set
orderProductFlowas the default flow, do the following.Click on the Exclusive Gateway.
Click the General tab in the Properties pane and select
orderProductFlowin the drop down to assign it.
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}
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
approveOrderFlowas 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.
Now, you have configured all the BPMN artifacts.
Configuring the Mail Task
To configure the Mail Task, do the following.
Click on the Order Product Mail Task and enter o
rderProductas 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>/libdirectory and restart the Business Process profile server instance.In the
<EI_HOME>/wso2/business-process/conf/activiti.xmlfile, add the following properties under the<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">property as shown below, to enable the Gmail configurations.Replace the
mailServerHostandmailServerPortproperty 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>"/>