使用Java生成Drools Drl文件 [英] Generate drools drl file by using java

查看:157
本文介绍了使用Java生成Drools Drl文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照方法以编程方式使用Java创建drools drl文件.

我可以通过Java程序的简单规则创建以下简单规则.

 规则"Demo_testing";什么时候$ employee:EmployeeModel(部门包含帐户")然后// 

这对我来说很好,但是我需要从列表中获取员工信息.喜欢 $ employee:EmployeeModel(部门包含$ employeeList中的"Accounts",角色="manager")

我发现在drools编译器

最后,谢谢您的建议,我使用

此代码生成如下规则

 规则"Demo_testing";什么时候$ employee:EmployeeModel(部门包含$ employeeList中的"Accounts")然后System.out.println(执行规则"); 

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.

rule "Demo_testing"
when
    $employee : EmployeeModel( department contains "Accounts" )
then
//

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.

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);

解决方案

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.

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);

This code generate the rule as follow

rule "Demo_testing"
when
    $employee : EmployeeModel( department contains "Accounts" ) from $employeeList
then
System.out.println("Rule executed");

这篇关于使用Java生成Drools Drl文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆