Integration Vaadin and Activiti BPM by Spring framework

In some of my project in the past I remembered that in order to do a business flow we need to do it manually in the coding level so that it gives your project  risk when you are managing  big project since business process in the organization might change during your software development and for sure it is not good for your development.

Finally, I found a simple tools called JBoss BPM 3.0 on that time, This tools was so good and useful helping the software designer integrating the business process defined by the business with the application code. Playing with the BPM is so fun. Lately, I found an application called Activiti BPM. Put some hand on it for several days give me a lot of fun. Since then I use this BPM as my base engine to manage the process management. I think it is time to share some basic after 1 years worked on it.

I will explain the very basic configuration to integrate Vaadin and Activiti with spring framework.

1. Setup your eclipse and Jboss AS configuration

2. Setup a Vaadin project from Maven

3. Configure your web.xml as below to enable the spring bean injection

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 id="WebApp_ID" version="2.5">
 <display-name>Vaadin Web Application</display-name>
 <context-param>
 <description>Vaadin production mode</description>
 <param-name>productionMode</param-name>
 <param-value>false</param-value>
 </context-param>

<context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>/WEB-INF/applicationContext-spring.xml</param-value>
</context-param>
<listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
 <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<servlet>
 <servlet-name>Vaadin Application Servlet</servlet-name>
 <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
 <init-param>
 <description>Vaadin application class to start</description>
 <param-name>application</param-name>
 <param-value>study.ActivitiExclusive.MyVaadinApplication</param-value>
 </init-param>
 </servlet>
 <servlet-mapping>
 <servlet-name>Vaadin Application Servlet</servlet-name>
 <url-pattern>/*</url-pattern>
 </servlet-mapping>
</web-app>

2. Configure the applicationContext-spring.xml to manage the activiti bean creation and database connection

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
 http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
 <context:spring-configured />
 <context:annotation-config />

<context:component-scan base-package="study.ActivitiExclusive" />
 <bean id="dataSource"
 class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
 <property name="targetDataSource">
 <bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
 <property name="url" value="jdbc:mysql://localhost:3306/activiti" />
 <property name="driverClass" value="com.mysql.jdbc.Driver" />
 <property name="username" value="root" />
 <property name="password" value="*****" />
 </bean>
 </property>
 </bean>

<bean id="transactionManager"
 class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
 <property name="dataSource" ref="dataSource" />
 </bean>

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
 <property name="databaseType" value="mysql" />
 <property name="dataSource" ref="dataSource" />
 <property name="transactionManager" ref="transactionManager" />
 <property name="databaseSchemaUpdate" value="true" />
 <property name="history" value="full" />
 <property name="jobExecutorActivate" value="false" />
 <property name="deploymentResources" value="/WEB-INF/MyProcess.bpmn" />

</bean>

<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
 <property name="processEngineConfiguration" ref="processEngineConfiguration" />
 </bean>

<bean id="repositoryService" factory-bean="processEngine"
 factory-method="getRepositoryService" />
 <bean id="runtimeService" factory-bean="processEngine"
 factory-method="getRuntimeService" />
 <bean id="taskService" factory-bean="processEngine"
 factory-method="getTaskService" />
 <bean id="historyService" factory-bean="processEngine"
 factory-method="getHistoryService" />
 <bean id="managementService" factory-bean="processEngine"
 factory-method="getManagementService" />
 <bean id="identityService" factory-bean="processEngine"
 factory-method="getIdentityService" />

<bean id="Printing" class="study.ActivitiExclusive.Printing" />

</beans>

 

3. Configure your maven POM to enable the all library completed

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>study</groupId>
 <artifactId>ActivitiExclusive</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>
 <name>Vaadin Web Application</name>

<properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <vaadin.version>6.8.4</vaadin.version>
 <gwt.version>2.3.0</gwt.version>
 <gwt.plugin.version>2.2.0</gwt.plugin.version>
 </properties>

<build>
 <plugins>
 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-compiler-plugin</artifactId>
 <configuration>
 <source>1.5</source>
 <target>1.5</target>
 </configuration>
 </plugin>
 </plugins>
 </build>

<repositories>
 <repository>
 <id>vaadin-snapshots</id>
 <url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
 <releases>
 <enabled>false</enabled>
 </releases>
 <snapshots>
 <enabled>true</enabled>
 </snapshots>
 </repository>
 <repository>
 <id>vaadin-addons</id>
 <url>http://maven.vaadin.com/vaadin-addons</url>
 </repository>
 <repository>
 <id>activiti</id>
 <name>Activiti Repository</name>
 <url>https://maven.alfresco.com/nexus/content/repositories/activiti/</url>
 </repository>
 </repositories>

<dependencies>
 <dependency>
 <groupId>com.vaadin</groupId>
 <artifactId>vaadin</artifactId>
 <version>${vaadin.version}</version>
 </dependency>
 <dependency>
 <groupId>org.aspectj</groupId>
 <artifactId>aspectjrt</artifactId>
 <version>1.7.0</version>
 </dependency>
 <dependency>
 <groupId>org.aspectj</groupId>
 <artifactId>aspectjweaver</artifactId>
 <version>1.7.0</version>
 </dependency>
 <dependency>
 <groupId>org.activiti</groupId>
 <artifactId>activiti-engine</artifactId>
 <version>5.10</version>
 </dependency>

<dependency>
 <groupId>org.activiti</groupId>
 <artifactId>activiti-spring</artifactId>
 <version>5.10</version>
 </dependency>
 <dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <version>5.1.21</version>
 </dependency>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-aspects</artifactId>
 <version>3.1.2.RELEASE</version>
 </dependency>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-webmvc</artifactId>
 <version>3.1.2.RELEASE</version>
 </dependency>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-core</artifactId>
 <version>3.1.2.RELEASE</version>
 </dependency>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-beans</artifactId>
 <version>3.1.2.RELEASE</version>
 </dependency>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-context</artifactId>
 <version>3.1.2.RELEASE</version>
 </dependency>
 <dependency>
 <groupId>log4j</groupId>
 <artifactId>log4j</artifactId>
 <version>1.2.17</version>
 </dependency>
 <dependency>
 <groupId>org.apache.tomcat</groupId>
 <artifactId>jsp-api</artifactId>
 <version>6.0.35</version>
 </dependency>
 </dependencies>

</project>

5. Create a simple activiti BPM as a sample “MyProcess.BPMN” in the WEB-INF directory

 

 

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
 <process id="process1" name="process1">
 <startEvent id="startevent1" name="Start"></startEvent>
 <userTask id="usertask1" name="Approve"></userTask>
 <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
 <endEvent id="endevent1" name="End"></endEvent>
 <serviceTask id="servicetask1" name="Service Task" activiti:expression="#{Printing.printMessage()}" ></serviceTask>
 <sequenceFlow id="flow2" name="" sourceRef="usertask1" targetRef="servicetask1"></sequenceFlow>
 <userTask id="usertask2" name="Makan2"></userTask>
 <sequenceFlow id="flow3" name="" sourceRef="servicetask1" targetRef="usertask2"></sequenceFlow>
 <endEvent id="endevent2" name="End"></endEvent>
 <sequenceFlow id="flow4" name="" sourceRef="usertask2" targetRef="endevent2"></sequenceFlow>
 </process>
 <bpmndi:BPMNDiagram id="BPMNDiagram_process1">
 <bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1">
 <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
 <omgdc:Bounds height="35" width="35" x="170" y="40"></omgdc:Bounds>
 </bpmndi:BPMNShape>
 <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
 <omgdc:Bounds height="55" width="105" x="140" y="210"></omgdc:Bounds>
 </bpmndi:BPMNShape>
 <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
 <omgdc:Bounds height="35" width="35" x="460" y="220"></omgdc:Bounds>
 </bpmndi:BPMNShape>
 <bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
 <omgdc:Bounds height="55" width="105" x="300" y="210"></omgdc:Bounds>
 </bpmndi:BPMNShape>
 <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
 <omgdc:Bounds height="55" width="105" x="460" y="210"></omgdc:Bounds>
 </bpmndi:BPMNShape>
 <bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
 <omgdc:Bounds height="35" width="35" x="620" y="220"></omgdc:Bounds>
 </bpmndi:BPMNShape>
 <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
 <omgdi:waypoint x="187" y="75"></omgdi:waypoint>
 <omgdi:waypoint x="192" y="210"></omgdi:waypoint>
 </bpmndi:BPMNEdge>
 <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
 <omgdi:waypoint x="245" y="237"></omgdi:waypoint>
 <omgdi:waypoint x="300" y="237"></omgdi:waypoint>
 </bpmndi:BPMNEdge>
 <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
 <omgdi:waypoint x="405" y="237"></omgdi:waypoint>
 <omgdi:waypoint x="460" y="237"></omgdi:waypoint>
 </bpmndi:BPMNEdge>
 <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
 <omgdi:waypoint x="565" y="237"></omgdi:waypoint>
 <omgdi:waypoint x="620" y="237"></omgdi:waypoint>
 </bpmndi:BPMNEdge>
 </bpmndi:BPMNPlane>
 </bpmndi:BPMNDiagram>
</definitions>

 

6. Finally in the application  I can autowire all the necessary activity bean from the spring context. (Please refer on how to create the injection for vaadin in my previous article)

package study.ActivitiExclusive;
import org.activiti.engine.IdentityService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;

import com.vaadin.ui.Window;

public class MyWindow extends Window {

@Autowired
 RepositoryService repositoryService;

@Autowired
 RuntimeService runtimeService;

@Autowired
 TaskService taskService;

@Autowired
 IdentityService identityService;
 public MyWindow() {

 Inject.Inject(this);
 }

}

 

7. Yeah just follow the configuration above then you can start playing Activiti BPM with Vaadin. In the above configuration don’t forget that you should have configure your Mysql database with the specified schema and DB.

 

Have a nice try all …

11 thoughts on “Integration Vaadin and Activiti BPM by Spring framework

    1. Hi,
      Thanks for the comment. I think it is good to follow the steps given so that you can get the experience. If you have problem on setting up the integration just send me your question..

      1. Thanks for reply.

        Application running correctly but not showing any thing in the page, showing only blank page.

      2. Hi Bhimanna, The application is showing nothing in this tutorial as you can see in the MyWindow class is doing nothing except autowiring all the required fields to work with activity. Try to check either the field autowired is null or not. if the autowire is not null then you have done it. But dont create the check in the constructor, you should check after the class fully created.

  1. Hello…
    Thanks a lot for guide. It helps a lot. I have follow each n every steps but still getting following error..

    IOException parsing XML document from ServletContext resource [/WEB_INF/applicationContext-spring.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB_INF/applicationContext-spring.xml]

    I searched on net to resolve this exception but didn’t get over it.
    Please help me. I am not getting where i am going wrong.

    applicationContext-spring.xml file is present in WEB_INF.

    n I have created Vaadin project from Maven.

    Please help. I am a fresher.

    1. Hi Minakshi,

      This error was caused by the statement of this in web.xml. the context tried to find the spring configuration in the “/WEB-INF/applicationContext-spring.xml”

      contextConfigLocation
      /WEB-INF/applicationContext-spring.xml

      First check. Ensure the “applicationContext-spring.xml” is available in the specified folder.

      Second check. Ensure the file name spelling is correct as specified in the web.xml

  2. Hello,
    I m integrating the Activiti BPM with Vaadin 7. Here I have a simple BPM diagram which have only one service task. At the end of this service task, I want to change the vaadin view screen ( like getUI.getNavigator().navigateTo(“OtherUI”)).

    My question is – how to change the view from completion of service task? 🙂

    1. Hi Ashutosh,

      Thanks for writting comments on my blogs. Basically service task is an async background job which call a delegated java class. To wait this service task done you can create a receiving task for the service task. Vaadin application will wait at this point (try to create a thread for waiting). This thread which will be the UI navigator trigger. I’m sorry cannot give you any sample code but only the concept.

  3. Hello
    Thanks a lot for guide …
    I m integrating the Activiti with Vaadin
    but when i use the RepositoryService or (other @Autowired) i have an error: java.lang.NullPointerException …
    plz help
    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s