Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-3322

declared class inserted from function hidden from engine

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 5.3.0.Final
    • drools-core
    • None
    • Hide

      Example:

      ksession.insert(objectA);
      ksession.insert(objectB);
      ksession.getAgenda().getAgendaGroup("Foo").setFocus();

      I have 2 rules simplified down to illustrate my confusion. The first rule simply sets some default values evaluated in the second rule if objectA exists. In the example that works I set the defaults in the RHS explicitly. However I want to use these defaults from different agenda-groups, so when I put them in a function, the second rule never fires, the activation is created for the first rule but never the second. Can someone tell me why the use of a function seems to alter the truth of the rule?

      THIS WORKS:

      declare SomeDefault
      minValueA : Integer
      minValueB : Double
      maxValueB : Double
      end

      rule "Check Object A and Set Default"
      agenda-group "Foo"
      salience 100
      when
      $a : ObjectA()
      then
      default = new SomeDefault()
      default.minValueA = 100
      default.minValueB = 20.0
      default.maxValueB = 20000.0
      insert(default)
      end

      rule "Use the defaults"
      agenda-group "Foo"
      salience 100
      when
      $default : SomeDefault()
      then
      System.out.println("Default minA=" + $default.minValueA)
      end

      THIS DOES NOT WORK:

      declare SomeDefault
      minValueA : Integer
      minValueB : Double
      maxValueB : Double
      end

      rule "Check Object A and Set Default"
      agenda-group "Foo"
      salience 100
      when
      $a : ObjectA()
      then
      insertDefault(drools.getWorkingMemory())
      end

      rule "Use the defaults"
      agenda-group "Foo"
      salience 90
      when
      $default : SomeDefault()
      then
      System.out.println("Default minA=" + $default.minValueA)
      end

      function void insertDefault(WorkingMemory workingMemory) {
      SomeDefault default = new SomeDefault();
      default.setMinValueA(100);
      default.setMinValueB(20.0);
      default.setMaxValueB(20000.0);
      workingMemory.insert(default);
      }

      In the latter (non-working) example the first rule activates and then drools returns, it never even attempts to try to fire the second rule. However in the working example BOTH rules fire as I would expect.

      Show
      Example: ksession.insert(objectA); ksession.insert(objectB); ksession.getAgenda().getAgendaGroup("Foo").setFocus(); I have 2 rules simplified down to illustrate my confusion. The first rule simply sets some default values evaluated in the second rule if objectA exists. In the example that works I set the defaults in the RHS explicitly. However I want to use these defaults from different agenda-groups, so when I put them in a function, the second rule never fires, the activation is created for the first rule but never the second. Can someone tell me why the use of a function seems to alter the truth of the rule? THIS WORKS: declare SomeDefault minValueA : Integer minValueB : Double maxValueB : Double end rule "Check Object A and Set Default" agenda-group "Foo" salience 100 when $a : ObjectA() then default = new SomeDefault() default.minValueA = 100 default.minValueB = 20.0 default.maxValueB = 20000.0 insert(default) end rule "Use the defaults" agenda-group "Foo" salience 100 when $default : SomeDefault() then System.out.println("Default minA=" + $default.minValueA) end THIS DOES NOT WORK: declare SomeDefault minValueA : Integer minValueB : Double maxValueB : Double end rule "Check Object A and Set Default" agenda-group "Foo" salience 100 when $a : ObjectA() then insertDefault(drools.getWorkingMemory()) end rule "Use the defaults" agenda-group "Foo" salience 90 when $default : SomeDefault() then System.out.println("Default minA=" + $default.minValueA) end function void insertDefault(WorkingMemory workingMemory) { SomeDefault default = new SomeDefault(); default.setMinValueA(100); default.setMinValueB(20.0); default.setMaxValueB(20000.0); workingMemory.insert(default); } In the latter (non-working) example the first rule activates and then drools returns, it never even attempts to try to fire the second rule. However in the working example BOTH rules fire as I would expect.

      When declaring a class within a DRL and using a function to insert a populated fact into working memory, the inserted class is not seen by the engine and therefore not available to downstream rules. See steps to reproduce for an example.

      Explanation from users mailing list (Wolfgang Luan):

      This is a bug. Please submit a JIRA.

      In spite of all the fixes that have been made, using dialect "mvel" is still risky.

      In this case, it would appear that the WM insert from inside the called function is somehow hidden from the Engine due to the RHS being evaluated in a MVEL context. You can easily verify this by adding another rule:

      rule "objects"

        1. agenda-group "Foo" (not
          when
          $object: Object()
          then
          System.out.println( "Fact: " + $object.getClass() + " " + $object);
          end

            mproctor@redhat.com Mark Proctor
            milehimikey Mike Key (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

              Created:
              Updated:
              Archived: