How To use pluggable process variable persistence with Case Files in jBPM 7

Some times we need to persist case file which includes business information into different database table along with processInstanceId so that you can map business information with particular processInstanceId.  We can achieve this with below steps:

  • Define custom data object,define it as Entity and make sure to extend VariableEntity
    and must implement a Serializable interface, which look like as
  • In kie-workbench, goto Project settings-->Persistence and add custom entity(com.Shippment) and 'org.drools.persistence.jpa.marshaller.MappedVariable' under persistable data object, like as
  • Note down the persistence unit name from the top of the screen and update
    the datasource JNDI and hibernate dialect if needed
  • In kie-workbench,  goto Project->Settings->Deployments->Marshalling Strategie and define the following marshaling strategy which is required for case file persistence 
    • new org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy("persistenceUnitName", classLoader);
  • Create a case file variable in case  definition of type 'com.Shippment'
  • Start case instance with the following payload
    • Java
       




      x
      10


      1
       {
      2
        "case-data" : {
      3
      "shippment": {
      4
      "com.Shippment":{
      5
      "shippmentId": 1234,
      6
       "shippmentDestination":"IN"
      7
      } } },
      8
       "case-user-assignments" : {  },
      9
        "case-group-assignments" : { }}
      10
      
                    


  • In database schema you can see two tables with name 'Shippment' and 'MappedVariable'. Entries in these tables look like as
    • Java
       




      x


       
      1
      ysql> select * from Shippment;
      2
      +----+------------+---------------------+
      3
      | id |shippmentId |shippmentDestination |
      4
      +----+------------+---------------------+
      5
      |  1 | 1234       |         IN          |
      6
      |  2 | 4321       |         IN          |
      7
      +----+------------+---------------------+
      8
      2 rows in set (0.00 sec)
      9
      
                    
      10
      
                    
      11
      
                    
      12
      mysql> mysql> select * from MappedVariable;
      13
      +-------------+-------------------+--------+------------+--------------+---------+------------+------------+
      14
      | mappedVarId | processInstanceId | taskId | variableId | variableType | OPTLOCK | workItemId | MAP_VAR_ID |
      15
      +-------------+-------------------+--------+------------+--------------+---------+------------+------------+
      16
      |           1 |                14 |     19 |          1 | com.Shippment |       0 |         28 |          1 |
      17
      |           2 |                15 |     20 |          2 | com.Shippment |       0 |         29 |          2 |
      18
      +-------------+-------------------+--------+------------+--------------+---------+------------+------------+
      19
      2 rows in set (0.00 sec)


How to Attach a Document to BPMN Process In jBPM 7

Multiple times we have to attach docuemnt to BPMN process which is part of process execution or if its required to perform HumanTask operation. Here are the steps for attaching Document to BPMN process in jBPM 7. 

  • In the kie-workbench, in project settings goto  deployment-descriptor file(kie-deployment-descriptor.xml)  and define the marshalling strategy for document
    • XML
       




      xxxxxxxxxx
      1


      1
      <marshalling-strategies>
      2
        <marshalling-strategy>
      3
        <resolver>mvel</resolver>
      4
        <identifier>new  org.jbpm.document.marshalling.DocumentCollectionImplMarshallingStrategy(new org.jbpm.document.marshalling.DocumentMarshallingStrategy())</identifier>
      5
         <parameters/>
      6
         </marshalling-strategy>
      7
      </marshalling-strategies>


  • Define process variable of type org.jbpm.document.DocumentCollection.

'DocumentCollectionImplMarshallingStrategy' and process variable of type 'org.jbpm.document.DocumentCollection'  support use of multiple documents in BPMN process, i.e at a time you can upload multiple documents while starting process/case execution or while performing task operation. For single document, we can use process variable of type 'org.jbpm.document.Document' with marshalling strategy 'org.jbpm.document.marshalling.DocumentMarshallingStrategy'.   

Using Pluggable HumanTask Assignment Strategy in jBPM 7

jBPM 7 release provides logic to find the best suitable user to assign the task. Multiple assignment strategies are supported in this release,

  • Potential owner busyness strategy (default)
  • Business Rules Strategy
  • RoundRobin Strategy

1. Potential Owner Busyness Strategy:

This strategy makes sure that the least loaded user from the potential owner list will be selected as task owner. To make this strategy work effectively we need to provide groups of the users.It can be done by using UserInfo configured in the environment. To load user group details we can use org.jbpm.ht.userinfo option while server startup. We can load user and group mapping from DB or from LDAP. We can load user group details from the file as well.We have to create a file with a name jbpm.user.info.properties in the application classpath.