我正在尝试在Drools Expert中编写规则。在规则的when
部分中,我检查了Application
对象的一些属性。这个对象包含一个List,我想检查一堆规则是否适用于此列表中SomeOtherType的所有对象。仅当约束对该列表中的所有对象有效时,才应触发该规则。
rule "Application eligible"
when
app : Application(
some constrains
& write some constraints for all objects in app.getList() (a method
that returns a List<SomeOtherType> object)
)
then
// application is eligible
end
答案 0 :(得分:3)
如果你想要使用像Geoffry建议的那样将你的对象插入到工作记忆中,我还发现了另一种黑客方法:
rule "Person has all brothers"
when
$person : Person(siblings != null, siblings.size > 0)
List(size == siblings.size) from collect (Person(sex != null, sex == "m") from $person.siblings)
then
#Person has all brothers
end
答案 1 :(得分:2)
如果您还没有将所有SomeOtherType
实例插入工作内存中。
如果你想检查所有SomeOtherType的颜色是RED:
rule "Application eligible"
when
$app : Application()
forall( $x : SomeOtherType( application == $app )
SomeOtherType( this == $x, color == RED ) )
then
// application is eligible
end