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

DrlDumper does wrong dumps, when lhs contains complex conditions with And.

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

XMLWordPrintable

      DrlDumper does wrong dumps, when lhs contains complex conditions with And.

      When there is ConditionalElementDescr in other ConditionalElementDescr, DrlDumper prints condition without round brackets. But should, because formed text can not be parsed with DrlParser into the same tree structure.

      Example 1.
      rule in file "Test1.drl":

      rule "continued_rule"
      no-loop true
      when
      ($a : Action1() || $b : Action2())
      &&
      ($c : Action3() || $d : Action4())
      then
      System.out.println("Fired.");
      end

      And method:
      public void test1() throws DroolsParserException
      {
      DrlParser parser = new DrlParser();
      final InputStream drl = getClass().getResourceAsStream(
      "Test1.drl");
      final PackageDescr packageDescr = parser.parse(drl);
      if (parser.hasErrors())

      { Assert.fail(parser.getErrors().toString()); }

      final String dump = new DrlDumper().dump(packageDescr);
      System.out.println(dump);
      }

      Output is:
      rule "continued_rule"
      no-loop true
      when
      $a : Action1( ) || $b : Action2( ) && $c : Action3( ) || $d : Action4( )
      then
      System.out.println("Fired.");
      end

      According to operation priority in this case will be
      $a : Action1( ) || ($b : Action2( ) && $c : Action3( )) || $d : Action4( )
      and it is quite another operation.

      DrlDumper should support brackets to save operation grouping.

      Example 2.
      Rule
      rule "continued_rule2"
      no-loop true
      when
      ($a : Action1() && $b : Action2())

      ($c : Action3() && $d : Action4())
      then
      System.out.println("Fired.");
      end

      Out after performing test1() from Example 1:
      rule "continued_rule"
      no-loop true
      when
      $a : Action1( ) || $c : Action3( )
      then
      System.out.println("Fired.");
      end
      DrlDumper lost $b : Action2() and $d : Action4()! It happened because processOrDescrList in DrlDumper.
      In string
      if ( descrString.endsWith( DrlDumper.eol ) )

      { descrString = descrString.substring( 0, descrString.indexOf( DrlDumper.eol ) ); }


      we lose all subconditions except first line. It should be
      if ( descrString.endsWith( DrlDumper.eol ) )

      { descrString = descrString.substring( 0, descrString.LastIndexOf( DrlDumper.eol ) ); }

      .

              mfusco@redhat.com Mario Fusco
              k_rudenko Kateryna Rudenko (Inactive)
              Archiver:
              rhn-support-ceverson Clark Everson

                Created:
                Updated:
                Resolved:
                Archived: