使用Java生成Drools Drl文件 [英] Generate drools drl file by using java
问题描述
我正在尝试按照方法以编程方式使用Java创建drools drl文件.
我可以通过Java程序的简单规则创建以下简单规则.
规则"Demo_testing";什么时候$ employee:EmployeeModel(部门包含帐户")然后//
这对我来说很好,但是我需要从列表中获取员工信息.喜欢 $ employee:EmployeeModel(部门包含$ employeeList中的"Accounts",角色="manager")
我发现在drools编译器 最后,谢谢您的建议,我使用 此代码生成如下规则 I m trying to create the drools drl file using java programmatically by following method. I can able to create the below simple rules by simple rule by java program. And this in one working fine for me, but i need get the employee information from list. Like
$employee : EmployeeModel( department contains "Accounts", role = "manager" ) from $employeeList I found the list on descriptor available in drools compiler here
But i don't know which descriptor i needs to use and how to define.? Please any one help me to relove this one. Thanks in advance.
Hi thanks for your suggestions finally i done by using FromDescr. As per my requirement i can genrate Rule drl file by using below java code. This code generate the rule as follow
这篇关于使用Java生成Drools Drl文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
规则"Demo_testing";什么时候$ employee:EmployeeModel(部门包含$ employeeList中的"Accounts")然后System.out.println(执行规则");
rule "Demo_testing"
when
$employee : EmployeeModel( department contains "Accounts" )
then
//
PatternDescr employeePatternDescr=new PatternDescr();
employeePatternDescr.setIdentifier("$employee");
employeePatternDescr.setObjectType("EmployeeModel");
RelationalExprDescr relationalExprDescr = null;
constraintDescr.setExpression("department");
ExprConstraintDescr constraintDescr2=new ExprConstraintDescr();
constraintDescr2.setExpression("Accounts" );
relationalExprDescr = new RelationalExprDescr("contains" ,false, null, constraintDescr, constraintDescr2);
employeePatternDescr.addConstraint(relationalExprDescr);
andDescr.addDescr(employeePatternDescr);
ruleDescr.setLhs(andDescr);
PatternDescr employeePatternDescr=new PatternDescr();
employeePatternDescr.setIdentifier("$employee");
employeePatternDescr.setObjectType("EmployeeModel");
**FromDescr fromDescr = new FromDescr();
fromDescr.setDataSource( new MVELExprDescr( "$employeeList") );
employeePatternDescr.setSource(fromDescr);**
RelationalExprDescr relationalExprDescr = null;
constraintDescr.setExpression("department");
ExprConstraintDescr constraintDescr2=new ExprConstraintDescr();
constraintDescr2.setExpression("Accounts" );
relationalExprDescr = new RelationalExprDescr("contains" ,false, null,
constraintDescr, constraintDescr2);
employeePatternDescr.addConstraint(relationalExprDescr);
andDescr.addDescr(employeePatternDescr);
ruleDescr.setLhs(andDescr);
rule "Demo_testing"
when
$employee : EmployeeModel( department contains "Accounts" ) from $employeeList
then
System.out.println("Rule executed");