我有一个通过 Guvnor 控制台创建的 drools 规则,如果满足条件,该规则会验证并将一个事实插入到工作内存中。规则是:
1. | rule "EligibilityCheck001"
2. | dialect "mvel"
3. | when
4. | Eligibility( XXX== "XXX" , YYY== "YYY" , ZZZ== "ZZZ" , BBB == "BBB" )
5. | then
6. | EligibilityInquiry fact0 = new EligibilityInquiry();
7. | fact0.setServiceName( "ABCD" );
8. | fact0.setMemberStatus( true );
9. | insert(fact0 );
10. | System.out.println( "Hello from Drools");
11. | end
执行规则的Java代码如下
RuleAgent ruleAgent = RuleAgent.newRuleAgent("/Guvnor.properties");
RuleBase ruleBase = ruleAgent.getRuleBase();
FactType factType = ruleBase.getFactType("mortgages.Eligibility");
Object obj = factType.newInstance();
factType.set(obj, "XXX", "XXX");
factType.set(obj, "YYY", "YYY");
factType.set(obj, "ZZZ", "XXX");
factType.set(obj, "BBB", "BBB");
WorkingMemory workingMemory = ruleBase.newStatefulSession();
workingMemory.insert(obj);
workingMemory.fireAllRules();
System.out.println("After drools execution");
long count = workingMemory.getFactCount();
System.out.println("count " + count);
一切看起来都很棒,输出如下:
Hello from Drools
After drools execution
count 2
我似乎无法找到一种方法来让EligibilityInquiry
我的 Java 代码中的事实对象返回并获取上面规则中设置的属性(serviceName
和status
)。我已经使用了这种StatefulSession
方法。
属性文件具有通过用户名和密码进行基本身份验证的快照链接。总共有 2 个事实:EligibilityInquiry
和Eligibility
。
我对流口水还很陌生,对上述任何帮助表示赞赏。