Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-365

Rule attribute for adding inverse of consequence as rule condition

    Details

    • Type: Feature Request
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 5.5.0.Final
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      I have quite a few rules that look like this:

      rule "if foo then bar"
        when
          Foo($a : a, $b : b)
          not Bar(a == $a, b == $b)
        then
          insert(new Bar($a, $b));
      end
      

      This is a fairly common pattern for me: a rule should not activate if the facts generated by its consequence were already asserted. It's a pattern I use extensively to generate linear (i.e. non-repeating) workflows.

      Ideally I'd be able to express it as follows:

      rule "if foo then bar"
      condition-on-inverse-of-consequence
        when
          Foo($a : a, $b : b)
        then
          insert(new Bar($a, $b));
      end
      

      And condition-on-inverse-of-consequence would cause Drools to generate the right kind of condition, which would be the inverse of the fact changes made by the consequence.

      I think lock-on-active is similar but harsher: it prevents the rule from firing a second time altogether, regardless of input. At least, that's based on my reading of the docs. In my example, that would be equivalent to not Bar() condition in the rule, which is stricter than not Bar(a == $a, b == $b).

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  mark.proctor Mark Proctor
                  Reporter:
                  hltbdivl Adar Dembo
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: