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