Search in sources :

Example 21 with ContentQuery

use of com.enonic.xp.content.ContentQuery in project xp by enonic.

the class ContentServiceImplTest_findPaths method single_item.

@Test
public void single_item() throws Exception {
    final Content site = createContent(ContentPath.ROOT, "a");
    final Content child3 = createContent(site.getPath(), "d");
    final Content child2 = createContent(site.getPath(), "c");
    final Content child1 = createContent(site.getPath(), "b");
    final ContentQuery query = ContentQuery.create().queryExpr(QueryParser.parse("_path = '/content" + child1.getPath().asAbsolute() + "'")).build();
    assertEquals(ContentPaths.from(child1.getPath()), contentService.findPaths(query).getContentPaths());
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 22 with ContentQuery

use of com.enonic.xp.content.ContentQuery 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

ContentQuery (com.enonic.xp.content.ContentQuery)22 Test (org.junit.jupiter.api.Test)18 Content (com.enonic.xp.content.Content)15 PropertyTree (com.enonic.xp.data.PropertyTree)8 PropertySet (com.enonic.xp.data.PropertySet)7 FindContentByQueryResult (com.enonic.xp.content.FindContentByQueryResult)4 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)2 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)2 FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)2 OrderExpr (com.enonic.xp.query.expr.OrderExpr)2 ContentIds (com.enonic.xp.content.ContentIds)1 ContentPath (com.enonic.xp.content.ContentPath)1 ReprocessContentResultJson (com.enonic.xp.impl.server.rest.model.ReprocessContentResultJson)1 GeoDistanceAggregationQuery (com.enonic.xp.query.aggregation.GeoDistanceAggregationQuery)1 ConstraintExpr (com.enonic.xp.query.expr.ConstraintExpr)1 BooleanFilter (com.enonic.xp.query.filter.BooleanFilter)1 ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)1 Filter (com.enonic.xp.query.filter.Filter)1 IdFilter (com.enonic.xp.query.filter.IdFilter)1 ValueFilter (com.enonic.xp.query.filter.ValueFilter)1