如何在kie workbecnh / Drools 6.2中

时间:2015-10-29 10:49:07

标签: java drools kie kie-workbench

我可能在这里走错了路,所以如果是这样请纠正我。

我有一个名为action的成员的数据模型,它是枚举。所以看起来像这样:

合同类:

public class Contract {

    public Action action;

    public Action getAction() {
        return action;
    }

    public void setAction(Action action) {
        this.action = action;
    }
}

行动类:

public enum Action {

    CREATE, AMEND, RENEWAL

}

现在,问题是我无法在Kie Workbench中复制这个数据模型,因为它似乎不支持枚举?或者我可能不知道如何实施它们?

这反过来意味着当我通过Kie Execution Server获取规则时,因为我无法拥有操作类型的操作成员(这是一个枚举)以下规则永远不会被解雇:

rule "Contract rule"
when
    $c : Contract ( action.equals("CREATE") ) 
then
    System.out.println("This order action is: " + $c.getAction());
end

这里有解决方法吗?我错过了什么吗?

如果你想看到我在实现以下代码时得到的错误,那么它就是:

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

1 个答案:

答案 0 :(得分:1)

我不知道工作台如何允许或反驳枚举类的使用,但如果你用普通的DRL编写规则,则必须

rule "Contract rule"
when
    $c : Contract ( action == Action.CREATE ) 
then
    System.out.println("This order action is: " + $c.getAction());
end