Пример #1
0
  private Node processNodeSource(
      final VirtualFile nodeFolder, final ProcessNodeSettings.Builder processNodeSettings) {
    final VirtualFile nodeSource = this.exportReader.getNodeSource(nodeFolder);

    final Node.Builder newNodeBuilder = Node.create();
    try {
      final XmlNodeParser parser = new XmlNodeParser();
      parser.builder(newNodeBuilder);
      parser.source(nodeSource.getCharSource());
      parser.parse();
    } catch (final Exception e) {
      throw new XmlException(e, "Could not load source node [" + nodeSource.getUrl() + "]: ", e);
    }

    final Node newNode = newNodeBuilder.build();

    final NodePath importNodePath =
        NodeImportPathResolver.resolveNodeImportPath(nodeFolder, this.exportRoot, this.importRoot);

    final boolean isNodeExisting = this.nodeService.getByPath(importNodePath) != null;
    final Node importedNode = importNode(nodeFolder, processNodeSettings, newNode, importNodePath);

    if (isNodeExisting) {
      result.updated(importedNode.path());
    } else {
      result.added(importedNode.path());
    }

    return importedNode;
  }
Пример #2
0
  @Override
  public Node update(final UpdateNodeParams params) {
    final Node persistedNode = nodeIdMap.get(params.getId());
    final EditableNode editableNode = new EditableNode(persistedNode);
    params.getEditor().edit(editableNode);

    final Node editedNode = editableNode.build();
    if (editedNode.equals(persistedNode)) {
      return persistedNode;
    }

    final Node.Builder updateNodeBuilder =
        Node.create(editedNode).permissions(persistedNode.getPermissions());

    return updateNodeBuilder.build();
  }
Пример #3
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;
  }