use of com.enonic.xp.node.GetActiveNodeVersionsParams in project xp by enonic.
the class GetActiveVersionHandlerTest method testGetActiveVersionsHandler.
@Test
public void testGetActiveVersionsHandler() {
final NodeVersionMetadata nodeVersionMeta = NodeVersionMetadata.create().nodeId(NodeId.from("nodeId1")).nodeVersionId(NodeVersionId.from("nodeVersionId1")).nodePath(NodePath.ROOT).timestamp(Instant.ofEpochSecond(1000)).build();
final GetActiveNodeVersionsResult getActiveNodeVersionsResult = GetActiveNodeVersionsResult.create().add(Branch.from("master"), nodeVersionMeta).build();
final ArgumentCaptor<GetActiveNodeVersionsParams> getActiveNodeVersionsParamsCaptor = ArgumentCaptor.forClass(GetActiveNodeVersionsParams.class);
Mockito.when(nodeService.getActiveVersions(Mockito.any())).thenReturn(getActiveNodeVersionsResult);
runScript("/lib/xp/examples/node/getActiveVersion.js");
Mockito.verify(nodeService).getActiveVersions(getActiveNodeVersionsParamsCaptor.capture());
final GetActiveNodeVersionsParams params = getActiveNodeVersionsParamsCaptor.getValue();
assertEquals("nodeId", params.getNodeId().toString());
assertTrue(params.getBranches().contains(Branch.from("master")));
}
use of com.enonic.xp.node.GetActiveNodeVersionsParams in project xp by enonic.
the class RepoDumper method getActiveVersion.
private NodeVersionMetadata getActiveVersion(final NodeId nodeId) {
final Branch branch = ContextAccessor.current().getBranch();
final GetActiveNodeVersionsParams params = GetActiveNodeVersionsParams.create().nodeId(nodeId).branches(Branches.from(branch)).build();
return this.nodeService.getActiveVersions(params).getNodeVersions().get(branch);
}
use of com.enonic.xp.node.GetActiveNodeVersionsParams 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());
}
use of com.enonic.xp.node.GetActiveNodeVersionsParams 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);
}
Aggregations