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