Search in sources :

Example 16 with ContentIds

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

the class DuplicateContentCommand method doExecute.

private DuplicateContentsResult doExecute() {
    final NodeId sourceNodeId = NodeId.from(params.getContentId());
    final Node sourceNode = nodeService.getById(sourceNodeId);
    if (sourceNode == null) {
        throw new IllegalArgumentException(String.format("Content with id [%s] not found", params.getContentId()));
    }
    final DuplicateNodeParams duplicateNodeParams = DuplicateNodeParams.create().duplicateListener(this).nodeId(sourceNodeId).dataProcessor(new DuplicateContentProcessor()).includeChildren(params.getIncludeChildren()).build();
    final Node duplicatedNode = nodeService.duplicate(duplicateNodeParams);
    final Content duplicatedContent = translator.fromNode(duplicatedNode, true);
    final ContentIds childrenIds = params.getIncludeChildren() ? getAllChildren(duplicatedContent) : ContentIds.empty();
    return DuplicateContentsResult.create().setSourceContentPath(ContentNodeHelper.translateNodePathToContentPath(sourceNode.path())).setContentName(duplicatedContent.getDisplayName()).addDuplicated(duplicatedContent.getId()).addDuplicated(childrenIds).build();
}
Also used : DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) ContentIds(com.enonic.xp.content.ContentIds)

Example 17 with ContentIds

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

the class ContentQueryNodeQueryTranslator method processReferenceIds.

private static void processReferenceIds(final ContentQuery contentQuery, final NodeQuery.Builder builder) {
    final ContentIds contentIds = contentQuery.getFilterContentIds();
    if (contentIds != null && contentIds.isNotEmpty()) {
        final IdFilter.Builder contentTypeFilterBuilder = IdFilter.create().fieldName(ContentIndexPath.ID.getPath()).values(contentIds.asStrings()).setCache(true);
        builder.addQueryFilter(contentTypeFilterBuilder.build());
    }
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) ContentIds(com.enonic.xp.content.ContentIds)

Example 18 with ContentIds

use of com.enonic.xp.content.ContentIds 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 19 with ContentIds

use of com.enonic.xp.content.ContentIds 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 20 with ContentIds

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

the class ContentOutboundDependenciesIdsResolverTest method resolve_outbound_from_xdata.

@Test
public void resolve_outbound_from_xdata() throws Exception {
    final PropertyTree data = new PropertyTree();
    final Content folderRefContent1 = createContent("folderRefContent1", data, ContentTypeName.folder());
    final Content folderRefContent2 = createContent("folderRefContent2", data, ContentTypeName.folder());
    final Content siteRefContent1 = createContent("siteRefContent1", data, ContentTypeName.site());
    data.addReference("myRef1", Reference.from(folderRefContent1.getId().toString()));
    data.addReference("myRef2", Reference.from(folderRefContent2.getId().toString()));
    data.addReference("myRef3", Reference.from(siteRefContent1.getId().toString()));
    data.addReference("refToMyself", Reference.from("contentId"));
    final Content content = createContent("contentId", new PropertyTree(), ContentTypeName.site(), ExtraDatas.create().add(new ExtraData(XDataName.from("x-data"), data)).build());
    Mockito.when(contentService.getByIds(Mockito.any())).thenReturn(Contents.from(folderRefContent1, folderRefContent2, siteRefContent1));
    Mockito.when(contentService.getById(content.getId())).thenReturn(content);
    final ContentIds result = resolver.resolve(content.getId());
    assertEquals(result.getSize(), 3);
    assertTrue(result.contains(folderRefContent1.getId()));
    assertTrue(result.contains(folderRefContent2.getId()));
    assertTrue(result.contains(siteRefContent1.getId()));
}
Also used : Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIds(com.enonic.xp.content.ContentIds) ExtraData(com.enonic.xp.content.ExtraData) Test(org.junit.jupiter.api.Test)

Aggregations

ContentIds (com.enonic.xp.content.ContentIds)38 Test (org.junit.jupiter.api.Test)27 Content (com.enonic.xp.content.Content)22 Contents (com.enonic.xp.content.Contents)11 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)10 PropertyTree (com.enonic.xp.data.PropertyTree)8 ContentId (com.enonic.xp.content.ContentId)6 PushContentParams (com.enonic.xp.content.PushContentParams)6 UnpublishContentParams (com.enonic.xp.content.UnpublishContentParams)4 NodeIds (com.enonic.xp.node.NodeIds)4 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)3 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)2 PublishContentResult (com.enonic.xp.content.PublishContentResult)2 UnpublishContentsResult (com.enonic.xp.content.UnpublishContentsResult)2 Context (com.enonic.xp.context.Context)2 PropertySet (com.enonic.xp.data.PropertySet)2 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)2 Node (com.enonic.xp.node.Node)2 NodeId (com.enonic.xp.node.NodeId)2