Geoffrey De Smet created DROOLS-2440:
----------------------------------------
Summary: API gap: KieBase.getGlobalType(String identifier) which returns the
class of the global field
Key: DROOLS-2440
URL:
https://issues.jboss.org/browse/DROOLS-2440
Project: Drools
Issue Type: Enhancement
Components: core engine
Affects Versions: 7.6.0.Final
Reporter: Geoffrey De Smet
Assignee: Mario Fusco
This is needed to avoid try-catching kieSession.setGlobal(...) in for example
optaplanner.
This code
{code}
kieSession.setGlobal("scoreHolder", workingScoreHolder);
{code}
throws
{code}
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)
{code}
because the user didn't align his global field ScoreHolder type with his domain
classes score type.
Instead they should get
{code}
IllegalStateException: your global field ScoreHolder type (...) does not align with your
domain classes score type (...).
{code}
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.
--
This message was sent by Atlassian JIRA
(v7.5.0#75005)