Apr 04

After deploying a new process I sure that you would like to run it ;)

It’s easy. First of all, you must create a new process instance:

        jbpmContext = jbpmConfiguration.createJbpmContext();
        processInstance = jbpmContext.newProcessInstance("processname");

Then you can initialize it by adding some variables to the process:

        contextInstance = processInstance.getContextInstance();
	contextInstance.setVariable("var", myVar);

To start it you have to send a signal to the process first token :

	processInstance.getRootToken().signal();

		

Related Posts

Mar 14

jBPM Task node

jBPM task nodes are designed to interact with users. The main utility of this kind of nodes is to treat forms data. When a process arrives to a task node, it waits until the required actor makes an action.

Task nodes are the most complex nodes, you will have to implement two handlers: one to assign the task to an actor and another to define this task.

Lets start with the AssignmentHandler.

Using Eclipse interface you can setup your task node as it follows, specifying where is your class.

jBPM AssignmentHandler

ExampleAssign must be something like that:

public class ExampleAssign implements AssignmentHandler{
....
}

Implementing this interface means that you will have to develop an assign method.

public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception;

Inside this function you will need to assign the current task(assignable) to somebody using assignable.setActorId(actor).

The responsibility of this method does not finish here. When you came into a task node, you will have to save all process state and variables to stop the process. You can not assume that the actor will be waiting for the assignment and neither you will want to wait until he logins into the application. System must continue running normally.

Calling this two functions you will save the execution context into database using Hibernate.

executionContext.getJbpmContext().save(executionContext.getTaskInstance());
executionContext.getJbpmContext().close();

Next step is to configure and develop a task controller.

jBPM task controller config

This class must look like this:

public class ControlExample implements TaskControllerHandler{
...
}

It must implement this two methods:

public void initializeTaskVariables(TaskInstance taskInstance, ContextInstance contextInstance, Token token);
public void submitTaskVariables(TaskInstance taskInstance, ContextInstance contextInstance, Token token);

First one is used to initialize task variables, you can set default values or whatever you need.

Second one treat all task variables. This is the main function of the task nodes. Remember to invoke token.signal(); when all treatment is done.

Thats all, but you will be wondering how does it work, how can I wake up the sleeping process…

Somewhere in your program, in a from treatment function or in a button event, for example, you will have to make some extra work. You will need to identify the user and the process instance. Functions like:

 List l = jbpmContext.getTaskMgmtSession().findTaskInstances(user);

will help you. When you have the correct TaskInstance you will have to invoke ti.end();. This function will wake up the process and the associated state from database using Hibernate and call submitTaskVariables(). Workflow will continue normally at this point.

Thats all I wanted to explain of jBPM nodes. I’m not normally using Fork and Join nodes in my projects, so I will not write a guide for them. They are very easy to include in your workflows but if somebody ask for it, I will write a mini how-to.

Related Posts

Feb 15

jBPM mail node

jBPM mail nodes are simple nodes designed only to send mails. This time you don’t have to implement any handler or function, jBPM libraries provide nearly all you need.

In mail info tab you can set the destination e-mail address, the subject and the mail body that is going to send. This will be useful when you know destination e-mail address, orders@mycompany.com, for instance.

If you need to send mails to workflow actors, you can set a user variable in context:

executionContext.setVariable("user", workflowActor);

and configure mail info as it follows:

jBPM mail info

jBPM address resolver will check for user e-mail address from database and send him the mail, you will have to do nothing!

This is a great node but I had some requirements that it didn’t provide to me, so I re-implemented it, adding some new methods.

You can download new implementation here.

Now I can send mails using a gmail account. To explain it in a simple way, my implementation read some extra parameters from jbpm.cfg.xml file before sending the mail.

  <string name="jbpm.mail.smtp.host" value="smtp.gmail.com" />
  <bean   name="jbpm.mail.address.resolver" class="org.jbpm.identity.mail.IdentityAddressResolver" singleton="true" />
  <string name="jbpm.mail.from.address" value="yourMail@gmail.com" />
  <string name="jbpm.mail.user" value="yourUser@gmail.com" />
  <string name="jbpm.mail.pass" value="yourPassword" />
  <string name="jbpm.mail.port" value="465" />
  <string name="jbpm.mail.smtp.socketFactory.port" value="465" />
  <string name="jbpm.mail.smtp.socketFactory.class" value="javax.net.ssl.SSLSocketFactory" />
  <string name="jbpm.mail.smtp.auth" value="true" />
  <string name="jbpm.mail.smtp.starttls.enable" value="true" />
  <string name="jbpm.mail.debug" value="true" />
  <string name="jbpm.mail.smtp.socketFactory.fallback" value="false" />
  <string name="jbpm.mail.advanced.config" value="true" />
  <string name='mail.class.name' value='FastSign.mail.Mail' />

If jbpm.mail.advanced.config is set to false it works as the original mail node. Setting it to true, activates the extra parameters. In this case, 465 is gmail port, I suppose you can change it to use other system. Note that you have to define mail.class.name with the correct package.

I hope this will be useful.

Related Posts

Feb 14

Decision node

jBPM decision nodes are very useful to create some alternative path along the workflow. The implementation of this node will choose the correct way.

Decision node example

To program these kind of nodes I prefer to develop a DecisionHandler rather than using an expression.

public class Validacion implements DecisionHandler{
....
}

Implement a decide method is mandatory:

public String decide(ExecutionContext executionContext) throws Exception;

Among this function code lines you can query database, consult session or recover variables from execution context:

executionContext.getVariable("previouslySetVariable");

This function must return a String containing the name of the transition to choose.

As the other nodes, you must configure the handler class with the node using Eclipse interface.

Decision node configuration

Related Posts

Feb 14

jBPM node

jBPM simple nodes are the most common nodes in all processes. They are used to encapsulate an action of your workflow.

The easiest way to program these kind of nodes is to develop an ActionHandler . You must do something like this:

public class Example implements ActionHandler{
.......
}

Developing ActionHandler interfaces involves to implement an execute method:

public void execute(ExecutionContext executionContext) throws Exception;

Inside this function you can add all code you need to perform the desired action. Remember that you have to send a signal to navigate to the next node at the end of execution.

executionContext.getProcessInstance().signal();

Finally, using Eclipse interface you have to link you node with you handler.

Action

At Action menu you must check Configure Action (your node must be selected). Inside Details tab you will be able to select and configure your class.

jBPM node Details

As easy as you read.

Related Posts

Nov 23

This semester I’m studying a subject called Network Project where we study the principles behind the design, configuration and evaluation of computer network applications, protocols and specific formats for use on the Internet.

As a final project we have to build a system using several network technologies such XML, Ajax, SOAP or RMI. We decided to develop contract signing portal to give support to businessmen.

To build a big system like that in a record time we are going to use frameworks to make our workload lighter. JBoss jBPM is one of them.

jBPM includes an Eclipse plug-in to model business processes. You can specify the work-flow of you processes using a drag&drop interface, adding nodes and transition in a very simple way.

jBPM designer

Eclipse automatically creates an XML file that defines the process. You can deploy this file to your application and jBPM work-flow engine controls its execution. This engine includes tools like Hibernate to manage persistence and state of the process and log4j for system logging.

jBPM also includes a tool for monitoring the execution of your business processes so you can control your company.

In my opinion this is an excellent middleware for integration of enterprise applications. It makes easy all the development to the programmer and offers great advantages to CEO’s and other members on the board.

Related Posts

Nov 23

This post is a how-to with the necessary steps to install jBPM 3.2.2 on a Apache Tomcat 5.5 and MySQL 5.0.

  1. Create schema and table in database
    In this example a schema 'jbpm' with a user 'jboss' is used.
    Generate all jBPM tables using the script jbpm.jpdl.mysql.sql. If you want your users/roles information (the identity components) also from the MySQL db, use the second sql script attached here mysql.identity.script.jbpm321.sql to set up the necessary tables and fill them with the demo values.
  2. Prepare your jBPM archive
    1. Open a console in jbpm-jpdl-3.2.2/deploy and run:
      ant customize.console.for.tomcat
    2. This builds a jbpm-console.war in jbpm-jpdl-3.2.2/deploy/customized
    3. Unzip this file and change jbpm-console/WEB-INF/classes/hibernate.cfg.xml to reflect the following changes:
      <hibernate-configuration>
        <session-factory>
      
          <!-- hibernate dialect -->
          <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
      
          <!-- JDBC connection properties (begin) -->
          <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
          <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jbpm</property>
          <property name="hibernate.connection.username">jboss</property>
          <property name="hibernate.connection.password">jboss</property>
           <!-- JDBC connection properties (end) -->
      
          <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
      
          <!-- DataSource properties (begin) ==
          <property name="hibernate.connection.datasource">java:/JbpmDS</property>
          == DataSource properties (end) -->
          <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
      ...
    4. Note that the following line is commented:
          <property name="hibernate.connection.datasource">java:/JbpmDS</property>
    5. Extract el-api.jar and el-ri.jar from the original war file (jbpm-console.war/WEB-INF/lib) to jbpm-console/WEB-INF/lib
    6. Copy jboss-j2ee.jar and commons-collections.jar to jbpm-console/WEB-INF/lib. You can find these files in jbpm-jpdl-3.2.2/server/server/jbpm/lib
    7. Download mysql jdbc driver from MySQL Home Page and move it to $TOMCAT_HOME/common/lib
    8. Zip jbpm-console to a war file and move it to $TOMCAT_HOME/webapps
  3. Setup a JDBC Realm in Tomcat
    Create a file jbpm-console.xml in /$CATALINA_HOME/conf/Catalina/localhost similar to
<Context>
<Realm  className="org.apache.catalina.realm.JDBCRealm"
	driverName="com.mysql.jdbc.Driver"
	connectionURL="jdbc:mysql://localhost:3306/jbpm"
	connectionName="jboss"
	connectionPassword="jboss"
	userTable="JBPM_ID_USER u, JBPM_ID_MEMBERSHIP m, JBPM_ID_GROUP g"
	userNameCol="g.TYPE_ = 'security-role' AND m.GROUP_ = g.ID_ AND m.USER_ = u.ID_ AND u.NAME_"
	userCredCol="DISTINCT u.PASSWORD_"
	userRoleTable="JBPM_ID_USER u, JBPM_ID_MEMBERSHIP m, JBPM_ID_GROUP g"
	roleNameCol="g.NAME_" />
</Context>

Now you should be able to run jBPM default web app in Tomcat.

jBPM Console

This how-to is a resume and an adaptation of JBoss.com Wiki. Sql scripts are also the same of the original page.

Related Posts