Search in sources :

Example 11 with ContentIds

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

the class PublishContentCommand method pushAndDelete.

private void pushAndDelete(final CompareContentResults results) {
    NodeIds.Builder pushNodesIds = NodeIds.create();
    NodeIds.Builder deletedNodesIds = NodeIds.create();
    for (CompareContentResult compareResult : results) {
        if (compareResult.getCompareStatus() == CompareStatus.PENDING_DELETE) {
            deletedNodesIds.add(NodeId.from(compareResult.getContentId()));
        } else {
            pushNodesIds.add(NodeId.from(compareResult.getContentId()));
        }
    }
    final ContentIds pushContentsIds = ContentIds.from(pushNodesIds.build().stream().map((n) -> ContentId.from(n.toString())).toArray(ContentId[]::new));
    final boolean validContents = checkIfAllContentsValid(pushContentsIds);
    if (validContents) {
        doPushNodes(pushNodesIds.build());
    } else {
        this.resultBuilder.setFailed(pushContentsIds);
    }
    doDeleteNodes(deletedNodesIds.build());
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) CompareContentResult(com.enonic.xp.content.CompareContentResult) ContentIds(com.enonic.xp.content.ContentIds) ContentId(com.enonic.xp.content.ContentId)

Example 12 with ContentIds

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

the class UnpublishContentCommand method unpublish.

private UnpublishContentsResult unpublish() {
    final ContentIds.Builder contentBuilder = ContentIds.create();
    for (final ContentId contentId : this.params.getContentIds()) {
        recursiveUnpublish(NodeId.from(contentId), this.params.isIncludeChildren(), contentBuilder);
    }
    final ContentIds contentIds = contentBuilder.build();
    final Context draftContext = ContextBuilder.from(ContextAccessor.current()).branch(ContentConstants.BRANCH_DRAFT).build();
    draftContext.callWith(() -> removePublishInfo(contentIds));
    final UnpublishContentsResult.Builder resultBuilder = UnpublishContentsResult.create().addUnpublished(contentIds);
    if (contentIds.getSize() == 1) {
        draftContext.callWith(() -> {
            resultBuilder.setContentPath(this.getContent(contentIds.first()).getPath());
            return null;
        });
    }
    final UnpublishContentsResult result = resultBuilder.build();
    removePendingDeleteFromDraft(result);
    return result;
}
Also used : Context(com.enonic.xp.context.Context) UnpublishContentsResult(com.enonic.xp.content.UnpublishContentsResult) ContentIds(com.enonic.xp.content.ContentIds) ContentId(com.enonic.xp.content.ContentId)

Example 13 with ContentIds

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

the class ContentOutboundDependenciesIdsResolverTest method resolve_content_processed_ids.

@Test
public void resolve_content_processed_ids() throws Exception {
    final ContentId ref = ContentId.from("ref1");
    final Content content = Content.create(createContent("folderRefContent1", new PropertyTree(), ContentTypeName.folder())).addProcessedReference(ref).build();
    Mockito.when(contentService.getById(content.getId())).thenReturn(content);
    final ContentIds result = resolver.resolve(content.getId());
    assertEquals(result.getSize(), 1);
    assertEquals(result.first(), ref);
}
Also used : Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIds(com.enonic.xp.content.ContentIds) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 14 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)

Example 15 with ContentIds

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

the class ContentNodeHelperTest method toContentIds.

@Test
public void toContentIds() {
    final NodeIds nodeIds = NodeIds.from("e1f57280-d672-4cd8-b674-98e26e5b69ae", "45d67001-7f2b-4093-99ae-639be9fdd1f6");
    final ContentIds contentIds = ContentNodeHelper.toContentIds(nodeIds);
    assertEquals(ContentIds.from("e1f57280-d672-4cd8-b674-98e26e5b69ae", "45d67001-7f2b-4093-99ae-639be9fdd1f6"), contentIds);
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) ContentIds(com.enonic.xp.content.ContentIds) 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