use of org.bedework.calfacade.wrappers.CalendarWrapper 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.wrappers.CalendarWrapper in project bw-calendar-engine by Bedework.
the class CoreCalendars method getCalendar.
@Override
public BwCalendar getCalendar(final String path, final int desiredAccess, final boolean alwaysReturnResult) throws CalFacadeException {
BwCalendar col = getCollection(path);
if ((col != null) && (col.getCalType() == BwCalendar.calTypeAlias) && (!col.getOwnerHref().equals(col.getCreatorHref())) && ("/principals/users/public-user".equals(col.getOwnerHref()))) {
col.setOwnerHref(col.getCreatorHref());
}
col = checkAccess((CalendarWrapper) col, desiredAccess, alwaysReturnResult);
return col;
}
use of org.bedework.calfacade.wrappers.CalendarWrapper in project bw-calendar-engine by Bedework.
the class CoreCalendars method getChildren.
/* No access checks performed */
@SuppressWarnings("unchecked")
private Collection<BwCalendar> getChildren(final BwCalendar col) throws CalFacadeException {
final List<BwCalendar> ch;
final List<BwCalendar> wch = new ArrayList<>();
if (col == null) {
return wch;
}
if (sessionless) {
/*
Maybe we should just fetch them. We've probably not seen them and
we're just working our way down a tree. The 2 phase might be slower.
*/
ch = dao.getChildCollections(col.getPath());
} else {
/* Fetch the lastmod and paths of all children then fetch those we haven't
* got in the cache.
*/
final List<CoreCalendarsDAO.LastModAndPath> lmps = dao.getChildLastModsAndPaths(col.getPath());
final List<String> paths = new ArrayList<>();
if (Util.isEmpty(lmps)) {
return wch;
}
for (final CoreCalendarsDAO.LastModAndPath lmp : lmps) {
final String token = BwLastMod.getTagValue(lmp.timestamp, lmp.sequence);
final BwCalendar c = colCache.get(lmp.path, token);
if ((c != null) && !c.getTombstoned()) {
wch.add(c);
continue;
}
paths.add(lmp.path);
}
if (paths.isEmpty()) {
return wch;
}
/* paths lists those we couldn't find in the cache. */
ch = dao.getCollections(paths);
}
if (Util.isEmpty(ch)) {
return wch;
}
for (final BwCalendar c : ch) {
final CalendarWrapper wc = wrap(c);
colCache.put(wc);
wch.add(wc);
}
return wch;
}
Aggregations