Exemplo 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;
  }
  @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_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()));
  }
 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();
 }
Exemplo n.º 5
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.º 6
0
  private NodePath verifyNodeNotExistAtNewPath(final Node nodeToBeRenamed) {
    final NodePath parentPath = nodeToBeRenamed.parentPath().asAbsolute();
    final NodePath targetPath = new NodePath(parentPath, params.getNewNodeName());
    final Node existingNodeAtTargetPath =
        GetNodeByPathCommand.create(this).nodePath(targetPath).build().execute();

    if ((existingNodeAtTargetPath != null)
        && !nodeToBeRenamed.id().equals(existingNodeAtTargetPath.id())) {
      throw new NodeAlreadyExistAtPathException(targetPath);
    }

    return parentPath;
  }
  @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()));
  }
Exemplo n.º 8
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();
  }
Exemplo n.º 9
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();
  }
  private void queryAndAssert(final Node node, final String queryString, final int expected) {
    final NodeQuery query = NodeQuery.create().query(QueryParser.parse(queryString)).build();

    final FindNodesByQueryResult result = doFindByQuery(query);

    assertEquals(expected, result.getNodes().getSize());
    assertNotNull(result.getNodes().getNodeById(node.id()));
  }
 private PushNodesResult doPushNode(final Branch target, final Node createdNode) {
   return PushNodesCommand.create()
       .ids(NodeIds.from(createdNode.id()))
       .target(target)
       .indexServiceInternal(this.indexServiceInternal)
       .storageService(this.storageService)
       .searchService(this.searchService)
       .build()
       .execute();
 }
  @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());
  }
Exemplo n.º 13
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()));
  }
Exemplo n.º 15
0
  public MoveNodeResult execute() {
    final NodeId nodeId = params.getNodeId();

    final Node nodeToBeRenamed = doGetById(nodeId);

    if (nodeToBeRenamed == null) {
      throw new NodeNotFoundException("cannot rename node with id [" + nodeId + "]");
    }

    if (nodeToBeRenamed.isRoot()) {
      throw new OperationNotPermittedException("Not allowed to rename root-node");
    }

    final NodePath parentPath = verifyNodeNotExistAtNewPath(nodeToBeRenamed);

    return MoveNodeCommand.create(this)
        .id(params.getNodeId())
        .newParent(parentPath)
        .newNodeName(params.getNewNodeName())
        .build()
        .execute();
  }
Exemplo n.º 16
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);
    }
  }
  private Node doUpdateNode(final Node node) {
    final UpdateNodeParams updateNodeParams =
        UpdateNodeParams.create()
            .id(node.id())
            .editor(editableNode -> editableNode.manualOrderValue = 10l)
            .build();

    return UpdateNodeCommand.create()
        .params(updateNodeParams)
        .indexServiceInternal(this.indexServiceInternal)
        .binaryBlobStore(this.binaryBlobStore)
        .storageService(this.storageService)
        .searchService(this.searchService)
        .build()
        .execute();
  }
Exemplo n.º 18
0
  private BinaryAttachments processBinaryAttachments(
      final VirtualFile nodeFile, final Node newNode) {
    final PropertyTree data = newNode.data();

    final ImmutableList<Property> binaryReferences =
        data.getProperties(ValueTypes.BINARY_REFERENCE);

    if (binaryReferences.isEmpty()) {
      return BinaryAttachments.empty();
    }

    final BinaryAttachments.Builder builder = BinaryAttachments.create();

    for (final Property binaryReference : binaryReferences) {
      addBinary(nodeFile, builder, binaryReference);
    }

    return builder.build();
  }
Exemplo n.º 19
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;
  }
  @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++;
    }
  }
  @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());
  }