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