Search in sources :

Example 26 with ContentIds

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

the class ContentOutboundDependenciesIdsResolverTest method resolve_outbound_with_missing_dependency.

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

Example 27 with ContentIds

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

the class ContentOutboundDependenciesIdsResolverTest method resolve_outbound_dependencies.

@Test
public void resolve_outbound_dependencies() 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", data, ContentTypeName.site());
    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) Test(org.junit.jupiter.api.Test)

Example 28 with ContentIds

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

the class AbstractContentServiceTest method assertOrder.

protected void assertOrder(final FindContentByQueryResult result, final Content... expectedOrder) {
    final ContentIds contentIds = result.getContents().getIds();
    doAssertOrder(contentIds, expectedOrder);
}
Also used : ContentIds(com.enonic.xp.content.ContentIds)

Example 29 with ContentIds

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

the class UnpublishContentHandlerTest method unpublishByPath.

@Test
public void unpublishByPath() {
    final Content myContent = exampleContent(PUB_ID_2, "mycontent", "My Content", "/myfolder/mycontent", "myfield", "Hello World");
    Mockito.when(this.contentService.getByPath(ContentPath.from("/myfolder/mycontent"))).thenReturn(myContent);
    final Content yourContent = exampleContent(PUB_ID_3, "yourcontent", "Your Content", "/yourfolder/yourcontent", "yourfield", "Hello Universe!");
    Mockito.when(this.contentService.getByPath(ContentPath.from("/yourfolder/yourcontent"))).thenReturn(yourContent);
    ContentIds ids = ContentIds.from(PUB_ID_2, PUB_ID_3);
    UnpublishContentParams unpublishParams = UnpublishContentParams.create().contentIds(ids).unpublishBranch(ContentConstants.BRANCH_MASTER).includeChildren(true).build();
    Mockito.when(this.contentService.unpublishContent(unpublishParams)).thenReturn(exampleResult());
    runFunction("/test/UnpublishContentHandlerTest.js", "unpublishByPath");
}
Also used : Content(com.enonic.xp.content.Content) UnpublishContentParams(com.enonic.xp.content.UnpublishContentParams) ContentIds(com.enonic.xp.content.ContentIds) Test(org.junit.jupiter.api.Test)

Example 30 with ContentIds

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

the class UnpublishContentCommand method removePublishInfo.

private Void removePublishInfo(final ContentIds contentIds) {
    final Instant now = Instant.now();
    for (final ContentId contentId : contentIds) {
        this.nodeService.update(UpdateNodeParams.create().editor(toBeEdited -> {
            if (toBeEdited.data.getInstant(ContentPropertyNames.PUBLISH_INFO + PropertyPath.ELEMENT_DIVIDER + ContentPropertyNames.PUBLISH_FROM) != null) {
                PropertySet publishInfo = toBeEdited.data.getSet(ContentPropertyNames.PUBLISH_INFO);
                if (publishInfo.hasProperty(ContentPropertyNames.PUBLISH_FROM)) {
                    publishInfo.removeProperty(ContentPropertyNames.PUBLISH_FROM);
                }
                if (publishInfo.hasProperty(ContentPropertyNames.PUBLISH_TO)) {
                    publishInfo.removeProperty(ContentPropertyNames.PUBLISH_TO);
                }
                if (publishInfo.getInstant(ContentPropertyNames.PUBLISH_FIRST).compareTo(Instant.now()) > 0) {
                    publishInfo.removeProperty(ContentPropertyNames.PUBLISH_FIRST);
                }
            }
        }).id(NodeId.from(contentId)).build());
        commitUnpublishedNode(contentId);
    }
    return null;
}
Also used : RefreshMode(com.enonic.xp.node.RefreshMode) Nodes(com.enonic.xp.node.Nodes) ContentConstants(com.enonic.xp.content.ContentConstants) ContentPropertyNames(com.enonic.xp.content.ContentPropertyNames) ContentState(com.enonic.xp.content.ContentState) PropertySet(com.enonic.xp.data.PropertySet) Node(com.enonic.xp.node.Node) UnpublishContentParams(com.enonic.xp.content.UnpublishContentParams) Instant(java.time.Instant) Branch(com.enonic.xp.branch.Branch) NodeId(com.enonic.xp.node.NodeId) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) ContentId(com.enonic.xp.content.ContentId) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) ContentIds(com.enonic.xp.content.ContentIds) ContextAccessor(com.enonic.xp.context.ContextAccessor) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Preconditions(com.google.common.base.Preconditions) UnpublishContentsResult(com.enonic.xp.content.UnpublishContentsResult) Context(com.enonic.xp.context.Context) ContextBuilder(com.enonic.xp.context.ContextBuilder) PropertyPath(com.enonic.xp.data.PropertyPath) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) NodeIds(com.enonic.xp.node.NodeIds) Instant(java.time.Instant) PropertySet(com.enonic.xp.data.PropertySet) ContentId(com.enonic.xp.content.ContentId)

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