Checking if an object of a list has some value with drools

只愿长相守 提交于 2019-12-12 12:37:59

问题


I have some problems checking if an object of a list has a value with drools.

My model is this

class Products{
    private List<Approver> approvalPath;
}
class Approver{
    private String employeeName;
}

So, I need to make a rule like this

rule "member"
    when
        //approvalPath has an approver with name "Charles" (for example)
    then
        //do something
end

How can I do it?


回答1:


Here are two versions.

when
  $app: Approver( employeeName == "Charles" )
  Products( approvalPath contains $pp )

And:

when
  Products( $ap: approvalPath )
  Approver( employeeName == "Charles" ) from $ap

Number 1 requires the insertion of Approver objects as facts.




回答2:


rule member
when
    $p : Products()
    $a : Approver( name == "Charles" ) from $p.approvalPath
then
...
end

The above rule will fire once for each Approver named Charles in the list. If you want to fire the rule just once, no matter how many approvers named Charles are in the list, just wrap the second line in exists( ... ).



来源:https://stackoverflow.com/questions/22257132/checking-if-an-object-of-a-list-has-some-value-with-drools

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!