use of com.enonic.xp.node.RoutableNodeVersionId in project xp by enonic.
the class PublishContentCommand method commitPushedNodes.
private void commitPushedNodes(final NodeBranchEntries branchEntries) {
final String commitEntryMessage = message == null ? ContentConstants.PUBLISH_COMMIT_PREFIX : String.join(ContentConstants.PUBLISH_COMMIT_PREFIX_DELIMITER, ContentConstants.PUBLISH_COMMIT_PREFIX, message);
final NodeCommitEntry commitEntry = NodeCommitEntry.create().message(commitEntryMessage).build();
final RoutableNodeVersionIds.Builder routableNodeVersionIds = RoutableNodeVersionIds.create();
for (NodeBranchEntry branchEntry : branchEntries) {
final RoutableNodeVersionId routableNodeVersionId = RoutableNodeVersionId.from(branchEntry.getNodeId(), branchEntry.getVersionId());
routableNodeVersionIds.add(routableNodeVersionId);
}
nodeService.commit(commitEntry, routableNodeVersionIds.build());
}
use of com.enonic.xp.node.RoutableNodeVersionId 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.RoutableNodeVersionId 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