Search in sources :

Example 1 with CalendarCollection

use of com.zimbra.cs.dav.resource.CalendarCollection in project zm-mailbox by Zimbra.

the class MkCalendar method handle.

// valid return codes:
// 201 Created, 207 Multi-Status (403, 409, 423, 424, 507),
// 403 Forbidden, 409 Conflict, 415 Unsupported Media Type,
// 507 Insufficient Storage
@Override
public void handle(DavContext ctxt) throws DavException, IOException {
    String user = ctxt.getUser();
    String name = ctxt.getItem();
    if (user == null || name == null)
        throw new DavException("invalid uri", HttpServletResponse.SC_FORBIDDEN, null);
    Element top = null;
    if (ctxt.hasRequestMessage()) {
        Document doc = ctxt.getRequestMessage();
        top = doc.getRootElement();
        if (!top.getName().equals(DavElements.P_MKCALENDAR))
            throw new DavException("msg " + top.getName() + " not allowed in MKCALENDAR", HttpServletResponse.SC_BAD_REQUEST, null);
    }
    Collection col = UrlNamespace.getCollectionAtUrl(ctxt, ctxt.getPath());
    if (col instanceof CalendarCollection)
        throw new DavException("can't create calendar under another calendar", HttpServletResponse.SC_FORBIDDEN, null);
    Collection newone = col.mkCol(ctxt, name, MailItem.Type.APPOINTMENT);
    boolean success = false;
    try {
        PropPatch.handlePropertyUpdate(ctxt, top, newone, true, MKCALENDAR);
        success = true;
    } finally {
        if (!success)
            newone.delete(ctxt);
    }
    ctxt.setStatus(HttpServletResponse.SC_CREATED);
    ctxt.getResponse().addHeader(DavProtocol.HEADER_CACHE_CONTROL, DavProtocol.NO_CACHE);
}
Also used : CalendarCollection(com.zimbra.cs.dav.resource.CalendarCollection) DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element) CalendarCollection(com.zimbra.cs.dav.resource.CalendarCollection) Collection(com.zimbra.cs.dav.resource.Collection) Document(org.dom4j.Document)

Example 2 with CalendarCollection

use of com.zimbra.cs.dav.resource.CalendarCollection in project zm-mailbox by Zimbra.

the class CalendarQuery method handle.

@Override
public void handle(DavContext ctxt) throws DavException, ServiceException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.E_CALENDAR_QUERY)) {
        throw new DavException("msg " + query.getName() + " is not calendar-query", HttpServletResponse.SC_BAD_REQUEST, null);
    }
    RequestProp reqProp = ctxt.getRequestProp();
    QueryContext qctxt = new QueryContext(ctxt, query, reqProp);
    if (qctxt.componentFilter == null) {
        throw new DavException("missing filter element in the request", HttpServletResponse.SC_BAD_REQUEST, null);
    }
    DavResource rsc = ctxt.getRequestedResource();
    if (!(rsc instanceof CalendarCollection)) {
        throw new DavException("not a calendar resource", HttpServletResponse.SC_BAD_REQUEST, null);
    }
    CalendarCollection cal = (CalendarCollection) rsc;
    TimeRange tr = qctxt.componentFilter.getTimeRange();
    if (tr == null) {
        tr = new TimeRange(rsc.getOwner());
    }
    /**
         * Even if there are no matching items, we should return a DAV:multistatus report
         * http://tools.ietf.org/html/rfc4791#section-7.8 CALDAV:calendar-query REPORT
         * The response body for a successful request MUST be a DAV:multistatus XML element (i.e., the response uses
         * the same format as the response for PROPFIND).  In the case where there are no response elements, the
         * returned DAV:multistatus XML element is empty.
         */
    qctxt.davCtxt.setStatus(DavProtocol.STATUS_MULTI_STATUS);
    DavResponse resp = qctxt.davCtxt.getDavResponse();
    resp.getTop(DavElements.E_MULTISTATUS);
    for (DavResource calItem : cal.getChildren(ctxt, tr)) {
        handleCalendarItem(qctxt, calItem);
    }
}
Also used : TimeRange(com.zimbra.cs.dav.caldav.Range.TimeRange) DavResource(com.zimbra.cs.dav.resource.DavResource) CalendarCollection(com.zimbra.cs.dav.resource.CalendarCollection) DavException(com.zimbra.cs.dav.DavException) DavResponse(com.zimbra.cs.dav.service.DavResponse) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp) Element(org.dom4j.Element)

Example 3 with CalendarCollection

use of com.zimbra.cs.dav.resource.CalendarCollection in project zm-mailbox by Zimbra.

the class FreeBusyQuery method handle.

public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.E_FREE_BUSY_QUERY))
        throw new DavException("msg " + query.getName() + " is not free-busy-query", HttpServletResponse.SC_BAD_REQUEST, null);
    Element trElem = query.element(DavElements.E_TIME_RANGE);
    if (trElem == null)
        throw new DavException("need time-range", HttpServletResponse.SC_BAD_REQUEST, null);
    TimeRange timeRange = new TimeRange(trElem);
    DavResource rs = ctxt.getRequestedResource();
    if (!(rs instanceof CalendarCollection))
        throw new DavException("not a calendar collection", HttpServletResponse.SC_BAD_REQUEST, null);
    try {
        String freebusy = ((CalendarCollection) rs).getFreeBusyReport(ctxt, timeRange);
        HttpServletResponse resp = ctxt.getResponse();
        resp.setContentType(MimeConstants.CT_TEXT_CALENDAR);
        resp.getOutputStream().write(freebusy.getBytes("UTF-8"));
        ctxt.responseSent();
    } catch (ServiceException se) {
        throw new DavException("can't get freebusy report", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, se);
    }
}
Also used : TimeRange(com.zimbra.cs.dav.caldav.Range.TimeRange) DavResource(com.zimbra.cs.dav.resource.DavResource) CalendarCollection(com.zimbra.cs.dav.resource.CalendarCollection) ServiceException(com.zimbra.common.service.ServiceException) DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 4 with CalendarCollection

use of com.zimbra.cs.dav.resource.CalendarCollection in project zm-mailbox by Zimbra.

the class CalendarMultiget method handle.

public void handle(DavContext ctxt) throws ServiceException, DavException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.E_CALENDAR_MULTIGET))
        throw new DavException("msg " + query.getName() + " is not calendar-multiget", HttpServletResponse.SC_BAD_REQUEST, null);
    DavResponse resp = ctxt.getDavResponse();
    ArrayList<String> hrefs = new ArrayList<String>();
    for (Object obj : query.elements(DavElements.E_HREF)) if (obj instanceof Element)
        hrefs.add(((Element) obj).getText());
    long ts = System.currentTimeMillis();
    DavResource reqResource = ctxt.getRequestedResource();
    if (!(reqResource instanceof CalendarCollection))
        throw new DavException("requested resource is not a calendar collection", HttpServletResponse.SC_BAD_REQUEST, null);
    CalendarCollection calResource = (CalendarCollection) reqResource;
    long now = System.currentTimeMillis();
    ZimbraLog.dav.debug("GetRequestedResource: " + (now - ts) + "ms");
    RequestProp reqProp = ctxt.getRequestProp();
    for (DavResource rs : calResource.getAppointmentsByUids(ctxt, hrefs)) resp.addResource(ctxt, rs, reqProp, false);
    ts = now;
    now = System.currentTimeMillis();
    ZimbraLog.dav.debug("multiget: " + (now - ts) + "ms");
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) CalendarCollection(com.zimbra.cs.dav.resource.CalendarCollection) DavException(com.zimbra.cs.dav.DavException) DavResponse(com.zimbra.cs.dav.service.DavResponse) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Aggregations

DavException (com.zimbra.cs.dav.DavException)4 CalendarCollection (com.zimbra.cs.dav.resource.CalendarCollection)4 Element (org.dom4j.Element)4 DavResource (com.zimbra.cs.dav.resource.DavResource)3 RequestProp (com.zimbra.cs.dav.DavContext.RequestProp)2 TimeRange (com.zimbra.cs.dav.caldav.Range.TimeRange)2 DavResponse (com.zimbra.cs.dav.service.DavResponse)2 ServiceException (com.zimbra.common.service.ServiceException)1 Collection (com.zimbra.cs.dav.resource.Collection)1 ArrayList (java.util.ArrayList)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Document (org.dom4j.Document)1