Uploaded image for project: 'Kogito'
  1. Kogito
  2. KOGITO-2127

Add SingletonStore initialization in DTO

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Obsolete
    • Icon: Minor Minor
    • None
    • 0.10.1
    • Core Engine
    • None
    • 2
    • 2020 Week 19-21 (from May 4), 2020 Week 22-24 (from May 25), 2020 Week 25-27 (from Jun 15)

      When you declare RuleUnitData in DRL, DataStore can work without initialization because generated DTO has DataStore initialization (= DataSource.createStore()). But SingletonStore doesn't work because generated DTO doesn't have SingletonStore initialization (DataSource.createSingleton()).

      Hello.drl

      declare Hello extends RuleUnitData
        // result : SingletonStore<Result> = DataSource.createSingleton() // This works
        result : SingletonStore<Result> // This doesn't work
        messages : DataStore<String>
      end
      

      HelloDTO.java

          public Hello get() {
              Hello unit = new Hello();
              {
                  org.kie.kogito.rules.DataStore<java.lang.String> messages = org.kie.kogito.rules.DataSource.createStore();
                  unit.setMessages(messages);
                  this.messages.forEach(unit.getMessages()::add);
              }
              {
                  unit.getResultList().set(this.resultList);
              }
              return unit;
          }
      

      It fails with NPE when accessed REST endpoint.

      Caused by: java.lang.NullPointerException
      	at org.kie.kogito.examples.HelloDTO.get(HelloDTO.java:9)
      	at org.kie.kogito.examples.HelloQueryHelloEndpoint.executeQuery(HelloQueryHelloEndpoint.java:31)
      

      If you explicitly initialize in the DRL (SingletonStore<Result> = DataSource.createSingleton()), it works. So this issue is not serious. Just to align with DataStore behaviour.

      Note: however, overwriting in DTO may lose flexibility. See https://issues.redhat.com/browse/KOGITO-2029

              rhn-support-tkobayas Toshiya Kobayashi
              rhn-support-tkobayas Toshiya Kobayashi
              Marian Macik Marian Macik
              Marian Macik Marian Macik
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: