Search in sources :

Example 6 with CalendarWrapper

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

Example 7 with CalendarWrapper

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

Example 8 with CalendarWrapper

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

Aggregations

CalendarWrapper (org.bedework.calfacade.wrappers.CalendarWrapper)8 BwCalendar (org.bedework.calfacade.BwCalendar)7 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)4 ArrayList (java.util.ArrayList)1 AccessPrincipal (org.bedework.access.AccessPrincipal)1 Acl (org.bedework.access.Acl)1 CurrentAccess (org.bedework.access.Acl.CurrentAccess)1 PrivilegeSet (org.bedework.access.PrivilegeSet)1 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)1 BwCategory (org.bedework.calfacade.BwCategory)1 BwContact (org.bedework.calfacade.BwContact)1 BwDateTime (org.bedework.calfacade.BwDateTime)1 BwEvent (org.bedework.calfacade.BwEvent)1 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)1 BwEventProperty (org.bedework.calfacade.BwEventProperty)1 BwEventProxy (org.bedework.calfacade.BwEventProxy)1 BwLocation (org.bedework.calfacade.BwLocation)1 BwPrincipal (org.bedework.calfacade.BwPrincipal)1 BwRecurrenceInstance (org.bedework.calfacade.BwRecurrenceInstance)1 BwShareableContainedDbentity (org.bedework.calfacade.base.BwShareableContainedDbentity)1