Exemple #1
0
  protected Node createNode(final NodePath parentPath, final String name) {
    final PropertyTree data = new PropertyTree();
    data.setString("displayName", "This is brand new node");
    final PropertySet someData = data.addSet("someData");
    someData.setString("cars", "skoda");
    someData.addString("cars", "tesla model x");
    someData.setString("likes", "plywood");
    someData.setLong("numberOfUselessGadgets", 123L);

    final PatternIndexConfigDocument indexConfig =
        PatternIndexConfigDocument.create()
            .defaultConfig(IndexConfig.MINIMAL)
            .add("displayName", IndexConfig.FULLTEXT)
            .build();

    return Node.create()
        .id(NodeId.from("nodeId"))
        .parentPath(parentPath)
        .name(name)
        .data(data)
        .indexConfigDocument(indexConfig)
        .permissions(
            AccessControlList.create()
                .add(
                    AccessControlEntry.create()
                        .principal(PrincipalKey.ofRole("admin"))
                        .allowAll()
                        .build())
                .build())
        .nodeState(NodeState.DEFAULT)
        .nodeVersionId(NodeVersionId.from("versionKey"))
        .timestamp(Instant.parse("2010-10-10T10:10:10.10Z"))
        .build();
  }
Exemple #2
0
 protected NodeBranchEntry createEntry(final String id) {
   return NodeBranchEntry.create()
       .nodeId(NodeId.from(id))
       .nodeState(NodeState.DEFAULT)
       .nodePath(NodePath.create(NodePath.ROOT + id).build())
       .build();
 }
Exemple #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;
  }
  private void createWithTitleAndDescription(
      final String id, final String title, final String description) {
    final PropertyTree data = new PropertyTree();
    data.addString("title", title);
    if (!Strings.isNullOrEmpty(description)) {
      data.addString("description", description);
    }

    createNode(
        CreateNodeParams.create()
            .setNodeId(NodeId.from(id))
            .name(title)
            .parent(NodePath.ROOT)
            .data(data)
            .indexConfigDocument(
                PatternIndexConfigDocument.create()
                    .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER)
                    .defaultConfig(IndexConfig.BY_TYPE)
                    .build())
            .build());
  }
  @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++;
    }
  }