Changeset 366

Show
Ignore:
Timestamp:
04/12/06 12:03:31
Author:
douglm
Message:

More free/busy changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/appcommon/src/org/bedework/appcommon/TimeView.java

    r314 r366  
    107107   */ 
    108108  private TimeViewDailyInfo[] tvdis; 
    109    
     109 
    110110  //private static final TimezoneCache tzcache = new TimezoneCache(false); 
    111111 
     
    162162    return cal.getTimezones(); 
    163163  } 
    164    
     164 
    165165  /** 
    166166   * @return CalSvcI 
     
    278278   */ 
    279279  public Collection getDaysEvents(MyCalendarVO date) throws Throwable { 
    280     ArrayList al = new ArrayList(); 
    281280    CalTimezones tzcache = cal.getTimezones(); 
    282 //    Dur oneDay = new Dur(1, 0, 0, 0); 
    283     long millis = System.currentTimeMillis(); 
    284      
    285     //tzcache.setSysTimezones(cal.getTimezones()); 
    286     BwDateTime startDt = CalFacadeUtil.getDateTime(date.getDateDigits(), 
    287                                                    tzcache); 
    288  
    289     BwDateTime endDt = startDt.getNextDay(tzcache); 
    290     String start = startDt.getDate(); 
    291     String end = endDt.getDate(); 
    292      
    293     if (debug) { 
    294       debugMsg("Did UTC stuff in " + (System.currentTimeMillis() - millis)); 
    295     } 
    296  
    297281    //if (debug) { 
    298282    //  debugMsg("Get days events in range " + start + " to " + end); 
     
    307291    } 
    308292 
     293    ArrayList al = new ArrayList(); 
     294//  Dur oneDay = new Dur(1, 0, 0, 0); 
     295    long millis = System.currentTimeMillis(); 
     296 
     297    //tzcache.setSysTimezones(cal.getTimezones()); 
     298    BwDateTime startDt = CalFacadeUtil.getDateTime(date.getDateDigits(), 
     299                                                   tzcache); 
     300 
     301    BwDateTime endDt = startDt.getNextDay(tzcache); 
     302    String start = startDt.getDate(); 
     303    String end = endDt.getDate(); 
     304 
     305    if (debug) { 
     306      debugMsg("Did UTC stuff in " + (System.currentTimeMillis() - millis)); 
     307    } 
     308 
    309309    Iterator it = events.iterator(); 
    310310    while (it.hasNext()) { 
     
    319319         2.    ((evStart >= :start) and (evStart < :end)) or 
    320320         3.    ((evEnd > :start) and (evEnd <= :end))) 
    321           
     321 
    322322         XXX followed caldav which might be wrong. Try 
    323323         3.    ((evEnd > :start) and (evEnd < :end))) 
     
    440440      gtpi.multi = !gtpi.last.isSameDate(gtpi.first); 
    441441      gtpi.currentDay = new MyCalendarVO(gtpi.first.getTime(), 
    442                                               calInfo.getLocale()); 
     442                                         calInfo.getLocale()); 
    443443      gtpi.year = String.valueOf(gtpi.currentDay.getYear()); 
    444444 
    445445      Locale loc = Locale.getDefault(); // XXX Locale 
    446446      gtpi.todaysMonth = new MyCalendarVO(   // XXX Expensive?? 
    447                                           new Date(System.currentTimeMillis()),  
     447                                          new Date(System.currentTimeMillis()), 
    448448                                          loc).getTwoDigitMonth(); 
    449449 
     
    451451        debugMsg("getFirstDayOfWeek() = " + getFirstDayOfWeek()); 
    452452        debugMsg("gtpi.first.getFirstDayOfWeek() = " + 
    453                             calInfo.getFirstDayOfWeek()); 
     453                 calInfo.getFirstDayOfWeek()); 
    454454      } 
    455455 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/BwDateTime.java

    r172 r366  
    9797   * complications to dates, the end date is specified as non-inclusive 
    9898   * but there are a number of boundary problems to watch out for. 
    99    *  
     99   * 
    100100   * <p>For date only values this field has a zero time appended so that simple 
    101101   * string comparisons will work. 
     
    206206  } 
    207207 
     208  public BwDateTime copy(CalTimezones timezones) throws CalFacadeException { 
     209    return makeDateTime(makeDtEnd(), timezones); 
     210  } 
     211 
    208212  /** Make a DtStart from this object 
    209213   * 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/BwFreeBusy.java

    r2 r366  
    5555 
    5656import java.io.Serializable; 
     57import java.util.ArrayList; 
    5758import java.util.Collection; 
    5859import java.util.Iterator; 
    59 import java.util.Vector; 
    6060 
    6161/** Class representing free busy time. Used in icalendar objects 
     
    7474  /** Collection of FreeBusyComponentVO 
    7575   */ 
    76   private Vector times; 
     76  private Collection times; 
    7777 
    7878  /** Constructor 
     
    139139  /** Get the free busy times 
    140140   * 
    141    * @return Collection    of FreeBusyComponentVO 
     141   * @return Collection    of BwFreeBusyComponent 
    142142   */ 
    143143  public Collection getTimes() { 
    144144    if (times == null) { 
    145       times = new Vector(); 
     145      times = new ArrayList(); 
    146146    } 
    147147    return times; 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/CalFacadeUtil.java

    r273 r366  
    5555 
    5656import org.bedework.calfacade.ifs.CalTimezones; 
     57import org.bedework.calfacade.svc.EventInfo; 
    5758 
    5859import net.fortuna.ical4j.model.Parameter; 
     
    607608    return tzid; 
    608609  } 
     610 
     611  /** This class defines the events and the period of interest and can be passed 
     612   * repeatedly to getPeriodsEvents. 
     613   * 
     614   * <p>The end datetime will be updated ready for the next call. If endDt is 
     615   * non-null on entry it will be used to set the startDt. 
     616   */ 
     617  public static class GetPeriodsPars { 
     618    /** Event Info objects to extract from */ 
     619    public Collection events; 
     620    /* Start of period - updated at each call from endDt */ 
     621    public BwDateTime startDt; 
     622    /** Duration of period */ 
     623    public BwDuration dur; 
     624    /** */ 
     625    public CalTimezones tzcache; 
     626 
     627    /** On return has the end date of the period. */ 
     628    public BwDateTime endDt; 
     629  } 
     630 
     631  /** Select the events in the collection which fall within the period 
     632   * defined by the start and duration. 
     633   * 
     634   * @param   pars      GetPeriodsPars object 
     635   * @return  Collection of EventInfo being one days events or empty for no events. 
     636   * @throws Throwable 
     637   */ 
     638  public static Collection getPeriodsEvents(GetPeriodsPars pars) throws CalFacadeException { 
     639    ArrayList al = new ArrayList(); 
     640    //long millis = System.currentTimeMillis(); 
     641 
     642    if (pars.endDt != null) { 
     643      pars.startDt = pars.endDt.copy(pars.tzcache); 
     644    } 
     645    pars.endDt = pars.startDt.addDuration(pars.dur, pars.tzcache); 
     646    String start = pars.startDt.getDate(); 
     647    String end = pars.endDt.getDate(); 
     648 
     649    //if (debug) { 
     650    //  debugMsg("Did UTC stuff in " + (System.currentTimeMillis() - millis)); 
     651    //} 
     652 
     653    Iterator it = pars.events.iterator(); 
     654    while (it.hasNext()) { 
     655      EventInfo ei = (EventInfo)it.next(); 
     656      BwEvent ev = ei.getEvent(); 
     657 
     658      String evStart = ev.getDtstart().getDate(); 
     659      String evEnd = ev.getDtend().getDate(); 
     660 
     661      /* Event is within range if: 
     662         1.   (((evStart <= :start) and (evEnd > :start)) or 
     663         2.    ((evStart >= :start) and (evStart < :end)) or 
     664         3.    ((evEnd > :start) and (evEnd <= :end))) 
     665 
     666         XXX followed caldav which might be wrong. Try 
     667         3.    ((evEnd > :start) and (evEnd < :end))) 
     668      */ 
     669 
     670      int evstSt = evStart.compareTo(start); 
     671      int evendSt = evEnd.compareTo(start); 
     672 
     673      //debugMsg("                   event " + evStart + " to " + evEnd); 
     674 
     675      if (((evstSt <= 0) && (evendSt > 0)) || 
     676          ((evstSt >= 0) && (evStart.compareTo(end) < 0)) || 
     677          //((evendSt > 0) && (evEnd.compareTo(end) <= 0))) { 
     678          ((evendSt > 0) && (evEnd.compareTo(end) < 0))) { 
     679        // Passed the tests. 
     680        /* 
     681        if (debug) { 
     682          debugMsg("Event passed range " + start + "-" + end + 
     683                   " with dates " + evStart + "-" + evEnd + 
     684                   ": " + ev.getSummary()); 
     685        }*/ 
     686        al.add(ei); 
     687      } 
     688    } 
     689 
     690    return al; 
     691  } 
    609692} 
    610693 
  • trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/calquery/FreeBusyQuery.java

    r310 r366  
    147147      try { 
    148148        BwFreeBusy fb = svci.getFreeBusy(null, new BwUser(user), 
    149                                          tr.getStart(), tr.getEnd()); 
     149                                         tr.getStart(), tr.getEnd(), null); 
    150150 
    151151        if (debug) { 
  • trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java

    r365 r366  
    5656 
    5757import org.bedework.calenv.CalEnv; 
     58import org.bedework.calfacade.CalFacadeUtil.GetPeriodsPars; 
    5859import org.bedework.calfacade.base.BwOwnedDbentity; 
    5960import org.bedework.calfacade.base.BwShareableDbentity; 
     
    6263import org.bedework.calfacade.BwCategory; 
    6364import org.bedework.calfacade.BwDateTime; 
     65import org.bedework.calfacade.BwDuration; 
    6466import org.bedework.calfacade.BwEvent; 
    6567import org.bedework.calfacade.BwEventAlarm; 
     
    10121014 
    10131015  public BwFreeBusy getFreeBusy(BwCalendar cal, BwPrincipal who, 
    1014                                 BwDateTime start, BwDateTime end) 
     1016                                BwDateTime start, BwDateTime end, 
     1017                                BwDuration granularity) 
    10151018          throws CalFacadeException { 
    10161019    if (!(who instanceof BwUser)) { 
     
    10311034      subs = new ArrayList(); 
    10321035      subs.add(sub); 
    1033     } else if (!currentUser().equals(who)) { 
     1036    } else if (currentUser().equals(who)) { 
    10341037      subs = getSubscriptions(); 
    10351038    } else { 
     
    10381041 
    10391042    BwFreeBusy fb = new BwFreeBusy(who, start, end); 
     1043    Collection events = new TreeSet(); 
    10401044 
    10411045    Iterator subit = subs.iterator(); 
     
    10501054                                 CalFacadeDefs.retrieveRecurExpanded); 
    10511055 
    1052       try { 
    1053         /* For the moment just build a single FreeBusyComponentVO 
     1056      // Filter out transparent events 
     1057      Iterator it = evs.iterator(); 
     1058 
     1059      while (it.hasNext()) { 
     1060        EventInfo ei = (EventInfo)it.next(); 
     1061        BwEvent ev = ei.getEvent(); 
     1062 
     1063        // XXX Need to add sub.ignoreTransparency 
     1064        if (BwEvent.transparencyTransparent.equals(ev.getTransparency())) { 
     1065          continue; 
     1066        } 
     1067 
     1068        events.add(ei); 
     1069      } 
     1070    } 
     1071 
     1072    try { 
     1073      if (granularity != null) { 
     1074        // chunked. 
     1075        GetPeriodsPars gpp = new GetPeriodsPars(); 
     1076 
     1077        gpp.events = events; 
     1078        gpp.startDt = start; 
     1079        gpp.dur = granularity; 
     1080        gpp.tzcache = getTimezones(); 
     1081 
     1082        /* For the moment just build a single BwFreeBusyComponent 
    10541083         */ 
    10551084        BwFreeBusyComponent fbc = new BwFreeBusyComponent(); 
    10561085 
    1057         Iterator it = evs.iterator(); 
    1058  
    1059         TreeSet eventPeriods = new TreeSet(); 
    1060  
    1061         while (it.hasNext()) { 
    1062           EventInfo ei = (EventInfo)it.next(); 
    1063           BwEvent ev = ei.getEvent(); 
    1064  
    1065           // XXX Need to add sub.ignoreTransparency 
    1066           if (BwEvent.transparencyTransparent.equals(ev.getTransparency())) { 
    1067             continue; 
     1086        int limit = 10000; // XXX do this better 
     1087        while (gpp.startDt.before(end)) { 
     1088          if (debug) { 
     1089            trace("gpp.startDt=" + gpp.startDt + " end=" + end); 
    10681090          } 
    1069  
    1070           // Ignore if times were specified and this event is outside the times 
    1071  
    1072           BwDateTime estart = ev.getDtstart(); 
    1073           BwDateTime eend = ev.getDtend(); 
    1074  
    1075           /* Don't report out of the requested period */ 
    1076  
    1077           String dstart; 
    1078           String dend; 
    1079  
    1080           if (estart.before(start)) { 
    1081             dstart = start.getDtval(); 
    1082           } else { 
    1083             dstart = estart.getDtval(); 
     1091          if (limit < 0) { 
     1092            throw new CalFacadeException("org.bedework.svci.limit.exceeded"); 
    10841093          } 
    1085  
    1086           if (eend.after(end)) { 
    1087             dend = end.getDtval(); 
    1088           } else { 
    1089             dend = eend.getDtval(); 
     1094          limit--; 
     1095 
     1096          Collection periodEvents = CalFacadeUtil.getPeriodsEvents(gpp); 
     1097 
     1098          if (periodEvents.size() != 0) { 
     1099            // Some events fall in the period. Add an entry. 
     1100 
     1101            fbc.addPeriod(new Period(new DateTime(gpp.startDt.getDtval()), 
     1102                                     new DateTime(gpp.endDt.getDtval()))); 
    10901103          } 
    1091  
    1092           eventPeriods.add(new EventPeriod(new DateTime(dstart), 
    1093               new DateTime(dend))); 
    10941104        } 
    1095  
    1096         /* iterate through the sorted periods combining them where they are 
    1097          adjacent or overlap */ 
    1098  
    1099         Period p = null; 
    1100  
    1101         it = eventPeriods.iterator(); 
    1102         while (it.hasNext()) { 
    1103           EventPeriod ep = (EventPeriod)it.next(); 
    1104  
    1105           if (p == null) { 
    1106             p = new Period(ep.start, ep.end); 
    1107           } else if (ep.start.after(p.getEnd())) { 
    1108             // Non adjacent periods 
    1109             fbc.addPeriod(p); 
    1110             p = new Period(ep.start, ep.end); 
    1111           } else if (ep.end.after(p.getEnd())) { 
    1112             // Extend the current period 
    1113             p = new Period(p.getStart(), ep.end); 
    1114           } // else it falls within the existing period 
     1105        fb.addTime(fbc); 
     1106 
     1107        return fb; 
     1108      } 
     1109 
     1110      /* For the moment just build a single BwFreeBusyComponent 
     1111       */ 
     1112      BwFreeBusyComponent fbc = new BwFreeBusyComponent(); 
     1113 
     1114      Iterator it = events.iterator(); 
     1115 
     1116      TreeSet eventPeriods = new TreeSet(); 
     1117 
     1118      while (it.hasNext()) { 
     1119        EventInfo ei = (EventInfo)it.next(); 
     1120        BwEvent ev = ei.getEvent(); 
     1121 
     1122        // Ignore if times were specified and this event is outside the times 
     1123 
     1124        BwDateTime estart = ev.getDtstart(); 
     1125        BwDateTime eend = ev.getDtend(); 
     1126 
     1127        /* Don't report out of the requested period */ 
     1128 
     1129        String dstart; 
     1130        String dend; 
     1131 
     1132        if (estart.before(start)) { 
     1133          dstart = start.getDtval(); 
     1134        } else { 
     1135          dstart = estart.getDtval(); 
    11151136        } 
    11161137 
    1117         if (p != null) { 
     1138        if (eend.after(end)) { 
     1139          dend = end.getDtval(); 
     1140        } else { 
     1141          dend = eend.getDtval(); 
     1142        } 
     1143 
     1144        eventPeriods.add(new EventPeriod(new DateTime(dstart), 
     1145                                         new DateTime(dend))); 
     1146      } 
     1147 
     1148      /* iterate through the sorted periods combining them where they are 
     1149       adjacent or overlap */ 
     1150 
     1151      Period p = null; 
     1152 
     1153      it = eventPeriods.iterator(); 
     1154      while (it.hasNext()) { 
     1155        EventPeriod ep = (EventPeriod)it.next(); 
     1156 
     1157        if (p == null) { 
     1158          p = new Period(ep.start, ep.end); 
     1159        } else if (ep.start.after(p.getEnd())) { 
     1160          // Non adjacent periods 
    11181161          fbc.addPeriod(p); 
    1119         } 
    1120  
    1121         fb.addTime(fbc); 
    1122       } catch (Throwable t) { 
    1123         throw new CalFacadeException(t); 
    1124       } 
     1162          p = new Period(ep.start, ep.end); 
     1163        } else if (ep.end.after(p.getEnd())) { 
     1164          // Extend the current period 
     1165          p = new Period(p.getStart(), ep.end); 
     1166        } // else it falls within the existing period 
     1167      } 
     1168 
     1169      if (p != null) { 
     1170        fbc.addPeriod(p); 
     1171      } 
     1172 
     1173      fb.addTime(fbc); 
     1174    } catch (Throwable t) { 
     1175      throw new CalFacadeException(t); 
    11251176    } 
    11261177 
  • trunk/calendar3/calsvci/src/org/bedework/calsvci/CalSvcI.java

    r356 r366  
    5959import org.bedework.calfacade.BwCategory; 
    6060import org.bedework.calfacade.BwDateTime; 
     61import org.bedework.calfacade.BwDuration; 
    6162import org.bedework.calfacade.BwEvent; 
    6263import org.bedework.calfacade.BwEventAlarm; 
     
    796797   * ==================================================================== */ 
    797798 
    798   /** Get the free busy for the given principal. 
     799  /** Get the free busy for the given principal. A granularity of null results 
     800   * in a list of busy periods. Otherwise the start to end time is divided up 
     801   * into granularity sized chunks which will only be reported if one or more 
     802   * events fall in the segment. 
    799803   * 
    800804   * @param cal    Calendar to provide free-busy for. Null for default 
     
    803807   * @param start 
    804808   * @param end 
     809   * @param granularity BwDuration object defining how to divide free/busy 
     810   *                    null for one big glob. or set to e.g. 1 hour for 
     811   *                    hourly chunks. 
    805812   * @return BwFreeBusy 
    806813   * @throws CalFacadeException 
    807814   */ 
    808815  public abstract BwFreeBusy getFreeBusy(BwCalendar cal, BwPrincipal who, 
    809                                          BwDateTime start, BwDateTime end) 
     816                                         BwDateTime start, BwDateTime end, 
     817                                         BwDuration granularity) 
    810818          throws CalFacadeException; 
    811819 
  • trunk/calendar3/webclient/src/org/bedework/webclient/BwFreeBusyAction.java

    r365 r366  
    5757//import org.bedework.calfacade.BwDateTime; 
    5858import org.bedework.appcommon.MyCalendarVO; 
     59import org.bedework.calfacade.BwDuration; 
    5960import org.bedework.calfacade.BwFreeBusy; 
    60 import org.bedework.calfacade.BwFreeBusyComponent; 
    6161import org.bedework.calfacade.BwUser; 
    6262import org.bedework.calfacade.CalFacadeUtil; 
     
    6464import org.bedework.calsvci.CalSvcI; 
    6565 
    66  
    67  
    6866import java.util.Calendar; 
    6967import java.util.Date; 
    70 import java.util.Iterator; 
    7168import javax.servlet.http.HttpServletRequest; 
    7269 
     
    128125    } 
    129126 
    130     int intunit = Calendar.HOUR; 
    131127    String intunitStr = getReqPar(request, "intunit"); 
     128    BwDuration dur = new BwDuration(); 
    132129 
    133130    if (intunitStr != null) { 
    134131      if ("minutes".equals(intunitStr)) { 
    135         intunit = Calendar.MINUTE
     132        dur.setMinutes(interval)
    136133      } else if ("hours".equals(intunitStr)) { 
    137         intunit = Calendar.HOUR
     134        dur.setHours(interval)
    138135      } else if ("days".equals(intunitStr)) { 
    139         intunit = Calendar.DAY_OF_MONTH
     136        dur.setDays(interval)
    140137      } else if ("weeks".equals(intunitStr)) { 
    141         intunit = Calendar.WEEK_OF_YEAR; 
    142       } else if ("months".equals(intunitStr)) { 
    143         intunit = Calendar.MONTH; 
     138        dur.setWeeks(interval); 
    144139      } else { 
    145140        form.getErr().emit("org.bedework.client.error.badintervalunit"); 
    146141        return "error"; 
    147142      } 
     143    } else { 
     144      dur.setHours(interval); 
    148145    } 
    149146 
     
    151148    CalTimezones tzs = svci.getTimezones(); 
    152149 
    153     BwFreeBusy fb = null; 
    154     while (start.before(end)) { 
    155       Date sdt = start.getTime(); 
    156       start.add(intunit, interval); 
     150    Date sdt = start.getTime(); 
     151    Date edt = end.getTime(); 
    157152 
    158       if (debug) { 
    159         debugMsg("getFreeBusy for start =  " + sdt + 
    160                  " end = " + start.getTime()); 
    161       } 
    162       BwFreeBusy fb1 = svci.getFreeBusy(null, user, 
    163                           CalFacadeUtil.getDateTime(sdt, false, true, tzs), 
    164                           CalFacadeUtil.getDateTime(start.getTime(), false, true, 
    165                                                     tzs)); 
    166  
    167       if (fb == null) { 
    168         fb = fb1; 
    169       } else { 
    170         Iterator it = fb1.iterateTimes(); 
    171         while (it.hasNext()) { 
    172           BwFreeBusyComponent fbc = (BwFreeBusyComponent)it.next(); 
    173  
    174           if (!fbc.getEmpty()) { 
    175             fb.addTime(fbc); 
    176           } 
    177         } 
    178       } 
     153    if (debug) { 
     154      debugMsg("getFreeBusy for start =  " + sdt + 
     155               " end = " + edt); 
    179156    } 
    180  
    181     fb.setEnd(CalFacadeUtil.getDateTime(end.getTime(), false, false, tzs)); 
     157    BwFreeBusy fb = svci.getFreeBusy(null, user, 
     158                                     CalFacadeUtil.getDateTime(sdt, false, false, tzs), 
     159                                     CalFacadeUtil.getDateTime(edt, false, false, tzs), 
     160                                     dur); 
    182161 
    183162    form.assignFreeBusy(fb);