Search in sources :

Example 6 with NodeComparison

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);
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) CompareStatus(com.enonic.xp.content.CompareStatus) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Example 7 with NodeComparison

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());
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) NodeComparison(com.enonic.xp.node.NodeComparison) NodeId(com.enonic.xp.node.NodeId)

Example 8 with NodeComparison

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);
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) NodeIds(com.enonic.xp.node.NodeIds)

Example 9 with NodeComparison

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);
    }
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) NodePaths(com.enonic.xp.node.NodePaths) NodeIds(com.enonic.xp.node.NodeIds) NodeComparisons(com.enonic.xp.node.NodeComparisons)

Example 10 with NodeComparison

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());
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Aggregations

NodeComparison (com.enonic.xp.node.NodeComparison)27 Test (org.junit.jupiter.api.Test)14 Node (com.enonic.xp.node.Node)9 NodeId (com.enonic.xp.node.NodeId)4 NodeIds (com.enonic.xp.node.NodeIds)4 SyncWorkResolverParams (com.enonic.xp.node.SyncWorkResolverParams)4 Context (com.enonic.xp.context.Context)3 NodeComparisons (com.enonic.xp.node.NodeComparisons)3 InternalContext (com.enonic.xp.repo.impl.InternalContext)3 CompareStatus (com.enonic.xp.content.CompareStatus)2 NodeBranchEntries (com.enonic.xp.node.NodeBranchEntries)2 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)2 NodePaths (com.enonic.xp.node.NodePaths)2 Branch (com.enonic.xp.branch.Branch)1 ContentId (com.enonic.xp.content.ContentId)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)1 NodePath (com.enonic.xp.node.NodePath)1 PushNodeEntries (com.enonic.xp.node.PushNodeEntries)1 ResolveSyncWorkResult (com.enonic.xp.node.ResolveSyncWorkResult)1