use of com.enonic.xp.content.DeleteContentsResult in project xp by enonic.
the class ContentServiceImpl method deleteWithoutFetch.
@Override
public DeleteContentsResult deleteWithoutFetch(final DeleteContentParams params) {
final DeleteContentsResult result = DeleteContentCommand.create().nodeService(this.nodeService).contentTypeService(this.contentTypeService).translator(this.translator).eventPublisher(this.eventPublisher).params(params).build().execute();
contentAuditLogSupport.delete(params, result);
return result;
}
use of com.enonic.xp.content.DeleteContentsResult in project xp by enonic.
the class DeleteContentCommand method doDeleteContent.
private DeleteContentsResult doDeleteContent(NodeId nodeToDelete) {
final CompareStatus rootNodeStatus = getCompareStatus(nodeToDelete);
final DeleteContentsResult.Builder result = DeleteContentsResult.create();
if (rootNodeStatus == CompareStatus.NEW) {
// Root node is new, just delete all children
final NodeIds nodes = this.nodeService.deleteById(nodeToDelete, this);
result.addDeleted(ContentIds.from(nodes.getAsStrings()));
} else if (this.params.isDeleteOnline()) {
deleteNodeInDraftAndMaster(nodeToDelete, result);
} else {
this.nodeService.setNodeState(SetNodeStateParams.create().nodeId(nodeToDelete).nodeState(NodeState.PENDING_DELETE).build());
result.addPending(ContentId.from(nodeToDelete.toString()));
this.nodesDeleted(1);
final NodeIds children = getDirectChildren(nodeToDelete);
for (final NodeId child : children) {
final DeleteContentsResult childDeleteResult = this.doDeleteContent(child);
result.addDeleted(childDeleteResult.getDeletedContents());
result.addPending(childDeleteResult.getPendingContents());
}
}
return result.build();
}
use of com.enonic.xp.content.DeleteContentsResult in project xp by enonic.
the class PublishContentCommand method doDeleteNodes.
private void doDeleteNodes(final NodeIds nodeIdsToDelete) {
final ContentIds.Builder deleted = ContentIds.create();
final ContentIds.Builder unpublished = ContentIds.create();
totalToDelete(nodeIdsToDelete.getSize());
nodeIdsToDelete.forEach((id) -> {
if (nodeService.nodeExists(id)) {
final Node nodeToDelete = nodeService.getById(id);
final ContentPath contentPathToDelete = ContentNodeHelper.translateNodePathToContentPath(nodeToDelete.path());
final DeleteContentsResult deleteResult = DeleteContentCommand.create().contentTypeService(contentTypeService).nodeService(nodeService).translator(translator).eventPublisher(eventPublisher).params(DeleteContentParams.create().deleteOnline(true).contentPath(contentPathToDelete).build()).build().execute();
deleted.addAll(deleteResult.getDeletedContents());
unpublished.addAll(deleteResult.getUnpublishedContents());
if (nodeIdsToDelete.getSize() == 1) {
this.resultBuilder.setDeletedPath(contentPathToDelete);
}
}
nodesDeleted(1);
});
nodesPushed(nodeIdsToDelete.getSize());
this.resultBuilder.setDeleted(deleted.build());
this.resultBuilder.setUnpublishedContents(unpublished.build());
}
use of com.enonic.xp.content.DeleteContentsResult in project xp by enonic.
the class ContentServiceImplTest_delete method move_to_folder_starting_with_same_name_and_delete.
@Test
public void move_to_folder_starting_with_same_name_and_delete() throws Exception {
final Content site = createContent(ContentPath.ROOT, "site");
final Content child1 = createContent(site.getPath(), "child1");
createContent(child1.getPath(), "child1_1");
createContent(child1.getPath(), "child2_1");
final Content site2 = createContent(ContentPath.ROOT, "site2");
refresh();
final MoveContentParams params = MoveContentParams.create().contentId(child1.getId()).parentContentPath(site2.getPath()).build();
this.contentService.move(params);
final DeleteContentsResult result = this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(site.getPath()).build());
assertEquals(1, result.getDeletedContents().getSize());
}
use of com.enonic.xp.content.DeleteContentsResult 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());
}
Aggregations