Professional Documents
Culture Documents
BonitaSoft Custom Application Development PDF
BonitaSoft Custom Application Development PDF
1. Introduction
Bonita Open Solution is a 3-in-1 suite composed of: Bonita Studio, an integrated process-based application builder based on BPMN2 modeling and drag-and-drop form customization, Bonita Execution Engine, a powerful and scalable BPM engine, and Bonita User Experience, a breakthrough end-user interface.
Creating applications with Bonita Open Solution is easy with the help of Bonita Web Application Builder which dramatically reduces the need for coding. But sometimes developers may want to break away from Bonita end-user technology either to create highly customized interfaces - using for example a different framework than GWT (Google Web Toolkit) used in Bonita User Experience - or embed Bonita Execution Engine in even more complex applications, which is possible through the use of Bonita Execution Engine APIs. Bonita Execution Engine - also referred as Runtime in this paper - was designed to provide a lot of flexibility through service injection. It is a completely configurable engine using an XML file called environment. This configuration describes all services used. You can change all of them or replace them with your own implementation. In addition, Bonita Execution Engine is non-intrusive, meaning that it requires only Java. You can install it in any JVM of your choice, in any web/JEE container or use it as a simple Java library. Another remarkable feature of Bonita Execution Engine is that it supports for command injection, allowing you to create your own operations in the Runtime.
Free download on www.bonitasoft.com BonitaSoft, 2010
uuid name label description version state deployedBy deployedDate undeployedBy undeployedDate
ProcessDefinition also contains a set of other entities: e.g. datafields, participants, activities, attachments, metadata. The most used entities are: activities, datafields and participants. All major elements in the Definition object model have the following fields in common:
All objects which are children of ProcessDefinition also have direct access to the parent process uuid. A ProcessDefinition can be in one of the three following states:
enabled: the process is in the runtime repository and can be instantiated disabled: the process is in the runtime repository and cannot be instantiated (i.e. suspended) archived: the process is no longer in the runtime repository. It has been moved to the history repository and can no longer be instantiated.
BonitaSoft, 2010
activities variables attachments involvedUsers variableUpdates (history of all variables assignments during the process instance life) stateUpdates (history of all states assignments during the process instance life)
The most used entities are: activities and variables. A few explanations about activities There are two types of activities. Automatic activities do not require a human contribution. Manual activities require a human contribution. The Runtime object model makes the distinction between these by using inheritance. Automatic activities are of type ActivityInstance. Human activities are of type TaskInstance. A TaskInstance is an ActivityInstance with additional information. A ProcessInstance can be in one of the following states:
started: the process instance is started and currently executing (some activities still have to be done) finished: the process instance has reached the end and is finished canceled: an admin user has manually canceled this instance and it can no longer be executed aborted: an internal error has aborted this instance and it can no longer be executed
BonitaSoft, 2010
DRAW your processes CONNECT to your systems RUN in one clic 3. Using APIs
Bonita Execution Engine provides a very useful feature related to environment management. This feature ensures that your application is not dependent on the target deployment architecture. You can develop your application inside a simple web container and then deploy it on a JEE server without modifying your Java code. This is automatically done through AccessorUtil capabilities. AccessorUtil (org.ow2.bonita.util.AccessorUtil) is the main entry point to Bonita Execution Engine APIs. Using this utility class, you can get access to all available APIs. Bonita Execution Engine provides different APIs organized by the following concepts: ManagementAPI operations related to process installation/removal, resources/filters management. e.g. deploy(businessArchive), deleteProcess(processUUID), addMetadata(key, value)
QueryDefinitionAPI query operations related to the Definition object model. These operations do not modify the persisted objects. e.g. getProcesses(), getProcess(processUUID), getProcessActivities(processUUID, activityName)
RuntimeAPI modification operations related to the Runtime object model. These operations modify the persisted objects. e.g. executeTask(taskUUID), assignTask(taskUUID, userId), instantiateProcess(processUUID), setProcessInstanceVariable(processInstanceUUID, variableName, variableValue), deleteProcessInstance(processInstanceUUID)
QueryRuntimeAPI Query operations related to the Runtime object model. These operations do not modify the persisted objects. e.g. getProcessInstances(), getActivityInstance(activityInstanceUUID), getTaskList(taskState), getVariable(activityInstanceUUID, variableName), getProcessInstanceVariable(processInstanceUUID, variableName)
BonitaSoft, 2010
CommandAPI operations to execute commands available in a given process or in the overall engine e.g. execute(command, processUUID), execute(command)
IdentityAPI operations related to embedded user module e.g. addUser(userName, password), addRole(roleName), getUsers(), getUsersInRole(roleName)
BAMAPI query operations to retrieve statistics from the runtime data e.g. getNumberOfOverdueSteps(), getNumberOfOpenSteps(), getNumberOfOpenStepsPerDay(startDate)
BonitaSoft, 2010
Java standard logging property: -Djava.util.logging.config.file=<absolute path to your logging.properties> (one logging.properties is provided in the distribution) Java standard security configuration (JAAS): java.security.auth.login.config=<absolute path to your jaas configuration file> (some configurations are provided in the distribution for local and JEE deployments) Bonita API type access: org.ow2.bonita.api-type (only used if Bonita Runtime is not in the same JVM as this Client) Java standard JEE naming properties: -Djava.naming.factory.initial and Djava.naming.provider.url
BonitaSoft, 2010
5. Using EJBs
Bonita Execution Engine distribution contains an ear folder. In this folder, all necessary artifacts are provided to build an ear containing Bonita Execution Engine ejbjar and all its dependencies. The generated ear is build using the conf folder, i.e. if you modify hibernate.properties files or environment, changes will be used in the ear. ear folder also contains deployment descriptors for JBoss, JOnAS, Weblogic and Glassfish (EJB3 only). If you want to include other deployment descriptors, you can add your own in this folder. You can build ear files for both EJB3 and EJB2 by calling ear.ejb3 or ear.ejb2 from the root folder of the distribution. Once the ear file is generated, you have to install it in your preferred JEE application server and then start the server with the Java System properties:
Bonita API type access: org.ow2.bonita.api-type=<EJB3 or EJB2> java.naming.factory.initial java.naming.provider.url Dont forget to use the correct JAAS file (probably one of the configurations you can find in the distribution
BonitaSoft, 2010
DRAW your processes CONNECT to your systems RUN in one clic 6. Using commands
Bonita Execution Engine is providing its very useful mechanism called Commands which allows developers to write their own commands inside the Bonita Execution Engine Server. A command is a Java class implementing org.ow2.bonita.util.Command interface. There is only one operation to implement: T execute(org.ow2.bonita.env.Environment environment) throws Exception; To execute a command, you have to make it available in both client and server side classpath. You can do that either by
having the jar file containing the command available in the classpath (Env property or common lib folder in a web container for example) including the command compiled class in the deployed bar file deploying the jar file containing the command inside Bonita class loader using ManagementAPI
A command has many benefits and can be used for different purposes. A command is executed on the server side and you have access to the entire runtime inside (I mean not only APIs but all internal objects, services). Let me give you the reasons why you could use Commands: 1. Transaction: you want that a sequence of APIs calls to be executed in the same transaction. e.g. you want to create a new ProcessInstance and then set some variables. If setVariable call fails and you are doing that outside of a command, then your ProcessInstance remains created. If the behavior you want is Do no create the ProcessInstance if something fails then you have to write your own command with these 2 calls inside. 2. Bug fixing: youve identified a bug in an API operation and you want to fix it without waiting for the next maintenance release. You can use all internal Object model and services to implement the needed feature without bug 3. Missing operation: APIs are offering a wide scope of operations but maybe you miss one important thing for your application? In that case, you can use the commands mechanism to implement your own feature just as explained in point 2. You can find an example of commands in the community source explorer here. Bonita Execution Engine full Javadoc can be accessed here
BonitaSoft, 2010
DRAW your processes CONNECT to your systems RUN in one clic Example 1: Embedded application using Maven
In this chapter, I am going to help you to get started with your first Bonita project using Maven. In this example I am going to setup a very simple architecture without any container (neither Web neither EJB). Bonita Execution Engine is going to be used as a simple library. This example will illustrate basic operations of the APIs such as
This example will use a very simple process inside Bonita Open Solution Studio. This process contains only 2 human tasks, both assigned to the process instance initiator:
Lets start with our 5 minutes setup using my favorite IDE: Eclipse. First of all, you can create a new simple maven project with the following parameters:
src/main/resources in which I copied the exported process and jaas-standard.cfg file (available in runtime distribution).
Free download on www.bonitasoft.com BonitaSoft, 2010
/** * Copyright (C) 2009 BonitaSoft S.A. * BonitaSoft, 31 rue Gustave Eiffel 38000 Grenoble * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2.0 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.bonitasoft.example.runtime; import java.io.File; import java.util.Collection; import javax.security.auth.login.LoginContext; import org.ow2.bonita.facade.ManagementAPI; import org.ow2.bonita.facade.QueryRuntimeAPI; import org.ow2.bonita.facade.RuntimeAPI; import org.ow2.bonita.facade.def.element.BusinessArchive; import org.ow2.bonita.facade.def.majorElement.ProcessDefinition; import org.ow2.bonita.facade.runtime.ActivityState; import org.ow2.bonita.facade.runtime.InstanceState; import org.ow2.bonita.facade.runtime.TaskInstance; import org.ow2.bonita.facade.uuid.ProcessDefinitionUUID; import org.ow2.bonita.facade.uuid.ProcessInstanceUUID; import org.ow2.bonita.util.AccessorUtil; import org.ow2.bonita.util.BonitaConstants; import org.ow2.bonita.util.BusinessArchiveFactory; import org.ow2.bonita.util.SimpleCallbackHandler;
BonitaSoft, 2010
BonitaSoft, 2010
DRAW your processes CONNECT to your systems RUN in one clic Example 2: Write your own Web applications with Bonita Execution Engine
Bonita Open Solution Studio is generating web applications for your processes using GWT (Google Web Toolkit) technology. In some cases, this may not fit your needs as you want to use another technology to develop your BPM applications. In that case, you can still leverage Bonita Execution Engine or runtime functionalities by using APIs. In this example Im going to explain in details on how to use major APIs operations to create your own Web application based on Bonita Execution Engine. Application functionalities This application is divided in many screens. 1. Login: allows you to log to the application using default users: admin, john, james, jack (all with password bpm).
2. Home: displays the tasks of the logged user. Both job done and job to be done are displayed. The logged in user can also start a new process instance of one of Enabled processes.
BonitaSoft, 2010
4. Processes: displays the list of enabled and disabled processes. For every process in those lists, you can execute appropriate actions. This page is accessible only for users that have admin rights (admin user by default).
BonitaSoft, 2010
Source code structure To build this example application, I decided to use a different web technology than GWT to demonstrate Bonita Execution Engine that can be leveraged in all Java compliant Web technologies: Java Server Pages. The project contains different folders, so let me explain what is the content of each of them. This application is a simple Maven web-app project. I created it using: mvn archetype:create -DgroupId=org.bonitasoft.example -DartifactId=bonita-application DarchetypeArtifactId=maven-archetype-webapp
BonitaSoft, 2010
pom.xml: maven pom file defining dependencies to Bonita-server, servlet-api and jsp-api webapp: contains jsp files that display the pages above and html header and footer (only for a look & feel purpose). webapp/actions: contains jsp file in charge of executing an action without displaying anything (when action is performed, a redirection is performed) webapp/WEB-INF: contains web.xml file (very simple one) webaap/WEB-INF/classes: contains jaas-standard.cfg file used if no jaas property is defined webaap/css: contains css files used by html header and footer webapp/images: contains images used by html header and footer
Jsp actions in detail In this section Im going to explain all API calls performed in this application. login.jsp Bonita Execution Engine does not require JAAS authentication but this is the default configuration. It comes with 2 different login modules:
BonitaAuth in charge of authenticating the user with the given login and password BonitaStore in charge of propagating the user credentials to the server (in our case, the runtime is embedded in the application, so credentials are stored in a ThreadLocal)
You can see that both login modules are used. You will see in other jsp files that only BonitaStore is called before using APIs. Once the user is authenticated, we store the user name in the web session and we only need to propagate the user name to the server before calling APIs. This jsp file also determines and stores in the web session if the user has admin rights or not. logout.jsp In this action, we only remove information stored in the web session to force a new login. apiCall.jsp This jsp file is in charge of executing all usual Bonita Execution Engine API calls. This file has 2 required parameters:
back: the name of the jsp file to which the user must be redirected after the api call action: the id of the action to execute
This file may have been split in one file per API action but to prevent code duplication, I wrote everything in the same file.
BonitaSoft, 2010
archiveProcess: archive a process based on its ProcessDefinitionUUID o managementAPI.archive(ProcessDefinitionUUID) cancelInstance: cancel a process instance base on its ProcessInstanceUUID o runtimeAPI.cancelProcessInstance(ProcessInstanceUUID) createInstance: create a new process instance of the given ProcessDefinitionUUID o runtimeAPI.instantiateProcess(ProcessDefinitionUUID) deleteInstance: delete a process instance based on its ProcessInstanceUUID o runtimeAPI.deleteProcessInstance(ProcessInstanceUUID) deleteProcess: delete a process based on its ProcessDefinitionUUID o managementAPI.deleteProcess(ProcessDefinitionUUID) deployProcess: deploy a new process based on a given bar file (exported from Bonita Open Solution Studio) o managementAPI.deploy(BusinessArchive) disableProcess: disable a process based on its ProcessDefinitionUUID o managementAPI.disable(ProcessDefinitionUUID) enableProcess: enable a process based on its ProcessDefinitionUUID o managementAPI.enable(ProcessDefinitionUUID) executeTask: execute a task based on its ActivityInstanceUUID o runtimeAPI.executeTask(ActivityInstanceUUID, assignTaskToUser) setActivityVariable: set a new value to a local variable based on the ActivityInstanceUUID, the name of the variable and the value to set o runtimeAPI.setActivityInstanceVariable(ActivityInstanceUUID, variableName, variableValue); setProcessVariable: set a new value to a global variable based on the ProcessInstanceUUID, the name of the variable and the value to set o runtimeAPI.setProcessInstanceVariable(ProcessInstanceUUID, variableName, variableValue);
tasks to perform o queryRuntimeAPI.getLightTaskList(ActivityState.READY) o returned objects are light objects as we do not need all information of the retrieved activities done tasks o queryRuntimeAPI.getLightTaskList(ActivityState.FINISHED) o returned objects are light objects as we do not need all information of the retrieved activities startable processes o queryDefinitionAPI.getLightProcesses(ProcessDefinition.ProcessState.ENABLE D) o returned objects are light objects as we do not need all information of the retrieved processes
BonitaSoft, 2010
task properties o queryRuntimeAPI.getTask(ActivityInstanceUUID) o using all task getters local variables o task.getLastKnownVariableValues() o also retrieve activity datafields to get type information activityDefinition = queryDefinitionAPI.getProcessActivity(ProcessDefinitionUUID, activityName) activityDefinition.getDataFields() global variables o queryRuntimeAPI.getProcessInstanceVariables(ProcessInstanceUUID) o also retrieve process datafields to get type information queryDefinitionAPI.getProcessDataFields(ProcessDefinitionUUID)
processes.jsp This page displays a form to deploy a new bar file and 2 tables:
processes of the journal (runtime database). This table is paginated: only the 20 first processes (by name) are retrieved o journalQueryDefinitionAPI = AccessorUtil.getQueryDefinitionAPI(AccessorUtil.QUERYLIST_JOURNAL_KEY) o journalQueryDefinitionAPI.getLightProcesses(0, 20) o returned objects are light objects as we do not need all information of the retrieved processes processes of the history (history database). This table is paginated: only the 20 first processes (by name) are retrieved o historyQueryDefinitionAPI = AccessorUtil.getQueryDefinitionAPI(AccessorUtil.QUERYLIST_HISTORY_KEY) o historyQueryDefinitionAPI.getLightProcesses(0, 20) o returned objects are light objects as we do not need all information of the retrieved processes
instances of the journal (runtime database). This table is paginated: only the 20 first instances (by last update date) are retrieved o journalQueryRuntimeAPI = AccessorUtil.getQueryRuntimeAPI(AccessorUtil.QUERYLIST_JOURNAL_KEY) o journalQueryRuntimeAPI.getLightProcessInstances(0, 20)
BonitaSoft, 2010
Tips & performance As you can see in jsp files, light objects are used as much as possible. In fact this improves performance as light objects do not execute join tables in the database. I advise you to do such a thing as much as possible. Download source code and binaries You can download the bonita-application source code and the pre packaged version of this example.
9. Conclusion
As described in this paper, Bonita Execution Engine provides great flexibility for your custom application developments through the use of its APIs. Whether you just want to integrate BPM capabilities in a Portal based on a specific framework or you want to build complex applications making the most of the power and effectiveness of Bonita Execution Engine, the way to achievement is not paved with such a great complexity. Last but not least, Bonita Execution Engine is released under LGPL license, offering you multiple opportunities for developing simple to complex customized process-based applications.
About BonitaSoft
BonitaSoft is the leading provider of open source business process management (BPM) software. Created in 2009 by the founders of Bonita project, BonitaSoft democratizes the use of BPM in companies of all sizes with an intuitive and powerful solution with an optimum cost. The Bonita solution has been downloaded more than 370.000 times to date by companies and organizations worldwide. Sales inquiries : sales@bonitasoft.com | Partner inquiries : partners@bonitasoft.com www.bonitasoft.com bonitasoft.com/blog twitter.com/bonitasoft youtube.com/bonitasoft
BonitaSoft, 2010