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