5-26 Oracle Fusion Middleware Users Guide for Oracle Business Rules
5.4.2 How to Create an Application for Order Approval
To work with Oracle Business Rules, you first create an application in Oracle JDeveloper.
To create an application for order approval: 1.
In the Application Navigator, click New Application. 2.
In the Name your application dialog, enter the name and location for the new application.
a. In the Application Name field, enter an application name. For example, enter
OrderApprovalApp .
b. In the Directory field, specify a directory name or accept the default.
c. In the Application Package Prefix field, enter an application package prefix,
for example com.example.order. The prefix, followed by a period, applies to objects created in the initial project
of an application.
d.
For an SOA composite with Oracle Business Rules, in the Application Template area select SOA Application for the application template. For
example, see Figure 5–18
.
e. Click Next.
Figure 5–18 Adding the Order Approval Application
3.
In the Name your project page enter the name and location for the project.
a. In the Project Name field, enter a name. For example, enter OrderApproval.
b.
Enter or browse for a directory name, or accept the default.
c. For an Oracle Business Rules project, in the Project Technologies area ensure
that SOA, ADF Business Components, Java, and XML are in the Selected area on the Project Technologies tab, as shown in
Figure 5–19 . If an item is missing,
Working with Decision Tables 5-27
select it in the Available pane and add it to the Selected pane using the Add button.
Figure 5–19 Adding a Project to an Application
4. Click Finish.
5.4.3 How to Create a Business Rule Service Component for Order Approval
After creating a project in Oracle JDeveloper you need to create a Business Rule Service component within the project. When you add a business rule you can create
input and output variables to provide input to the service component and to obtain results from the service component.
To use business rules with Oracle JDeveloper, you do the following:
■
Add a business rules service component
■
Create input and output variables for the service component
■
Create an Oracle Business Rules dictionary in the project
To create a business rule service component: 1.
In the Application Navigator, in the OrderApproval project expand SOA Content and double-click composite.xml to launch the SOA composite editor this may
already be open after you create the project.
2. From the Component Palette, drag-and-drop a Business Rule from the Service
Components
area of the SOA menu to the Components lane of the
composite.xml editor.
Oracle JDeveloper displays a Create Business Rules page, as shown in Figure 5–20
.
5-28 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Figure 5–20 Adding a Business Rule Dictionary with the Create Business Rules Dialog
3. To add an input, from the list next to the Add icon select Input to enter input for
the business rule.
4. In the Type Chooser dialog, click the Import Schema File... icon. This displays the
Import Schema File dialog, as shown in Figure 5–21
.
Figure 5–21 Import Schema File with Type Chooser
5. In the Import Schema dialog click Browse Resources to choose the XML schema
elements for the input variable of the process. This displays the SOA Resource Lookup dialog.
Working with Decision Tables 5-29
6.
In the SOA Resource Lookup dialog, navigate to find the order.xsd schema file and click OK.
7. In the Import Schema File dialog, make sure Copy to Project is selected, as shown
in Figure 5–22
.
Figure 5–22 Importing the Order.xsd Schema File
8. In the Import Schema File dialog, click OK.
9. If the Localize Files dialog displays, click OK to copy the schema to the composite
process directory.
10. In the Type Chooser, navigate to the Project Schemas Files folder to select the input
variable. For this example, select CustomerOrder as the input variable.
11. On the Type Chooser window, click OK. This displays the Create Business Rules
dialog, as shown in Figure 5–23
.
5-30 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Figure 5–23 Create Business Rules Dialog with CustomerOrder Input
12. In a similar manner, add the output fact type OrderApproval from the imported
order.xsd .
13. In the Create Business Rules dialog, select Expose as Composite Service, as shown
in Figure 5–24
.
Figure 5–24 Create Business Rules Dialog with Input and OrderApproval Output
14. Click OK. This creates the Business Rule component and Oracle JDeveloper shows
the Business Rule in the canvas workspace, as shown in Figure 5–25
.
Working with Decision Tables 5-31
Figure 5–25 Business Rules Component in OrderApproval Composite
The business rule service component enables you to integrate your SOA composite application with a business rule. This creates a business rule dictionary and enables
you to execute business rules and make business decisions based on the rules.
5.4.4 How to View Data Model Elements for Order Approval
Before adding rules you need to create the Oracle Business Rules data model. The data model contains the business data definitions types and definitions for facts that you
use to create rules. For example, for this sample the data model includes the XML schema elements from order.xsd that you specify when you define inputs and
outputs for the business rule activity.
At times when you work with Rules Designer to create a rule or a Decision Table, you may need to create or modify elements in the data model.
To view data model elements for Oracle business rules: 1.
Select the composite tab with the value composite.xml, and in the Components lane select the business rule this surrounds the component, OracleRules1 with a
dashed selection box.
2.
Double-click the selection box to launch Rules Designer.
3. In Rules Designer select the Facts navigation tab.
4. Select XML Facts tab in the Facts navigation tab as shown in
Figure 5–26 .
5-32 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Figure 5–26 Opening a Business Rules Dictionary with Rules Designer
5.4.5 How to Add Bucketsets to the Data Model for Order Approval
To use a Decision Table you need to define bucketsets that specify how to draw values for each cell for the conditions that constitute the Decision Table. For this example the
bucketsets are defined with a list of ranges that you define in Rules Designer.
To add OrderAmount bucketset to the data model: 1.
In Rules Designer, select the Bucketsets navigation tab. 2.
From the dropdown next to the Create BucketSet... icon, select List of Ranges. 3.
In the Name field, enter OrderAmount In Rules Designer be sure to press Enter to accept the name.
4. Double-click the OrderAmount bucketset icon to display the Edit Bucketset
dialog.
5. Click Add Bucket to add a bucket.
6. Click Add Bucket again to add another bucket.
7. In the Range Bucket Values area, in the top Endpoint field enter 1000 for the
endpoint value.
8. In the Range Bucket Values area, for the middle bucket in the Endpoint field enter
500 for the endpoint value.
9. In the Included Endpoint field for each bucket ensure the checkbox is selected, as
shown in Figure 5–27
.
Working with Decision Tables 5-33
Figure 5–27 Adding the OrderAmount Bucketset
10. Modify the Alias field for each value to High, Medium, and Low, as shown in
Figure 5–28 .
Figure 5–28 Adding the OrderAmount Bucketset with Low Medium and High Aliases
11. Click OK.
To add CreditScore bucketset to data model: 1.
In Rules Designer select the Bucketsets navigation tab. 2.
From the dropdown next to the Create BucketSet... icon, select List of Ranges. 3.
In the Name field, enter CreditScore. 4.
Double-click the CreditScore bucketset icon to display the Edit Bucketset dialog. 5.
Click Add Bucket to add a bucket. 6.
Click Add Bucket again to add another bucket. 7.
In the top bucket, in the Endpoint field enter 750. 8.
For the middle bucket, in the Endpoint field enter 400. 9.
In the Included Endpoint field for each bucket, ensure the checkbox is selected as shown in
Figure 5–29 .
5-34 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Figure 5–29 Adding the CreditScore Bucketset
10. Modify the Alias field for each endpoint value to solid for 750, avg for 400, and
risky
for -Infinity as shown in Figure 5–30
.
11. Click OK.
Figure 5–30 Adding the CreditScore Bucketset with Risky Avg and Solid Aliases
5.4.6 How to Associate Bucketsets with Order and CreditScore Properties
To prepare for creating Decision Tables you can associate a bucketset with fact properties in the data model. In this way condition cells in a Decision Table
Conditions
area can use the bucketset when you create a Decision Table. Note that the OrderApproval.status property is associated with the Status
bucketset when the OrderApproval fact type is imported from the XML schema. In the schema, Status is a restricted String type and is therefore represented as an
enum bucketset. Rules Designer creates the status bucketset. For more information, see
Section 3.2.4, What You Need to Know About XML Facts .
To associate bucketsets with Order and CreditScore properties: 1.
In Rules Designer select the Facts navigation tab.
Working with Decision Tables 5-35
2. Select the XML Facts tab in the Facts navigation tab as shown in
Figure 5–31 .
Figure 5–31 Opening a Business Rules Dictionary with Rules Designer
3. Select the type you want to modify. For example in the XML Facts table
double-click the icon next to the CustomerOrder entry. This displays the Edit XML Fact dialog.
4. In the Edit XML Fact dialog, in the Properties table in the Bucketset column select
the cell for the appropriate property and from the list select the bucketset you want to use. For example, for the property order select the OrderAmount
bucketset, as shown in Figure 5–32
.
5-36 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Figure 5–32 Associating the OrderAmount Bucketset with CustomerOrder.order
5. In a similar manner, for the property creditScore select the CreditScore bucketset.
6. Click OK.
5.4.7 How to Add a Decision Table for Order Approval
You create a Decision Table to process input facts and to produce output facts, or to produce intermediate conclusions that Oracle Business Rules can further process using
additional rules or in another Decision Table.
While you work with rules you can use the rule validation features in Rules Designer to assist you. Rules Designer performs dictionary validation when you make any
change to the dictionary. To show the validation log window, click the Validate icon or select ViewLog and select the Business Rule Validation tab. If you view the rules
validation log you should see warning messages. You remove these warning messages as you create the Decision Table. For more information on rule validation see
Section 4.4.2, Understanding Rule Validation .
To use a Decision Table for rules in this sample application you work with facts representing a customer spending level and a customer credit risk for a particular
customer and a particular order. Then, you use a Decision Table to create rules based on customer spending, the order amount, and the credit risk of the customer.
To add a decision table for order approval: 1.
In Rules Designer, select Ruleset_1 under the Rulesets navigation tab. 2.
Click the Add icon and from the list and select Create Decision Table.
Working with Decision Tables 5-37
3. In the Decision Table, click the Add icon and from the list select Condition.
4. In the Decision Table, double-click edit condition. Then, in the navigator
expand CustomerOrder and select creditScore. This enters the expression CustomerOrder.creditScore
in the Conditions column. 5.
Again, in the Decision Table, click the Add icon and from the list select Condition. 6.
In the Decision Table, in the Conditions area double-click the edit condition. Then, in the navigator expand CustomerOrder and select order. This enters the
expression CustomerOrder.order.
7. Again, in the Decision Table, click the Add icon and from the list select Condition.
8. In the Decision Table, double-click edit condition.
9. In the navigator expand CustomerOrder and select annualSpending. In the text
entry area, add 2000 as shown in Figure 5–33
.
Figure 5–33 Adding the Annual Spending Entry to a Decision Table
10. Type Enter to accept the value, as shown in
Figure 5–34 . If you view the rules
validation log you should see the warning messages as shown in Figure 5–34
. You remove these warning messages as you modify the Decision Table in later steps.
5-38 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Figure 5–34 Adding Conditions to the CustomerOrder Decision Table
To create an action in a decision table: 1.
In the Decision Table click the Add icon and from the list select Action Assert New
.
2. In the Actions area, double-click assert new. This displays the Action Editor
dialog.
3. In the Action Editor dialog, in the Facts area select OrderApproval.
4. In the Action Editor dialog, in the Properties table for the property status select
the Parameterized checkbox and the Constant checkbox. This specifies that each rule independently sets the status.
5. In the Action Editor dialog, select the Always Selected checkbox as shown in
Figure 5–35 .
Working with Decision Tables 5-39
Figure 5–35 Adding an Action to a Decision Table with the Action Editor Dialog
6. In the Action Editor dialog, click OK.
Next you need to add rules to the Decision Table and specify an action for each rule.
5.4.7.1 Split the Cells in the Decision Table and Add Actions
You can use the Decision Table split operation to create rules for the bucketsets associated with the condition rows in the Decision Table. This creates one rule for
every combination of condition buckets. There are three order amount buckets, three credit score buckets, and two boolean buckets for the annual spending amount for a
total of eighteen rules 3 x 3 x 2 = 18.
To split cells in a decision table: 1.
Select the Decision Table.
2. In the Decision Table, click the Split Table icon and from the list select Split
Table . The split table operation eliminates the do not care cells from the table.
The table now shows eighteen rules that cover all ranges as shown in Figure 5–36
. These steps produce validation warnings for action cells with missing expressions. You
fix these in later steps.
5-40 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Figure 5–36 Splitting a Decision Table Using Split Table Operation
To add actions for each rule in the decision table: In the Decision Table you specify a value for the status property associated with
OrderApproval for each action cell in the Actions area. The possible choices are: Status.MANUAL
, Status.REJECTED, or Status.ACCEPTED. In this step you fill in a value for status for each of the 18 rules. The values you enter correspond to the
conditions that form each rule in the Decision Table.
1. In the Actions area, double-click the action cell for the rule you want to work with,
as shown in Figure 5–37
.
Figure 5–37 Adding Action Cell Values to a Decision Table
2.
In the list, select and enter a value for the action cell. For example, enter Status.MANUAL
.
Working with Decision Tables 5-41
3.
For each action cell, enter the appropriate value as determined by the logic of your application. For this sample application use the values for the Decision Table
actions as shown in Table 5–5
.
4. Select Save All from the File main menu to save your work.
5.4.7.2 Compact the Decision Table
In this step you compact the rules to merge from eighteen rules to nine rules. This automatically eliminates the rules that are not needed and preserves the no gap, no
conflict properties for the Decision Table.
To compact the decision table: 1.
Select the Decision Table.
2. Click the Resize All Columns to Same Width icon.
3. Click the Compact Table icon and from the list select Compact Table. The compact
table operation eliminates rules from the Decision Table. The Decision Table now shows nine rules, as shown in
Figure 5–38 .
Table 5–5 Values for Decision Table Actions
Rule C1 creditScore
C2 order C3 annualSpending 2000
A1 OrderApproval status
R1 risky
Low true
Status.MANUAL R2
risky Low
false Status.MANUAL
R3 risky
Medium true
Status.MANUAL R4
risky Medium
false Status.REJECTED
R5 risky
High true
Status.MANUAL R6
risky High
false Status.REJECTED
R7 avg
Low true
Status.APPROVED R8
avg Low
false Status.MANUAL
R9 avg
Medium true
Status.APPROVED R10
avg Medium
false Status.MANUAL
R11 avg
High true
Status.MANUAL R12
avg High
false Status.MANUAL
R13 solid
Low true
Status.APPROVED R14
solid Low
false Status.APPROVED
R15 solid
Medium true
Status.APPROVED R16
solid Medium
false Status.APPROVED
R17 solid
High true
Status.APPROVED R18
solid High
false Status.MANUAL
5-42 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Figure 5–38 Compacting a Decision Table Using Compact Table
5.4.7.3 Replace Several Specific Rules with One General Rule
Notice that five of the nine remaining rules result in a manual order approval status. You can reduce the number of rules by deleting these five rules. Note it is often best
practice to not do this that is not replace several specific rules with one general rule. You need to compare the benefits of having fewer rules with the added complexity of
managing the conflicts introduced when you reduce the number of rules.
To replace several specific rules with one general rule: 1.
Select the Decision Table.
2. In the Decision Table, select a rule with OrderApproval status action set to
Status.MANUAL . To select a rule, click the column heading. For example, click
rule R2 as shown in Figure 5–39
.
3. Click Delete to remove a rule in the Decision Table. Be careful to click the delete
icon in the Decision Table area to delete a rule in the decision table there is also a delete icon shown in the Ruleset area that deletes the complete Decision Table.
Working with Decision Tables 5-43
Figure 5–39 Deleting Rules from a Decision Table
4.
Repeat these steps to delete all the rules with action set to Status.MANUAL. This should leave the Decision Table with four rules as shown in
Figure 5–40 .
Figure 5–40 Decision Table After Manual Actions Removed
5.4.7.4 Add a General Rule
Now you can add a single rule to handle the manual case. After adding this rule you set the conflict policy with the option Conflict Policy auto override for conflict
resolution.
To add a general rule: 1.
In the Decision Table, click the Add icon and from the list select Rule.
5-44 Oracle Fusion Middleware Users Guide for Oracle Business Rules
2. In the Conditions area, for the three conditions leave the - do not care value for
each cell in the rule.
3. In the Actions area, enter Status.MANUAL, as shown in
Figure 5–41 . Notice that
the Business Rule Validation log includes the warning RUL-05851 for unresolved conflicts.
Figure 5–41 Decision Table with Conflicting Rules
4. Show the conflicting rules by clicking the Toggle Display of Conflict Resolution
icon, as shown in Figure 5–42
.
Working with Decision Tables 5-45
Figure 5–42 Adding a Rule to Handle Status Manual
To enable the auto override conflict resolution policy: 1.
In the Decision Table click Show Advanced Settings the icon next to the Decision Table name.
2. In the Conflict Policy list, select auto override. After adding the manual case rule
and selecting auto override, notice that the conflicts are resolved and special cases override the general case, as shown in
Figure 5–43 .
Figure 5–43 Adding a Rule to Handle Status Manual with Auto Override Conflict Policy
5-46 Oracle Fusion Middleware Users Guide for Oracle Business Rules
5.4.8 How to Check the Business Rule Validation Log for Order Approval
Before you can deploy the application you need to make sure the dictionary validates without warnings. If there are any validation warnings you need fix any associated
problems.
To validate the dictionary: 1.
In the Business Rule Validation Log, check for validation warnings.
2.
If there are validation warnings, perform appropriate actions to correct the problems.
5.4.9 How to Deploy the Order Approval Application
Business rules created in an SOA application are deployed as part of the SOA composite when you create a deployment profile in Oracle JDeveloper. You deploy an
SOA composite application to Oracle WebLogic Server.
To deploy and run the order approval application: 1.
If you have not started your application server instance, then start the Oracle WebLogic Server.
2. In the Application Navigator, right-click the OrderApproval project and select
Deploy OrderApproval to WLS Server Name.
Then the SOA Deployment Configuration dialog displays.
3. Click OK.
4.
In the Authorization Request dialog, enter your authorization.
5. Click OK.
5.4.10 How to Test the Order Approval Application
After deploying the application you can test the Decision Table in the SOA composite application with the Oracle Enterprise Manager Fusion Middleware Control Console.
To test the application: 1.
Open the composite application in Oracle Enterprise Manager Fusion Middleware Control Console, as shown in
Figure 5–44 .
Working with Decision Tables 5-47
Figure 5–44 Testing the Order Approval Application
2. Click Test.
3. In the Input Arguments area, select XML View. Replace the XML with the
contents of example Example 5–2
.
Example 5–2 Sample Input for Testing Order Approval Application
soap:Envelope xmlns:soap=http:schemas.xmlsoap.orgsoapenvelope soap:Body xmlns:ns1=http:xmlns.oracle.comOracleRules1OracleRules1_DecisionService_1
ns1:callFunctionStateless name=OracleRules1_DecisionService_1 ns1:parameterList xmlns:ns3=http:example.comnscustomerorder
ns3:CustomerOrder ns3:nameGaryns3:name
ns3:creditScore600ns3:creditScore ns3:annualSpending2001.0ns3:annualSpending
ns3:valueHighns3:value ns3:order100.0ns3:order
ns3:CustomerOrder ns1:parameterList
ns1:callFunctionStateless soap:Body
soap:Envelope
4.
Replace the values in the input shown in Example 5–2
as desired for your test.
5. Click Test Web Service.
6. In the Response tab, view the results. For example, for this input:
OracleRules1_DecisionService_1 xmlns:ns2=http:xmlns.oracle.combpel resultList
OrderApproval:OrderApproval xmlns:OrderApproval=http:example.comnscustomerorder
xmlns=http:example.comnscustomerorder
5-48 Oracle Fusion Middleware Users Guide for Oracle Business Rules
statusapprovedstatus OrderApproval:OrderApproval
resultList callFunctionStatefulDecision
6
Working with Decision Functions 6-1
6
Working with Decision Functions
Use a decision function to call rules from a Java application, from a composite, or from a BPEL process.
This chapter includes the following sections:
■
Section 6.1, Introduction to Decision Functions
■
Section 6.2, Working with Decision Functions
■
Section 6.3, What You Need to Know About Decision Functions
6.1 Introduction to Decision Functions
A decision function is a function that is configured declaratively. A decision function contains the following declarations:
■
input facts
■
rulesets and nested decision functions
■
output facts A decision function performs the following operations:
■
Asserts inputs as rule facts into the Oracle Business Rules Engine working memory
■
Runs rulesets configured in the current decision function and in nested decision functions in order
■
Returns output facts from the Oracle Business Rules Engine working memory You can create a decision function to simplify the use of Oracle Business Rules from a
Java application or from a BPEL process. In a decision function the rules you want to use can be organized into several rulesets, and those rulesets can be executed in a
prescribed order. Facts may flow to the first ruleset, and this ruleset may assert additional facts that flow to the second and subsequent rulesets until finally facts flow
back to the decision function as decision function output.
6.2 Working with Decision Functions
A decision function is a function that is configured declaratively.
6.2.1 How to Add or Edit a Decision Function
You use Rules Designer to add a decision function.
6-2 Oracle Fusion Middleware Users Guide for Oracle Business Rules
To add a decision function: 1.
In Rules Designer, select the Decision Functions navigation tab. 2.
In the Decision Functions area, click Create.... 3.
Enter the decision function name in the Name field, or use the default name as
Figure 6–1 shows.
Figure 6–1 The Decision Functions Area in Rules Designer
4.
In the decision functions table, double-click the decision function icon. For example, double-click the decision function icon for DecisionFunction_1. This
displays the Edit Decision Function dialog, as shown in Figure 6–2
.
Working with Decision Functions 6-3
Figure 6–2 Edit Decision Function Dialog
5. In the Name field, enter a name or accept the default value.
6. In the Description field, optionally enter a description.
7. In the Rule Firing Limit field, select unlimited. In some cases when you are
debugging a decision function, you may want to enter a value other than unlimited
for the rule firing limit. For more information, see Section 6.3.1, What
You May Need to Know About Rule Firing Limit Option for Debugging Rules .
8. Select the appropriate decision function options:
■
Will be invoked as a Web Service : select whether the decision function will be
invoked as a Web Service.
■
Check Rule Flow : when selected, this option specifies that the rule flow is
checked to ensure that facts of the appropriate type are either explicit inputs to the decision function or are asserted by rules in the rule flow. However, when
this is selected this does not always produce useful information; there are cases where facts can be asserted in Java code that uses the decision function,
but this code might not be available at design time. In this case, validation warnings may produced with Check Rule Flow selected may not be useful.
6-4 Oracle Fusion Middleware Users Guide for Oracle Business Rules
■
Stateless : when selected specifies the decision function is stateless. For more
information, see Section 6.3.3, What You May Need to Know About the
Decision Function Stateless Option .
9. In the Inputs Table, click Add to add inputs. For each input in the Inputs Table,
select the appropriate options:
■
Name - enter an input name and press Enter or accept the default name.
■
Fact Type - select the appropriate fact type from the list.
■
Tree - When unselected, the input is asserted using the assert function.
When selected, the input is asserted using the assertTree function. When selected it is expected that the input object or objects are the root of an object
tree that is connected in one-to-many relationships with other objects using List
properties. For more information, see Section 4.8, Working with Tree
Mode Rules .
■
List - When unselected, the input must be a single object and the assertion
applies only to that single input object. When selected, the input must be a List
of objects and the assertion applies to each object in the input List java.util.List.
10. In the Outputs Table, click Add to add outputs. For each output in the Outputs
Table, select the appropriate options:
■
Name - enter an output name and press Enter or accept the default name.
■
Fact Type - select the appropriate fact type from the list.
■
Tree - When selected, this option sets a flag that enables certain design-time
decision function argument checking. For an output argument, this option has no effect on runtime behavior. However, at design time in the case where
several decision functions are called in a sequence, it is useful to notate explicitly that the output of one decision function is a tree. This implies that
the input of another decision function in the sequence is expecting a tree as an input. For more information, see
Section 4.8, Working with Tree Mode Rules .
■
List - When unselected the output is a single object. When selected the output
is a group of objects. For more information on the behavior of the List option on an output argument, see
Section 6.3.2, What You May Need to Know to About Decision Function Arguments
.
11. In the Rulesets and Decision Functions area, use the shuttle to move items from
the Available box to the Selected box. 12.
Select an item in the Selected box, and click Move Up or Move Down as appropriate to order the rulesets and the decision functions.
To edit an existing decision function: 1.
In Rules Designer, select the Decision Functions navigation tab. 2.
Select the decision function to edit and click the Edit icon or double-click the decision function icon.
3.
Edit the appropriate decision function fields in the same manner as you would when you add a decision function.
To change the order of inputs: 1.
In Rules Designer, select the Decision Functions navigation tab.
Working with Decision Functions 6-5
2. Select the decision function to edit and click the Edit icon or double-click the
decision function icon.
3. Select the input argument you want to move. Click either Move Up or Move
Down to reorder the input argument.
To change the order of outputs: 1.
In Rules Designer, select the Decision Functions navigation tab. 2.
Select the decision function to edit and click the Edit icon or double-click the decision function icon.
3. Select the output argument you want to move. Click either Move Up or Move
Down to reorder the output argument.
6.3 What You Need to Know About Decision Functions
A decision function is a function that is configured declaratively.
6.3.1 What You May Need to Know About Rule Firing Limit Option for Debugging Rules
The Rule Firing Limit allows you to set the maximum number of steps rule firings that are allowed at runtime. Using this option and specifying a value other than
unlimited can help you debug certain rule design problems and in some cases might help prevent java.lang.OutOfMemoryError errors at runtime. This is can be
useful when debugging infinitely recursive rule firings.
6.3.2 What You May Need to Know to About Decision Function Arguments
Oracle Business Rules generates a corresponding RL Language function for each decision function.
The signature of a generated decision function is similar to:
function nameInputFactType1 input1, ... InputFactTypeN inputN returns List
In a decision function, each parameter is generated depending on the List option, with the decision function input, as follows:
■
Input argument, List option unselected: for FactTypei the input must be a single object and the assertion applies only to that single input object.
■
Input List option selected: ListFactTypei the input must be a List of objects and the assertion applies to each object in the input List java.util.List.
The generated RL Language function includes calls either to assert or assertTree for each argument, depending on the decision function Input option, Tree. When Tree
is unselected the input is asserted using the assert function. When Tree is selected, the input is asserted using the assertTree function. When Tree is selected it is
expected that the input object or objects are the root of an object tree that is connected in one-to-many relationships with other objects using List or array type properties.
For the decision function selected rulesets, as specified in the Rulesets and Decision Functions
area Selected box, the generated RL Language function includes a call to
run with the selected rulesets in the selected ruleset stack order.
The generated RL Language function returns a list. The list has an element for each decision function output in order. If the output is declared to be a list, then the
corresponding element is a list. However, if the output is not declared to be a list, then the corresponding element is the output fact or null if there is no output fact of the
6-6 Oracle Fusion Middleware Users Guide for Oracle Business Rules
declared type. If an output is not declared to be a list, and more than one output fact of the specified type is found in the working memory of Oracle Business Rules Engine,
then an exception is thrown.
After you edit a decision function, for example, to change or add inputs and outputs, the changes are visible in BPEL for new Business Rule activities. However, the changes
are not visible to existing Business Rule activities. For more information, see Getting Started with Oracle Business Rules in the Oracle Fusion Middleware Developers Guide
for Oracle SOA Suite.
6.3.3 What You May Need to Know About the Decision Function Stateless Option
A decision function supports either stateful or stateless operation. The Stateless checkbox in the Edit Decision Function dialog provides support for these two modes
of operation.
By default the Stateless checkbox is selected which indicates stateless operation. With stateless operation, at runtime, the rule session is released after each invocation of the
decision function.
When Stateless is deselected the underlying Oracle Business Rules object is kept in the memory of the Business Rules service engine, so that it is not given back to the Rule
Session Pool when the operation is finished. A subsequent use of the decision function re-uses the cached RuleSession object, with all its state information from the previous
invocation. Thus, when Stateless is deselected the rule session is saved for a subsequent request and a sequence of decision function invocations from the same
process should always end with a stateless invocation.
7
Working with Rules SDK Decision Point API 7-1
7
Working with Rules SDK Decision Point API
Oracle Business Rules SDK Rules SDK lets you write applications that access, create, modify, and execute rules in Oracle Business Rules dictionaries and work with the
contents of a dictionary. This chapter provides a brief description of Rules SDK and shows how to work with the Rules SDK Decision Point API.
This chapter includes the following sections:
■
Section 7.1, Introduction to Rules SDK and the Car Rental Sample Application
■
Section 7.2, Creating a Dictionary for Use with a Decision Point
■
Section 7.3, Creating a Java Application Using Rules SDK Decision Point
■
Section 7.4, Running the Car Rental Sample
■
Section 7.5, What You Need to Know About Using Decision Point in a Production Environment
■
Section 7.6, What You Need to Know About Decision Point and Decision Tracing For more information, see Oracle Fusion Middleware Java API Reference for Oracle
Business Rules.
7.1 Introduction to Rules SDK and the Car Rental Sample Application
The Rules SDK consists of four areas:
■
Engine: provides for rules execution
■
Storage: provides access to rule dictionaries and repositories
■
Editing: provides a programatic way to create and modify dictionary components
■
Decision Point: provides an interface to access a dictionary and execute a decision function
Other than for explanation purposes, there is not an explicit distinction between these areas in Rules SDK. For example, to edit rules you also need to use the storage area of
Rules SDK to access a dictionary. These parts of the Rules SDK are divided to help describe the different modes of usage, rather than to describe distinct Rules SDK APIs.
7.1.1 Introduction to Decision Point API
The Decision Point API provides a concise way to execute rules. Most users create Oracle Business Rules artifacts, including data model elements, rules, Decision Tables,
and rulesets using the Rules Designer extension to Oracle JDeveloper. Thus, most users do not need to work directly with the engine, storage, or editing parts of Rules
SDK.
7-2 Oracle Fusion Middleware Users Guide for Oracle Business Rules
To work with the Rules SDK Decision Point package you need to understand three important classes:
■
DecisionPoint : is a helper class that follows the factory design pattern to create
instances of DecisionPointInstance. In most applications there should be one DecisionPoint
object that is shared by all application threads. A caller uses the getInstance
method of DecisionPoint to get an instance of DecisionPointInstance
which can be used to call the defined Decision Point.
■
DecisionPointBuilder : follows the Builder design pattern to construct a
Decision Point.
■
DecisionPointInstance : users call invoke in this class to assert facts and
execute a decision function. The DecisionPoint classes support a fluent interface model so that methods can be
chained together. For more information, see http:www.martinfowler.comblikiFluentInterface.html
A Decision Point manages several aspects of rule execution, including:
■
Use of oracle.rules.rl.RuleSession objects
■
Reloading of a dictionary when the dictionary is updated To create a Decision Point in a Java application you need the following:
■
Either the name of a dictionary to be loaded from an MDS repository or a pre-loaded oracle.rules.sdk2.dictionary.RuleDictionary instance.
■
The name of a decision function stored in the specified dictionary.
7.1.2 How to Obtain the Car Rental Sample Application
This chapter shows a car rental application that demonstrates the use of Rules SDK and the Decision Point API. You can obtain the sample application in a ZIP file,
CarRentalApplication.zip . This ZIP contains a complete JDeveloper application
and project. The source code for Oracle Business Rules-specific samples is available online at
https:www.samplecode.oracle.comsfgopage1497 For SOA samples online visit
https:www.samplecode.oracle.comsfprojectssoasamples To work with the sample unzip CarRentalApplication.zip into an appropriate
directory. The car rental application project contains a rules dictionary and several Java examples using Rules SDK.
7.1.3 How to Open the Car Rental Sample Application and Project
The Car Rental sample application shows you how to work with the Rules SDK Decision Point API.
To open the car rental sample application: 1.
Start Oracle JDeveloper.
2.
Open the car rental application in the directory where you unzipped the sample. For example, from the File menu select Open... and in the Open dialog navigate to
the CarRentalApplication folder.
Working with Rules SDK Decision Point API 7-3
3. In the Open dialog select CarRentalApplication.jws and click Open.
4. In the Application Navigator, expand the CarRentalApplication, expand
Application Sources and Resources. This displays the Oracle Business Rules
dictionary named CarRental.rules and several Java source files.
7.2 Creating a Dictionary for Use with a Decision Point
The car rental sample uses the Rules SDK Decision Point API with either a pre-loaded Oracle Business Rules dictionary or a repository stored in MDS. When you are
working in a development environment you can use the Decision Point API with the pre-loaded dictionary signature. In a production environment you would typically use
a Decision Point with the MDS repository signature.
The CarRental dictionary is pre-defined and is available in the car rental sample application.
To work with the Decision Point API you need to create a dictionary that contains a decision function the car rental sample application comes with a predefined
dictionary and decision function.
You perform the following steps to create a dictionary and a decision function:
■
Section 7.2.1, How to Create Data Model Elements for Use with a Decision Point
■
Section 7.2.2, How to View a Decision Function to Call from the Decision Point
■
Section 7.2.3, How to Create Rules or Decision Tables for the Decision Function
7.2.1 How to Create Data Model Elements for Use with a Decision Point
You need the following to add to a decision function when you create an application with a Decision Point.
■
A dictionary containing data model elements that you use to create rules or Decision Tables and when working with ADF Business Components fact types,
you need to add links for the Decision Point support dictionary. For more information, see
Chapter 2, Working with Data Model Elements . For more
information, see Chapter 10, Working with Oracle Business Rules and ADF
Business Components .
■
A dictionary containing fact definitions. For more information, see Chapter 3,
Working with Facts and Bucketsets .
To view the data model in the supplied car rental sample application: 1.
In Rules Designer, click the Facts navigation tab. 2.
Select the Java Facts tab, as shown in Figure 7–1
.
The Java Facts tab shows four fact types imported, in addition to the fact types provided as built-in to the dictionary.
The Driver Java Fact is imported from the Driver Java class in the project. The Denial Java Fact is imported from Denial Java class in the project.
The LicenseType and VehicleType facts are imported from the nested enum classes defined in the Driver class.
7-4 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Figure 7–1 Defined Java Facts for the Car Rental Sample Application
When you use a Decision Point with Rules SDK, you call a decision function in a specified dictionary. The decision function that you call can contain one or more
rulesets that are executed as part of the Decision Point.
To view the ruleset in the supplied car rental sample application: 1.
In Rules Designer, expand the CarRentalApplication. 2.
In the CarRentalApplication, expand Resources. 3.
Double-click the CarRental.rules.
7.2.2 How to View a Decision Function to Call from the Decision Point
When you work with the Decision Point API you use decision functions to expose an Oracle Business Rules dictionary. For more information on decision functions, see
Chapter 6, Working with Decision Functions .
To view the decision function in the car rental sample application: 1.
In Rules Designer, click the Decision Functions navigation tab. This displays the available decision functions in the CarRental dictionary, as shown in
Figure 7–2 .
Working with Rules SDK Decision Point API 7-5
Figure 7–2 Car Rental Sample Decision Function
2. Select the row with CarRentalDecisionFunction and double-click the decision
function icon. This opens the Edit Decision Function dialog as shown in Figure 7–3
.
The decision function Inputs table includes a single argument for a Driver fact type.
The decision function Outputs table includes a single argument for a Denial fact type.
The decision function Rulesets and Decision Functions area shows Denial Rules:if-then
in the Selected box.
7-6 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Figure 7–3 Car Rental Decision Function for the Car Rental Sample Application
7.2.3 How to Create Rules or Decision Tables for the Decision Function
The car rental sample includes two rulesets, one with IFTHEN rules and another containing a Decision Table. You can use either IFTHEN rules or Decision Tables or
both in your application if you are using a Decision Point.
To view the rules in the car rental sample application: 1.
In Rules Designer click the Denial Rules:if-then ruleset, as shown in Figure 7–4
.
Working with Rules SDK Decision Point API 7-7
Figure 7–4 Ruleset with IFTHEN Rules for the Car Rental Sample Application
The Denial Rules:if-then ruleset includes two rules:
■
under age : this rule defines the minimum age of the driver. The rule compares the
Driver instance age property to the global Minimum driver age. If the driver
is under this age, then a new Denial fact is asserted. A call to the decision function collects this Denial fact, as defined in its output. The rule also calls a
user-defined function, audit, to provide some auditing output about why the Denial
is created.
■
too many accidents : this rule defines an upper threshold for the number of
accidents a driver can have before a rental for the driver is denied. The rule also calls a user-defined function, audit, to provide some auditing output about why
the Denial is created.
To view the Decision Table in the car rental application: 1.
In Rules Designer, click the Denial Rules:decision table ruleset, as shown in
Figure 7–5 .
7-8 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Figure 7–5 Ruleset with Decision Table for the Car Rental Sample Application
7.2.4 What You Need to Know About Using Car Rental Sample with a Decision Table
The car rental sample application includes the Denial Rules: decision table ruleset. To switch to use a Decision Table in the supplied decision function sample, move the
Denial Rules:if-then from the Selected area in the decision function and add the
Denial Rules: decision table ruleset, which uses a Decision Table to define similar
rules, as shown in Figure 7–6
.
Working with Rules SDK Decision Point API 7-9
Figure 7–6 Decision Function for Car Rental Sample with Decision Table Ruleset
7.3 Creating a Java Application Using Rules SDK Decision Point
When use Rules SDK in a development environment you of the option of using Decision Point API with a pre-loaded dictionary. In a production environment you
typically use the Decision Point API with the MDS repository signature and the dictionary is stored in MDS. For more information on using a Decision Point with, see
Section 7.5, What You Need to Know About Using Decision Point in a Production Environment
. The source code for Oracle Business Rules-specific samples is available online at
https:www.samplecode.oracle.comsfgopage1497 For SOA samples online visit
https:www.samplecode.oracle.comsfprojectssoasamples The CarRentalProject project includes the com.example.rules.demo package that
includes the car rental sample file, CarRentalWithDecisionPointUsingPreloadedDictionary.java.
The project also includes several .java source files that support different variations for
7-10 Oracle Fusion Middleware Users Guide for Oracle Business Rules
using Decision Point. Table 7–1
provides a summary of the different versions of the car rental sample.
For more information on working with the Rules SDK Decision Point API, see Oracle Fusion Middleware Java API Reference for Oracle Business Rules.
7.3.1 How to Add a Decision Point Using Decision Point Builder
To use a Decision Point you create a DecisionPoint instance using DecisionPointBuilder
, as shown in Example 7–1
.
Example 7–1 Using the Decision Point Builder
static { try {
specifying the Decision Function and a pre-loaded RuleDictionary instance
m_decisionPoint = new DecisionPointBuilder .withDF_NAME
.withloadRuleDictionary .build;
} catch SDKException e { System.err.printlnFailed to build Decision Point: +
e.getMessage; e.printStackTrace;
} }
Table 7–1 Java Files in the Decision Point Sample CarRentalProject
Base Java Filename Description
CarRental This is the base class for all of the examples. It contains constant values
for using the CarRental dictionary and a method createDrivers which creates instances of the Driver class.
CarRentalWithDecisionPoint Contains a static attribute of type DecisionPoint and a method
checkDriver that invokes a Decision Point with a specified instance
of the Driver class. This class includes these methods for the sample application so that both the MDS repository and pre-loaded dictionary
examples can share the same checkDriver implementation. CarRentalWithDecisionPointUsi
ngMdsRepository Contains an example of creating a Decision Point that uses MDS to
access and load the rule dictionary. In a production environment, most applications use the Decision Point API with MDS.
CarRentalWithDecisionPointUsi ngPreloadedDictionary
Contains an example of creating a Decision Point from an instance of the RuleDictionary
class. This example also contains code for manually loading the dictionary to create a RuleDictionary instance.
CarRentalWithRuleSession Contains an advanced usage of the Engine API that is documented
further in the comments. CarRentalWithRuleSessionPool
Contains an advanced usage of the Engine API that is documented further in the comments.
Denial Contains the class that defines the Denial fact type used to create the
rules and Decision Table. Driver
Contains the class that defines the Driver fact type used to create the rules and Decision Table.
DriverCheckerRunnable Contains the class which can be used as a thread for simulating
concurrent users invoking the Decision Point.
Working with Rules SDK Decision Point API 7-11
Example 7–1 shows the DecisionPointBuilder supports a fluent interface pattern,
so all methods can easily be chained together when you create a Decision Point. The three most common methods for configuring the Decision Point with
DecisionPointBuilder are overloaded to have the name with. Each with
method takes a single argument of type RuleDictionary, DictionaryFQN, or String
. The DecisionPointBuilder also supports similar set and get methods: getDecisionFunction
, setDecisionFunction, getDictionary, setDictionary
, getDictionaryFQN, setDictionaryFQN. This chain shown in
Example 7–1 includes the following steps:
1.
The first step is to create a DecisionPointBuilder instance with code such as the following:
new DecisionPointBuilder
2.
The with method using a String argument defines the name of the decision function that the Decision Point executes. Calling this method is mandatory.
.withDF_NAME The DF_NAME specifies the name of the decision function you define for your
application. For example for the sample car rental application DF_NAME is defined in CarRental.java as CarRentalDecisionFunction.
3.
Call only one of the other two with methods. In this case the sample code uses a pre-loaded Rule Dictionary instance, containing the specified decision function.
The loadDictionary method loads an instance of RuleDictionary from a file.
Example 7–2 shows the loadDictionary method. For more information,
see Section 7.3.2, How to Use a Decision Point with a Pre-loaded Dictionary
. .withloadRuleDictionary
4.
Call the build method to construct and return a DecisionPoint instance. The DecisionPoint instance is shared among all instances of the application, which
is why it is a static attribute and created in a static block. Another way of initializing the DecisionPoint would be to initialize the m_decisionPoint attribute with a
static method that created and returned a DecisionPoint instance.
7.3.2 How to Use a Decision Point with a Pre-loaded Dictionary
Example 7–2 shows the loadRuleDictionary method that loads an instance of
RuleDictionary from a file. When reading or writing a dictionary directly from a file as shown in
Example 7–2 ,
ensure to set the encoding to UTF-8. If this is not done, Unicode characters used in the dictionary are corrupted. The UTF-8 option must be set explicitly in the
FileInputStream or OutputStreamWriter constructor. Do not use Java classes
such as FileReader and FileWriter, as these classes always use the platform default encoding which is usually an ASCII variant rather than a Unicode variant.
Example 7–2 Load Rule Dictionary Method
private static RuleDictionary loadRuleDictionary{ RuleDictionary dict = null;
BufferedReader reader = null; try {
reader = new BufferedReader new InputStreamReader
new FileInputStream
7-12 Oracle Fusion Middleware Users Guide for Oracle Business Rules
new FileDICT_LOCATION, UTF-8; dict = RuleDictionary.readDictionaryreader,
new DecisionPointDictionaryFindernull;
ListSDKWarning warnings = new ArrayListSDKWarning; dict.updatewarnings;
if warnings.size 0 { System.err.printlnValidation warnings: + warnings;
} } catch SDKException e{
System.err.printlne; } catch FileNotFoundException e{
System.err.printlne; } catch IOException e{
System.err.printlne; } finally {
if reader = null { try { reader.close; } catch IOException ioe {ioe.printStackTrace;}}
} return dict;
}
7.3.3 How to Use Executor Service to Run Threads with Decision Point
The car rental sample allows you to use Oracle Business Rules and simulate multiple concurrent users.
Example 7–3 shows use of the Java ExecutorService interface to
execute multiple threads that invoke the Decision Point. The ExecutorService is not part of the Rules SDK Decision Point API.
Example 7–3 Checking Drivers with Threads that Invoke Decision Point
ExecutorService exec = Executors.newCachedThreadPool; ListDriver drivers = createDrivers;
for int i = 0; i NUM_CONCURRENT; i++ { Driver driver = drivers.geti drivers.size;
exec.executenew DriverCheckerRunnabledriver; }
Example 7–3 includes the following code for the sample application:
■
Create the Executor Service: ExecutorService exec = Executors.newCachedThreadPool;
■
Call method createDrivers, defined in CarRental.java, to create a list of Driver
instances. ListDriver drivers = createDrivers;
■
A loop through a list of Driver instances to fill the driver list with drivers.
■
A loop to start multiple threads from DriverCheckerRunnable instances. These instances open a Decision Point and run the rules on each driver. For information
on this code, see Section 7.3.4, How to Create and Use Decision Point Instances
. Example 7–4
shows the code that waits for the threads to complete.
Working with Rules SDK Decision Point API 7-13
Example 7–4 Code to Await Thread Termination
try { exec.awaitTermination5, TimeUnit.SECONDS;
} catch InterruptedException e { e.printStackTrace;
} exec.shutdown;
}
7.3.4 How to Create and Use Decision Point Instances
The DriverCheckerRunnable instances call the checkDriver method. Example 7–5
shows the checkDriver method that is defined in CarRentalWithDecisionPoint
. The checkDriver method handles invoking Decision Point with a Driver instance.
Example 7–5 Code to Create a Decision Point Instance with getInstance
public class CarRentalWithDecisionPoint extends CarRental { protected static DecisionPoint m_decisionPoint;
public static void checkDriverfinal Driver driver { try {
DecisionPointInstance instance = m_decisionPoint.getInstance; instance.setInputsnew ArrayListObject {
{ adddriver;
} };
ListObject outputs = instance.invoke; if outputs.isEmpty
System.err.printlnOops, no results; java.util.ListDenial denials =
java.util.ListDenialoutputs.get0; if denials.isEmpty {
System.out.printlnRental is allowed for + driver.getName;
} else { for Denial denial : denials {
System.out.printlnRental is denied for + denial.getDriver.getName +
because + denial.getReason; }
} } catch RLException e {
e.printStackTrace; } catch SDKException e {
e.printStackTrace; }
} }
Example 7–5 shows the following:
7-14 Oracle Fusion Middleware Users Guide for Oracle Business Rules
■
Getting a DecisionPointInstance from the static DecisionPoint defined with the DecisionPointBuilder, with the following code.
DecisionPointInstance instance = m_decisionPoint.getInstance;
■
Add inputs according to the signature of the decision function associated with the Decision Point. This defines one argument of type List as the input. This List
contains the Driver instances:
instance.setInputsnew ArrayListObject { {
adddriver; }
};
■
Invoke the Decision Point and store the return value. The return type follows the same pattern as the decision function which is being called in the Decision Point.
ListObject outputs = instance.invoke; In this case the invoke returns a List of length one, containing a List of
Denial instances.
■
If the return is a List of any other size than one, then this is an error: if outputs.isEmpty
System.err.printlnOops, no results;
■
The first entry that is returned from the Decision Point is caste it to a List of type ListDenial
: java.util.ListDenial denials =
java.util.ListDenialoutputs.get0;
■
If the denials list is empty, then no Denial instances were asserted by the rules. This indicates that it is OK to rent a car to the driver. Otherwise, print the reasons
why the driver rental was rejected:
if denials.isEmpty { System.out.printlnRental is allowed for +
driver.getName; } else {
for Denial denial : denials { System.out.printlnRental is denied for +
denial.getDriver.getName + because + denial.getReason;
} }
7.4 Running the Car Rental Sample
In the car rental sample installed on your system, for the code shown in Example 7–2
, modify the value of DICT_LOCATION to match the location of the dictionary on your
system.
To run the car rental sample on your system: 1.
In the Application Navigator, select the dictionary and from the Edit menu select Copy Path
.
Working with Rules SDK Decision Point API 7-15
2.
In the CarRental.java file, paste the path value into the DICT_LOCATION value.
3. In the CarRentalProject select the
CarRentalWithDecisionPointUsingPreloadedDictionary.java
file.
4. Right-click and in the list select Run.
Example 7–6 shows sample output.
Example 7–6 Output from Car Rental Sample
Rental is allowed for Carol Rental is allowed for Alice
Rental is allowed for Alice Rental is allowed for Carol
Rental is denied for Bob because under age, age was 15, minimum age is 21 Mar 13, 2009 11:18:00 AM oracle.rules.rl.exceptions.LogWriter flush
INFO: Fired: under age because driver age less than minimum threshold for license number d222
Mar 13, 2009 11:18:00 AM oracle.rules.rl.exceptions.LogWriter flush INFO: Fired: under age because driver age less than minimum threshold for license
number d222 Rental is denied for Bob because under age, age was 15, minimum age is 21
Rental is allowed for Alice Rental is allowed for Eve
7.5 What You Need to Know About Using Decision Point in a Production Environment
In a production environment you can use an MDS repository to store Oracle Business Rules dictionaries. When you use an MDS repository to store the dictionary, the steps
shown in Section 7.3.1, How to Add a Decision Point Using Decision Point Builder
and Section 7.3.2, How to Use a Decision Point with a Pre-loaded Dictionary
change to access the dictionary. The
CarRentalWithDecisionPointUsingMdsRepository shows sample code for
using Decision Point with MDS. To see a complete example with deployment steps showing the use of a Decision Point
to access a dictionary in MDS, see Section 9.4, Adding a Servlet with Rules SDK Calls
for Grades Sample Application .
Example 7–7 shows the use of DictionaryFQN with DecisionPointBuilder to
access a dictionary in an MDS repository. The complete example is shown in the sample code in CarRentalWithDecisionPointUsingMdsRepository.
Example 7–7 Using Decision Point Builder with MDS Repository
static { try {
specifying the Decision Function and Dictionary FQN loads the rules from the MDS repository.
m_decisionPoint = new DecisionPointBuilder .withDF_NAME
.withDICT_FQN .build;
} catch SDKException e { System.err.printlnFailed to build Decision Point: +
e.getMessage;
7-16 Oracle Fusion Middleware Users Guide for Oracle Business Rules
Similar to the steps in Example 7–1
, Example 7–7
shows the following:
1.
The first step is to create a DecisionPointBuilder instance with. new DecisionPointBuilder
2.
The with method using a String argument defines the name of the decision function that the Decision Point executes. Calling this method is mandatory.
.withDF_NAME The DF_NAME specifies the name of the decision function you define for your
application. For example for the car rental application this is defined in CarRental.java
a CarRentalDecisionFunction.
3.
Call only one of the other two with methods. In this case the sample code calls a DictionaryFQN to access an MDS repository.
Example 7–8 shows the routing
that uses the dictionary package and the dictionary name to create the DictionaryFQN
. .withDICT_FQN
4.
Call the build method to construct and return a DecisionPoint instance.
Example 7–8 Using the DictionaryFQN Method with MDS Repository
protected static final String DICT_PKG = com.example.rules.demo; protected static final String DICT_NAME = CarRental;
protected static final DictionaryFQN DICT_FQN = new DictionaryFQNDICT_PKG, DICT_NAME;
protected static final String DF_NAME = CarRentalDecisionFunction;
7.6 What You Need to Know About Decision Point and Decision Tracing