Search in sources :

Example 11 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class FindNodeVersionsCommandTest method get_single_version.

@Test
void get_single_version() {
    final Node node = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build());
    final NodeVersionQuery query = NodeVersionQuery.create().size(100).from(0).nodeId(node.id()).build();
    final NodeVersionQueryResult result = FindNodeVersionsCommand.create().query(query).searchService(this.searchService).build().execute();
    assertEquals(1, result.getHits());
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) Node(com.enonic.xp.node.Node) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) Test(org.junit.jupiter.api.Test)

Example 12 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class NodeExporter method writeVersions.

private void writeVersions(final Node node) {
    if (node.isRoot()) {
        return;
    }
    // TODO: Batch this?
    final NodeVersionQueryResult versions = this.nodeService.findVersions(GetNodeVersionsParams.create().from(0).size(-1).nodeId(node.id()).build());
    for (final NodeVersionMetadata version : versions.getNodeVersionsMetadata()) {
        if (version.getNodeVersionId().equals(node.getNodeVersionId())) {
            continue;
        }
        final NodeVersion nodeVersion = this.nodeService.getByNodeVersionKey(version.getNodeVersionKey());
        final Node exportNode = NodeFromNodeVersionBuilder.create(version, nodeVersion);
        writeVersion(exportNode, resolveNodeVersionBasePath(node, version));
    }
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

Example 13 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class DumpServiceImplTest method versions.

@Test
public void versions() throws Exception {
    final Node node = createNode(NodePath.ROOT, "myNode");
    final Node updatedNode = updateNode(node);
    final Node currentNode = updateNode(updatedNode);
    refresh();
    final NodeVersionQueryResult versionsBeforeDump = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
    NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
    refresh();
    final NodeVersionQueryResult versionsAfterLoad = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
    assertEquals(3, versionsAfterLoad.getTotalHits());
    final Node currentStoredNode = this.nodeService.getById(node.id());
    assertEquals(currentNode.data(), currentStoredNode.data());
    assertEquals(getOrderedTimestamps(versionsBeforeDump), getOrderedTimestamps(versionsAfterLoad));
}
Also used : Node(com.enonic.xp.node.Node) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 14 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class DumpServiceImplTest method checkCommitUpgrade.

private void checkCommitUpgrade(final NodeId nodeId) {
    nodeService.refresh(RefreshMode.ALL);
    final NodeCommitQuery nodeCommitQuery = NodeCommitQuery.create().build();
    final NodeCommitQueryResult nodeCommitQueryResult = ContextBuilder.from(ContextAccessor.current()).branch(Branch.from("master")).build().callWith(() -> nodeService.findCommits(nodeCommitQuery));
    assertEquals(1, nodeCommitQueryResult.getTotalHits());
    final NodeCommitEntry commitEntry = nodeCommitQueryResult.getNodeCommitEntries().iterator().next();
    final NodeCommitId nodeCommitId = commitEntry.getNodeCommitId();
    assertEquals("Dump upgrade", commitEntry.getMessage());
    assertEquals("user:system:node-su", commitEntry.getCommitter().toString());
    final GetActiveNodeVersionsParams activeNodeVersionsParams = GetActiveNodeVersionsParams.create().nodeId(nodeId).branches(Branches.from(ContentConstants.BRANCH_DRAFT, ContentConstants.BRANCH_MASTER)).build();
    final GetActiveNodeVersionsResult activeNodeVersionsResult = ContextBuilder.from(ContextAccessor.current()).branch(Branch.from("master")).build().callWith(() -> nodeService.getActiveVersions(activeNodeVersionsParams));
    final NodeVersionMetadata draftNodeVersion = activeNodeVersionsResult.getNodeVersions().get(ContentConstants.BRANCH_DRAFT);
    assertNull(draftNodeVersion.getNodeCommitId());
    final NodeVersionMetadata masterNodeVersion = activeNodeVersionsResult.getNodeVersions().get(ContentConstants.BRANCH_MASTER);
    assertEquals(nodeCommitId, masterNodeVersion.getNodeCommitId());
    final NodeVersionQuery nodeVersionQuery = NodeVersionQuery.create().nodeId(nodeId).build();
    final NodeVersionQueryResult versionQueryResult = ContextBuilder.from(ContextAccessor.current()).branch(Branch.from("draft")).build().callWith(() -> nodeService.findVersions(nodeVersionQuery));
    assertEquals(16, versionQueryResult.getTotalHits());
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeCommitQuery(com.enonic.xp.node.NodeCommitQuery) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) NodeCommitQueryResult(com.enonic.xp.node.NodeCommitQueryResult) NodeCommitId(com.enonic.xp.node.NodeCommitId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) GetActiveNodeVersionsParams(com.enonic.xp.node.GetActiveNodeVersionsParams)

Example 15 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class DumpServiceImplTest method skip_versions.

@Test
public void skip_versions() throws Exception {
    final Node node = createNode(NodePath.ROOT, "myNode");
    final Node updatedNode = updateNode(node);
    final Node currentNode = updateNode(updatedNode);
    refresh();
    NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true, false));
    refresh();
    final NodeVersionQueryResult versionsAfterLoad = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
    assertEquals(1, versionsAfterLoad.getTotalHits());
    final Node currentStoredNode = this.nodeService.getById(node.id());
    assertEquals(currentNode.data(), currentStoredNode.data());
}
Also used : Node(com.enonic.xp.node.Node) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

NodeVersionQueryResult (com.enonic.xp.node.NodeVersionQueryResult)22 Node (com.enonic.xp.node.Node)12 Test (org.junit.jupiter.api.Test)11 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)9 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)8 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)8 NodeId (com.enonic.xp.node.NodeId)5 Instant (java.time.Instant)4 Branch (com.enonic.xp.branch.Branch)3 GetActiveNodeVersionsResult (com.enonic.xp.node.GetActiveNodeVersionsResult)3 NodeVersionsMetadata (com.enonic.xp.node.NodeVersionsMetadata)3 Context (com.enonic.xp.context.Context)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)2 ContextBuilder (com.enonic.xp.context.ContextBuilder)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 GetNodeVersionsParams (com.enonic.xp.node.GetNodeVersionsParams)2 NodeVersionId (com.enonic.xp.node.NodeVersionId)2 InternalContext (com.enonic.xp.repo.impl.InternalContext)2 Repository (com.enonic.xp.repository.Repository)2 RepositoryConstants (com.enonic.xp.repository.RepositoryConstants)2