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

API gap: KieBase.getGlobalType(String identifier) which returns the class of the global field

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 7.6.0.Final
    • core engine
    • None
    • NEW
    • NEW

      This is needed to avoid try-catching kieSession.setGlobal(...) in for example optaplanner.

      This code

              kieSession.setGlobal("scoreHolder", workingScoreHolder);
      

      throws

      Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Illegal class for global. Expected [org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScoreHolder], found [org.optaplanner.core.api.score.buildin.hardsoftlong.HardSoftLongScoreHolder].
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.setGlobal(StatefulKnowledgeSessionImpl.java:1189)
      	at org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector.resetKieSession(DroolsScoreDirector.java:79)
      	at org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector.setWorkingSolution(DroolsScoreDirector.java:69)
      

      because the user didn't align his global field ScoreHolder type with his domain classes score type.

      Instead they should get

      IllegalStateException: your global field ScoreHolder type (...) does not align with your domain classes score type (...).
      

      To do this, we need to have KieBase.getGlobalType("scoreHolder") return HardSoftScoreHolder.class, so I can check it's not equal HardSoftLongScoreHolder.class, during bootstrap, instead of try-catching every setGlobal() call.

      Furthermore, I believe this should be added in the public api - it is clearly an api gap. But I can work with adding this in the internal api too.

            mfusco@redhat.com Mario Fusco
            gdesmet@redhat.com Geoffrey De Smet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: