I might be on the wrong track here so please correct me if so.
I have a data model with a member called action
which is an enum. So looks like this:
Contract class:
public class Contract {
public Action action;
public Action getAction() {
return action;
}
public void setAction(Action action) {
this.action = action;
}
}
Action class:
public enum Action {
CREATE, AMEND, RENEWAL
}
Now, the problem is that I can not replicate this data model in Kie Workbench as it seems not to support enums? Or maybe I do not know how to implement them?
Which in turn means that when I fetch the rules via the Kie Execution Server, because I can not have an action member of type Action (which is an enum) the following rule will never get fired:
rule "Contract rule"
when
$c : Contract ( action.equals("CREATE") )
then
System.out.println("This order action is: " + $c.getAction());
end
Is there a workaround here? Am I missing something?
If you wanna see the error that I get when I implement the following code, here it is:
java.lang.NoSuchMethodError: com.heg.projectdelta.contractcreator.model.Contract.getAction()Lcom/heg/projectdelta/contractcreator/model/Action;
at com.heg.projectdelta.contractcreator.model.Rule_Contract_rule116883127.defaultConsequence(Rule_Contract_rule116883127.java:7)
at com.heg.projectdelta.contractcreator.model.Rule_Contract_rule116883127DefaultConsequenceInvokerGenerated.evaluate(Unknown Source)
at com.heg.projectdelta.contractcreator.model.Rule_Contract_rule116883127DefaultConsequenceInvoker.evaluate(Unknown Source)
at org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1114)
at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:160)
at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:108)
at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1016)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1302)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1289)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1262)
at com.heg.projectdelta.cedroolscore.service.DroolsService.fireAllRules(DroolsService.java:115)
at com.heg.projectdelta.contractcreator.service.impl.DroolsWebServiceImpl.fireRules(DroolsWebServiceImpl.java:66)
at com.heg.projectdelta.contractcreator.integration.DroolsWebServiceTest.testFireRules(DroolsWebServiceTest.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Ta
I don't know how the workbench would permit or refute the use of enum classes, but if you were to write the rule in plain DRL, it would have to be
rule "Contract rule" when $c : Contract ( action == Action.CREATE ) then System.out.println("This order action is: " + $c.getAction()); end