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());
}
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;
}
}
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());
}
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));
}
Aggregations