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