Search in sources :

Example 6 with GetActiveNodeVersionsResult

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

the class GetActiveNodeVersionsCommandTest method get_active_versions.

@Test
public void get_active_versions() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addString("myString", "value");
    final Node node = createNode(CreateNodeParams.create().name("myNode").parent(NodePath.ROOT).data(data).build());
    pushNodes(NodeIds.from(node.id()), WS_OTHER);
    final GetActiveNodeVersionsResult result = GetActiveNodeVersionsCommand.create().storageService(this.storageService).searchService(this.searchService).nodeId(node.id()).branches(Branches.from(WS_DEFAULT, WS_OTHER)).build().execute();
    NodeVersionMetadata draft = result.getNodeVersions().get(WS_DEFAULT);
    NodeVersionMetadata master = result.getNodeVersions().get(WS_OTHER);
    assertEquals(draft, master);
    updateNode(node, ctxDefault());
    final GetActiveNodeVersionsResult result2 = GetActiveNodeVersionsCommand.create().storageService(this.storageService).searchService(this.searchService).nodeId(node.id()).branches(Branches.from(WS_DEFAULT, WS_OTHER)).build().execute();
    assertEquals(2, result2.getNodeVersions().size());
    draft = result2.getNodeVersions().get(WS_DEFAULT);
    master = result2.getNodeVersions().get(WS_OTHER);
    assertFalse(draft.equals(master));
    assertTrue(draft.getTimestamp().isAfter(master.getTimestamp()));
}
Also used : GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 7 with GetActiveNodeVersionsResult

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

the class GetActiveNodeVersionsCommand method execute.

public GetActiveNodeVersionsResult execute() {
    final GetActiveNodeVersionsResult.Builder builder = GetActiveNodeVersionsResult.create();
    for (final Branch branch : branches) {
        final Context context = ContextAccessor.current();
        final NodeBranchEntry nodeBranchEntry = this.nodeStorageService.getBranchNodeVersion(this.nodeId, InternalContext.create(context).branch(branch).build());
        if (nodeBranchEntry != null) {
            builder.add(branch, this.nodeStorageService.getVersion(nodeBranchEntry.getNodeId(), nodeBranchEntry.getVersionId(), InternalContext.from(context)));
        }
    }
    return builder.build();
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) Branch(com.enonic.xp.branch.Branch) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Aggregations

GetActiveNodeVersionsResult (com.enonic.xp.node.GetActiveNodeVersionsResult)7 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)6 Branch (com.enonic.xp.branch.Branch)4 Test (org.junit.jupiter.api.Test)4 Node (com.enonic.xp.node.Node)3 GetActiveNodeVersionsParams (com.enonic.xp.node.GetActiveNodeVersionsParams)2 NodeVersionQueryResult (com.enonic.xp.node.NodeVersionQueryResult)2 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 GetActiveContentVersionsResult (com.enonic.xp.content.GetActiveContentVersionsResult)1 Context (com.enonic.xp.context.Context)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)1 NodeCommitEntry (com.enonic.xp.node.NodeCommitEntry)1 NodeCommitId (com.enonic.xp.node.NodeCommitId)1 NodeCommitQuery (com.enonic.xp.node.NodeCommitQuery)1 NodeCommitQueryResult (com.enonic.xp.node.NodeCommitQueryResult)1 NodeId (com.enonic.xp.node.NodeId)1 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)1 InternalContext (com.enonic.xp.repo.impl.InternalContext)1