use of com.enonic.xp.node.NodeVersionMetadata 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.NodeVersionMetadata in project xp by enonic.
the class NodeServiceImplTest method test_commit.
@Test
public void test_commit() {
// Create and update node
final Node createdNode = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build());
final NodeId nodeId = createdNode.id();
final UpdateNodeParams updateNodeParams = UpdateNodeParams.create().id(nodeId).editor(toBeEdited -> {
toBeEdited.data.addString("newField", "fisk");
}).build();
final Node updatedNode = updateNode(updateNodeParams);
nodeService.refresh(RefreshMode.STORAGE);
// Check that the two versions have no commit ID by default
final NodeVersionsMetadata versionsMetadata = getVersionsMetadata(nodeId);
assertEquals(2, versionsMetadata.size());
final Iterator<NodeVersionMetadata> versionMetadataIterator = versionsMetadata.iterator();
final NodeVersionMetadata latestVersionMetadata = versionMetadataIterator.next();
final NodeVersionMetadata firstVersionMetadata = versionMetadataIterator.next();
assertNull(latestVersionMetadata.getNodeCommitId());
assertNull(firstVersionMetadata.getNodeCommitId());
// Call commit with node ID
final NodeCommitEntry commitEntry = NodeCommitEntry.create().message("Commit message").build();
final NodeCommitEntry returnedCommitEntry = nodeService.commit(commitEntry, NodeIds.from(nodeId));
nodeService.refresh(RefreshMode.STORAGE);
// Check created commit entry
final NodeCommitId nodeCommitId = returnedCommitEntry.getNodeCommitId();
assertNotNull(nodeCommitId);
assertEquals("Commit message", returnedCommitEntry.getMessage());
assertNotNull(returnedCommitEntry.getTimestamp());
assertEquals("user:system:test-user", returnedCommitEntry.getCommitter().toString());
// Check that only the latest version has a commit ID
final NodeVersionsMetadata versionsMetadata2 = getVersionsMetadata(nodeId);
assertEquals(2, versionsMetadata2.size());
final Iterator<NodeVersionMetadata> versionMetadataIterator2 = versionsMetadata2.iterator();
final NodeVersionMetadata latestVersionMetadata2 = versionMetadataIterator2.next();
final NodeVersionMetadata firstVersionMetadata2 = versionMetadataIterator2.next();
assertEquals(nodeCommitId, latestVersionMetadata2.getNodeCommitId());
assertNull(firstVersionMetadata2.getNodeCommitId());
// Call commit with the node version ID of the first version
final NodeCommitEntry commitEntry2 = NodeCommitEntry.create().message("Commit message 2").build();
final RoutableNodeVersionId routableNodeVersionId = RoutableNodeVersionId.from(nodeId, firstVersionMetadata2.getNodeVersionId());
final NodeCommitEntry returnedCommitEntry2 = nodeService.commit(commitEntry, RoutableNodeVersionIds.from(routableNodeVersionId));
nodeService.refresh(RefreshMode.STORAGE);
// Check that only the first version has been impacted
final NodeVersionsMetadata versionsMetadata3 = getVersionsMetadata(nodeId);
assertEquals(2, versionsMetadata3.size());
final Iterator<NodeVersionMetadata> versionMetadataIterator3 = versionsMetadata3.iterator();
final NodeVersionMetadata latestVersionMetadata3 = versionMetadataIterator3.next();
final NodeVersionMetadata firstVersionMetadata3 = versionMetadataIterator3.next();
assertEquals(nodeCommitId, latestVersionMetadata3.getNodeCommitId());
assertEquals(returnedCommitEntry2.getNodeCommitId(), firstVersionMetadata3.getNodeCommitId());
}
use of com.enonic.xp.node.NodeVersionMetadata in project xp by enonic.
the class NodeStorageServiceImpl method commit.
@Override
public NodeCommitEntry commit(final NodeCommitEntry nodeCommitEntry, final RoutableNodeVersionIds routableNodeVersionIds, final InternalContext context) {
final NodeCommitId nodeCommitId = new NodeCommitId();
final NodeCommitEntry updatedCommitEntry = NodeCommitEntry.create(nodeCommitEntry).nodeCommitId(nodeCommitId).build();
this.commitService.store(updatedCommitEntry, context);
for (RoutableNodeVersionId routableNodeVersionId : routableNodeVersionIds) {
final NodeVersionMetadata existingVersion = this.versionService.getVersion(routableNodeVersionId.getNodeId(), routableNodeVersionId.getNodeVersionId(), context);
final NodeVersionMetadata updatedVersion = NodeVersionMetadata.create(existingVersion).nodeCommitId(nodeCommitId).build();
this.versionService.store(updatedVersion, context);
}
return updatedCommitEntry;
}
use of com.enonic.xp.node.NodeVersionMetadata in project xp by enonic.
the class GetActiveNodeVersionsCommandTest method get_active_versions.
@Test
public void get_active_versions() throws Exception {
final PropertyTree data = new PropertyTree();
data.addString("myString", "value");
final Node node = createNode(CreateNodeParams.create().name("myNode").parent(NodePath.ROOT).data(data).build());
pushNodes(NodeIds.from(node.id()), WS_OTHER);
final GetActiveNodeVersionsResult result = GetActiveNodeVersionsCommand.create().storageService(this.storageService).searchService(this.searchService).nodeId(node.id()).branches(Branches.from(WS_DEFAULT, WS_OTHER)).build().execute();
NodeVersionMetadata draft = result.getNodeVersions().get(WS_DEFAULT);
NodeVersionMetadata master = result.getNodeVersions().get(WS_OTHER);
assertEquals(draft, master);
updateNode(node, ctxDefault());
final GetActiveNodeVersionsResult result2 = GetActiveNodeVersionsCommand.create().storageService(this.storageService).searchService(this.searchService).nodeId(node.id()).branches(Branches.from(WS_DEFAULT, WS_OTHER)).build().execute();
assertEquals(2, result2.getNodeVersions().size());
draft = result2.getNodeVersions().get(WS_DEFAULT);
master = result2.getNodeVersions().get(WS_OTHER);
assertFalse(draft.equals(master));
assertTrue(draft.getTimestamp().isAfter(master.getTimestamp()));
}
use of com.enonic.xp.node.NodeVersionMetadata in project xp by enonic.
the class GetActiveVersionHandler method execute.
@Override
public Object execute() {
final NodeId nodeId = getNodeId(key);
if (nodeId == null) {
return null;
}
final Branch branch = ContextAccessor.current().getBranch();
final GetActiveNodeVersionsParams params = GetActiveNodeVersionsParams.create().nodeId(nodeId).branches(Branches.from(branch)).build();
final NodeVersionMetadata nodeVersionMetadata = nodeService.getActiveVersions(params).getNodeVersions().get(branch);
if (nodeVersionMetadata == null) {
return null;
}
return new NodeVersionMapper(nodeVersionMetadata);
}
Aggregations