use of com.enonic.xp.node.GetActiveNodeVersionsResult 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.GetActiveNodeVersionsResult in project xp by enonic.
the class GetActiveContentVersionsCommand method execute.
public GetActiveContentVersionsResult execute() {
this.nodeService.refresh(RefreshMode.STORAGE);
final NodeId nodeId = NodeId.from(contentId.toString());
final GetActiveNodeVersionsResult activeNodeVersions = this.nodeService.getActiveVersions(GetActiveNodeVersionsParams.create().nodeId(nodeId).branches(this.branches).build());
final ContentVersionFactory contentVersionFactory = new ContentVersionFactory(this.nodeService);
final GetActiveContentVersionsResult.Builder builder = GetActiveContentVersionsResult.create();
final ImmutableMap<Branch, NodeVersionMetadata> nodeVersionsMap = activeNodeVersions.getNodeVersions();
for (final Branch branch : nodeVersionsMap.keySet()) {
final NodeVersionMetadata nodeVersionMetadata = nodeVersionsMap.get(branch);
builder.add(ActiveContentVersionEntry.from(branch, contentVersionFactory.create(nodeVersionMetadata)));
}
return builder.build();
}
use of com.enonic.xp.node.GetActiveNodeVersionsResult 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.GetActiveNodeVersionsResult 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());
}
use of com.enonic.xp.node.GetActiveNodeVersionsResult in project xp by enonic.
the class GetActiveNodeVersionsCommand method execute.
public GetActiveNodeVersionsResult execute() {
final GetActiveNodeVersionsResult.Builder builder = GetActiveNodeVersionsResult.create();
for (final Branch branch : branches) {
final Context context = ContextAccessor.current();
final NodeBranchEntry nodeBranchEntry = this.nodeStorageService.getBranchNodeVersion(this.nodeId, InternalContext.create(context).branch(branch).build());
if (nodeBranchEntry != null) {
builder.add(branch, this.nodeStorageService.getVersion(nodeBranchEntry.getNodeId(), nodeBranchEntry.getVersionId(), InternalContext.from(context)));
}
}
return builder.build();
}
Aggregations