Search in sources :

Example 1 with NodeComparisons

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

the class ResolveRequiredDependenciesCommand method resolveDependencies.

private void resolveDependencies() {
    final NodeComparisons nodeComparisons = nodeService.compare(NodeIds.from(contentIds.asStrings()), target);
    this.resultBuilder.addAll(getRequiredIds(nodeComparisons));
}
Also used : NodeComparisons(com.enonic.xp.node.NodeComparisons)

Example 2 with NodeComparisons

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

the class UndoPendingDeleteContentCommand method undoDeleteContent.

private void undoDeleteContent(final NodeIds nodeIds) {
    final NodeComparisons compare = this.nodeService.compare(nodeIds, this.params.getTarget());
    Set<NodeComparison> pendingDeleteNodes = compare.getWithStatus(CompareStatus.PENDING_DELETE);
    for (final NodeComparison nodeComparison : pendingDeleteNodes) {
        ensureValidParent(nodeComparison);
        removePendingDeleteState(nodeComparison);
    }
    for (NodeId nodeId : nodeIds) {
        this.undoDeleteContent(this.getAllChildren(nodeId));
    }
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) NodeId(com.enonic.xp.node.NodeId) NodeComparisons(com.enonic.xp.node.NodeComparisons)

Example 3 with NodeComparisons

use of com.enonic.xp.node.NodeComparisons 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 4 with NodeComparisons

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

the class CompareNodesCommandTest method compare_nodes.

@Test
public void compare_nodes() throws Exception {
    final Node node = createNode(CreateNodeParams.create().name("node1").parent(NodePath.ROOT).build());
    final Node node2 = createNode(CreateNodeParams.create().name("node2").parent(NodePath.ROOT).build());
    final Node node3 = createNode(CreateNodeParams.create().name("node3").parent(NodePath.ROOT).build());
    pushNodes(NodeIds.from(node.id(), node2.id()), WS_OTHER);
    doDeleteNode(node2.id());
    refresh();
    final NodeComparisons result = CompareNodesCommand.create().nodeIds(NodeIds.from(node.id(), node2.id(), node3.id())).storageService(this.storageService).target(WS_OTHER).build().execute();
    assertEquals(1, result.getWithStatus(CompareStatus.NEW_TARGET).size());
    assertEquals(1, result.getWithStatus(CompareStatus.NEW).size());
    assertEquals(1, result.getWithStatus(CompareStatus.EQUAL).size());
}
Also used : Node(com.enonic.xp.node.Node) NodeComparisons(com.enonic.xp.node.NodeComparisons) Test(org.junit.jupiter.api.Test)

Example 5 with NodeComparisons

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

the class CompareNodesCommand method execute.

public NodeComparisons execute() {
    Set<NodeId> allNodeIds = new HashSet<>();
    final Context context = ContextAccessor.current();
    final NodeComparisons.Builder builder = NodeComparisons.create();
    final NodeBranchEntries sourceVersions = nodeStorageService.getBranchNodeVersions(nodeIds, false, InternalContext.from(context));
    final NodeBranchEntries targetVersions = nodeStorageService.getBranchNodeVersions(nodeIds, false, InternalContext.create(context).branch(this.target).build());
    allNodeIds.addAll(sourceVersions.getKeys());
    allNodeIds.addAll(targetVersions.getKeys());
    for (final NodeId id : allNodeIds) {
        final CompareStatus compareStatus = CompareStatusResolver.create().source(sourceVersions.get(id)).target(targetVersions.get(id)).storageService(this.nodeStorageService).build().resolve();
        builder.add(new NodeComparison(sourceVersions.get(id), targetVersions.get(id), compareStatus));
    }
    return builder.build();
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeComparison(com.enonic.xp.node.NodeComparison) NodeId(com.enonic.xp.node.NodeId) CompareStatus(com.enonic.xp.content.CompareStatus) NodeComparisons(com.enonic.xp.node.NodeComparisons) HashSet(java.util.HashSet)

Aggregations

NodeComparisons (com.enonic.xp.node.NodeComparisons)8 NodeComparison (com.enonic.xp.node.NodeComparison)3 NodeId (com.enonic.xp.node.NodeId)3 NodeIds (com.enonic.xp.node.NodeIds)3 CompareStatus (com.enonic.xp.content.CompareStatus)2 Context (com.enonic.xp.context.Context)2 Node (com.enonic.xp.node.Node)2 NodeBranchEntries (com.enonic.xp.node.NodeBranchEntries)2 InternalContext (com.enonic.xp.repo.impl.InternalContext)2 Test (org.junit.jupiter.api.Test)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 NodePath (com.enonic.xp.node.NodePath)1 NodePaths (com.enonic.xp.node.NodePaths)1 Reference (com.enonic.xp.util.Reference)1 HashSet (java.util.HashSet)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1