Search in sources :

Example 1 with GetNodeVersionsParams

use of com.enonic.xp.node.GetNodeVersionsParams 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 2 with GetNodeVersionsParams

use of com.enonic.xp.node.GetNodeVersionsParams 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

GetNodeVersionsParams (com.enonic.xp.node.GetNodeVersionsParams)2 NodeVersionQueryResult (com.enonic.xp.node.NodeVersionQueryResult)2 NodeId (com.enonic.xp.node.NodeId)1 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)1 NodeVersionsMetadata (com.enonic.xp.node.NodeVersionsMetadata)1 Test (org.junit.jupiter.api.Test)1