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