Search in sources :

Example 1 with RoutableNodeVersionId

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());
}
Also used : RoutableNodeVersionIds(com.enonic.xp.node.RoutableNodeVersionIds) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Example 2 with RoutableNodeVersionId

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;
}
Also used : RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) NodeCommitId(com.enonic.xp.node.NodeCommitId)

Example 3 with RoutableNodeVersionId

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());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Permission(com.enonic.xp.security.acl.Permission) NodeCommitId(com.enonic.xp.node.NodeCommitId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) ContextBuilder(com.enonic.xp.context.ContextBuilder) BinaryReference(com.enonic.xp.util.BinaryReference) User(com.enonic.xp.security.User) NodeIndexPath(com.enonic.xp.node.NodeIndexPath) CreateRootNodeParams(com.enonic.xp.node.CreateRootNodeParams) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) Test(org.junit.jupiter.api.Test) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) OrderExpr(com.enonic.xp.query.expr.OrderExpr) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) ChildOrder(com.enonic.xp.index.ChildOrder) RefreshMode(com.enonic.xp.node.RefreshMode) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) EventPublisher(com.enonic.xp.event.EventPublisher) RoutableNodeVersionIds(com.enonic.xp.node.RoutableNodeVersionIds) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) Iterator(java.util.Iterator) NodePath(com.enonic.xp.node.NodePath) IOException(java.io.IOException) ReorderChildNodeParams(com.enonic.xp.node.ReorderChildNodeParams) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito(org.mockito.Mockito) NodeName(com.enonic.xp.node.NodeName) BranchNotFoundException(com.enonic.xp.repository.BranchNotFoundException) PrincipalKey(com.enonic.xp.security.PrincipalKey) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) NodeIds(com.enonic.xp.node.NodeIds) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodeId(com.enonic.xp.node.NodeId) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) NodeCommitId(com.enonic.xp.node.NodeCommitId) Test(org.junit.jupiter.api.Test)

Aggregations

NodeCommitEntry (com.enonic.xp.node.NodeCommitEntry)3 RoutableNodeVersionId (com.enonic.xp.node.RoutableNodeVersionId)3 NodeCommitId (com.enonic.xp.node.NodeCommitId)2 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)2 RoutableNodeVersionIds (com.enonic.xp.node.RoutableNodeVersionIds)2 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 EventPublisher (com.enonic.xp.event.EventPublisher)1 ChildOrder (com.enonic.xp.index.ChildOrder)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 CreateRootNodeParams (com.enonic.xp.node.CreateRootNodeParams)1 DuplicateNodeParams (com.enonic.xp.node.DuplicateNodeParams)1 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)1 GetNodeVersionsParams (com.enonic.xp.node.GetNodeVersionsParams)1 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)1 Node (com.enonic.xp.node.Node)1 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)1 NodeId (com.enonic.xp.node.NodeId)1