Search in sources :

Example 6 with FindContentByParentResult

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

the class GetChildContentHandlerTest method getChildrenById.

@Test
public void getChildrenById() throws Exception {
    final Contents contents = TestDataFixtures.newContents(3);
    final FindContentByParentResult findResult = FindContentByParentResult.create().hits(contents.getSize()).totalHits(20).contents(contents).build();
    Mockito.when(this.contentService.findByParent(Mockito.isA(FindContentByParentParams.class))).thenReturn(findResult);
    runFunction("/test/GetChildContentHandlerTest.js", "getChildrenById");
}
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 7 with FindContentByParentResult

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

the class GetChildContentHandlerTest method getChildrenById_notFound.

@Test
public void getChildrenById_notFound() throws Exception {
    final FindContentByParentResult findResult = FindContentByParentResult.create().hits(0).totalHits(0).contents(Contents.empty()).build();
    Mockito.when(this.contentService.findByParent(Mockito.isA(FindContentByParentParams.class))).thenReturn(findResult);
    runFunction("/test/GetChildContentHandlerTest.js", "getChildrenById_notFound");
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Test(org.junit.jupiter.api.Test)

Example 8 with FindContentByParentResult

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

the class ContentServiceImpl method findByParent.

@Override
public FindContentByParentResult findByParent(final FindContentByParentParams params) {
    final Trace trace = Tracer.newTrace("content.findByParent");
    if (trace == null) {
        return doFindByParent(params);
    }
    return Tracer.trace(trace, () -> {
        trace.put("query", params.getParentPath() != null ? params.getParentPath() : params.getParentId());
        trace.put("from", params.getFrom());
        trace.put("size", params.getSize());
        final FindContentByParentResult result = doFindByParent(params);
        trace.put("hits", result.getTotalHits());
        return result;
    });
}
Also used : Trace(com.enonic.xp.trace.Trace) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult)

Example 9 with FindContentByParentResult

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

the class ParentContentSynchronizer method cleanDeletedContents.

private void cleanDeletedContents(final ContentToSync contentToSync) {
    contentToSync.getTargetContext().runWith(() -> {
        final Queue<Content> queue = new ArrayDeque<>(Set.of(contentToSync.getTargetContent()));
        while (queue.size() > 0) {
            final Content currentContent = queue.poll();
            createEventCommand(createEventCommandParams(List.of(ContentToSync.create().targetContent(currentContent).sourceContext(contentToSync.getSourceContext()).targetContext(contentToSync.getTargetContext()).build())), ContentSyncEventType.DELETED).sync();
            if (currentContent.hasChildren()) {
                final FindContentByParentResult result = contentService.findByParent(FindContentByParentParams.create().parentId(currentContent.getId()).recursive(false).childOrder(currentContent.getChildOrder()).size(-1).build());
                for (final Content content : result.getContents()) {
                    queue.offer(content);
                }
            }
        }
    });
}
Also used : FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) ArrayDeque(java.util.ArrayDeque)

Example 10 with FindContentByParentResult

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

the class GetPageTemplateBySiteCommand method execute.

public PageTemplates execute() {
    final PageTemplates.Builder pageTemplatesBuilder = PageTemplates.create();
    if (sitePath == null) {
        final Content site = contentService.getById(siteId);
        sitePath = site.getPath();
    }
    final ContentPath pageTemplatesFolderPath = ContentPath.from(sitePath, ContentServiceImpl.TEMPLATES_FOLDER_NAME);
    final FindContentByParentParams.Builder findContentByParentParams = FindContentByParentParams.create().parentPath(pageTemplatesFolderPath);
    if (supportedContentTypes != null) {
        final ValueFilter.Builder supportsContentTypeFilter = ValueFilter.create().fieldName("data.supports");
        supportedContentTypes.forEach(supportedContentType -> {
            supportsContentTypeFilter.addValue(ValueFactory.newString(supportedContentType.toString()));
        });
        findContentByParentParams.queryFilter(supportsContentTypeFilter.build());
    }
    if (size != null) {
        findContentByParentParams.size(size);
    }
    final FindContentByParentResult result = contentService.findByParent(findContentByParentParams.build());
    for (final Content content : result.getContents()) {
        if (content instanceof PageTemplate) {
            pageTemplatesBuilder.add((PageTemplate) content);
        }
    }
    return pageTemplatesBuilder.build();
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) PageTemplate(com.enonic.xp.page.PageTemplate) Content(com.enonic.xp.content.Content) PageTemplates(com.enonic.xp.page.PageTemplates) ValueFilter(com.enonic.xp.query.filter.ValueFilter) ContentPath(com.enonic.xp.content.ContentPath)

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