Creating Rules and Synchronizing Modules

In this step of the Rule Engine trail, create a new source rule, see how source rules are versioned, and carry out module synchronization in the Backoffice.

Context

Source Rules are versioned by the Rule Engine. A new source rule version is created whenever the rule diverges from the last published version of that source rule. This step of the trail illustrates how source rule versioning works.

Procedure

  1. Log on to the Backoffice and navigate to Start of the navigation pathRule Engine Next navigation step Source Rules Next navigation step Show AllEnd of the navigation path.
  2. To create a new custom source rule, click + CustomSourceRule.
  3. Enter a name and a code for your new rule, for example:
    • Code: custom_source_rule_order_fixed_discount
    • Name:Custom source rule order fixed discount
  4. Open the newly created rule. On the Conditions & Actions tab, add the Cart total Condition, which is mapped to the CustomSourceRule in the previous steps. Add value (for example, USD 200) to the cart total value in the Condition. For the Action, use Fixed Discount on Cart, which is also mapped to the CustomSourceRule. Then specify an absolute discount value (for example, USD 10).
  5. Save the rule.

    The Source Rule is version 0 and has the status Unpublished.

  6. Publish the rule to the customdrools-preview-module. Only the two rule modules created earlier in the trail can be chosen as publication target. This is due to the RuleToEngineRuleTypeMapping we added earlier.

    Verify that the rule is successfully published (the status is now Published). In the Availability column, you see the customdroolsrule-preview-module listed.

  7. You can also switch to Start of the navigation pathRule Engine Next navigation step Drools RulesEnd of the navigation path and verify that there is a rule custom_source_rule_order_fixed_discount with the rule type CUSTOMDROOLSRULE. Note that the version of the Drools rule might differ from the version of the source rule, as the versioning mechanisms work differently.
  8. To synchronize modules, navigate to Start of the navigation pathRule Engine Next navigation step Drools ModulesEnd of the navigation path and perform the following:
    1. Click on the customdroolsrule-module. Verify that it is not possible to synchronize the rule module. This is because we have not defined any allowed target rule modules for this rule module.
    2. Switch to the customdroolsrule-preview-module. Click the Synchronize button.
    3. In the dialog window, customdroolsrule-module is pre-selected as the target module. Click Synchronize to start module synchronization. This synchronizes the customdroolsrule-module with the customdroolsrule-preview-module. Backoffice notifications inform you about the start and end of the rule module synchronization.
    4. Return to Start of the navigation pathRule Engine Next navigation step Source Rules Next navigation step Show AllEnd of the navigation path and inspect the custom source rule. Note that the version is still 0, the status is still Published and that Availabilitycolumn now also lists the customdroolsrule-module.
    5. Switch to Start of the navigation pathRule Engine Next navigation step Drools RuleEnd of the navigation path. Note that there are now two rules with the code of our source rule. Each time a source rule is published to a rule module, a separate Drools rule is created. Thus, the Drools rule version does not match the source rule version.
  9. Go to Start of the navigation pathRule Engine Next navigation step Source Rules Next navigation step Show AllEnd of the navigation path and open the custom_source_rule_order_fixed_discount source rule in the Rule Builder. Make any change to the rule, for example:
    1. Change the Cart total threshold from 200 to 180.
    2. Save the rule. Note in the list view of all source rules that there are now two rules with the code custom_source_rule_order_fixed_discount. (You might have to refresh the list view to see the change.) The source rule versioning creates a new version whenever the source rule diverges from the most recently published source rule. The new version has the next higher version number, for example, 1, and has the status Unpublished. Also note that you are only able to save changes to the latest source rule version.
  10. Edit the new unpublished new version of the source rule by changing the discount value of the Fixed discount action to 20. Save the rule. Note that this does not create a new source rule version, as the edited rule is still unpublished.
  11. Publish the new version of the source rule to the preview module again. In the source rule list view, you can now see that version 0 of the rule is no longer available in the preview module, but only in the customdroolsrule-module. While version 1 is not available in the preview module.
  12. You can optionally switch to the Start of the navigation pathRule Engine Next navigation step Drools RulesEnd of the navigation path to see two rules, one published in each rule module. In reality, a third Drools rule has been created as we have published three times in total, two regular publications and one publication as part of the rule module synchronization. Each rule publication creates a new engine rule. Any previously created rule that belongs to the same source rule will be marked as "Is current version?" with the value False as it is no longer the current version. The default view of Drools Rules only shows the most current version, which is why only two rules are visible in the list view. You can remove the "Is current version?" search restriction in the advanced search to see all rules.

Results

This concludes the Rule Engine trail.