Search in sources :

Example 1 with GetActiveNodeVersionsParams

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")));
}
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 GetActiveNodeVersionsParams

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);
}
Also used : Branch(com.enonic.xp.branch.Branch) GetActiveNodeVersionsParams(com.enonic.xp.node.GetActiveNodeVersionsParams)

Example 3 with GetActiveNodeVersionsParams

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());
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeCommitQuery(com.enonic.xp.node.NodeCommitQuery) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) NodeCommitQueryResult(com.enonic.xp.node.NodeCommitQueryResult) NodeCommitId(com.enonic.xp.node.NodeCommitId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) GetActiveNodeVersionsParams(com.enonic.xp.node.GetActiveNodeVersionsParams)

Example 4 with GetActiveNodeVersionsParams

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

Aggregations

GetActiveNodeVersionsParams (com.enonic.xp.node.GetActiveNodeVersionsParams)4 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)3 Branch (com.enonic.xp.branch.Branch)2 GetActiveNodeVersionsResult (com.enonic.xp.node.GetActiveNodeVersionsResult)2 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 NodeVersionQueryResult (com.enonic.xp.node.NodeVersionQueryResult)1 Test (org.junit.jupiter.api.Test)1