use of com.enonic.xp.content.DeleteContentsResult in project xp by enonic.
the class DeleteContentCommand method execute.
DeleteContentsResult execute() {
params.validate();
try {
final DeleteContentsResult deletedContents = doExecute();
nodeService.refresh(RefreshMode.SEARCH);
return deletedContents;
} catch (NodeAccessException e) {
throw new ContentAccessException(e);
}
}
use of com.enonic.xp.content.DeleteContentsResult in project xp by enonic.
the class DeleteContentCommand method doExecute.
private DeleteContentsResult doExecute() {
this.nodeService.refresh(RefreshMode.ALL);
final NodePath nodePath = ContentNodeHelper.translateContentPathToNodePath(this.params.getContentPath());
final Node nodeToDelete = this.nodeService.getByPath(nodePath);
if (nodeToDelete == null) {
throw new ContentNotFoundException(this.params.getContentPath(), ContextAccessor.current().getBranch());
}
if (!params.isDeleteOnline()) {
final NodeIds draftChildren = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(nodeToDelete.id()).recursive(true).build()).getNodeIds();
final boolean anyChildIsMovedIn = nodeService.compare(draftChildren, ContentConstants.BRANCH_MASTER).getComparisons().stream().anyMatch(nodeComparison -> {
final boolean moved = CompareStatus.MOVED.equals(nodeComparison.getCompareStatus());
return moved && !nodeComparison.getTargetPath().asAbsolute().toString().startsWith(nodePath.asAbsolute().toString());
});
if (anyChildIsMovedIn) {
throw new RuntimeException(String.format("Cannot make content tree pending delete for [%s], at least one published child is moved in from outside.", nodeToDelete.id()));
}
}
final DeleteContentsResult deletedContents = doDeleteContent(nodeToDelete.id());
this.nodeService.refresh(RefreshMode.ALL);
return deletedContents;
}
Aggregations