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; }
@Override public Node importNode(final ImportNodeParams params) { final Node importNode = params.getNode(); return doCreate( CreateNodeParams.create() .setBinaryAttachments(params.getBinaryAttachments()) .childOrder(importNode.getChildOrder()) .data(importNode.data()) .indexConfigDocument(importNode.getIndexConfigDocument()) .insertManualStrategy(params.getInsertManualStrategy()) .manualOrderValue(importNode.getManualOrderValue()) .name(importNode.name().toString()) .parent(importNode.parentPath()) .setNodeId(importNode.id()) .permissions(importNode.getPermissions()) .build(), importNode.getTimestamp()); }
private Node doCreate(final CreateNodeParams params, final Instant timestamp) { final Node.Builder builder = Node.create() .id(params.getNodeId() != null ? params.getNodeId() : NodeId.from(System.nanoTime())) .name(NodeName.from(params.getName())) .parentPath(params.getParent()) .timestamp(timestamp != null ? timestamp : null) .manualOrderValue(params.getManualOrderValue()) .childOrder(params.getChildOrder()); final AttachedBinaries.Builder attachmentBuilder = AttachedBinaries.create(); for (final BinaryAttachment binaryAttachment : params.getBinaryAttachments()) { final String blobKey = binaryAttachment.getReference().toString(); attachmentBuilder.add(new AttachedBinary(binaryAttachment.getReference(), blobKey)); blobStore.put(binaryAttachment.getReference(), binaryAttachment.getByteSource()); } builder.attachedBinaries(attachmentBuilder.build()); final Node createdNode = builder.build(); nodeIdMap.putIfAbsent(createdNode.id(), createdNode); // LOG.info( "Store id " + createdNode.id() ); nodePathMap.putIfAbsent(createdNode.path(), createdNode); // LOG.info( "Store path " + createdNode.path() ); final MockNodeTree<NodePath> nodePathTreeNode = this.nodeTree.find(createdNode.parentPath()); if (nodePathTreeNode == null) { LOG.error( "Could not find nodePathTreeNode for created node: " + createdNode.path() + ", node not inserted in tree"); return createdNode; } nodePathTreeNode.addChild(createdNode.path()); return createdNode; }