use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class UserManagerImpl method findAuthorizables.
/**
* @see UserManager#findAuthorizables(String,String, int)
*/
public Iterator<Authorizable> findAuthorizables(String relPath, String value, int searchType) throws RepositoryException {
if (searchType < SEARCH_TYPE_USER || searchType > SEARCH_TYPE_AUTHORIZABLE) {
throw new IllegalArgumentException("Invalid search type " + searchType);
}
Path path = session.getQPath(relPath);
NodeIterator nodes;
if (relPath.indexOf('/') == -1) {
// search for properties somewhere below an authorizable node
nodes = authResolver.findNodes(path, value, searchType, true, Long.MAX_VALUE);
} else {
path = path.getNormalizedPath();
if (path.getLength() == 1) {
// only search below the authorizable node
Name ntName;
switch(searchType) {
case SEARCH_TYPE_GROUP:
ntName = NT_REP_GROUP;
break;
case SEARCH_TYPE_USER:
ntName = NT_REP_USER;
break;
default:
ntName = NT_REP_AUTHORIZABLE;
}
nodes = authResolver.findNodes(path.getName(), value, ntName, true);
} else {
// search below authorizable nodes but take some path constraints
// into account.
nodes = authResolver.findNodes(path, value, searchType, true, Long.MAX_VALUE);
}
}
return new AuthorizableIterator(nodes);
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class ConcurrentQueriesWithUpdatesTest method testQueriesWithUpdates.
public void testQueriesWithUpdates() throws Exception {
final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
final AtomicBoolean running = new AtomicBoolean(true);
// track executed queries and do updates at most at the given rate
final BlockingQueue<Object> queryExecuted = new LinkedBlockingQueue<Object>();
Thread queries = new Thread(new Runnable() {
public void run() {
try {
runTask(new Task() {
public void execute(Session session, Node test) throws RepositoryException {
QueryManager qm = session.getWorkspace().getQueryManager();
while (running.get()) {
Query q = qm.createQuery(testPath + "//element(*, nt:unstructured) order by @jcr:score descending", Query.XPATH);
NodeIterator nodes = q.execute().getNodes();
assertEquals("wrong result set size", numNodes, nodes.getSize());
queryExecuted.offer(new Object());
}
}
}, 5, testRootNode.getPath());
} catch (RepositoryException e) {
exceptions.add(e);
}
}
});
queries.start();
Thread update = new Thread(new Runnable() {
public void run() {
try {
runTask(new Task() {
public void execute(Session session, Node test) throws RepositoryException {
Random rand = new Random();
QueryManager qm = session.getWorkspace().getQueryManager();
for (int i = 0; i < NUM_UPDATES; i++) {
try {
// wait at most 10 seconds
queryExecuted.poll(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// ignore
}
Query q = qm.createQuery(testPath + "//node" + rand.nextInt(numNodes) + " order by @jcr:score descending", Query.XPATH);
NodeIterator nodes = q.execute().getNodes();
if (nodes.hasNext()) {
Node n = nodes.nextNode();
n.setProperty("foo", "bar");
session.save();
}
}
}
}, 1, testRootNode.getPath());
} catch (RepositoryException e) {
exceptions.add(e);
}
}
});
update.start();
update.join();
running.set(false);
queries.join();
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class AxisQueryTest method testExecuteQueries.
public void testExecuteQueries() throws RepositoryException {
Node testLocation = superuser.getRootNode().getNode(relTestLocation);
long end = System.currentTimeMillis() + 1000 * RUN_NUM_SECONDS;
while (end > System.currentTimeMillis()) {
StringBuffer statement = new StringBuffer(relTestLocation);
StringBuffer regexp = new StringBuffer(absTestLocation);
// at least one step
int numSteps = rand.nextInt(NUM_LEVELS) + 1;
while (numSteps-- > 0) {
String axis = getRandomAxis();
String name = getRandomName();
statement.append(axis).append(name);
if (axis.equals("//")) {
regexp.append("/(.*/)?");
} else {
regexp.append("/");
}
if (name.equals("*")) {
regexp.append("[^/]*");
} else {
regexp.append(name);
}
}
long time = System.currentTimeMillis();
NodeIterator nodes = executeQuery(statement.toString()).getNodes();
nodes.hasNext();
time = System.currentTimeMillis() - time;
log.print(statement + "\t" + nodes.getSize() + "\t" + time);
if (CHECK_RESULT) {
Set paths = new HashSet();
time = System.currentTimeMillis();
traversalEvaluate(testLocation, Pattern.compile(regexp.toString()), paths);
time = System.currentTimeMillis() - time;
log.println("\t" + time);
assertEquals("wrong number of results", paths.size(), nodes.getSize());
while (nodes.hasNext()) {
String path = nodes.nextNode().getPath();
assertTrue(path + " is not part of the result set", paths.contains(path));
}
} else {
log.println();
}
log.flush();
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class AcReadWriteTest method testReadAccessControl.
public void testReadAccessControl() throws NotExecutableException, RepositoryException {
/* precondition:
testuser must have READ-only permission on test-node and below
*/
checkReadOnly(path);
/* give 'testUser' jcr:readAccessControl privileges at subtree below
path excluding the node at path itself. */
Privilege[] privileges = privilegesFromNames(new String[] { Privilege.JCR_READ_ACCESS_CONTROL });
Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));
restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/" + nodeName2));
JackrabbitAccessControlList tmpl = givePrivileges(path, privileges, restrictions);
/*
testuser must not be allowed to read AC content at the target node;
however, retrieving potential AC content at 'childPath' is granted.
*/
Session testSession = getTestSession();
AccessControlManager testAcMgr = getTestACManager();
assertFalse(testAcMgr.hasPrivileges(path, privileges));
try {
testAcMgr.getPolicies(path);
fail("AccessDeniedException expected");
} catch (AccessDeniedException e) {
// success.
}
assertTrue(testAcMgr.hasPrivileges(childNPath, privileges));
assertEquals(0, testAcMgr.getPolicies(childNPath).length);
/* similarly reading the corresponding AC items at 'path' must be forbidden */
String aclNodePath = null;
Node n = superuser.getNode(path);
for (NodeIterator itr = n.getNodes(); itr.hasNext(); ) {
Node child = itr.nextNode();
if (child.isNodeType("rep:Policy")) {
aclNodePath = child.getPath();
}
}
if (aclNodePath == null) {
fail("Expected node at " + path + " to have an ACL child node.");
}
assertFalse(testSession.nodeExists(aclNodePath));
for (NodeIterator aceNodes = superuser.getNode(aclNodePath).getNodes(); aceNodes.hasNext(); ) {
Node aceNode = aceNodes.nextNode();
String aceNodePath = aceNode.getPath();
assertFalse(testSession.nodeExists(aceNodePath));
for (PropertyIterator it = aceNode.getProperties(); it.hasNext(); ) {
assertFalse(testSession.propertyExists(it.nextProperty().getPath()));
}
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class NodeDiscoveringNodeTypesTest method setUp.
/**
* Sets up the fixture for the test cases.
*/
protected void setUp() throws Exception {
isReadOnly = true;
super.setUp();
session = getHelper().getReadOnlySession();
testRootNode = session.getRootNode().getNode(testPath);
NodeIterator nodes = testRootNode.getNodes();
try {
childNode = nodes.nextNode();
} catch (NoSuchElementException e) {
}
}
Aggregations