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