RSS

Category Archives: JBPM

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);
 }


@Override
 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>());
 facts.add(output);
 ksession.execute(facts);
 manager.completeWorkItem(workItem.getId(), output.getDataMap());
 }
 }

Then, just assigned the task to this WorkItemHandler:


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

And created the rule:

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

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

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:
https://github.com/calcacuervo/JBPM5-Samples/tree/master/test-rules

Feel free to ask any question/suggestion!

Thanks for reading!

Demian

Advertisement
 
2 Comments

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!

Demian

 
1 Comment

Posted by on May 25, 2011 in Drools, JBPM

 

Tags:

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!
Demian
 
5 Comments

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!

Now.. HOW CAN I MAKE A CENTRALIZED INTERFACE FOR MY HUMAN TASKS?

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:

https://github.com/Salaboy/smart-tasks

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: https://github.com/calcacuervo/HumanTaskExamples

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!

Demian

References

http://incubator.apache.org/hise/WS-HumanTask_v1.pdf

http://publib.boulder.ibm.com/infocenter/dmndhelp/v6rxmx/topic/com.ibm.wbit.help.tel.ui.doc/topics/cundht.html

http://www.theenterprisearchitect.eu/archive/2007/04/11/SOA_and_Human_Interaction

http://is.tm.tue.nl/staff/wvdaalst/BPMcenter/reports/2007/BPM-07-10.pdf

 
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:
http://tinyurl.com/3ugrmgw

I will work with an open source project called Drools (http://www.jboss.org/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!

Demian

 
4 Comments

Posted by on April 17, 2011 in Drools, JBPM