[rules-users] Finding matching values in composite constraint

bdolbeare bdolbeare at yahoo.com
Sat Jan 5 13:29:14 EST 2013


Suppose we have a Transaction object with a String field.  Users want to
create a rule through our application that says alert me whenever the value
of that field contains a value in a list of values provided in the rule. 
It's easy enough to write this type of rule and send an alert; however, it
would be helpful to include the value from the list that matched.  

The only way I can think to do this type of thing is to create a function
somewhere that checks if the field contains any of the values in the user
list and if so return that value.  Then call that function in the rule
condition and bind the result.  Something like what follows:


public class ExternalMatcher
{
  public static String contains(String field, String...list)
  {
  // return the first string that satisfies the contains logic or null if no
strings succeed
  }
}

rule "test"
when 
Transaction( $matchedValue : ExternalMatcher.contains(field, "value1",
"value2", "value3") != null)
then
sendAlert("I found a transaction that matched your criteria because field
foo equals: " + $matchedValue);
end





--
View this message in context: http://drools.46999.n3.nabble.com/Finding-matching-values-in-composite-constraint-tp4021343p4021346.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list