use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method updateEvent.
@Override
public void updateEvent(final CalDAVEvent event) throws WebdavException {
try {
EventInfo ei = getEvinfo(event);
getSvci().getEventsHandler().update(ei, false);
} catch (CalFacadeAccessException cfae) {
throw new WebdavForbidden();
} catch (CalFacadeForbidden cff) {
throw new WebdavForbidden(cff.getQname(), cff.getMessage());
} catch (CalFacadeException cfe) {
if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
throw new WebdavBadRequest("Duplicate-guid");
}
throw new WebdavException(cfe);
} catch (Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.calfacade.svc.EventInfo 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.calfacade.svc.EventInfo 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.calfacade.svc.EventInfo 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);
}
}
use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getFreeBusy.
/* (non-Javadoc)
* @see org.bedework.caldav.server.sysinterface.SysIntf#getFreeBusy(org.bedework.caldav.server.CalDAVCollection, int, org.bedework.caldav.util.TimeRange)
*/
@Override
public CalDAVEvent getFreeBusy(final CalDAVCollection col, final int depth, final TimeRange timeRange) throws WebdavException {
try {
BwCalendar bwCol = unwrap(col);
int calType = bwCol.getCalType();
if (!bwCol.getCollectionInfo().allowFreeBusy) {
throw new WebdavForbidden(WebdavTags.supportedReport);
}
Collection<BwCalendar> cals = new ArrayList<BwCalendar>();
if (calType == BwCalendar.calTypeCalendarCollection) {
cals.add(bwCol);
} else if (depth == 0) {
/* Cannot return anything */
} else {
for (BwCalendar ch : getSvci().getCalendarsHandler().getChildren(bwCol)) {
// For depth 1 we only add calendar collections
if ((depth > 1) || (ch.getCalType() == BwCalendar.calTypeCalendarCollection)) {
cals.add(ch);
}
}
}
AccessPrincipal owner = col.getOwner();
String orgUri;
if (owner instanceof BwPrincipal) {
orgUri = getSvci().getDirectories().principalToCaladdr((BwPrincipal) owner);
} else {
BwPrincipal p = BwPrincipal.makeUserPrincipal();
p.setAccount(owner.getAccount());
orgUri = getSvci().getDirectories().principalToCaladdr(p);
}
BwOrganizer org = new BwOrganizer();
org.setOrganizerUri(orgUri);
BwEvent fb;
if (cals.isEmpty()) {
// Return an empty object
fb = new BwEventObj();
fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
fb.setDtstart(getBwDt(timeRange.getStart()));
fb.setDtend(getBwDt(timeRange.getEnd()));
} else {
fb = getSvci().getScheduler().getFreeBusy(cals, (BwPrincipal) currentPrincipal, getBwDt(timeRange.getStart()), getBwDt(timeRange.getEnd()), org, // uid
null, null);
}
EventInfo ei = new EventInfo(fb);
return new BwCalDAVEvent(this, ei);
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
} catch (WebdavException wde) {
throw wde;
} catch (Throwable t) {
throw new WebdavException(t);
}
}
Aggregations