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

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

    XMLWordPrintable

    Details

      Description

      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 ) ); }

      .

        Attachments

          Activity

            People

            Assignee:
            mfusco Mario Fusco
            Reporter:
            k_rudenko Kateryna Rudenko (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: