Activiti BPMN on JBoss AS 7

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

In this tutorial we show how to install the Activiti BPMN platform on JBoss AS 7 and how to deploy and test a sample process in it. 

Activiti is a light-weight workflow and Business Process Management (BPM)  engine. We have already published an Activiti tutorial about one year ago, now we will explore a newer release and try it with the latest JBoss AS 7.

Start by downloading Activiti latest release http://www.activiti.org/download.html

Installing Activiti

Just unzip the file to a directory of choice and then check out the readme.html that includes pointers to the docs and the release notes. The userguide ( docs/userguide/index.html ) includes instructions on how to get started simple and quick.

The default activiti installation is targeted on H2 in memory Database. We will show here how to switch to MySQL database.

Create the Activiti Database

mysql> create database activiti;

mysql> grant usage on *.* to kermit@localhost identified by 'kermit';

mysql> grant all privileges on activiti.* to kermit@localhost ;


Picktup the createdb script: The script is named activiti.mysql.create.engine.sql and is located in the activiti-engine-5.9.jar (Into the org\activiti\db\create folder). Execute the script from your sql session (or any other Sql client application)

mysql> source activiti.mysql.create.engine.sql

Install the Eclipse plugin

Activiti comes with an Eclipse plugin, the Activiti Eclipse Designer, that can be used to graphically model, test and deploy BPMN 2.0 processes.
Go to Help -> Install New Software. In the following panel, click on Add button and fill in the following fields:

Name: Activiti BPMN 2.0 designer

Location: http://activiti.org/designer/update/
activiti install plugin eclipse install plugin eclipse
Once installed restart Eclipse.

Create an Activiti Project

Now we will create a new Activiti Project which will provide the archetype for building our first application.
Next add a diagram to it. In this diagram we will simulate a Review process which will be used to approve or reject a candidate.
Create a process where you have an User Task (that will be in charge to evaluate the candidate) and two Mail Tasks where you will dispatch the approval or rejection of your candidate.


Here's how your process looks like:
activiti tutorial jboss 7
Within the User Task (1), select the Main Config Tab and choose as Assignee the user "kermit" (the default administrator).

activiti tutorial jboss 7
Next move to the Form Tab we will set three properties (name, mail and experience) that can be filled by the Reviewers and will decide the path of the workflow.
activiti tutorial jboss example
Now move to the upper Sequence Flow (2) and add the condition which will be undertaken if approved the candidate (in this simple process we suppose that candidates with over 5 years of experience are accepted).
jboss as 7 activiti tutorial
Now add the corresponding confition in the lower Sequence Flow (3)
activiti bpmn 2.0 tutorial
Next move to the Mail task (4) and adds the information necessary to dispatch the mail. The mail will be sent to the address specified by the "mail" variable and, into the text, we will use as well the "name" form property.
activiti bpmn 2.0 tutorial bpmn 2.0 tutorial
Fine, repeat the same for th Mail task(5) in case the candidate is rejected.

Good, now your simple Review process can be uploaded. It should look like this (we have not included for brevity the bpmn graphic notation. You can download the full process from here)

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="SampleReview" name="SampleReview">
    <startEvent id="startevent1" name="Start"></startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <userTask id="usertask1" name="User Task" activiti:assignee="kermit">
      <extensionElements>
        <activiti:formProperty id="name" name="name" type="string"></activiti:formProperty>
        <activiti:formProperty id="experience" name="experience" type="long" required="true"></activiti:formProperty>
        <activiti:formProperty id="email" name="email" type="string"></activiti:formProperty>
      </extensionElements>
    </userTask>
    <serviceTask id="mailtask1" name="Approved" activiti:type="mail">
      <extensionElements>
        <activiti:field name="to" expression="${email}"></activiti:field>
        <activiti:field name="subject" expression="Request Approved"></activiti:field>
        <activiti:field name="html">
          <activiti:expression><![CDATA[${name} we are glad to inform you that your canditature has been accepted.]]></activiti:expression>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <serviceTask id="mailtask2" name="Rejected" activiti:type="mail">
      <extensionElements>
        <activiti:field name="to" expression="${email}"></activiti:field>
        <activiti:field name="subject" expression="Request Rejected"></activiti:field>
        <activiti:field name="html">
          <activiti:expression><![CDATA[${name} we are sorry to inform you that your canditature has been accepted.]]></activiti:expression>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <sequenceFlow id="flow2" name="" sourceRef="usertask1" targetRef="exclusivegateway1"></sequenceFlow>
    <sequenceFlow id="flow3" name="" sourceRef="exclusivegateway1" targetRef="mailtask1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${experience > 5}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow4" name="" sourceRef="exclusivegateway1" targetRef="mailtask2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${experience <= 5}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow5" name="" sourceRef="mailtask1" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow6" name="" sourceRef="mailtask2" targetRef="endevent1"></sequenceFlow>
  </process>



(In order to upload it from the Activiti explorer you can either use a .zip file, a .bar archive or an xml file ending with .bpmn20.xml)

Follow us on Twitter