Getting started with decision services

Red Hat Decision Manager 7.0

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 Decision Central in Red Hat Decision 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. In this chapter, you will create the Driver department traffic violations project.

Procedure

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

    Tip: Red Hat Decision Manager provides a default space called myteam, 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

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 Date of Birth to specify personal details for loan application rules. These custom data types determine what data your assets and your decision service are based on.

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

Figure 2.1. Driver department traffic violations data objects

data model

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. Log in to Decision Central. Click MenuDesignProjects, then Driver department traffic violations.
  2. Click Create New AssetData Object.
  3. In the Create new Data Object wizard, enter the following values:

    • Data Object: Violation.
    • Package: select com.myteam.driverdepartmenttrafficviolations.
  4. Click Ok.

    Figure 2.2. Create new Data Object window

    data object

2.1.1. Adding the Violation data object data fields

Prerequisites

You have created the Violation data object.

Procedure

The data fields in the Violation data object define the available constraints that you can select from when you define your violation rules later.

  1. In the Violation-general properties section, locate the Label property and enter: Violation.

    Figure 2.3. 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, 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.4. 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. Log in to Decision Central. Click MenuDesignProjects, then Driver department traffic violations.
  2. Click Create New AssetData Object.
  3. In the Create new Data Object wizard, enter the following values:

    • Data Object: Driver.
    • Package: select com.myteam.driverdepartmenttrafficviolations.
  4. Click Ok.

    Figure 2.5. Create new Data Object window

    data object2

2.2.1. Adding the Driver data object data fields

Prerequisites

You have created the Driver data object.

Procedure

The data fields in the Driver data object define the driver details that you can select from when you define your violation rules later.

  1. In the 'Driver'- general properties section, locate the Label property and enter: Driver.
  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.myteam.driverdepartmenttrafficviolations.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, 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.6. 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

The Driver license suspension rule is created using the Guided Rule wizard and is comprised of various conditions and their resulting actions.

Prerequisite

Created both the Violation and Driver data objects.

Procedure

  1. Log in to Decision Central. Click MenuDesignProjects, then Driver department traffic violations.
  2. Click Create New AssetGuided Rule, then enter:

    • Guided Rule: DriverLicenseSuspensionRule
    • Package: com.myteam.driverdepartmenttrafficviolations
  3. 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

The Suspension rule contains 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. . . Select Driver and click Ok.

    Figure 3.3. Create new Guided Rule window

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

Figure 3.4. Suspension Rule conditions

rule conditions

3.3. Setting the Suspension rule actions

The Suspension rule actions determine a driver’s resulting penalties including points and fine amounts based on the Suspension rule conditions.

Prerequisite

You have created 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, then click Ok.
  3. Click the Set value of Driver [driver] field and select state from the Add field pull-down 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 pull-down menu.
  8. Enter trafficViolation in to the ruleflow-group field.
  9. Click Save, 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 Decision 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 the necessary data objects and the guided decision table are created, 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

Created both the Violation and Driver data objects.

Procedure

  1. Log in to Decision Central. Click MenuDesignProjects, then Driver department traffic violations.
  2. Click Create New AssetGuided Decision Table, then enter:

    • Guided Decision Table: SpeedViolationRule
    • Package: com.myteam.driverdepartmenttrafficviolations
  3. Select Unique Hit from the Hit Policy pull-down menu.
  4. Select Extended entry, values defined in table body in the Table format section.
  5. 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

Created the traffic violation guided decision table.

Procedure

  1. Click ColumnsInsert Column and 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 pull-down 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 pull-down menu.
  9. Select Operator and then equal to from the Operator pull-down 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 pull-down 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 pull-down 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

Inserted the Violation Type column.

Procedure

  1. Click Insert Column, select Set the value of a fieldPattern, and select Violation[v] from the Pattern pull-down menu.
  2. Select Field and then fineAmount from the Field pull-down menu.
  3. Select Value options, 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 pull-down menu.
  6. Select Field and then points from the Field pull-down 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
  9. Click Columns, expand Attribute columns, and select the Hide column option.

    Figure 4.12. Column attributes

    hide column

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.

Procedure

  1. Click EditorInsertAppend row. Repeat this step to add a total of five table rows.

    Figure 4.13. Appending rows

    append row
  2. Fill out the table as shown in the following example.

    Figure 4.14. Populated data fields

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

Chapter 5. Test Scenarios

Test Scenarios in Red Hat Decision 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 given 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.

Figure 5.1. Speed test scenario screen

Speed test Scenario screen

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 speed violation guided decision table.

Prerequisites

  • Created the Driver department traffic violations project
  • Created the Violation and Driver data objects
  • Created the speed violation guided decision table

Procedure

  1. Log in to Decision Central. Click MenuDesignProjects, then Driver department traffic violations.
  2. Click ProjectsCreate New AssetTest Scenario.
  3. In the Create new Test Scenario window wizard, enter the following values:

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

    Figure 5.2. Speed test results screen

    Speed test results screen

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

  • Created the Driver department traffic violations project
  • Created the Violation and Driver data objects
  • Set the Driver License Suspension rules and actions

Procedure

  1. Log in to Decision Central. Click MenuDesignProjects, then Driver department traffic violations.
  2. Click Create New AssetTest Scenario.
  3. In the Create new Test Scenario window wizard, enter the following values:

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

    Suspension test results screen

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

  • Created the Driver department traffic violations project
  • Created the Violation and Driver data objects
  • Set the driver license suspension rules and actions

Procedure

  1. Log in to Decision Central. Click MenuDesignProjects, then Driver department traffic violations.
  2. Click Suspend due to total pointsCopy, enter Suspend due to multiple violations in the New Asset Name field, and click Make a Copy.

    Figure 5.4. Make a copy window

    Making a copy panel
  3. Click SpacemyteamDriver department traffic violations, and then select the Suspend due to multiple violations Asset.
  4. Click +GIVEN to open the New input window.
  5. Select Violation from the Insert a new fact pull-down menu.
  6. Enter violation2 in the Fact name field and click Add.
  7. Click 6191 next to points, click Literal value, then enter 5 in the pointsviolation2 field.
  8. In the totalPoints field, change the value from 10 to 5.
  9. Click Save, then click Save to confirm your changes.
  10. Click Run scenario.

    Figure 5.5. Suspension test results screen

    Suspension test results screen

Appendix A. Versioning information

Documentation last updated on: Monday, October 1, 2018.

Legal Notice

Copyright © 2018 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, 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 Software Collections 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.