jBPM 5.0 – creating simple Human Tasks with variables

The fastest way to get jBPM 5.0 running is to take these three simple steps:

1. Download the jBPM 5.0 installer: http://sourceforge.net/projects/jbpm/files/jBPM%205/jbpm-5.0-Final/
2. Run ant install.demo
3. Once everything is downloaded, run ant start.demo

Start off by creating a new BPMN file. To do so, select File->New->File, as the filename input “YourProcessName.bpmn” (thanks to the extension the Process Editor will open).

Inside the editor, create the business logic that you desire.

For this example I have created a process that looks like this:

I used two Script Tasks to set the variables and two User Tasks.
Script tasks are necessary because a Human Task can have only a single input parameter, “Content”.
To pass multiple variables “Content” must be set to a map that contains all the variables.

Begin by opening the properties tab of the project.
If you cannot see the properties view, open it using the menu “Window”, then “Show View” and “Other…”, and under the “General” folder select the Properties View.
Set the projects Id, Name, Package and variables (click on the “…” button in the Value section).
The map field should be a object type with its classname set to java.util.HashMap.
The other fields should be set to strings.
The end result should look like this:

jpbm-process-properties

Select the first Script task and open its properties tab.
Open the Action editor for the Action field (click on the “…” button in the Value section).
Set the dialect to Java.

Create a map and add the necessary variables:

map = new java.util.HashMap();

map.put("name","John Doe");
map.put("phoneNumber","123456789");

kcontext.setVariable("map", map);
kcontext.setVariable("name",name);
kcontext.setVariable("phoneNumber",phoneNumber);

The last three lines of this Action create globally accessible data stored in the Knowledge Session.

Now open the properties view for the First User Task.
Set ActorId to “krisv”.
Open the parameter mapping editor and add a mapping:
Parameter = “Content”, Value = “map”
This will allow us to use variables inside the Human Task Form.
Open the result mapping editor and add a mapping of the returned values:
Parameter = “phoneNumber”, Value = “phoneNumber”
Parameter = “name”, Value = “name”
Set Skippable to “false” and TaskName to “TaskOne”
The task name is important because it connects the task with its form.

Open the properties of the second Script Task and add the necessary action:


map.put("name",name);
map.put("phoneNumber",phoneNumber);

Now open the properties view for the Second User Task.
Set ActorId to “john”.
Open the parameter mapping editor and add a mapping:
Parameter = “Content”, Value = “map”
Set Skippable to “false”, TaskName to “TaskTwo”.

Now its time to create the Human Task Forms.
jBPM 5.0 uses ftl forms which are basically HTML.

Create two files, TaskOne.ftl and TaskTwo.ftl.

Their sources should look accordingly:

TaskOne.ftl:

<html>
<body>
<h2>First Task</h2>
<hr>

Name: ${name}<br>
Phone Number: ${phoneNumber}
<br>
<br>
<form action="complete" method="post"
enctype="multipart/form-data">
Name : <input name="name" type="text">
<br>
<br>
Phone number : <input name="phoneNumber" type="text">
<br>
<input value="Complete" type="submit"></form>

</body>
</html>

TaskTwo.ftl:

<html>
<body>
<h2>Task Two</h2>
Name: ${name} <br>
Phone Number: ${phoneNumber} <br>
<br>

<form action="complete" method="POST" enctype="multipart/form-data">
<input type="submit" value="Complete">
</form>
</body>
</html>

Create a screenshot of the process diagram and save it as a png file with its name set to the process Id (in this case
myproject.MyProcess.png).

Pack these three files (two .ftl files and a .png screenshot) into a .jar file.

There are two ways to deploy a process: by Guvnor or by hand.
The second option means that the .jar file has to be added to the servers classpath (jboss-dir/server/default/lib/),
and the .bpmn file has to be added to the directory where all bpmn files are stored – this directory is set in the ant build.xml file by the
-Djbpm.console.directory argument. The Default value is: ${install.home}/sample/evaluation/src/main/resources/.

When changes are made to the .ftl files, because the .jar is being added to the servers class path, the server has to be restarted.
When using the demo you can simply run ant stop.demo and ant start.demo.

When changes are made to the bpmn file, no restart is necessary. Just copy the new file to the appropriate directory and the
process will change accordingly.

When the deployment is completed, the task can be started.
There are two ways to accomplish this:
From the jBPM console or by an application.
Login into the jBPM console (localhost:8080/jbpm-console), go to Processes -> Process Overview, select the appropriate process and click “Start”.
Once the process has started you can login as krisv/krisv and view the human task form by selecting “view” for the appropriate task in the Personal Tasks tab.
Once you complete the form, login as john/john. The new variables you have entered should be visible in this users form.

The easiest way to start a task from an application is to create a jBPM project in Eclipse, select adding the Hello World example and slightly modify the ProcessTest.java code.
The final code should look like this:


package myproject;

import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.process.workitem.wsht.WSHumanTaskHandler;

/**
* This is a sample file to launch a process.
*/
public class ProcessTest {

public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WSHumanTaskHandler());
// start a new process instance
ksession.startProcess("myproject.MyProcess");
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}

private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("MyProcess.bpmn"), ResourceType.BPMN2);
return kbuilder.newKnowledgeBase();
}


}

Once this file is ran as a Java Application, the process starts and can be accessed via the jBPM console for the user krisv.

While learning the basics of jBPM I found very helpful information here:
1. Getting started with jBPM 5 screencast: http://www.youtube.com/watch?v=-8pDrcGejxk
2. jBPM 5 Example – Human Task Forms with Variables: http://community.jboss.org/people/bpmn2user/blog/2011/02/21/jbpm5-example-for-forms-with-variables

Advertisements

Web Services with Eclipse, Tomcat, Axis, Rampart

This article is a part of a bigger document that has been created as a summary of my 3-month experience with IBM ESI.

Below you will find basic information about Web Services as well as a step-by-step tutorial ilustrating how to create and test:

– A simple Hello World Web Service
– A SSL-based Web Service
– A WS-Security enabled Web Service

With the use of:

– Eclipse
– Web Tools Platform
– Apache Tomcat
– Apache Axis
– Apache Rampart
– Eclipse Web Services Explorer
– SoapUI

Read more here

Użytkownik systemowy WSLE

W momencie instalacji WSLE w wersji “sandbox” (7.1) / “simple” (7.2) na Windowsie, w systemie zostaje dodany nowy użytkownik o nazwie WSLE.

Użytkownik ten służy wyłącznie do uruchamiania usług systemowych zarządzających bazą danych DB2 Express, która również instaluje się razem z WSLE (ważne – DB2 nie może być zainstalowane wcześniej!)

Uwagi dotyczące tego użytkownika:

– w momencie odinstalowania Lombardi konto to nie zostaje usunięte więc np. próba kolejnej instalacji zakończy się błędem (należy najpierw usunąć użytkownika a dopiero potem instalować WSLE)

– procedura zmiany hasła dla tego użytkownika jest skomplikowana dlatego w razie potrzeby lepiej jest skorzystać z ustawień domyślnych:
login: WSLE
pass: L0mbard1#BPM

Update

W ostatnich tygodniach udało mi się:

– przeinstalować WebSphere Lombardi Edition 7.2

– przejść przez tutorial “1st successful build from scratch”

– przejść przez całą propozycję (ostateczna wersja jest jeszcze niedostępna) Proof Of Technology dla WSLE

– stworzyć WebService

– zintegrować stworzony WS z Lombardi

Dalsze działania obejmują sprawdzenie jak zachowuje się Lombardi z WS przy wykorzystaniu różnych typów zabezpieczeń.

Praktyki IBM ESI

Dwa tygodnie temu rozpocząłem praktyki w IBM z tematem Integracja Web Services w procesach biznesowych w WebSphere Lombardi Edition. Niniejszy blog, tworzony w postaci okresowych raportów, będzie stanowił zwięzły opis moich postępów.

Zadanie jakie sobie postawiłem do zrealizowania w tym tygodniu:

– Przeinstalowanie WLE do wersji 7.2
– Przejście przez tutorial “1st successful build”


Language / Język