@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());
  }
  @Test
  public void negate() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addString("title", "fisk kake");

    final Node node =
        createNode(
            CreateNodeParams.create()
                .name("my-node-1")
                .parent(NodePath.ROOT)
                .data(data)
                .indexConfigDocument(
                    PatternIndexConfigDocument.create()
                        .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER)
                        .defaultConfig(IndexConfig.BY_TYPE)
                        .build())
                .build());

    final PropertyTree data2 = new PropertyTree();
    data2.addString("title", "fisk båt");

    createNode(
        CreateNodeParams.create()
            .name("my-node-2")
            .parent(NodePath.ROOT)
            .data(data2)
            .indexConfigDocument(
                PatternIndexConfigDocument.create()
                    .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER)
                    .defaultConfig(IndexConfig.BY_TYPE)
                    .build())
            .build());

    final NodeQuery query =
        NodeQuery.create()
            .query(
                QueryExpr.from(
                    new DynamicConstraintExpr(
                        FunctionExpr.from(
                            "fulltext",
                            ValueExpr.string("title"),
                            ValueExpr.string("fisk -båt"),
                            ValueExpr.string("AND")))))
            .build();

    final FindNodesByQueryResult result = doFindByQuery(query);

    assertEquals(1, result.getNodes().getSize());
    assertNotNull(result.getNodes().getNodeById(node.id()));
  }
  @Test
  public void fulltext() throws Exception {
    final Node node =
        createNode(
            CreateNodeParams.create()
                .name("my-node-1")
                .parent(NodePath.ROOT)
                .indexConfigDocument(
                    PatternIndexConfigDocument.create()
                        .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER)
                        .defaultConfig(IndexConfig.BY_TYPE)
                        .build())
                .build());

    final NodeQuery query =
        NodeQuery.create()
            .query(
                QueryExpr.from(
                    new DynamicConstraintExpr(
                        FunctionExpr.from(
                            "fulltext",
                            ValueExpr.string(NodeIndexPath.NAME.getPath()),
                            ValueExpr.string("My node name is my-node-1"),
                            ValueExpr.string("OR")))))
            .build();

    final FindNodesByQueryResult result = doFindByQuery(query);

    assertEquals(1, result.getNodes().getSize());
    assertNotNull(result.getNodes().getNodeById(node.id()));
  }
  @Test
  public void fulltext_wildcard_paths() throws Exception {
    final PropertyTree data = new PropertyTree();
    final String path1 = "test.of.string-1.with.path-1";
    final String value1 = "fisk ost pølse løk";
    data.setString(path1, value1);

    createNode(
        CreateNodeParams.create()
            .name("node1")
            .parent(NodePath.ROOT)
            .data(data)
            .indexConfigDocument(
                PatternIndexConfigDocument.create()
                    .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER)
                    .defaultConfig(IndexConfig.BY_TYPE)
                    .build())
            .build());

    final PropertyTree data2 = new PropertyTree();
    final String path2 = "test.of.string-2.with.path-2";
    final String value2 = "fisk ost pølse løk";
    data2.setString(path2, value2);

    createNode(
        CreateNodeParams.create()
            .name("node2")
            .parent(NodePath.ROOT)
            .data(data2)
            .indexConfigDocument(
                PatternIndexConfigDocument.create()
                    .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER)
                    .defaultConfig(IndexConfig.BY_TYPE)
                    .build())
            .build());

    queryAndAssert("fulltext('test*', 'leter etter fisk', 'OR')", 2);
    queryAndAssert("fulltext('test.*', 'leter etter fisk', 'OR')", 2);
    queryAndAssert("fulltext('test.of*', 'leter etter fisk', 'OR')", 2);
    queryAndAssert("fulltext('test.of.string*', 'leter etter fisk', 'OR')", 2);
    queryAndAssert("fulltext('test.of.string-1.*', 'leter etter fisk', 'OR')", 1);
    queryAndAssert("fulltext('test.of.string-2.*', 'leter etter fisk', 'OR')", 1);
    queryAndAssert("fulltext('*path*', 'leter etter fisk', 'OR')", 2);
    queryAndAssert("fulltext('*path', 'leter etter fisk', 'OR')", 0);
    queryAndAssert("fulltext('*path-1', 'leter etter fisk', 'OR')", 1);
    queryAndAssert("fulltext('*path-2', 'leter etter fisk', 'OR')", 1);
  }
  @Test
  public void fulltext_norwegian_characters() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addString("myProperty", "æ");
    final PropertySet userdata = data.addSet("data");
    userdata.addString("displayName", "ø å");

    final Node node =
        createNode(
            CreateNodeParams.create()
                .name("my-node-1")
                .parent(NodePath.ROOT)
                .data(data)
                .indexConfigDocument(
                    PatternIndexConfigDocument.create()
                        .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER)
                        .defaultConfig(IndexConfig.BY_TYPE)
                        .build())
                .build());

    refresh();

    printContentRepoIndex();

    final NodeQuery query =
        NodeQuery.create()
            .query(
                QueryExpr.from(
                    new DynamicConstraintExpr(
                        FunctionExpr.from(
                            "fulltext",
                            ValueExpr.string(NodeIndexPath.ALL_TEXT.getPath()),
                            ValueExpr.string("æ"),
                            ValueExpr.string("OR")))))
            .build();

    final FindNodesByQueryResult result = doFindByQuery(query);

    assertEquals(1, result.getNodes().getSize());
    assertNotNull(result.getNodes().getNodeById(node.id()));

    final NodeQuery query2 =
        NodeQuery.create()
            .query(
                QueryExpr.from(
                    new DynamicConstraintExpr(
                        FunctionExpr.from(
                            "fulltext",
                            ValueExpr.string("data.displayName"),
                            ValueExpr.string("ø å"),
                            ValueExpr.string("OR")))))
            .build();

    final FindNodesByQueryResult result2 = doFindByQuery(query2);

    assertEquals(1, result2.getNodes().getSize());
    assertNotNull(result2.getNodes().getNodeById(node.id()));
  }
  @Test
  public void deleted_in_target() throws Exception {
    final Node node =
        createNode(CreateNodeParams.create().name("mynode").parent(NodePath.ROOT).build());

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

    doPushNode(WS_OTHER, rootNode);
    doPushNode(WS_OTHER, node);
    doPushNode(WS_OTHER, node2);

    assertEquals(0, getDiff(WS_DEFAULT, WS_OTHER).getNodesWithDifferences().getSize());

    CTX_OTHER.runWith(() -> doDeleteNode(node.id()));

    assertEquals(1, getDiff(WS_DEFAULT, WS_OTHER).getNodesWithDifferences().getSize());
    assertEquals(1, getDiff(WS_OTHER, WS_DEFAULT).getNodesWithDifferences().getSize());
  }
  @Test
  public void moved_in_source() throws Exception {
    final Node node =
        createNode(CreateNodeParams.create().name("mynode").parent(NodePath.ROOT).build());

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

    doPushNode(WS_OTHER, rootNode);
    doPushNode(WS_OTHER, node);
    doPushNode(WS_OTHER, node2);

    assertEquals(0, getDiff(WS_DEFAULT, WS_OTHER).getNodesWithDifferences().getSize());

    doMoveNode(node, node2);

    assertEquals(1, getDiff(WS_DEFAULT, WS_OTHER).getNodesWithDifferences().getSize());
    assertEquals(1, getDiff(WS_OTHER, WS_DEFAULT).getNodesWithDifferences().getSize());
  }
  @Test
  public void same_version() throws Exception {
    final Node node =
        CTX_DEFAULT.callWith(
            () ->
                createNode(CreateNodeParams.create().name("mynode").parent(NodePath.ROOT).build()));

    doPushNode(WS_OTHER, rootNode);
    doPushNode(WS_OTHER, node);

    assertEquals(0, getDiff(WS_DEFAULT, WS_OTHER).getNodesWithDifferences().getSize());
    assertEquals(0, getDiff(WS_OTHER, WS_DEFAULT).getNodesWithDifferences().getSize());
  }
  @Test
  public void only_in_source() throws Exception {
    final Node node =
        createNode(CreateNodeParams.create().name("mynode").parent(NodePath.ROOT).build());

    refresh();

    assertEquals(2, getDiff(WS_DEFAULT, WS_OTHER).getNodesWithDifferences().getSize());

    doPushNode(WS_OTHER, node);
    doPushNode(WS_OTHER, this.rootNode);

    assertEquals(0, getDiff(WS_DEFAULT, WS_OTHER).getNodesWithDifferences().getSize());
    assertEquals(0, getDiff(WS_OTHER, WS_DEFAULT).getNodesWithDifferences().getSize());
  }
Ejemplo n.º 10
0
  @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());
  }
  @Test
  public void fulltext_with_path() throws Exception {

    final PropertyTree data = new PropertyTree();

    final String path1 = "test.of.string.with.path";
    final String value1 = "fisk ost pølse løk";
    data.setString(path1, value1);

    final String path2 = "mystring.with.path2";
    final String value2 = "vif rbk lsk sif";
    data.setString(path2, value2);

    final Node node =
        createNode(
            CreateNodeParams.create()
                .name("fisk ost")
                .parent(NodePath.ROOT)
                .data(data)
                .indexConfigDocument(
                    PatternIndexConfigDocument.create()
                        .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER)
                        .defaultConfig(IndexConfig.BY_TYPE)
                        .build())
                .build());

    final NodeQuery query =
        NodeQuery.create()
            .query(
                QueryExpr.from(
                    new DynamicConstraintExpr(
                        FunctionExpr.from(
                            "fulltext",
                            ValueExpr.string(path1),
                            ValueExpr.string("leter etter fisk"),
                            ValueExpr.string("OR")))))
            .build();

    final FindNodesByQueryResult result = doFindByQuery(query);

    assertEquals(1, result.getNodes().getSize());
    assertNotNull(result.getNodes().getNodeById(node.id()));
  }
  @Test
  public void word_delimiter_testing_dot() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addString("title", "testing.delimiter");

    final Node node =
        createNode(
            CreateNodeParams.create()
                .name("my-node-1")
                .parent(NodePath.ROOT)
                .data(data)
                .indexConfigDocument(
                    PatternIndexConfigDocument.create()
                        .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER)
                        .defaultConfig(IndexConfig.BY_TYPE)
                        .build())
                .build());

    queryAndAssert("fulltext('title', 'testing', 'AND')", 1);
    queryAndAssert("fulltext('title', 'delimiter', 'AND')", 1);
  }
  @Test
  public void fulltext_word_breaking_character() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addString("title", "Levenshteins-algorithm");

    final Node node =
        createNode(
            CreateNodeParams.create()
                .name("my-node-1")
                .parent(NodePath.ROOT)
                .data(data)
                .indexConfigDocument(
                    PatternIndexConfigDocument.create()
                        .analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER)
                        .defaultConfig(IndexConfig.BY_TYPE)
                        .build())
                .build());

    queryAndAssert("fulltext('title', 'levenshteins algorithm', 'AND')", 1);
    queryAndAssert("fulltext('title', 'levenshteins-algorithm', 'AND')", 1);
  }
  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());
  }
Ejemplo n.º 15
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.º 16
0
  private Node createNode(final Instant instantValue, final String name, final NodePath parent) {
    final PropertyTree data = new PropertyTree();
    data.addInstant("instant", instantValue);

    return createNode(CreateNodeParams.create().parent(parent).name(name).data(data).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++;
    }
  }