Search in sources :

Example 21 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class FindVersionsHandler method execute.

@Override
public Object execute() {
    final NodeVersionQueryResult result;
    NodeId nodeId = getNodeId(key);
    if (nodeId == null) {
        result = NodeVersionQueryResult.empty(0);
    } else {
        GetNodeVersionsParams params = GetNodeVersionsParams.create().nodeId(nodeId).from(from).size(size).build();
        result = nodeService.findVersions(params);
    }
    return new NodeVersionsQueryResultMapper(result);
}
Also used : NodeId(com.enonic.xp.node.NodeId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams)

Example 22 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class FindVersionsHandlerTest method testFindVersionsHandler.

@Test
public void testFindVersionsHandler() {
    final NodeVersionMetadata newNodeVersionMeta = NodeVersionMetadata.create().nodeId(NodeId.from("nodeId1")).nodeVersionId(NodeVersionId.from("nodeVersionNew")).nodePath(NodePath.ROOT).timestamp(Instant.ofEpochSecond(1000)).build();
    final NodeVersionMetadata oldNodeVersionMeta = NodeVersionMetadata.create().nodeId(NodeId.from("nodeId1")).nodeVersionId(NodeVersionId.from("nodeVersionOld")).nodePath(NodePath.ROOT).timestamp(Instant.ofEpochSecond(500)).build();
    final NodeVersionsMetadata nodeVersionsMetadata = NodeVersionsMetadata.create(NodeId.from("nodeId1")).add(newNodeVersionMeta).add(oldNodeVersionMeta).build();
    final NodeVersionQueryResult result = NodeVersionQueryResult.create().entityVersions(nodeVersionsMetadata).from(0).to(2).hits(2).totalHits(40).build();
    final ArgumentCaptor<GetNodeVersionsParams> getNodeVersionsParamsCaptor = ArgumentCaptor.forClass(GetNodeVersionsParams.class);
    Mockito.when(nodeService.findVersions(Mockito.any(GetNodeVersionsParams.class))).thenReturn(result);
    runScript("/lib/xp/examples/node/findVersions.js");
    Mockito.verify(nodeService).findVersions(getNodeVersionsParamsCaptor.capture());
    assertEquals("nodeId", getNodeVersionsParamsCaptor.getValue().getNodeId().toString());
    assertEquals(0, getNodeVersionsParamsCaptor.getValue().getFrom());
    assertEquals(2, getNodeVersionsParamsCaptor.getValue().getSize());
}
Also used : NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams) Test(org.junit.jupiter.api.Test)

Aggregations

NodeVersionQueryResult (com.enonic.xp.node.NodeVersionQueryResult)22 Node (com.enonic.xp.node.Node)12 Test (org.junit.jupiter.api.Test)11 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)9 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)8 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)8 NodeId (com.enonic.xp.node.NodeId)5 Instant (java.time.Instant)4 Branch (com.enonic.xp.branch.Branch)3 GetActiveNodeVersionsResult (com.enonic.xp.node.GetActiveNodeVersionsResult)3 NodeVersionsMetadata (com.enonic.xp.node.NodeVersionsMetadata)3 Context (com.enonic.xp.context.Context)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)2 ContextBuilder (com.enonic.xp.context.ContextBuilder)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 GetNodeVersionsParams (com.enonic.xp.node.GetNodeVersionsParams)2 NodeVersionId (com.enonic.xp.node.NodeVersionId)2 InternalContext (com.enonic.xp.repo.impl.InternalContext)2 Repository (com.enonic.xp.repository.Repository)2 RepositoryConstants (com.enonic.xp.repository.RepositoryConstants)2