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
3.1. Creating the Driver License Suspension rule
Create the Driver license suspension rule using the guided rules designer.
Prerequisites
You have created both the Violation and Driver data objects.
Procedure
-
Click Menu
Design Projects, then Driver_department_traffic_violations. Click Add Asset
Guided Rule, then enter the following values: -
Guided Rule:
DriverLicenseSuspensionRule
-
Package:
com.myspace.driver_department_traffic_violations
-
Guided Rule:
Click Ok to open the Guided Rule designer.
Figure 3.2. Create new guided rule window
3.2. Setting the Suspension rule conditions
Set the Suspension rule conditions that are used to determine the driver’s violation.
Prerequisites
You have created the Driver License Suspension rule.
Procedure
- Click ( ) 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
- Click the There is a Driver label to open the Modify constraints for Driver window.
-
Enter
driver
in the Variable name field and click Set. - Click There is a Driver[driver] and click Expression editor.
- Click [not bound] to open the Expression editor.
-
In the Bind the Expression to a new variable field, enter:
previousPts
and click Set. - From the Choose menu, select totalPoints.
- Click ( ) next to line 1 (the previousPts label) to open the Add a condition to the rule window.
- Select From Accumulate and click Ok.
- Click click to add pattern above the From Accumulate label and select Number from the choose fact type menu.
- Click There is a number label to open the Modify contraints for Number window.
- Click Expression editor and select intValue() from the [not bound]: Choose menu.
- Click [not bound] to open the Expression editor.
-
In the Bind the Expression to a new variable field, enter:
totalNewPoints
and click Set. - Click click to add pattern and select Violation from the choose fact type menu.
- Click All Violation with: to open the Modify contraints for Violation window and select points from the Add a restriction on a field menu.
- Click please choose next to the points label and select greater than.
- Click ( ), and then click Literal value.
- Click the points label to open the Add a field window.
-
Enter
vPoints
and click Set. -
In the Function field, enter
sum(vPoints)
. -
Select greater than or equal to from the totalNewPoints
please choose menu. -
Click (
), click New formula, and enter
20-previousPts
in the new field. - Click Save, and then click Save to confirm your changes.
Figure 3.4. Suspension Rule conditions
3.3. Setting the Suspension rule actions
Set the Suspension rule actions that are used to determine a driver’s penalties, including points and fine amounts. These values are based on the Suspension rule conditions.
Prerequisites
You have set the Suspension rule conditions.
Procedure
Click (show options…) next to the THEN label.
Figure 3.5. show options selection
- Click ( ) next to the THEN label and select Change field values of driver, and click Ok.
- Click the Set value of Driver [driver] field and select state from the Add field menu.
- Click ( ) next to state in the Set value of Driver [driver] section to open the Field value window.
Click Literal value and enter
suspend
in the new field.Figure 3.6. New field
- Click ( ) next to the (options) label below the Set value of Driver [driver] section.
- From the Add an option to the rule window, select the ruleflow-group option from the Attribute menu.
-
Enter
trafficViolation
in to the ruleflow-group field. Click Save, and then click Save to confirm your changes.
Figure 3.7. Suspension rule actions