jBPM5 - Example


Advertisements

We will take an example in this chapter to explain how to put jBPM into practice. The task at hand is to use jBPM to decide whether a passenger will board a flight or a train, depending upon his income.

Steps to create the project remains the same as that of "Hello World" project. Open the .rf file in the editor, and see the changes as marked in red −

Hello World Project

Here, we have changed the ruleflow id (unique) and added a variable income, as we will be deciding the route based on the income of the passenger.

How to set variable − Select the edit button marked in red.

Set variable

Click the Add button −

Variable List

The following screen pops up −

Screen Pops

Put name as income and type as Integer.

Edit Variable

Click OK. You will see the income variable defined now.

Variable Defined

Changes to be done in ProcessTest.java class (Class to load and run your process) −

Process Test
Map<String, Object> params = new HashMap<String, Object>();
params.put("income", 1200);

// start a new process instance
ksession.startProcess("vivek.ruleflow", params);

You need to create a MAP and set the value in MAP and pass this value to the startProcess overloaded method. As depicted, we have changed the ruleflow id and hence used the same id (vivek.ruleflow) in the startProcess method.

Before running the ProcessTest.java class, create a POJO Passenger.java in the same package as ProcessTest.java

public class Passenger {
   private String name;
   private int income;
   Getters and setters here
}

Now run the ProcessTest.java class as a Java Application and see the output −

ProcessTest

Change the value − params.put("income", 900); and re-run the class and see the change in output.

Change value
Advertisements