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