Chapter 6. Hello World Business Rule
Since Red Hat JBoss BPM Suite comes with Red Hat JBoss BRMS integrated, this chapter provides an introduction to how business rules work and integrate into Red Hat JBoss BPM Suite.
You will add a new Business Rule Task to the Hello World process, which will fire a business rule of a particular business rule group.
Note that this is a very simple integration case and in production you may need to use a more advanced concept and techniques. For more information on business rules, see the Red Hat JBoss BPM Suite Development Guide.
6.1. Creating Business Rule Copy linkLink copied to clipboard!
Business rules are defined as when-then statements: when something is true, then something happens. For example, when the person is older than 18, then particular content becomes available. Business rules are stored in DRL files.
To define the helloworldrule
business rule in the Hello World project, do the following:
-
In Project Explorer, select the
Loan Application
organizational unit, thehelloworldrepo
repository, theHello World
project, and thedefault
package. Create the DRL file:
-
On the perspective menu, click New Item
DRL file. -
In the Create new DRL file dialog box, define the resource name as
helloworldrule
and check that the package is set todefault
. - Click Ok.
-
On the perspective menu, click New Item
In the displayed DRL editor with the
helloworldrule.drl
file, define the rule:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This rule does not define any when condition, that is, it will always be true when fired (called to execute) and the
Hello World!
phrase will be printed.- Click Save.
- The Save this item prompt is displayed. Enter the Check-in comment and click Save.
6.2. Adding Business Rule Task Copy linkLink copied to clipboard!
A Business Rule Task is a task which fires rules that belong to a certain ruleflow group.
To add a Business Rule Task to your process, do the following:
- In Project Explorer, click the arrow next to the organizational unit path.
Expand BUSINESS PROCESSES and select`HelloWorld`.
Note: If you are creating your project on a fresh installation, the BUSINESS PROCESSES menu is not visible until you click the arrow.
Figure 6.1. The Hello World organizational unit path
-
In the displayed Business Process Designer with the Hello World process, expand the Object Library palette with Process Elements. Click the double-arrow button (
) in the upper left hand corner of the Business Process Designer tab to do so.
Expand the Tasks menu and drag-and-drop the Business Rule Task to the canvas on the right.
Adjust flow connections so as to integrate the task into the workflow.
Select the Business Rule Task and define its properties in the Properties panel:
-
Name:
BusinessRule
Ruleflow Group:
helloworldgroup
The Ruleflow Group property defines the group of rules that should be fired when the task is being executed. In this example, only one rule, the
helloworldrule
rule defined in thehelloworldrule.drl
file, is present in thehelloworldgroup
group.
Figure 6.2. The Hello World Process with the Business Rule Task and Its Properties
-
Name:
- Click the save button to save the changes.
6.3. Building and Deploying Copy linkLink copied to clipboard!
Build the project and deploy it to the Execution Server:
-
On the main menu of Business Central, click Authoring
Project Authoring. - In the Project Explorer, locate the Hello World project.
- Open the project in the Project Editor: in Project Explorer, click Open Project Editor.
-
Set Version to
1.0.1
. - Click Save and confirm the dialogue to save your changes.
-
Check that the correct project details are displayed on the project screen and click Build
Build & Deploy in the upper right hand corner of the project screen view.
A green notification appears in the upper part of the screen informing you that the project has been built and deployed to the Execution Server and is available for instantiation.
6.4. Instantiating Business Process Copy linkLink copied to clipboard!
To create an instance of the Hello World process, do the following:
-
Click Process Management
Process Definitions on the main menu. -
On the displayed Process Definitions tab, locate the new
Hello World
process definition, that isorg.bpms:HelloWorld:1.0.1
. If it is not available, click Refresh to have the process definition displayed. Click the Start (
) next to the process definition entry and in the dialog box, click Submit to confirm that you want to instantiate the process.
The process is instantiated with the currently logged-in user as the process owner and the process form is displayed. When you define the form for your business process, it serves to request input from a user during process instantiation. For further information, see the Red Hat JBoss BPM Suite User Guide.
The Process Instance Details view is displayed with details about the started process instance. The Hello World!
message appears in standard output twice, typically the terminal emulator in which the server was started. Then the process instance waits on the Timer Event.
Click Options
Figure 6.3. Hello World Realtime Execution Diagram: the Timer Event Being Executed