Search in sources :

Example 21 with WebdavForbidden

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

WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)21 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)20 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)15 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)13 EventInfo (org.bedework.calfacade.svc.EventInfo)8 BwCalendar (org.bedework.calfacade.BwCalendar)7 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)7 ArrayList (java.util.ArrayList)6 BwEvent (org.bedework.calfacade.BwEvent)4 SysiIcalendar (org.bedework.caldav.server.SysiIcalendar)3 CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)3 Icalendar (org.bedework.icalendar.Icalendar)3 CalDAVEvent (org.bedework.caldav.server.CalDAVEvent)2 BwResource (org.bedework.calfacade.BwResource)2 ScheduleResult (org.bedework.calfacade.ScheduleResult)2 IcalMalformedException (org.bedework.icalendar.IcalMalformedException)2 UrlHandler (org.bedework.webdav.servlet.shared.UrlHandler)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1