Red Hat Training

A Red Hat training course is available for Red Hat Decision Manager

Designing a decision service using guided rules

Red Hat Decision Manager 7.0

Red Hat Customer Content Services

Abstract

This document describes how to design a decision service using guided rules in Red Hat Decision Manager 7.0.

Preface

As a business analyst or business rules developer, you can define business rules using the guided rules designer in Decision Central. These guided rules are compiled into Drools Rule Language (DRL) and form the core of the decision service for your project.

Prerequisite

The team and project for the guided rules have been created in Decision Central. Each asset is associated with a project assigned to a team. For details, see Getting started with decision services.

Chapter 1. Rule-authoring assets in Red Hat Decision Manager

Red Hat Decision Manager provides several assets that you can use to create business rules for your decision service. Each rule-authoring asset has different advantages, and you might prefer to use one or a combination of multiple assets depending on your goals and needs.

The following table highlights each rule-authoring asset in Decision Central to help you decide or confirm the best method for creating rules in your decision service.

Table 1.1. Rule-authoring assets in Decision Central

AssetHighlightsDocumentation

Guided decision tables

  • Are tables of rules that you create in a UI-based table designer in Decision Central
  • Are a wizard-led alternative to uploaded decision table spreadsheets
  • Provide fields and options for acceptable input
  • Support template keys and values for creating rule templates
  • Support hit policies, real-time validation, and other additional features not supported in other assets
  • Are optimal for creating rules in a controlled tabular format to minimize compilation errors

Designing a decision service using guided decision tables

Uploaded decision tables

  • Are XLS or XLSX decision table spreadsheets that you upload into Decision Central
  • Support template keys and values for creating rule templates
  • Are optimal for creating rules in decision tables already managed outside of Decision Central
  • Have strict syntax requirements for rules to be compiled properly when uploaded

Designing a decision service using uploaded decision tables

Guided rules

  • Are individual rules that you create in a UI-based rule designer in Decision Central
  • Provide fields and options for acceptable input
  • Are optimal for creating single rules in a controlled format to minimize compilation errors

Designing a decision service using guided rules

Guided rule templates

  • Are reusable rule structures that you create in a UI-based template designer in Decision Central
  • Provide fields and options for acceptable input
  • Support template keys and values for creating rule templates (fundamental to the purpose of this asset)
  • Are optimal for creating many rules with the same rule structure but with different defined field values

Designing a decision service using guided rule templates

DRL rules

  • Are individual rules that you define directly in .drl text files
  • Provide the most flexibility for defining rules and other technicalities of rule behavior
  • Can be created in certain standalone environments and integrated with Red Hat Decision Manager
  • Are optimal for creating rules that require advanced DRL options
  • Have strict syntax requirements for rules to be compiled properly

Designing a decision service using DRL rules

Chapter 2. Guided rules

Guided rules are business rules that you create in a UI-based guided rules designer in Decision Central that leads you through the rule-creation process. The guided rules designer provides fields and options for acceptable input based on the data objects for the rule being defined. The guided rules that you define are compiled into Drools Rule Language (DRL) rules as with all other rule assets.

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

Chapter 3. 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.

3.1. Creating data objects

The data objects that you define are the building blocks for rule assets in your project and determine what data your assets and your decision service are based on.

Procedure

  1. Go to MenuDesignProjects and click the project name.
  2. Click Create New AssetData Object.
  3. Enter a unique Data Object name and select the Package where you want the data object to be available for other rule assets. Data objects with the same name cannot exist in the same package. The package that you specify must be the same package where the rule assets that require those data objects have been assigned or will be assigned.

    Importing data objects from other packages

    You can also import an existing data object from another package into the package of the rule asset. In the Project Explorer, expand the asset panel (such as for guided decision tables or guided rules), select the specific asset, and in the asset designer, go to Data Objects → New item to select the object to be imported.

  4. To make your data object persistable, select the Persistable checkbox. Persistable data objects are able to be stored in a database according to the JPA specification. The default JPA is Hibernate.
  5. Click Ok.
  6. In the data object designer, click add field to add a field to the object with the attributes Id, Label, and Type. Required attributes are marked with an asterisk (*).

    • Id: Enter the unique ID of the field.
    • Label: (Optional) Enter a label for the field.
    • Type: Enter the data type of the field.
    • List: Select this check box to enable the field to hold multiple items for the specified type.

      Figure 3.1. Add data fields to a data object

      Add data fields to a data object
  7. Click Create to add the new field, or click Create and continue to add the new field and continue adding other fields.

    Note

    To edit a field, select the field row and use the general properties on the right side of the screen.

Chapter 4. Creating guided rules

Guided rules enable you to define business rules in a structured format, based on the data objects associated with the rules. You can create and define guided rules individually for your project.

Procedure

  1. Go to MenuDesignProjects and click the project name.
  2. Click Create New AssetGuided Rule.
  3. Enter an informative Guided Rule name and select the appropriate Package. The package that you specify must be the same package where the required data objects have been assigned or will be assigned.

    You can also select Use Domain Specific Language (DSL) if any DSL assets have been defined in your project (in the Domain Specific Language Definitions panel in the Project Explorer). These DSL assets will then become usable objects for conditions and actions that you define in the guided rules designer.

  4. Click Ok to create the rule asset.

    The new guided rule is now listed in the Guided Rules panel of the Project Explorer, or in the Guided Rules (with DSL) panel if you selected the Use Domain Specific Language (DSL) option.

  5. Click the Data Objects tab and confirm that all data objects required for your rules are listed. If not, click New item to import data objects from other packages, or create data objects within your package.
  6. After all data objects are in place, return to the Editor tab of the guided rules designer and use the buttons on the right of the editor window to add and define the WHEN (condition) and THEN (action) sections of the rule, based on the available data objects.

    Figure 4.1. The guided rules designer

    The guided rules designer

    The WHEN part of the rule contains the conditions that must be met to execute an action. For example, if a bank requires loan applicants to have over 21 years of age, then the WHEN condition of an "Underage" rule would be Age | less than | 21.

    The THEN part of the rule contains the actions to be performed when the conditional part of the rule has been met. For example, when the loan applicant is under 21 years old, the THEN action would set approved to false, declining the loan because the applicant is under age.

    You can also specify exceptions for more complex rules, such as if a bank may approve of an under-aged applicant when a guarantor is involved. In that case, you would create or import a guarantor data object and then add the field to the guided rule.

  7. After you define all components of the rule, click Validate in the upper-right toolbar of the guided rules designer to validate the guided rule. If the rule validation fails, address any problems described in the error message, review all components in the rule, and try again to validate the rule until the rule passes.
  8. Click Save in the guided rules designer to save your work.

For more details about adding conditions to rules, see Section 4.1, “Adding WHEN conditions in guided rules”.

For more details about adding actions to rules, see Section 4.2, “Adding THEN actions in guided rules”.

4.1. Adding WHEN conditions in guided rules

The WHEN part of the rule contains the conditions that must be met to execute an action. For example, if a bank requires loan applicants to have over 21 years of age, then the WHEN condition of an "Underage" rule would be Age | less than | 21. You can set simple or complex conditions to determine how and when your rules are applied.

Prerequisite

All data objects required for your rules have been created or imported and are listed in the Data Objects tab of the guided rules designer.

Procedure

  1. In the guided rules designer, click the plus icon ( 5686 ) on the right side of the WHEN section.

    The Add a condition to the rule window with the available condition elements opens.

    Figure 4.2. Add a condition to the rule

    Add a condition to the rule

    The list includes the data objects from the Data Objects tab of the guided rules designer, any DSL objects defined for the package (if you selected Use Domain Specific Language (DSL) when you created this guided rule), and the following standard options:

    • The following does not exist: Use this to specify facts and constraints that must not exist.
    • The following exists: Use this to specify facts and constraints that must exist. This option is triggered on only the first match, not subsequent matches.
    • Any of the following are true: Use this to list facts and constraints that must be true.
    • From: Use this to define a From conditional element for the rule.
    • From Accumulate: Use this to define an Accumulate conditional element for the rule.
    • From Collect: Use this to define a Collect conditional element for the rule.
    • From Entry Point: Use this to define an Entry Point for the pattern.
    • Free form DRL: Use this to insert a free-form DRL field where you can define condition elements freely, without the guided rules designer.
  2. Choose a condition element (for example, LoanApplication) and click Ok.
  3. Click the condition element in the guided rules designer and use the Modify constraints for LoanApplication window to add a restriction on a field, apply multiple field constraints, add a new formula style expression, apply an expression editor, or set a variable name.

    Figure 4.3. Modify a condition

    Modifying a condition
    Note

    A variable name enables you to identify a fact or field in other constructs within the guided rule. For example, you could set the variable of LoanApplication to a and then reference a in a separate Bankruptcy constraint that specifies which application the bankruptcy is based on.

    a : LoanApplication()
    Bankruptcy(application == a ).

    After you select a constraint, the window closes automatically.

  4. Choose an operator for the restriction (for example, greater than) from the drop-down menu next to the added restriction.
  5. Click the edit icon ( 6191 ) to define the field value. The field value can be a literal value, a formula, or a full MVEL expression.
  6. To apply multiple field constraints, click the condition and in the Modify constraints for LoanApplication window, select All of(And) or Any of(Or) from the Multiple field constraint drop-down menu.

    Figure 4.4. Add multiple field constraints

    Modifying a condition
  7. Click the constraint in the guided rules designer and further define the field value.
  8. After you define all condition components of the rule, click Validate in the upper-right toolbar of the guided rules designer to validate the guided rule conditions. If the rule validation fails, address any problems described in the error message, review all components in the rule, and try again to validate the rule until the rule passes.
  9. Click Save in the guided rules designer to save your work.

4.2. Adding THEN actions in guided rules

The THEN part of the rule contains the actions to be performed when the WHEN condition of the rule has been met. For example, when a loan applicant is under 21 years old, the THEN action might set approved to false, declining the loan because the applicant is under age. You can set simple or complex actions to determine how and when your rules are applied.

Prerequisite

All data objects required for your rules have been created or imported and are listed in the Data Objects tab of the guided rules designer.

Procedure

  1. In the guided rules designer, click the plus icon ( 5686 ) on the right side of the THEN section.

    The Add a new action window with the available action elements opens.

    Figure 4.5. Add a new action to the rule

    Add a new action to the rule

    The list includes insertion and modification options based on the data objects in the Data Objects tab of the guided rules designer, and on any DSL objects defined for the package (if you selected Use Domain Specific Language (DSL) when you created this guided rule):

    • Change field values of: Use this to set the value of fields on a fact (such as LoanApplication) without notifying the decision engine of the change.
    • Delete: Use this to delete a fact.
    • Modify: Use this to specify fields to be modified for a fact and to notify the decision engine of the change.
    • Insert fact: Use this to insert a fact and define resulting fields and values for the fact.
    • Logically Insert fact: Use this to insert a fact logically into the decision engine and define resulting fields and values for the fact. The Red Hat Decision Manager decision engine is responsible for logical decisions on insertions and retractions of facts. After regular or stated insertions, facts have to be retracted explicitly. After logical insertions, facts are automatically retracted when the conditions that originally asserted the facts are no longer true.
    • Add free form DRL: Use this to insert a free-form DRL field where you can define condition elements freely, without the guided rules designer.
    • Call method on: Use this to invoke a method from another fact.
  2. Choose an action element (for example, Modify) and click Ok.
  3. Click the action element in the guided rules designer and use the Add a field window to select a field.

    Figure 4.6. Add a field

    Add a field

    After you select a field, the window closes automatically.

  4. Click the edit icon ( 6191 ) to define the field value. The field value can be a literal value or a formula.
  5. After you define all action components of the rule, click Validate in the upper-right toolbar of the guided rules designer to validate the guided rule actions. If the rule validation fails, address any problems described in the error message, review all components in the rule, and try again to validate the rule until the rule passes.
  6. Click Save in the guided rules designer to save your work.

4.3. Adding other rule options

You can also use the rule designer to add metadata within a rule, define additional rule attributes (such as salience and no-loop), and freeze areas of the rule to restrict modifications to conditions or actions.

Procedure

  1. In the rule designer, click (show options…​) under the THEN section.
  2. Click the plus icon ( 5686 ) on the right side of the window to add options.
  3. Select an option to be added to the rule:

    • Metadata: Enter a metadata label and click the plus icon ( 5686 ). Then enter any needed data in the field provided in the rule designer.
    • Attribute: Select from the list of rule attributes. Then further define the value in the field or option displayed in the rule designer.
    • Freeze areas for editing: Select Conditions or Actions to restrict the area from being modified in the rule designer.

      Figure 4.7. Rule options

      Additional rule options
  4. Click Save in the rule designer to save your work.

4.3.1. Rule attributes

Rule attributes are additional specifications that you can add to business rules to modify rule behavior. The following table lists the names and supported values of the attributes that you can assign to rules:

Table 4.1. Rule attributes

AttributeValue

salience

An integer defining the priority of the rule. Rules with a higher salience value are given higher priority when ordered in the activation queue.

Example: salience 10

enabled

A Boolean value. When the option is selected, the rule is enabled. When the option is not selected, the rule is disabled.

Example: enabled true

date-effective

A string containing a date and time definition. The rule can be activated only if the current date and time is after a date-effective attribute.

Example: date-effective "4-Sep-2018"

date-expires

A string containing a date and time definition. The rule cannot be activated if the current date and time is after the date-expires attribute.

Example: date-expires "4-Oct-2018"

no-loop

A Boolean value. When the option is selected, the rule cannot be reactivated (looped) if a consequence of the rule re-triggers a previously met condition. When the condition is not selected, the rule can be looped in these circumstances.

Example: no-loop true

agenda-group

A string identifying an agenda group to which you want to assign the rule. Agenda groups allow you to partition the agenda to provide more execution control over groups of rules. Only rules in an agenda group that has acquired a focus are able to be activated.

Example: agenda-group "GroupName"

activation-group

A string identifying an activation (or XOR) group to which you want to assign the rule. In activation groups, only one rule can be activated. The first rule to fire will cancel all pending activations of all rules in the activation group.

Example: activation-group "GroupName"

duration

A long integer value defining the duration of time in milliseconds after which the rule can be activated, if the rule conditions are still met.

Example: duration 10000

timer

A string identifying either int (interval) or cron timer definition for scheduling the rule.

Example: timer "*/5 * * * *" (every 5 minutes)

calendar

A Quartz calendar definition for scheduling the rule.

Example: calendars "* * 0-7,18-23 ? * *" (exclude non-business hours)

auto-focus

A Boolean value, applicable only to rules within agenda groups. When the option is selected, the next time the rule is activated, a focus is automatically given to the agenda group to which the rule is assigned.

Example: auto-focus true

lock-on-active

A Boolean value, applicable only to rules within rule flow groups or agenda groups. When the option is selected, the next time the ruleflow group for the rule becomes active or the agenda group for the rule receives a focus, the rule cannot be activated again until the ruleflow group is no longer active or the agenda group loses the focus. This is a stronger version of the no-loop attribute, because the activation of a matching rule is discarded regardless of the origin of the update (not only by the rule itself). This attribute is ideal for calculation rules where you have a number of rules that modify a fact and you do not want any rule re-matching and firing again.

Example: lock-on-active true

ruleflow-group

A string identifying a rule flow group. In rule flow groups, rules can fire only when the group is activated by the associated rule flow.

Example: ruleflow-group "GroupName"

dialect

A string identifying either JAVA or MVEL as the language to be used for code expressions in the rule. By default, the rule uses the dialect specified at the package level. Any dialect specified here overrides the package dialect setting for the rule.

Example: dialect "JAVA"

Chapter 5. Next steps

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.