Search in sources :

Example 1 with CalDAVEvent

use of org.bedework.caldav.server.CalDAVEvent in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getEvents.

@Override
public Collection<CalDAVEvent> getEvents(final CalDAVCollection col, final FilterBase filter, final List<String> retrieveList, final RetrievalMode recurRetrieval) throws WebdavException {
    try {
        /* Limit the results to just this collection by adding an ANDed filter */
        final SimpleFilterParser sfp = getSvci().getFilterParser();
        final String expr = "(colPath='" + SfpTokenizer.escapeQuotes(col.getPath()) + "')";
        final ParseResult pr = sfp.parse(expr, true, null);
        if (!pr.ok) {
            throw new WebdavBadRequest("Failed to reference collection " + col.getPath() + ": message was " + pr.message);
        }
        final FilterBase f = FilterBase.addAndChild(filter, pr.filter);
        final Collection<EventInfo> bwevs = // Collection
        getSvci().getEventsHandler().getEvents(// Collection
        null, f, // start
        null, // end
        null, RetrieveList.getRetrieveList(retrieveList), DeletedState.noDeleted, getRrm(recurRetrieval));
        if (bwevs == null) {
            return null;
        }
        final Collection<CalDAVEvent> evs = new ArrayList<>();
        for (final EventInfo ei : bwevs) {
            if (recurRetrieval != null) {
                ei.getEvent().setForceUTC(recurRetrieval.getExpand() != null);
            }
            evs.add(new BwCalDAVEvent(this, ei));
        }
        return evs;
    } catch (final CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (final CalFacadeException cfe) {
        if (CalFacadeException.unknownProperty.equals(cfe.getMessage())) {
            throw new WebdavBadRequest("Unknown property " + cfe.getExtra());
        }
        throw new WebdavException(cfe);
    } catch (final WebdavException wde) {
        throw wde;
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) ParseResult(org.bedework.calfacade.filter.SimpleFilterParser.ParseResult) EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) SimpleFilterParser(org.bedework.calfacade.filter.SimpleFilterParser) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) CalDAVEvent(org.bedework.caldav.server.CalDAVEvent) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 2 with CalDAVEvent

use of org.bedework.caldav.server.CalDAVEvent in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method writeCalendar.

@Override
public String writeCalendar(final Collection<CalDAVEvent> evs, final MethodEmitted method, final XmlEmit xml, final Writer wtr, final String contentType) throws WebdavException {
    try {
        Collection<EventInfo> bwevs = new ArrayList<EventInfo>();
        int meth = ScheduleMethods.methodTypeNone;
        if (method == MethodEmitted.publish) {
            meth = ScheduleMethods.methodTypePublish;
        }
        for (CalDAVEvent cde : evs) {
            BwCalDAVEvent bcde = (BwCalDAVEvent) cde;
            if (method == MethodEmitted.eventMethod) {
                meth = getEvent(bcde).getScheduleMethod();
            }
            bwevs.add(bcde.getEvinfo());
        }
        String ctype = contentType;
        if ((ctype == null) || (!ctype.equals("text/calendar") && !ctype.equals("application/calendar+json") && !ctype.equals(XcalTags.mimetype))) {
            ctype = getDefaultContentType();
        }
        if (ctype.equals("text/calendar")) {
            Calendar ical = trans.toIcal(bwevs, meth);
            if (xml == null) {
                IcalTranslator.writeCalendar(ical, wtr);
            } else {
                xml.cdataValue(toIcalString(ical, "text/calendar"));
            }
        } else if (ctype.equals("application/calendar+json")) {
            if (xml == null) {
                trans.writeJcal(bwevs, meth, wtr);
            } else {
                final StringWriter sw = new StringWriter();
                trans.writeJcal(bwevs, meth, sw);
                xml.cdataValue(sw.toString());
            }
        } else if (ctype.equals(XcalTags.mimetype)) {
            XmlEmit x;
            if (xml == null) {
                x = new XmlEmit();
                x.startEmit(wtr);
            } else {
                x = xml;
            }
            trans.writeXmlCalendar(bwevs, meth, x);
        }
        return ctype;
    } catch (WebdavException we) {
        throw we;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) StringWriter(java.io.StringWriter) BwCalendar(org.bedework.calfacade.BwCalendar) Calendar(net.fortuna.ical4j.model.Calendar) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalDAVEvent(org.bedework.caldav.server.CalDAVEvent) XmlEmit(org.bedework.util.xml.XmlEmit)

Example 3 with CalDAVEvent

use of org.bedework.caldav.server.CalDAVEvent in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method addEvent.

/* ====================================================================
   *                   Events
   * ==================================================================== */
/* (non-Javadoc)
   * @see org.bedework.caldav.server.SysIntf#addEvent(org.bedework.caldav.server.CalDAVEvent, boolean, boolean)
   */
@Override
public Collection<CalDAVEvent> addEvent(final CalDAVEvent ev, final boolean noInvites, final boolean rollbackOnError) throws WebdavException {
    try {
        /* Is the event a scheduling object? */
        final EventInfo ei = getEvinfo(ev);
        final Collection<BwEventProxy> bwevs = getSvci().getEventsHandler().add(ei, noInvites, // scheduling - inbox
        false, // autocreate
        false, rollbackOnError).failedOverrides;
        if (bwevs == null) {
            return null;
        }
        final Collection<CalDAVEvent> evs = new ArrayList<CalDAVEvent>();
        for (final BwEvent bwev : bwevs) {
            evs.add(new BwCalDAVEvent(this, new EventInfo(bwev)));
        }
        return evs;
    } catch (final CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (final CalFacadeException cfe) {
        if (CalFacadeException.schedulingTooManyAttendees.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.maxAttendeesPerInstance, ev.getParentPath() + "/" + cfe.getExtra());
        }
        if (CalFacadeException.invalidOverride.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.validCalendarData, ev.getParentPath() + "/" + cfe.getExtra());
        }
        if (CalFacadeException.duplicateGuid.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.noUidConflict, ev.getParentPath() + "/" + cfe.getExtra());
        }
        if (CalFacadeException.duplicateName.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.noUidConflict, ev.getParentPath() + "/" + ev.getName());
        }
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) CalDAVEvent(org.bedework.caldav.server.CalDAVEvent)

Aggregations

ArrayList (java.util.ArrayList)3 CalDAVEvent (org.bedework.caldav.server.CalDAVEvent)3 EventInfo (org.bedework.calfacade.svc.EventInfo)3 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)2 StringWriter (java.io.StringWriter)1 Calendar (net.fortuna.ical4j.model.Calendar)1 FilterBase (org.bedework.caldav.util.filter.FilterBase)1 BwCalendar (org.bedework.calfacade.BwCalendar)1 BwEvent (org.bedework.calfacade.BwEvent)1 BwEventProxy (org.bedework.calfacade.BwEventProxy)1 SimpleFilterParser (org.bedework.calfacade.filter.SimpleFilterParser)1 ParseResult (org.bedework.calfacade.filter.SimpleFilterParser.ParseResult)1 XmlEmit (org.bedework.util.xml.XmlEmit)1 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)1