use of com.enonic.xp.content.FindContentByParentParams in project xp by enonic.
the class ContentResourceTest method reprocess_child_with_error.
@Test
public void reprocess_child_with_error() throws Exception {
Content content = createContent("content-id", ContentPath.from("/path/to/content"));
Content reprocessedContent = Content.create(content).displayName("new name").build();
Content child = createContent("child-id", ContentPath.from(content.getPath(), "child"));
Mockito.when(this.contentService.getByPath(content.getPath())).thenReturn(content);
Mockito.when(this.contentService.reprocess(content.getId())).thenReturn(reprocessedContent);
Mockito.when(this.contentService.reprocess(child.getId())).thenThrow(new RuntimeException("errorMessage"));
final FindContentByParentParams findParams = FindContentByParentParams.create().parentId(content.getId()).from(0).size(5).build();
Mockito.when(this.contentService.findByParent(findParams)).thenReturn(FindContentByParentResult.create().contents(Contents.create().add(child).build()).build());
final String result = request().path("content/reprocess").entity(readFromFile("reprocess_params.json"), MediaType.APPLICATION_JSON_TYPE).post().getAsString();
assertEquals("{\"errors\":[\"Content '/path/to/content/child' - java.lang.RuntimeException: errorMessage\"],\"updatedContent\":[\"/path/to/content\"]}", result);
}
use of com.enonic.xp.content.FindContentByParentParams in project xp by enonic.
the class GetChildContentHandlerTest method getChildrenByPath_allParameters.
@Test
public void getChildrenByPath_allParameters() throws Exception {
final Contents contents = TestDataFixtures.newContents(3);
final FindContentByParentResult findResult = FindContentByParentResult.create().hits(contents.getSize()).totalHits(20).contents(contents).build();
final FindContentByParentParams expectedFindParams = FindContentByParentParams.create().parentPath(ContentPath.from("/a/b/mycontent")).from(5).size(3).childOrder(ChildOrder.from("_modifiedTime ASC")).build();
Mockito.when(this.contentService.findByParent(Mockito.eq(expectedFindParams))).thenReturn(findResult);
runFunction("/test/GetChildContentHandlerTest.js", "getChildrenByPath_allParameters");
}
use of com.enonic.xp.content.FindContentByParentParams 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();
}
use of com.enonic.xp.content.FindContentByParentParams in project xp by enonic.
the class ContentServiceImplTest_findByParent method invalid_parent_path.
@Test
public void invalid_parent_path() throws Exception {
final Content rootContent = createContent(ContentPath.ROOT);
final Content childrenLevel1 = createContent(rootContent.getPath());
this.nodeService.refresh(RefreshMode.SEARCH);
final FindContentByParentParams params = FindContentByParentParams.create().from(0).size(30).parentPath(ContentPath.from("/test_invalid_path")).build();
final FindContentByParentResult result = contentService.findByParent(params);
assertNotNull(result);
assertEquals(0, result.getTotalHits());
}
use of com.enonic.xp.content.FindContentByParentParams in project xp by enonic.
the class ContentServiceImplTest_findByParent method deep_children.
@Test
public void deep_children() throws Exception {
final Content rootContent = createContent(ContentPath.ROOT);
final Content childrenLevel1 = createContent(rootContent.getPath());
final Content childrenLevel2_1 = createContent(childrenLevel1.getPath());
final Content childrenLevel2_2 = createContent(childrenLevel1.getPath());
final Content childrenLevel2_3 = createContent(childrenLevel1.getPath());
final ContentPath parentContentPath = childrenLevel1.getPath();
this.nodeService.refresh(RefreshMode.SEARCH);
final FindContentByParentParams params = FindContentByParentParams.create().from(0).size(30).parentPath(parentContentPath).build();
final FindContentByParentResult result = contentService.findByParent(params);
assertNotNull(result);
assertEquals(3, result.getTotalHits());
}
Aggregations