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;
}
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());
}
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());
}
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());
}
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());
}
Aggregations