Search in sources :

Example 1 with RangeIteratorAdapter

use of org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter in project jackrabbit by apache.

the class AuthorizableImpl method collectMembership.

private Iterator<Group> collectMembership(boolean includeIndirect) throws RepositoryException {
    Collection<String> groupNodeIds;
    MembershipCache cache = userManager.getMembershipCache();
    String nid = node.getIdentifier();
    final long t0 = System.nanoTime();
    boolean collect = false;
    if (node.getSession().hasPendingChanges()) {
        collect = true;
        // avoid retrieving outdated cache entries or filling the cache with
        // invalid data due to group-membership changes pending on the
        // current session.
        // this is mainly for backwards compatibility reasons (no cache present)
        // where transient changes (in non-autosave mode) were reflected to the
        // editing session (see JCR-2713)
        Session session = node.getSession();
        groupNodeIds = (includeIndirect) ? cache.collectMembership(nid, session) : cache.collectDeclaredMembership(nid, session);
    } else {
        //  retrieve cached membership. there are no pending changes.
        groupNodeIds = (includeIndirect) ? cache.getMemberOf(nid) : cache.getDeclaredMemberOf(nid);
    }
    final long t1 = System.nanoTime();
    Set<Group> groups = new HashSet<Group>(groupNodeIds.size());
    for (String identifier : groupNodeIds) {
        try {
            NodeImpl n = (NodeImpl) getSession().getNodeByIdentifier(identifier);
            Group group = userManager.createGroup(n);
            groups.add(group);
        } catch (RepositoryException e) {
        // group node doesn't exist or cannot be read -> ignore.
        }
    }
    final long t2 = System.nanoTime();
    if (log.isDebugEnabled()) {
        log.debug("Collected {} {} group ids for [{}] in {}us, loaded {} groups in {}us (collect={}, cachesize={})", new Object[] { groupNodeIds.size(), includeIndirect ? "all" : "declared", getID(), (t1 - t0) / 1000, groups.size(), (t2 - t1) / 1000, collect, cache.getSize() });
    }
    return new RangeIteratorAdapter(groups.iterator(), groups.size());
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) NodeImpl(org.apache.jackrabbit.core.NodeImpl) RangeIteratorAdapter(org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) HashSet(java.util.HashSet)

Example 2 with RangeIteratorAdapter

use of org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter in project jackrabbit-oak by apache.

the class AuthorizableImpl method getMembership.

/**
     * Retrieve the group membership of this authorizable.
     *
     * @param includeInherited Flag indicating whether the resulting iterator only
     * contains groups this authorizable is declared member of or if inherited
     * group membership is respected.
     *
     * @return Iterator of groups this authorizable is (declared) member of.
     * @throws RepositoryException If an error occurs.
     */
@Nonnull
private Iterator<Group> getMembership(boolean includeInherited) throws RepositoryException {
    if (isEveryone()) {
        return Collections.<Group>emptySet().iterator();
    }
    MembershipProvider mMgr = getMembershipProvider();
    Iterator<String> oakPaths = mMgr.getMembership(getTree(), includeInherited);
    Authorizable everyoneGroup = userManager.getAuthorizable(EveryonePrincipal.getInstance());
    if (everyoneGroup instanceof GroupImpl) {
        String everyonePath = ((GroupImpl) everyoneGroup).getTree().getPath();
        oakPaths = Iterators.concat(oakPaths, ImmutableSet.of(everyonePath).iterator());
    }
    if (oakPaths.hasNext()) {
        AuthorizableIterator groups = AuthorizableIterator.create(oakPaths, userManager, AuthorizableType.GROUP);
        return new RangeIteratorAdapter(groups, groups.getSize());
    } else {
        return RangeIteratorAdapter.EMPTY;
    }
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RangeIteratorAdapter(org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter) Nonnull(javax.annotation.Nonnull)

Example 3 with RangeIteratorAdapter

use of org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter in project sling by apache.

the class MockSession method listChildren.

RangeIterator listChildren(final String parentPath, final ItemFilter filter) throws RepositoryException {
    List<Item> children = new ArrayList<Item>();
    //remove trailing slash or make root path / empty string
    final String path = parentPath.replaceFirst("/$", "");
    // build regex pattern for all child paths of parent
    Pattern pattern = Pattern.compile("^" + Pattern.quote(path) + "/[^/]+$");
    // collect child resources
    for (ItemData item : this.items.values()) {
        if (pattern.matcher(item.getPath()).matches() && (filter == null || filter.accept(item))) {
            children.add(item.getItem(this));
        }
    }
    return new RangeIteratorAdapter(children.iterator(), children.size());
}
Also used : Item(javax.jcr.Item) Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) RangeIteratorAdapter(org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter)

Example 4 with RangeIteratorAdapter

use of org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter in project jackrabbit by apache.

the class VersionHistoryImpl method getAllVersions.

/**
     * @see VersionHistory#getAllVersions()
     */
public VersionIterator getAllVersions() throws RepositoryException {
    checkStatus();
    refreshEntry(vhEntry);
    Iterator<NodeEntry> childIter = vhEntry.getNodeEntries();
    List<NodeEntry> versionEntries = new ArrayList<NodeEntry>();
    // all child-nodes except from jcr:versionLabels point to Versions.
    while (childIter.hasNext()) {
        NodeEntry entry = childIter.next();
        if (!NameConstants.JCR_VERSIONLABELS.equals(entry.getName())) {
            versionEntries.add(entry);
        }
    }
    return new LazyItemIterator(getItemManager(), new RangeIteratorAdapter(versionEntries));
}
Also used : NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) ArrayList(java.util.ArrayList) LazyItemIterator(org.apache.jackrabbit.jcr2spi.LazyItemIterator) RangeIteratorAdapter(org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter)

Aggregations

RangeIteratorAdapter (org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 Pattern (java.util.regex.Pattern)1 Nonnull (javax.annotation.Nonnull)1 Item (javax.jcr.Item)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)1 Group (org.apache.jackrabbit.api.security.user.Group)1 NodeImpl (org.apache.jackrabbit.core.NodeImpl)1 LazyItemIterator (org.apache.jackrabbit.jcr2spi.LazyItemIterator)1 NodeEntry (org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)1