1 Reply Latest reply on Aug 30, 2010 10:56 AM by Marco Baroetto

    Custom BusinessCalendar

    Marco Baroetto Newbie

      Hi there!

       

      I have:

      public class MyBusinessCalendar implements BusinessCalendar {
      
          public MyBusinessCalendar() {
              System.out.println("aaaaaaaa");
          }
      
          public Date add(final Date date, final String duration) {
              Date retDate = null;
              if ("dayOfTheDead".equals(duration)) {
                  final GregorianCalendar gregorianCalendar = new GregorianCalendar();
                  gregorianCalendar.set(Calendar.MONTH, Calendar.NOVEMBER);
                  gregorianCalendar.set(Calendar.DAY_OF_MONTH, 1);
                  retDate = gregorianCalendar.getTime();
              }
              return retDate;
          }
      
          public Date subtract(final Date date, final String duration) {
              // TODO Auto-generated method stub
              return null;
          }
      
      }
      

       

      and in my cfg:

       

      <process-engine-context>
           <object class="my.own.MyBusinessCalendar" />
      </process-engine-context>
      

       

      And in my jpdl:

       

      <task name="TaskTransaction2_step1"  duedate="#{dayOfTheDead} +3 days" candidate-groups="user">

       

      The deployment is ok, but when I try to execute  TaskTransaction2_step1 i get the following exception:

       

      javax.el.PropertyNotFoundException: Cannot resolve identifier 'dayOfTheDead'

       

      It all works if I write my task like this:

       

      <task name="TaskTransaction2_step1"  duedate="dayOfTheDead" candidate-groups="user">
      

       

      Any hint?

        • 1. Re: Custom BusinessCalendar
          Marco Baroetto Newbie

          I think the jBPM Develpers Guide is not correct in 2.1.2 Business Calendar:

           

           For example: 
          public class CustomBusinessCalendar implements BusinessCalendar {
            
            public Date add(Date date, String duration) {
              if ("my next birthday".equals(duration)) {
                GregorianCalendar gregorianCalendar = new GregorianCalendar();
                gregorianCalendar.set(Calendar.MONTH, Calendar.JULY);
                gregorianCalendar.set(Calendar.DAY_OF_MONTH, 21);
                return gregorianCalendar.getTime();
              }
              return null;
            }
          }     
          To configure the jBPM engine to use this custom business calendar, just add      the following line to your jbpm.cfg.xml: 
          <process-engine-context>
              <object  class="org.jbpm.test.custombusinesscalendarimpl.CustomBusinessCalendar"
          />
          </process-engine-context>  
          
          Take a look at the       
          org.jbpm.test.custombusinesscalendarimpl.CustomBusinessCalendarImplTest for more information. 
          

           

           

          1) org.jbpm.test.custombusinesscalendarimpl.CustomBusinessCalendarImplTest doesn't exist

           

          2) To add your EL expression in timers (at least for task's duedate) you have to:

           

          - Write my.own.MyNextBirthday extends Date (or Calendar,GregorianCalendar...) and is equals to the date you want.

          - Add to your cfg the following:

           

          <object name="myNextBirthday" class="my.own.MyNextBirthday" />

           

          3) Write your jpdl as follows:

           

          <task name="TaskTransaction2_step1"  duedate="#{myNextBirthday} +3 days" candidate-groups="user">