Ok, so what's behind this picture ? jBPM uses jPDL to describe the process in XML format.

<process-definition xmlns="urn:jbpm.org:jpdl-3.2"
    name="simple">
    <swimlane name="buyer">
        <assignment actor-id="customer"></assignment>
    </swimlane>

    <swimlane name="deliverDepartment">
        <assignment actor-id="deliver-man"></assignment>
    </swimlane>

    <start-state name="start">
        <transition name="trPlaceOrder" to="PlaceOrder"></transition>
    </start-state>

    <task-node name="PlaceOrder">
        <task name="placeOrderTask" swimlane="buyer">
        </task>
        <transition name="" to="CheckAvailability"></transition>
    </task-node>

    <decision name="CheckAvailability">
        <handler class="com.sample.decision.VerifyOrder"></handler>
        <transition name="trDeliver" to="Deliver"></transition>
        <transition name="trGetFromStock" to="GetFromStock"></transition>
    </decision>

    <state name="GetFromStock">
        <event type="node-enter">
            <action class="com.sample.action.GetFromStockActionHandler"
                name="recharge"></action>
        </event>
        <transition name="checkAvailability" to="CheckAvailability"></transition>
    </state>

    <task-node name="Deliver">
        <task name="getFromStock" swimlane="deliverDepartment">
        </task>
        <transition name="trEnd" to="end"></transition>
    </task-node>

    <end-state name="end"></end-state>
</process-definition>

 

You can clearly see how the graphical elements have been translated into XML source code. jPDL in not too complicated, in short it will associate actions with handlers. Handlers are written as plain Java classes implementing business interfaces.

For example, the decision node CheckAvailability delegates to a DecisionHandler which path should be followed by our process. Here we'll use a very simple decision handler which compares two process variables in order to decide if there are enough good in the stock. In real world process, we'll likely query a Database in order to collect this information.  

package com.sample.decision;

import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.node.DecisionHandler;

public class VerifyOrder implements DecisionHandler {


    public String decide(ExecutionContext executionContext) throws Exception {

        Integer goodsOrdered = (Integer)executionContext.
                getContextInstance().getVariable("goodsOrdered");
        System.out.println("Goods ordered "+goodsOrdered.intValue());


        Integer goodsInStock = (Integer)executionContext.
                getContextInstance().getVariable("goodsInStock");
        System.out.println("Goods in stock "+goodsInStock.intValue());

        if (goodsOrdered.intValue() > goodsInStock.intValue()) {
            return "trGetFromStock";
        }
        else {
            return "trDeliver";
        }
    }

}

 

0
0
0
s2smodern

Related articles available on mastertheboss.com

How do I fire an action every time a JBPM Node enters?

JBoss recipe of the day

JBoss Jbpm superstates

What is a superstate ? a Superstate is a group of nodes. Supersta

Jbpm Mail delivery

Almost every workflow needs a notification of the process activit

How do you embed Java code in your JPDL ?

  You can use a BeanShell expression to add a Java script in you

JBPM best practices

There's no perfect rule to model your workflow, it depends on the

How to delete/persist your JBPM process after restart ?

JBoss recipe of the day