Exemplo n.º 1
0
  @Override
  public Node deleteByPath(final NodePath path) {
    final MockNodeTree<NodePath> treeNode = nodeTree.find(path);
    treeNode.getParent().children.remove(treeNode);

    final Node toBeRemoved = this.nodePathMap.get(path);

    this.nodePathMap.remove(path);
    this.nodeIdMap.remove(toBeRemoved.id());

    return toBeRemoved;
  }
Exemplo n.º 2
0
  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;
  }