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());
}
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));
}
}
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));
}
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());
}
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());
}
Aggregations