我需要根据来自后端的数据启用/禁用 drl 文件中的某些规则。即为迪拜启用规则 1,2,3,为新加坡启用 1,3 所以,我通过 drools.getRule().getName() 如下。
rule "Apply 50% discount to VIP customers"
enabled (checkenabled(drools.getRule().getName()))
when
$s : Sale( customer.type == CustomerType.VIP )
then
$s.setDiscount(0.50);
System.out.println("VIP discount applied1" + drools.getRule().getName());
end
我在这方面遇到了错误。
Exception in thread "main" [Error: null pointer: drools.rule.name]
[Near : {... checkenabled(drools.rule.name) ....}]
^
[Line: 1, Column: 14]
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:427)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:140)
at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
at org.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:948)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:373)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:140)
at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:86)
at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
at org.mvel2.MVEL.executeExpression(MVEL.java:930)
at org.drools.core.base.mvel.MVELEnabledExpression.getValue(MVELEnabledExpression.java:92)
at org.drools.core.definitions.rule.impl.RuleImpl.isEffective(RuleImpl.java:384)
at org.drools.core.phreak.RuleExecutor.cancelAndContinue(RuleExecutor.java:326)
at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:142)
at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:94)
at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:964)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1234)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1239)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1212)
at com.emirates.App.testGoodCustomer(App.java:95)
at com.emirates.App.main(App.java:74)
Caused by: java.lang.NullPointerException
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:393)
... 25 more