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;
}
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");
}
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());
}
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());
}
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());
}
Aggregations