Search in sources :

Example 1 with Condition

use of org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition in project jackrabbit by apache.

the class XPathQueryEvaluator method visit.

public void visit(XPathQueryBuilder.OrCondition condition) throws RepositoryException {
    int pos = xPath.length();
    int count = 0;
    for (Condition c : condition) {
        xPath.append(count++ > 0 ? " or " : "");
        c.accept(this);
    }
    // Surround or clause with parentheses if it contains more than one term
    if (count > 1) {
        xPath.insert(pos, '(');
        xPath.append(')');
    }
}
Also used : Condition(org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition)

Example 2 with Condition

use of org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition in project jackrabbit by apache.

the class XPathQueryEvaluator method visit.

public void visit(XPathQueryBuilder.AndCondition condition) throws RepositoryException {
    int count = 0;
    for (Condition c : condition) {
        xPath.append(count++ > 0 ? " and " : "");
        c.accept(this);
    }
}
Also used : Condition(org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition)

Example 3 with Condition

use of org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition in project jackrabbit by apache.

the class XPathQueryEvaluator method eval.

public Iterator<Authorizable> eval() throws RepositoryException {
    xPath.append("//element(*,").append(getNtName(builder.getSelector())).append(')');
    Value bound = builder.getBound();
    long offset = builder.getOffset();
    if (bound != null && offset > 0) {
        log.warn("Found bound {} and offset {} in limit. Discarding offset.", bound, offset);
        offset = 0;
    }
    Condition condition = builder.getCondition();
    String sortCol = builder.getSortProperty();
    Direction sortDir = builder.getSortDirection();
    if (bound != null) {
        if (sortCol == null) {
            log.warn("Ignoring bound {} since no sort order is specified");
        } else {
            Condition boundCondition = builder.property(sortCol, getCollation(sortDir), bound);
            condition = condition == null ? boundCondition : builder.and(condition, boundCondition);
        }
    }
    if (condition != null) {
        xPath.append('[');
        condition.accept(this);
        xPath.append(']');
    }
    if (sortCol != null) {
        boolean ignoreCase = builder.getSortIgnoreCase();
        xPath.append(" order by ").append(ignoreCase ? "" : "fn:lower-case(").append(sortCol).append(ignoreCase ? " " : ") ").append(sortDir.getDirection());
    }
    QueryManager queryManager = session.getWorkspace().getQueryManager();
    Query query = queryManager.createQuery(xPath.toString(), Query.XPATH);
    long maxCount = builder.getMaxCount();
    if (maxCount == 0) {
        return Iterators.empty();
    }
    // here (inefficient!) otherwise we can apply the limit in the query
    if (builder.getGroupName() == null) {
        if (offset > 0) {
            query.setOffset(offset);
        }
        if (maxCount > 0) {
            query.setLimit(maxCount);
        }
        return toAuthorizables(execute(query));
    } else {
        Iterator<Authorizable> result = toAuthorizables(execute(query));
        Iterator<Authorizable> filtered = filter(result, builder.getGroupName(), builder.isDeclaredMembersOnly());
        return BoundedIterator.create(offset, maxCount, filtered);
    }
}
Also used : Condition(org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition) Query(javax.jcr.query.Query) Value(javax.jcr.Value) QueryManager(javax.jcr.query.QueryManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Direction(org.apache.jackrabbit.api.security.user.QueryBuilder.Direction)

Aggregations

Condition (org.apache.jackrabbit.core.security.user.XPathQueryBuilder.Condition)3 Value (javax.jcr.Value)1 Query (javax.jcr.query.Query)1 QueryManager (javax.jcr.query.QueryManager)1 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)1 Direction (org.apache.jackrabbit.api.security.user.QueryBuilder.Direction)1