Search in sources :

Example 1 with ConstraintExpr

use of com.enonic.xp.query.expr.ConstraintExpr in project xp by enonic.

the class ContentQueryNodeQueryTranslator method buildNodeQueryExpr.

private static QueryExpr buildNodeQueryExpr(final ContentQuery contentQuery) {
    final QueryExpr queryExpr = contentQuery.getQueryExpr();
    final CompareExpr contentPathRootExpr = CompareExpr.like(FieldExpr.from("_path"), ValueExpr.string(ContentNodeHelper.getContentRoot() + "/*"));
    if (queryExpr != null) {
        final ConstraintExpr newExpr = queryExpr.getConstraint() != null ? LogicalExpr.and(queryExpr.getConstraint(), contentPathRootExpr) : contentPathRootExpr;
        return QueryExpr.from(newExpr, queryExpr.getOrderList());
    }
    return QueryExpr.from(contentPathRootExpr);
}
Also used : ConstraintExpr(com.enonic.xp.query.expr.ConstraintExpr) QueryExpr(com.enonic.xp.query.expr.QueryExpr) CompareExpr(com.enonic.xp.query.expr.CompareExpr)

Example 2 with ConstraintExpr

use of com.enonic.xp.query.expr.ConstraintExpr in project xp by enonic.

the class QueryBuilderFactory method create.

public QueryBuilder create() {
    final QueryBuilder queryBuilder;
    if (queryExpr != null) {
        final ConstraintExpr constraint = queryExpr.getConstraint();
        queryBuilder = ConstraintExpressionBuilder.build(constraint, fieldNameResolver);
    } else {
        queryBuilder = QueryBuilders.matchAllQuery();
    }
    final boolean wrapInFilteredQuery = filters != null && !filters.isEmpty();
    if (wrapInFilteredQuery) {
        final QueryBuilder filterBuilder = new FilterBuilderFactory(fieldNameResolver).create(filters);
        final BoolQueryBuilder boolBuilder = new BoolQueryBuilder();
        boolBuilder.filter(filterBuilder);
        return boolBuilder.must(queryBuilder);
    } else {
        return queryBuilder;
    }
}
Also used : ConstraintExpr(com.enonic.xp.query.expr.ConstraintExpr) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 3 with ConstraintExpr

use of com.enonic.xp.query.expr.ConstraintExpr in project xp by enonic.

the class FindNodesByQueryCommandTest_order method sort.

private FindNodesByQueryResult sort(String[] orders) {
    StringBuilder order = new StringBuilder();
    for (String curOrder : orders) {
        order.append(curOrder).append(",");
    }
    order.deleteCharAt(order.length() - 1);
    final List<OrderExpr> orderExpressions = QueryParser.parseOrderExpressions(order.toString());
    final ConstraintExpr constraintExpr = QueryParser.parseCostraintExpression(PARENT_QUERY);
    final QueryExpr queryExpr = QueryExpr.from(constraintExpr, orderExpressions);
    final NodeQuery query = NodeQuery.create().query(queryExpr).build();
    return doFindByQuery(query);
}
Also used : ConstraintExpr(com.enonic.xp.query.expr.ConstraintExpr) QueryExpr(com.enonic.xp.query.expr.QueryExpr) OrderExpr(com.enonic.xp.query.expr.OrderExpr) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 4 with ConstraintExpr

use of com.enonic.xp.query.expr.ConstraintExpr in project xp by enonic.

the class FindUsersHandler method execute.

public PrincipalsResultMapper execute() {
    final ConstraintExpr constraintExpr = QueryParser.parseCostraintExpression(this.query == null ? "" : this.query);
    final List<OrderExpr> orderExpressions = QueryParser.parseOrderExpressions(this.sort == null ? "" : this.sort);
    final QueryExpr queryExpr = QueryExpr.from(constraintExpr, orderExpressions);
    final UserQuery userQuery = UserQuery.create().from(this.start).size(this.count).queryExpr(queryExpr).build();
    final UserQueryResult result = this.securityService.get().query(userQuery);
    return new PrincipalsResultMapper(result.getUsers(), result.getTotalSize(), this.includeProfile);
}
Also used : ConstraintExpr(com.enonic.xp.query.expr.ConstraintExpr) QueryExpr(com.enonic.xp.query.expr.QueryExpr) OrderExpr(com.enonic.xp.query.expr.OrderExpr) UserQuery(com.enonic.xp.security.UserQuery) UserQueryResult(com.enonic.xp.security.UserQueryResult)

Example 5 with ConstraintExpr

use of com.enonic.xp.query.expr.ConstraintExpr in project xp by enonic.

the class ReprocessRunnableTask method run.

@Override
public void run(final TaskId id, final ProgressReporter progressReporter) {
    final List<ContentPath> updated = new ArrayList<>();
    final List<String> errors = new ArrayList<>();
    final Content content = this.contentService.getByPath(params.getSourceBranchPath().getContentPath());
    try {
        if (!params.isSkipChildren()) {
            String nodePath = CONTENT_ROOT_PATH.asAbsolute().toString();
            final ContentPath contentPath = params.getSourceBranchPath().getContentPath();
            if (!ContentPath.ROOT.equals(contentPath)) {
                nodePath += content.getPath().asAbsolute().toString();
            }
            final ConstraintExpr pathExpr = CompareExpr.like(FieldExpr.from("_path"), ValueExpr.string(nodePath + "/*"));
            final ContentQuery countChildren = ContentQuery.create().queryExpr(QueryExpr.from(pathExpr)).size(0).build();
            total = (int) contentService.find(countChildren).getTotalHits() + 1;
        }
        reprocessContent(content, params.isSkipChildren(), updated, errors, progressReporter);
    } catch (Exception e) {
        errors.add(String.format("Content '%s' - %s: %s", content.getPath().toString(), e.getClass().getCanonicalName(), e.getMessage()));
        LOG.warn("Error reprocessing content [" + content.getPath() + "]", e);
    }
    progressReporter.info(new ReprocessContentResultJson(ContentPaths.from(updated), errors).toString());
}
Also used : ConstraintExpr(com.enonic.xp.query.expr.ConstraintExpr) ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) ArrayList(java.util.ArrayList) ContentPath(com.enonic.xp.content.ContentPath) ReprocessContentResultJson(com.enonic.xp.impl.server.rest.model.ReprocessContentResultJson)

Aggregations

ConstraintExpr (com.enonic.xp.query.expr.ConstraintExpr)5 QueryExpr (com.enonic.xp.query.expr.QueryExpr)3 OrderExpr (com.enonic.xp.query.expr.OrderExpr)2 Content (com.enonic.xp.content.Content)1 ContentPath (com.enonic.xp.content.ContentPath)1 ContentQuery (com.enonic.xp.content.ContentQuery)1 ReprocessContentResultJson (com.enonic.xp.impl.server.rest.model.ReprocessContentResultJson)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 CompareExpr (com.enonic.xp.query.expr.CompareExpr)1 UserQuery (com.enonic.xp.security.UserQuery)1 UserQueryResult (com.enonic.xp.security.UserQueryResult)1 ArrayList (java.util.ArrayList)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1