use of com.enonic.xp.node.NodeCommitId in project xp by enonic.
the class CommitDumpUpgrader method createCommit.
private void createCommit(final RepositoryId repositoryId) {
tmpDumpWriter.openCommitsMeta(repositoryId);
try {
final NodeCommitEntry nodeCommitEntry = NodeCommitEntry.create().build();
commitId = new NodeCommitId().toString();
final CommitDumpEntryJson commitDumpEntryJson = CommitDumpEntryJson.create().commitId(commitId).message("Dump upgrade").committer(nodeCommitEntry.getCommitter().toString()).timestamp(nodeCommitEntry.getTimestamp().toString()).build();
final byte[] commitDumpEntrySerialized = serialize(commitDumpEntryJson);
tmpDumpWriter.storeTarEntry(commitDumpEntrySerialized, commitId + ".json");
} finally {
tmpDumpWriter.closeMeta();
}
}
use of com.enonic.xp.node.NodeCommitId 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.NodeCommitId 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.NodeCommitId 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());
}
Aggregations