Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
  @Override
  public Node deleteById(final NodeId id) {
    final Node toBeRemoved = this.nodeIdMap.get(id);

    final MockNodeTree<NodePath> treeNode = nodeTree.find(toBeRemoved.path());
    treeNode.getParent().children.remove(treeNode);

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

    return toBeRemoved;
  }
  @Test
  public void only_in_source_with_path() throws Exception {
    final Node node =
        createNode(CreateNodeParams.create().name("mynode").parent(NodePath.ROOT).build());

    printBranchIndex();

    final Node child1 =
        createNode(CreateNodeParams.create().name("mynode").parent(node.path()).build());

    final Node child1_1 =
        createNode(CreateNodeParams.create().name("mynode").parent(child1.path()).build());

    final Node child1_1_1 =
        createNode(CreateNodeParams.create().name("mynode").parent(child1_1.path()).build());

    assertEquals(
        5, getDiff(WS_DEFAULT, WS_OTHER, NodePath.ROOT).getNodesWithDifferences().getSize());
    assertEquals(4, getDiff(WS_DEFAULT, WS_OTHER, node.path()).getNodesWithDifferences().getSize());
    assertEquals(
        3, getDiff(WS_DEFAULT, WS_OTHER, child1.path()).getNodesWithDifferences().getSize());
    assertEquals(
        2, getDiff(WS_DEFAULT, WS_OTHER, child1_1.path()).getNodesWithDifferences().getSize());
    assertEquals(
        1, getDiff(WS_DEFAULT, WS_OTHER, child1_1_1.path()).getNodesWithDifferences().getSize());

    doPushNode(WS_OTHER, node);
    doPushNode(WS_OTHER, child1);
    doPushNode(WS_OTHER, child1_1);

    assertEquals(1, getDiff(WS_DEFAULT, WS_OTHER, node.path()).getNodesWithDifferences().getSize());
  }
 private void doMoveNode(final Node node, final Node newParent) {
   MoveNodeCommand.create()
       .newParent(newParent.path())
       .id(node.id())
       .indexServiceInternal(this.indexServiceInternal)
       .storageService(this.storageService)
       .searchService(this.searchService)
       .build()
       .execute();
 }
Ejemplo n.º 5
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;
  }
Ejemplo n.º 6
0
  private void processNodeFolder(
      final VirtualFile nodeFolder, final ProcessNodeSettings.Builder processNodeSettings) {
    try {
      final Node node = processNodeSource(nodeFolder, processNodeSettings);

      try {
        if (!node.getChildOrder().isManualOrder()) {
          importFromDirectoryLayout(nodeFolder);
        } else {
          importFromManualOrder(nodeFolder);
        }
      } catch (Exception e) {
        result.addError("Error when parsing children of " + node.path(), e);
      }

    } catch (Exception e) {
      result.addError(
          "Could not import node in folder ["
              + nodeFolder.getPath().getPath()
              + "]: "
              + e.getMessage(),
          e);
    }
  }
  @Test
  public void assure_correct_diff_order_when_there_are_children() {
    final Node node1 =
        createNode(
            CreateNodeParams.create()
                .setNodeId(NodeId.from("dddd"))
                .parent(NodePath.ROOT)
                .name("dddd")
                .build());

    final Node node1_1 =
        createNode(
            CreateNodeParams.create()
                .setNodeId(NodeId.from("ccc"))
                .parent(node1.path())
                .name("ccc")
                .build());

    final Node node1_1_1 =
        createNode(
            CreateNodeParams.create()
                .setNodeId(NodeId.from("11"))
                .parent(node1_1.path())
                .name("11")
                .build());

    final Node node1_1_1_1 =
        createNode(
            CreateNodeParams.create()
                .setNodeId(NodeId.from("_a"))
                .parent(node1_1_1.path())
                .name("_a")
                .build());

    final Node node2 =
        createNode(
            CreateNodeParams.create()
                .setNodeId(NodeId.from("node2"))
                .parent(NodePath.ROOT)
                .name("node2")
                .build());

    pushNodes(WS_OTHER, node1.id(), node1_1_1_1.id(), node1_1_1.id(), node1_1.id(), node2.id());

    CTX_OTHER.runWith(() -> doUpdateNode(node1_1_1_1));
    CTX_OTHER.runWith(() -> doUpdateNode(node1_1_1));
    CTX_OTHER.runWith(() -> doUpdateNode(node1_1));
    CTX_OTHER.runWith(() -> doUpdateNode(node1));

    NodeVersionDiffResult result = getDiff(WS_DEFAULT, WS_OTHER, node1.path());

    assertEquals(4, result.getNodesWithDifferences().getSize());

    int counter = 0;
    for (final NodeId nodeId : result.getNodesWithDifferences()) {
      if (counter == 0) {
        assertEquals("dddd", nodeId.toString());
      } else if (counter == 1) {
        assertEquals("ccc", nodeId.toString());
      } else if (counter == 2) {
        assertEquals("11", nodeId.toString());
      } else if (counter == 3) {
        assertEquals("_a", nodeId.toString());
      }

      counter++;
    }
  }