Search in sources :

Example 1 with PublishContentResult

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

the class PublishContentHandler method publishContent.

private PublishContentResultMapper publishContent() {
    final List<ContentPath> contentNotFound = new ArrayList<>();
    final List<ContentId> contentIds = new ArrayList<>();
    for (final String key : this.keys) {
        if (key.startsWith("/")) {
            final ContentPath path = ContentPath.from(key);
            final Content content = getByPath(path);
            if (content != null) {
                contentIds.add(content.getId());
            } else {
                contentNotFound.add(path);
            }
        } else {
            contentIds.add(ContentId.from(key));
        }
    }
    final PushContentParams.Builder builder = PushContentParams.create();
    builder.contentIds(ContentIds.from(contentIds));
    builder.target(Branch.from(targetBranch));
    if (this.contentPublishInfo != null) {
        final Object from = this.contentPublishInfo.get("from");
        final Object to = this.contentPublishInfo.get("to");
        final ContentPublishInfo contentPublishInfo = ContentPublishInfo.create().from(from == null ? null : Instant.parse((String) from)).to(to == null ? null : Instant.parse((String) to)).build();
        builder.contentPublishInfo(contentPublishInfo);
    }
    if (this.excludeChildrenIds != null) {
        builder.excludeChildrenIds(ContentIds.from(this.excludeChildrenIds));
    }
    if (this.includeChildren != null) {
        builder.includeChildren(this.includeChildren);
    }
    if (this.includeDependencies != null) {
        builder.includeDependencies(includeDependencies);
    }
    builder.message(message);
    final PublishContentResult result = this.contentService.publish(builder.build());
    return result != null ? new PublishContentResultMapper(result, contentNotFound) : null;
}
Also used : ArrayList(java.util.ArrayList) ContentPath(com.enonic.xp.content.ContentPath) PublishContentResultMapper(com.enonic.xp.lib.content.mapper.PublishContentResultMapper) PushContentParams(com.enonic.xp.content.PushContentParams) PublishContentResult(com.enonic.xp.content.PublishContentResult) Content(com.enonic.xp.content.Content) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) ContentId(com.enonic.xp.content.ContentId)

Example 2 with PublishContentResult

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

the class PublishContentHandlerTest method publishWithoutChildrenOrDependencies.

@Test
public void publishWithoutChildrenOrDependencies() {
    Contents published = Contents.from(exampleContent(PUB_ID_3, "mycontent", "My Content", "/mysite/somepage", "myfield", "Hello World"));
    PublishContentResult exampleResult = PublishContentResult.create().setPushed(published.getIds()).build();
    ContentIds ids = ContentIds.from(PUB_ID_3);
    PushContentParams pushParams = PushContentParams.create().contentIds(ids).target(Branch.from("master")).excludeChildrenIds(ids).includeDependencies(false).build();
    Mockito.when(this.contentService.publish(pushParams)).thenReturn(exampleResult);
    runFunction("/test/PublishContentHandlerTest.js", "publishWithoutChildrenOrDependencies");
}
Also used : PublishContentResult(com.enonic.xp.content.PublishContentResult) Contents(com.enonic.xp.content.Contents) ContentIds(com.enonic.xp.content.ContentIds) PushContentParams(com.enonic.xp.content.PushContentParams) Test(org.junit.jupiter.api.Test)

Example 3 with PublishContentResult

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

the class ContentServiceImplTest_delete method create_delete_published_content.

@Test
public void create_delete_published_content() throws Exception {
    final Content content = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").name("myContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build());
    refresh();
    final PublishContentResult result = this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).build());
    assertEquals(1, result.getPushedContents().getSize());
    // Deletes the content
    final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(content.getPath()).build();
    final DeleteContentsResult deletedContents = this.contentService.deleteWithoutFetch(deleteContentParams);
    assertNotNull(deletedContents);
    assertEquals(1, deletedContents.getPendingContents().getSize());
    for (ContentId deletedContent : deletedContents.getPendingContents()) {
        assertTrue(NodeState.PENDING_DELETE == this.nodeService.getById(NodeId.from(deletedContent)).getNodeState());
    }
    // Checks that the content is marked for deletion
    final Content foundContent = this.contentService.getById(content.getId());
    assertTrue(ContentState.PENDING_DELETE == foundContent.getContentState());
}
Also used : DeleteContentParams(com.enonic.xp.content.DeleteContentParams) PublishContentResult(com.enonic.xp.content.PublishContentResult) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentId(com.enonic.xp.content.ContentId) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Example 4 with PublishContentResult

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

the class ContentServiceImplTest_delete method publish_pending_content_with_child_moved_inside_the_tree.

@Test
public void publish_pending_content_with_child_moved_inside_the_tree() 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 createMovedContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Content to move").parent(child1Content.getPath()).type(ContentTypeName.folder()).build();
    final Content contentToMove = this.contentService.create(createMovedContentParams);
    refresh();
    this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(contentToMove.getId())).target(WS_OTHER).build());
    refresh();
    this.contentService.move(MoveContentParams.create().contentId(contentToMove.getId()).parentContentPath(content.getPath()).build());
    refresh();
    DeleteContentsResult result = this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(content.getPath()).build());
    assertEquals(3, result.getPendingContents().getSize());
    final PublishContentResult publishResult = this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).includeDependencies(false).build());
    assertEquals(3, publishResult.getUnpublishedContents().getSize());
    assertEquals(3, publishResult.getDeletedContents().getSize());
}
Also used : PublishContentResult(com.enonic.xp.content.PublishContentResult) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Example 5 with PublishContentResult

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

the class ContentServiceImplTest_delete method publish_pending_content_with_excluded_child_moved_out_of_tree.

@Test
public void publish_pending_content_with_excluded_child_moved_out_of_tree() 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 createMovedContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Content to move").parent(child1Content.getPath()).type(ContentTypeName.folder()).build();
    final Content contentToMove = this.contentService.create(createMovedContentParams);
    refresh();
    this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(contentToMove.getId())).target(WS_OTHER).build());
    refresh();
    this.contentService.move(MoveContentParams.create().contentId(contentToMove.getId()).parentContentPath(ContentPath.ROOT).build());
    refresh();
    DeleteContentsResult result = this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(content.getPath()).build());
    assertEquals(2, result.getPendingContents().getSize());
    final PublishContentResult publishResult = this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).includeDependencies(false).excludedContentIds(ContentIds.from(contentToMove.getId())).build());
    assertEquals(0, publishResult.getPushedContents().getSize());
    assertEquals(2, publishResult.getDeletedContents().getSize());
    assertEquals(3, publishResult.getUnpublishedContents().getSize());
}
Also used : PublishContentResult(com.enonic.xp.content.PublishContentResult) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Aggregations

PublishContentResult (com.enonic.xp.content.PublishContentResult)21 Test (org.junit.jupiter.api.Test)19 Content (com.enonic.xp.content.Content)12 PropertyTree (com.enonic.xp.data.PropertyTree)11 PushContentParams (com.enonic.xp.content.PushContentParams)10 CreateContentParams (com.enonic.xp.content.CreateContentParams)7 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)5 Disabled (org.junit.jupiter.api.Disabled)3 ContentId (com.enonic.xp.content.ContentId)2 ContentIds (com.enonic.xp.content.ContentIds)2 Contents (com.enonic.xp.content.Contents)2 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)1 ContentPath (com.enonic.xp.content.ContentPath)1 ContentPublishInfo (com.enonic.xp.content.ContentPublishInfo)1 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)1 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)1 PropertySet (com.enonic.xp.data.PropertySet)1 PublishContentResultMapper (com.enonic.xp.lib.content.mapper.PublishContentResultMapper)1 ContentType (com.enonic.xp.schema.content.ContentType)1 ArrayList (java.util.ArrayList)1