jrulesibm-odm

How to define a function for use in an ODM decision table w/o changing the XOM?


I'm using ODM 8.5 (the JRules successor). In my Java domain, I have a three-character String field that represents a number, "000" to "999". I'd like to have a decision table that represents logic like:

if field is between "000" and "012" then set the result to "tiny"
if field is between "013" and "060" then set the result to "less tiny"
...

IBM's documentation on defining columns states - "A condition statement is an incomplete BAL predicate expression...". Is there anything in the BAL that does the kind of String comparison I want to do? If not, is it possible to call a function defined in the IRL from the BAL? If so, how? I'm also open to other suggestions on how to handle this simple problem in ODM (without changing the existing Java XOM). Right now, it looks to me that I can't use an ODM decision table, although the underlying logic seems well-suited to a decision table.


Solution

  • This answer is heavily based on Justin Phillips's nice answer to this question, updated for ODM 8.5. Please plus up his answer.

    The main idea is to create a function in the Business Object Model (BOM) that can be called from your rules. To add a BOM function:

    1. Right click the bom folder in the Eclipse rules project.
    2. Select New -> BOM Entry from the menu.
    3. Select the Create an empty BOM entry option and then click Finish.
    4. Double click the new BOM entry to bring up the BOM editor view, and then click New Class.
    5. Enter the class name and then click Finish.
    6. Double click the new BOM class from the list, then under the Members section, click the New button.
    7. In the New Member dialog, select the Method option, enter a Name (isBetween), return Type for the method (boolean), and add three String parameters (testee - the value being tested, min and max). Click the Finish button.
    8. Double click the new method under the Members section, and select the Static and Final options.
    9. Click the Create link under the "Member Verbalization" section and fill in the Template text box with {0} is between {1,min} to {2,max}
    10. Under the BOM to XOM Mapping section, enter your Java code.

    enter image description here 11. Go back to the class level BOM editor and set the Execution name to the value void in the "BOM to XOM Mapping" section. This indicates that the BOM class is not linked to a Java class (XOM).

    The verbalization for the newly created member should now be accessible when filling out the Test in the Condition Column for the decision table.