How to integrate BOS engine in a Struts 2 application

bouquetf's picture
bouquetf
Blog Categories: 

A few days ago, I’ve found a French article [1] where the author was trying but unfortunately failing to integrate a process in a Struts 2 web application. The context was a simple bugtracker. In this article, we will do this integration and see what are the right steps to perform. First, have a reminder on some BOS basics. We will then focus on the process design. We will finish by integrating this process in the existing Struts application. What is Bonita Open Solution

Bonita Open Solution is a full Business Process Management Solution. This means you can design, automate, run, monitor and optimise your process with the full software stack. The whole solution is open source and following the Bonitasoft Manifesto [2]: Transparency, Collaboration, Meritocracy and Excellence.

Bonita Open Solution (BOS) is composed of three tools:

  • Bonita Execution Engine (BEE) under LGPL which is designed to run Bonita processes.
  • Bonita Studio (Studio) under GPL which is a full development environment to develop and optimize your processes
  • Bonita User Experience (UserXP) under GPL which is composed of three parts. It provides end users with an interface to manage their cases. It allows administrators to manage the execution platform. And it renders the process-based web applications developed in the Studio.

Source can be browsed directly from the community website [3]

An easy way to contribute to the BOS project [4] is by developing an example or a plugin like a connector to other application or a look’n’feel for web applications. BOS also has an active community [5] where you can get help or help other users. Bonitasoft R&D and professional services teams are also active on this community to share their knowledge of the project.

As processes are complex, you are highly recommended to use the Studio to develop them. Even if it’s not mandatory, we also recommend using BOS forms for most use cases as it’s a fast and easy way to develop web applications. In the last section, we will see that it’s really easy to interact with BEE using its API. If you’re using Java, you can access BEE locally or remotely. You also have the possibility of accessing BOS using any language as BEE shares a API over HTTP. In our case we will access the engine locally in Java as we will use a Struts web application deployed in a Tomcat bundle, but will talk about it a bit later.

Design of the bugtracker process

Let’s start now with the design of the process. BOS implements a subset of the BPMN 2.0 [6] standard to make it possible to design all sorts of processes, even if you are not a BPM expert. In this section, we will develop a really simple bug report process. When someone report a bug, the process is started. The first task is a review performed by reviewers. If the review is accepted, developers have to resolve the issue to finish the process. If the bug is rejected, the process is finished.

The main difficulty here is to know what will start the process. For us, it’s when the user submits a new issue, so the start event will be named “Issue submitted”.

Only reporters will have the access to the start of the process. We won’t explore this in the article but basically, it is done by setting a rule in the Access Control List of BOS.

Concerning the rest of the process, we have first to design the way people work.

Secondly, we’ll have to create process data. We’ll only use simple data types here: String and Date. Of course, for a real project which will go in production, the good practice is to store business data in a business database and manipulate them remotely using connectors.

The last thing to do is to configure conditions on transitions and actor selectors. From Review bug to Resolve bug, the condition will be result==’Accepted’. From Review bug to Bug rejected, the transition will be made by default. Concerning the actor selectors, Review bug will be assigned to the group reviewers, Resolve bug will be assigned to the group developers.

Now, the process is ready to be executed. Let’s now create the web applications.

Integration

Concerning integration in an existing web application, three use cases are of interest:

  • Start processes
  • List all the tasks for a user
  • Interact with a running process by providing a web interface
  • The third case is what we will explore in this section. We will consider that the web application already exists, as the interesting thing is how to map this web application to the engine.

In our web application, we have a form to get the information from the user to start the process.

When the user submits this form, the corresponding action (SaveBugAction) in the project will ask Bonita to create the bug. The information flow goes from the web application to the Bonita Engine. This will be done by calling the RuntimeAPI and its instantiateProcess by providing the process definition id (ProcessDefinitionUUID). Then, the process will run in parallel to our web application, which will continue its execution.

The next form of our web application displays the list of bugs.

Here, when the user ask for the list, the web application will retrieve the information from the Bonita Engine and display it. The information flow goes this time from Bonita to the web application. This will be done by calling the QueryRuntimeAPI and one method of the getLightTaskList family. The web application will now just need to parse the output as needed, and display it.

The last form is when a user selects a bug to resolve. The application has to retrieve the task data information from the Bonita Engine and, when the task is validated, update the relevant process data.

Here, the information flow goes from the Bonita Engine to the Web Application to retrieve the information. Then, the information flow goes back from the Web Application to the Bonita Engine at submission. Retrieving the information from the process instance is done by calling the QueryDefinitionAPI and its getProcessInstanceVariable with the process instance id. In our case, it is done in the ReviewBugAction. Sending back the information to the process instance is done by calling the RuntimeAPI and its setProcessInstanceVariable. By the way, the task has to be submitted, we’ll still do it in the RuntimeApi. When the user submits the task, it corresponds to the startTask method. When the data are updated, the task can be finished by the finishTask method.

The source code illustrating the example can be download on GitHub [7].

Links

  1. http://www.improve-technologies.com/2012/06/27/panorama-des-moteurs-bpmworkflow-open-source/
  2. http://www.bonitasoft.com/company/bonitasoft-manifesto
  3. http://www.bonitasoft.org/websvn/
  4. http://www.bonitasoft.org/exchange/index.php
  5. http://www.bonitasoft.org/forum/
  6. http://www.bpmn.org/
  7. https://github.com/bouquetf/bugreport
Notifications