Drools:规则形成 - 一个规则输出应触发其他规则

时间:2018-02-06 13:22:16

标签: jboss drools

我对Drools相当新,并且让我了解它。 场景:

规则A输出 - >应该触发规则b,规则c并发送然后获得最终输出等

示例:简化

CountryBean --> { String isdCode ,List<String> tates} 

rule "Get States by Country's ISD Code"
no-loop true
  when country: Country(isCode=="+1")
then 
  country.setStates("Kentucky" , "North Carolina"....);
  update(country);

StateBean --> {String state,String population}
rule "Get Population of States"
no-loop true
  when state: States(state !="", $state=state)
then 
  if(state=="Kentucky")
  state.population("1M");
  update(state)

我的解决方案

  1. 执行第一条规则
  2. 然后迭代状态并执行状态规则

    Country country = new Country("+1");
      ksession.insert(country )
      ksession.fireAllRules();
    List<States> stateList=new ArrayList<States>();
    country.getStates().forEach(state-> {
        ksession.insert(new State(state)); 
        ksession.fireAllRules();stateList.add(state);
    });
    
  3. 我不认为这是正确的做法。我该如何处理这个问题?

0 个答案:

没有答案
相关问题