Search in sources :

Example 41 with BwCalendar

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));
    }
}
Also used : BasicSystemProperties(org.bedework.calfacade.configs.BasicSystemProperties) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 42 with BwCalendar

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;
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 43 with BwCalendar

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);
    }
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar)

Example 44 with BwCalendar

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);
        }
    }
}
Also used : HibSession(org.bedework.calcorei.HibSession) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 45 with BwCalendar

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);
}
Also used : FixNamesEntity(org.bedework.calfacade.base.FixNamesEntity) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwCalendar (org.bedework.calfacade.BwCalendar)134 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)46 EventInfo (org.bedework.calfacade.svc.EventInfo)23 BwEvent (org.bedework.calfacade.BwEvent)19 ArrayList (java.util.ArrayList)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)18 BwPrincipal (org.bedework.calfacade.BwPrincipal)15 TreeSet (java.util.TreeSet)10 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)10 BwCategory (org.bedework.calfacade.BwCategory)10 BwResource (org.bedework.calfacade.BwResource)10 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)9 FilterBase (org.bedework.caldav.util.filter.FilterBase)8 BwPreferences (org.bedework.calfacade.svc.BwPreferences)8 BwEventProxy (org.bedework.calfacade.BwEventProxy)7 CalendarWrapper (org.bedework.calfacade.wrappers.CalendarWrapper)7 CurrentAccess (org.bedework.access.Acl.CurrentAccess)6 CalendarsI (org.bedework.calsvci.CalendarsI)6 Acl (org.bedework.access.Acl)5 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)5