Uploaded image for project: 'Red Hat Decision Manager'
  1. Red Hat Decision Manager
  2. RHDM-25

Use of "contains" operator does not add values from enumeration with quotes in Guided Rules etc.

XMLWordPrintable

    • Release Notes
    • Hide

      ==> Enumeration:
      ~~~
      'SimpleFact.factOne' : ['one','two','three']
      ~~~

      ==> Fact: SimpleFact
      ~~~
      public class SimpleFact implements java.io.Serializable
      {

      static final long serialVersionUID = 1L;

      @org.kie.api.definition.type.Label(value = "factOne")
      private java.util.List<java.lang.String> factOne;

      public SimpleFact()
      {
      }

      public java.util.List<java.lang.String> getFactOne()

      { return this.factOne; }

      public void setFactOne(java.util.List<java.lang.String> factOne)

      { this.factOne = factOne; }

      public SimpleFact(java.util.List<java.lang.String> factOne)
      { this.factOne = factOne; }

      }
      ~~~

      ==> Guided Rule (using above enumeration and fact):
      ~~~
      package simplepackage;

      import java.lang.Number;

      rule "SimpleEnumGuidedRule"
      dialect "mvel"
      when
      SimpleFact( factOne contains two )
      then
      end
      ~~~
      Here you can see that although it is an enumeration for "factOne" , but the chosen value "two" does not contain quotes. This causes the issue given below.

      Result while building project/validating the rule:
      ~~~
      20:15:34,050 ERROR [org.drools.compiler.kie.builder.impl.AbstractKieModule] (http-127.0.0.1:8080-1) Unable to build KieBaseModel:defaultKieBase
      Unable to Analyse Expression two:
      [Error: unable to resolve method using strict-mode: simplepackage.SimpleFact.two()]
      [Near :

      {... two ....}

      ]
      ^ : [Rule name='SimpleEnumGuidedRule']

      Unable to Analyse Expression factOne contains two:
      [Error: unable to resolve method using strict-mode: simplepackage.SimpleFact.two()]
      [Near :

      {... factOne contains two ....}

      ]
      ^
      [Line: 8, Column: 2] : [Rule name='SimpleEnumGuidedRule']

      Unable to Analyse Expression @Modify with( f1 )

      { setFactOne( one ) };:

      ~~~


      ==> Guided Decision Table (source given below):
      ~~~
      package simplepackage;

      import java.util.List;
      import java.lang.Number;

      //from row number: 1
      rule "Row 1 GuidedEnumerationTable"
      dialect "mvel"
      when
      f1 : SimpleFact( factOne contains "one" )
      then
      modify( f1 ) { setFactOne( one ) }
      end

      //from row number: 2
      rule "Row 2 GuidedEnumerationTable"
      dialect "mvel"
      when
      f1 : SimpleFact( factOne contains "two" )
      then
      modify( f1 ) { setFactOne( one ) }
      end

      //from row number: 3
      rule "Row 3 GuidedEnumerationTable"
      dialect "mvel"
      when
      f1 : SimpleFact( factOne contains "three" )
      then
      modify( f1 ) { setFactOne( one ) }
      end

      ~~~

      Here you can see that although in condition section the values for enumerated field "factOne" is chosen with quotes ("three") , but in then section the setter method does not contain the value in quotes .

      Result while building project/validating the rule:
      ~~~
      [Line: 8, Column: 2] : [Rule name='SimpleEnumGuidedRule']

      Unable to Analyse Expression @Modify with( f1 ) { setFactOne( one ) }

      ;:
      [Error: unable to resolve method using strict-mode: org.drools.core.spi.KnowledgeHelper.one()]
      [Near : {... @Modify with( f1 )

      { setFactOne( one ) }

      ; ....}]
      ^
      ~~~

      ==> Guided Decision Template (source given below):

      Unfortunately due to some issues , I am not able to see the rule source at my end. But I used the same enumeration as shown above and I can see that it does not cause any validation error. I also tested in a separate project as seen in the attached second archive "Model_TestProject.zip" , where I used similar tests on Guided Decision Template, and there as well the template validates fine and the project builds fine too. However as per some users, they are seeing validation errors in Guided Decision Template too.

      Show
      ==> Enumeration: ~~~ 'SimpleFact.factOne' : ['one','two','three'] ~~~ ==> Fact: SimpleFact ~~~ public class SimpleFact implements java.io.Serializable { static final long serialVersionUID = 1L; @org.kie.api.definition.type.Label(value = "factOne") private java.util.List<java.lang.String> factOne; public SimpleFact() { } public java.util.List<java.lang.String> getFactOne() { return this.factOne; } public void setFactOne(java.util.List<java.lang.String> factOne) { this.factOne = factOne; } public SimpleFact(java.util.List<java.lang.String> factOne) { this.factOne = factOne; } } ~~~ ==> Guided Rule (using above enumeration and fact): ~~~ package simplepackage; import java.lang.Number; rule "SimpleEnumGuidedRule" dialect "mvel" when SimpleFact( factOne contains two ) then end ~~~ Here you can see that although it is an enumeration for "factOne" , but the chosen value "two" does not contain quotes. This causes the issue given below. Result while building project/validating the rule: ~~~ 20:15:34,050 ERROR [org.drools.compiler.kie.builder.impl.AbstractKieModule] (http-127.0.0.1:8080-1) Unable to build KieBaseModel:defaultKieBase Unable to Analyse Expression two: [Error: unable to resolve method using strict-mode: simplepackage.SimpleFact.two()] [Near : {... two ....} ] ^ : [Rule name='SimpleEnumGuidedRule'] Unable to Analyse Expression factOne contains two: [Error: unable to resolve method using strict-mode: simplepackage.SimpleFact.two()] [Near : {... factOne contains two ....} ] ^ [Line: 8, Column: 2] : [Rule name='SimpleEnumGuidedRule'] Unable to Analyse Expression @Modify with( f1 ) { setFactOne( one ) };: ~~~ ==> Guided Decision Table (source given below): ~~~ package simplepackage; import java.util.List; import java.lang.Number; //from row number: 1 rule "Row 1 GuidedEnumerationTable" dialect "mvel" when f1 : SimpleFact( factOne contains "one" ) then modify( f1 ) { setFactOne( one ) } end //from row number: 2 rule "Row 2 GuidedEnumerationTable" dialect "mvel" when f1 : SimpleFact( factOne contains "two" ) then modify( f1 ) { setFactOne( one ) } end //from row number: 3 rule "Row 3 GuidedEnumerationTable" dialect "mvel" when f1 : SimpleFact( factOne contains "three" ) then modify( f1 ) { setFactOne( one ) } end ~~~ Here you can see that although in condition section the values for enumerated field "factOne" is chosen with quotes ("three") , but in then section the setter method does not contain the value in quotes . Result while building project/validating the rule: ~~~ [Line: 8, Column: 2] : [Rule name='SimpleEnumGuidedRule'] Unable to Analyse Expression @Modify with( f1 ) { setFactOne( one ) } ;: [Error: unable to resolve method using strict-mode: org.drools.core.spi.KnowledgeHelper.one()] [Near : {... @Modify with( f1 ) { setFactOne( one ) } ; ....}] ^ ~~~ ==> Guided Decision Template (source given below): Unfortunately due to some issues , I am not able to see the rule source at my end. But I used the same enumeration as shown above and I can see that it does not cause any validation error. I also tested in a separate project as seen in the attached second archive "Model_TestProject.zip" , where I used similar tests on Guided Decision Template, and there as well the template validates fine and the project builds fine too. However as per some users, they are seeing validation errors in Guided Decision Template too.

      • The issue mentioned in the title could be seen with the use case of enumeration with Guided Rules, Guided Decision Tables and as per some users Guided Decision Template too (although my attached test case might not be able to replicate this one). The issue occurs when we use Enumeration for a field of a fact in Guided rules and we could see that the resultant rule does not contain the selected value from the enumeration drop down as within quotes ("") , thus resulting validation errors. Following are my findings from the research and it can be validated it from the attached project archive "repository1_TestProject.zip" as well.
      • Although the use case of an enumeration used for a 'List' type of fact ('SimpleFact.factOne') might not look as a best way to use the enumeration feature in guided rules, but in some use cases it can be a valid use case. For an example take the following use case.
        If a rule developer has a 'List' and they want to find out if the list contains a specific value and he would like to use a dropdown to identify the specific value, in an effort to prevent the user of the rules to enter an invalid value/entry. e.g. to validate a list of 'loan' types (e.g. "housing", "automobile" , "personal" , "industrial") and developer needs to be able to check whether the 'loan' is of a predefined type. Instead of typing in the type of 'loan' , developer would restrict the options to what is visible in a drop down, based of an enumerator just like in above example project.

        1. Model_TestProject.zip
          17 kB
        2. repository1_TestProject.zip
          20 kB
        3. reproducer.zip
          1.81 MB

              manstis@redhat.com Michael Anstis
              rhn-support-mhussain Musharraf Hussain
              Jozef Marko Jozef Marko (Inactive)
              Jozef Marko Jozef Marko (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: