Changeset 119

Show
Ignore:
Timestamp:
02/08/06 10:00:04
Author:
douglm
Message:

Small changes to free/busy code.

Added new factory method to BwSubscription? and used it in a few places.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Events.java

    r99 r119  
    855855    sess.createQuery(sb.toString()); 
    856856 
     857    /* XXX Limit result set size - pagination allows something like: 
     858       query.setFirstResult(0); 
     859       query.setMaxResults(10); 
     860       */ 
     861 
    857862    if (startDate != null) { 
    858863      sess.setString("fromDate", startDate.getDate()); 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/BwEvent.java

    r2 r119  
    226226  private BwOrganizer organizer; 
    227227 
     228  /** */ 
     229  public final static String transparencyOpaque = "OPAQUE"; 
     230  /** */ 
     231  public final static String transparencyTransparent = "TRANSPARENT"; 
    228232  /** Transparency is used in free/busy time calculation 
     233   *      transp     = "TRANSP" tranparam ":" transvalue CRLF 
     234 
     235     tranparam  = *(";" xparam) 
     236 
     237     transvalue = "OPAQUE"      ;Blocks or opaque on busy time searches. 
     238                / "TRANSPARENT" ;Transparent on busy time searches. 
     239        ;Default value is OPAQUE 
    229240   */ 
    230241  private String transparency; 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/svc/BwSubscription.java

    r54 r119  
    267267   * ==================================================================== */ 
    268268 
     269  /** Make a subscription to the calendar object defaulting most fields 
     270   * 
     271   * @param  val            BwCalendar the calendar to subscribe to 
     272   * @return BwSubscription a new subscription object 
     273   */ 
     274  public static BwSubscription makeSubscription(BwCalendar val) { 
     275    BwSubscription sub = new BwSubscription(); 
     276 
     277    sub.setName(val.getName()); 
     278    sub.setUri(CalFacadeDefs.bwUriPrefix + val.getPath()); 
     279    sub.setDisplay(true); 
     280    sub.setAffectsFreeBusy(true); 
     281    sub.setInternalSubscription(true); 
     282    sub.setCalendar(val); 
     283    sub.setInternalSubscription(true); 
     284    sub.setEmailNotifications(false); 
     285 
     286    return sub; 
     287  } 
     288 
    269289  /** Make a subscription to the calendar object 
    270290   * 
  • trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/CaldavCalNode.java

    r2 r119  
    133133      } 
    134134 
    135       BwSubscription sub = new BwSubscription(); 
    136       sub.setName(cal.getName()); 
    137       sub.setDisplay(true); 
    138       sub.setInternalSubscription(true); 
    139       sub.setCalendar(cal); 
     135      BwSubscription sub = BwSubscription.makeSubscription(cal); 
    140136 
    141137      Collection events = svci.getEvents(sub, CalFacadeDefs.retrieveRecurExpanded); 
  • trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/calquery/FreeBusyQuery.java

    r2 r119  
    146146 
    147147      try { 
    148         BwFreeBusy fb = svci.getFreeBusy(new BwUser(user), 
     148        BwFreeBusy fb = svci.getFreeBusy(null, new BwUser(user), 
    149149                                         tr.getStart(), tr.getEnd()); 
    150150 
  • trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/filter/Filter.java

    r2 r119  
    5454 
    5555package edu.rpi.cct.uwcal.caldav.filter; 
    56 import org.bedework.calfacade.BwCalendar; 
    5756import org.bedework.calfacade.svc.BwSubscription; 
    5857import org.bedework.calsvci.CalSvcI; 
     
    322321 
    323322    try { 
    324       BwSubscription sub = new BwSubscription(); 
    325       BwCalendar cal = wdnode.getCDURI().getCal(); 
    326       sub.setName(cal.getName()); 
    327       sub.setDisplay(true); 
    328       sub.setInternalSubscription(true); 
    329       sub.setCalendar(cal); 
     323      BwSubscription sub = BwSubscription.makeSubscription(wdnode.getCDURI().getCal()); 
    330324 
    331325      if (eventq.trange == null) { 
  • trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java

    r111 r119  
    959959   * ==================================================================== */ 
    960960 
    961   public BwFreeBusy getFreeBusy(BwPrincipal who, BwDateTime start, BwDateTime end) 
     961  public BwFreeBusy getFreeBusy(BwCalendar cal, BwPrincipal who, 
     962                                BwDateTime start, BwDateTime end) 
    962963          throws CalFacadeException { 
    963964    if (!(who instanceof BwUser)) { 
     
    970971    } 
    971972 
     973    BwUser u = (BwUser)who; 
     974    Collection subs; 
     975 
     976    if (cal != null) { 
     977      BwSubscription sub = BwSubscription.makeSubscription(cal); 
     978 
     979      subs = new Vector(); 
     980      subs.add(sub); 
     981    } else if (!currentUser().equals(who)) { 
     982      subs = getSubscriptions(); 
     983    } else { 
     984      subs = dbi.fetchPreferences(u).getSubscriptions(); 
     985    } 
     986 
    972987    BwFreeBusy fb = new BwFreeBusy(who, start, end); 
    973988 
    974     Collection evs = getEvents(null, null, start, end, CalFacadeDefs.retrieveRecurExpanded); 
    975  
    976     try { 
    977       /* For the moment just build a single FreeBusyComponentVO 
    978        */ 
    979       BwFreeBusyComponent fbc = new BwFreeBusyComponent(); 
    980  
    981       Iterator it = evs.iterator(); 
    982  
    983       TreeSet eventPeriods = new TreeSet(); 
    984  
    985       while (it.hasNext()) { 
    986         EventInfo ei = (EventInfo)it.next(); 
    987         BwEvent ev = ei.getEvent(); 
    988  
    989         // Ignore if times were specified and this event is outside the times 
    990  
    991         BwDateTime estart = ev.getDtstart(); 
    992         BwDateTime eend = ev.getDtend(); 
    993  
    994         /* Don't report out of the requested period */ 
    995  
    996         String dstart; 
    997         String dend; 
    998  
    999         if (estart.before(start)) { 
    1000           dstart = start.getDtval(); 
    1001         } else { 
    1002           dstart = estart.getDtval(); 
     989    Iterator subit = subs.iterator(); 
     990    while (subit.hasNext()) { 
     991      BwSubscription sub = (BwSubscription)subit.next(); 
     992 
     993      if (!sub.getAffectsFreeBusy()) { 
     994        continue; 
     995      } 
     996 
     997      Collection evs = getEvents(sub, null, start, end, CalFacadeDefs.retrieveRecurExpanded); 
     998 
     999      try { 
     1000        /* For the moment just build a single FreeBusyComponentVO 
     1001         */ 
     1002        BwFreeBusyComponent fbc = new BwFreeBusyComponent(); 
     1003 
     1004        Iterator it = evs.iterator(); 
     1005 
     1006        TreeSet eventPeriods = new TreeSet(); 
     1007 
     1008        while (it.hasNext()) { 
     1009          EventInfo ei = (EventInfo)it.next(); 
     1010          BwEvent ev = ei.getEvent(); 
     1011 
     1012          // XXX Need to add sub.ignoreTransparency 
     1013          if (BwEvent.transparencyTransparent.equals(ev.getTransparency())) { 
     1014            continue; 
     1015          } 
     1016 
     1017          // Ignore if times were specified and this event is outside the times 
     1018 
     1019          BwDateTime estart = ev.getDtstart(); 
     1020          BwDateTime eend = ev.getDtend(); 
     1021 
     1022          /* Don't report out of the requested period */ 
     1023 
     1024          String dstart; 
     1025          String dend; 
     1026 
     1027          if (estart.before(start)) { 
     1028            dstart = start.getDtval(); 
     1029          } else { 
     1030            dstart = estart.getDtval(); 
     1031          } 
     1032 
     1033          if (eend.after(end)) { 
     1034            dend = end.getDtval(); 
     1035          } else { 
     1036            dend = eend.getDtval(); 
     1037          } 
     1038 
     1039          eventPeriods.add(new EventPeriod(new DateTime(dstart), 
     1040              new DateTime(dend))); 
    10031041        } 
    10041042 
    1005         if (eend.after(end)) { 
    1006           dend = end.getDtval(); 
    1007         } else { 
    1008           dend = eend.getDtval(); 
     1043        /* iterate through the sorted periods combining them where they are 
     1044         adjacent or overlap */ 
     1045 
     1046        Period p = null; 
     1047 
     1048        it = eventPeriods.iterator(); 
     1049        while (it.hasNext()) { 
     1050          EventPeriod ep = (EventPeriod)it.next(); 
     1051 
     1052          if (p == null) { 
     1053            p = new Period(ep.start, ep.end); 
     1054          } else if (ep.start.after(p.getEnd())) { 
     1055            // Non adjacent periods 
     1056            fbc.addPeriod(p); 
     1057            p = new Period(ep.start, ep.end); 
     1058          } else if (ep.end.after(p.getEnd())) { 
     1059            // Extend the current period 
     1060            p = new Period(p.getStart(), ep.end); 
     1061          } // else it falls within the existing period 
    10091062        } 
    10101063 
    1011         eventPeriods.add(new EventPeriod(new DateTime(dstart), 
    1012                                          new DateTime(dend))); 
    1013       } 
    1014  
    1015       /* iterate through the sorted periods combining them where they are 
    1016          adjacent or overlap */ 
    1017  
    1018       Period p = null; 
    1019  
    1020       it = eventPeriods.iterator(); 
    1021       while (it.hasNext()) { 
    1022         EventPeriod ep = (EventPeriod)it.next(); 
    1023  
    1024         if (p == null) { 
    1025           p = new Period(ep.start, ep.end); 
    1026         } else if (ep.start.after(p.getEnd())) { 
    1027           // Non adjacent periods 
     1064        if (p != null) { 
    10281065          fbc.addPeriod(p); 
    1029           p = new Period(ep.start, ep.end); 
    1030         } else if (ep.end.after(p.getEnd())) { 
    1031           // Extend the current period 
    1032           p = new Period(p.getStart(), ep.end); 
    1033         } // else it falls within the existing period 
    1034       } 
    1035  
    1036       if (p != null) { 
    1037         fbc.addPeriod(p); 
    1038       } 
    1039  
    1040       fb.addTime(fbc); 
    1041     } catch (Throwable t) { 
    1042       throw new CalFacadeException(t); 
     1066        } 
     1067 
     1068        fb.addTime(fbc); 
     1069      } catch (Throwable t) { 
     1070        throw new CalFacadeException(t); 
     1071      } 
    10431072    } 
    10441073 
  • trunk/calendar3/calsvci/src/org/bedework/calsvci/CalSvcI.java

    r111 r119  
    756756  /** Get the free busy for the given principal. 
    757757   * 
     758   * @param cal    Calendar to provide free-busy for. Null for default 
     759   *               collection (as specified by user). 
    758760   * @param who 
    759761   * @param start 
     
    762764   * @throws CalFacadeException 
    763765   */ 
    764   public abstract BwFreeBusy getFreeBusy(BwPrincipal who, BwDateTime start
    765                                          BwDateTime end) 
     766  public abstract BwFreeBusy getFreeBusy(BwCalendar cal, BwPrincipal who
     767                                         BwDateTime start, BwDateTime end) 
    766768          throws CalFacadeException; 
    767769 
  • trunk/calendar3/webclient/src/org/bedework/webclient/BwFreeBusyAction.java

    r55 r119  
    164164                 " end = " + start.getTime()); 
    165165      } 
    166       BwFreeBusy fb1 = svci.getFreeBusy(user, 
     166      BwFreeBusy fb1 = svci.getFreeBusy(null, user, 
    167167                          CalFacadeUtil.getDateTime(sdt, false, true, 
    168168                                                    svci.getTimezones()), 
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/misc/ExportAction.java

    r85 r119  
    126126        } 
    127127 
    128         sub = new BwSubscription(); 
    129         sub.setName(cal.getName()); 
    130         sub.setDisplay(true); 
    131         sub.setInternalSubscription(true); 
    132         sub.setCalendar(cal); 
     128        sub = BwSubscription.makeSubscription(cal); 
    133129      } else if (subid >= 0) { 
    134130        sub = svci.getSubscription(subid); 
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/misc/SetSelectionAction.java

    r111 r119  
    117117      } 
    118118 
    119       BwSubscription sub = new BwSubscription(); 
    120       sub.setName(url); 
    121       sub.setDisplay(true); 
    122       sub.setInternalSubscription(true); 
    123       sub.setCalendar(cal); 
     119      BwSubscription sub = BwSubscription.makeSubscription(cal); 
    124120 
    125121      Collection c = new Vector();