Search in sources :

Example 11 with NodeVersionMetadata

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

the class CompareStatusResolver method resolveFromVersion.

private CompareStatus resolveFromVersion() {
    final NodeVersionMetadata sourceVersion = getVersion(this.source);
    final NodeVersionMetadata targetVersion = getVersion(this.target);
    if (sourceVersion.getTimestamp().isAfter(targetVersion.getTimestamp())) {
        return CompareStatus.NEWER;
    }
    if (sourceVersion.getTimestamp().isBefore(targetVersion.getTimestamp())) {
        return CompareStatus.OLDER;
    }
    return CompareStatus.EQUAL;
}
Also used : NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata)

Example 12 with NodeVersionMetadata

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

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

the class NodeVersionsQueryResultMapper method serialize.

private void serialize(final MapGenerator gen, final NodeVersionsMetadata nodeVersions) {
    gen.array("hits");
    for (NodeVersionMetadata nodeVersion : nodeVersions) {
        gen.map();
        new NodeVersionMapper(nodeVersion).serialize(gen);
        gen.end();
    }
    gen.end();
}
Also used : NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata)

Example 14 with NodeVersionMetadata

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

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

the class ContentVersionFactory method create.

public ContentVersions create(final NodeId nodeId, final NodeVersionsMetadata nodeVersionsMetadata) {
    final ContentVersions.Builder contentVersionsBuilder = ContentVersions.create().contentId(ContentId.from(nodeId.toString()));
    for (final NodeVersionMetadata nodeVersionMetadata : nodeVersionsMetadata) {
        final ContentVersion contentVersion = create(nodeVersionMetadata);
        contentVersionsBuilder.add(contentVersion);
    }
    return contentVersionsBuilder.build();
}
Also used : ContentVersions(com.enonic.xp.content.ContentVersions) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) ContentVersion(com.enonic.xp.content.ContentVersion)

Aggregations

NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)25 Node (com.enonic.xp.node.Node)10 Test (org.junit.jupiter.api.Test)9 NodeVersionQueryResult (com.enonic.xp.node.NodeVersionQueryResult)8 NodeId (com.enonic.xp.node.NodeId)7 GetActiveNodeVersionsResult (com.enonic.xp.node.GetActiveNodeVersionsResult)6 Branch (com.enonic.xp.branch.Branch)5 NodeVersion (com.enonic.xp.node.NodeVersion)5 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)4 NodeVersionsMetadata (com.enonic.xp.node.NodeVersionsMetadata)4 InternalContext (com.enonic.xp.repo.impl.InternalContext)4 PropertyTree (com.enonic.xp.data.PropertyTree)3 GetActiveNodeVersionsParams (com.enonic.xp.node.GetActiveNodeVersionsParams)3 NodeCommitEntry (com.enonic.xp.node.NodeCommitEntry)3 NodeCommitId (com.enonic.xp.node.NodeCommitId)3 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)3 NodePath (com.enonic.xp.node.NodePath)3 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 Context (com.enonic.xp.context.Context)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)2