Search in sources :

Example 1 with WebdavBadRequest

use of org.bedework.webdav.servlet.shared.WebdavBadRequest 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 WebdavBadRequest

use of org.bedework.webdav.servlet.shared.WebdavBadRequest in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method updateEvent.

@Override
public UpdateResult updateEvent(final CalDAVEvent event, final List<ComponentSelectionType> updates) throws WebdavException {
    try {
        EventInfo ei = getEvinfo(event);
        if (updates == null) {
            return new UpdateResult("No updates");
        }
        UpdateResult ur = new BwUpdates(getPrincipal().getPrincipalRef()).updateEvent(ei, updates, getSvci().getIcalCallback());
        if (!ur.getOk()) {
            getSvci().rollbackTransaction();
            return ur;
        }
        getSvci().getEventsHandler().update(ei, false);
        return ur;
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeForbidden cff) {
        throw new WebdavForbidden(cff.getQname(), cff.getMessage());
    } catch (CalFacadeException cfe) {
        if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
            throw new WebdavBadRequest("Duplicate-guid");
        }
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 3 with WebdavBadRequest

use of org.bedework.webdav.servlet.shared.WebdavBadRequest in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getRrm.

private RecurringRetrievalMode getRrm(final RetrievalMode rm) throws WebdavException {
    if (rm == null) {
        return RecurringRetrievalMode.overrides;
    }
    try {
        if (rm.getExpand() != null) {
            /* expand with time range */
            ExpandType ex = rm.getExpand();
            DateTime s = new DateTime(XcalUtil.getIcalFormatDateTime(ex.getStart()));
            DateTime e = new DateTime(XcalUtil.getIcalFormatDateTime(ex.getEnd()));
            return new RecurringRetrievalMode(Rmode.expanded, getBwDt(s), getBwDt(e));
        }
        if (rm.getLimitRecurrenceSet() != null) {
            /* Only return master event and overrides in range */
            LimitRecurrenceSetType l = rm.getLimitRecurrenceSet();
            DateTime s = new DateTime(XcalUtil.getIcalFormatDateTime(l.getStart()));
            DateTime e = new DateTime(XcalUtil.getIcalFormatDateTime(l.getEnd()));
            return new RecurringRetrievalMode(Rmode.overrides, getBwDt(s), getBwDt(e));
        }
    } catch (Throwable t) {
        throw new WebdavBadRequest(CaldavTags.validFilter, "Invalid time-range");
    }
    /* Return master + overrides */
    return RecurringRetrievalMode.overrides;
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) RecurringRetrievalMode(org.bedework.calfacade.RecurringRetrievalMode) LimitRecurrenceSetType(ietf.params.xml.ns.caldav.LimitRecurrenceSetType) ExpandType(ietf.params.xml.ns.caldav.ExpandType) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime)

Example 4 with WebdavBadRequest

use of org.bedework.webdav.servlet.shared.WebdavBadRequest in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method doNoteHeader.

/* ====================================================================
   *                         Private methods
   * ==================================================================== */
private String doNoteHeader(final String hdr, final String account) throws WebdavException {
    if (hdr == null) {
        return account;
    }
    try {
        final String[] hparts = hdr.split(":");
        if (hparts.length != 2) {
            throw new WebdavBadRequest();
        }
        final String id = hparts[0];
        final NotificationProperties nprops = configs.getNotificationProps();
        final String token = hparts[1];
        if (id == null) {
            throw new WebdavBadRequest();
        }
        if (!id.equals(nprops.getNotifierId()) || (token == null) || !token.equals(nprops.getNotifierToken())) {
            throw new WebdavBadRequest();
        }
        if (account != null) {
            return account;
        }
        return id;
    } catch (final WebdavException wde) {
        throw wde;
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) NotificationProperties(org.bedework.calfacade.configs.NotificationProperties) WebdavException(org.bedework.webdav.servlet.shared.WebdavException)

Example 5 with WebdavBadRequest

use of org.bedework.webdav.servlet.shared.WebdavBadRequest in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method requestFreeBusy.

@Override
public Collection<SchedRecipientResult> requestFreeBusy(final CalDAVEvent val, final boolean iSchedule) throws WebdavException {
    try {
        ScheduleResult sr;
        BwEvent ev = getEvent(val);
        if (currentPrincipal != null) {
            ev.setOwnerHref(currentPrincipal.getPrincipalRef());
        }
        if (Icalendar.itipReplyMethodType(ev.getScheduleMethod())) {
            sr = getSvci().getScheduler().scheduleResponse(getEvinfo(val));
        } else {
            sr = getSvci().getScheduler().schedule(getEvinfo(val), null, null, iSchedule);
        }
        return checkStatus(sr);
    } catch (CalFacadeAccessException cfae) {
        if (debug) {
            error(cfae);
        }
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
            throw new WebdavBadRequest("Duplicate-guid");
        }
        throw new WebdavException(cfe);
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) ScheduleResult(org.bedework.calfacade.ScheduleResult) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)9 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)8 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)7 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)6 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)6 EventInfo (org.bedework.calfacade.svc.EventInfo)4 BwEvent (org.bedework.calfacade.BwEvent)2 ScheduleResult (org.bedework.calfacade.ScheduleResult)2 CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)2 ExpandType (ietf.params.xml.ns.caldav.ExpandType)1 LimitRecurrenceSetType (ietf.params.xml.ns.caldav.LimitRecurrenceSetType)1 ArrayList (java.util.ArrayList)1 DateTime (net.fortuna.ical4j.model.DateTime)1 CalDAVEvent (org.bedework.caldav.server.CalDAVEvent)1 SysiIcalendar (org.bedework.caldav.server.SysiIcalendar)1 SynchReportDataItem (org.bedework.caldav.server.sysinterface.SysIntf.SynchReportData.SynchReportDataItem)1 FilterBase (org.bedework.caldav.util.filter.FilterBase)1 BwCalendar (org.bedework.calfacade.BwCalendar)1 BwDateTime (org.bedework.calfacade.BwDateTime)1 RecurringRetrievalMode (org.bedework.calfacade.RecurringRetrievalMode)1