© ILOG 2002. All rights reserved 1
ILOG JRules workshopILOG JRules workshop
Lab: Rule Tech
Developing Business Rules
1
Lab: Rule Tech
�Lab goals
� Basic concepts
� Step 1: prepare the BOM and rule structure� Step 1: prepare the BOM and rule structure
� Step 2: write and execute rules
� Step 3: synchronize to RTS
� Step 4: deploy to RES
2
� Step 5: test the project with TDS
� Summary
© ILOG 2002. All rights reserved 2
� Provide hands on experience of ILOG Tools for developing a Business
Rule Application
� The Lab will follow all the steps necessary to create a working Business
Rules application
Objectives
� Mapping XML Schemas to create the Business Object Model (BOM)
� Preparing the Business terms & vocabulary
� Writing Business Rules, Decision Tables
� Preparing for deployment & execution with ruleflow and parameters
� Testing in the development environment
� Learn how to deploy rules to the Rule Execution Server (RES).
� Test the project with Transparent Decision Services (TDS)
� See how to execute rules from a client application.
3
� See how to execute rules from a client application.
� Provide enough JRules Knowledge to enable you to evaluate BRMS
technologies
Lab: Rule Tech
• Lab goals
�Basic concepts
� Step 1: prepare the BOM and rule structure� Step 1: prepare the BOM and rule structure
� Step 2: write and execute rules
� Step 3: synchronize to RTS
� Step 4: deploy to RES
4
� Step 5: test the project with TDS
� Summary
© ILOG 2002. All rights reserved 3
Basic Concepts
� Rule projects are managed in the Rule Studio, Eclipse with
dedicated editors and plug-ins
5
� The following types of projects exists:
� Rule project:
� rule and BOM artifacts
Lab: Rule Tech
� rule and BOM artifacts
� RuleApp project:
� packaging for RES deployment
� Rule project for team server
� Import of a RTS project
� Java project for Rules
� Java application without RES
6
Java application without RES
� Java project for RuleApps
� Application with RES
� RES configuration project
� Configurations for the RES
© ILOG 2002. All rights reserved 4
Lab: Rule Tech
� Good practice to be observed while rule
application developmentgp
� Hint about how to use the tools for specific
tasks
� To reference specific resources of the Eclipse
workspace we will use the following
hint
7
workspace we will use the following
convention:
� //project/path/resource
Lab: Rule Tech
• Lab goals
• Basic concepts
�Step 1: prepare the BOM and rule structure�Step 1: prepare the BOM and rule structure
� Step 2: write and execute rules
� Step 3: synchronize to RTS
� Step 4: deploy to RES
8
� Step 5: test the project with TDS
� Summary
© ILOG 2002. All rights reserved 5
Step 1: Prepare the BOM (1/9)
� Before writing any rules a vocabulary must be prepared
� The vocabulary is defined by a Business Object Model
(BOM)(BOM)
� BOM classes are “Terms”
� Class members are “Phrases” to be used as conditions or
actions
� A BOM is based on an eXecutable Object Model (XOM)
� XOM can be Java classes, XML Schemas, WSDL
9
� XOM can be Java classes, XML Schemas, WSDL
� Not necessarily one to one mapping. A BOM can have virtual
artifacts with explicit BOM to XOM mapping defined
Step 1: Prepare the BOM (2/9)
10
© ILOG 2002. All rights reserved 6
� Rule Studio provides a dedicated editor to prepare the
BOM
Step 1: Prepare the BOM (3/9)
Term
BOM class
editor
Term
verbalization
BOM
navigation
Discrete domain
definition
11
Rule category
applicability
Custom BOM
to XOM
mapping
Step 1: Prepare the BOM (4/9)
Phrase
verbalization
Class member editor
Discrete domain
definition
Rule category
applicability
12
definition
Custom BOM to
XOM mapping
© ILOG 2002. All rights reserved 7
� Open Rule Studio:
� Start->All programs->ILOG JRules 6.7-> ILOG Rule Studio
� When prompted select the workspace in C://JRulesWorkshop/labs/step-1
� Switch to Rule perspective (if required)
Step 1: Prepare the BOM (5/9)
� In the workspace you will find a rule project « credit_rules »
� The rule project contains one element: “bom”
� The rule project also contains a schema XSD:
//credit_rules/schemas/credit.xsd
� The bom element contains a BOM-entry named « model » created from this
schema
� Explore the content of the BOM-entry « //credit_rules/bom/model ». You can
expand the packages and double-click in the class Result to open the editor
� We will create another BOM-entry from the schema « credit.xsd »
ILOG JRules can mix Java classes and XML Schemas in the same
rule project
13
hint
Step 1: Prepare the BOM (6/9)
BOM folder
BOM Entry
BOM class
created from the
schema
« credit.xsd »
14
Schema XSD
© ILOG 2002. All rights reserved 8
� Create a new BOM entry:
� Switch to the Rule perspective (if required)
� Right click on “//credit_rules/bom” and select New->BOM Entry
� name it « model2 »
� Check “Create a BOM from a XOM” and next
Step 1: Prepare the BOM (7/9)
� Check “Create a BOM from a XOM” and next
� Click on “Browse XOM …” and select “credit.xsd”
� Check to verbalize the top three classes (Borrower, Property and Request in the
package “com.ilog.workshop.model”) and click next
15
� Create a new BOM entry (cont):
� uncheck “Setters” and click finish
This is because classes in this package are used for input data, we
don’t want to modify this data as result of the rule execution
Step 1: Prepare the BOM (8/9)
don’t want to modify this data as result of the rule execution
Analyse your business
domain and avoid the
verbalization of attributes not
required in the rules. This
way the resulting business
gp
16
way the resulting business
language will be more
compact and easy to use
© ILOG 2002. All rights reserved 9
� Double-click in the new BOM entry to open the BOM editor and
check the ‘Terms’ (Click Edit term) and phrases created by the
verbalization for the different classes and members
Step 1: Prepare the BOM (9/9)
17
� BOM customization:
� We’re going to define a new “virtual” attribute representing the loan-to-value.
This is calculated as the ratio between the requested amount and the appraised
value of the property
Step 1: prepare the BOM (optional)
value of the property
� Double click in the class Request to open the BOM editor on this class
� In the member section click New
18
� Define a new attribute named “LTV” of
type int
� Double click on the new attribute
to open the BOM-member editor
on this member
© ILOG 2002. All rights reserved 10
� BOM customisation (cont):
� Check “Read Only” radio button
Step 1: prepare the BOM (optional)
� In the “Member Verbalization” section click to create a default verbalization and
check the resulting phrase
19
� BOM customization:
� In the “BOM to XOM Mapping” section of the member editor write the
code of the new member in the getter section:
Step 1: prepare the BOM (optional)
return (int) ((this.amount*100.0) / this.property.estimatedValue);
gp
Adding virtual members helps to create business languages more
expressive. Compare the following two equivalent conditions:
20
© ILOG 2002. All rights reserved 11
Step 1: Prepare rule structure (1/7)
� A rule service is defined by a ruleset containing:
� a set of rules artifacts grouped into several packages
� a ruleflow or a main function orchestrating the execution of the rules
� a set of input/output parameters� a set of input/output parameters
� a set of local variables
� For the Labs we are going to create a rule project to define a rule
service with the following characteristics:
� 4 rule packages grouping rules with the same functionality
� Eligibility, Scoring , Acceptance, Rejection
� a ruleflow named “decision process”
� one input parameter of the type com.ilog.workshop.model.Request
� one output parameter of type com.ilog.workshop.model.Result
21
� one output parameter of type com.ilog.workshop.model.Result
Rule project structure and rule packaging should be carefully designed. This
will depend on the results from analysing your rules
gp
Step 1: Prepare rule structure (2/7)
� Create rule packages
� Right click in the chapter “rules” of the rule project “credit_rules” and
select new->Rule Package, name it “Rejection” and finish
� Rule packages “Scoring”, “Acceptance” and “Rejection” already exist� Rule packages “Scoring”, “Acceptance” and “Rejection” already exist
� The rule project should be like this:
22
© ILOG 2002. All rights reserved 12
Step 1: Prepare rule structure (3/7)
� Create the parameters
� Right click in the “credit-rules” rule project and select “Properties”
� In the properties editor select “Ruleset Parameters”
� Click “Add…” button to create the “request” ruleset parameter with � Click “Add…” button to create the “request” ruleset parameter with
name, type, direction and verbalization as show below
� “result” has already been completed
23
� Create the variables
� Right click on the project « credit_rules » and select New->Variable Set
� In the properties editor, choose a name e.g. « Variable List », click Finish
� Click on "Add…" to create
Step 1: Prepare rule structure (4/7)
� Click on "Add…" to create
two variables names “appProperty” and “client”,
types and verbalizations like the following:
24
© ILOG 2002. All rights reserved 13
Step 1: Prepare rule structure (5/7)
� Create the ruleflow
� Right click in the “//credit_rules/rules” chapter and select “New->Ruleflow”,
name it “decision process” and finish
� Using the toolbar add a start node, an end node and a choice node
� Drag & drop the 4 rule packages from the “Rule Explorer” tree on the left to
the edition area of the flow.
� Select the transition tool and connect the different nodes like in the
following figure:
25
� You can automatically arrange the graph using the layout tools
hint
Step 1: Prepare rule structure (6/7)
� Create the ruleflow
� In the “Diagram” tab of the ruleflow editor select the links going out
from choice node and move to the “Transition” tab to fill the conditions
like in the figure
Update the transition to add
the condition
26
© ILOG 2002. All rights reserved 14
� Initialize result:
� We need to initialize ‘result’ output parameter
� Select the first task in the main ruleflow and then
select the tab “Task”
Step 1: Prepare rule structure (7/7)
� Expand the “Initial Action” section
and review the initialization code.
� Uncomment the last two lines
27
� Initialization Explanation:
� In the previous step, we initialized the results. This is typical in a rule
flow.
� In an initialization it is common practice to set a value to 0, true, or
false. The rules will then populate the value to non-zero, or negate or
Step 1: Initialization Explanation
false. The rules will then populate the value to non-zero, or negate or
affirm the Boolean value.
� In our case, the request is accepted, and the various tests (rules) will
determine if it is not accepted.
gp
28
© ILOG 2002. All rights reserved 15
Lab: Rule Tech
• Lab goals
• Basic concepts
• Step 1: prepare the BOM and rule structure• Step 1: prepare the BOM and rule structure
�Step 2: write and execute rules
� Step 4: synchronize to RTS
� Step 5: deploy to RES
29
� Step 6: test the project with TDS
� Summary
Step 2: Write & execute rules (1/16)
� Using ILOG JRules, business logic is expressed using
rule artifacts based on the vocabulary of all the “visible”
BOM’sBOM’s
Rule Artifacts
business rules decision tables decision trees ruleflows
30
BOM
Vocabulary
© ILOG 2002. All rights reserved 16
Step 2: Write & execute rules (2/16)
� Anatomy of a rule
rule name rule documentation rule category
definitions
conditions
actions
31
parameter
actions
variable value of BOM attribute
Step 2: Write & execute rules (3/16)
� Create a business rule
If you didn’t complete previous step you can start from workspace step-2
(File->Switch Workspace)
hint
� Create a business rule
� Right-click in the chapter “credit-rules/rules/Eligibility” and select “New-
>Business Rule”, name it “CheckNetValue” and click finish
32
© ILOG 2002. All rights reserved 17
Step 2: Write & execute rules (4/16)
� Create a business rule
� The text rule editor opens
ILOG JRules text rule editor
sticks to the eclipse code
development best practices:
� Write the text of the rule in the
code area
� At any moment ctrl-space
shows contextual code
hint
33
shows contextual code
completion options grouped by
the starting characters.
� Click ctrl-space again to show
the full list of code completion
options.
Step 2: Write & execute rules (5/16)
� Create a business rule (cont)
� Make the following sequence of selections of the code completion options
type the name of type the name of
the variable here
and ctrl-space
type “th” and ctr-
space to get more
focus of code
completion options
34
© ILOG 2002. All rights reserved 18
Step 2: Write & execute rules (6/16)
� Create a business rule
� Select ‘;’ to finish with the definition part of the rule
� Select ‘if
’ to continue with the condition part of the
rule
35
rule
Step 2: Write & execute rules (7/16)
Step 3: Write & execute rules – Hands on� Create a business rule
� Continue selecting code completion options until you have defined the
rule shown below
� Don’t forget to save � Don’t forget to save
36
© ILOG 2002. All rights reserved 19
Step 2: Write & execute rules (8/16)
� Create a decision table
� A decition table is created by right-clicking on the rule package
“New->Decision Table”
� Within Scoring, the Decision Table ScoreByStabilityAtWork has
been created for you to complete
37
Step 2: Write & execute rules (9/16)
� Create a decision table
� The Decision Table has been partially
filled in
� The first column, “Self Employed”, is � The first column, “Self Employed”, is
created with the condition that “client is
employer”.
� This value can be true or false and you
will fill it in later
38
© ILOG 2002. All rights reserved 20
Step 2: Write & execute rules (10/16)
� Create a decision table
� Double click in the header of the second column named “B”
� Write “Months in Position” in the “Title” input
� Click in