Mule 3.3 – jBPM Model Part 1

In this post I’d like to describe the integration between Mule (Release 3.3) and Business Process Model (BPM). I’m using a Jboss implementation named jBPM.

BPM is a very huge argument, we’ll try to speak about it and look at used in Mule ESB. This wouldn’t be a post about entire BPM. I’ll not so able to speak about it.

You need to know that I’ve always been fascinated by these types of system. One of my first project has been with Microsoft BizTalk (are you suprised that now I’m speaking about java ?) and I’m very happy speaking again about these arguments.

Now some FAQ:

What is Business Process Model? (http://www.jboss.org/jbpm).

How does Mule get this integration? (http://blogs.mulesoft.org/using-mule-with-drools-and-jbpm/)

Is jBPM the only possible BPM integration engine with mule? Which version of BPM does Mule supported? (http://blogs.mulesoft.org/modeling-your-business-logic-bpm-rules-and-cep-part-2/). Take a look of it “The latest version supported by Mule is jBPM 4.2“.

Let’s start to describe my business flow.  I have to decide if accept or refuse company’s orders . For this purpose we’ll check the order’s quantity. If this quantity is less than 100 I refuse the order; otherwise I accept it. Easy, not?

It’s available a graphic plugin for Eclipse and we’ll use it to design the Business Rule. This is the result:

How have we got this result? First you’ve to download the jbpm version 4.2 from jboss web site.

http://sourceforge.net/projects/jbpm/files/jBPM%204/jbpm-4.2/jbpm-4.2.zip/download

Once you have unzipped the files into a folder, you can install the plugin. Go to Help->Install new software and take the <source_jbpmdirectory>/install/src/gpd/jbpm-gpd-site.zip file.

Some next, next, next later you’ll able to create jBPM4 Process Definition from “New”  window.

Let’s proceed with the creation of the business process. A complete guide about the language (jPDL) is available here (http://docs.jboss.com/jbpm/v4/userguide/html_single/#jpdl).

The xml source of our process is the follow:


<?xml version="1.0" encoding="UTF-8"?>

<process name="orderprocess" xmlns="http://jbpm.org/4.3/jpdl">
	<mule-receive endpoint="toOrderprocess" name="receiveOrder" type="java.lang.String" var="orderid">
        <transition to="ProcessOrder"/>
    </mule-receive>

   <decision g="206,180,48,48" name="orderDecision">
      <transition g="-62,-20" name="to RefuseOrder" to="RefuseOrder">
      	<condition expr="#{orderwarehouse.quantity &lt; 100}"/>
      </transition>
      <transition g="-66,6" name="to AcceptOrder" to="AcceptOrder">
      	<condition expr="#{orderwarehouse.quantity &gt;= 100}"/>
      </transition>
   </decision>

   <java class="it.matrix.samplemulejbpm.CheckOrder" g="17,179,92,52" method="processOrder" name="ProcessOrder" var="orderwarehouse">
   	<arg><object expr="#{orderid}"/></arg>
      <transition g="-39,-19" name="to orderDecision" to="orderDecision"/>
   </java>

   <java class="it.matrix.samplemulejbpm.CheckOrder" g="317,245,92,52" method="acceptOrder" name="AcceptOrder">
   	<arg><object expr="#{orderwarehouse}"/></arg>
      <transition g="-74,-18" name="to orderResult" to="orderResult"/>
   </java>

   <java class="it.matrix.samplemulejbpm.CheckOrder" g="316,116,92,52" method="refuseOrder" name="RefuseOrder">
   	<arg><object expr="#{orderwarehouse}"/></arg>
      <transition g="-75,-1" name="to orderResult" to="orderResult"/>
   </java>
   <join g="506,176,48,48" name="orderResult">
   </join>

	<mule-send endpoint="fromOrderprocess" exchange-pattern="one-way" expr="#{orderwarehouse}" name="sendToOutput">
	</mule-send>

</process>

I used a controller class named it.matrix.samplemulejbpm.CheckOrder.


package it.matrix.samplemulejbpm;

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

public class CheckOrder {
 
 private static final long serialVersionUID = 1L;
 
 Map<String, Order> warehouse = new HashMap<String, Order>()
 {
  {
   put("AZ-1265", new Order("AZ-1265", 100, 2011.9f));
   put("AZ-6522", new Order("AZ-6522", 10, 115.9f));
   put("AZ-8436", new Order("AZ-8436", 200, 500.10f));
  }
 };
 
 public String acceptOrder(Order payload)
 {
  payload.setResponse("Accepted");
  return payload.toString();
 }
 
 public String refuseOrder(Order payload)
 {
  payload.setResponse("Refused");
  return payload.toString();
 }
 
 public Order processOrder(String payload)
 {
  Order order = warehouse.get(payload);
  if (order == null)
  {
   //Order not found
   order = new Order("0", 0, 0);
  }
  
  return order;
 }
}

And here the bean Order.


package it.matrix.samplemulejbpm;

import java.io.Serializable;

public class Order implements Serializable {

 /**
  *
  */
 private static final long serialVersionUID = 7830120993371620210L;
 
 public String orderId;
 public int quantity;
 public float amount;
 private String response;
 
 public Order(String orderId,
     int quantity,
     float amount)
 {
  this.orderId = orderId;  
  this.quantity = quantity;
  this.amount = amount;
 }
 
 public String getOrderId() {
  return orderId;
 }
 public void setOrderId(String orderId) {
  this.orderId = orderId;
 }
 public int getQuantity() {
  return quantity;
 }
 public void setQuantity(int quantity) {
  this.quantity = quantity;
 }
 public float getAmount() {
  return amount;
 }
 public void setAmount(float amount) {
  this.amount = amount;
 }
 
 @Override
 public String toString()
 {
  return "orderId: " + orderId +
    " quantity: " + quantity +
    " amount: " + amount +
    " response:" + response ;
 }

 public String getResponse() {
  return response;
 }

 public void setResponse(String response) {
  this.response = response;
 }

}

In the next part of this post I’ll show you how integrate this flow with Mule. Stay tuned.

Advertisements

2 thoughts on “Mule 3.3 – jBPM Model Part 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s