use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method schedule.
@Override
public Collection<SchedRecipientResult> schedule(final CalDAVEvent ev) throws WebdavException {
try {
ScheduleResult sr;
BwEvent event = getEvent(ev);
event.setOwnerHref(currentPrincipal.getPrincipalRef());
if (Icalendar.itipReplyMethodType(event.getScheduleMethod())) {
sr = getSvci().getScheduler().scheduleResponse(getEvinfo(ev));
} else {
sr = getSvci().getScheduler().schedule(getEvinfo(ev), null, null, // iSchedule
true);
}
return checkStatus(sr);
} catch (WebdavException we) {
throw we;
} catch (CalFacadeAccessException cfae) {
throw new WebdavForbidden();
} 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.BwEvent 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.BwEvent 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);
}
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class BwUpdates method findSubComponent.
private Component findSubComponent(final EventInfo ei, final BaseComponentType bc) throws WebdavException {
try {
BwEvent ev = ei.getEvent();
int etype = ev.getEntityType();
if (bc instanceof ValarmType) {
if ((etype != IcalDefs.entityTypeEvent) || (etype != IcalDefs.entityTypeTodo)) {
return null;
}
/* Look for the alarm - we match on the whole component */
BwAlarm matched = null;
BwAlarm pattern = Xalarms.toBwAlarm((ValarmType) bc, false);
if ((pattern == null) || (ev.getNumAlarms() == 0)) {
return null;
}
for (BwAlarm al : ev.getAlarms()) {
if (al.matches(pattern)) {
if (matched != null) {
// Multiple matches - bad
return null;
}
matched = al;
}
}
return new PropertyUpdateComponent(ei, matched);
}
return null;
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.calfacade.BwEvent in project bw-calendar-engine by Bedework.
the class BwUpdates method addSubComp.
private UpdateResult addSubComp(final EventInfo ei, final ComponentReferenceType sel) throws WebdavException {
try {
BwEvent ev = ei.getEvent();
int etype = ev.getEntityType();
BaseComponentType bc = sel.getBaseComponent().getValue();
if (bc instanceof ValarmType) {
if ((etype != IcalDefs.entityTypeEvent) || (etype != IcalDefs.entityTypeTodo)) {
return new UpdateResult("Invalid entity type for alarm add");
}
BwAlarm al = Xalarms.toBwAlarm((ValarmType) bc, false);
if (al == null) {
return new UpdateResult("Invalid alarm for add");
}
ev.addAlarm(al);
return UpdateResult.getOkResult();
}
return new UpdateResult("Invalid entity type for add");
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
Aggregations