0
votes

I am trying to write a drools rule that check if two events happens from the same stream. I have a compliance rules class which contains logic (in the working memory) to be compared with events coming from entry point. all I need is to detect the occurrence of two events, for example I want to detect that event A occurred and after that B occurred. I wrote this role in drools syntax

$comrule : Comprules ( pattern == "response" , isBefore == false)  
Event  (task == $comrule.antecedent) from entry-point StoreOne  
Event (task == $comrule.consequent) from entry-point StoreOne

the problem is this technique doesn't work. the only one working is when I wrote this

Event  (task == $comrule.antecedent) from entry-point StoreOne  
not Event (task == $comrule.consequent) from entry-point StoreOne

I read the drools documentation but I couldn't find any solve to this problem any help will be appreciated

1
It's impossible to tell why you don't get the expected result. You need to provide a complete example. -- Did you insert two Event facts with the proper values for task and were they in Working Memory at the same time? If the second version of the patterns fires you have inserted the first one but not yet the second one. - laune
this is the input I inserted insertEvent(entryPointStoreOne, new Event(), "X","8"); insertEvent(entryPointStoreOne, new Event(), "Y","9"); Comprules cr4 = new Comprules(); cr4.setpattern("response"); cr4.setantecedent("X"); cr4.setconsequent("Y"); cr4.setanttimestamp(3); cr4.setconsimesptamp(4); cr4.settimespan(2); - Marwa Galal

1 Answers

0
votes

The typical pattern for checking that two Events occur in the right order is this:

Comprules( pattern == "response", !isBefore, $a: antecedent, $b: consequent )
$one: Event( task == $a ) from entry-point StoreOne  
$two: Event( task == $b, this after $one ) from entry-point StoreOne

Using not tests for the absence of a fact, which would be the situation after $one has arrived while $two still is absent.