Search in sources :

Example 16 with DeleteContentsResult

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);
    }
}
Also used : NodeAccessException(com.enonic.xp.node.NodeAccessException) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) ContentAccessException(com.enonic.xp.content.ContentAccessException)

Example 17 with DeleteContentsResult

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;
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) NodeIds(com.enonic.xp.node.NodeIds) Node(com.enonic.xp.node.Node) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) NodePath(com.enonic.xp.node.NodePath)

Aggregations

DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)17 Content (com.enonic.xp.content.Content)12 Test (org.junit.jupiter.api.Test)12 PropertyTree (com.enonic.xp.data.PropertyTree)11 CreateContentParams (com.enonic.xp.content.CreateContentParams)9 PublishContentResult (com.enonic.xp.content.PublishContentResult)5 ContentIds (com.enonic.xp.content.ContentIds)4 Contents (com.enonic.xp.content.Contents)4 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)4 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)3 Node (com.enonic.xp.node.Node)2 NodeIds (com.enonic.xp.node.NodeIds)2 CompareStatus (com.enonic.xp.content.CompareStatus)1 ContentAccessException (com.enonic.xp.content.ContentAccessException)1 ContentId (com.enonic.xp.content.ContentId)1 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)1 ContentPath (com.enonic.xp.content.ContentPath)1 MoveContentParams (com.enonic.xp.content.MoveContentParams)1 PushContentParams (com.enonic.xp.content.PushContentParams)1 NodeAccessException (com.enonic.xp.node.NodeAccessException)1