Search in sources :

Example 1 with NodeComparison

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

the class PushNodeHandlerTest method testExample3.

@Test
public void testExample3() {
    Mockito.when(nodeService.resolveSyncWork(Mockito.isA(SyncWorkResolverParams.class))).thenReturn(ResolveSyncWorkResult.create().add(new NodeComparison(createEntry("a"), createEntry("a"), CompareStatus.NEW)).add(new NodeComparison(createEntry("b"), createEntry("b"), CompareStatus.NEW)).add(new NodeComparison(createEntry("c"), createEntry("c"), CompareStatus.NEW)).build());
    Mockito.when(nodeService.push(Mockito.isA(NodeIds.class), Mockito.eq(Branch.from("otherBranch")))).thenReturn(PushNodesResult.create().addSuccess(createEntry("a")).addSuccess(createEntry("d")).build());
    runScript("/lib/xp/examples/node/push-3.js");
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) NodeIds(com.enonic.xp.node.NodeIds) SyncWorkResolverParams(com.enonic.xp.node.SyncWorkResolverParams) Test(org.junit.jupiter.api.Test)

Example 2 with NodeComparison

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

the class CompareContentCommand method execute.

public CompareContentResult execute() {
    final NodeId nodeId = NodeId.from(contentId.toString());
    final NodeComparison compareResult = this.nodeService.compare(nodeId, this.target);
    return CompareResultTranslator.translate(compareResult);
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) NodeId(com.enonic.xp.node.NodeId)

Example 3 with NodeComparison

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

the class DeleteContentCommand method getCompareStatus.

private CompareStatus getCompareStatus(final NodeId nodeToDelete) {
    final Context context = ContextAccessor.current();
    final Branch currentBranch = context.getBranch();
    final NodeComparison compare;
    if (currentBranch.equals(ContentConstants.BRANCH_DRAFT)) {
        compare = this.nodeService.compare(nodeToDelete, ContentConstants.BRANCH_MASTER);
    } else {
        compare = this.nodeService.compare(nodeToDelete, ContentConstants.BRANCH_DRAFT);
    }
    return compare.getCompareStatus();
}
Also used : Context(com.enonic.xp.context.Context) NodeComparison(com.enonic.xp.node.NodeComparison) Branch(com.enonic.xp.branch.Branch)

Example 4 with NodeComparison

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

the class ResolveRequiredDependenciesCommand method getRequiredIds.

private ContentIds getRequiredIds(final NodeComparisons nodeComparisons) {
    final NodePaths parentPaths = getParentPaths(nodeComparisons.getComparisons());
    final NodePaths resultPaths = nodeComparisons.getSourcePaths();
    final Set<ContentId> requiredIds = parentPaths.stream().filter(resultPaths::contains).map(parentPath -> {
        final NodeComparison comparison = nodeComparisons.getBySourcePath(parentPath);
        if (!CompareStatus.NEWER.equals(comparison.getCompareStatus())) {
            return ContentId.from(comparison.getNodeId().toString());
        }
        return null;
    }).filter(Objects::nonNull).collect(Collectors.toSet());
    return ContentIds.from(requiredIds);
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) NodePaths(com.enonic.xp.node.NodePaths) ContentId(com.enonic.xp.content.ContentId)

Example 5 with NodeComparison

use of com.enonic.xp.node.NodeComparison 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)

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