use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendars method checkNewCalendarName.
private void checkNewCalendarName(final String name, final boolean special, final BwCalendar parent) throws CalFacadeException {
// XXX This should be accessible to all implementations.
if (!special) {
final BasicSystemProperties sys = getSyspars();
if (name.equals(sys.getUserInbox())) {
throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
}
if (name.equals(sys.getUserOutbox())) {
throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
}
if (name.equals(sys.getDefaultNotificationsName())) {
throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
}
}
/* Ensure the name is not-null and contains no invalid characters
*/
if ((name == null) || name.contains("/")) {
throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
}
/* Ensure the new path is unique */
String path;
if (parent == null) {
path = "";
} else {
path = parent.getPath();
}
path = Util.buildPath(colPathEndsWithSlash, path, "/", name);
final BwCalendar col = dao.getCollection(path);
if (col != null) {
if (!col.getTombstoned()) {
throw new CalFacadeException(CalFacadeException.duplicateCalendar);
}
dao.deleteCalendar(unwrap(col));
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendars method deleteCalendar.
@Override
public boolean deleteCalendar(BwCalendar val, final boolean reallyDelete) throws CalFacadeException {
colCache.flush();
ac.checkAccess(val, privUnbind, false);
final String parentPath = val.getColPath();
if (parentPath == null) {
throw new CalFacadeException(CalFacadeException.cannotDeleteCalendarRoot);
}
/* Ensure the parent exists and we have writeContent on the parent.
*/
final BwCalendar parent = getCalendar(parentPath, privWriteContent, false);
if (parent == null) {
throw new CalFacadeException(CalFacadeException.collectionNotFound);
}
val = getCalendar(val.getPath(), privUnbind, false);
if (val == null) {
throw new CalFacadeException(CalFacadeException.collectionNotFound);
}
if (!isEmpty(val)) {
throw new CalFacadeException(CalFacadeException.collectionNotEmpty);
}
/* See if this is a no-op after all. We do this now to ensure the caller
* really does have access
*/
if (!reallyDelete && val.getTombstoned()) {
// Nothing to do
return true;
}
final BwCalendar unwrapped = unwrap(val);
final String path = val.getPath();
/* Ensure it's not in any (auth)user preferences */
dao.removeCalendarFromAuthPrefs(unwrapped);
/* Ensure no tombstoned events or childen */
dao.removeTombstoned(fixPath(path));
if (reallyDelete) {
dao.deleteCalendar(unwrapped);
} else {
tombstoneEntity(unwrapped);
unwrapped.tombstone();
dao.updateCollection(unwrapped);
touchCalendar(unwrapped);
}
colCache.remove(path);
touchCalendar(parent);
notify(SysEvent.SysCode.COLLECTION_DELETED, val);
getIndexer(val).unindexEntity(path);
return true;
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendars method updatePaths.
private void updatePaths(BwCalendar val, final BwCalendar newParent) throws CalFacadeException {
final Collection<BwCalendar> children = getChildren(val);
final String oldHref = val.getPath();
val = unwrap(val);
final String ppath = newParent.getPath();
val.setPath(Util.buildPath(colPathEndsWithSlash, ppath, "/", val.getName()));
val.setColPath(ppath);
val.getLastmod().setPath(val.getPath());
val.updateLastmod(getCurrentTimestamp());
notifyMove(SysEvent.SysCode.COLLECTION_MOVED, oldHref, val);
for (final BwCalendar ch : children) {
updatePaths(ch, val);
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class CoreCalendarsDAO method removeTombstoned.
protected void removeTombstoned(final String path) throws CalFacadeException {
final HibSession sess = getSess();
sess.createQuery(removeTombstonedCollectionEventsQuery);
sess.setString("path", path);
sess.executeUpdate();
sess.createQuery(getTombstonedCollectionsQuery);
sess.setString("path", path);
sess.setString("tsfilter", BwCalendar.tombstonedFilter);
@SuppressWarnings("unchecked") final List<BwCalendar> cols = sess.getList();
if (!Util.isEmpty(cols)) {
for (final BwCalendar col : cols) {
sess.delete(col);
}
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class DocBuilder method getHref.
/* ===================================================================
* package private methods
* =================================================================== */
String getHref(final BwShareableContainedDbentity val) throws CalFacadeException {
if (val instanceof BwEvent) {
return ((BwEvent) val).getHref();
}
if (val instanceof BwCalendar) {
return ((BwCalendar) val).getPath();
}
if (val instanceof FixNamesEntity) {
final FixNamesEntity ent = (FixNamesEntity) val;
ent.fixNames(basicSysprops, principal);
return ent.getHref();
}
throw new CalFacadeException("Unhandled class " + val);
}
Aggregations