Search in sources :

Example 6 with Icalendar

use of org.bedework.icalendar.Icalendar 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

Icalendar (org.bedework.icalendar.Icalendar)6 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)5 StringReader (java.io.StringReader)4 SysiIcalendar (org.bedework.caldav.server.SysiIcalendar)4 EventInfo (org.bedework.calfacade.svc.EventInfo)4 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)3 BwCalendar (org.bedework.calfacade.BwCalendar)2 BwEvent (org.bedework.calfacade.BwEvent)2 IcalMalformedException (org.bedework.icalendar.IcalMalformedException)2 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 QName (javax.xml.namespace.QName)1 TimeZone (net.fortuna.ical4j.model.TimeZone)1 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)1 SysIntfReader (org.bedework.caldav.server.SysIntfReader)1 BwAlarm (org.bedework.calfacade.BwAlarm)1 ResponseElement (org.bedework.calsvc.scheduling.hosts.Response.ResponseElement)1 IcalTranslator (org.bedework.icalendar.IcalTranslator)1 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)1