Search in sources :

Example 6 with WebdavBadRequest

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

the class BwSysIntfImpl method updateEvent.

@Override
public void updateEvent(final CalDAVEvent event) throws WebdavException {
    try {
        EventInfo ei = getEvinfo(event);
        getSvci().getEventsHandler().update(ei, false);
    } 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 7 with WebdavBadRequest

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

the class BwSysIntfImpl method getSyncReport.

@Override
public SynchReportData getSyncReport(final String path, final String token, final int limit, final boolean recurse) throws WebdavException {
    try {
        String syncToken = null;
        if (token != null) {
            if (!token.startsWith("data:,")) {
                throw new WebdavForbidden(WebdavTags.validSyncToken, token);
            }
            syncToken = token.substring(6);
        }
        if ((syncToken != null) && (syncToken.length() == 16)) {
            // Force a full reload
            syncToken = null;
        }
        final SynchReport sr = getSvci().getSynchReport(path, syncToken, limit, recurse);
        if (sr == null) {
            return null;
        }
        final SynchReportData srd = new SynchReportData();
        srd.items = new ArrayList<>();
        srd.token = "data:," + sr.getToken();
        srd.truncated = sr.getTruncated();
        for (final SynchReportItem sri : sr.getItems()) {
            final SynchReportDataItem srdi;
            if (sri.getEvent() != null) {
                srdi = new SynchReportDataItem(sri.getVpath(), new BwCalDAVEvent(this, sri.getEvent()), sri.getToken());
            } else if (sri.getResource() != null) {
                srdi = new SynchReportDataItem(sri.getVpath(), new BwCalDAVResource(this, sri.getResource()), sri.getToken());
            } else if (sri.getCol() != null) {
                srdi = new SynchReportDataItem(sri.getVpath(), new BwCalDAVCollection(this, sri.getCol()), sri.getToken(), sri.getCanSync());
            } else {
                throw new RuntimeException("Unhandled sync report item type");
            }
            srd.items.add(srdi);
        }
        return srd;
    } catch (final CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (final CalFacadeInvalidSynctoken cist) {
        throw new WebdavBadRequest(WebdavTags.validSyncToken);
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (final WebdavException we) {
        throw we;
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) SynchReport(org.bedework.calsvci.SynchReport) SynchReportDataItem(org.bedework.caldav.server.sysinterface.SysIntf.SynchReportData.SynchReportDataItem) CalFacadeInvalidSynctoken(org.bedework.calfacade.exc.CalFacadeInvalidSynctoken) SynchReportItem(org.bedework.calsvci.SynchReportItem)

Example 8 with WebdavBadRequest

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

the class BwSysIntfImpl method schedule.

@Override
public Collection<SchedRecipientResult> schedule(final CalDAVEvent ev) throws WebdavException {
    try {
        ScheduleResult sr;
        BwEvent event = getEvent(ev);
        event.setOwnerHref(currentPrincipal.getPrincipalRef());
        if (Icalendar.itipReplyMethodType(event.getScheduleMethod())) {
            sr = getSvci().getScheduler().scheduleResponse(getEvinfo(ev));
        } else {
            sr = getSvci().getScheduler().schedule(getEvinfo(ev), null, null, // iSchedule
            true);
        }
        return checkStatus(sr);
    } catch (WebdavException we) {
        throw we;
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } 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) 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)

Example 9 with WebdavBadRequest

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

the class BwSysIntfImpl method fromIcal.

@Override
public SysiIcalendar fromIcal(final CalDAVCollection col, final IcalendarType ical, final IcalResultType rtype) throws WebdavException {
    // Ensure open
    getSvci();
    boolean rollback = true;
    try {
        BwCalendar bwcol = null;
        if (col != null) {
            bwcol = unwrap(col.resolveAlias(true));
        }
        Icalendar ic = trans.fromIcal(bwcol, ical, // diff the contents
        true);
        if (rtype == IcalResultType.OneComponent) {
            if (ic.getComponents().size() != 1) {
                throw new WebdavBadRequest(CaldavTags.validCalendarObjectResource);
            }
            if (!(ic.getComponents().iterator().next() instanceof EventInfo)) {
                throw new WebdavBadRequest(CaldavTags.validCalendarObjectResource);
            }
        } else if (rtype == IcalResultType.TimeZone) {
            if (ic.getTimeZones().size() != 1) {
                throw new WebdavBadRequest("Expected one timezone");
            }
        }
        SysiIcalendar sic = new MySysiIcalendar(this, ic);
        rollback = false;
        return sic;
    } catch (WebdavException wde) {
        throw wde;
    } catch (IcalMalformedException ime) {
        throw new WebdavForbidden(CaldavTags.validCalendarData, ime.getMessage());
    } catch (Throwable t) {
        if (debug) {
            error(t);
        }
        // Assume bad data in some way
        throw new WebdavForbidden(CaldavTags.validCalendarObjectResource, t.getMessage());
    } finally {
        if (rollback) {
            try {
                getSvci().rollbackTransaction();
            } catch (Throwable t) {
            }
        }
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) EventInfo(org.bedework.calfacade.svc.EventInfo) Icalendar(org.bedework.icalendar.Icalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCalendar(org.bedework.calfacade.BwCalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) IcalMalformedException(org.bedework.icalendar.IcalMalformedException)

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