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

Evaluation of facts hasn't been affected by 'modify()' when parsing String to Double

XMLWordPrintable

    • 2019 Week 20-22
    • 3
    • Hide
      rule "Rule 1"
      salience 30
      when
      
      then
          Resource resource1 = new Resource();
          resource1.setName("Resource 1");
          resource1.setAmount("5");
          insert(resource1);
          System.out.println("First");
      end
      
      rule "Rule 2"
      salience 20
      //no-loop - next rule fires if use 'update()' instead
      when
          $resource1: Resource(name == "Resource 1")
      then
          modify($resource1) {setAmount("20")};
      //    update($resource1);
          System.out.println("Second");
      end
      
      rule "Rule 3"
      salience 30
      when
          $resource1: Resource(name == "Resource 1", Double.parseDouble(amount) == 20.0)
      //    - interesting that the line below fires this rule
      //    $resource1: Resource(name == "Resource 1", amount.startsWith("20"))
      then
          System.out.println("Rule is fired"); //doesn't fire
      end
      
      Show
      rule "Rule 1" salience 30 when then Resource resource1 = new Resource(); resource1.setName( "Resource 1" ); resource1.setAmount( "5" ); insert(resource1); System .out.println( "First" ); end rule "Rule 2" salience 20 //no-loop - next rule fires if use 'update()' instead when $resource1: Resource(name == "Resource 1" ) then modify($resource1) {setAmount( "20" )}; // update($resource1); System .out.println( "Second" ); end rule "Rule 3" salience 30 when $resource1: Resource(name == "Resource 1" , Double .parseDouble(amount) == 20.0) // - interesting that the line below fires this rule // $resource1: Resource(name == "Resource 1" , amount.startsWith( "20" )) then System .out.println( "Rule is fired" ); //doesn't fire end
    • Hide

      So why it works with java String methods, but doesn't with Double parsing?
      And I try to walk away situations of using 'update()' as it is being noted often in books about Drools. Because when I have a lot of rules updating may brake my saliences leading to unexpected executions.

      Show
      So why it works with java String methods, but doesn't with Double parsing? And I try to walk away situations of using 'update()' as it is being noted often in books about Drools. Because when I have a lot of rules updating may brake my saliences leading to unexpected executions.
    • NEW
    • NEW

      When I modify amount in an example below from 5 to 20 (both are Strings) and then try to evaluate this fact parsing it to Double - the third rule doesn't fire. But it fires when use 'update()' instead of 'modify() {}'

              mfusco@redhat.com Mario Fusco
              almastoimbekov Almas Toimbekov (Inactive)
              Tibor Zimányi Tibor Zimányi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: