Search in sources :

Example 21 with NodeVersionMetadata

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());
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeCommitQuery(com.enonic.xp.node.NodeCommitQuery) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) NodeCommitQueryResult(com.enonic.xp.node.NodeCommitQueryResult) NodeCommitId(com.enonic.xp.node.NodeCommitId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) GetActiveNodeVersionsParams(com.enonic.xp.node.GetActiveNodeVersionsParams)

Example 22 with NodeVersionMetadata

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

Example 23 with NodeVersionMetadata

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;
}
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 24 with NodeVersionMetadata

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()));
}
Also used : GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 25 with NodeVersionMetadata

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);
}
Also used : Branch(com.enonic.xp.branch.Branch) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeId(com.enonic.xp.node.NodeId) GetActiveNodeVersionsParams(com.enonic.xp.node.GetActiveNodeVersionsParams)

Aggregations

NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)25 Node (com.enonic.xp.node.Node)10 Test (org.junit.jupiter.api.Test)9 NodeVersionQueryResult (com.enonic.xp.node.NodeVersionQueryResult)8 NodeId (com.enonic.xp.node.NodeId)7 GetActiveNodeVersionsResult (com.enonic.xp.node.GetActiveNodeVersionsResult)6 Branch (com.enonic.xp.branch.Branch)5 NodeVersion (com.enonic.xp.node.NodeVersion)5 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)4 NodeVersionsMetadata (com.enonic.xp.node.NodeVersionsMetadata)4 InternalContext (com.enonic.xp.repo.impl.InternalContext)4 PropertyTree (com.enonic.xp.data.PropertyTree)3 GetActiveNodeVersionsParams (com.enonic.xp.node.GetActiveNodeVersionsParams)3 NodeCommitEntry (com.enonic.xp.node.NodeCommitEntry)3 NodeCommitId (com.enonic.xp.node.NodeCommitId)3 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)3 NodePath (com.enonic.xp.node.NodePath)3 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 Context (com.enonic.xp.context.Context)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)2