use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendars method resolveAlias.
/*
indexer != null => Use ES for the searches
*/
private BwCalendar resolveAlias(final BwCalendar val, final boolean resolveSubAlias, final boolean freeBusy, final ArrayList<String> pathElements, final BwIndexer indexer) throws CalFacadeException {
if ((val == null) || !val.getInternalAlias()) {
return val;
}
final BwCalendar c = val.getAliasTarget();
if (c != null) {
if (!resolveSubAlias) {
return c;
}
final BwCalendar res = resolveAlias(c, true, freeBusy, pathElements, indexer);
res.setAliasOrigin(val);
return res;
}
if (val.getDisabled()) {
return null;
}
int desiredAccess = privRead;
if (freeBusy) {
desiredAccess = privReadFreeBusy;
}
final String path = val.getInternalAliasPath();
if (pathElements.contains(path)) {
disableAlias(val);
return null;
}
pathElements.add(path);
// if (debug) {
// trace("Search for calendar \"" + path + "\"");
// }
BwCalendar col;
try {
if (indexer != null) {
col = getCollectionIdx(indexer, path, desiredAccess, false);
} else {
col = getCalendar(path, desiredAccess, false);
}
} catch (final CalFacadeAccessException cfae) {
col = null;
}
if (col == null) {
/* Assume deleted - flag in the subscription if it's ours or a temp.
*/
if ((val.getId() == CalFacadeDefs.unsavedItemKey) || val.getOwnerHref().equals(getPrincipal().getPrincipalRef())) {
disableAlias(val);
}
return null;
}
val.setAliasTarget(col);
if (!resolveSubAlias) {
col.setAliasOrigin(val);
return col;
}
final BwCalendar res = resolveAlias(col, true, freeBusy, pathElements, indexer);
res.setAliasOrigin(val);
return res;
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendars method getCollectionIdx.
@Override
public BwCalendar getCollectionIdx(final BwIndexer indexer, final String path, final int desiredAccess, final boolean alwaysReturnResult) throws CalFacadeException {
BwCalendar col = colCache.get(path);
if (col != null) {
return col;
}
col = indexer.fetchCol(path, PropertyIndex.PropertyInfoIndex.HREF);
if (col != null) {
restoreCategories(col);
}
return col;
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendars method getSpecialCalendar.
private GetSpecialCalendarResult getSpecialCalendar(final BwPrincipal owner, final int calType, final boolean create, final boolean tryFetch, final int access) throws CalFacadeException {
final String name;
final BasicSystemProperties sys = getSyspars();
int ctype = calType;
if (calType == BwCalendar.calTypeInbox) {
name = sys.getUserInbox();
} else if (calType == BwCalendar.calTypePendingInbox) {
// sys.getUserInbox();
name = ".pendingInbox";
} else if (calType == BwCalendar.calTypeOutbox) {
name = sys.getUserOutbox();
} else if (calType == BwCalendar.calTypeNotifications) {
name = sys.getDefaultNotificationsName();
} else if (calType == BwCalendar.calTypeEventList) {
name = sys.getDefaultReferencesName();
} else if (calType == BwCalendar.calTypePoll) {
name = sys.getUserDefaultPollsCalendar();
} else if (calType == BwCalendar.calTypeAttachments) {
name = sys.getDefaultAttachmentsName();
} else if (calType == BwCalendar.calTypeCalendarCollection) {
name = sys.getUserDefaultCalendar();
} else if (calType == BwCalendar.calTypeTasks) {
name = sys.getUserDefaultTasksCalendar();
ctype = BwCalendar.calTypeTasks;
} else {
// Not supported
return null;
}
final List<String> entityTypes = BwCalendar.entityTypes.get(calType);
final String pathTo = cb.getPrincipalInfo().getCalendarHomePath(owner);
final GetSpecialCalendarResult gscr = new GetSpecialCalendarResult();
if (!dao.collectionExists(pathTo)) {
gscr.noUserHome = true;
return gscr;
}
if (tryFetch) {
gscr.cal = getCalendar(Util.buildPath(colPathEndsWithSlash, pathTo, "/", name), access, false);
if ((gscr.cal != null) || !create) {
return gscr;
}
}
/*
BwCalendar parent = getCalendar(pathTo, privRead);
if (parent == null) {
throw new CalFacadeException("org.bedework.calcore.calendars.unabletocreate");
}
*/
gscr.cal = new BwCalendar();
gscr.cal.setName(name);
gscr.cal.setCreatorHref(owner.getPrincipalRef());
gscr.cal.setOwnerHref(owner.getPrincipalRef());
gscr.cal.setCalType(ctype);
if (entityTypes != null) {
gscr.cal.setSupportedComponents(entityTypes);
}
/* I think we're allowing privNone here because we don't mind if the
* calendar gets created even if the caller has no access.
*/
gscr.cal = add(gscr.cal, pathTo, true, access);
gscr.created = true;
return gscr;
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendars method add.
private BwCalendar add(final BwCalendar val, final String parentPath, final boolean special, final int access) throws CalFacadeException {
BwCalendar parent = null;
final String newPath;
if ("/".equals(parentPath)) {
// creating a new root
newPath = Util.buildPath(colPathEndsWithSlash, "/", val.getName());
} else {
parent = getCalendar(parentPath, access, false);
if (parent == null) {
throw new CalFacadeException(CalFacadeException.collectionNotFound, parentPath);
}
/* Is the parent a calendar collection or a resource folder?
*/
if (parent.getCalendarCollection() || (parent.getCalType() == BwCalendar.calTypeResourceCollection)) {
if (val.getAlias() || ((val.getCalType() != BwCalendar.calTypeFolder) && (val.getCalType() != BwCalendar.calTypeResourceCollection))) {
throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
}
if (val.getCalType() == BwCalendar.calTypeFolder) {
val.setCalType(BwCalendar.calTypeResourceCollection);
}
} else if (parent.getCalType() != BwCalendar.calTypeFolder) {
throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
}
newPath = Util.buildPath(colPathEndsWithSlash, parent.getPath(), "/", val.getName());
}
/* Ensure the name isn't reserved and is unique */
checkNewCalendarName(val.getName(), special, parent);
val.setPath(newPath);
if (val.getOwnerHref() == null) {
val.setOwnerHref(getPrincipal().getPrincipalRef());
}
val.updateLastmod(getCurrentTimestamp());
if (parent != null) {
val.setColPath(parent.getPath());
val.setPublick(parent.getPublick());
}
/* Remove any tombstoned collection with the same name */
dao.removeTombstonedVersion(val);
// No cascades - explicitly save child
dao.saveCollection(unwrap(val));
if (parent != null) {
touchCalendar(parent);
}
notify(SysEvent.SysCode.COLLECTION_ADDED, val);
final CalendarWrapper wcol = wrap(val);
colCache.put(wcol);
return checkAccess(wcol, privAny, true);
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendars method renameCalendar.
@Override
public void renameCalendar(BwCalendar val, final String newName) throws CalFacadeException {
colCache.flush();
/* update will check access
*/
final BwCalendar parent = dao.getCollection(val.getColPath());
/* Ensure the name isn't reserved and the path is unique */
checkNewCalendarName(newName, false, parent);
val = unwrap(val);
val.setName(newName);
val.updateLastmod(getCurrentTimestamp());
/* 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, parent);
/* Remove any tombstoned collection with the same name */
dao.removeTombstonedVersion(val);
// Flush it again
colCache.flush();
}
Aggregations