Part 1 of this two-part article introduced you to Business Process Modeling Notation (BPMN) and Bonita Open Solution, a Java-based, open source workflow tool. You used Bonita to start designing a workflow for booking hotel rooms. Now in Part 2, you'll configure variables to hold workflow data, and design forms in the room-booking workflow for user interaction. Then you'll connect your workflow with the PostgreSQL database and the JasperReports reporting engine, so that it can read booking information from the database and generate reports. Finally, you'll execute the workflow to see the room-booking process in action.
Designing a simple form in Bonita
Launch Bonita and open the RoomBookingDiagram_1.0.proc file that you saved at the end of
Part 1. (The file is also available in this article's source code download.) The workflow contains EnterRoomInformation, CheckRoomAvailability, and BookRoom activities, as shown in Figure 1:
Figure 1. The room-booking workflow in Bonita
The next step is to design a simple form for the EnterRoomInformation activity, like the one shown in Figure 2:
Figure 2. A simple data-entry form
The form in Figure 2 contains a title (EnterRoomInformation), a drop-down list with its label (Type of room required), and a button named Check Room Availability. It also contains some other graphical elements such as the Bonita logo, which are part of a standard Bonita template. (Bonita allows use of custom templates, but for simplicity, this article uses the standard template.)
To start creating this new form for the EnterRoomInformation activity, click on the activity to display its properties in the details window. Click on the Forms tab in the details window and click the Add button. A Create a new Form dialog opens, as shown in Figure 3:
Figure 3. Dialog for creating a new form
Notice in Figure 3 that Bonita has entered EnterRoomInformation as the name of the new form for you in the Name field. You can also see a Description text box in the dialog, where you can enter a description of the form such as A form showing a drop-down list so that the receptionist can choose the type of room required by the customer.
Just below the Description text box, you can see Add widgets based on... and two buttons labeled Select All and Unselect All. Below the buttons is a check box labeled isRequiredRoomTypeAvailable. This check box, which is selected by default, represents the isRequiredRoomTypeAvailable variable that you configured in Part 1's Adding a room-availability flag to your workflow section.
How Bonita uses variables in form design
Recall from Part 1 that the isRequiredRoomTypeAvailable variable is actually a flag that the CheckRoomAvailability activity sets. The workflow uses this flag later to decide if the BookRoom activity can take place, or if control must be transferred back to the EnterRoomInformation activity.
Because the EnterRoomInformation form that you are designing has only one field (Type of room required, which is a drop-down list), you can deduce that the isRequiredRoomTypeAvailable variable (or flag) is not required for designing this form. You are probably wondering, then, why the Create a new Form dialog for the EnterRoomInformation form shows this variable as a check box.
Normally when you design and implement forms in the Java language, each field (such as a text box or a drop-down list) in the form is associated with a Java object that holds application data. Commonly called model beans, such objects are mostly used in the Model-View-Controller (MVC) architecture that most Java programmers are familiar with (see Resources). Bonita uses the same concept to associate fields with process variables, allowing you to build forms quickly directly from the process variables. It simply makes a default form that contains all the fields corresponding to each of the variables you choose. This is a quick way to have a form that you can edit and tailor according to your requirements.
Because isRequiredRoomTypeAvailable is a global variable, it is valid in the context of the complete room-booking workflow as well as all individual activities of the workflow. And you have not declared any other variable for the workflow so far. That's why this is the only variable that Bonita thinks can be used to build the EnterRoomInformation form. It simply includes the isRequiredRoomTypeAvailable global variable in the list of variables that you can use to design your form.
If you were to click the Finish button at the bottom of the Create a
new Form dialog now, Bonita would create a form that includes a field corresponding to the isRequiredRoomTypeAvailable variable. But as you know from the business logic of your room-booking workflow, you don't need the isRequiredRoomTypeAvailable variable in designing the EnterRoomInformation form. So, in the Create a new Form dialog, you should now uncheck the box next to the isRequiredRoomTypeAvailable variable, then click Finish. Bonita automatically configures an empty EnterRoomInformation form, as shown in Figure 4:
Figure 4. Newly configured empty form for the
EnterRoomInformation activity
Now you must configure a variable for the Type of room required field. This variable will hold all the available room types, so that the receptionist can choose the type that the customer wants. I'll call this variable TypesOfRoomsAvailable. The Type of room required field on the EnterRoomInformation form will use the TypesOfRoomsAvailable variable to fetch the different types of available rooms.
Configuring a variable to hold a list of options
The TypesOfRoomsAvailable variable is only required in the EnterRoomInformation form. This makes it a local variable.
To start creating the TypesOfRoomsAvailable variable, click on the EnterRoomInformation activity in the Bonita whiteboard (design view). Details of the EnterRoomInformation activity appear in the details window. Click on the Data tab in the details window and click the Add button. An Add a new variable dialog, similar to the one in Figure 9 of Part 1 (which you used to configure the isRequiredRoomTypeAvailable global variable) appears. It includes Name (required), Description, Data type, and Default value fields. Enter TypesOfRoomsAvailable in the Name field and A variable to hold the different types of rooms available in the hotel in the Description text box, as shown in Figure 5:
Figure 5. Dialog for adding a new variable
Now look at the Data type field in Figure 5. When you configured the isRequiredRoomTypeAvailable variable in Figure 9 of Part 1, you chose Boolean as the Data type value, because the isRequiredRoomTypeAvailable variable is a flag that can be true or false. The TypesOfRoomsAvailable variable needs to be a list of options — the types of available rooms — so select List of options from the drop-down list next to the Data type field.
As soon as you select List of options as the data type, a new group of three fields (Name, Description, and List) and four buttons (Add, Up, Down, Remove) appears in the lower portion of the Add a new variable dialog, as shown in Figure 6:
Figure 6. Dialog for adding a new variable, with extra fields for the List of options data type
Bonita shows the extra fields because it needs to know the actual types of rooms that are available, so that it can associate the list of types with your TypesOfRoomsAvailable variable.
As you can see in Figure 6, the Name and List fields are marked with an asterisk to indicate that they are mandatory. This is a reusability feature of Bonita that allows you to give a name to a list of values. Later you can reuse the same list with some other variable.
Type ListOfRoomTypes in the Name field and These are the types of rooms available as the description. Then, in order to enter the actual values into the list, click the Add button. An Add an item dialog appears, as shown in Figure 7, that allows you to enter the different types of rooms one by one:
Figure 7. Dialog for adding values to the List of options data type
You'll enter only two values in the list. First, type Single in the Item name field of the Add an item dialog and click OK. The value now appears in the List text box of the Add a new variable dialog shown in Figure 6. Click the Add button again, and this time type Double in the Item name field, then click OK. You are done with the Add a new variable dialog. Now click the OK button, which I've circled in Figure 8:
Figure 8. Complete configuration for the
TypesOfRoomsAvailable variable
Click the Finish button at the bottom of completed Add a new variable
dialog. The dialog disappears, and the TypesOfRoomsAvailable variable now appears in the Data tab for the EnterRoomInformation activity, as shown in Figure 9:
Figure 9. The
TypesOfRoomsAvailable variable added to the EnterRoomInformation activity
You have successfully configured the TypesOfRoomsAvailable variable, so now you can use the variable to add the Type of room required drop-down list to your EnterRoomInformation form.
While the EnterRoomInformation activity is still selected in the whiteboard, click on the Forms tab in the details window. Click on EnterRoomInformation in the list of forms, then click the Edit button, circled in Figure 10:
Figure 10. Editing a Bonita form
The empty EnterRoomInformation form that you developed in the Creating a new form section appears in a form-editor window, which has a palette of components on the left and the form's design view on the right. The form's design view shows rectangular cells. Click the Select component in the component palette and drag it to the top-most cell in the form, as shown in Figure 11:
Figure 11. Dragging a component from the palette into your form
A new field with Select1 as its label is dropped onto the form, as shown in Figure 12:
Figure 12. A Select component dropped into the form's design view
Now click the Select1 field. The details window displays its properties, as shown in Figure 13:
Figure 13. Details window showing the properties of a field
Enter RequiredRoomType and Type of room required as values in the Name and Show label fields, respectively. The new field now shows Type of room required as its label, as shown in Figure 14:
Figure 14. Updated label for the Type of room required field
The drop-down list for the Type of room required field should show types of rooms available so the receptionist can choose. So the next step is to populate the drop-down list with available type of rooms using the TypesOfRoomsAvailable variable that you configured in the Configuring a variable to hold a list of options section.
Associating Bonita variables with a field on a form
While the Type of room required field is selected in the form's designer view, click on the Data tab in the details window. Notice that this tab includes four fields: Available Values, Initial value, Expression, and save to, as shown in Figure 15. These form fields allow you to associate variables with the field.
Figure 15. The Data tab showing variables associated with a field
Click the drop-down list next to the Available Values field and select the typesOfRoomsAvailable variable as its value. This populates the types of rooms in the drop-down list next to the Type of room required field in the EnterRoomInformation form.
Now click the drop-down list next to the Initial value field and select Single. This sets Single as the initial value selected by default for the Type of room required field when the EnterRoomInformation form is presented to the user. Now the Data tab should look like the one in Figure 16:
Figure 16. Data tab for RequiredRoomType after selection of default initial value
The Data tab's Expression field allows you to write an expression that Bonita uses to evaluate the value of a variable specified by the save to field. This feature is useful if you want to process user input before saving it to a variable. However, you don't require any processing of the user input, so leave the Expression field with its default value.
The workflow's next activity, CheckRoomAvailability, needs
to know the type of room required so that it can query the hotel's room-booking
database for its availability. You need to define a workflow-level variable of text
type to store the user input. So create a variable named requiredRoomType, setting its data type as Text, using the steps
described in the Configuring a variable to hold a list of
options section. The requiredRoomType variable now
gets listed in the drop-down list next to the save to field. As soon as you select
this value from the drop-down list, the check box on the left of the save to field also
gets selected, as shown in Figure 17. This is because Bonita knows that now the save to field has the name of a variable for storing the user input.
Figure 17. Expression and save to fields of the Data tab for the RequiredRoomType field
You have finished configuring fields and variables for the EnterRoomInformation form. Now you need to configure a button for the form that the receptionist will click after choosing the required type of room.
Working with buttons in Bonita forms
Bonita provides three types of buttons: submit, next, and previous. The submit-type button submits form data for processing: when a user clicks the button, form data is submitted and the next activity in the workflow takes place. In the design view of the EnterRoomInformation form, you can see a Submit button at bottom of the form. Bonita automatically placed this button for you while creating the new form. You just need to change thus button's label from Submit to Check Room Availability. The rest is already configured by Bonita.
Click on the Submit button in the design view. The details window displays the button's properties, as shown in Figure 18:
Figure 18. Details window showing properties of the Submit button
Type Check Room Availability in the Show label field in the details window. This changes the button's label — and completes the configuration for your EnterRooomInformation form.
Connecting Bonita to PostgreSQL
The CheckRoomAvailability activity will consult the hotel's room-booking database for availability of the required type of room. I'll use PostgreSQL, a popular open source database, to hold room-booking data. Bonita provides many connectors that you can configure to connect it to external applications. You'll configure Bonita's PostgreSQL connector to connect your CheckRoomAvailability activity with the hotel's room-booking database.
To configure Bonita's PostgreSQL connector, you will:
- Add a PostgreSQL connector to the
CheckRoomAvailabilityactivity. - Write a SQL query using the
requiredRoomTypevariable. - Store the output of the SQL query in the
isRequiredRoomTypeAvailableworkflow-level variable to be used later by the other BPM elements for decision making.
Configuring Bonita's PostgreSQL connector
Select the CheckRoomAvailability activity on the whiteboard to display its properties in the details window. Click the Connectors tab in the details window, as shown in Figure 19:
Figure 19. Connectors tab of the CheckRoomAvailability activity
The Connectors tab has no connector yet for the CheckRoomAvailability activity. To add a connector for PostgreSQL, click the Add button to open the Select a connector dialog, as shown in Figure 20:
Figure 20. Adding the PostgreSQL connector to an activity
You'll find the PostgreSQL connector under the Database item in the connectors list. Double-click the Database item, then select the PostgreSQL - Execute a query on a PostgreSQL DB option and click Next, as shown in Figure 21:
Figure 21. PostgreSQL database connector selected from Bonita's database connectors
Next you'll see a Name the connector dialog, shown in Figure 22, which asks you to enter a name, description, and the event at which the connector will activate:
Figure 22. PostgreSQL connector properties for the hotel database
Enter HotelDB and PostgreSQL connector for the CheckRoomAvailability activity in the Name and Description fields, respectively.
The Select event field allows you to choose whether you need this connector at the start or at the end of the CheckRoomAvailability activity. Because the CheckRoomAvailability activity in your room-booking workflow is just a database query, it doesn't matter whether the connector is activated at the start or end of the activity. So leave the Select event field with its default value.
The last field in the Name the connector dialog is If connector fails.... From the drop-down list next to it, you can choose one of two options in case a problem occurs in communicating with the database: either raise an error or ignore it. For the sake of simplicity, also leave the If connector fails.., field at its default value, which will raise an error if the connector with the database doesn't work.
Click the Next button. The next dialog asks you to enter database connection information, including database name, username, password, and name and port of the server hosting the database. These values depend on how you have set up your database. Figure 23 shows the values that I used:
Figure 23. PostgreSQL database connection dialog
After entering the database connection information, click the Next button.
Providing an SQL query to read from the database
Now you have a query dialog, shown in Figure 24, where you can enter an SQL query to check for room availability:
Figure 24. Entering an SQL query
You know that the requiredRoomType variable holds the selection made by the user. So the SQL query must check the availability of that type of room, using the requiredRoomType variable. Enter the following query in the Query text box:
Select "Availability" from "RoomInfo" WHERE "RoomType" = '${requiredRoomType}' AND
"Availability" = TRUE |
This query picks all the records whose availability column is true from the RoomInfo table in PostgreSQL.
Bonita will replace ${requiredRoomType} with the value of the requiredRoomType variable before executing this query. So, if the receptionist selects Single in the form as the required type of room, the actual SQL query that will be executed is:
Select "Availability" from "RoomInfo" where "RoomType" = 'Single' AND "Availability"
= TRUE |
This is how Bonita lets you write dynamic SQL queries that are decided at run time.
Capturing the output of the SQL query in a workflow-level variable
You need to store the SQL query output in the isRequiredRoomTypeAvailable variable, which you configured as a global variable in Part 1. Click the Next button, and you'll see the Execute a query on a PostgreSQL DB dialog, which lets you map the output of the SQL query to a Bonita variable. Type rowSet.getValues().asBoolean() in the Connector output combo box and select isRequiredRoomTypeAvailable from the Destination variable drop-down list, as shown in Figure 25:
Figure 25. Mapping output of the SQL query to a Bonita variable
The rowSet.getValues().asBoolean() method will insert true as the value of the isRequiredRoomTypeAvailable variable if the required type of room is available for booking.
You have connected your workflow to the database. Now you can do the last remaining
workflow-configuration step: designing the room-booking form for gathering customer
information and booking the room. For this step, define CustomerName, PhoneNumber, and BookingDate local variables to hold customer information. Then, use the Create a new form screen (see Figure 3) to design the new form. Finally, configure a connector and write an SQL query to submit the room-booking information to the database. Because I've already demonstrated all of these procedures, I leave this form as an exercise for you. The RoomBookingDiagram_2.0.proc file in this article's source code contains the final iteration of the room-booking workflow.
Integrating JasperReports with Bonita
You have now configured your complete room-booking workflow. Before I demonstrate how to execute the workflow, I'll show how you can integrate JasperReports with the EnterRoomInformation activity. Bonita-JasperReports integration is useful in BPM applications, because reporting capabilities are often required in real-world scenarios such as a hotel's room-booking process. And JasperReports is among the most popular open source reporting engines.
You need to install JasperReports before using it with Bonita. Go to the JasperReports website for download and installation instructions (see Resources).
The process of configuring JasperReports with the EnterRoomInformation activity is similar to the steps you performed in the Connecting Bonita to PostgreSQL section.
Select the EnterRoomInformation activity in the whiteboard,
click on its Connectors tab, and click Add. You will
get the Name the connector dialog. Then select the Create report - Create a
Jasper Report from a database option from the Jasper item in the Select a
connector dialog. In the Name the connector dialog, enter BookingSummaryReport as the name of the connector.
After that, you will get the Database access information dialog shown in Figure 26, which asks you for information that JasperReports needs to connect to your database:
Figure 26. Entering database access information for JasperReports
Enter org.postgresql.Driver in the Database driver field. org.postgresql.Driver is the JDBC driver, which you need whenever you use the PostgreSQL database. The other field values shown in Figure 26 are the ones I entered for my configuration: jdbc:postgresql://localhost:5432/hotelDB for the JDBC URL field, and postgres for both the User name and Password fields.
See Resources for more details about connecting JasperReports with relational databases such as PostgreSQL.
Click the Next button and the Report Settings dialog opens, shown in Figure 27:
Figure 27. Report settings for JasperReports
This dialog asks you for the path to your JasperReports XML (JRXML) file. All JasperReports reports are designed as JRXML files. I've provided a CurrentBookingSummaryReport.jrxml file for a simple room-booking summary report in this article's source code download. Copy this file into a location of your choice and provide the path to the file in the JRXML file path field.
In the Output file path field, specify the location where you want Bonita to save the PDF version of the room-booking summary report. In the Output format field, select PDF. Click Finish, and your room-booking summary report is now fully integrated with Bonita.
Executing the room-booking workflow
Bonita comes bundled with Jetty, a popular open source web server. This makes it easy for users to test BPM applications configured in Bonita.
Before you can try the room-booking workflow, you need to set up your PostgreSQL database and populate it with sample data, if you haven't done so already. Refer to the Readme.txt file in the source code download for instructions on setting up and populating PostgreSQL with the same sample data that I used to try the application.
The download also contains RoomBookingDiagram_2.0.proc, which contains the complete room-booking workflow with all the forms and variables. Open this file from Bonita's file menu and then click Run on Bonita's toolbar to execute the workflow, as shown in Figure 28:
Fig 28. The Bonita toolbar
When you click the Run button, Bonita automatically bundles the room-booking workflow in a web archive (WAR) file that it deploys and runs on Jetty. Bonita then opens the EnterRoomInformation form in a web browser, as shown in Figure 29:
Fig 29. The EnterRoomInformation form
You can see that Single is the default value selected in the Type of room required drop-down list. Select Double instead and click the Check Room Availability button. You get the same EnterRoomInformation form again, because a double room is not available for booking in the sample data.
Now reselect Single and click the Check Room Availability button. Because the sample data in the room-booking database says that a single room is available for booking, the BookRoom form, shown in Figure 30, now appears:
Fig 30. The BookRoom form
You can also observe that the EnterRoomInformation activity has saved a PDF version of your room-booking summary JasperReports report in the location you specified earlier.
In this two-part series of articles, you configured and executed a simple room-booking workflow of a hotel as a BPM application in Bonita. You also interfaced your workflow with two external applications. You did all this configuration just by using Bonita's graphical workflow and form editors, without writing any Java code.
Interfacing with external applications is required in almost all BPM applications. Most real-world BPM applications require more than one BPM engine and a number of other non-BPM external applications, all working together. For the moment, no standard Java API is available to describe how a BPM tool can interface with external applications and how different BPM tools can interface with one another. For this reason, every BPM tool has to devise some sort of interfacing mechanism, such as Bonita's connector mechanism. This interfacing can become seamless if a standard Java BPM API is developed that defines how a BPM tool or other application can expose its functionality to be integrated into a workflow.
| Description | Name | Size | Download method |
|---|---|---|---|
| BPMN, JRXML, and Readme.txt files for this article | j-bpm2.zip | 11KB | HTTP |
Information about download methods
Learn
-
Object Management Group/Business Process Management Initiative: Check out the BPMN specification and other BPMN resources.
-
Bonita Open Solution: Visit the Bonita web site.
-
Building your BPM applications with Bonita Runtime - Part 1 and Building your BPM applications with Bonita Runtime - Part 2: Learn more about using Bonita's runtime engine from these tutorials on the Bonita site.
-
BPMN 2.0 new features: Watch this video to see some of the BPMN 2.0 features available in Bonita.
-
BPMN Modeling and Reference Guide: Understanding and Using BPMN (Stephen A. White and Derek Miers, Future Strategies, 2008): This guide is available for purchase in both print and digital editions.
-
"JasperReports
3.6: Using Multiple Relational Databases to Generate a Report" (Bilal Siddiqui,
Packt Publishing, June 2010): Learn more about how to use JasperReports with
relational databases such as PostgreSQL. In addition, this free sample chapter from JasperReports 3.6 Development Cookbook (Bilal Siddiqui, Packt Publishing, 2010) explains JRXML design.
-
"Struts, an open-source MVC implementation" (Malcolm Davis, developerWorks, February 2001): Learn about implementing the MVC design pattern in your web applications.
-
developerWorks Java technology zone: Find hundreds of articles about every aspect of Java programming.
Get products and technologies
-
Bonita Open Solution: Download Bonita. The article uses version 5.2.2.
-
PostgreSQL: Download PostgreSQL.
-
JasperReports: Download JasperReports.
Discuss
- Get involved in the My developerWorks community. Connect with other developerWorks users while exploring the developer-driven blogs, forums, groups, and wikis.
Bilal Siddiqui is an electronics engineer, XML consultant, technology evangelist, and frequently published technical author. He is the founder of XML4Java.com, a company focused on simplifying e-business. After graduating in 1995 from the University of Engineering and Technology, Lahore, Bilal began designing software solutions for industrial control systems. Later, he turned to XML and built web- and WAP-based XML processing tools, server-side parsing solutions, and service applications. Since 2006, he has focused exclusively on Java- and XML-based open source tools and solutions. A strong advocate of open source tools, he not only designs solutions based on them but also trains software and IT personnel at Lahore universities in using open source technologies. Bilal is the author of JasperReports 3.6 Development Cookbook (Packt Publishing, 2010).




