Ejemplo n.º 1
0
  private NodePath verifyNodeNotExistAtNewPath(final Node nodeToBeRenamed) {
    final NodePath parentPath = nodeToBeRenamed.parentPath().asAbsolute();
    final NodePath targetPath = new NodePath(parentPath, params.getNewNodeName());
    final Node existingNodeAtTargetPath =
        GetNodeByPathCommand.create(this).nodePath(targetPath).build().execute();

    if ((existingNodeAtTargetPath != null)
        && !nodeToBeRenamed.id().equals(existingNodeAtTargetPath.id())) {
      throw new NodeAlreadyExistAtPathException(targetPath);
    }

    return parentPath;
  }
Ejemplo n.º 2
0
  public MoveNodeResult execute() {
    final NodeId nodeId = params.getNodeId();

    final Node nodeToBeRenamed = doGetById(nodeId);

    if (nodeToBeRenamed == null) {
      throw new NodeNotFoundException("cannot rename node with id [" + nodeId + "]");
    }

    if (nodeToBeRenamed.isRoot()) {
      throw new OperationNotPermittedException("Not allowed to rename root-node");
    }

    final NodePath parentPath = verifyNodeNotExistAtNewPath(nodeToBeRenamed);

    return MoveNodeCommand.create(this)
        .id(params.getNodeId())
        .newParent(parentPath)
        .newNodeName(params.getNewNodeName())
        .build()
        .execute();
  }