Search in sources :

Example 31 with NodeIds

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

the class FindNodesDependenciesCommand method resolveDependencies.

private NodeIds resolveDependencies(final NodeIds nodeIds) {
    Set<NodeId> nonProcessedNodes = nodeIds.getSet().stream().filter((nodeId) -> !processed.contains(nodeId)).collect(Collectors.toSet());
    if (nonProcessedNodes.isEmpty()) {
        return NodeIds.empty();
    }
    final SearchResult result = getReferences(nonProcessedNodes);
    this.processed.addAll(nonProcessedNodes);
    final NodeIds.Builder builder = NodeIds.create();
    if (result.isEmpty()) {
        return NodeIds.empty();
    }
    addNodeIdsFromReferenceReturnValues(result, builder);
    if (this.recursive) {
        NodeIds currentLevelDependencies = builder.build();
        if (recursionFilter != null) {
            currentLevelDependencies = recursionFilter.apply(currentLevelDependencies);
        }
        builder.addAll(resolveDependencies(currentLevelDependencies));
    }
    return builder.build();
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) ReturnFields(com.enonic.xp.repo.impl.ReturnFields) ReturnValue(com.enonic.xp.repo.impl.ReturnValue) NodeIndexPath(com.enonic.xp.node.NodeIndexPath) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) Set(java.util.Set) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) SingleRepoSearchSource(com.enonic.xp.repo.impl.SingleRepoSearchSource) NodeId(com.enonic.xp.node.NodeId) HashSet(java.util.HashSet) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) ContextAccessor(com.enonic.xp.context.ContextAccessor) SearchHit(com.enonic.xp.repo.impl.search.result.SearchHit) NodeQuery(com.enonic.xp.node.NodeQuery) NodeIds(com.enonic.xp.node.NodeIds) NodeIds(com.enonic.xp.node.NodeIds) NodeId(com.enonic.xp.node.NodeId) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 32 with NodeIds

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

the class SecurityServiceImpl method deletePrincipal.

@Override
public void deletePrincipal(final PrincipalKey principalKey) {
    final NodeIds deletedNodes;
    try {
        deletedNodes = callWithContext(() -> {
            doRemoveRelationships(principalKey);
            doRemoveMemberships(principalKey);
            final NodeIds nodes = this.nodeService.deleteByPath(principalKey.toPath());
            this.nodeService.refresh(RefreshMode.SEARCH);
            return nodes;
        });
    } catch (// catch doRemoveRelationships and doRemoveMemberships leak of permissions
    NodeNotFoundException e) {
        throw new PrincipalNotFoundException(principalKey);
    }
    if (deletedNodes.isEmpty()) {
        throw new PrincipalNotFoundException(principalKey);
    }
    securityAuditLogSupport.removePrincipal(principalKey);
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeIds(com.enonic.xp.node.NodeIds) PrincipalNotFoundException(com.enonic.xp.security.PrincipalNotFoundException)

Example 33 with NodeIds

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

the class SecurityServiceImpl method deleteIdProvider.

@Override
public void deleteIdProvider(final IdProviderKey idProviderKey) {
    removeRelationships(idProviderKey);
    final NodeIds deletedNodes = callWithContext(() -> {
        final NodePath idProviderNodePath = IdProviderNodeTranslator.toIdProviderNodePath(idProviderKey);
        final Node node = this.nodeService.getByPath(idProviderNodePath);
        if (node == null) {
            return null;
        }
        return this.nodeService.deleteById(node.id());
    });
    if (deletedNodes == null) {
        throw new IdProviderNotFoundException(idProviderKey);
    }
    securityAuditLogSupport.removeIdProvider(idProviderKey);
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) Node(com.enonic.xp.node.Node) IdProviderNotFoundException(com.enonic.xp.security.IdProviderNotFoundException) NodePath(com.enonic.xp.node.NodePath)

Example 34 with NodeIds

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

the class DeleteContentCommand method deleteNodeInDraftAndMaster.

private void deleteNodeInDraftAndMaster(final NodeId nodeToDelete, final DeleteContentsResult.Builder result) {
    final Context draftContext = ContextAccessor.current();
    final Context masterContext = ContextBuilder.from(draftContext).branch(ContentConstants.BRANCH_MASTER).build();
    final Node draftRootNode = nodeService.getById(nodeToDelete);
    final NodeIds draftNodes = deleteNodeInContext(nodeToDelete, draftContext);
    final NodeIds masterNodes = deleteNodeInContext(nodeToDelete, masterContext);
    result.addDeleted(ContentIds.from(draftNodes.getAsStrings()));
    result.addUnpublished(ContentIds.from(masterNodes.getAsStrings()));
    final NodeIds masterIdsByDraftPath = masterContext.callWith(() -> this.nodeService.findByParent(FindNodesByParentParams.create().parentPath(draftRootNode.path()).recursive(true).build()).getNodeIds());
    Stream.concat(masterIdsByDraftPath.stream(), draftNodes.stream()).filter(id -> !masterNodes.contains(id)).forEach(id -> {
        deleteNodeInContext(id, masterContext);
        result.addUnpublished(ContentId.from(id.toString()));
    });
}
Also used : Context(com.enonic.xp.context.Context) RefreshMode(com.enonic.xp.node.RefreshMode) ContentConstants(com.enonic.xp.content.ContentConstants) Node(com.enonic.xp.node.Node) NodeComparison(com.enonic.xp.node.NodeComparison) Branch(com.enonic.xp.branch.Branch) DeleteContentParams(com.enonic.xp.content.DeleteContentParams) ContentId(com.enonic.xp.content.ContentId) ContextAccessor(com.enonic.xp.context.ContextAccessor) ContextBuilder(com.enonic.xp.context.ContextBuilder) ContentAccessException(com.enonic.xp.content.ContentAccessException) NodePath(com.enonic.xp.node.NodePath) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) NodeId(com.enonic.xp.node.NodeId) SetNodeStateParams(com.enonic.xp.node.SetNodeStateParams) Stream(java.util.stream.Stream) NodeState(com.enonic.xp.node.NodeState) ContentIds(com.enonic.xp.content.ContentIds) DeleteNodeListener(com.enonic.xp.node.DeleteNodeListener) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) NodeAccessException(com.enonic.xp.node.NodeAccessException) Preconditions(com.google.common.base.Preconditions) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) NodeIds(com.enonic.xp.node.NodeIds) CompareStatus(com.enonic.xp.content.CompareStatus) NodeIds(com.enonic.xp.node.NodeIds) Node(com.enonic.xp.node.Node)

Example 35 with NodeIds

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

the class DeleteContentCommand method doExecute.

private DeleteContentsResult doExecute() {
    this.nodeService.refresh(RefreshMode.ALL);
    final NodePath nodePath = ContentNodeHelper.translateContentPathToNodePath(this.params.getContentPath());
    final Node nodeToDelete = this.nodeService.getByPath(nodePath);
    if (nodeToDelete == null) {
        throw new ContentNotFoundException(this.params.getContentPath(), ContextAccessor.current().getBranch());
    }
    if (!params.isDeleteOnline()) {
        final NodeIds draftChildren = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(nodeToDelete.id()).recursive(true).build()).getNodeIds();
        final boolean anyChildIsMovedIn = nodeService.compare(draftChildren, ContentConstants.BRANCH_MASTER).getComparisons().stream().anyMatch(nodeComparison -> {
            final boolean moved = CompareStatus.MOVED.equals(nodeComparison.getCompareStatus());
            return moved && !nodeComparison.getTargetPath().asAbsolute().toString().startsWith(nodePath.asAbsolute().toString());
        });
        if (anyChildIsMovedIn) {
            throw new RuntimeException(String.format("Cannot make content tree pending delete for [%s], at least one published child is moved in from outside.", nodeToDelete.id()));
        }
    }
    final DeleteContentsResult deletedContents = doDeleteContent(nodeToDelete.id());
    this.nodeService.refresh(RefreshMode.ALL);
    return deletedContents;
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) NodeIds(com.enonic.xp.node.NodeIds) Node(com.enonic.xp.node.Node) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) NodePath(com.enonic.xp.node.NodePath)

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