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