2016/03/02
2 Mar, 2016

[Tutorial] How to Model Your Business Processes with WSO2 Business Process Server

  • Chathurika De Silva
  • Senior Software Engineer - Quality Assurance - WSO2
Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.

Table of contents


Introduction

Every organization consists of business processes that are designed to cater to a specific business goal. In order to get the business to operate in a smooth manner, these business processes should be comprehensive and complete. With the advancement of technology, various methodologies have been created to make them automated and versatile for organizations. This tutorial will discuss business process model and notation (BPMN) with a sample business process that can be leveraged to offer exclusive experiences for your customers.


BPMN and its role in business processes

BPMN1 is designed to provide businesses with the capability to understand their internal business procedures in a graphical manner and allows them to communicate these procedures in a standard manner. The graphical representation of BPMN makes it a powerful tool that provides cross border understanding and visualization to all the stakeholders involved.


Role of WSO2 Business Process Server in BPMN

WSO2 Business Process Server (WSO2 BPS)2 is designed to provide a complete web-based graphical console to manage, deploy, view and execute business processes and human tasks within a single server instance. Furthermore, WSO2 BPS enables users to model their business processes with either WS-BPEL or BPMN 2.0 standards.


WSO2 BPS and Activiti Engine

BPMN 2.0 in WSO2 BPS is powered by Activiti3, which is a lightweight business process modelling platform. Activiti provides a sophisticated set of tools and APIs that can be easily used by Java developers when modeling a business process. The step by step tutorial below examine how to implement a simple process using Activiti components.


Use case: Customer reward approval process

A small enterprise rewards its loyal customers based on their quarterly purchases. They don’t have sophisticated technology so the following steps are used to determine the rewards:

  • A record of the yearly purchases are kept.
  • A clerk checks the total amount.
  • He/she picks a random number (from 1 to 20) that are in a box.
  • He/she multiplies the total amount by the random number.
  • If the result is greater than 600,000 then the customer is rewarded.
  • The customer is sent a congratulatory letter by post when he/she is rewarded.

Now the enterprise wants to integrate technology into their everyday routine. First, they want to automate their above explained seasonal marketing activity.


How can this be achieved using Activiti

If the above use case is analyzed, it’s objective is to reward customers and to let them know that they were rewarded. Furthermore this process is short lived. It consists of the following components:

  1. Obtaining the purchases done for the year
  2. Multiplying it with a random number
  3. Checking whether the result is greater than 600,000
  4. Sending a postcard if it’s greater than 600,000

The above components can be matched to Activiti tasks as shown below:

  • Start Task: Clerk filling in a form with customer ID, customer name, purchase value
  • Java Service Task: Automated calculation
  • User Task: Clerk approves or rejects the result based on the condition
  • Exclusive Gateway, Mail Task: If approved, an email is sent
  • User Task: If rejected, the clerk fills form again

Modeling the use case using BPMN 2.0

Tools

WSO2 Developer Studio Version 3.7.1 (should be configured with Activiti designer plugin4)

Step 1: Writing the java class to be used in BPMN

  1. Open WSO2 Developer Studio IDE.
  2. Create a Maven Project5.
  3. Add the following code to java class:
    package org.wso2.bps.samplebpmn;
    import org.activiti.engine.delegate.DelegateExecution;
    import org.activiti.engine.delegate.JavaDelegate;
    import java.lang.Long;
    import java.util.Random;
    
    public class App implements JavaDelegate{
       	public void execute(DelegateExecution execution) throws Exception {
       	   	int billAmount = Integer.parseInt((String)execution.getVariable("amount"));
       	   	Random randomGenerator = new Random();
       	   	int value = randomGenerator.nextInt(20);;
       	   	int result = (billAmount * value);
    
       	 	execution.setVariable("result", "" + result);	 
       	}
    }
    

    The above java class implements the JavaDelegate interface by Activiti. By implementing this method it will enable the variables passed along the business processed to be used and automated.

    The above class takes a variable named amount using the getVariable() method, multiplies it with a random number and sets it using the setVariable() method. The setVariable() method allows the returning variable to be accessed from the business process.

  4. Add the following dependency to the pom.xml:
    <project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
     
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>org.wso2.bps</groupId>
    	<artifactId>samplebpmn</artifactId>
    	<version>0.0.1-SNAPSHOT</version>
    	<packaging>jar</packaging>
    	<name>samplebpmn</name>
    	<url>https://maven.apache.org</url>
    
    	<properties>
    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    	</properties>
    
    	<dependencies>
    		<dependency>
      			<groupId>junit</groupId>
      			<artifactId>junit</artifactId>
      			<version>3.8.1</version>
      			<scope>test</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.activiti</groupId>
    			<artifactId>activiti-engine</artifactId>
    			<version>5.19.0</version>
    		</dependency>
    	</dependencies>
    </project>
    
  5. Save the project.
  6. Open a command prompt and go to the project location.
  7. Issue the command mvn clean install to build the project to obtain the relevant dependencies.

The java class that is to be used with the business process is now ready as a jar file.


Step 2: Modelling the process with BPMN using Activiti designer plugin

The section below explains the steps to create a BPMN diagram using WSO2 Developer Studio.

  1. Open WSO2 Developer Studio.
  2. Go to File > New > Other and search for Activiti Project and click Next.

    Figure 1

  3. Enter a name for the Activiti Project and click Finish.

    Figure 2

  4. Right click on the project and select New > Other > Activiti Diagram and click Next.

    Figure 3

  5. Give a name for the process and click Finish.
  6. Figure 4

  7. Select Start Task from the right hand panel. Drag and drop it.

    Figure 5

  8. In a similar manner drag and drop a Java Service Task, two User Tasks and a Mail Task.

    Figure 6

  9. Drag and drop the connection element Exclusive Gateway.

    Figure 7

  10. Connect the tasks in the following order:
    • Start Task and Service Task
    • Service Task and User Task 1
    • User Task 1 and Exclusive Gateway
    • User Task 2 and Exclusive Gateway
    • Mail Task and Exclusive Gateway

    Figure 8

  11. Configure the Properties tab of the Start Task as shown below:
    • General tab

      Figure 9

    • Form tab

      Figure 10

  12. Configure the Properties tab of the Service Task as shown below:
    • General tab

      Figure 11

    • Main Config tab: the relevant java class that contains the logic should be specified.

      Figure 12

  13. Configure the Properties tab of the User Task 1 as shown below:
    • General tab

      Figure 13

    • Form tab

      Figure 14

    • Main Config tab: this user task should be completed by people who has a “finance” role. This is specified here.

      Figure 15

  14. Configure the Properties tab of User Task 2 as shown below:
    • General tab

      Figure 16

    • Form tab

      Figure 17

    • Main Config tab: this user task should be completed by people who has a “finance” role. This is specified here.

      Figure 18

  15. Configure the Properties tab of Mail Task as shown below:
    • General tab

      Figure 19

    • Main Config tab: the recipient email address, sender's email address, and other properties can be configured.

      Figure 20

  16. Configure the Properties tab of the Exclusive Gateway.

    The exclusive gateway is used to define the condition. In this sample the default path is the path from Exclusive Gateway to User Task 2. If the condition of the result returned from the service task is greater than 600,000 then the flow from Exclusive Gateway to the Mail Task should be executed.

    In the exclusive gateway, the default path is configured as shown below:

    • General tab

      Figure 21

  17. Configuring the condition to execute the Mail Task.

    The Mail Task’s execution should be defined in the flow connecting the Exclusive Gateway and the Mail task. In below diagram the variable “return” is the variable that is returned using the setVariable() method, in the java class that was implemented earlier.

    Figure 22

  18. Save the project.
  19. Right click on the Activiti project and click Create Deployment Artifacts.

    Figure 23

The MyProcess.bar should be created in the project folder under Deployment.


Testing the process using WSO2 BPS

The above sample is tested using WSO2 BPS 3.5.0.


Prerequisites

  1. Please refer to Working with Email Task for the email configuration.
  2. Copy the jar file created earlier to the <BPS_HOME>/repository/components/lib file.

Steps to test

  1. Start the BPS server.
  2. Open the management console and log in.
  3. Go to Manage > Add > BPMN.
  4. Browse for MyProcess.bar and upload it.
  5. The MyProcess.bar will be deployed and shown under Manage > List > BPMN.

    Figure 24

  6. Create a role named “finance”.
  7. Create a user and assign the role “finance” to them.
  8. Open BPMN-Explorer and log in as the the above created user.
  9. Go to Processes and start the process.

    Figure 25

  10. Fill in the form with the customer details and click Start.

    Figure 26

  11. Go to Search and search for the created task.

    Figure 27

  12. Click on the task and claim it.
  13. Approve the task if the amount is greater than 600,000.
  14. Click Complete. This will trigger an email to the defined recipient.

In a similar manner if the amount is less than 600,000, the user completes User Task 1 as rejected. Then another user task will be created to enter new customer details as shown below:

Figure 28


Conclusion

BPMN is a comprehensive technique that brings together various aspects of real world business scenarios. WSO2 BPS enables such business processes to be automated and hosted with the integration of Activiti Engine. Furthermore it offers state of the art tooling using WSO2 Developer Studio and user friendly customizable interfaces. This combination will give a personalized and exclusive experiences for the enterprise developers as well as the end users.


References

 

About Author

  • Chathurika De Silva
  • Senior Software Engineer - Quality Assurance
  • WSO2