Search in sources :

Example 1 with GetActiveNodeVersionsResult

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

Example 2 with GetActiveNodeVersionsResult

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

Example 3 with GetActiveNodeVersionsResult

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

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

Example 5 with GetActiveNodeVersionsResult

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();
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) Branch(com.enonic.xp.branch.Branch) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Aggregations

GetActiveNodeVersionsResult (com.enonic.xp.node.GetActiveNodeVersionsResult)7 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)6 Branch (com.enonic.xp.branch.Branch)4 Test (org.junit.jupiter.api.Test)4 Node (com.enonic.xp.node.Node)3 GetActiveNodeVersionsParams (com.enonic.xp.node.GetActiveNodeVersionsParams)2 NodeVersionQueryResult (com.enonic.xp.node.NodeVersionQueryResult)2 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 GetActiveContentVersionsResult (com.enonic.xp.content.GetActiveContentVersionsResult)1 Context (com.enonic.xp.context.Context)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)1 NodeCommitEntry (com.enonic.xp.node.NodeCommitEntry)1 NodeCommitId (com.enonic.xp.node.NodeCommitId)1 NodeCommitQuery (com.enonic.xp.node.NodeCommitQuery)1 NodeCommitQueryResult (com.enonic.xp.node.NodeCommitQueryResult)1 NodeId (com.enonic.xp.node.NodeId)1 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)1 InternalContext (com.enonic.xp.repo.impl.InternalContext)1