我需要在我的自定义函数中获取规则名称,并在其中使用它进行一些处理,下面的代码是我想要做的。如果这不能直接实现,是否有替代方案。顺便说一句,目前我们正在使用 Drools 5.6
import org.drools.spi.KnowledgeHelper;
function boolean printRuleName(KnowledgeHelper context ) {
System.out.println(context.getRule().getName());
return true;
}
// rule values at C15, header at C10
rule "MY_RULE_15"
salience 65521
when
k:StatefulKnowledgeSession(true == "true")
//context: KnowledgeHelper(true=="true")
m:Map(true == "true")
Map((printRuleName(kcontext) == "true")
then
System.out.println(kcontext.getRule().getName());
//this works in action
end
//Map((printRuleName(kcontext) == "true") this is causing null pointer exception, kcontext is not getting injected