use of org.bedework.caldav.server.CalDAVEvent in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getEvents.
@Override
public Collection<CalDAVEvent> getEvents(final CalDAVCollection col, final FilterBase filter, final List<String> retrieveList, final RetrievalMode recurRetrieval) throws WebdavException {
try {
/* Limit the results to just this collection by adding an ANDed filter */
final SimpleFilterParser sfp = getSvci().getFilterParser();
final String expr = "(colPath='" + SfpTokenizer.escapeQuotes(col.getPath()) + "')";
final ParseResult pr = sfp.parse(expr, true, null);
if (!pr.ok) {
throw new WebdavBadRequest("Failed to reference collection " + col.getPath() + ": message was " + pr.message);
}
final FilterBase f = FilterBase.addAndChild(filter, pr.filter);
final Collection<EventInfo> bwevs = // Collection
getSvci().getEventsHandler().getEvents(// Collection
null, f, // start
null, // end
null, RetrieveList.getRetrieveList(retrieveList), DeletedState.noDeleted, getRrm(recurRetrieval));
if (bwevs == null) {
return null;
}
final Collection<CalDAVEvent> evs = new ArrayList<>();
for (final EventInfo ei : bwevs) {
if (recurRetrieval != null) {
ei.getEvent().setForceUTC(recurRetrieval.getExpand() != null);
}
evs.add(new BwCalDAVEvent(this, ei));
}
return evs;
} catch (final CalFacadeAccessException cfae) {
throw new WebdavForbidden();
} catch (final CalFacadeException cfe) {
if (CalFacadeException.unknownProperty.equals(cfe.getMessage())) {
throw new WebdavBadRequest("Unknown property " + cfe.getExtra());
}
throw new WebdavException(cfe);
} catch (final WebdavException wde) {
throw wde;
} catch (final Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.caldav.server.CalDAVEvent in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method writeCalendar.
@Override
public String writeCalendar(final Collection<CalDAVEvent> evs, final MethodEmitted method, final XmlEmit xml, final Writer wtr, final String contentType) throws WebdavException {
try {
Collection<EventInfo> bwevs = new ArrayList<EventInfo>();
int meth = ScheduleMethods.methodTypeNone;
if (method == MethodEmitted.publish) {
meth = ScheduleMethods.methodTypePublish;
}
for (CalDAVEvent cde : evs) {
BwCalDAVEvent bcde = (BwCalDAVEvent) cde;
if (method == MethodEmitted.eventMethod) {
meth = getEvent(bcde).getScheduleMethod();
}
bwevs.add(bcde.getEvinfo());
}
String ctype = contentType;
if ((ctype == null) || (!ctype.equals("text/calendar") && !ctype.equals("application/calendar+json") && !ctype.equals(XcalTags.mimetype))) {
ctype = getDefaultContentType();
}
if (ctype.equals("text/calendar")) {
Calendar ical = trans.toIcal(bwevs, meth);
if (xml == null) {
IcalTranslator.writeCalendar(ical, wtr);
} else {
xml.cdataValue(toIcalString(ical, "text/calendar"));
}
} else if (ctype.equals("application/calendar+json")) {
if (xml == null) {
trans.writeJcal(bwevs, meth, wtr);
} else {
final StringWriter sw = new StringWriter();
trans.writeJcal(bwevs, meth, sw);
xml.cdataValue(sw.toString());
}
} else if (ctype.equals(XcalTags.mimetype)) {
XmlEmit x;
if (xml == null) {
x = new XmlEmit();
x.startEmit(wtr);
} else {
x = xml;
}
trans.writeXmlCalendar(bwevs, meth, x);
}
return ctype;
} catch (WebdavException we) {
throw we;
} catch (Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.caldav.server.CalDAVEvent in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method addEvent.
/* ====================================================================
* Events
* ==================================================================== */
/* (non-Javadoc)
* @see org.bedework.caldav.server.SysIntf#addEvent(org.bedework.caldav.server.CalDAVEvent, boolean, boolean)
*/
@Override
public Collection<CalDAVEvent> addEvent(final CalDAVEvent ev, final boolean noInvites, final boolean rollbackOnError) throws WebdavException {
try {
/* Is the event a scheduling object? */
final EventInfo ei = getEvinfo(ev);
final Collection<BwEventProxy> bwevs = getSvci().getEventsHandler().add(ei, noInvites, // scheduling - inbox
false, // autocreate
false, rollbackOnError).failedOverrides;
if (bwevs == null) {
return null;
}
final Collection<CalDAVEvent> evs = new ArrayList<CalDAVEvent>();
for (final BwEvent bwev : bwevs) {
evs.add(new BwCalDAVEvent(this, new EventInfo(bwev)));
}
return evs;
} catch (final CalFacadeAccessException cfae) {
throw new WebdavForbidden();
} catch (final CalFacadeException cfe) {
if (CalFacadeException.schedulingTooManyAttendees.equals(cfe.getDetailMessage())) {
throw new WebdavForbidden(CaldavTags.maxAttendeesPerInstance, ev.getParentPath() + "/" + cfe.getExtra());
}
if (CalFacadeException.invalidOverride.equals(cfe.getDetailMessage())) {
throw new WebdavForbidden(CaldavTags.validCalendarData, ev.getParentPath() + "/" + cfe.getExtra());
}
if (CalFacadeException.duplicateGuid.equals(cfe.getDetailMessage())) {
throw new WebdavForbidden(CaldavTags.noUidConflict, ev.getParentPath() + "/" + cfe.getExtra());
}
if (CalFacadeException.duplicateName.equals(cfe.getDetailMessage())) {
throw new WebdavForbidden(CaldavTags.noUidConflict, ev.getParentPath() + "/" + ev.getName());
}
throw new WebdavException(cfe);
} catch (Throwable t) {
throw new WebdavException(t);
}
}
Aggregations