[JAVA] I touched ODM for Developer ② Rule development

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.

Eclipse installation

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.

  1. If you don't have Eclipse or the version is different, please install Eclipse Oxygen.

  2. Start Eclipse and open the Eclipse Marketplace window. Search for "odm" and install IBM ODM Rule Designer for Developer V8.10.1. a1.png

  3. In the license confirmation window, select "I accept the terms…" and click the "Finish" button.

  4. After the installation is complete, restart Eclipse. Make sure the rule perspective has been added. a2.png

The rule development environment is ready. In the following steps, we will develop a simple rule.

Creating an Execution Model (XOM)

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.

  1. Open the Java perspective in Eclipse. Click New> Java Project. b1.png

  2. Enter CustomerLoyaltyXOM as the name of the project, make sure the JRE version is 1.8, and click Finish. b2.png

  3. Right-click on the Java project you created in Package Explorer and select New> Class. b3.png

  4. Enter "my.first.rule" for the package name and "Loyalty" for the class name, then click Finish. b4.png

  5. The Java editor opens. Create three Private variables as shown below. b5.png

  6. Right-click on the Java editor and select Source> Generate Getter and Setter.

  7. Click Select all on the right, then click the OK button. b7.png

  8. Right-click again in the Java editor and select Source> Generate Constructor using Fields.

  9. Make sure three fields are selected by default and click OK. b9.png

  10. Right-click again in the Java editor and select Source> Generate Constructor from Superclass.

  11. Keep the defaults and click OK. b11.png

  12. The code should look like the following. Press Ctrl + S to save. b12.png

Rule project creation and XOM import

  1. Click the icon in the upper right corner of Eclipse to switch to the rules perspective. c1.png

  2. 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. c2.png

  3. Make sure Main Rule Project is selected for the template and click Next. c3.png

  4. Enter CustomerLoyaltyRule as the name of the rule project and click Finish. c4.png

  5. From the decision service map displayed at the bottom of the screen, click "Import XOM".

  6. Make sure Java Execution Object Model is selected and click OK. c6.png

  7. Check "Customer Loyalty XOM" from the list and click "Apply and Close". c7.png

Creating a business object model (BOM)

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.

  1. Click Create BOM on the decision service map.

  2. Keep the defaults and click Next. d2.png

  3. Click the "Browse for XOM" button on the right, select the "Customer Loyalty XOM" you just created, and click "Finish". d3.png

  4. Double-click Model in Rule Explorer to open it. d4.png

  5. Expand the package and double-click on the "Loyalty" class. d5.png

  6. In the verbalization section of the class, click Edit Term. d6.png

  7. Change the label to "Loyalty Program" and click the "OK" button. d7.png

  8. Next, verbalize the members. Double-click on "discount_rate" at the top of the members section.

  9. In the member's verbalization section, click the "Edit subject used in the phrase" link. d9.png

  10. Change the label to "Discount Rate" and click "OK". d10.png

  11. The term discount rate remains in the action template. Edit the text and change it to "Discount rate". d11.png

  12. 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.

  13. In the member's verbalization section, click Edit subject used in the phrase.

  14. Change the label to "Customer Rank" and click the "OK" button.

  15. Edit the word "lank" that remains in the action template to "Customer Rank".

  16. Customer ranks are limited to a few types, so create a domain to identify the term. Click Create Domain in the Domains section. d16.png

  17. From the domain type, select Literal and click Next. d17.png

  18. 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. d18.png

  19. Under the BOM editor, select the Classes tab and double-click on the third "message" from the Members section.

  20. Click the "Edit subject used in the phrase" link in the member's verbalization section.

  21. Change the label to "Message" and click the "OK" button.

  22. Edit the word "message" that remains in the action template to "message".

  23. Click Ctrl + S to save your changes.

Decision-making operations and rule flow creation

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.

  1. From the decision service map, click Add Decision Operation.

  2. Enter "getDiscount" as the name of the operation and click the "Finish" button. e2.png

  3. From the decision service map, click Go to Operations Map.

  4. In the decision operation selection window, select "getDiscount" and click the "OK" button. e4.png

  5. The operation map opens. Click "Add Variable Set". e5.png

  6. Enter param as the name of the variable set and click Finish. e6.png

  7. 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". e7.png

  8. Click Ctrl + S to save your changes and close the variable set editor.

  9. Click Bind Variable on the operation map.

  10. Drag and drop the variable (myVar) you just added into the I / O Parameters section. e10.png

  11. Click Ctrl + S to save your changes and close the decision operation editor.

  12. Then click Add Rule Package on the operation map.

  13. Enter "Judgment" in the name of the package and click the "Finish" button. e13.png

  14. On the operation map, click Add Rule Flow.

  15. Enter Main Flow as the name of the rule flow and click the Finish button. e15.png

  16. The Rule Flow Editor opens. Click Start Node (top arrow icon) in the palette on the left, then click on the editor.

  17. 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. e18.png

  18. Click Rule Tasks (third gear icon) in the palette on the left, then click between the start and end nodes in the editor.

  19. In the properties under the editor, change the label of the rule task to "judgment". e20.png

  20. Click the Edit button on the Select Rule tab of the properties.

  21. Click the >> button in the rule selection window and select the Judgment rule package (displayed in the list on the right). e22.png

  22. 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.

  23. Right-click on the editor and select "Layout of all nodes". The flow is as follows. e24.png

  24. Display the operation map again. Click "Bind Rule Flow".

  25. The decision operation editor opens. In the Rule Flow section, click the Select Rule Flow link and select the Main Flow you just created. e26.png

  26. Click Ctrl + S to save your changes and close the Decision Operations Editor.

Rule definition

  1. From the operation map, click Add Action Rule.

  2. 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.

  3. Enter "Empty Rank Check" in the name and click "Finish". f3.png

  4. 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) f4.png

  5. 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.

  6. Return to the operation map again and click "Add Decision Table".

  7. Select Judgment for the package and enter Discount Judgment for the name. Click the "Finish" button. f7.png

  8. An empty decision table is created. Right-click on column A and select "Edit Condition Column". f8.png

  9. 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 " f9.png

  10. Change the title to "Customer Rank" and click the "OK" button.

  11. Right-click columns B and C of the decision table and delete the condition column.

  12. Right-click the action column (grayish column) in the decision table and select Edit Action Column. f12.png

  13. Change the action to "Set the loyalty program discount rate to ".

  14. Enter "Discount rate" in the title and click the "OK" button. f14.png

  15. Right-click on the condition column "Customer Rank" and select "Add> All Domain Values". All domains defined in the BOM are added. f15.png

  16. Enter an appropriate number (a decimal from 0.01 to 0.99) in the action column "Discount rate". f16.png

  17. It is also possible to display the discount rate in%. Right-click on the action column and select Format. (Select columns, not single cells)

  18. From the list of formats, select "{0, number, percent}". Click the "OK" button to close the window. f18.png

  19. Make sure that the discount rate on the decision table is displayed in%.

  20. Click Ctrl + S to save your changes and close the decision table editor.

  21. Summary

    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.