Search in sources :

Example 16 with NodeComparison

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

the class PushNodesCommand method pushNodes.

private InternalPushNodesResult.Builder pushNodes(final Context context, final NodeBranchEntries nodeBranchEntries, final NodeComparisons comparisons) {
    final PushNodeEntries.Builder publishBuilder = PushNodeEntries.create().targetBranch(this.target).targetRepo(context.getRepositoryId());
    final InternalPushNodesResult.Builder builder = InternalPushNodesResult.create();
    final ArrayList<NodeBranchEntry> list = new ArrayList<>(nodeBranchEntries.getSet());
    list.sort(Comparator.comparing(NodeBranchEntry::getNodePath));
    for (final NodeBranchEntry branchEntry : list) {
        final NodeComparison comparison = comparisons.get(branchEntry.getNodeId());
        final NodeBranchEntry nodeBranchEntry = nodeBranchEntries.get(comparison.getNodeId());
        final boolean hasPublishPermission = NodesHasPermissionResolver.create(this).nodeIds(NodeIds.from(nodeBranchEntry.getNodeId())).permission(Permission.PUBLISH).build().execute();
        if (!hasPublishPermission) {
            builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.ACCESS_DENIED);
            nodePushed(1);
            continue;
        }
        if (comparison.getCompareStatus() == CompareStatus.EQUAL) {
            builder.addSuccess(nodeBranchEntry);
            nodePushed(1);
            continue;
        }
        if ((CompareStatus.NEW == comparison.getCompareStatus() || CompareStatus.MOVED == comparison.getCompareStatus()) && targetAlreadyExists(nodeBranchEntry.getNodePath(), comparisons, context)) {
            builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.ALREADY_EXIST);
            nodePushed(1);
            continue;
        }
        if (!targetParentExists(nodeBranchEntry.getNodePath(), builder, context)) {
            builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.PARENT_NOT_FOUND);
            nodePushed(1);
            continue;
        }
        publishBuilder.add(PushNodeEntry.create().nodeBranchEntry(nodeBranchEntry).currentTargetPath(comparison.getTargetPath()).build());
        builder.addSuccess(nodeBranchEntry);
        if (comparison.getCompareStatus() == CompareStatus.MOVED) {
            updateTargetChildrenMetaData(nodeBranchEntry, builder);
        }
    }
    final PushNodeEntries pushNodeEntries = publishBuilder.build();
    builder.setPushNodeEntries(pushNodeEntries);
    final InternalContext pushContext = InternalContext.create(context).skipConstraints(true).build();
    this.nodeStorageService.push(pushNodeEntries, pushListener, pushContext);
    return builder;
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) InternalContext(com.enonic.xp.repo.impl.InternalContext) ArrayList(java.util.ArrayList) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) PushNodeEntries(com.enonic.xp.node.PushNodeEntries)

Example 17 with NodeComparison

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

the class ResolveSyncWorkCommand method markChildrenForDeletion.

private void markChildrenForDeletion(final NodeComparison comparison) {
    final FindNodesByParentResult result = FindNodeIdsByParentCommand.create(this).size(NodeSearchService.GET_ALL_SIZE_FLAG).parentId(comparison.getNodeId()).childOrder(ChildOrder.from(NodeIndexPath.PATH + " asc")).recursive(true).build().execute();
    final NodeBranchEntries brancEntries = this.nodeStorageService.getBranchNodeVersions(result.getNodeIds(), false, InternalContext.from(ContextAccessor.current()));
    addToResult(NodeComparisons.create().addAll(brancEntries.stream().map((branchEntry) -> new NodeComparison(branchEntry, branchEntry, CompareStatus.PENDING_DELETE)).collect(Collectors.toSet())).build());
}
Also used : NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeComparison(com.enonic.xp.node.NodeComparison) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Example 18 with NodeComparison

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

the class CompareNodeCommandTest method status_deleted_stage_yields_new_in_target.

@Test
public void status_deleted_stage_yields_new_in_target() throws Exception {
    ctxOther().callWith(this::createDefaultRootNode);
    final Node createdNode = ctxOther().callWith(() -> createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build()));
    assertNotNull(ctxOther().callWith(() -> getNodeById(createdNode.id())));
    ctxOther().runWith(() -> doPushNode(WS_DEFAULT, createdNode));
    assertNotNull(ctxDefault().callWith(() -> getNodeById(createdNode.id())));
    DeleteNodeByIdCommand.create().nodeId(createdNode.id()).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    final NodeComparison comparison = ctxDefault().callWith(() -> doCompare(WS_OTHER, createdNode));
    assertEquals(CompareStatus.NEW_TARGET, comparison.getCompareStatus());
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 19 with NodeComparison

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

the class CompareNodeCommandTest method status_new_target.

@Test
public void status_new_target() throws Exception {
    ctxOther().callWith(this::createDefaultRootNode);
    final Node createdNode = ctxOther().callWith(() -> createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build()));
    final NodeComparison comparison = ctxDefault().callWith(() -> doCompare(WS_OTHER, createdNode));
    assertEquals(CompareStatus.NEW_TARGET, comparison.getCompareStatus());
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 20 with NodeComparison

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

the class CompareNodeCommandTest method status_new.

@Test
public void status_new() throws Exception {
    ctxDefault().callWith(this::createDefaultRootNode);
    final Node createdNode = ctxDefault().callWith(() -> createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build()));
    final NodeComparison comparison = ctxDefault().callWith(() -> doCompare(WS_OTHER, createdNode));
    assertEquals(CompareStatus.NEW, 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