use of org.bedework.calfacade.BwCalendar 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.BwCalendar 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) {
}
}
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendars method moveCalendar.
@Override
public void moveCalendar(BwCalendar val, final BwCalendar newParent) throws CalFacadeException {
colCache.flush();
/* check access - privbind on new parent privunbind on val?
*/
ac.checkAccess(val, privUnbind, false);
ac.checkAccess(newParent, privBind, false);
if (newParent.getCalType() != BwCalendar.calTypeFolder) {
throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
}
val = unwrap(val);
val.setColPath(newParent.getPath());
val.updateLastmod(getCurrentTimestamp());
final BwCalendar tombstoned = val.makeTombstoneCopy();
tombstoned.tombstone();
dao.save(tombstoned);
/* This triggers off a cascade of updates down the tree as we are storing the
* path in the calendar objects. This may be preferable to calculating the
* path at every access
*/
updatePaths(val, newParent);
/* Remove any tombstoned collection with the same name */
dao.removeTombstonedVersion(val);
// Flush it again
colCache.flush();
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendars method addNewCalendars.
@Override
public void addNewCalendars(final BwPrincipal user) throws CalFacadeException {
/* Add a user collection to the userCalendarRoot and then a default
calendar collection. */
String path = userCalendarRootPath;
final BwCalendar userrootcal = dao.getCollection(path);
if (userrootcal == null) {
throw new CalFacadeException("No user root at " + path);
}
BwCalendar parentCal = userrootcal;
BwCalendar usercal = null;
/* We may have a principal e.g. /principals/resources/vcc311
* All except the last may exist already.
*/
final String[] upath = user.getAccountSplit();
for (int i = 0; i < upath.length; i++) {
final String pathSeg = upath[i];
if ((pathSeg == null) || (pathSeg.length() == 0)) {
// Leading or double slash - skip it
continue;
}
path = Util.buildPath(colPathEndsWithSlash, path, "/", pathSeg);
usercal = dao.getCollection(path);
if (i == (upath.length - 1)) {
if (usercal != null) {
throw new CalFacadeException("User calendar already exists at " + path);
}
/* Create a folder for the user */
usercal = new BwCalendar();
usercal.setName(pathSeg);
usercal.setCreatorHref(user.getPrincipalRef());
usercal.setOwnerHref(user.getPrincipalRef());
usercal.setPublick(false);
usercal.setPath(path);
usercal.setColPath(parentCal.getPath());
dao.saveCollection(usercal);
notify(SysEvent.SysCode.COLLECTION_ADDED, usercal);
} else if (usercal == null) {
/* Create a new system owned folder for part of the principal
* hierarchy
*/
usercal = new BwCalendar();
usercal.setName(pathSeg);
usercal.setCreatorHref(userrootcal.getCreatorHref());
usercal.setOwnerHref(userrootcal.getOwnerHref());
usercal.setPublick(false);
usercal.setPath(path);
usercal.setColPath(parentCal.getPath());
dao.saveCollection(usercal);
notify(SysEvent.SysCode.COLLECTION_ADDED, usercal);
}
parentCal = usercal;
}
if (usercal == null) {
throw new CalFacadeException("Invalid user " + user);
}
/* Create a default calendar */
final BwCalendar cal = new BwCalendar();
cal.setName(getSyspars().getUserDefaultCalendar());
cal.setCreatorHref(user.getPrincipalRef());
cal.setOwnerHref(user.getPrincipalRef());
cal.setPublick(false);
cal.setPath(Util.buildPath(colPathEndsWithSlash, path, "/", cal.getName()));
cal.setColPath(usercal.getPath());
cal.setCalType(BwCalendar.calTypeCalendarCollection);
cal.setAffectsFreeBusy(true);
dao.saveCollection(cal);
notify(SysEvent.SysCode.COLLECTION_ADDED, cal);
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendars method getCollection.
@Override
public BwCalendar getCollection(final String path) throws CalFacadeException {
if (path == null) {
return null;
}
BwCalendar col = colCache.get(path);
if (col != null) {
return col;
}
col = dao.getCollection(path);
if (col == null) {
if (path.equals("/")) {
// Fake a root collection
col = new BwCalendar();
col.setPath("/");
// Use this for owner/creator
final BwCalendar userRoot = getCollection(userCalendarRootPath);
if (userRoot == null) {
return null;
}
col.setOwnerHref(userRoot.getOwnerHref());
col.setCreatorHref(userRoot.getCreatorHref());
col.setAccess(Access.getDefaultPublicAccess());
} else if (!getPrincipal().getUnauthenticated()) {
/* Didn't find it. Is this a special collection we should create,
Only try this if authenticated.
*/
final GetSpecialCalendarResult gscr = getIfSpecial(getPrincipal(), path);
if (gscr == null) {
return null;
}
col = gscr.cal;
} else {
return null;
}
}
final CalendarWrapper wcol = wrap(col);
if (wcol != null) {
colCache.put(wcol);
}
return wcol;
}
Aggregations