Menu

Problem with getting FReeBusy information

Help
2005-04-19
2013-06-05
  • Stanislav Davidov

    Hi!

    I need to get a list of FreeBusy components for specified calendar and period. I set up the calendar and requesting FreeBusy for it. But got some strange result. I attached my source code and the result.

    If I understood right, I should get the list of FreeBusy.

    Am I do something wrong? Could someone help me with this issue.

    Thank you!

    public class FreeBusyTest extends TestCase
    {
        private VEvent makeBuzyEvent (String summary, Date fromTime, Date toTime, RRule rRule, Transp transp) {
            VEvent event = new VEvent();
            event.getProperties().add(new DtStart(fromTime));
            event.getProperties().add(new DtEnd(toTime));
            event.getProperties().add(transp);
            event.getProperties().add(rRule);
            event.getProperties().add(new Uid("MyUID_" + System.currentTimeMillis()));
            event.getProperties().add(new Summary(summary));
            event.getProperties().add(new DtStamp(new Date()));
            return event;
        }

        public void testFreeBusy() throws ParseException, IOException, URISyntaxException
        {
            java.util.Calendar calendar = java.util.Calendar.getInstance();

            calendar.setTime(new Date());
            calendar.add(java.util.Calendar.YEAR, -1);  // year ago
            calendar.set(java.util.Calendar.HOUR_OF_DAY, 0);
            calendar.set(java.util.Calendar.MINUTE, 0);
            calendar.set(java.util.Calendar.SECOND, 0);

            Date dayStart = calendar.getTime();
            calendar.set(java.util.Calendar.HOUR_OF_DAY, 10);
            Date workDayStart = calendar.getTime();
            calendar.set(java.util.Calendar.HOUR_OF_DAY, 14);
            Date lunchStart = calendar.getTime();
            calendar.set(java.util.Calendar.HOUR_OF_DAY, 15);
            Date lunchEnd = calendar.getTime();
            calendar.set(java.util.Calendar.HOUR_OF_DAY, 19);
            Date workDayEnd = calendar.getTime();
            calendar.set(java.util.Calendar.HOUR_OF_DAY, 23);
            calendar.set(java.util.Calendar.MINUTE, 59);
            calendar.set(java.util.Calendar.SECOND, 59);
            Date dayEnd = calendar.getTime();

            Recur recur = new Recur(Recur.WEEKLY, null);
            recur.setInterval(1);
            recur.setFrequency(Recur.WEEKLY);
            recur.getDayList().add(WeekDay.MO);
            recur.getDayList().add(WeekDay.TU);
            recur.getDayList().add(WeekDay.WE);
            recur.getDayList().add(WeekDay.TH);
            recur.getDayList().add(WeekDay.FR);
            recur.setWeekStartDay(WeekDay.SU.toString());
            RRule rRule = new RRule(recur);

            Calendar libraryCalendar = new Calendar();
            libraryCalendar.getProperties().add(Version.VERSION_2_0);
            libraryCalendar.getProperties().add(new ProdId ("-//Dynix Corp//Horizon 8//EN"));
            libraryCalendar.getProperties().add(Method.PUBLISH);
            libraryCalendar.getComponents().add(makeBuzyEvent("00-10", dayStart, workDayStart, rRule, Transp.OPAQUE));
            libraryCalendar.getComponents().add(makeBuzyEvent("14-15", lunchStart, lunchEnd, rRule, Transp.OPAQUE));
            libraryCalendar.getComponents().add(makeBuzyEvent("19-23", workDayEnd, dayEnd, rRule, Transp.OPAQUE));

            System.out.println(libraryCalendar);

            calendar.setTime(new Date());
            calendar.add(java.util.Calendar.DAY_OF_YEAR, -10);
            Date startDate = calendar.getTime();
            calendar.setTime(new Date());
            calendar.add(java.util.Calendar.DAY_OF_YEAR, 10);
            Date endDate = calendar.getTime();

            VFreeBusy request = new VFreeBusy(startDate, endDate, 3600 * 1000);

            VFreeBusy reply = new VFreeBusy(request, libraryCalendar.getComponents());

            Calendar myCalendar = new Calendar();
            myCalendar.getComponents().add(reply);

            System.out.println(myCalendar);
        }

    }

    ======== [System.out] =========
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//Dynix Corp//Horizon 8//EN
    METHOD:PUBLISH
    BEGIN:VEVENT
    DTSTART:20040419T000000
    DTEND:20040419T100000
    TRANSP:OPAQUE
    RRULE:FREQ=WEEKLY;WKST=SU;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
    UID:MyUID_1113921325559
    SUMMARY:00-10
    DTSTAMP:20050419T143525Z
    END:VEVENT
    BEGIN:VEVENT
    DTSTART:20040419T140000
    DTEND:20040419T150000
    TRANSP:OPAQUE
    RRULE:FREQ=WEEKLY;WKST=SU;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
    UID:MyUID_1113921325559
    SUMMARY:14-15
    DTSTAMP:20050419T143525Z
    END:VEVENT
    BEGIN:VEVENT
    DTSTART:20040419T190000
    DTEND:20040419T235959
    TRANSP:OPAQUE
    RRULE:FREQ=WEEKLY;WKST=SU;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
    UID:MyUID_1113921325559
    SUMMARY:19-23
    DTSTAMP:20050419T143525Z
    END:VEVENT
    END:VCALENDAR

    BEGIN:VCALENDAR
    BEGIN:VFREEBUSY
    DTSTART:20050409T143525Z
    DTEND:20050429T143525Z
    DTSTAMP:20050419T143525Z
    DURATION:PT1H
    END:VFREEBUSY
    END:VCALENDAR

     
    • Brad Rust

      Brad Rust - 2005-04-20

      Hello.

      I am working with Stanislav on this issue.  Based on the code above, there is an addition to DtStart and DtEnd (in his makeBuzyEvent) properties to include the Value.DATE_TIME.

      While debugging the code, if you have an RRule event, you call rrule.getRecur().getDates(null,....)   Inside of that method, it returns near the top of the method with a comment (// this should never happen).  But, based on the method signature, it will always happen.

      Should the recurrence rules section of createPeriodList be calling the other getDates method of rrule.getRecur()?

      We would be happy to contribute back to this project.  I am not jumping in too quickly since I probably don't understand all the use-cases involved.

      Brad

       
      • Ben Fortuna

        Ben Fortuna - 2005-04-20

        Brad,

        This method was added recently in patch #1170060, and I think what Dustin is getting at is that you shouldn't be calling that method if you don't have a valid DTSTART property to pass into it (there is a similar method without a DTSTART parameter you should be calling instead).

        I think I will eventually merge the functionality of these two methods, but for now don't call this method by passing null as the DTSTART parameter.

        regards,
        ben

         
      • Ben Fortuna

        Ben Fortuna - 2005-04-20

        Oops, now I see what you mean. It had seemed ok when I applied the patch but now I can't see how it works.

        Anyway, my suggestion is that we combine the two getDates() methods and pass in java.util.Dates for all parameters (i.e. no DtStart property), so this signature will most likely change in the next release anyway.

        In the meantime however, it does seem that we should be calling the other method in VFreeBusy.createPeriodList().

        b.

         
    • Ben Fortuna

      Ben Fortuna - 2005-04-20

      Hi Stanislav,

      You will only get a FreeBusy property in your VFreeBusy reply component if some free time was identified.

      The problem I see here is that all of your events are set to a year ago (2004) whereas your VFreeBusy request is set to this year (2005). So no free time will be identified.

      regards,
      ben

       

Log in to post a comment.