Search in sources :

Example 1 with TimeRange

use of com.zimbra.cs.dav.caldav.Range.TimeRange 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 2 with TimeRange

use of com.zimbra.cs.dav.caldav.Range.TimeRange 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 3 with TimeRange

use of com.zimbra.cs.dav.caldav.Range.TimeRange in project zm-mailbox by Zimbra.

the class CalendarCollection method getAppointmentMap.

protected Map<String, DavResource> getAppointmentMap(DavContext ctxt, TimeRange range) throws ServiceException, DavException {
    Mailbox mbox = getCalendarMailbox(ctxt);
    HashMap<String, DavResource> appts = new HashMap<String, DavResource>();
    ctxt.setCollectionPath(getUri());
    if (range == null)
        range = new TimeRange(getOwner());
    long start = range.getStart();
    long end = range.getEnd();
    start = start == Long.MIN_VALUE ? -1 : start;
    end = end == Long.MAX_VALUE ? -1 : end;
    if (!needCalendarData(ctxt)) {
        ZimbraLog.dav.debug("METADATA only");
        mMetadataOnly = true;
        for (CalendarItem.CalendarMetadata item : mbox.getCalendarItemMetadata(getId(), start, end)) {
            appts.put(item.uid, new CalendarObject.LightWeightCalendarObject(getUri(), getOwner(), item));
        }
    } else {
        for (CalendarItem calItem : mbox.getCalendarItemsForRange(ctxt.getOperationContext(), start, end, getId(), null)) appts.put(calItem.getUid(), new CalendarObject.LocalCalendarObject(ctxt, calItem));
    }
    return appts;
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) TimeRange(com.zimbra.cs.dav.caldav.Range.TimeRange) Mailbox(com.zimbra.cs.mailbox.Mailbox) HashMap(java.util.HashMap)

Example 4 with TimeRange

use of com.zimbra.cs.dav.caldav.Range.TimeRange in project zm-mailbox by Zimbra.

the class Filter method parse.

protected void parse(Element elem) {
    for (Object o : elem.elements()) {
        if (o instanceof Element) {
            Element e = (Element) o;
            QName name = e.getQName();
            if (canHaveCompFilter() && name.equals(DavElements.E_COMP_FILTER))
                mComps.add(new CompFilter(e));
            else if (canHavePropFilter() && name.equals(DavElements.E_PROP_FILTER))
                mProps.add(new PropFilter(e));
            else if (canHaveParamFilter() && name.equals(DavElements.E_PARAM_FILTER))
                mParams.add(new ParamFilter(e));
            else if (name.equals(DavElements.E_TEXT_MATCH))
                mTextMatches.add(new TextMatch(e));
            else if (name.equals(DavElements.E_TIME_RANGE))
                mTimeRange = new TimeRange(e);
            else if (name.equals(DavElements.E_IS_NOT_DEFINED))
                mIsNotDefinedSet = true;
            else
                ZimbraLog.dav.info("unrecognized filter " + name.getNamespaceURI() + ":" + name.getName());
        }
    }
}
Also used : TimeRange(com.zimbra.cs.dav.caldav.Range.TimeRange) QName(org.dom4j.QName) Element(org.dom4j.Element)

Aggregations

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