Search in sources :

Example 1 with ContentAlreadyMovedException

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

the class MoveContentCommand method doExecute.

private MoveContentsResult doExecute() {
    final ContentId contentId = params.getContentId();
    final Content sourceContent = getContent(contentId);
    final NodePath newParentPath = ContentNodeHelper.translateContentPathToNodePath(params.getParentContentPath());
    if (nodeService.nodeExists(NodePath.create(newParentPath, sourceContent.getName().toString()).build())) {
        throw new ContentAlreadyMovedException(String.format("Content with name [%s] is already a child of [%s]", sourceContent.getName(), params.getParentContentPath()), sourceContent.getPath());
    }
    validateParentChildRelations(params.getParentContentPath(), sourceContent.getType());
    final NodeId sourceNodeId = NodeId.from(contentId);
    final MoveNodeParams.Builder builder = MoveNodeParams.create().nodeId(sourceNodeId).parentNodePath(newParentPath).moveListener(this);
    if (params.stopInherit()) {
        builder.processor(new MoveContentProcessor());
    }
    final Node movedNode = nodeService.move(builder.build());
    final Content movedContent = translator.fromNode(movedNode, true);
    return MoveContentsResult.create().setContentName(movedContent.getDisplayName()).addMoved(movedContent.getId()).build();
}
Also used : MoveNodeParams(com.enonic.xp.node.MoveNodeParams) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) ContentId(com.enonic.xp.content.ContentId) ContentAlreadyMovedException(com.enonic.xp.content.ContentAlreadyMovedException) NodePath(com.enonic.xp.node.NodePath)

Aggregations

Content (com.enonic.xp.content.Content)1 ContentAlreadyMovedException (com.enonic.xp.content.ContentAlreadyMovedException)1 ContentId (com.enonic.xp.content.ContentId)1 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)1 Node (com.enonic.xp.node.Node)1 NodeId (com.enonic.xp.node.NodeId)1 NodePath (com.enonic.xp.node.NodePath)1