Search in sources :

Example 11 with NodeIds

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

the class DeleteIssueCommentCommandTest method delete.

@Test
public void delete() {
    DeleteIssueCommentParams params = DeleteIssueCommentParams.create().comment(NodeId.from(UUID.randomUUID())).build();
    final NodeIds nodeIds = NodeIds.from(params.getComment());
    final DeleteIssueCommentCommand command = createDeleteIssueCommentCommand(params);
    Mockito.when(this.nodeService.deleteById(Mockito.any(NodeId.class))).thenReturn(nodeIds);
    final DeleteIssueCommentResult result = command.execute();
    assertNotNull(result);
    assertEquals(1, result.getIds().getSize());
    assertEquals(params.getComment(), result.getIds().first());
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) NodeId(com.enonic.xp.node.NodeId) DeleteIssueCommentParams(com.enonic.xp.issue.DeleteIssueCommentParams) DeleteIssueCommentResult(com.enonic.xp.issue.DeleteIssueCommentResult) Test(org.junit.jupiter.api.Test)

Example 12 with NodeIds

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

the class DeleteScheduledJobCommand method doExecute.

private boolean doExecute() {
    final NodeIds result = nodeService.deleteByPath(NodePath.create(NodePath.ROOT, name.getValue()).build());
    nodeService.refresh(RefreshMode.ALL);
    return !result.isEmpty();
}
Also used : NodeIds(com.enonic.xp.node.NodeIds)

Example 13 with NodeIds

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

the class DeleteContentCommand method doDeleteContent.

private DeleteContentsResult doDeleteContent(NodeId nodeToDelete) {
    final CompareStatus rootNodeStatus = getCompareStatus(nodeToDelete);
    final DeleteContentsResult.Builder result = DeleteContentsResult.create();
    if (rootNodeStatus == CompareStatus.NEW) {
        // Root node is new, just delete all children
        final NodeIds nodes = this.nodeService.deleteById(nodeToDelete, this);
        result.addDeleted(ContentIds.from(nodes.getAsStrings()));
    } else if (this.params.isDeleteOnline()) {
        deleteNodeInDraftAndMaster(nodeToDelete, result);
    } else {
        this.nodeService.setNodeState(SetNodeStateParams.create().nodeId(nodeToDelete).nodeState(NodeState.PENDING_DELETE).build());
        result.addPending(ContentId.from(nodeToDelete.toString()));
        this.nodesDeleted(1);
        final NodeIds children = getDirectChildren(nodeToDelete);
        for (final NodeId child : children) {
            final DeleteContentsResult childDeleteResult = this.doDeleteContent(child);
            result.addDeleted(childDeleteResult.getDeletedContents());
            result.addPending(childDeleteResult.getPendingContents());
        }
    }
    return result.build();
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) CompareStatus(com.enonic.xp.content.CompareStatus) NodeId(com.enonic.xp.node.NodeId) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult)

Example 14 with NodeIds

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

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

Aggregations

NodeIds (com.enonic.xp.node.NodeIds)38 Node (com.enonic.xp.node.Node)12 NodeId (com.enonic.xp.node.NodeId)11 Test (org.junit.jupiter.api.Test)11 NodePath (com.enonic.xp.node.NodePath)6 Collectors (java.util.stream.Collectors)5 CompareStatus (com.enonic.xp.content.CompareStatus)4 ContentIds (com.enonic.xp.content.ContentIds)4 ContextAccessor (com.enonic.xp.context.ContextAccessor)4 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)4 NodeComparison (com.enonic.xp.node.NodeComparison)4 NodeComparisons (com.enonic.xp.node.NodeComparisons)4 NodeQuery (com.enonic.xp.node.NodeQuery)4 Branch (com.enonic.xp.branch.Branch)3 ContentId (com.enonic.xp.content.ContentId)3 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)3 Context (com.enonic.xp.context.Context)3 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)3 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)2 PropertyTree (com.enonic.xp.data.PropertyTree)2