piątek, 15 czerwca 2018

jBPM 7.8 native execution of BPMN2, DMN 1.1 and CMMN 1.1

with upcoming 7.8 release of jBPM there is quite nice thing to announce - native execution of:

  • BPMN2 - was there already for many years
  • DMN 1.1 - from the early days of version 7
  • CMMN 1.1 - comes with version 7.8

The biggest thing coming with 7.8 is actually CMMN execution. It is mainly added for completeness of the execution so people who would like to model case with CMMN can actually execute that directly on jBPM (via KIE Server or embedded).

Although jBPM supports now CMMN, it is still recommended to use BPMN2 and case management features of jBPM for advanced cases to benefit from features that both specification brings rather to be limited to particular approach. Nevertheless CMMN can be a good visualisation for less complex cases where data and loosely coupled activities can build a good business view.

Disclaimer: jBPM currently does not provide nor plans to provide any modelling capabilities for CMMN.

With that said let's take a quick look at what is supported from the CMMN specification as obviously it's not covering 100% of the spec.

  • tasks (human task, process task, decision task, case task)
  • discretionary tasks (same as above)
  • stages
  • milestones
  • case file items
  • sentries (both entry and exit)
Not all attributes of tasks are supported - required, repeat and manual activation are currently not supported. Although most of the behaviour can still be achieved using different constructs.
Sentries for individual tasks are limited to entry criteria while entry and exit are supported for stages and milestones.

Decision task by default maps to DMN decision although ruleflow group based is also possible with simplified syntax - decisionRef should be set to ruleflow-group attribute.

Event listeners are not supported as they do not bring much value for execution and instead CaseEventListener support in jBPM should be used as substitute.

Let's have a quick look at how the sample Order IT case would look like designed in CMMN


some might say it's less or more readable and frankly speaking it's just a matter of preferences.

Here is a screencast showing this CMMN model being executed 


Next I'd like to show the true power of jBPM - execution of all three types of models:
  • CMMN for top level case definition
  • DMN for decision service
  • BPMN2 for process execution
you can add all of them into kjar (via import asset in workbench) build, deploy from workbench directly to KIE Server and execute. So here are our assets

A case definition that has:
  • decision task that invokes DMN decision that calculates vacation days (Total Vacation Days)
  • two human tasks that are triggered based on the data (entry criterion)
  • process task that invokes BPMN2 process if the entry condition is met


Here is our DMN model


and last but not least is the BPMN2 process (actually the most simple one but still a valid process)



Another thing to mention is that, all the models where done with Tristotech Editors to illustrate that they can be simply created with another tool and imported into kjar for execution.


Here is another screencast showing this all step by step, from exporting from Tristotech, importing into workbench, building and deploying kjar and lastly execute on KIE Server.


That's all to share for now, 7.8 is just around the corner so keep your eyes open and visit jbpm.org to learn more.

And at the end here are the links to the projects (kjars) in github


Enjoy!

środa, 13 czerwca 2018

single zip distribution for jBPM

To simplify getting started experience for users I'd like to showcase a single zip distribution that includes:

  • WildFly server (at the moment version 11.0.0.Final)
  • workbench (aka jbpm console)
  • kie server with all capabilities enabled
  • jBPM case management show case application

All of them are perfectly configured and ready to run with just single and short command:
./stanalone.sh
or on windows
standalone.bat

The only thing user needs to do is download, unzip and run!

But that's not all that comes with this single zip distribution - it comes with very handy scripts that allow to switch to different databases as easy as just one click.
There are three databases supported out of the box:
  • H2 - default with file based data base stored under WILDFLY_HOME/standalone/data
  • MySQL
  • PostgreSQL
MySQL and PostgreSQL must be installed before use. Moreover the scripts assume following values:

  • host -> localhost
  • port -> 3306 for MySQL and 5432 for PostgreSQL
  • database name -> jbpm
  • user name -> jbpm
  • password -> jbpm
in case the values are not correct, edit them in the script files 
  • jbpm-mysql-config.cli for MySQL 
  • jbpm-postgres-config.cli for PostgreSQL 
in both scripts values to be updated are on line 17 and these are located under WILDFLY_HOME/bin.

To switch to MySQL stop the server and use following command when server is stopped
<WILDFLY_HOME>/bin/jboss-cli.sh --file=jbpm-mysql-config.cli           (Unix / Linux)

<WILDFLY_HOME>\bin\jboss-cli.bat --file=jbpm-mysql-config.cli     (Windows)

To switch to PostgreSQL stop the server and  use following command when server is stopped
<WILDFLY_HOME>/bin/jboss-cli.sh --file=jbpm-postgres-config.cli      (Unix / Linux)

<WILDFLY_HOME>\bin\jboss-cli.bat --file=jbpm-postgres-config.cli     (Windows)

next, start the server again and all your data will be stored in external database.

All this in action can be seen in this "not so short" screencast


As usual feedback welcome and please share your opinion if you'd like to see this in the official distribution of jBPM.

For those that would like to give it a go directly here is the project - just clone it and build locally - in case you want to use another version of jBPM change property named kie.version to the version number you want to use.

poniedziałek, 21 maja 2018

Contract Net Protocol with jBPM

jBPM provides lots of capabilities that could be used out of the box to build rather sophisticated solutions. In this article I'd like to show one of them - Contract Net Protocol.

Contract Net Protocol (CNP) is a task-sharing protocol in multi-agent systems, consisting of a collection of nodes or software agents that form the 'contract net'. Each node on the network can, at different times or for different tasks, be a manager or a contractor. [1]

This concepts nicely fits into case management capabilities of jBPM 7. It allows to easily model interaction between Initiator and Participant(s).

source http://www.fipa.org/specs/fipa00029/SC00029H.html#_ftnref1
Contract can be announced to many participants (aka bidders) that can either be interested in the contract and then bid or simply reject it and leave the contract net completely.

with jBPM 7, contract net can be modelled as a case definition where individual phases of the protocol can be externalised to processes to carry on with additional work. This improves readability and at the same time promotes reusability of the implementation.


Announce contract and Offer contract are separate processes that can be implemented separately according to needs. For this basic showcase they are based on human decision and look as follows

Each of the participants of the contract net will have dedicated instance of the announce contract process. Each should make the decision if they will place a bid or not. In case they won't do it at all, main contract net case definition keeps a timer event on them to remove given bidder if the deadline was reached.

As soon as all bidders replied (or time for reply elapsed) there are set of business rules that will evaluate all provided bids and select only one. Once it is selected an Offer contract subprocess will be initiated - after milestone of selecting a bid is completed.


So the bidder who placed the selected bid will get the "Work on contract" task assigned to actually perform the work. Once done the worker indicates if the work was done or she failed at doing the work. In case of successful completion of the work additional business rules are invoked to verify it.

Completion of the work (assuming it was done) will show the results of the work to the initiator for final verification. Once the results are reviewed the contract is ended - by that case instance is ready to be closed.

All this in action can be seen in the following screencast




Again, this is just basic implementation but shows the potential that can be unleashed to build advanced Contract Net Protocol solutions.

Complete project that can be easily imported into workbench and executed in KIE server can be found here.

To start the case instance you can use following payload that includes data (both contract and bidders) and case role assignments

{
    "case-data": 
    {
        "contract": 
        {
            "Contract": 
            {
                "name" : "jBPM contract",
                "description" : "provide development expertise for jBPM project",
                "price" : 1234.40
            }
        },
        "bidders": [
        {
            "Bidder": 
            {
                "id" : "maciek",
                "name" : "Maciej Swiderski",
                "email" : "maciek@email.com"   
            }
        },
        {
            "Bidder": 
            {
                "id" : "john",
                "name" : "John doe",
                "email" : "john@email.com"   
            }
        }
        ]
    },

    "case-user-assignments": 
    {
        "Initiator": "mary",
        "Participant": "john"
    },

    "case-group-assignments": 
    {
        
    }
}

If you need more bidders just add them by copying the single bidder in the payload

[1] Source - https://en.wikipedia.org/wiki/Contract_Net_Protocol

wtorek, 24 kwietnia 2018

jBPM Work Items repository tips + tricks

In his previous post, Maciej showcased the updates to the jBPM Work Items module and how easy it is now to get up and running with creating new workitems and start using them in your business processes right away.

In this post I wanted to leverage on what Maciej showed and add a couple of cool features that the jBPM Work Item repository gives you out of the box, specifically related to the repository content generation.

1. Skinning
By default the work item repository generates static content including all workitem info, documentation and download links. Here is what they look like out of the box:

1. Default repository index page

2. Default workitem documentation page

Using the default look/feel is fine, but there are cases you might want to change it to fit your company/business better by changing the colors, adding your logo, or even completely change the layout of these pages and here is how you can do it. 

The jBPM work items module includes a sub-module called template-resources. In this module you can find all related templates that are used to build your final repository content. Lets take a look at these files to find out what each dose:

a) repoheader.html and repofooter.html - responsible for the top and bottom part of your repository index page. You can change these to for example define different page colors, add your logo to it, etc. Whatever you feel like. 
b) repoindex.part- defines each workitem information (each table row on the repository index page). You can change this to change the display for each of your workitems, add/remove download links etc.
c) indextemplate.st - this is a StringTemplate file that is used by each workitem module to generate its documentation page. Again you have free reign to change the look/feel of your workitem documentation as you wish.

With little knowledge of html (and power of jQuery and Boostrap that are built in) you can customize your workitem repository, for example (I'm not a designer btw :):

3) "Skinned" workitem repository index page

2. Excluding workitems from generated repository content
By default all workitems in the jBPM work items module will be displayed in the generated repository. You may not want to expose all of the available ones to your clients and can control which ones you wish to expose via the repository Maven assembly descriptor.
Here in the dependencySet section you can define excludes on the workitems you do not wish to display. Let's say you do not want to show the Archive and Dropbox workitems, you would do:

<excludes>
  <exclude>${project.groupId}:repository-springboot</exclude>
  <exclude>${project.groupId}:archive-workitem</exclude>
  <exclude>${project.groupId}:dropbox-workitem</exclude>
</excludes>

and those will not show up in the generated repository content any more. 
3. Generating additional download content using workitem handler information
By default each workitem in the repository might have one or more handler implementations. Each handler describes itself via the @Wid annotation, here is an example handler for sending Twitter messages.  During compilation step of your handlers repository gathers the info from this annotations and uses it to generate the workitem defintion configuration, the json config, the deployment descriptor xml, etc etc. You may want to generate additional configuration files that currently do not exist. 
This can be configured in the main project's pom.xml file. Here you can add more or remove existing config files generated from the annotation information in your workitem handlers.
I hope this info will be of some help to you guys. As always if there are any questions or if you have ideas on how to further enhance the workitem repository feel free to ask. 








poniedziałek, 23 kwietnia 2018

jBPM Work Items are really simple!

Work items are the way to build custom (domain specific) services that can be used from within a process. They are as any other activity in the process with the difference that they are usually focused on given domain or area.


Work Items are by default placed under Service Tasks category on the palette so can be easily drag and dropped into the canvas when designing processes and cases. Location on the palette is also configurable via category property of the work item definition. So let's have a guided tour on how to create a very simple but functional work item.

The complete process consists of following steps:

  • generating maven project for work item (both definition and handler)
  • implementing handler and configuring work item
  • optionally provide custom icon (16x16)
  • add work item project into service repository
  • import work item into project in workbench

Let's get our hands dirty and implement simple work item and then use it in a process.

Generate work item maven project

First step is to generate maven project that will be our base for:
  • work item definition
  • work item handler
First things first, what is work item definition and what is work item handler?
Work Item definition is a description of the work to be done. That is usually described by unique name, description, to make it more visible on the diagram - an icon and then what is expected at the entry (data inputs - parameters) and what is expected at the exit (data output - results).

Work Item handler is a logic that will be actually executed when given activity (representing work item) will be triggered as part of the process instance execution. 

Work Item is then a runtime representation of the Work Item definition that is backed by Work Item handler that is registered in the process engine via Work Item name. This registration gives users additional flexibility to allow usage of different logic to be executed depending where the process is executed - test vs production environment.

So to generate a maven project use maven archetype

mvn archetype:generate \
-DarchetypeGroupId=org.jbpm \
-DarchetypeArtifactId=jbpm-workitems-archetype \
-DarchetypeVersion=7.8.0-SNAPSHOT \
-DgroupId=org.jbpm.contrib \
-DartifactId=custom-workitem \
-DclassPrefix=Custom \
-Dversion=7.8.0-SNAPSHOT \
-DarchetypeCatalog=local

This command will generate a new project with:

  • groupId - org.jbpm.contrib
  • artifactId - custom-workitem
  • version - 7.8.0-SNAPSHOT
  • with work item configuration and handler class custom-workitem/src/main/java/org/jbpm/contrib/CustomWorkItemHandler.java

I'd like to recommend to generate this project as part of the official jbpm-work-items repository to benefit from service repository included in there. The rest of the article will assume this has been done. 
If you haven't done it yet, follow these:

  • clone github project: https://github.com/kiegroup/jbpm-work-items
  • go into jbpm-work-items
  • check the version number of the cloned project and adjust version argument accordingly in the maven archetype:generate command

Once the project is generated, import it into your IDE and implement the handler - CustomWorkItemHandler.java. You might need to add additional dependencies to your project, depending your the implementation - when doing so please keep following in mind:
  • dependencies that are already included in KIE Server - mark them as provided
  • check for any conflicts with application server, KIE Server and your app dependencies and resolve them - either by adjusting your handler project dependencies or runtime environment
CustomWorkItemHandler.java class consists of @Wid annotation that is actually responsible for configuring your work item definition. It allows you to define (to name just few):
  • name
  • description
  • category
  • icon
  • input parameters
  • results
  • handler
Most of the important parts are already generated for you, so examine them and check for correctness. Most likely parameters and results will be the one most often changed when implementing handlers.

Once that is done, proceed with implementation of the executeWorkItem method which is the heart of your custom work item.

Expose your work item in Service Repository

Now to take advantage of repository generation of jbpm-work-items project you need to add your newly generated project into two pom files:

  • main pom.xml file of jbpm-work-items project - one regular and one zip dependency
  • <dependency>
            <groupId>org.jbpm.contrib</groupId>
            <artifactId>custom-workitem</artifactId>
            <version>${project.version}</version>
          </dependency>
          <dependency>
            <groupId>org.jbpm.contrib</groupId>
            <artifactId>custom-workitem</artifactId>
            <version>${project.version}</version>
            <type>zip</type>
          </dependency>
    
  • repository/pom.xml - only zip dependency (but this time without the version tag)
  • <dependency>
          <groupId>org.jbpm.contrib</groupId>
          <artifactId>custom-workitem</artifactId>
          <type>zip</type>
        </dependency>
    


When you're finished just build the project (assuming you're in jbpm-work-items repository) use following:

mvn clean install -DskipTests -rf :custom-workitem

this will then build your project (custom-work item - adjust it if the artifactId is different) and repositories. Then if you start SpringBoot based Service Repository

java -jar repository-springboot/target/repository-springboot-7.8.0-SNAPSHOT.jar

you'll have your work item available there, just go to http://localhost:8090/repository

And that's it, you have your work item implemented, built and exposed via Service Repository!!!


Use work item in workbench

To make use of your newly created work item, login to workbench and:

  • create project
  • create asset - Business Process
  • use the yellow repository icon in the designer menu to open service repository browser
  • select work item and install it
  • reopen process editor and you'll find your installed work item under Service Tasks category (unless you changed the category when implementing work item)

That's all you need, in the background when the work item was installed your project was modified to add:
  • dependency to your work item jar (as maven dependency of your workbench's project)
  • deployment descriptor to register work item handler 
So now you're ready to launch it - just build and deploy your project in workbench and enjoy your work item being executed.

All this in single screen cast can be found below



Data set editor for KIE Server custom queries

Custom queries feature in KIE Server has been out for quite a while and proved to be very useful. Although there was no integration with workbench to take advantage of when:

  • working with subset of data from various tables that are not exposed via runtime views (processes or tasks)
  • building data set entries for reporting purpose
  • building dashboards

With version 7.8, jBPM is now equipped with data set editor for KIE Server custom queries, it allows users to:
  • define (as data set) and test queries on remote KIE Servers
  • save and edit existing data sets 
  • use defined data sets when building dashboards via Pages feature of workbench

Moreover, data set editor for KIE Server queries is built in a way that it ensures that queries are always send to all known kie servers when using managed mode. New KIE Servers connecting to controller (workbench) will also receive custom queries defined via data set editor.

See all this in action in short screencast



As usual, comments are more than welcome

środa, 28 lutego 2018

React to SLA violations in cases

As a follow up article for Track your processes and activities with SLA here is a short addon for case management. You can already track your SLA violations for cases, processes and activities but there is more to it.
jBPM 7.7 comes with out of the box support for automatic handling of SLA violations:

  • notification to case instance owner
  • escalation to administrator of case instance
  • starting another process instance as part of the case instance
With this you can easily enhance your cases with additional capabilities that will make sure your personnel is aware of the SLA violations. It can become crucial to make sure your customers are satisfied and you won't mis any targets.

Let's quickly dig into details of each of the mechanisms
As described in previous post, SLA violations are delivered via event listener (ProcessEventListener). 

Notification to case instance owner

Notification is of email type. It will essentially create a dynamic Email task so to make this work you need to register EmailWorkItemHandler via deployment descriptor.

It's implemented by org.jbpm.casemgmt.impl.wih.NotifyOwnerSLAViolationListener class and supports following parameters to be given (as part of its constructor):
  • subject - email subject that will be used for emails
  • body - email body that will be used for emails
  • template - email body template that should be used when preparing body
node that template parameter will override body when given. See this article for more information about email templates and this one for using Email task.

You can use default values as well by simply using the default constructor when registering listener in deployment descriptor.

Email addresses are retrieved via UserInfo for users assigned to role "owner" of the case. If there are no such role or no assigned users this event listener will silently skip any notifications.

Escalation to administrator of case instance

Escalation to admin means that whoever is assigned to role admin in given case instance will get assigned new user task (regardless if admin case role has assigned users or groups).
Similar to notification, this is done via dynamic user task that is "injected" into case instance. Depending if the escalation is for case instance SLA violation or particular activity, administrator will see slightly different task name and description to help him/her identify the failing element.

It's implemented by org.jbpm.casemgmt.impl.wih.EscalateToAdminSLAViolationListener class.

Starting another process instance as part of the case instance

Another type of automatic reaction to SLA violation is starting another process instance (of given process id) to handle SLA violation. This usually applies to more complex scenarios where handling can be multi step or requires many actors to be involved.

It's implemented by org.jbpm.casemgmt.impl.wih.StartProcessSLAViolationListener class. This class requires a single parameter to be given when registering it and that is process id of the process that should be started upon SLA violations.


These are basic ways of handling SLA violations and their main purpose is to illustrate how users can plug their own mechanism to deal with this kind of situations. Users can:
  • create their own listeners
  • extend existing listeners (e.g. with notification one, you can just override the method responsible for building map of parameters for Email task)
  • combine both
  • compose listeners and take decisions which one to used based on the content of the SLAViolationEvent
  • or anything else you find useful

Last but not least have a look how easy it is to extend our Order IT hardware case with SLA tracking and automatic escalation to administrator.



Stay tuned and let us know what you think!