Search in sources :

Example 21 with FindContentByParentParams

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

the class ContentServiceImplTest_findIdsByParent method hasChildResolved.

@Test
public void hasChildResolved() throws Exception {
    final Content parentContent = createContent(ContentPath.ROOT);
    final Content content1 = createContent(parentContent.getPath());
    createContent(content1.getPath());
    this.nodeService.refresh(RefreshMode.SEARCH);
    final FindContentByParentParams params = FindContentByParentParams.create().from(0).size(30).parentId(parentContent.getId()).build();
    final FindContentIdsByParentResult result = contentService.findIdsByParent(params);
    assertNotNull(result);
    assertEquals(1, result.getTotalHits());
    final Content content1Result = this.contentService.getById(result.getContentIds().first());
    assertTrue(content1Result.hasChildren());
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) Content(com.enonic.xp.content.Content) FindContentIdsByParentResult(com.enonic.xp.content.FindContentIdsByParentResult) Test(org.junit.jupiter.api.Test)

Example 22 with FindContentByParentParams

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

the class ReprocessRunnableTask method reprocessContent.

private void reprocessContent(final Content content, final boolean skipChildren, final List<ContentPath> updated, final List<String> errors, final ProgressReporter progressReporter) {
    final Content reprocessedContent = this.contentService.reprocess(content.getId());
    if (!reprocessedContent.equals(content)) {
        updated.add(content.getPath());
    }
    progressReporter.progress(++current, total);
    if (skipChildren) {
        return;
    }
    int from = 0;
    int resultCount;
    do {
        final FindContentByParentParams findParams = FindContentByParentParams.create().parentId(content.getId()).from(from).size(5).build();
        final FindContentByParentResult results = this.contentService.findByParent(findParams);
        for (Content child : results.getContents()) {
            try {
                reprocessContent(child, false, updated, errors, progressReporter);
            } catch (Exception e) {
                errors.add(String.format("Content '%s' - %s: %s", child.getPath().toString(), e.getClass().getCanonicalName(), e.getMessage()));
                LOG.warn("Error reprocessing content [" + child.getPath() + "]", e);
            }
        }
        resultCount = Math.toIntExact(results.getHits());
        from = from + resultCount;
    } while (resultCount > 0);
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content)

Example 23 with FindContentByParentParams

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

the class ContentResource method reprocessContent.

@Deprecated
private void reprocessContent(final Content content, final boolean skipChildren, final List<ContentPath> updated, final List<String> errors) {
    final Content reprocessedContent = this.contentService.reprocess(content.getId());
    if (!reprocessedContent.equals(content)) {
        updated.add(content.getPath());
    }
    if (skipChildren) {
        return;
    }
    int from = 0;
    int resultCount;
    do {
        final FindContentByParentParams findParams = FindContentByParentParams.create().parentId(content.getId()).from(from).size(5).build();
        final FindContentByParentResult results = this.contentService.findByParent(findParams);
        for (Content child : results.getContents()) {
            try {
                reprocessContent(child, false, updated, errors);
            } catch (Exception e) {
                errors.add(String.format("Content '%s' - %s: %s", child.getPath().toString(), e.getClass().getCanonicalName(), e.getMessage()));
                LOG.warn("Error reprocessing content [" + child.getPath() + "]", e);
            }
        }
        resultCount = Math.toIntExact(results.getHits());
        from = from + resultCount;
    } while (resultCount > 0);
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content)

Aggregations

FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)23 Content (com.enonic.xp.content.Content)18 Test (org.junit.jupiter.api.Test)18 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)12 ContentPath (com.enonic.xp.content.ContentPath)10 FindContentIdsByParentResult (com.enonic.xp.content.FindContentIdsByParentResult)8 Contents (com.enonic.xp.content.Contents)1 PageTemplate (com.enonic.xp.page.PageTemplate)1 PageTemplates (com.enonic.xp.page.PageTemplates)1 ValueFilter (com.enonic.xp.query.filter.ValueFilter)1