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

Accumulate doesn't get modified and parsed to double String correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not a Bug
    • Icon: Optional Optional
    • None
    • None
    • None
    • Hide
      Bar.java
      rule "Inserting rule"
      salience 10
      when
      then
          Resource resource1 = new Resource();
          resource1.setName("Resource 1");
          resource1.setAmount("5");
          insert(resource1);
          System.out.println("Resource is set");
      end
      
      rule "Modifying rule"
      salience 20
      when
          $resource1: Resource(name == "Resource 1")
      then
          modify($resource1) {setAmount("20")};
          System.out.println("Resource is modified to 20");
      end
      
      rule "Accumulating rule"
      salience 30
      when
          Resource(amount != "")
          $total: Number() from accumulate(
              Resource($amount: Double.parseDouble(amount)),
              sum($amount))
      then
          System.out.println("Accumulated: " + $total);
      end
      

      So the output is

      Resource is set
      Accumulated: 5.0
      Resource is modified to 20
      Accumulated: 5.0

      The last line expected as "Accumulate: 20.0"

      Show
      Bar.java rule "Inserting rule" salience 10 when then Resource resource1 = new Resource(); resource1.setName( "Resource 1" ); resource1.setAmount( "5" ); insert(resource1); System .out.println( "Resource is set" ); end rule "Modifying rule" salience 20 when $resource1: Resource(name == "Resource 1" ) then modify($resource1) {setAmount( "20" )}; System .out.println( "Resource is modified to 20" ); end rule "Accumulating rule" salience 30 when Resource(amount != "") $total: Number () from accumulate( Resource($amount: Double .parseDouble(amount)), sum($amount)) then System .out.println( "Accumulated: " + $total); end So the output is Resource is set Accumulated: 5.0 Resource is modified to 20 Accumulated: 5.0 The last line expected as "Accumulate: 20.0"
    • NEW
    • NEW

      I have to sum one field on all objects of "Resource" class. And I found out that accumulate's behavior is odd when before accumulating I am modifying that field.

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

                Created:
                Updated:
                Resolved: