Rule development for ODM is done in Rule Designer. The free Rule Designer for ODM for Developer can be obtained and installed as a plug-in from the Eclipse marketplace.
This time, I would like to develop a simple rule with Rule Designer.
The latest Rule Designer is based on Eclipse v4.7.3 (Oxygen), so you need to install the same version. Please note that you may not be able to change the language locale of Rule Designer if you have installed the latest version of Eclipse or the Japanese localization plug-in.
If you don't have Eclipse or the version is different, please install Eclipse Oxygen.
Start Eclipse and open the Eclipse Marketplace window. Search for "odm" and install IBM ODM Rule Designer for Developer V8.10.1.
In the license confirmation window, select "I accept the terms…" and click the "Finish" button.
After the installation is complete, restart Eclipse. Make sure the rule perspective has been added.
The rule development environment is ready. In the following steps, we will develop a simple rule.
Develop a simple rule that returns the discount rate according to the customer rank. (Simple logic doesn't require you to use rules, but it simplifies the scenario to understand how ODM works and how to create rules.)
ODM rules define a dictionary that associates an execution model (XOM) with a business object model (BOM) in order to write rules in Japanese. At the beginning of rule development, design the data items used in the rule and create an execution model using Java classes and XML schema. Here we will use Java to create the XOM.
Open the Java perspective in Eclipse. Click New> Java Project.
Enter CustomerLoyaltyXOM as the name of the project, make sure the JRE version is 1.8, and click Finish.
Right-click on the Java project you created in Package Explorer and select New> Class.
Enter "my.first.rule" for the package name and "Loyalty" for the class name, then click Finish.
The Java editor opens. Create three Private variables as shown below.
Right-click on the Java editor and select Source> Generate Getter and Setter.
Click Select all on the right, then click the OK button.
Right-click again in the Java editor and select Source> Generate Constructor using Fields.
Make sure three fields are selected by default and click OK.
Right-click again in the Java editor and select Source> Generate Constructor from Superclass.
Keep the defaults and click OK.
The code should look like the following. Press Ctrl + S to save.
Click the icon in the upper right corner of Eclipse to switch to the rules perspective.
The decision service map is displayed at the bottom of the screen. This is a guide to the steps you take to develop your rules. Click "Create Main Rule Project" at the top left.
Make sure Main Rule Project is selected for the template and click Next.
Enter CustomerLoyaltyRule as the name of the rule project and click Finish.
From the decision service map displayed at the bottom of the screen, click "Import XOM".
Make sure Java Execution Object Model is selected and click OK.
Check "Customer Loyalty XOM" from the list and click "Apply and Close".
BOM is a dictionary of business terms used in rule descriptions. It defines not only the words used for the XOM interface, but also the words required in the calculation and judgment logic.
By defining words with limited patterns such as product names and business establishment names as "domains", it is possible to efficiently develop and verify rules.
Click Create BOM on the decision service map.
Keep the defaults and click Next.
Click the "Browse for XOM" button on the right, select the "Customer Loyalty XOM" you just created, and click "Finish".
Double-click Model in Rule Explorer to open it.
Expand the package and double-click on the "Loyalty" class.
In the verbalization section of the class, click Edit Term.
Change the label to "Loyalty Program" and click the "OK" button.
Next, verbalize the members. Double-click on "discount_rate" at the top of the members section.
In the member's verbalization section, click the "Edit subject used in the phrase" link.
Change the label to "Discount Rate" and click "OK".
The term discount rate remains in the action template. Edit the text and change it to "Discount rate".
Verbalize the other members in the same way. Select the Classes tab under the BOM editor and double-click on the second "lank" from the members section.
In the member's verbalization section, click Edit subject used in the phrase.
Change the label to "Customer Rank" and click the "OK" button.
Edit the word "lank" that remains in the action template to "Customer Rank".
Customer ranks are limited to a few types, so create a domain to identify the term. Click Create Domain in the Domains section.
From the domain type, select Literal and click Next.
Click the "Add" button on the right and change the newValue added to the list to "Platinum". Similarly, add gold, silver and bronze and click Finish.
Under the BOM editor, select the Classes tab and double-click on the third "message" from the Members section.
Click the "Edit subject used in the phrase" link in the member's verbalization section.
Change the label to "Message" and click the "OK" button.
Edit the word "message" that remains in the action template to "message".
Click Ctrl + S to save your changes.
A decision operation is an interface definition when a rule is called from the outside. This is an operation that has the XOM created in the previous step as a parameter. Here, the decision-making operation is defined and verbalized (Japaneseized), and the order of calculation and judgment in the rule is defined as the rule flow.
From the decision service map, click Add Decision Operation.
Enter "getDiscount" as the name of the operation and click the "Finish" button.
From the decision service map, click Go to Operations Map.
In the decision operation selection window, select "getDiscount" and click the "OK" button.
The operation map opens. Click "Add Variable Set".
Enter param as the name of the variable set and click Finish.
Click the Add button on the right side of the variable set editor and change the type to "Loyalty" and the verbalization to "Loyalty Program".
Click Ctrl + S to save your changes and close the variable set editor.
Click Bind Variable on the operation map.
Drag and drop the variable (myVar) you just added into the I / O Parameters section.
Click Ctrl + S to save your changes and close the decision operation editor.
Then click Add Rule Package on the operation map.
Enter "Judgment" in the name of the package and click the "Finish" button.
On the operation map, click Add Rule Flow.
Enter Main Flow as the name of the rule flow and click the Finish button.
The Rule Flow Editor opens. Click Start Node (top arrow icon) in the palette on the left, then click on the editor.
Similarly, click the "End Node" (the second red circle icon), then click on the editor. The start and end nodes should be arranged as shown below.
Click Rule Tasks (third gear icon) in the palette on the left, then click between the start and end nodes in the editor.
In the properties under the editor, change the label of the rule task to "judgment".
Click the Edit button on the Select Rule tab of the properties.
Click the >> button in the rule selection window and select the Judgment rule package (displayed in the list on the right).
Click Transition (down arrow at the bottom) from the Rule Flow Editor palette. Click the start node, rule task, and end node in that order to connect.
Right-click on the editor and select "Layout of all nodes". The flow is as follows.
Display the operation map again. Click "Bind Rule Flow".
The decision operation editor opens. In the Rule Flow section, click the Select Rule Flow link and select the Main Flow you just created.
Click Ctrl + S to save your changes and close the Decision Operations Editor.
From the operation map, click Add Action Rule.
Click the Browse button next to the package and select the Judgment package. This will include the action rule in the Judgment package and execute it within the rule flow.
Enter "Empty Rank Check" in the name and click "Finish".
The Rule Editor opens. Click Ctrl + Space and the Code Assist feature will display the wording of the rule. Create a rule like the one below. (You can also enter text directly)
Enter "1" for the priority in the properties at the bottom of the screen. If there are multiple rules in the same rule package, this setting causes the rules to run first.
Return to the operation map again and click "Add Decision Table".
Select Judgment for the package and enter Discount Judgment for the name. Click the "Finish" button.
An empty decision table is created. Right-click on column A and select "Edit Condition Column".
In the Test section of the Edit Column window, use Code Assist and enter the following: "Customer rank of'loyalty program'is the same as
Change the title to "Customer Rank" and click the "OK" button.
Right-click columns B and C of the decision table and delete the condition column.
Right-click the action column (grayish column) in the decision table and select Edit Action Column.
Change the action to "Set the loyalty program discount rate to
Enter "Discount rate" in the title and click the "OK" button.
Right-click on the condition column "Customer Rank" and select "Add> All Domain Values". All domains defined in the BOM are added.
Enter an appropriate number (a decimal from 0.01 to 0.99) in the action column "Discount rate".
It is also possible to display the discount rate in%. Right-click on the action column and select Format. (Select columns, not single cells)
From the list of formats, select "{0, number, percent}". Click the "OK" button to close the window.
Make sure that the discount rate on the decision table is displayed in%.
Click Ctrl + S to save your changes and close the decision table editor.
This time, I used Rule Designer to develop a simple rule. Next time, I'll show you how to deploy this rule to your server for testing and editing.