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) {
}
}
}
}
Aggregations