Red Hat Training

A Red Hat training course is available for Red Hat Process Automation Manager

Getting started with decision services

Red Hat Process Automation Manager 7.1

Red Hat Customer Content Services

Abstract

In this tutorial, you will create and test a driver's license suspension scenario.

Preface

As a business analyst or rules developer, you can use Business Central in Red Hat Process Automation Manager to design a variety of decision services. In this tutorial, you will create and test a driver’s license suspension scenario.

Prerequisites

Chapter 1. Creating the traffic violations project

A project is the container for assets such as data objects, guided decision tables, and guided rules. For this tutorial, you will create the Driver_department_traffic_violations project.

Procedure

  1. Log in to Business Central.
  2. Go to MenuDesignProjects.

    Tip: Red Hat Decision Manager provides a default space called MySpace, as shown in the following image. You can use the default space to create and test example projects.

    Figure 1.1. Default spaces

    spaces teams
  3. Click Add Project.
  4. Enter Driver_department_traffic_violations in the Name field.
  5. Click Add.

    Figure 1.2. Add Project window

    addproject

The Assets view of the project opens.

Chapter 2. Data objects

Data objects are the building blocks for the rule assets that you create. Data objects are custom data types implemented as Java objects in specified packages of your project. For example, you might create a Person object with data fields Name, Address, and DateOfBirth to specify personal details for loan application rules. These custom data types determine what data your assets and your decision services are based on.

The following tables show the Violation and Driver data objects that you will create in this tutorial.

Table 2.1. Violation data object

IDLabelType

code

Code

String

points

Points

Integer

violationDate

Violation Date

Date

type

Type

String

fineAmount

Fine Amount

Double

speedLimit

Speed Limit

Integer

actualSpeed

Actual Speed

Integer

Table 2.2. Driver data object

IDLabelType

name

Name

String

age

Age

Integer

state

State

String

city

City

String

violations

Violations

Violation (org.jboss.example.traffic_violations.Violation) Note: The violations field is set to "List" to hold multiple items for the given type.

fineAmount

Fine Amount

Double

totalPoints

Total Points

Integer

reason

Reason

String

2.1. Creating the Violation data object

The Violation data object contains data fields based on violation details, such as Violation Date, Fine Amount, and Speed Limit.

Prerequisites

You have created the Driver_department_traffic_violations project.

Procedure

  1. Click Add AssetData Object.
  2. In the Create new Data Object wizard, enter the following values:

    • Data Object: Violation
    • Package: select com.myspace.driver_department_traffic_violations
  3. Click Ok.

    Figure 2.1. Create new Data Object window

    data object

2.1.1. Adding the Violation data object constraints

Populate the Violation data object fields with the constraints that you will select when you define your rules.

Prerequisites

You have created the Violation data object.

Procedure

  1. In the 'Violation'-general properties section, enter Violation in the Label field.

    Figure 2.2. General properties

    gen props
  2. Click + add field.
  3. Enter the following values:

    • Id: code
    • Label: Code
    • Type: String
  4. Click Create and continue, then enter the following values:

    • Id: points
    • Label: Points
    • Type: Integer
  5. Click Create and continue, then enter the following values:

    • Id: violationDate
    • Label: Violation Date
    • Type: Date
  6. Click Create and continue, then enter the following values:

    • Id: type
    • Label: Type
    • Type: String
  7. Click Create and continue, then enter the following values:

    • Id: fineAmount
    • Label: Fine Amount
    • Type: Double
  8. Click Create and continue, then enter the following values:

    • Id: speedLimit
    • Label: Speed Limit
    • Type: Integer
  9. Click Create and continue, then enter the following values:

    • Id: actualSpeed
    • Label: Actual Speed
    • Type: Integer
  10. Click Create.
  11. Click Save, and then click Save to confirm your changes.
  12. Click the Driver_department_traffic_violations label to return to the Assets view of the project.

    Figure 2.3. Violation data object fields

    violation data fields

2.2. Creating the Driver data object

The Driver data object contains data fields based on driver details, such as Name, Age, and Total Points.

Prerequisites

You have created the Driver_department_traffic_violations project.

Procedure

  1. Click Add AssetData Object.
  2. In the Create new Data Object wizard, enter the following values:

    • Data Object: Driver
    • Package: select com.myspace.driver_department_traffic_violations
  3. Click Ok.

    Figure 2.4. Create new Data Object window

    data object2

2.2.1. Adding the Driver data object constraints

Populate the Driver data object fields with the constraints that you will select when you define your rules.

Prerequisites

You have created the Driver data object.

Procedure

  1. In the 'Driver'-general properties section, enter Driver in the Label field.
  2. Click + add field.
  3. Enter the following values:

    • Id: name
    • Label: Full Name
    • Type: String
  4. Click Create and continue, then enter the following values:

    • Id: age
    • Label: Age
    • Type: Integer
  5. Click Create and continue, then enter the following values:

    • Id: state
    • Label: State
    • Type: String
  6. Click Create and continue, then enter the following values:

    • Id: city
    • Label: City
    • Type: String
  7. Click Create and continue, then enter the following values:

    • Id: violations
    • Label: Violations
    • Type: Violation(com.myspace.driver_department_traffic_violations.Violation)
    • List: Select this check box to enable the field to hold multiple items for the specified type.
  8. Click Create and continue, then enter the following values:

    • Id: fineAmount
    • Label: Fine Amount
    • Type: Double
  9. Click Create and continue, then enter the following values:

    • Id: totalPoints
    • Label: Total Points
    • Type: Integer
  10. Click Create and continue, then enter the following values:

    • Id: reason
    • Label: Reason
    • Type: String
  11. Click Create.
  12. Click Save, and then click Save to confirm your changes.
  13. Click the Driver_department_traffic_violations label to return to the Assets view of the project.

    Figure 2.5. Driver data object fields

    driver data fields

Chapter 3. Guided Rules

Guided Rules are business rules that you can create in a UI-based Guided Rules designer that leads you through the rule creation process. The rule designer provides fields and options for acceptable input based on the object model of the rule being edited. All data objects related to the rule must be in the same project package as the rule. Assets in the same package are imported by default. You can use the Data Objects tab of the rule designer to verify that all required data objects are listed or to import any other needed data objects.

Figure 3.1. The Guided Rule designer

The Guided Rule designer

3.1. Creating the Driver License Suspension rule

Create the Driver license suspension rule using the Guided Rule wizard.

Prerequisite

You have created both the Violation and Driver data objects.

Procedure

  1. Log in to Business Central.
  2. Click MenuDesignProjects, then Driver_department_traffic_violations.
  3. Click Add AssetGuided Rule, then enter:

    • Guided Rule: DriverLicenseSuspensionRule
    • Package: com.myspace.driver_department_traffic_violations
  4. Click Ok to open the Guided Rule designer.

    Figure 3.2. Create new Guided Rule window

    guided rule

3.2. Setting the Suspension rule conditions

Set the Suspension rule conditions that are used to determine the driver’s violation.

Prerequisite

You have created the Driver License Suspension rule.

Procedure

  1. Click ( 6176 ) next to the WHEN label to open the Add a condition to the rule window.
  2. Select Driver and click Ok.

    Figure 3.3. Create new Guided Rule window

    add condition
  3. Click the There is a Driver label to open the Modify constraints for Driver window.
  4. Enter driver in the Variable name field and click Set.
  5. Click There is a Driver[driver] and click Expression editor.
  6. Click [not bound] to open the Expression editor.
  7. In the Bind the Expression to a new variable field, enter: previousPts and click Set.
  8. From the Choose menu, select totalPoints.
  9. Click ( 6176 ) next to line 1 (the previousPts label) to open the Add a condition to the rule window.
  10. Select From Accumulate and click Ok.
  11. Click click to add pattern above the From Accumulate label and select Number from the choose fact type menu.
  12. Click There is a number label to open the Modify contraints for Driver window.
  13. Click Expression editor and select intValue() from the [not bound]: Choose menu.
  14. Click [not bound] to open the Expression editor.
  15. In the Bind the Expression to a new variable field, enter: totalNewPoints and click Set.
  16. Click click to add pattern and select Violation from the choose fact type menu.
  17. Click All Violation with: to open the Modify contraints for Violation window and select points from the Add a restriction on a field menu.
  18. Click please choose next to the points label and select greater than.
  19. Click ( 6191 ), and then click Literal value.
  20. Click the points label to open the Add a field window.
  21. Enter vPoints and click Set.
  22. In the Function field, enter sum(vPoints).
  23. Select greater than or equal to from the totalNewPointsplease choose menu.
  24. Click ( 6191 ), click New formula, and enter 20-previousPts in the new field.
  25. Click Save, and then click Save to confirm your changes.

Figure 3.4. Suspension Rule conditions

rule conditions

3.3. Setting the Suspension rule actions

Set the Suspension rule actions that are used to determine a driver’s resulting penalties, including points and fine amounts, based on the Suspension rule conditions.

Prerequisite

You have set the Suspension rule conditions.

Procedure

  1. Click (show options…​).

    Figure 3.5. show options selection

    show options
  2. Click ( 6176 ) next to the THEN label and select Change field values of driver, and click Ok.
  3. Click the Set value of Driver [driver] field and select state from the Add field menu.
  4. Click ( 6191 ) next to state in the Set value of Driver [driver] section to open the Field value window.
  5. Click Literal value and enter suspend in the new field.

    Figure 3.6. New field

    suspend entry
  6. Click ( 6176 ) next to the (options) label below the Set value of Driver [driver] section.
  7. From the Add an option to the rule window, select the ruleflow-group option from the Attribute menu.
  8. Enter trafficViolation in to the ruleflow-group field.
  9. Click Save, and then click Save to confirm your changes.

    Figure 3.7. Suspension rule actions

    rulepanel

Chapter 4. Guided decision tables

Guided decision tables are a wizard-led alternative to uploaded decision table spreadsheets for defining business rules in a tabular format. With guided decision tables, you are led by a UI-based wizard in Business Central that helps you define rule attributes, metadata, conditions, and actions based on specified data objects in your project. After you create your guided decision tables, the rules you defined are compiled into Drools Rule Language (DRL) rules as with all other rule assets.

All data objects related to a guided decision table must be in the same project package as the guided decision table. Assets in the same package are imported by default. After you create the necessary data objects and the guided decision table, you can use the Data Objects tab of the guided decision tables designer to verify that all required data objects are listed or to import other existing data objects by adding a New item.

4.1. Creating a traffic violation guided decision table

Use the Guided Decision Table designer to create the traffic violation guided decision table, which specifies the driver’s specific violation and the resulting fine and points.

Prerequisite

You have created both the Violation and Driver data objects.

Procedure

  1. Log in to Business Central.
  2. Click MenuDesignProjects, then Driver_department_traffic_violations.
  3. Click Add AssetGuided Decision Table, then enter:

    • Guided Decision Table: SpeedViolationRule
    • Package: com.myspace.driver_department_traffic_violations
  4. Select Unique Hit from the Hit Policy menu.
  5. Select Extended entry, values defined in table body in the Table format section.
  6. Click Ok to open the Guided Decision Tables designer.

    Figure 4.1. Guided Decision Tables designer

    dec table

4.1.1. Inserting Violation Type columns

The Violation Type column contains the violation details such as the the driver’s speed and if the driver was under the influence of drugs or alcohol.

Prerequisite

You have created the traffic violation guided decision table.

Procedure

  1. Click ColumnsInsert Column and then select Include advanced options.

    Figure 4.2. Column tab

    column tab
  2. Select Add an Attribute column and click Next.

    Figure 4.3. Add a new column window

    new column
  3. Select Ruleflow-group and click Finish.
  4. Expand Attribute columns and enter trafficViolation in the Default value field.

    Figure 4.4. Attribute columns window

    attrib column
  5. Click Insert Column, select Add a ConditionPattern+Create a new Fact Pattern.
  6. Select Violation from the Fact type menu, enter v in the Binding field, and click OK.

    Figure 4.5. Create a new fact pattern window

    fact pattern
  7. Select Calculation typeLiteral value.

    Figure 4.6. Calculation type options

    literal value
  8. Select Field and then select type from the Field menu.
  9. Select Operator and then equal to from the Operator menu.
  10. Select Value options and enter Speed,Driving while intoxicated,DWI=Driving while under the influence of drugs in the Value list (optional) field.
  11. Select Additional info, enter Violation Type in the Header (description) field, and click Finish.

    Figure 4.7. Violation Type header

    violation columns
  12. Click Insert Column, select Add a ConditionPattern, and select Violation[v] from the Pattern menu.
  13. Select Calculation typePredicateField and enter actualSpeed-speedLimit > $param.
  14. Select Value options, then select Additional info and enter Speed Limit (MPH) > in the Header (description) field.
  15. Click Finish.

    Figure 4.8. Speed Limit (MPH) > header

    speed header
  16. Click Insert Column, select Add a ConditionPattern, and select Violation[v] from the Pattern menu.
  17. Select Calculation typePredicate.
  18. Select Field and enter actualSpeed-speedLimit < $param in the Field field.
  19. Select Operator, select Value options, then select Additional info.
  20. Enter Speed Limit (MPH) < in the Header (description) field and click Finish.

    Figure 4.9. Condition columns

    cond columns

4.1.2. Inserting Fine Amount and Points columns

The Fine Amount* and Points columns contain the fines and points based on the corresponding Violation Type field values.

Prerequisite

You have inserted the Violation Type column in to the traffic violation guided decision table.

Procedure

  1. Click Insert Column, select Set the value of a fieldPattern, and select Violation[v] from the Pattern menu.
  2. Select Field and then fineAmount from the Field menu.
  3. Select Value options, and then select Additional info, and enter Fine Amount in the Header (description) field.
  4. Select the Update engine with changes option and click Finish.

    Figure 4.10. Fine Amount header

    fine amount
  5. Click Insert Column, select Set the value of a fieldPattern, and select Violation[v] from the Pattern menu.
  6. Select Field and then points from the Field menu.
  7. Select Value options, then select Additional info and enter Points in the Header (description) field.
  8. Select the Update engine with changes option and click Finish.

    Figure 4.11. Action columns

    point amount

4.1.3. Inserting guided decision table rows

After you have created your columns in the guided decision table, you can add rows and define rules within the decision table designer.

Prerequisite

You have created the Violation Type, Fine Amount, and Points columns in the traffic violation guided decision table.

Procedure

  1. Click EditorInsertAppend row. Repeat this step to add a total of five table rows.
  2. Fill out the table as shown in the following example:

    Figure 4.12. Populated data fields

    guided dt ds
  3. Click Save, and then click Save to confirm your changes.

Chapter 5. Test Scenarios

Test Scenarios in Red Hat Process Automation Manager enable you to validate the functionality of rules, models, and events before deploying them into production. A test scenario uses data for conditions that resemble an instance of your fact or project model. This data is matched against a specific set of rules and if the expected results match the actual results, the test is successful. If the expected results do not match the actual results, then the test fails.

After you run all test scenarios, the status of the scenarios is reported in a Reporting panel.

Test scenarios can be executed one at a time or as a group. The group execution contains all the scenarios from one package. Test scenarios are independent, so that one scenario cannot affect or modify the other.

5.1. Testing the speed limit scenario

Test the speed limit scenario using the data that you specified when you created the traffic violation guided decision table.

Prerequisites

  • You have created the Driver_department_traffic_violations project.
  • You have created the Violation and Driver data objects.
  • You have created the speed violation guided decision table.

Procedure

  1. Log in to Business Central.
  2. Click MenuDesignProjects, then Driver_department_traffic_violations.
  3. Click Add AssetTest Scenario.
  4. In the Create new Test Scenario window wizard, enter the following values:

    1. Test Scenario: Speed limit 10-20.
    2. Package: select com.myspace.driver_department_traffic_violations.
  5. Click Ok.
  6. Click +GIVEN to open the New input window.
  7. Select Violation from the Insert a new fact menu.
  8. Enter violation in the Fact name field and click Add.
  9. Click Add a field located under Insert 'Violation'[violation] to open the Choose a field to add window.
  10. Select speedLimit from the Choose a field to add menu and click OK.
  11. Click ( 6191 ), and then click Literal value next to speedLimit.
  12. Click Literal value in the Field value window, then enter 40 in the speedLimit field.
  13. Click Insert 'Violation'[violation].
  14. Select type from the Choose a field to add menu in the Choose a field to add window, and click OK.
  15. Click ( 6191 ), and then click Literal value next to Literal value.
  16. Enter Speed in the type field.
  17. Click Insert 'Violation'[violation].
  18. Select actualSpeed from the Choose a field to add menu, and click OK.
  19. Click ( 6191 ), and then click Literal value next to Literal value.
  20. Enter 55 in the actualSpeed field.
  21. Click +Expect to open the New expectation window.
  22. Expand the Rule menu, select Row 1 SpeedViolationRule, and click OK.
  23. Click +GIVEN to open the New input window, enter trafficViolation in the Activate rule flow group field, and click Add.
  24. Click +Expect to open the New expectation window and click Add next to Fact value: violation.
  25. Click Violation 'violation' has values: to open the Choose a field to add window.
  26. Select fineAmount from the Choose a field to add menu and click OK.
  27. Enter 100.0 in the fineAmount: equals field.
  28. Click Violation 'violation' has values: to open the Choose a field to add window.
  29. Select points from the Choose a field to add menu and click OK.
  30. Enter 1 in the points: equals field.
  31. Click Save, and then click Save to confirm your changes.
  32. Click Run scenario.

    Figure 5.1. Speed test results screen

    Speed test results screen

If the values and conditions set in the test scenario meet the requirements as specified in the speed violation guided decision table, the Reporting section at the bottom of the window displays a Success message.

5.2. Testing the driver license suspension scenario

Test the driver license suspension scenario using the data that you specified when you set the Driver License Suspension rules and actions.

Prerequisites

  • You have created the Driver_department_traffic_violations project.
  • You have created the Violation and Driver data objects.
  • You have set the Driver License Suspension rules and actions.

Procedure

  1. Log in to Business Central.
  2. Click MenuDesignProjects, then Driver_department_traffic_violations.
  3. Click Add AssetTest Scenario.
  4. In the Create new Test Scenario window wizard, enter the following values:

    1. Test Scenario: Suspend due to total points.
    2. Package: select com.myspace.driver_department_traffic_violations.
  5. Click Ok.
  6. Click +GIVEN to open the New input window.
  7. Select Driver from the Insert a new fact menu.
  8. Enter driver in the Fact name field and click Add.
  9. Click Add a field located under 'Driver'[driver] to open the Choose a field to add window.
  10. Select totalPoints from the Choose a field to add menu and click OK.
  11. Click ( 6191 ) next to totalPoints, click Literal value, then enter 10 in the totalPoints field.
  12. Click +GIVEN to open the New input window.
  13. Select Violation from the Insert a new fact menu.
  14. Enter violation in the Fact name field and click Add.
  15. Click Add a field located under Insert 'Violation'[violation] to open the Choose a field to add window.
  16. Select points from the Choose a field to add menu and click OK.
  17. Click ( 6191 ), and then click Literal value next to Literal value.
  18. Enter 10 in the points field.
  19. Click +Expect to open the New expectation window.
  20. Expand the Rule menu, select DriverLicenseSuspensionRule, and click OK.
  21. Click +GIVEN to open the New input window, enter trafficViolation in the Activate rule flow group field, and click Add.
  22. Click +Expect to open the New expectation window and click Add next to Fact value: driver.
  23. Click Driver 'driver' has values: to open the Choose a field to add window.
  24. Select state from the Choose a field to add menu and click OK.
  25. Enter suspend in the state: equals field.
  26. Click Save, and then click Save to confirm your changes.
  27. Click Run scenario.

    Result

    The rule is fired and the driver’s license is suspended because the total number of points is >= 20.

    Figure 5.2. Suspension test results screen

    Suspension test results screen

If the values and conditions set in the test scenario meet the requirements that you specified when you set the Driver License Suspension rules and actions, the Reporting section at the bottom of the window displays a Success message.

5.3. Testing the multiple violations scenario

Copy the Suspend due to total points asset and modify it to create the driver license suspension scenario for drivers with multiple violations using the data that you specified when you set the Driver License Suspension rules and actions.

Prerequisites

  • You have created the Driver_department_traffic_violations project.
  • You have created the Violation and Driver data objects.
  • You have set the driver license suspension rules and actions.

Procedure

  1. Log in to Business Central.
  2. Click MenuDesignProjects, then Driver_department_traffic_violations.
  3. Click Suspend due to total pointsCopy, enter Suspend due to multiple violations in the New Asset Name field, and click Make a Copy.
  4. Click SpaceMySpaceDriver_department_traffic_violations, and then select the Suspend due to multiple violations Asset.
  5. Click +GIVEN to open the New input window.
  6. Select Violation from the Insert a new fact menu.
  7. Enter violation2 in the Fact name field and click Add.
  8. Click ( 6191 ) next to points, click Literal value, then enter 5 in the pointsviolation2 field.
  9. In the totalPoints field, change the value from 10 to 5.
  10. Click Save, and then click Save to confirm your changes.
  11. Click Run scenario.

    Figure 5.3. Suspension test results screen

    Suspension test results screen

If the values and conditions set in the test scenario meet the requirements that you specified when you set the Driver License Suspension rules and actions, the Reporting section at the bottom of the window displays a Success message.

Appendix A. Versioning information

Documentation last updated on Friday, May 22, 2020.

Legal Notice

Copyright © 2020 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.