Search in sources :

Example 1 with FindContentByParentParams

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);
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 2 with FindContentByParentParams

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");
}
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 3 with FindContentByParentParams

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

Example 4 with FindContentByParentParams

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());
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 5 with FindContentByParentParams

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());
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath) Test(org.junit.jupiter.api.Test)

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