[jboss-user] [jBPM] - Re: Issue with timer and calendar

saig0 do-not-reply at jboss.com
Thu Jun 21 11:17:37 EDT 2012


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&containerType=14&container=2034]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120621/9dea75d4/attachment-0001.html 


More information about the jboss-user mailing list