Changeset 472

Show
Ignore:
Timestamp:
05/12/06 16:51:23
Author:
douglm
Message:

Bring caldav free/busy query up to date

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/CaldavBWIntf.java

    r465 r472  
    12171217 
    12181218  /** The node represents a calendar resource for which we must get free-busy 
    1219    * information. We return a copy of the node for each time period in the 
    1220    * request. 
     1219   * information. 
    12211220   * 
    1222    * @param wdnode 
     1221   * @param cnode  CaldavCalNode 
    12231222   * @param freeBusy 
    1224    * @return Collection 
    12251223   * @throws WebdavIntfException 
    12261224   */ 
    1227   public Collection getFreeBusy(WebdavNsNode wdnode, 
    1228                                 FreeBusyQuery freeBusy) throws WebdavIntfException { 
    1229     try { 
    1230       CaldavBwNode uwnode = getBwnode(wdnode); 
    1231       if (!(uwnode instanceof CaldavCalNode)) { 
    1232         throw WebdavIntfException.badRequest(); 
    1233       } 
    1234  
    1235       CaldavCalNode cnode = (CaldavCalNode)uwnode; 
    1236  
     1225  public void getFreeBusy(CaldavCalNode cnode, 
     1226                          FreeBusyQuery freeBusy) throws WebdavIntfException { 
     1227    try { 
    12371228      String user = cnode.getCDURI().getOwner(); 
    12381229 
    12391230      getSvci(); 
    12401231 
    1241       Iterator it = freeBusy.getFreeBusy(svci, user).iterator(); 
    1242       Collection nodes = new ArrayList(); 
    1243  
    1244       while (it.hasNext()) { 
    1245         BwFreeBusy fb = (BwFreeBusy)it.next(); 
    1246  
    1247         CaldavCalNode fbnode = (CaldavCalNode)cnode.clone(); 
    1248  
    1249         fbnode.setFreeBusy(fb); 
    1250  
    1251         nodes.add(fbnode); 
    1252       } 
    1253  
    1254       return nodes; 
     1232      BwFreeBusy fb = freeBusy.getFreeBusy(svci, user); 
     1233 
     1234      cnode.setFreeBusy(fb); 
    12551235    } catch (WebdavIntfException we) { 
    12561236      throw we; 
  • trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/CaldavCalNode.java

    r119 r472  
    6969import java.util.Vector; 
    7070 
     71import net.fortuna.ical4j.model.Calendar; 
    7172import net.fortuna.ical4j.model.component.VFreeBusy; 
    7273 
     
    7677 */ 
    7778public class CaldavCalNode extends CaldavBwNode { 
    78   private VFreeBusy vfreeBusy
     79  private Calendar ical
    7980 
    8081  private String vfreeBusyString; 
     
    153154  public void setFreeBusy(BwFreeBusy fb) throws WebdavIntfException { 
    154155    try { 
    155       vfreeBusy = VFreeUtil.toVFreeBusy(fb); 
     156      VFreeBusy vfreeBusy = VFreeUtil.toVFreeBusy(fb); 
    156157      if (vfreeBusy != null) { 
    157         vfreeBusyString = vfreeBusy.toString(); 
     158        ical = new Calendar(); 
     159        ical.getComponents().add(vfreeBusy); 
     160        vfreeBusyString = ical.toString(); 
    158161        contentLen = vfreeBusyString.length(); 
    159162      } else { 
     
    161164        contentLen = 0; 
    162165      } 
     166      allowsGet = true; 
    163167    } catch (Throwable t) { 
    164168      if (debug) { 
     
    172176    init(true); 
    173177 
    174     if (vfreeBusy == null) { 
     178    if (ical == null) { 
    175179      return null; 
    176180    } 
  • trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/ReportMethod.java

    r469 r472  
    127127    } 
    128128 
    129     startEmit(resp); 
    130  
    131129    int st = processDoc(doc); 
    132130 
     
    145143      processFbResp(req, resp); 
    146144    } else { 
     145      startEmit(resp); 
     146 
    147147      processResp(req, resp, depth); 
    148148    } 
     
    182182      } else if (nodeMatches(root, CaldavTags.freeBusyQuery)) { 
    183183        reportType = reportTypeFreeBusy; 
     184        freeBusy = new FreeBusyQuery(intf, debug); 
    184185      } else if (nodeMatches(root, WebdavTags.expandProperty)) { 
    185186        reportType = reportTypeExpandProperty; 
     
    204205 
    205206        if (reportType == reportTypeFreeBusy) { 
    206           freeBusy = new FreeBusyQuery(intf, debug); 
    207207          freeBusy.parse(curnode); 
    208208        } else if (reportType == reportTypeExpandProperty) { 
     
    420420   * @param req 
    421421   * @param resp 
    422    * @param depth 
    423422   * @throws WebdavException 
    424423   */ 
     
    433432    WebdavNsNode node = intf.getNode(resourceUri); 
    434433 
    435     int status = HttpServletResponse.SC_OK; 
    436  
    437     Collection nodes = null; 
    438  
    439     try { 
    440       nodes = intf.getFreeBusy(node, freeBusy); 
    441     } catch (WebdavException wde) { 
     434    if (!(node instanceof CaldavCalNode)) { 
    442435      if (debug) { 
    443         trace("intf.getFreeBusy exception"); 
    444       } 
    445       status = wde.getStatusCode(); 
    446     } 
    447  
    448     if (status != HttpServletResponse.SC_OK) { 
    449       if (debug) { 
    450         trace("REPORT status " + status); 
    451       } 
    452       // Entire request failed. 
    453       node.setStatus(status); 
    454       doNode(node); 
    455     } else if (nodes != null) { 
    456       Iterator it = nodes.iterator(); 
    457  
    458       // XXX Only one node? 
    459       while (it.hasNext()) { 
    460         WebdavNsNode curnode = (WebdavNsNode)it.next(); 
    461  
    462         if (!(node instanceof CaldavCalNode)) { 
    463           if (debug) { 
    464             trace("Expected CaldavCalNode - got " + node); 
    465           } 
    466           status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; 
    467         } else { 
    468           CaldavCalNode cnode = (CaldavCalNode)node; 
    469  
    470           Writer out; 
    471           try { 
    472             out = resp.getWriter(); 
    473           } catch (Throwable t) { 
    474             throw new WebdavException(t); 
    475           } 
    476  
    477           /** Get the content now to set up length, type etc. 
    478            */ 
    479           Reader in = getNsIntf().getContent(node); 
    480           resp.setContentLength(node.getContentLen()); 
    481           if (in == null) { 
    482             if (debug) { 
    483               debugMsg("status: " + HttpServletResponse.SC_NO_CONTENT); 
    484             } 
    485  
    486             resp.setStatus(HttpServletResponse.SC_NO_CONTENT); 
    487           } else { 
    488             if (debug) { 
    489               debugMsg("send content - length=" + node.getContentLen()); 
    490             } 
    491  
    492             writeContent(in, out); 
    493           } 
    494         } 
    495       } 
    496     } 
    497  
    498     flush(); 
     436        trace("Expected CaldavCalNode - got " + node); 
     437      } 
     438      node.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 
     439    } else { 
     440      try { 
     441        intf.getFreeBusy((CaldavCalNode)node, freeBusy); 
     442      } catch (WebdavException wde) { 
     443        if (debug) { 
     444          trace("intf.getFreeBusy exception"); 
     445        } 
     446        node.setStatus(wde.getStatusCode()); 
     447      } 
     448 
     449      Writer out; 
     450      try { 
     451        out = resp.getWriter(); 
     452      } catch (Throwable t) { 
     453        throw new WebdavException(t); 
     454      } 
     455 
     456      /** Get the content now to set up length, type etc. 
     457       */ 
     458      Reader in = getNsIntf().getContent(node); 
     459      resp.setContentLength(node.getContentLen()); 
     460      if (in == null) { 
     461        if (debug) { 
     462          debugMsg("status: " + HttpServletResponse.SC_NO_CONTENT); 
     463        } 
     464 
     465        resp.setStatus(HttpServletResponse.SC_NO_CONTENT); 
     466      } else { 
     467        if (debug) { 
     468          debugMsg("send content - length=" + node.getContentLen()); 
     469        } 
     470 
     471        writeContent(in, out); 
     472      } 
     473    } 
    499474  } 
    500475 
  • trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/calquery/FreeBusyQuery.java

    r420 r472  
    6868import edu.rpi.cct.webdav.servlet.shared.WebdavNsIntf; 
    6969 
    70 import java.util.ArrayList; 
    71 import java.util.Collection; 
    72 import java.util.Iterator; 
    73 import javax.servlet.http.HttpServletResponse; 
    74  
    7570import org.apache.log4j.Logger; 
    7671import org.w3c.dom.Node; 
     
    8681  protected transient Logger log; 
    8782 
    88   private Collection timeRanges
     83  private TimeRange timeRange
    8984 
    9085  /** Constructor 
     
    9994 
    10095  /** The given node is is the free-busy-query time-range element 
    101    * Should have one or more time-range elements
     96   * Should have exactly one time-range element
    10297   * 
    10398   * @param nd 
    104    * @return int     htp status 
    10599   * @throws WebdavException 
    106100   */ 
    107   public int parse(Node nd) throws WebdavException { 
     101  public void parse(Node nd) throws WebdavException { 
    108102    try { 
    109       if (timeRanges == null) { 
    110         timeRanges = new ArrayList(); 
     103      if (timeRange != null) { 
     104        throw new WebdavBadRequest(); 
    111105      } 
    112106 
     
    115109      } 
    116110 
    117       TimeRange tr = CalDavParseUtil.parseTimeRange(nd, intf.getSvci().getTimezones()); 
    118       timeRanges.add(tr); 
     111      timeRange = CalDavParseUtil.parseTimeRange(nd, intf.getSvci().getTimezones()); 
    119112 
    120113      if (debug) { 
    121         trace("Parsed time range " + tr); 
     114        trace("Parsed time range " + timeRange); 
    122115      } 
    123116    } catch (WebdavBadRequest wbr) { 
    124       return wbr.getStatusCode()
     117      throw wbr
    125118    } catch (Throwable t) { 
    126119      throw new WebdavBadRequest(); 
    127120    } 
    128  
    129     return HttpServletResponse.SC_OK; 
    130121  } 
    131122 
     
    133124   * @param svci 
    134125   * @param user 
    135    * @return Collection 
     126   * @return BwFreeBusy 
    136127   * @throws WebdavException 
    137128   */ 
    138   public Collection getFreeBusy(CalSvcI svci, String user) throws WebdavException { 
    139     Iterator it = timeRanges.iterator(); 
    140     Collection fbs = new ArrayList(); 
    141  
    142     while (it.hasNext()) { 
    143       TimeRange tr = (TimeRange)it.next(); 
    144  
    145       try { 
    146         BwFreeBusy fb = svci.getFreeBusy(null, new BwUser(user), 
    147                                          tr.getStart(), tr.getEnd(), null, 
    148                                          false); 
    149  
    150         if (debug) { 
    151           trace("Got " + fb); 
    152         } 
    153         fbs.add(fb); 
    154       } catch (Throwable t) { 
    155         throw new WebdavException(t); 
    156       } 
    157     } 
    158  
    159     return fbs; 
     129  public BwFreeBusy getFreeBusy(CalSvcI svci, String user) throws WebdavException { 
     130    try { 
     131      BwFreeBusy fb = svci.getFreeBusy(null, new BwUser(user), 
     132                                       timeRange.getStart(), timeRange.getEnd(), 
     133                                       null, false); 
     134 
     135      if (debug) { 
     136        trace("Got " + fb); 
     137      } 
     138 
     139      return fb; 
     140    } catch (Throwable t) { 
     141      throw new WebdavException(t); 
     142    } 
    160143  } 
    161144 
     
    166149    trace("<free-busy-query>"); 
    167150 
    168     Iterator it = timeRanges.iterator(); 
    169     while (it.hasNext()) { 
    170       TimeRange tr = (TimeRange)it.next(); 
    171  
    172       tr.dump(getLogger(), "  "); 
    173     } 
     151    timeRange.dump(getLogger(), "  "); 
    174152 
    175153    trace("</free-busy-query>"); 
  • trunk/calendar3/icalendar/src/org/bedework/icalendar/BwFreeBusyUtil.java

    r471 r472  
    7070import net.fortuna.ical4j.model.parameter.FbType; 
    7171import net.fortuna.ical4j.model.property.DtEnd; 
     72import net.fortuna.ical4j.model.property.DtStamp; 
    7273import net.fortuna.ical4j.model.property.DtStart; 
    7374import net.fortuna.ical4j.model.property.Duration; 
     
    168169          Iterator perit = perpl.iterator(); 
    169170          while (perit.hasNext()) { 
    170             Period per = (Period)it.next(); 
     171            Period per = (Period)perit.next(); 
    171172 
    172173            fbc.addPeriod(per); 
     
    174175 
    175176          fb.addTime(fbc); 
     177        } else if (prop instanceof DtEnd) { 
     178          /* ------------------- DtEnd -------------------- */ 
     179        } else if (prop instanceof DtStamp) { 
     180          /* ------------------- DtStamp -------------------- */ 
     181 
     182          //ev.setDtstamp(wrapper.getDtStamp()); 
     183        } else if (prop instanceof DtStart) { 
     184          /* ------------------- DtStart -------------------- */ 
    176185        } else { 
    177186          if (debug) {