流口水 如何在何时或条件下获取规则上下文



>我需要在我的自定义函数中获取规则名称,在那里我用它来进行一些处理,下面的代码是我尝试的方式。 如果这不能直接实现,是否有替代方案.顺便说一句,目前我们正在使用流口水 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 

规则左侧没有规则上下文,即在条件评估期间。

如果你真的需要左侧的规则名称(无论如何都不会有用(,你必须编写包含规则名称作为参数的字符串文字。

我建议审查一下提出这一要求的原因。

请注意,printRuleName(kcontext) == "true"永远不会为真,因为它将布尔值与字符串进行比较。此外,比较true == "true"没有任何意义。

最新更新