Search in sources :

Example 1 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 2 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 3 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 4 with NodeVersionMetadata

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

the class RepoDumper method dumpVersions.

private void dumpVersions(final Collection<NodeId> dumpedNodes) {
    writer.openVersionsMeta(repository.getId());
    try {
        for (NodeId nodeId : dumpedNodes) {
            final VersionsDumpEntry.Builder builder = VersionsDumpEntry.create(nodeId);
            final NodeVersionQueryResult versions = getVersions(nodeId);
            for (final NodeVersionMetadata metaData : versions.getNodeVersionsMetadata()) {
                doStoreVersion(builder, metaData, this.dumpResult);
                this.dumpResult.addedVersion();
            }
            writer.writeVersionsEntry(builder.build());
        }
    } finally {
        writer.closeMeta();
    }
}
Also used : NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeId(com.enonic.xp.node.NodeId) VersionsDumpEntry(com.enonic.xp.repo.impl.dump.model.VersionsDumpEntry) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

Example 5 with NodeVersionMetadata

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

the class RepoDumper method createDumpEntry.

private BranchDumpEntry createDumpEntry(final NodeId nodeId) {
    final BranchDumpEntry.Builder builder = BranchDumpEntry.create().nodeId(nodeId);
    final Node currentNode = this.nodeService.getById(nodeId);
    final NodeVersionMetadata currentVersionMetaData = getActiveVersion(nodeId);
    builder.meta(VersionMetaFactory.create(currentNode, currentVersionMetaData));
    if (this.includeBinaries) {
        builder.addBinaryReferences(currentNode.getAttachedBinaries().stream().map(AttachedBinary::getBlobKey).collect(Collectors.toSet()));
    }
    return builder.build();
}
Also used : NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) BranchDumpEntry(com.enonic.xp.repo.impl.dump.model.BranchDumpEntry) AttachedBinary(com.enonic.xp.node.AttachedBinary)

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