jBPM and Drools Introduction

jBPM and Drools Introduction

BPMN Introduction[edit]

BPMN Basics[edit]

Flow Objects

  • Element start event.png Events (Circles)
  • Element activity.png Activities (Roundtangles)
  • Element gateway.png Gateways (Diamonds)


  • Element pool.png Pools
  • Element lane.png Lanes

Connecting Objects

  • Element sequence flow.pngSequence Flows
  • Element message flow.pngMessage Flows
  • Element association.pngAssociations
  • Element association.pngData Associations

Artifacts (used to provide additional information about the Process)

  • Element group.png Group
  • Text annotations.png Text Annotation

Event Basics[edit]


An Event is something that “happens” during the course of a Process.
  • Events affect the flow of the Process and usually have a cause or an impact. The term “event” is general enough to cover many things in a Process.
  • The start of an Activity, the end of an Activity, the change of state of a document, a Message that arrives, etc., all could be considered Events



Gateways are used to control splitting and merging of sequence flows.

  • do not represent ‘work’ being done
  • are considered to have zero effect on the operational measures of the process (cost, time, etc.).
  • two types of gateways: converge and diverge
  • type of gateway determines type of behaviour for both, the diverging and converging Sequence Flow
  • are optional

Types of Tasks[edit]



JBPM 6 - 0.0 - jBPM Overview[edit]

jBPM General Info[edit]

  • jBPM is a BPMS (Business Process Management Suite) written in Java
  • It allows you to design, model, execute, and monitor business processes throughout their life cycle.
  • Contains Drools - BRMS
包括Drools - BRMS (业务规则管理系统)集成
  • jBPM, released by JBOSS (Red Hat boght JBOSS)
jBPM是由 Red Hat Inc. 发布的(Red Hat 收购了 JBOSS Inc.)
  • Open Source and Commercial


BPMN name and standard。[edit]

  • In Version 1.x BPMN stands for Business Process Modelling Notation
BPMN 1.版本是业务流程建模标记法
  • Since Version 2.x BPMN stands for Business Process Model and Notation
BPMN 2.x版本是业务流程模型和标记法
  • http://www.omg.org/spec/BPMN/

BPMN 2.0 Purpose。[edit]

  • Provide a notation that is readily understandable by business and technical people
  • Create a standardised bridge for the gap between the business process design and process implementation
  • To standardise a business process model and notation in the face of many different modelling notations and viewpoints
  • To provide a means of communicating process information to other businesses, users, managers and process implementers
  • To exchange BPMN definitions (both domain model and diagram layout) between different tools

Audience of BPMN|BPMN的用户。[edit]

  • Business users 业务用户
    • Business analysts 业务分析员
    • Strategy analyst 策略分析员
    • Quality managers 质量管理员
  • Technical developers 技术开发人员
    • Process designers 流程设计员
    • Developers 开发人员
    • Integrators 集成人员
    • Software, System and Enterprise Architects 软件,系统和企业架构人员

BPMN Conformance|BPMN标准一致性。[edit]

Software based on spec
  • software tool developed only partially matching compliance/conformance
Modeling Conformance
  • Process modeling 流程建模
  • Choreography modelling Choreography建模一致性
Execution Conformance 执行标准一致性
  • Process Execution 过程的执行
  • BPEL Process Execution
A tool can comply to one of the above or any subset of them.
BPMN Complete Conformance complies to the all 4 above.
jBPM is based on BPMN 2.0, but doesn't conform to BPMN standard

Sub-models within an end-to-end BPMN model 。[edit]

  1. Processes (Orchestration)
    • Private non-executable (internal) BP
    • Private executable (internal) BP <- jBPM
    • Public Processes
  2. Choreographies
  3. Collaborations (can include Processes and Choreographies
    • Conversations

jBPM components[edit]


BPM tools[edit]



JBPM 6 - 1.0 - Workbench Overview[edit]

Starting jBPM console[edit]

cd /opt/jbpm-installer
ant start.demo


ant start.demo.noeclipse

Go to Firefox and type: http://localhost:8080/jbpm-console

Hello World Demo[edit]

Evaluation Demo 评估的演示[edit]

  • An employee performance needs to be evaluated
  • First, the employee gives feedback about their own performance
  • Later, HR (mary) and PM (john) departments give their opinion about employee department
  • It does not matter whether HR or PM evaluation is done first


Lab 1.1.1 Executing Process in Kie[edit]

  1. localhost:8080/jbpm-console
  2. login krisv/krisv
  3. Build Project
    1. Got to Authoring/Project Autorining
    2. In Project Explorer select demo / jbpm-playground / Evaluation project
    3. Click BUSINESS PROCESSES / 'evaluation' process to view the diagram
    4. Click Open Project Editor / Build & Deploy
  4. Start an Process Instance
    1. Process Management / Process Definitions
    2. Actions / Start
    3. Employee: krisv (must be this user)
    4. Reason: evaluation
  5. Perform Self-Evaluation
    1. Task List / Actions / Start
    2. Performance: "I am excellent"
  6. HR Evaluation
    1. Log in as mary
    2. Tasks / Actions / Start
    3. Click on Magnifying Glass icon / Work tab / Complete
  7. PM Evaluation
    1. Log in as john
    2. Task / Actions / Start
    3. Click on Magnifying Glass icon / Work tab / Complete
  8. View Log
    1. Process Management / Process Instances / Completed
    2. Actions / Details

Exercise 1[edit]

  • Run another instance of the process on your own

JBPM 6 - 1.1 - Creating Simple Process 创建简单流程[edit]

Scenario 场景[edit]

  • We are going to recruit people
  • At first the company is small, so it involves only interviewing people over the phone
  • Later more things to the process will be added
  • We will use this example over the most of the materials

Hrproj.employee recruitment.png

Creating Organization Unit, repository, project and package 创建组织单元、库、项目和包[edit]

Jbpm orgaizing konwoledge.png

  1. Creating Organizational Unit
    1. Log in as krisv
    2. Authoring/Administration
    3. Organization Units/Manage Organization Units/Add
    4. Name: npou / Owner: NobleProg Ltd
  2. Creating Repository
    1. Authoring/Administration
    2. Repositories/New Repository
    3. Repository Name: nprep/Organizational Unit: npou
  3. Creating Project
    1. Authoring/ Project Authoring
    2. Switch to npou/nprep
    3. New Item/Project
    4. Resource Name: npproj1
    5. Group ID: nppack

Creating Simple Process[edit]

  1. Creating simple diagram
    1. Authoring/Project Authoring
    2. New Item/Business Process/Name: emp_recruitment1
    3. Create User Task, set
    4. Name HT Phone Interview
    5. Task Name to HT Phone Interview
    6. Actor: krisv
    7. Validate the process
    8. Save, check in with "Added Phone Interview Task" message

Deploying and Executing[edit]

  1. Deploy the process
    1. Open Project Editor 
    2. Project Editor/Build & Deploy 
      JBPM Build&Deploy.png
    3. Process Management/Process Definitions
    4. Actions/Start
  2. Check whether Instance is running
    1. Process Management/Process Instances
  3. Performing a task
    1. Tasks/Task List
    2. Actions/Start
    3. Details / Work / Complete
  4. Check the Instance
    1. Process Management / Process Instances / Completed
    2. View Instance log of the task

Optional Browsing Database for completed instances and tasks[edit]

  1. Download SQL Workbench
  2. Login to /home/installuser/jbpm-db (username sa, no password)
  3. select * from taskevent;

JBPM 6 - 1.2 - Process Variables 过程变量[edit]

Scenario 场景[edit]

  • We would like to record the name of the person we are interviewing and the outcome of the interview.

Instructions 步骤[edit]

  1. Copy emp_recruitment1 to emp_recruitment2
    Top Right Corner, click Copy
  2. Change the Process Name and ID accordingly
  3. Create process variable pv_candidate_name (Properties/Variable Definitions)
  4. Generate forms 
  5. Check in Project Explorer under FORM DEFINITIONS that the forms has been properly generated
  6. Deploy
  7. Start new process instance
  8. Perform a task
  9. Check in Completed instances (Process Management/Process Instances/Completed/Actions/Details) the value of the variable 

Exercise 1.2.1[edit]

  • Add pv_candidate_suitable:Boolean variable and generate forms for it

JBPM 6 - 1.3 - InputSets and OutputSets[edit]

InputDataSets Instructions[edit]

  1. Copy emp_recruitment2 to emp_recruitment3
  2. Change the Process Name and ID accordingly
  3. In the Phone Interview task, add DataInputSet ut_candidate_name
  4. In assignments, map pv_candidate_name to ut_candidate_name
  5. Generate forms
  6. Deploy
  7. Start new process, input Albert as the candidate name
  8. Perform a task, change the ut_candidate_name field value before complete a task to AlbertModifiedInUserTask
  9. Check in Completed instances the value of the variable

OutputDataSets Innstructions[edit]

Hrproj.employee recruitment.png

  1. Create DataOutputSet in Phone Interview task name ut_candidate_suitable:Boolean
  2. In Assignments, map ut_candidate_suitable to pv_candidate_suitable
  3. Generate all forms (remove old forms before)
  4. Edit process form (npproj.emp_recruitment3-taskform) and remove pv_candidate_suitable field
  5. Save and Deploy
  6. Execute the process
  7. When performing the task, tick the "candidate_suitable" field
  8. After completing the task, go to completed instances and view the process variables and process model.

Exclusive Gateway[edit]

Hrproj.emp recruitmen3.png

  • Modify process as shown on the diagram above
  • Add constraint to the appropriate sequence flows:
  • to Hired end:
return pv_candidate_suitable;
  • to Not Hired end:
return pv_candidate_suitable == false;
  • Run process twice selecting different option in ut_candidate_suitable check-box
  • In completed instances check whether the variable got different values

JBPM 6 - 1.4 - Actors and Groups[edit]

You will learn 你将学到[edit]

  • How to create a new user
  • How to create a new group
  • How to assign task to a user
  • How a user can claim and release tasks assign to a group

Scenario 场景[edit]

  • NobleProg is growing and now more people will perform the tasks.
  • We will create np_hr_role with two people: isabel and greg
我们将建立一个np_hr_role,其中包含两个人:isabel 和 greg
  • We will also create np_manager_role with one person: bernard
  • Manager will be responsible for face to face interview

Creating users instructions[edit]

  1. Creating roles
    1. edit /opt/jbpm-installer/wildfly-8.1.0.Final/standalone/configuration/roles.properties and add following lines (please note that the admin role has been added in order to grant the users permission to Workbench)
  1. Creating users
    1. edit /opt/jbpm-installer/wildfly-8.1.0.Final/standalone/configuration/users.properies and add folowing lines

Group Assignment[edit]

  1. Copy emp_recuritment3 to emp_recuritment4
  2. Change the Process Name and ID accordingly
  3. Edit Phone Interview task properties
  4. Remove Actor property
  5. In Group property type np_hr_role
  6. Deploy and start the process

Claiming task[edit]

  1. Log in as greg
  2. In Tasks you should see unlock padloc icon
  3. Log in as bernard
  4. You cannot claim the task because bernard is not np_hr_role

Face to Face interview[edit]

Npproj.emp recruitment4.png

  1. Add new user task as show in the digram
  2. Assign the np_manager_role to Face to Face interview user task
  3. Create pv_f2f_candidate_suitable:Boolean process variable
  4. Create ut_f2f_candidate_suitable:Boolean task DataOutputSet in Face to Face interview task
  5. Create appropriate assignments
  6. Generate task forms
  7. Create appropriate conditions on the second gateway sequence flows
  8. Execute and test the process


Sometimes it is a good idea to show different group assignments in lanes

Npproj.emp recruitment4 2.png


JBPM 6 - 1.5 - BAM[edit]


  • How to find meaningful statistics related to process variables



  1. Dahboards
  2. Business Dashboards
  3. Login in as krisv/krisv
  4. Administration -> Data Providers
  5. Check if jBPM Process Summary exists (go to Instances by process), if not create one
  6. Create new data provider
  7. Fill out the query and name as below:
Name: jBPM Process Summary, Type: SQL Query
       select processinstanceid,
       from processinstancelog

Instances by process[edit]

  1. Change workspace to jBPM Dashboard

Report based on custom variables[edit]

Browse database structure

cd /opt/jbpm-installer
ant stop.demo
cd /opt/jbpm-installer/db/driver 
java -jar h2.jar

Change database to jbpm or other location where it is (JDBC URL)

JDBC URL: jdbc:h2:~/jbpm


Find VARIABLEINSTANCELOG Click on it and run


Create Data Provider[edit]

  1. Dashboards / Business Dahsboards
  2. Workspace: Showcase
  3. Administration / Data Providers / Create new data provider
  4. Type: SQL Query
  5. Name: Process Variables
  6. Paste the query:

Create Page[edit]

  1. Page: Click on the "Create new page icon"
  2. Title: Process Variables Analysis
  3. Go to Workspace
  4. Choose Page: Process Variables Analysis
  5. Create new panel in current page
  6. Click on Key Performance Indicator
  7. Drag "Create Panel" to the CENTER_1 side area 
  8. Choose Process Variables data source
    1. KIP's name: Variables
    2. Domain X Axis: value
    3. Rage (Y Axis): variableid
    4. Change type pie chart

Create Filters[edit]

  1. Create new panel
  2. Filter & Drill-down
  3. Drag it to the left hand side
  4. Click on the cog and Edit Content
  5. Tick processid and variableid

The final view:


More Information[edit]



JBPM 6 - 2.0.0 - Unit Testing Introduction 单元测试介绍[edit]

Unit testing 单元测试[edit]

  • Unit testing is a software testing method by which individual units of source code are tested to determine if they are fit for use
  • Unit tests are short code fragments created by programmers or testers during the development process.
  • Unit testing provides a sort of living documentation of the system.


  • JUnit is a unit testing framework for the Java programming language.
public class TestFoobar {

    public void testOneThing() {
        // Code that tests one thing
    public void testAnotherThing() {
        // Code that tests another thing



  • An assertion is a true–false statement placed in a program to indicate that the developer thinks 'that the predicate is always true at that place.
  • If an assertion evaluates to false at run-time, an assertion failure results, which typically causes execution to abort.
x = 1;
assert (x > 0);
assert (x > 1);


assert methods used in jBPM[edit]

assertNodeTriggered(processInstance.getId(),"Book Hotel");
assertNodeTriggered(processInstance.getId(), "StartProcess", "Hello", "EndProcess");
// checks whether the given node(s) was/were executed during the process execution

assertProcessInstanceActive(processInstanceId, ksession)
// checks whether the process instance is active

assertProcessInstanceCompleted(processInstanceId, ksession);
// checks whether the process instance has completed successfully

java operators[edit]

Simple Assignment Operator[edit]

=       Simple assignment operator

Arithmetic Operators[edit]

+       Additive operator (also used for String concatenation)
-       Subtraction operator
*       Multiplication operator
/       Division operator
%       Remainder operator

Equality and Relational Operators[edit]

==      equal to
!=      not equal to
>       greater than
>=      greater than or equal to
<       less than
<=      less than or equal to
!       logical complement operator; inverts the value of a boolean

Conditional Operators[edit]

&& Conditional-AND
|| Conditional-OR

JBPM 6 - 2.0.1 - Eclipse Overview[edit]

Sample jBPM Project[edit]

  • Start eclipse using ant
$ ant start.eclipse
  • Create new jBPM project, include sample project


ProcesTest.java file:

public class ProcessTest extends JbpmJUnitBaseTestCase {

	public void testProcess() {
		RuntimeManager manager = createRuntimeManager("sample.bpmn");
		RuntimeEngine engine = getRuntimeEngine(null);
		KieSession ksession = engine.getKieSession();
		ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");
		// check whether the process instance has completed successfully
		assertProcessInstanceCompleted(processInstance.getId(), ksession);
		assertNodeTriggered(processInstance.getId(), "Hello");


Sample.bpmn file:


  • Run the project (Menu: Run / Run or Ctrl-F11) and check Console and JUnit windows

More Advanced jBPM Project[edit]

Scenario: A salesman will get a bonus if his sales is over 1000.

BPMN file[edit]

  • Create new jBPM project (or open 04.1.2_exercise project)
  • Change diagram file name to Bonus.bpmn2


  • Add sales variable
    • Properties Window/Data Items/Variable List for Process/Add
  • Add conditions
    • sales>1000
    • else - default flow


  • Define script tasks
    • Congratulation!
System.out.println("You are the best!");
  • Try harder!
System.out.println("Maybe next time.");

ProcessTest.java file[edit]

  • Write Unit Test - add code to ProcessTest class
  • Import Man and HashMap (import java.util.HashMap;, import java.util.Map;)
  • Run project and check what happens if sales is 20000. Is bonus assigned? Check JUnit Window.
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("sales", 20000);
        ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
        assertNodeTriggered(processInstance.getId(),"Bonus Assigned");
        assertProcessInstanceCompleted(processInstance.getId(), ksession);
  • The final code
public class ProcessTest extends JbpmJUnitBaseTestCase {

	public void testProcess() throws Exception {
		RuntimeEngine engine = getRuntimeEngine(null);
		KieSession ksession = engine.getKieSession();

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("sales", 20000);
        ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
        assertNodeTriggered(processInstance.getId(),"Bonus Assigned");
        assertProcessInstanceCompleted(processInstance.getId(), ksession);

  • Add another test


 * Copyright NobleProg Ltd
 * Author: Filip Stachecki (filip@nobleprog.pl)
 * more info: http://www.nobleprog.co.uk
package com.nobleprog;

import java.util.HashMap;
import java.util.Map;

import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
import org.jbpm.test.JbpmJUnitBaseTestCase;
import org.junit.Test;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.manager.RuntimeEngine;
import org.kie.api.runtime.process.ProcessInstance;
import org.kie.internal.KnowledgeBase;
import org.kie.internal.runtime.StatefulKnowledgeSession;

public class ProcessTest extends JbpmJUnitBaseTestCase {

	public void testProcess() throws Exception {
		RuntimeEngine engine = getRuntimeEngine(null);
		KieSession ksession = engine.getKieSession();

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("sales", 20000);
        ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
        assertNodeTriggered(processInstance.getId(),"Bonus Assigned");
        assertProcessInstanceCompleted(processInstance.getId(), ksession);

	public void testProcessNoBonus() throws Exception {
		RuntimeEngine engine = getRuntimeEngine(null);
		KieSession ksession = engine.getKieSession();

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("sales", 500);
        ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
        assertNodeTriggered(processInstance.getId(),"No Bonus");
        assertProcessInstanceCompleted(processInstance.getId(), ksession);



  • 04.1_exclusive_gateway
    • 04.1.2_exercise
  • 04.2_inclusive_gateway
    • 04.2.1_exercise
  • Parallel gateway
    • 04.3_parallel_exercise
  • 05_timer_delay
  • 05.1_timer_delay
    • 05.1.1_exercise_timer_delay

JBPM 6 - 2.2 - User Task[edit]

public class ProcessTestEmpRec extends JbpmJUnitBaseTestCase {

	public void testProcess() {
		RuntimeManager manager = createRuntimeManager("emp_recruitment1.bpmn2");
		RuntimeEngine engine = getRuntimeEngine(null);
		KieSession ksession = engine.getKieSession();
		TaskService taskService = engine.getTaskService();
		ProcessInstance processInstance = ksession.startProcess("hrproj.employee_recruitment");

		assertProcessInstanceActive(processInstance.getId(), ksession);
		// Executing PhoneInterview task
		List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK");
		TaskSummary task = list.get(0);
		System.out.println("Kris is executing task " + task.getName());
		taskService.start(task.getId(), "krisv");
		taskService.complete(task.getId(), "krisv", null);
		assertNodeTriggered(processInstance.getId(), "PhoneInterview");

		assertProcessInstanceCompleted(processInstance.getId(), ksession);
	public ProcessTestEmpRec() {
		  super(true, true, "org.jbpm.persistence.jpa.updated");  


  1. Write tests for emp_recuritment4 covering all possible paths

JBPM 6 - 2.3 - Debugging Processes[edit]


  • current state of your running processes can be inspected and visualized during the execution.
  • currently breakpoints cannot be put on the nodes within a process directly
  • breakpoints can be put inside any Java code:
    • code that is invoking the engine
    • code invoked by the engine
    • listeners
    • rules (than part)

Debug views[edit]

  1. The process instances view
    1. shows all running process instances (and their state)
    2. shows the current state of a process instance
  2. The audit view
    1. shows the audit log
  3. The global data view
  4. Working memory view (facts)
  5. Agenda view (activated rules)

The process instances view[edit]

  1. Open 04_Debuging project
  2. Windows / Show View / Other / Drools / Process Instances
  3. Put a breakpoint after ksession.startProcess line
  4. Press F11 (Debug as JUnit Test)
  5. Switch to debug perspective
  6. In Variables window click on ksession
  7. In Process Instances windows, click on ksession insance
  8. Look at Process Instance windows to see where the process "hanged"

The process instance view and persistance

  • This kind of debuging will not work with pressistance
  • Please make sure you will turn persistance off by setting super(true,false)

Audit View[edit]

  • Open 04_Deubgging project
  • Run ProcessTestAudit.java
  • Open the Audit view
  • Open mylogfile file