use of org.bedework.webdav.servlet.shared.WebdavException 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.webdav.servlet.shared.WebdavException 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.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getSvci.
/**
* @return CalSvcI
* @throws WebdavException
*/
private CalSvcI getSvci() throws WebdavException {
if (!svci.isOpen()) {
try {
svci.open();
svci.beginTransaction();
} catch (Throwable t) {
throw new WebdavException(t);
}
}
return svci;
}
use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getSvci.
private CalSvcI getSvci(final String account, final String runAs, final boolean service, final boolean publicAdmin, final String clientId, final boolean allowCreateEprops) throws WebdavException {
try {
/* account is what we authenticated with.
* user, if non-null, is the user calendar we want to access.
*/
final boolean possibleSuperUser = // allow SuperUser
"root".equals(account) || "admin".equals(account);
String runAsUser = null;
String clientIdent = null;
if (possibleSuperUser) {
runAsUser = runAs;
clientIdent = clientId;
}
final CalSvcIPars pars = CalSvcIPars.getCaldavPars("bwcaldav", account, runAsUser, clientIdent, // allow SuperUser
possibleSuperUser, service, publicAdmin, allowCreateEprops);
svci = new CalSvcFactoryDefault().getSvc(pars);
svci.open();
svci.beginTransaction();
trans = new IcalTranslator(svci.getIcalCallback());
} catch (Throwable t) {
throw new WebdavException(t);
}
return svci;
}
use of org.bedework.webdav.servlet.shared.WebdavException 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