[rules-users] Complex pattern

rcano rcano at netlabs.com.uy
Tue May 8 18:10:52 EDT 2012


Hi there,

I've been struggling for almost a day now, trying to create a pattern that goes something as follows (notice it doesn't compile):

rule "Complex pattern"
when
  $triviaResponse : TriviaResponseArrived($matchers: matchers)
  $subscriptions : ArrayList() from collect (
    $s: Subscription()
    $lock: Lock(object == $s)
    exists SubscriptionMatcher(matches($s)) from $matchers
  )
then
  logger.info("NO TRANSACTION", "Selected subscriptions " + $subscriptions);
end

where TriviaResponseArrived, contains a List of SubscriptionMatchers (a simple object which just returns true or false when its matches method is called).
Upon receiving this TriviaResponseArrived fact, I'm trying to select all subscriptions from the working memory, for which there is also a Lock, and that there exists a matcher within the matchers
list that validates it. To sum up, all subscriptions in the list subscription, should be locked, and matched by a matcher in the triviaResponseArrived fact.

The closes I've managed to come is: 

rule "Complex pattern"
when
  $triviaResponse : TriviaResponseArrived($matchers: matchers)
  $subscription : Subscription()
  $lock: Lock(object == $subscription)
  exists SubscriptionMatcher(matches($subscription)) from $matchers
then
  logger.info("NO TRANSACTION", "Subscription " + $subscription);
end

Which is not quite right, since I need to process all the subscription that match the above logic at once.

As always, all help is really appreciated. Thanks.

Cheers.


More information about the rules-users mailing list