On Enter and On Exit Node actions in jBPM5

Hi Everyone, I am back to the blog!

Today I will try to show a quite new feature of jbpm5, which are On Enter and On Exit node actions. As its name indicates, these are actions which will be executed after or before the execution of a node. This is a quite frequently needed feature, that is not included in BPMN 2.0 specification, so now there is a way to include these actions.

There is an example of it in jBPM 5 github:

Now I want to show something similar, but a more real situation were it was very helpful to use it for me.

In Emergency Services, we needed to make some processing on the result variables of a human task. It was not a trivial assignment that it could done (at least I did not see how) with the assignment expressions of the output mappings. Something like this should be done with the variables:

emergency.addUpdate(vehicle.getId(), new VehicleUpdate(comment, priority));

So we made it with an On Exit Node action. These actions are similar to script nodes, and we can get information about the process and also about the node from the kcontext.

We have a node

<userTask id="_12-2-4" name="Update Situation" >

Which has two data output variables,

<dataOutput id="_12-2-4_commentOutput" name="comment" />
<dataOutput id="_12-2-4_priorityOutput" name="priority" />

And also some input variables,

<dataInput id="_12-2-4_emergencyInput" name="emergency" />
<dataInput id="_12-2-4_vehicleInput" name="vehicle" />

Now, we added a On Exit Node action to make our desired processing,

 <tns:onExit-script scriptFormat="">
 Emergency em = (Emergency)((WorkItemNodeInstance)kcontext.getNodeInstance()).getWorkItem().getParameter("emergency");
 Vehicle vehicle = (Vehicle)((WorkItemNodeInstance)kcontext.getNodeInstance()).getWorkItem().getParameter("vehicle");
 String comment = (String)((WorkItemNodeInstance)kcontext.getNodeInstance()).getWorkItem().getResult("comment");
 Integer priority = (Integer)((WorkItemNodeInstance)kcontext.getNodeInstance()).getWorkItem().getResult("priority");
 emergency.addUpdate(vehicle.getId(), new VehicleUpdate(comment, priority));

After the human task node is finished, this script will be executed. As you can see, in kcontext we have access to process, with kcontext.getProcessInstance(), process variables with kcontext.getVariable() and also to node instance and the work itam with kcontext.getNodeInstance().

The full bpmn can be found at

You can also take a look at Emergency Services project source, where you will have lot of Jbpm and Drools examples. Hope this example helps you! Follow us @calcacuervo, @salaboy and @ilesteban.


Leave a comment

Posted by on September 3, 2011 in Drools



Drools and jBPM5 Open Training @London – August 8th/9th

Hi everyone,

Plugtree is going to organize an open training session, that will focus in Drools Expert and jBPM5, and also covering Drools Fusion. It is open to everyone who wants to learn about these projects, no matter if you have previous experience using them or not, as will it cover these technologies essential concepts as well as best practices and project internals.

You can check esteban and salaboy posts for more details, and also the event registration page.



Leave a comment

Posted by on July 18, 2011 in Drools


Tags: , , , , , , ,

Simple rules in my process with a stateless session

I’m back! I have been a bit busy at work. I traveled to BA to attend to the JBPM5/Drools Workshop where the leads of the project gave some excellent presentations. It was great, I was able to meet many of them, discover what’s being done currently and listen about interesting projects (such as Drools Chance, Drools Planner), that I didn’t have time to check yet.

This week I was trying to make rules work JBPM5 when using a persistence and transactions. This was a bit complicated, specially because when calling ksession.fireUntilHalt(), it will create another thread that will work with this session, and was always failing when the fire until halt thread was trying to commit the session. This will be another post, as I could not solve it all yet :).

Anyway, I realized that I only wanted to make a simple evaluation, that will produce a result that will be used to take a decision. And it seemed a work for an StatelessSession that simply evaluates some of the workflow parameters and put the results in the process instance.

So I made a simple workitem, which will have a KnowledgeStatelessSession and will evaluate the rules:

public class StatelessRuleEvaluationWorkItemHandler implements WorkItemHandler {

private StatelessKnowledgeSession ksession;
 public StatelessRuleEvaluationWorkItemHandler(KnowledgeBase kbase) {
 ksession = kbase.newStatelessKnowledgeSession();
 new WorkingMemoryConsoleLogger(ksession);

 public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
 List<Object> facts = new ArrayList<Object>();
 facts.add(new DataInput(workItem.getParameters()));
 DataOutput output = new DataOutput(new HashMap<String, Object>());
 manager.completeWorkItem(workItem.getId(), output.getDataMap());

Then, just assigned the task to this WorkItemHandler:

 "ExceedsRule", new StatelessRuleEvaluationWorkItemHandler(ksession.getKnowledgeBase()));

And created the rule:

rule "Exceeds"
$input: DataInput(dataMap["limit"] < dataMap["count"])
$output: DataOutput()
$output.getDataMap().put("exceeds", new Boolean(true));

rule "NotExceeds"
$input: DataInput(dataMap["limit"] >= dataMap["count"])
$output: DataOutput()
$output.getDataMap().put("exceeds", new Boolean(false));

And it worked fine, the rule was executed, the variable was used in the next node, and there were no problems with persistence. For simple rules, this example can definitely help!

You can check the full example here:

Feel free to ask any question/suggestion!

Thanks for reading!



Posted by on June 29, 2011 in JBPM


Drools & Jbpm will be present in Argentina

As Mark announced in his post, the Drools Core Team will be present in Buenos Aires, Argentina, in a two days workshop in the middle of June. It is a great opportunity to actually from people who are actually implementing Drools/JBPM5, and has the whole picture and concepts about these technologies.

I will assist and will try to learn a lot, and I hope many people from Argentina and South America can also be there to have a great time!

See you there!


1 Comment

Posted by on May 25, 2011 in Drools, JBPM



Using Variables in JBPM5 Human Tasks

I have been playing a bit with processes and human tasks, and I want to show how we can share variables between human tasks in Jbpm5.

Let’s see the following process:

There are three human tasks which may have input/output:

  • Write document: Should produce an output that should contain a document which will be used by the rest of the process.
  • Translate Document: Should take the “Write document” output to show to the user for reference, and produce an output that will contain the translated document.
  • Review Document: Should take the “Write document” output to show to the user for reference, and produce an output that will contain the review of this document.
First, let’s deal with the write document output.
In the .bpmn file, we will add a new item definition, which will define the structure and a name for this structure, and  then declare a variable inside our process:
Ok, now we should define the variable inside the “Write document” task, and bind it with this process property:
Results will be the name of the variable inside the task.
– In dataOutputAssociation we put the value of the Results to the approval.document variable.
Now, let’s use this variable as an input of “Translate Document”. We will use the already filled approval.document variable, and declare it as a parameter for the task.
Please note for the input variable, I used “Content” name variable. If you see the workitem for human tasks in jbpm5, its takes some predefined parameters and sends them to the task server, so the input information should be put in Content input. Edit: after a salaboy commit some time ago, now, the input of the task will be get from the “content” variable. If you want to send many separate variables, you can omit (send it blank) the content variable, and add other variables. If the human task work item handler  does not find anything in content variable, it will send a map with all the task variables as input.
The complete process definition can be found here:
Now, how can I use it from my human task?
To get the input, using the TaskClient and having the TaskSummary is possible:
To send the output:
The full example can be found in my examples github repository:
That’s all for now. Hope it helps.
Thanks for reading!

Posted by on May 6, 2011 in Drools, JBPM


Tags: , ,

Human Tasks in my process

Although we are living in a world where systems have replaced many human tasks, processes usually need humans to complete tasks in order to achieve some goal, so it is interesting to investigate a bit how these human tasks can be integrated into systems.

Imagine a very simple process for document writing process, defined like this:

In this case, we have three human tasks to be performed by three different people (or groups of people):

  • The person who writes the document.
  • The person who translates the document.
  • The person who review the original document.

In order to finish the document writing process, these three tasks must be finished by the correct people.

There is a specification for human tasks, WS-HumanTask, which standardize not also the notation and meanings, but the way to interact with a human task service. I won’t go in details with the spec, you can check the link in reference, but let’s see some concepts behind it:

Task Data

– A task has data that comes with its definition itself, such as name, description, etc.

– A task has runtime data about its execution, such as its state.

– A task has runtime information about the task definition itself. This data should help the person to complete the task. In the document writing example, the tasks “Review Document” and “Translate Document” has as input a document that has to be used to perform the task.

– A task produces output data, that will give some information about what happened in this task, and also can provide information to the system. For example. In the document writing example, the task “Write Document” produces a document to be used in the rest of the process.

User Roles

There are some roles that are important in the life-cycle of a task. Not only the person who actually performs the task is important, as there can be another actors such as the person who initiates the task, the potential and actual owner, the administrator and notification recipients are some of the roles which could be identified in a task.

Task Interface

To interact with tasks, it is good to have some interfaces to coordinate the task executions, giving enough visibility and functionality. Some needed interfaces could be:

  • Task List. An interface where a user can see all the tasks that has assigned, where a summary of the task is displayed.
  • Task details, where the user can check more details information of a task, with task input data, status, and more.
  • Operate the task. It means a way to start, complete, suspend, the task. It mean, make the task go through its state until finish it.

Task States

The task has different states that change when some operation is made to it. For example, in WS-HumanTask spec, the state diagram for a task is defined like this:

That is just an overview, now we can check some examples!


An interface for human task could like this:

Some interface to select a user (or maybe login), and get some profile for UI customization.

Another interface that should be present is the task list for the user.

And finally the task operation interface, to interact with a selected task.

I have made this example, which let us interact with tasks in a UI pages. The example uses smart task project:

Which allows the interaction between the UI and the task repository, abstracting this job from the producer vendor of the task (can be JBPM, Activiti, I will show an example in another post) and also providing a mechanism to define the configuration of how the information will be shown in the page, defining different profiles and customizations. For now, it does not have support to execute tasks, that’s why in my example I use a simple task client to execute them.

The example can be found here:

For now, it has three projects:

  • human-task-server-example. It is a Jbpm 5 human task server which exposes services to interact with services. Run it with mvn exec:java.
  • human-task-client-example. Run it with mvn exec:java. This is a sample client, which has the possibility to:

Start the writing document sample process.

Complete tasks to finish the process

  • human-task-web-ui-example. This is a web application, run it with mvn jetty:run. There we can:

List all tasks of a user

Get details, form and actions of each task

It only shows how to show the UI, so the actions are not executed.

That’s it for now, I will continue working with this projects and put in this blog things that may be interesting. Please let me know any suggestion, correction or just a hello!

Thanks for reading!



1 Comment

Posted by on May 5, 2011 in Drools, JBPM


Tags: , ,

Hello world!

Hello All!

Today I am opening this place, which will be my notebook from now on.

I have been working as a software developer for many years, mostly in Java, and have worked with many interesting technologies. Now, my career is changing, and I am about to start working with Plugtree team. I am really exited about that! The idea of this space is to share my research, development and ideas, so it can help other people.

I will start working with rules and processes. These topics have a lot to read, give opinions, research and share. Let’s check it:

I will work with an open source project called Drools ( Its homepage describes Drools 5 as:

Drools 5 introduces the Business Logic integration Platform which provides a unified and integrated platform for Rules, Workflow and Event Processing. It’s been designed from the ground up so that each aspect is a first class citizen, with no compromises.

It has many modules:

  • Guvnor: It is a repository for rules, which allows to manage them in a rich web GUI.
  • Expert: A business rule engine. It has a language to define the rules, and a way to evaluate facts with these rules.
  • Jbpm 5: Originally was named Drools Flow. It a Business Process Management Suite. It uses latest BPMN 2.0 specification
  • Fusion: An event processing module.
  • Planner: Module for planning problems.

These modules interacts to deliver a full integration business platform.

This is an small overview, and I will go deeper in next posts.

In this Blog you will find:

  • Tutorials with examples I implement during my work.
  • Ideas: Hope I can have many of them!
  • Research about specific topics.
  • Reviews about some article I read.
  • Anything that I feel important to share.

Please feel free to leave any comment, corrections or ideas, that will help me and the community, to grow.

Thanks for reading me, see you soon again!



Posted by on April 17, 2011 in Drools, JBPM