Search in sources :

Example 6 with NodeVersionMetadata

use of com.enonic.xp.node.NodeVersionMetadata in project xp by enonic.

the class NodeStorageServiceImpl method get.

@Override
public Node get(final NodeId nodeId, final NodeVersionId nodeVersionId, final InternalContext context) {
    final NodeVersionMetadata nodeVersionMetadata = versionService.getVersion(nodeId, nodeVersionId, context);
    if (nodeVersionMetadata == null) {
        return null;
    }
    final NodeVersion nodeVersion = nodeVersionService.get(nodeVersionMetadata.getNodeVersionKey(), context);
    if (nodeVersion == null) {
        return null;
    }
    final NodeBranchEntry nodeBranchEntry = branchService.get(nodeVersionMetadata.getNodeId(), context);
    if (nodeBranchEntry == null) {
        return null;
    }
    return constructNode(nodeBranchEntry, nodeVersion);
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Example 7 with NodeVersionMetadata

use of com.enonic.xp.node.NodeVersionMetadata in project xp by enonic.

the class NodeStorageServiceImplTest method testGetNode.

@Test
public void testGetNode() {
    final NodePath nodePath = NodePath.create("path").build();
    final NodeVersionMetadata nodeVersionMetadata = NodeVersionMetadata.create().nodeVersionId(nodeVersionId).nodeVersionKey(versionKey).nodePath(nodePath).build();
    final NodeVersion nodeVersion = NodeVersion.create().permissions(AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.EVERYONE).allow(Permission.READ).build()).build()).build();
    when(versionService.getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class))).thenReturn(nodeVersionMetadata);
    when(nodeVersionService.get(any(NodeVersionKey.class), any(InternalContext.class))).thenReturn(nodeVersion);
    final Node result = instance.getNode(nodeId, nodeVersionId, context);
    assertNotNull(result);
    verify(versionService, times(1)).getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class));
    verify(nodeVersionService, times(1)).get(any(NodeVersionKey.class), any(InternalContext.class));
    verifyNoMoreInteractions(versionService, nodeVersionService);
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) NodeVersionId(com.enonic.xp.node.NodeVersionId) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 8 with NodeVersionMetadata

use of com.enonic.xp.node.NodeVersionMetadata in project xp by enonic.

the class ApplyNodePermissionsCommandTest method assertVersions.

private void assertVersions(final Node node) {
    final NodeVersionQuery query = NodeVersionQuery.create().size(100).from(0).nodeId(node.id()).addOrderBy(FieldOrderExpr.create(VersionIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).build();
    final NodeVersionQueryResult versions = FindNodeVersionsCommand.create().query(query).searchService(this.searchService).build().execute();
    assertEquals(2, versions.getHits());
    final Iterator<NodeVersionMetadata> iterator = versions.getNodeVersionsMetadata().iterator();
    assertTrue(iterator.next().getTimestamp().isAfter(iterator.next().getTimestamp()));
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

Example 9 with NodeVersionMetadata

use of com.enonic.xp.node.NodeVersionMetadata in project xp by enonic.

the class DumpServiceImplTest method active_versions_in_versions_list.

@Test
public void active_versions_in_versions_list() throws Exception {
    final Node node = createNode(NodePath.ROOT, "myNode");
    this.nodeService.push(NodeIds.from(node.id()), WS_OTHER);
    updateNode(node);
    refresh();
    NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
    refresh();
    final GetActiveNodeVersionsResult activeVersions = this.nodeService.getActiveVersions(GetActiveNodeVersionsParams.create().branches(Branches.from(WS_DEFAULT, WS_OTHER)).nodeId(node.id()).build());
    final ImmutableMap<Branch, NodeVersionMetadata> activeVersionsMap = activeVersions.getNodeVersions();
    final NodeVersionQueryResult versionsAfterLoad = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
    activeVersionsMap.values().forEach(key -> assertTrue(versionsAfterLoad.getNodeVersionsMetadata().getAllVersionIds().contains(key.getNodeVersionId())));
}
Also used : GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) Branch(com.enonic.xp.branch.Branch) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 10 with NodeVersionMetadata

use of com.enonic.xp.node.NodeVersionMetadata in project xp by enonic.

the class DumpServiceImplTest method active_versions_after_load.

@Test
public void active_versions_after_load() throws Exception {
    final Node node = createNode(NodePath.ROOT, "myNode");
    this.nodeService.push(NodeIds.from(node.id()), WS_OTHER);
    updateNode(node);
    refresh();
    NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
    refresh();
    final GetActiveNodeVersionsResult activeVersions = this.nodeService.getActiveVersions(GetActiveNodeVersionsParams.create().branches(Branches.from(WS_DEFAULT, WS_OTHER)).nodeId(node.id()).build());
    final Node defaultBranchNode = ctxDefault().callWith(() -> this.nodeService.getById(node.id()));
    final Node otherBranchNode = ctxOther().callWith(() -> this.nodeService.getById(node.id()));
    final ImmutableMap<Branch, NodeVersionMetadata> activeVersionsMap = activeVersions.getNodeVersions();
    assertEquals(2, activeVersionsMap.size());
    assertEquals(defaultBranchNode.getNodeVersionId(), activeVersionsMap.get(WS_DEFAULT).getNodeVersionId());
    assertEquals(otherBranchNode.getNodeVersionId(), activeVersionsMap.get(WS_OTHER).getNodeVersionId());
}
Also used : GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) Branch(com.enonic.xp.branch.Branch) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

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