Skip navigation
2011

Here is an example that shows how to register and use custom workitems in the JBPM5 console using example described in http://community.jboss.org/people/bpmn2user/blog/2011/02/21/jbpm5-example-for-forms-with-variables.

 

Diduch Cordova has modified the bpmn file from the above example to include a custom notification workitem (http://community.jboss.org/people/bpmn2user/blog/2011/02/21/jbpm5-example-for-forms-with-variables#/?page=2) . A custom WorkItem for notification ('Notify Complete) is added at the end as shown below.

 

 

ScreenHunter_12 Mar. 30 15.42.gif

 

Following is the corresponding notification WorkItemHaldler class.

ScreenHunter_11 Mar. 30 15.39.gif

 

 

More details about creating  WorkItem can be found here http://community.jboss.org/people/bpmn2user/blog/2011/03/28/jbpm5--work-itemdomain-specific-process-hello-process-example.

 

Make sure the corresponding taskName (i.e, Email) for the WorkItem in the bpmn file is bound to Notification class in the workhandlers configuration file (CustomWorkItemHandlers.conf)

ScreenHunter_13 Mar. 30 15.43.gif

 

ScreenHunter_10 Mar. 30 15.38.gif

 

Deployment to an appsersever (e.g., JBoss or Tomcat)

 

1.) Copy the configuration file (CustomWorkItemHandlers.conf) to gwt-console-server's META-INF directory

 

e.g. jbpm-installer/boss-5.1.0.GA/server/default/deploy/jbpm-gwt-console-server.war/WEB-INF/classes/META-INF/CustomWorkItemHandlers.conf

 

2.) Copy the Notification class to the gwt-console-server's CLASSPATH.

 

e.g., Copy the Notification jar file into gwt-console-server war file  ( ..gwt-console-server\WEB-INF\lib)

or Copy the Notification jar and the dependant jar files into appserver's lib direcory (JBOSS_HOME\server\default\lib for JBOSS or TOMCAT_HOME\lib for TOMCAT)

 

3.) Copy the bpmn file to the directory where the other bpmn files are located  (specified using the parameter -Djbpm.console.directory).

 

ScreenHunter_15 Mar. 30 15.57.gif

 

After running the example successfully (i.e, after the second approval from 'john'), following log message can be seen.

ScreenHunter_09 Mar. 30 15.34.gif

JBPM5 provides the flexibility to extend the default process constructs with domain-specific extensions.

Here is a simple example that shows the usage of  a custom workitem.

 

This custom extension feature provides the ability to create a service task, a generic way to interact with external services (e.g., JMS, Web service etc).

 

How to install and run this example?

Start with the setup as shown in http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in.

 

This example has a bpmn file that has the custom WorkItem(sample.bpmn), two WorkItem configurations files (CustomWorkItem.conf and drools.rulebase.conf), WorkItem implementation class (HelloProcessExtension.java) and test class (ProcessTest.java).

 

These files can be imported into a 'HelloProcess' project as shown below.

 

 

ScreenHunter_04 Mar. 27 22.34.gif

After running the test class 'ProcessTest.java', following results can be seen.

ScreenHunter_07 Mar. 27 23.24.gif

Here are the main steps involved in creating the custom WorkItem.

 

1.) Workitem definition: Create the definition of the workitem using properties that are name-value pairs in a file CustomWorkItem.conf.

 

import org.drools.process.core.datatype.impl.type.ObjectDataType;

import org.drools.process.core.datatype.impl.type.StringDataType;

 

[

  [

    "name" : "HelloProcessExtension",

     "icon" : "icons/action.gif",

    "displayName" : "HelloProcessExtension"

  ]

]

This definition file (CustomWorkItem.conf) is located in META-INF directory.

 

 

2.) WorkItem registration:

The definition of the workitem (CustomWorkItem.conf) needs to be registered in a project. It can be done by including the definition using the drools.WorkDefinitions property in a file drools.rulebase.conf in META-INF dircectory.

 

drools.workDefinitions = CustomWorkItem.conf WorkDefinitions.conf

 

3.) After creating a definition and registering the workitem, it will show up in designer. The Eclipse might need to be restarted after creating the configuration files in Step1 and Step2 (i.e, CustomWorkItem.conf and drools.rulebase.conf files in META-INF directory of the project)

The new workitem 'HelloProcessExtension' can be seen in 'Service Tasks' as shown below.

ScreenHunter_03 Mar. 27 22.34.gif

'HelloProcesExtension' node can be created inside the process using drag and drop.

 

4.) A WorkItemHandler implementation class needs to be created for the 'HelloProcessExtension' node.

 

ScreenHunter_05 Mar. 27 23.12.gif

5.) The WorkItemHandler should be registered at the WorkItemManager, using API as shown below (in ProcessTest.java)

ScreenHunter_06 Mar. 27 23.15.gif

This example shows the persistence feature of JBPM5 using Hello Proces example (http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in).

 

JBPM5 database persistence involves following categories:

 

1.) Process persistence: This involves persisting runtime state that represents current execution state in a specific context. The runtime state contains the minimal runtime state that is required to continue execution at a later time. This allows restoring the state of execution of all the running processes in the event of a failure.

 

2.) Human task persistence: Task management component, which is treated as a separate component, can persist all the task information (e.g, user, assignment etc) into database.

 

3.) History or Auditlog persistence: All the audit log information(e.g., ProcessInstanceLog, NodeInstanceLog etc)can stored in database for reporting purposes.

 

How to install and run this example?

Start with the setup as shown in http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in.

This example needs two jar files, one for database (e.g, h2.jar for H2, oracle-11.1.0.6.jar for Oracel etc) and another one Bitronix transaction manager (btm-1.3.3.jar). Add theste two jar files into Eclipse's project classpath.

ScreenHunter_03 Mar. 25 17.58.gif

 

This examples has a bpmn file (HelloProcess.bpmn), a process test program that starts the process(ProcessTest.java), a standalone task server (TaskServer.java), two persistence configuration files (orm.xml and persistence.xml ) and a Bitronix JNDI file ( jndi.properties) .

The persistence configuration files need to be included in META-INF folder as shown below. Please refer to JPA/Hibernate documents to know more about persistence configuration details.

 

ScreenHunter_01 Mar. 26 21.15.gif

 

 

 

 

After running the example successfully, tables for process, human task etc are created as shown below.

ScreenHunter_02 Mar. 26 21.20.gif

 

The task can be approved using the Eclipse  plugin. Select the plugin using Windows->ShowView->DRools Task->Human Task View.

ScreenHunter_02 Mar. 27 13.41.gif

 

The logging for Hibernate persistence is set to true to display the generated SQL queries as shown below.

Process logs from ProcessTest.java

 

ScreenHunter_03 Mar. 26 21.22.gif

Taskserver logs from TaskServer.java

ScreenHunter_04 Mar. 26 21.23.gif

 

 

 

Here are some important points to note:

Process persistence: It uses JPA/Hibernate as default to persist the runtime state. Create the knowledge session as shown below .

 

/*

     * Create EntityManagerFactory and register it in the environment

     * Create the knowledge session that uses JPA to persists runtime state

     */

 

    private static StatefulKnowledgeSession createKnowledgeSession(KnowledgeBase kbase) {

        EntityManagerFactory emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );

        Environment env = KnowledgeBaseFactory.newEnvironment();

        env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );

        env.set( EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager() );

        env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );

 

        Properties properties = new Properties();

        properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");

        properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");

        KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);

        return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);

 

    }

 

Persistence configuration file (persistence.xml) includes the classes that are required for process persistence.

ScreenHunter_07 Mar. 25 20.19.gif

 

Human task persistence has another independent persistencecomponent which is responsible for persisting task related activities (e.g.,task assignments, comments, content, notification etc)

 

 

The human task management component is an independent service which has communication with the process engine. This is started using 'TaskServer.java' class.

 

            EntityManagerFactory emfTask = Persistence.createEntityManagerFactory( "org.jbpm.task" );

            TaskService taskService = new TaskService(emfTask, SystemEventListenerFactory.getSystemEventListener());

 

           /* Start Mina server for HT*/

            MinaTaskServer server = new MinaTaskServer(taskService);

            Thread thread = new Thread(server);

            thread.start();

 

It is also required to have the corresponding human task classes in the Hibernate persistence configuration file (persistence.xml) as shown below.

 

 

 

ScreenHunter_08 Mar. 25 20.31.gif

 

History or Auditlog persistence: The persistence configuration file should also include the classes that correspond to audit logs.

 

ScreenHunter_09 Mar. 25 20.37.gif

Here is an example that shows how to use custom Java classes from the JBPM5 example described in http://community.jboss.org/people/bpmn2user/blog/2011/02/21/jbpm5-example-for-forms-with-variables.

 

Rajesh Chikhale has modified the bpmn file from the above example to access a custom Test class (http://community.jboss.org/people/bpmn2user/blog/2011/02/21/jbpm5-example-for-forms-with-variables#/?page=2) from 'Check Quantity' node.

 

 

It is typically required to access the custom application classes (e.g, read application model data, write to application database, include custom business logic etc) from a workflow application.

 

Here are two steps that are required to access the custom Test class from the BPM application.

 

1.) Access the custom class (com.sample.Test) from scipt node as shown in example below.

Make sure to include the fully-qualified Java class name (i.e, com.sample.Test) or include the package name using the 'imports' tab shown below.

ScreenHunter_01 Mar. 14 22.07.gif

2.) Create a jar for all the custom Java classes, e.g, com.sample.Test and copy the jar file into server's CLASSPATH. For example, it can be one of the options as shown below:

 

Copy the jar file into gwt-console-server war file  ( ..gwt-console-server\WEB-INF\lib)

or Copy the jar file into appserver's lib direcory (JBOSS_HOME\server\default\lib for JBOSS or TOMCAT_HOME\lib for TOMCAT)

Excel decision tables are widely used to represent rule logic in a compact format.

This format is particularly popular as non-technical business users can read, edit and maintain the conditional logic in Excel spreadsheets.

 

This example shows how to use an Excel decision table rules inside a process.

The ‘Rule Task’ components can use the rules defined in a drl file, Excel decision table or the rules defined in BRMS (Guvnor).

An example to use the rules defined in drl file is shown in http://community.jboss.org/people/bpmn2user/blog/2011/03/07/jbpm5--ruletask-example.

This example shows how to run the same example using Excel decision table.

 

Please refer to Drools documentation (http://downloads.jboss.com/drools/docs/5.1.1.34858.FINAL/drools-expert/html/ch05.html#d0e5683) to know about authoring Drools decision tables.

 

Here are rules represented in Excel decision table.

ScreenHunter_12 Mar. 07 18.25.gif

 

There are three rules in the following decision table. For example, Rule1 (Row 11) means that if the 'userlocation' is set to ‘NewYorkUser’ and the initial count is less 4, then the ‘loopcondition’ is set to 6.

 

Following is the main process flow diagram. This example has a loop condition which is determined using the rules shown in the above decision table in the RuleTask 'LoopConditionRules'.

 

 

ScreenHunter_03 Mar. 07 14.14.gif

'LoopConditionRules' is a 'Rule Task' component and it needs to have a valid RuleFlowGroup name (e.g.,  EvalLoopcondistion as shown below) and it should match with the 'RULEFLOW-GROUP' name (Column C) of the decision table.

 

ScreenHunter_04 Mar. 07 14.14.gif

Excel decision table needs to be added to the Knowledgebase as shown below.

 

private static KnowledgeBase readKnowledgeBase() throws Exception {

        ProcessBuilderFactory

                .setProcessBuilderFactoryService(new ProcessBuilderFactoryServiceImpl());

        ProcessMarshallerFactory

                .setProcessMarshallerFactoryService(new ProcessMarshallerFactoryServiceImpl());

        ProcessRuntimeFactory

                .setProcessRuntimeFactoryService(new ProcessRuntimeFactoryServiceImpl());

        BPMN2ProcessFactory

                .setBPMN2ProcessProvider(new BPMN2ProcessProviderImpl());

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory

                .newKnowledgeBuilder();

        kbuilder.add(ResourceFactory.newClassPathResource("processRuleslooptest777.bpmn"),

                ResourceType.BPMN2);

        /*

         * Add Excel decision table file

         */

 

        DecisionTableConfiguration config = KnowledgeBuilderFactory.newDecisionTableConfiguration();

        config.setInputType(DecisionTableInputType.XLS);

        kbuilder.add(ResourceFactory.newClassPathResource("LoopConditionRules.xls"), ResourceType.DTABLE, config);

 

        return kbuilder.newKnowledgeBase();

    }

 

How to deploy?

This example has a bpmn file (processRuleslooptest777.bpmn), model file (HelloProcessModel.java), rules file (LoopConditionRules.xls) and a test file (HelloProcessTest.java). It might be easy to start with a HelloProcess project (http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in) and import these files.

ScreenHunter_13 Mar. 07 19.30.gif

 

Following results can be seen after successfully running the example.

ScreenHunter_07 Mar. 07 14.18.gif

Here is an example that shows how to use 'Rule Task' component with a process.

A simple example shown in http://community.jboss.org/people/bpmn2user/blog/2011/03/01/jbpm5--loop-example is considered here to illustrate the feature.

 

This example has a loop condition which is determined using the rules based on the location of the user and the starting condition.

 

ScreenHunter_03 Mar. 07 14.14.gif

'LoopConditionRules' is a 'Rule Task' component and it needs to have a valid RuleFlowGroup name (e.g.,  EvalLoopcondistion as shown below).

 

ScreenHunter_04 Mar. 07 14.14.gif

The RuleFlowGroup set in the previous step has to match with the 'ruleflow-group' name in the 'drl' rules file as shown below.

 

 

ScreenHunter_05 Mar. 07 14.15.gif

 

Here is the sample test code to start the process after setting the initial parameters.

 

          // load up the knowledge base

            KnowledgeBase kbase = readKnowledgeBase();

            StatefulKnowledgeSession ksession = createSession(kbase);

            KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory

                    .newFileLogger(ksession, "test");

 

            // set the parameters

            Map<String, Object> params = new HashMap<String, Object>();

            HelloProcessModel hpm = new HelloProcessModel();

            hpm.setCount(new Integer("3"));

            hpm.setUserlocation("NewYorkUser");

            params.put("hpm", hpm);


            ksession.startProcess("looptest777",params);

 

            ksession.fireAllRules();

            logger.close();

 

Note that the 'drl' rules file needs to be added to the knowledgebase as shown below.

 

private static KnowledgeBase readKnowledgeBase() throws Exception {

        ProcessBuilderFactory

                .setProcessBuilderFactoryService(new ProcessBuilderFactoryServiceImpl());

        ProcessMarshallerFactory

                .setProcessMarshallerFactoryService(new ProcessMarshallerFactoryServiceImpl());

        ProcessRuntimeFactory

                .setProcessRuntimeFactoryService(new ProcessRuntimeFactoryServiceImpl());

        BPMN2ProcessFactory

                .setBPMN2ProcessProvider(new BPMN2ProcessProviderImpl());

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory

                .newKnowledgeBuilder();

        kbuilder.add(ResourceFactory.newClassPathResource("processRuleslooptest777.bpmn"),

                ResourceType.BPMN2);

        /*

         * Add drl file

         */

        kbuilder.add(ResourceFactory.newClassPathResource("LoopConditionRules.drl"), ResourceType.DRL);

        return kbuilder.newKnowledgeBase();

    }

 

How to run this example?

 

This example has a bpmn file (processRuleslooptest777.bpmn), model file (HelloProcessModel.java), rules file (LoopConditionRules.drl) and a test file (HelloProcessTest.java). It might be easy to start with a HelloProcess project (http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in) and import these files.

 

 

ScreenHunter_08 Mar. 07 14.43.gif

 

Following results can be seen after successfully running the example.

ScreenHunter_07 Mar. 07 14.18.gif

JBPM5 provides 'Multiple Instances' node that can be used to create multiple instances of reusable sub-processes.

 

Here is a simple example that shows how to send a colection of elements to sub-process nodes and invoke mutiple processes.

The example from the discussion http://community.jboss.org/thread/163105?tstart=0 is considered here to illustrate the usage.

 

 

It has a main process (sampleMultiLoopSubprocessTest.bpmn) that invokes multiple sub-processes (multilooptest777.bpmn).

The main process sends a list of parameters (initial count ) to the sub-process.

 

 

 

ScreenHunter_01 Mar. 05 15.53.gif

The sub-process goes through a loop incrementing the value of 'count'. Once the 'count' reaches the 'do until' loop condition value, it will exit the loop.

 

ScreenHunter_02 Mar. 05 15.54.gif

A list to contain the parameters that need to be sent to sub-processes are populated as shown below (MultiLoopProcessTest.java).

 

            Map<String, Object> params = new HashMap<String, Object>();

            List<Integer> myList = new ArrayList<Integer>();

 

            myList.add(process1Count);

            myList.add(process2Count);

            params.put("list", myList);

 

            ksession.startProcess("com.sample.bpmn.multilooptest",params);

 

The 'CollectionExpression' is set to 'list' as shown below,

 

ScreenHunter_03 Mar. 05 15.54.gif

The ProcessID is set to 'multilooptest777' as shown below to bind the sub-process.

ScreenHunter_04 Mar. 05 15.54.gif

 

How to run this example?

 

This example has two bpmn files (sampleMultiLoopSubprocessTest.bpmn for main process that invokes multiple processes and multilooptest777.bpmn for sub-process loop) and a test file (LoopSubProcessTest.java). It might be easy to start with a HelloProcess project (http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in) and import these files.

 

ScreenHunter_06 Mar. 05 20.55.gif

 

Following results can be seen after successfully running this example.

 

ScreenHunter_05 Mar. 05 15.55.gif

bpmn2user

JBPM5 - Loop Example

Posted by bpmn2user Mar 1, 2011

Here is an example that shows how to process a loop using JBPM5.

A simple example shown in the discussion http://community.jboss.org/thread/163105?tstart=0 is considered here.

This example has two parameters ‘count’ and ‘loopcondition’.

The paramter ‘count’ gets incremented in a loop until it is less than a ‘loopcondition’.

 

ScreenHunter_09 Mar. 01 09.41.gif

 

ScreenHunter_05 Mar. 01 20.34.gif

How to run this example?

 

This example has a bpmn file (looptest777.bpmn) and a test file (ProcessTest2.java). It might be easy to start with a HelloProcess project (http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in) and import these files.

 

ScreenHunter_03 Mar. 01 20.16.gif

 

Here is the sample test code. The main process ‘looptest777’  is started as shown below.

 

 

public static final void main(String[] args) {
  try {
   // load up the knowledge base
   KnowledgeBase kbase = readKnowledgeBase();
   StatefulKnowledgeSession ksession = createSession(kbase);
   KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
     .newFileLogger(ksession, "test");

   // set the parameters
   Map<String, Object> params = new HashMap<String, Object>();
   params.put("count", 1);
   params.put("loopcondition", 3);
  
   // start a new process instance
   ksession.startProcess("looptest777", params);
  
   logger.close();
  } catch (Throwable t) {
   t.printStackTrace();
  }
}

 

Following output can be seen after running the example.

ScreenHunter_04 Mar. 01 20.18.gif

Here is an example that shows how to invoke a sub-process from a main process.

A simple example shown in the discussion http://community.jboss.org/thread/163105?tstart=0 is considered here.

 

This example has a main process as shown below. It sends a couple of parameters (count and loopcondition) to the subprocess.

ScreenHunter_08 Mar. 01 09.41.gif

The sub-process goes through a loop incrementing the value of 'count'. Once the 'count' reaches the 'do until' loop condition value, it will exit the loop and return the 'count' value to the main process. The 'loopcondition' can either be set inside this sub-process or can be retrieved from the parent process. In this example, it is set as a paramter in the main process.

ScreenHunter_09 Mar. 01 09.41.gif

How to run this example?

 

This example has two bpmn files (sampleLoopTest.bpmn for main process and looptest777.bpmn for sub-process loop) and a test file (LoopSubProcessTest.java). It might be easy to start with a HelloProcess project (http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in) and import these files.

ScreenHunter_01 Mar. 01 11.47.gif

 

 

Here is the sample test code. The main process 'com.sample.bpmn.looptest'  is started as shown below which inturn invokes the sub-process.

 

public class LoopSubProcessTest {

 

   public static final void main(String[] args) {

        try {

            // load up the knowledge base

            KnowledgeBase kbase = readKnowledgeBase();

            StatefulKnowledgeSession ksession = createSession(kbase);

            KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory

                    .newFileLogger(ksession, "test");

 

            // Set the initial count and loopcondition

            Map<String, Object> params = new HashMap<String, Object>();

            params.put("count", 1);

            params.put("loopcondition", 4);

 

            //start the main process

            ksession.startProcess("com.sample.bpmn.looptest", params);

 

            logger.close();

        } catch (Throwable t) {

            t.printStackTrace();

        }

    }

It is important to note that both the bpmn files need to be added to the KnowledgeBuilder as shown below.

 

IScreenHunter_11 Mar. 01 09.44.gif

 

 

Here are the results you would see after running the test program LoopSubProcessTest.

ScreenHunter_10 Mar. 01 09.44.gif

Filter Blog

By date:
By tag: