Friday, September 25, 2015

jBPM and BPMN 2.0 workflow creation






























In my previous post I was describing how to install and run jBPM console.

In this one post, I would like to describe how quickly create a workflow calling a web service.
I will be using a public weather web service based API (OpenWeatherMap) for convenience.

With this restful based API, I can easily query the current weather in a city or a zip code area:

   http://api.openweathermap.org/data/2.5/weather?q=Paris

   http://api.openweathermap.org/data/2.5/weather?zip=94404,us

I will now start by creating a new project called Meteo via the jBPM KIE console:




This will create a project where you will be able to add business processes and task forms.

Next, I am creating a business process called ObtainWeatherForecast to enter a city or zip code, call the web service and display the corresponding weather forecast:




















Automatically, the Process Modelling / Shape Repository panel opens with an initial default Start Event generated.

Two side panes are quite useful to add:

  • On the left the Object library. 
  • On the right side, the Properties of the BPMN diagram elements.You click on the top buttons to show the panes.









































First I am going to define a set of variables that will be available in the process to maintain internal values so I can share information between nodes.
For this I click on the background of the business process and edit the Variable Definitions Properties of the ObtainWeatherForecast business process.












































































In the Process Modelling panel, when you select a node (event or task), you can select some very useful context icons
such as View the BPMN Node Source, create a new task or event, link nodes etc ...



























When adding a new task, you have various ways to do this.

If the task is one of the 8 basic Tasks (User, Send, Receive, Manual, Service, Business Rule, Script, None),
then you can either click on the task context icon to create the next task node (as a generic/none type)
from an existing event node or a task node (1a) and specify one of the other 7 basic type if needed using the tool context icon for a more specific one (1b).


























You can also use the Object library and drag/drop the task (2) and link the nodes via the link context icon (3).

If you want to add a more specific Service Task (Email, Log, REST, WS), then you can use the Object Library and select the corresponding Service Task (4).







































The REST Service task has its Data Input (info associated to RESTful call) and Data Output (result from the call) properties already populated:



















































For the Data Assignment variables, we are going to set the Method to GET and for a quick hard-coded test,
we are going to set the url to http://api.openweathermap.org/data/2.5/weather?q=Paris
Then we are going to map the object Result of the call (use [Output Mapping]) to our process variable forecast.
Later we will be able to use the forecast JSON output and extract and display the associated information.



























At this point you can add another Script Task for displaying the weather forecast result and complete the business process workflow
with a Terminate End Event, link all nodes and add useful properties such as names.






























To deploy your Project and Business Process, select Build & Deploy.


















After your project is successfully deployed, you select Deploy|Process Deployments.























You can then see your deployed project with the option to Deactivate it or Undeploy it.






























Now you can check the Process Definitions and start ObtainWeatherForecast business process by clicking on the Start button:

















































After execution of the process, if you look at your Process Variables as part of the process definition, you can obtain the current weather in Paris (JSON returned object):



{"coord":{"lon":2.35,"lat":48.85},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"base":"cmc stations","main":{"temp":287.89,"pressure":1024,"humidity":67,"temp_min":286.15,"temp_max":289.26},"wind":{"speed":2.6,"deg":20},"clouds":{"all":75},"dt":1443208502,"sys":{"type":1,"id":5615,"message":0.0054,"country":"FR","sunrise":1443159717,"sunset":1443202883},"id":2988507,"name":"Paris","cod":200}


One last tip on this first hands-on experience. If your Project Explorer goes away for some reasons (it seems there is a bug in 6.2.0 final related to this). Try to click on the reset perspective button:

























No comments: