jBPM4 real-life example: The Train Ticket Demo (part 3: prototyping with the jBPM console)

Business processes are hard to get right from the first try. This is logical, since business processes are hard coded in the mind of the business people and pouring all this knowledge into a model is hard. So typically, it takes some iterations through the BPM lifecyle until a process model is derived that somewhat matches with what the business actually is doing.

So where are we now in the Train Ticket story? We’ve modeled our process and we added business-specific logic to the business process. We’re still in the development phase, according to the BPM lifecycle.  But in these days, nobody will ever rush into development straight away at this point. Agility is all the buzz nowadays, and there is no reason why it shouldn’t be.

In this article I’ll show how you can leverage the jBPM console to  build a prototype of the final application. Of course, the jBPM console can do  a whole lot more than prototyping (like basic process governance, reporting, etc), we’ll come back to these topics later. For this article, we’ll only highlight the prototyping capabilitites of the jBPM console.

Using the taskform functionality of the jBPM console, it is very easy to emulate user input and output without investing a lot of valuable development time. The use of these taskforms will allow you to show the interaction with the business process from the viewpoint of the end-user. It enables discussions between business and development, without actually building a complete application from scratch.

Agility in its purest form, who doesn’t love that?

Enriching the business process with taskforms

In a previous article, I already explained how to add a taskform to a business process. A task form is a HTML form which we can specify in the JPDL process definition, that captures the I/O towards and from the end-user. We’ll do the same here for the train ticket process, which is shown here again as reference:

There are 2 points of input/output in the process:

  • The process is started when a cellphone text message is arrived. This text message contains the start and destination train stations.
  • Once a price quote for the itinerary is calculated and the credit balance of the customer is verified, a text message is sent back with the price quote. An acceptance task is created for the customer. When the customer sends an acceptance message back, the process is continued by completing the task.

Whenever a process instance is started through the jBPM console, the ‘start’ activity is checked to have a start form. This form will be displayed before starting a process instance and the input variables of the form will be stored in the process instance so they can be used later on.

To attach a start form to a process definition, the start activity must be enhanced with a form attribute:

<start form="org/jbpm/trainticketdemo/trainticket_startform.ftl" g="11,105,48,48" name="start">
  <transition to="Calculate quote"/>
</start>

As shown in this snippet, the form is stored as a .ftl file somewhere in the project package tree. This file contains a basic HTML form and input text fields. Remember, the values of these input fields are later used as process variables.

<html>
  <body>
    <form action="${form.action}" method="POST" enctype="multipart/form-data">
      <h3>Send SMS:</h3>
      <table>
        <tr>
          <td>From:</td>
          <td><input type="text" name="from" /></td>
        </tr>
        <tr>
          <td>To:</td>
          <td><input type="text" name="to" /></td>
        </tr>
        <tr>
          <td>Source cellphone nr:</td>
          <td><input type="text" name="cellPhoneNr" value="" /></td>
        </tr>
      </table>
      <input type="submit" name="Send"/>
    </form>
  </body>
</html>

Filling in this form will store the from, to and cellPhoneNr variable in the process instance as a process variable.

Adding a taskform to the ‘accept quote’ task is done in exactly the same way:

<task assignee="#{cellPhoneNr}" form="org/jbpm/trainticketdemo/accept_quote.ftl" ... 

In our final application, a text message will be sent to the customer before arriving in the acceptance task. In the jBPM console, we can emulate this behavior by using the taskform to display process information. Note the usage of expressions ${} to output process variables in the html taskform.

<html>
  <body>
    <form action="${form.action}" method="POST" enctype="multipart/form-data">
      <h3>Accept Quote:</h3>
      <table>
        <tr>
          <td>From:</td>
          <td>${from}</td>
        </tr>
        <tr>
          <td>To:</td>
          <td>${to}</td>
        </tr>
        <tr>
          <td>Price:</td>
          <td><b>${quote.price}</b></td>
        </tr>
      </table>
      <input type="submit" name="Accept"/>
    </form>
  </body>
</html>

Taskforms in action

That’s all there is to it. Just enrich your JPDL process definitions with some taskforms and deploy them to the jBPM database. Don’t forget to add them to the deployment next to the process definition xml by calling the deployment.addResourceFromClasspath(“org/jbpm/…”) operation.

The following screencast shows the end result of this iteration: a protoype of the application using the jBPM console and the taskform functionality.

What’s next?

In the next article, we’ll finally be able to build the real application.

Stay tuned!

One Comment

  1. Sukla May 4, 2010

    I want to show a list of quotations retrieved from a legacy application using soap service, on a Task form. The quotes are returned as a vector of quote class. I will be thankful if you could suggest how to achieve that?

Leave a Reply

Your email address will not be published.