Search in sources :

Example 31 with FindContentByParentResult

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

the class GetChildContentHandlerTest method testExample.

@Test
public void testExample() {
    final Contents contents = TestDataFixtures.newContents(2);
    final FindContentByParentResult findResult = FindContentByParentResult.create().hits(contents.getSize()).totalHits(20).contents(contents).build();
    Mockito.when(this.contentService.findByParent(Mockito.isA(FindContentByParentParams.class))).thenReturn(findResult);
    runScript("/lib/xp/examples/content/getChildren.js");
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) Contents(com.enonic.xp.content.Contents) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Test(org.junit.jupiter.api.Test)

Example 32 with FindContentByParentResult

use of com.enonic.xp.content.FindContentByParentResult 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 33 with FindContentByParentResult

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

FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)33 Test (org.junit.jupiter.api.Test)26 Content (com.enonic.xp.content.Content)18 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)18 ContentPath (com.enonic.xp.content.ContentPath)7 Contents (com.enonic.xp.content.Contents)4 ArrayDeque (java.util.ArrayDeque)2 ArchiveConstants (com.enonic.xp.archive.ArchiveConstants)1 ContentConstants (com.enonic.xp.content.ContentConstants)1 BRANCH_DRAFT (com.enonic.xp.content.ContentConstants.BRANCH_DRAFT)1 CONTENT_ROOT_PATH_ATTRIBUTE (com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE)1 ContentId (com.enonic.xp.content.ContentId)1 ContentService (com.enonic.xp.content.ContentService)1 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 MediaInfoService (com.enonic.xp.media.MediaInfoService)1 NodePath (com.enonic.xp.node.NodePath)1 PageTemplate (com.enonic.xp.page.PageTemplate)1 PageTemplates (com.enonic.xp.page.PageTemplates)1