Search in sources :

Example 1 with GetContentByIdsParams

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

the class QueryContentHandler method convert.

private ContentsResultMapper convert(final FindContentIdsByQueryResult findQueryResult) {
    final ContentIds contentIds = findQueryResult.getContentIds();
    final Contents contents;
    if (contentIds.isEmpty()) {
        contents = Contents.empty();
    } else {
        contents = this.contentService.getByIds(new GetContentByIdsParams(contentIds));
    }
    return new ContentsResultMapper(contents, findQueryResult.getTotalHits(), findQueryResult.getAggregations(), findQueryResult.getHighlight(), findQueryResult.getSort(), findQueryResult.getScore());
}
Also used : Contents(com.enonic.xp.content.Contents) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) ContentsResultMapper(com.enonic.xp.lib.content.mapper.ContentsResultMapper) ContentIds(com.enonic.xp.content.ContentIds)

Example 2 with GetContentByIdsParams

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

the class ContentDependenciesResolver method resolveOutboundDependenciesAggregation.

private Collection<ContentDependenciesAggregation> resolveOutboundDependenciesAggregation(final ContentId contentId) {
    final Map<ContentTypeName, Long> aggregationJsonMap = new HashMap<>();
    final Contents contents = this.contentService.getByIds(new GetContentByIdsParams(this.contentService.getOutboundDependencies(contentId)));
    contents.forEach(existingContent -> {
        final ContentTypeName contentTypeName = existingContent.getType();
        final Long count = aggregationJsonMap.containsKey(contentTypeName) ? aggregationJsonMap.get(contentTypeName) + 1 : 1;
        aggregationJsonMap.put(contentTypeName, count);
    });
    return aggregationJsonMap.entrySet().stream().map(entry -> new ContentDependenciesAggregation(entry.getKey(), entry.getValue())).collect(toList());
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) ContentService(com.enonic.xp.content.ContentService) ContentIndexPath(com.enonic.xp.content.ContentIndexPath) FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) Collection(java.util.Collection) HashMap(java.util.HashMap) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) HashSet(java.util.HashSet) ContentQuery(com.enonic.xp.content.ContentQuery) ContentId(com.enonic.xp.content.ContentId) Collectors.toList(java.util.stream.Collectors.toList) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Contents(com.enonic.xp.content.Contents) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) TermsAggregationQuery(com.enonic.xp.query.aggregation.TermsAggregationQuery) Map(java.util.Map) ContentDependencies(com.enonic.xp.content.ContentDependencies) ContentDependenciesAggregation(com.enonic.xp.content.ContentDependenciesAggregation) Contents(com.enonic.xp.content.Contents) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) HashMap(java.util.HashMap) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName)

Example 3 with GetContentByIdsParams

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

the class ContentServiceImplTest_delete method create_delete_content.

@Test
public void create_delete_content() throws Exception {
    // Creates a content
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").name("myContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    // Deletes the content
    final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(content.getPath()).build();
    final DeleteContentsResult deletedContents = this.contentService.deleteWithoutFetch(deleteContentParams);
    assertNotNull(deletedContents);
    assertEquals(1, deletedContents.getDeletedContents().getSize());
    assertEquals(content.getId(), deletedContents.getDeletedContents().first());
    // Checks that the content is deleted
    final ContentIds contentIds = ContentIds.from(content.getId());
    final GetContentByIdsParams getContentByIdsParams = new GetContentByIdsParams(contentIds);
    final Contents foundContents = this.contentService.getByIds(getContentByIdsParams);
    assertEquals(0, foundContents.getSize());
}
Also used : DeleteContentParams(com.enonic.xp.content.DeleteContentParams) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Contents(com.enonic.xp.content.Contents) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIds(com.enonic.xp.content.ContentIds) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Example 4 with GetContentByIdsParams

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

the class ContentServiceImplTest_delete method create_delete_published_content_with_children.

@Test
public void create_delete_published_content_with_children() throws Exception {
    // Creates a content with children
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Root Content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final CreateContentParams createChild1ContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Child1 Content").parent(content.getPath()).type(ContentTypeName.folder()).build();
    final Content child1Content = this.contentService.create(createChild1ContentParams);
    final CreateContentParams createChild2ContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Child2 Content").parent(content.getPath()).type(ContentTypeName.folder()).build();
    final Content child2Content = this.contentService.create(createChild2ContentParams);
    final CreateContentParams createSubChildContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("SubChild Content").parent(child1Content.getPath()).type(ContentTypeName.folder()).build();
    final Content subChildContent = this.contentService.create(createSubChildContentParams);
    // Publishes the content
    final PushContentParams pushParams = PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).build();
    refresh();
    this.contentService.publish(pushParams);
    // Deletes the content
    final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(content.getPath()).build();
    final DeleteContentsResult deletedContents = this.contentService.deleteWithoutFetch(deleteContentParams);
    assertNotNull(deletedContents);
    assertEquals(4, deletedContents.getPendingContents().getSize());
    // Checks that the content and children are marked for deletion
    final ContentIds contentIds = ContentIds.from(content.getId(), child1Content.getId(), child2Content.getId(), subChildContent.getId());
    final GetContentByIdsParams getContentByIdsParams = new GetContentByIdsParams(contentIds);
    final Contents foundContents = this.contentService.getByIds(getContentByIdsParams);
    assertEquals(4, foundContents.getSize());
    for (Content foundContent : foundContents) {
        assertTrue(ContentState.PENDING_DELETE == foundContent.getContentState());
    }
}
Also used : DeleteContentParams(com.enonic.xp.content.DeleteContentParams) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Contents(com.enonic.xp.content.Contents) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIds(com.enonic.xp.content.ContentIds) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) PushContentParams(com.enonic.xp.content.PushContentParams) Test(org.junit.jupiter.api.Test)

Example 5 with GetContentByIdsParams

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

the class ContentServiceImplTest_delete method delete_published_content_with_unpublished_children.

@Test
public void delete_published_content_with_unpublished_children() throws Exception {
    final Content parent = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("Root Content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build());
    final Content child = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("Published Child Content").parent(parent.getPath()).type(ContentTypeName.folder()).build());
    refresh();
    final PublishContentResult result = this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(parent.getId())).target(WS_OTHER).build());
    assertEquals(2, result.getPushedContents().getSize());
    refresh();
    // Creates an child that we wont publish
    final Content unpublishedChildContent = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("Unpublished Child Content").parent(parent.getPath()).type(ContentTypeName.folder()).build());
    refresh();
    // Deletes the root content
    final DeleteContentsResult deletedContents = this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(parent.getPath()).build());
    assertNotNull(deletedContents);
    assertEquals(1, deletedContents.getDeletedContents().getSize());
    assertEquals(2, deletedContents.getPendingContents().getSize());
    DeleteContentParams.create().contentPath(parent.getPath()).build();
    assertTrue(deletedContents.getDeletedContents().contains(unpublishedChildContent.getId()));
    assertTrue(deletedContents.getPendingContents().contains(parent.getId()));
    assertTrue(deletedContents.getPendingContents().contains(child.getId()));
    // Checks that the content and published child are marked for deletion and that the unpublished child is deleted
    final ContentIds contentIds = ContentIds.from(parent.getId(), child.getId(), unpublishedChildContent.getId());
    final GetContentByIdsParams getContentByIdsParams = new GetContentByIdsParams(contentIds);
    final Contents foundContents = this.contentService.getByIds(getContentByIdsParams);
    assertEquals(2, foundContents.getSize());
    for (Content foundContent : foundContents) {
        assertTrue(ContentState.PENDING_DELETE == foundContent.getContentState());
        assertTrue(parent.getId().equals(foundContent.getId()) || child.getId().equals(foundContent.getId()));
    }
}
Also used : PublishContentResult(com.enonic.xp.content.PublishContentResult) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) Contents(com.enonic.xp.content.Contents) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIds(com.enonic.xp.content.ContentIds) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Aggregations

Contents (com.enonic.xp.content.Contents)13 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)13 Content (com.enonic.xp.content.Content)11 ContentIds (com.enonic.xp.content.ContentIds)11 Test (org.junit.jupiter.api.Test)10 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)5 PropertyTree (com.enonic.xp.data.PropertyTree)5 CreateContentParams (com.enonic.xp.content.CreateContentParams)4 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)3 ContentDependencies (com.enonic.xp.content.ContentDependencies)2 ContentId (com.enonic.xp.content.ContentId)2 ContentQuery (com.enonic.xp.content.ContentQuery)2 ContentService (com.enonic.xp.content.ContentService)2 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)1 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 ArchiveContentParams (com.enonic.xp.archive.ArchiveContentParams)1 ArchiveContentsResult (com.enonic.xp.archive.ArchiveContentsResult)1 RestoreContentParams (com.enonic.xp.archive.RestoreContentParams)1 RestoreContentsResult (com.enonic.xp.archive.RestoreContentsResult)1 Branches (com.enonic.xp.branch.Branches)1