Showing posts with label DRools. Show all posts
Showing posts with label DRools. Show all posts

Friday, May 6, 2011

jBPM 5 Tips

From jBoss advertisement (http://www.jboss.org/jbpm/components/core-engine.html):

- From a spring based web application for a grocery store on Tomcat over a top scale banking application to a plain standalone Java application.
- The jBPM engine can be used as a remote service.
- Simple API
- Human tasks
- Integrated with rules engine
- Transactional execution, timers and asynchronous continuations

Reality:

0. jBPM & Drools source code & documentation quality


- no comments in source code
- no Java API with any comments. (What do fireAllRuless() function while I start BPMN2 process?).

jBPM only:
- no developer documentation
- no typical deployment configurations (only Tomcal+hibernate. No typical GlassFish or JBoss configurations).
- no examples. Test cases only. Developer need read Drools documentation & source code for BPMN programming!
- absolutly unusefull API for Business Process Management. jBPM 5.0 have only API for Rules in simple drools-flow session, but it is nontrivial task to find active tasks for user "myuser" avtivity.
- no usefull remote API. Remote application can set tast "completed" or "aborted" but it cannot find tasks for execution! It must already now the Task ID for set it "completed", but without search! JBoss group said it is "Simple API" and "The jBPM engine can be used as a remote service." :)
- now any user authorithation internally (in source code)
- TCP port for MinaTaskServer "Human Task" without any authorithation. JBoss group said it is "top scale banking application" - ready :) Banks are welcome:)
- The community of previous versions of jBPM migrated from JBoss to Activiti fork project.

Guvner only:
- No any way to integrate with Subversion or other version control or build system for developers.


1. Experimental & unstable dependencies in "stable" releases.

jBPM 5.0 FINAL is based on Drool Flow and include drools, drools-flow 5.2.0.M1 (Milestome 1) library, with unfixed database bugs, etc. It is Drools/jBPM practice. It is fact.


2. Do you want to use JPA persistence?
- You need add persistence.xml + orm.cml to META-INF folder.
- You need catch exception ProcessInstancesWaitingForEvent, then use google, then find ProcessInstancesWaitingForEvent named query in GWT (http://community.jboss.org/thread/162854), then manually add ProcessInstancesWaitingForEvent named query to orm.xml.


ProcessInstancesWaitingForEvent named query:

<named-query name="ProcessInstancesWaitingForEvent">
<query>
select
    processInstanceInfo.processInstanceId
from
    ProcessInstanceInfo processInstanceInfo
where
    :type in elements(processInstanceInfo.eventTypes)
</query>
</named-query>


jBPM 5.0 Final user documentation said, for persistance:

StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(knowledgeBase, null, env);

It is not work with JPA, of course.
In reality (work example from jBPM JUnit test):

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

StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(knowledgeBase, config, env);



- For PostgreSQL, after Hibernate create database structure, developer must run database modification script to fix metadata bug:


ALTER TABLE sessioninfo DROP COLUMN rulesbytearray;
ALTER TABLE sessioninfo ADD COLUMN rulesbytearray bytea;


ALTER TABLE workiteminfo DROP COLUMN workitembytearray;
ALTER TABLE workiteminfo ADD COLUMN workitembytearray bytea;


There is same bug in processinstanceinfo table - processinstancebytearray column, but ORM mapping do not allow fix it by simple database modification.

So, yes! It is 5.0 FINAL version! :)

3. Do you want to use JBoss JPA?

- Use this persistence.xml configuration:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">


   <persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/jdbc/jbpmDS</jta-data-source>


    <class>org.drools.persistence.info.SessionInfo</class>
    <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
    <class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>
    <class>org.drools.persistence.info.WorkItemInfo</class>
    <class>org.jbpm.process.audit.ProcessInstanceLog</class>
    <class>org.jbpm.process.audit.NodeInstanceLog</class>
    <class>org.jbpm.process.audit.VariableInstanceLog</class>
   
    <class>org.jbpm.task.Attachment</class>
    <class>org.jbpm.task.Content</class>
    <class>org.jbpm.task.BooleanExpression</class>
    <class>org.jbpm.task.Comment</class>
    <class>org.jbpm.task.Deadline</class>
    <class>org.jbpm.task.Delegation</class>
    <class>org.jbpm.task.Escalation</class>
    <class>org.jbpm.task.Group</class>
    <class>org.jbpm.task.I18NText</class>
    <class>org.jbpm.task.Notification</class>
    <class>org.jbpm.task.EmailNotification</class>
    <class>org.jbpm.task.EmailNotificationHeader</class>
    <class>org.jbpm.task.PeopleAssignments</class>
    <class>org.jbpm.task.Reassignment</class>
    <class>org.jbpm.task.Status</class>
    <class>org.jbpm.task.SubTasksStrategy</class>
    <class>org.jbpm.task.Task</class>
    <class>org.jbpm.task.TaskData</class>
    <class>org.jbpm.task.OnParentAbortAllSubTasksEndStrategy</class>
    <class>org.jbpm.task.OnAllSubTasksEndParentEndStrategy</class>
    <class>org.jbpm.task.User</class>


      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.jdbc.batch_size" value="20"/>
         <property name="hibernate.default_schema" value="public"/>
         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
      </properties>
   </persistence-unit>
</persistence>




Still you want to use jBPM and DRools now?