If you need to reason over the contents of the list, I would probably write
a generic rule that will insert each element from a list into Working Memory
rule "Assert List Contents"
when
$list : List(size > 0)
$obj : Object() from $list
then
insert($obj);
end
Then write the other rules specific to the items in the list
rule "Validate ONFI final action - code 666"
when
RuleFlag(value == "Validate ONFI final action")
a: PackageMovementInfo(actionCode == "666")
b: ONFIAssignmentInfo(reviewType == "ES", subId == a.subId)
ONFIReviewerInfo(notId == b.notId, revStatus == "CLO", reviewerRole ==
"PR")
then
result.addMessage(a, "You can't do action code 666..." );
end
On Mon, Dec 14, 2009 at 9:21 AM, Warren, David [USA]
<warren_david(a)bah.com>wrote:
I am trying to write a rule whose consequence loads several lists
into the
session. Each list contains a different type of class. What I would like
to do (need to do as far as I can tell) is loop through the list and insert
each element individually, rather than inserting the list as a whole. Is
ther a way to do this in DRL?
Here is my example rule:
rule "Do we need to validate ONFI final action"
when
a : PackageMovementInfo( finalActionInd == "*", packageId == "AA")
b : SubmissionsInfoForRules(subId == a.subId, amendment == false,
onfiAssignmentId != null)
then
insert( new RuleFlag("Validate ONFI final action") );
insert( onfiService.getONFIAssignment(b.getSubId()) );
insert( onfiService.getONFIReviewers(b.getOnfiAssignmentId()) );
insert( onfiService.getONFIAttachments(b.getOnfiAssignmentId()) );
end
The last two insert statements insert lists. A problem occurs in
subsequent rules if I try to evaluate the contents of the lists. I've been
getting a ClassCastException when lists are present for both the reviewers
and attachments, because they are not the same class. Here is an example
rule that causes a ClassCastException:
rule "Validate ONFI final action - code 666"
when
RuleFlag(value == "Validate ONFI final action")
a: PackageMovementInfo(actionCode == "666")
b: ONFIAssignmentInfo(reviewType == "ES", subId == a.subId)
$list : List( size > 0 )
ONFIReviewerInfo(notId == b.notId, revStatus == "CLO", reviewerRole ==
"PR") from $list
then
result.addMessage(a, "You can't do action code 666..." );
end
What I need to do is either (1) load each element of the lists
individually, or (2) rewrite "$list : List (size > 0)" to only pick up
lists
of a particular class.
Is there a way to do either of these things from DRL? Or do I need to
handle the loading outside of my rules (in the Java class that calls the
rules).
Thank you,
David Warren
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users