在Drools LHS中使用绑定变量时出错

时间:2017-04-27 11:38:26

标签: drools drools-guvnor drools-planner

我有简单的规则,我想使用返回整数值的外部java函数。我想在规则LHS中使用此返回值进行比较。

rule "testRuleBTW"
 when
    $cfd        : FactsData()
    condition   : RuleData( ageCondition != null, 
                                    ageCondition.value1 != null, 
                                    ageCondition.value2 != null, 
                                    "BTW" == ageCondition.conditionCode, 
                                    $returnValue : Utils.foo($cfd.dateOfBirth, ageCondition.ageUnitCode) //Want to use this value in next c
                                    ageCondition.value1 <= $returnValue, $returnValue <= ageCondition.value2)
then
//do something

但低于错误

java.lang.RuntimeException:创建KieBase时出错[Message [id = 1,level = ERROR,path = com / test / rules / ageRule.drl,line = 13,column = 0    text = [ERR 101]第13:42行在规则“testRuleBTW”的输入'$ cfd'中没有可行的选择,消息[id = 2,level = ERROR,path = com / test / rules / ageRule.drll,line = 0,列= 0    text = Parser返回null包]]     在org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:433)     在org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:587)     在org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:558)     在org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)     在org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)     在org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989)     at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4913)     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5223)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)     在org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)     在org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)     在org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)     在org.apache.catalina.startup.HostConfig $ DeployWar.run(HostConfig.java:1823)     at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471)     在java.util.concurrent.FutureTask.run(FutureTask.java:262)     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)     在java.lang.Thread.run(Thread.java:745)

2 个答案:

答案 0 :(得分:1)

您无法将变量绑定到任意表达式。

再向前迈出一小步,实施

class Util {

    public static boolean fooInRange( dob Date, uc, UnitCode, ac AgeCondition ){
        if( ac.value1 == null ||
            ac.value2 == null ) return false;
        Value value = foo( dob, uc );
        return ac.value <= value && value <= ac.value2;
    }

     // ...
}

并在你的规则中使用它。

答案 1 :(得分:0)

经过大量的谷歌搜索,我设法如下所示。

es_ES
es_ES@euro
es_ES.iso88591
es_ES.iso885915@euro
es_ES.utf8