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

Allow binding of a complex expression using multiple facts

    XMLWordPrintable

Details

    • Feature Request
    • Resolution: Unresolved
    • Major
    • None
    • None
    • None
    • None
    • undefined
    • NEW
    • NEW

    Description

      At the moment it's not possible to use variables coming from a different fact inside bindings, as in the following example

          @Test
          public void testVariableInsideBinding() {
              String str =
                      "import " + Person.class.getCanonicalName() + ";" +
                              "import " + NameLengthCount.class.getCanonicalName() + ";" +
                              "rule X when\n" +
                              "  $nlc : NameLengthCount() \n" +
                              "  Person ( $nameLength : $nlc.getNameLength(name))" +
                              "then\n" +
                              "end";
      
              Results results = createKieBuilder(str ).getResults();
              assertThat(results.getMessages(Message.Level.ERROR).stream().map(Message::getText))
                      .contains("Variables can not be used inside bindings. Variable [$nlc] is being used in binding '$nlc.getNameLength(name)'");
          }
      
          public static class NameLengthCount {
              public int getNameLength(String name) {
                  return name.length();
              }
          }
      

      That's because the variable binding is implemented with an InternalReadAccessor that takes only an object and not a whole tuple as input. It is required to refactor the InternalReadAccessor to work with a tuple (or to get rid of and workaround it if necessary) in order to allow this use case.

      Attachments

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              mfusco@redhat.com Mario Fusco
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: