Search in sources :

Example 1 with SysiIcalendar

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

the class BwSysIntfImpl method fromIcal.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.sysinterface.SysIntf#fromIcal(org.bedework.caldav.server.CalDAVCollection, java.io.Reader, java.lang.String, org.bedework.caldav.server.sysinterface.SysIntf.IcalResultType, boolean)
   */
@Override
public SysiIcalendar fromIcal(final CalDAVCollection col, final Reader rdr, final String contentType, final IcalResultType rtype, final boolean mergeAttendees) throws WebdavException {
    // Ensure open
    getSvci();
    boolean rollback = true;
    /* (CALDAV:supported-calendar-data) */
    if ((contentType == null) || (!contentType.equals("text/calendar") && !contentType.equals("application/calendar+json"))) {
        if (debug) {
            debug("Bad content type: " + contentType);
        }
        throw new WebdavForbidden(CaldavTags.supportedCalendarData, "Bad content type: " + contentType);
    }
    try {
        BwCalendar bwcol = null;
        if (col != null) {
            bwcol = unwrap(col);
        }
        final Icalendar ic = trans.fromIcal(bwcol, new SysIntfReader(rdr), contentType, // diff the contents
        true, mergeAttendees);
        if (rtype == IcalResultType.OneComponent) {
            if (ic.getComponents().size() != 1) {
                throw new WebdavForbidden(CaldavTags.validCalendarObjectResource);
            }
            if (!(ic.getComponents().iterator().next() instanceof EventInfo)) {
                throw new WebdavForbidden(CaldavTags.validCalendarObjectResource);
            }
        } else if (rtype == IcalResultType.TimeZone) {
            if (ic.getTimeZones().size() != 1) {
                throw new WebdavForbidden("Expected one timezone");
            }
        }
        final SysiIcalendar sic = new MySysiIcalendar(this, ic);
        rollback = false;
        return sic;
    } catch (final IcalMalformedException ime) {
        throw new WebdavForbidden(CaldavTags.validCalendarData, ime.getMessage());
    } catch (final CalFacadeException cfe) {
        if (CalFacadeException.unknownTimezone.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.validTimezone, cfe.getMessage());
        }
        throw new WebdavForbidden(CaldavTags.validCalendarObjectResource, cfe.getMessage());
    } catch (final WebdavException wde) {
        throw wde;
    } catch (final 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 (final Throwable ignored) {
            }
        }
    }
}
Also used : SysIntfReader(org.bedework.caldav.server.SysIntfReader) EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) Icalendar(org.bedework.icalendar.Icalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCalendar(org.bedework.calfacade.BwCalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) IcalMalformedException(org.bedework.icalendar.IcalMalformedException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 2 with SysiIcalendar

use of org.bedework.caldav.server.SysiIcalendar 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

SysiIcalendar (org.bedework.caldav.server.SysiIcalendar)2 BwCalendar (org.bedework.calfacade.BwCalendar)2 EventInfo (org.bedework.calfacade.svc.EventInfo)2 IcalMalformedException (org.bedework.icalendar.IcalMalformedException)2 Icalendar (org.bedework.icalendar.Icalendar)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)2 SysIntfReader (org.bedework.caldav.server.SysIntfReader)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)1