use of com.enonic.xp.node.NodeComparison in project xp by enonic.
the class AbstractCompareNodeCommand method doCompareNodeVersions.
NodeComparison doCompareNodeVersions(final Context context, final NodeId nodeId) {
final NodeBranchEntry sourceWsVersion = nodeStorageService.getBranchNodeVersion(nodeId, InternalContext.from(context));
final NodeBranchEntry targetWsVersion = nodeStorageService.getBranchNodeVersion(nodeId, InternalContext.create(context).branch(this.target).build());
final CompareStatus compareStatus = CompareStatusResolver.create().source(sourceWsVersion).target(targetWsVersion).storageService(this.nodeStorageService).build().resolve();
return new NodeComparison(sourceWsVersion, targetWsVersion, compareStatus);
}
use of com.enonic.xp.node.NodeComparison in project xp by enonic.
the class PushNodesCommand method targetAlreadyExists.
private boolean targetAlreadyExists(final NodePath nodePath, final NodeComparisons comparisons, final Context currentContext) {
// Checks if a node exist
final Context targetContext = createTargetContext(currentContext);
final NodeId nodeId = targetContext.callWith(() -> GetNodeIdByPathCommand.create(this).nodePath(nodePath).build().execute());
// If the node does not exist, returns false
if (nodeId == null) {
return false;
}
// Else, if the existing node is being deleted or moved during the current push, returns false
final NodeComparison nodeComparison = comparisons.get(nodeId);
return nodeComparison == null || (CompareStatus.MOVED != nodeComparison.getCompareStatus() && CompareStatus.PENDING_DELETE != nodeComparison.getCompareStatus());
}
use of com.enonic.xp.node.NodeComparison in project xp by enonic.
the class ResolveSyncWorkCommand method getAllPossibleNodesToBePublished.
private void getAllPossibleNodesToBePublished() {
final NodeIds.Builder diffAndDependantsBuilder = NodeIds.create();
final NodeIds initialDiff = getInitialDiff();
diffAndDependantsBuilder.addAll(initialDiff);
if (includeDependencies) {
final NodeIds nodeDependencies = getNodeDependencies(initialDiff);
diffAndDependantsBuilder.addAll(nodeDependencies);
}
final Set<NodeComparison> comparisons = getFilteredComparisons(diffAndDependantsBuilder);
addNewAndMovedParents(comparisons);
comparisons.forEach(this::addToResult);
markPendingDeleteChildrenForDeletion(comparisons);
}
use of com.enonic.xp.node.NodeComparison in project xp by enonic.
the class ResolveSyncWorkCommand method addNewAndMovedParents.
private void addNewAndMovedParents(final Set<NodeComparison> comparisons) {
final NodePaths parentPaths = getPathsFromComparisons(comparisons);
final NodeIds parentIds = getParentIdsFromPaths(parentPaths);
final NodeIds.Builder filteredParentIdsBuilder = NodeIds.create();
getFilteredNewAndMovedParentComparisons(parentIds).stream().map(NodeComparison::getNodeId).forEach(filteredParentIdsBuilder::add);
final NodeIds filteredParentIds = filteredParentIdsBuilder.build();
final NodeIds parentsDependencies = includeDependencies ? getNodeDependencies(filteredParentIds) : NodeIds.empty();
final NodeComparisons newComparisonsToConsider = CompareNodesCommand.create().nodeIds(NodeIds.create().addAll(parentsDependencies).addAll(filteredParentIds).build()).target(this.target).storageService(this.nodeStorageService).build().execute();
final Set<NodeComparison> newAndMoved = getNewAndMoved(newComparisonsToConsider);
addToResult(NodeComparisons.create().addAll(newAndMoved).build());
if (!newAndMoved.isEmpty()) {
addNewAndMovedParents(newAndMoved);
}
}
use of com.enonic.xp.node.NodeComparison in project xp by enonic.
the class CompareNodeCommandTest method status_newer.
@Test
public void status_newer() throws Exception {
ctxDefault().callWith(this::createDefaultRootNode);
final Node createdNode = ctxDefault().callWith(() -> createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build()));
ctxDefault().runWith(() -> doPushNode(WS_OTHER, createdNode));
refresh();
ctxDefault().runWith(() -> doUpdateNode(createdNode));
refresh();
final NodeComparison comparison = ctxDefault().callWith(() -> doCompare(WS_OTHER, createdNode));
assertEquals(CompareStatus.NEWER, comparison.getCompareStatus());
}
Aggregations