0

我正在尝试执行用 Kie 工作台编写并与 Kie 执行服务器集成的规则,并得到预期的响应。但我的要求是只为定义的大规则列表执行一个特定规则。我可以实现哪些可能的方法。我使用了激活组,规则流组但没有运气如果有人可以帮助我实现这一点。

我在 KIE Workbench 中创建了引导决策表。并以这种方式生成源

    package demo.drools_examples;
    //from row number: 1
    rule "Row 1 Rule1"
    dialect "mvel"
    when
        f1 : Account( accountType == "Regular" )
    then
        f1.setBaseAmount( 10.0 );
        f1.setBaseThreshold( 10.0 );
        calculateAmount(f1);
        calculateThreshold(f1);
    end
    //from row number: 2
    rule "Row 2 Rule1"
    dialect "mvel"
    when
        f1 : Account( accountType == "Registered" )
    then
        f1.setBaseAmount( 5.0 );
        f1.setBaseThreshold( 15.0 );
        calculateAmount(f1);
        calculateThreshold(f1);
   end
   //from row number: 3
   rule "Row 3 Rule1"
   dialect "mvel"
   when
        f1 : Account( accountType == "Saving" )
    then
        f1.setBaseAmount( 20.0 );
        f1.setBaseThreshold( 10.0 );
        calculateAmount(f1);
        calculateThreshold(f1);
   end

如何定义 saliance 、 Activation 组或任何其他策略以仅调用规则 1 而不是调用 fireallRules(1) .. 请帮助我

4

1 回答 1

0

You'll have to call fireAllRules, but with a twist:

AgendaFilter af = new SingleRuleFilter( "Row 1 Rule1" );
int nFired = kieSession.fireAllRules( af );

And you only need to write something like this:

public class SingleRuleFilter implements AgendaFilter {
    private String name;
    public SingleRuleFilter( String name ){
         this.name = name;
    }
    public boolean accept( Activation activation ){
         return activation.getRule().getName().equals( name );
    }
}
于 2015-05-08T14:48:03.290 回答