use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class QueryResultTest method testGetSize.
public void testGetSize() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000]";
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, result.getNodes().getSize());
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class QueryResultTest method testGetSizeOrderByScore.
public void testGetSizeOrderByScore() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000] order by jcr:score()";
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, result.getNodes().getSize());
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class QueryResultTest method testGetPosition.
public void testGetPosition() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000]";
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
NodeIterator it = result.getNodes();
assertEquals("Wrong position", 0, it.getPosition());
int count = 0;
while (it.hasNext()) {
long position = it.getPosition();
it.nextNode();
assertEquals("Wrong position", count++, position);
}
try {
it.next();
fail("must throw NoSuchElementException");
} catch (Exception e) {
// correct
}
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class QueryResultTest method testIteratorNextOrderByScore.
public void testIteratorNextOrderByScore() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000] order by jcr:score()";
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
int size = 0;
for (NodeIterator it = result.getNodes(); it.hasNext(); ) {
it.nextNode();
size++;
}
assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, size);
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class ACLProvider method getEffectivePolicies.
/**
* @see org.apache.jackrabbit.core.security.authorization.AccessControlProvider#getEffectivePolicies(org.apache.jackrabbit.spi.Path,org.apache.jackrabbit.core.security.authorization.CompiledPermissions)
*/
public AccessControlPolicy[] getEffectivePolicies(Path absPath, CompiledPermissions permissions) throws ItemNotFoundException, RepositoryException {
if (absPath == null) {
// TODO: JCR-2774
log.warn("TODO: JCR-2774 - Repository level permissions.");
return new AccessControlPolicy[0];
}
String jcrPath = session.getJCRPath(absPath);
String pName = ISO9075.encode(session.getJCRName(ACLTemplate.P_NODE_PATH));
int ancestorCnt = absPath.getAncestorCount();
// search all ACEs whose rep:nodePath property equals the specified
// absPath or any of it's ancestors
StringBuilder stmt = new StringBuilder("/jcr:root");
stmt.append(acRoot.getPath());
stmt.append("//element(*,");
stmt.append(session.getJCRName(NT_REP_ACE));
stmt.append(")[");
for (int i = 0; i <= ancestorCnt; i++) {
String path = Text.getRelativeParent(jcrPath, i);
if (i > 0) {
stmt.append(" or ");
}
stmt.append("@");
stmt.append(pName);
stmt.append("='");
stmt.append(path.replaceAll("'", "''"));
stmt.append("'");
}
stmt.append("]");
QueryResult result;
try {
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery(stmt.toString(), Query.XPATH);
result = q.execute();
} catch (RepositoryException e) {
log.error("Unexpected error while searching effective policies. {}", e.getMessage());
throw new UnsupportedOperationException("Retrieve effective policies at absPath '" + jcrPath + "' not supported.", e);
}
/**
* Loop over query results and verify that
* - the corresponding ACE really takes effect on the specified absPath.
* - the corresponding ACL can be read by the editing session.
*/
Set<AccessControlPolicy> acls = new LinkedHashSet<AccessControlPolicy>();
for (NodeIterator it = result.getNodes(); it.hasNext(); ) {
Node aceNode = it.nextNode();
String accessControlledNodePath = Text.getRelativeParent(aceNode.getPath(), 2);
Path acPath = session.getQPath(accessControlledNodePath);
AccessControlPolicy[] policies = editor.getPolicies(accessControlledNodePath);
if (policies.length > 0) {
ACLTemplate acl = (ACLTemplate) policies[0];
for (AccessControlEntry ace : acl.getAccessControlEntries()) {
ACLTemplate.Entry entry = (ACLTemplate.Entry) ace;
if (entry.matches(jcrPath)) {
if (permissions.grants(acPath, Permission.READ_AC)) {
acls.add(new UnmodifiableAccessControlList(acl));
break;
} else {
throw new AccessDeniedException("Access denied at " + accessControlledNodePath);
}
}
}
}
}
return acls.toArray(new AccessControlPolicy[acls.size()]);
}
Aggregations