saig0 [
https://community.jboss.org/people/saig0] created the discussion
"Re: Issue with timer and calendar"
To view the discussion, visit:
https://community.jboss.org/message/743428#743428
--------------------------------------------------------------
Hi Srikant,
I copied your rule and wrote a test:
@Test
public void testCalenderRule() throws InterruptedException
{
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("drools/"
+ "expert.drl"), ResourceType.DRL);
KnowledgeBaseConfiguration config = KnowledgeBaseFactory
.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
KnowledgeSessionConfiguration conf = KnowledgeBaseFactory
.newKnowledgeSessionConfiguration();
ksession = kbase.newStatefulKnowledgeSession(conf, null);
ksession.getCalendars().set("weekDayCalendar", new
Calendar() {
public boolean isTimeIncluded(long timestamp) {
Date date = new Date(timestamp);
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
int dayOfWeek =
cal.get(GregorianCalendar.DAY_OF_WEEK);
if (dayOfWeek != GregorianCalendar.SATURDAY
&& dayOfWeek !=
GregorianCalendar.SUNDAY) {
return true;
} else {
return false;
}
}
});
ksession.getCalendars().set("holidayCalendar", new
Calendar() {
public boolean isTimeIncluded(long timestamp) {
Date date = new Date(timestamp);
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
int dayOfWeek =
cal.get(GregorianCalendar.DAY_OF_WEEK);
if (dayOfWeek == GregorianCalendar.SATURDAY
|| dayOfWeek ==
GregorianCalendar.SUNDAY) {
return true;
} else {
return false;
}
}
});
ksession.insert(new Alarm());
ksession.fireAllRules();
}
Only the "week days rule" is getting executed as excepted. For me it works
fine.
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/743428#743428]
Start a new discussion in jBPM at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]