facing problem with List iteration in drools
GoodsShipment has the list of GoodsItems and GoodsItem has the list of Documents
my requirement is, need to check atleast one document is available or no.
iam tried this but failed
writen a class to checking purpose
public class CheckDocument {
public boolean flag = false;
public CheckPreviousDocument() {
}
public boolean getPreviousDocument(GoodsShipment goodsshipment) {
List<GoodsItem> list = goodsshipment.getGoodsItems();
Iterator<GoodsItem> itr = list.iterator();
while (itr.hasNext()) {
GovernmentAgencyGoodsItem document = itr.next();
if (document.getDocuments().size() > 0) {
flag = true;
break;
}
}
return flag;
}
}
rule "previousDocuments minimum 1"
when
$o: GoodsShipment()
%x: CheckPreviousDocuments(previousDocuments($o) == false)
then
insert(-------------)
end
can anyone please help me.. thanks in advance
Your code is somewhat unusual, but thus rule should do. Note that I have used
Document
as the type for the elements in the list returned byGovernmentAgencyGoodsItem.getDocuments()
.