Hi everyone,
I'm relatively new at rule development and I'm having a problem tryin' to
implement one in particular.
I need to capture some events that they've got the same AttributeA and got
more than 9 AttributeB Objects (excluding one type in particular) in one or
more events.
*Model:*
Class Event {
Long id;
AttributeA attributeA;
List<AttributeB> listAttributeB;
Date timestamp;
Long duration;
}
Class AttributeA {
Long id;
double doubleValue;
String name;
}
Class AttributeB {
Long id;
String name;
String someString;
Boolean flag;
}
class AttributeBMock {
//it doesn't have any of "one_type_of_attB"
public List<AttributeB> getTenAttributeB() {
return Arrays.asList(new AttributeB(000001L, 23.4, "random_string_1"),
new AttributeB(000006L, 38.9, "random_string_2"),
new AttributeB(000005L, 35.2, "random_string_3"),
new AttributeB(000003L, 32.5, "random_string_4"),
new AttributeB(000006L, 32.5, "random_string_5"),
new AttributeB(000007L, 23.4, "random_string_6"),
new AttributeB(0000012L, 23.4, "random_string_7"),
new AttributeB(000015L, 44.4, "random_string_8"),
new AttributeB(000010L, 87.0, "random_string_9"),
new AttributeB(000010L, 87.0, "random_string_10"));
}
}
-----------------------------------------------------------------------------------
*Test:*
public void someMethod() {
SessionPseudoClock clock = (SessionPseudoClock) ruleEngine.getClock();
clock.advanceTime(10, TimeUnit.SECONDS);
//Just with this insertion i get the ArrayOutOfBounds exception
ruleEngine.addEvent(new Purchase(123456L,new AttributeA(),
AttributeBMock.getTenAttributeB(),new Date(clock.getCurrentTime(),0L));
Assert.assertTrue("The rule hasn't been fired", Assert.assertFalse("The
rule
hasn't been fired",
ruleEngine.getEventListener().getExecutedRulesNames().containsAll(EXPECTED_RULES_NAMES));
}
-------------------------------------------------------------------------------------------------------
*Rule:*
when
$event: event($attributeA : attributeA, attributeA.flag == true,
$listAttributeB : listAttributeB) from entry-point "some_entry_point"
$quantity: List() from collect($attributeB : attributeB(name !=
'one_type_of_attB') from $listAttributeB)
Number(doubleValue > 9)
from accumulate(event(attributeA == $attributeA) from entry-point
"some_entry_point",
sum($quantity.size))
then
System.out.println("Event: " + $event.id );
end
-----------------------------------------------------------------
Everytime when I fire an event that triggers the rule, the accumulate method
throws an "ArrayOutOfBounds" exception. I don't know why, the logic looks
good to me.
Can I get some help, please?
Thx. in advance
Regards
--
View this message in context:
http://drools.46999.n3.nabble.com/Rule-triggering-problem-with-Drools-tp4...
Sent from the Drools: User forum mailing list archive at
Nabble.com.