/** * Return the closest {@link ContainerScope} name associated to the given * container. Order of scopes is important since the first matching item * from this list is returned. * * @param scopes * The available scopes. * @param container * The containers to check. * @return The closest {@link ContainerScope} or <code>null</code> if not * found. */ public ContainerScope toScope(final List<ContainerScope> scopes, final ContainerOrg container) { return scopes.stream().filter(s -> DnUtils.equalsOrParentOf(s.getDn(), container.getDn())).findFirst().orElse(null); }
@Override protected void checkForDeletion(final ContainerOrg container) { super.checkForDeletion(container); // Company deletion is only possible where there is no user inside this company, or inside any sub-company final Map<String, UserOrg> users = getUser().findAll(); if (getRepository().findAll().values().stream() .filter(c -> DnUtils.equalsOrParentOf(container.getDn(), c.getDn())) .anyMatch(c -> users.values().stream().map(UserOrg::getCompany).anyMatch(c.getId()::equals))) { // Locked container is inside the container to delete throw new ValidationJsonException(getTypeName(), "not-empty-company", "0", getTypeName(), "1", container.getId()); } }
/** * Check the container can be deleted by the current user. * * @param container * The container to delete. */ protected void checkForDeletion(final ContainerOrg container) { // Check the container can be deleted by the current user. Used DN will // be FQN to match the delegates if (!delegateRepository.canCreate(securityHelper.getLogin(), Normalizer.normalize(container.getDn()), this.type.getDelegateType())) { // Not managed container, report this attempt and act as if this // company did not exist log.warn("Attempt to delete a {} '{}' out of scope", type, container.getName()); throw new ValidationJsonException(getTypeName(), BusinessException.KEY_UNKNOW_ID, "0", getTypeName(), "1", container.getId()); } // Check this container is not locked if (container.isLocked()) { throw new ValidationJsonException("company", "locked", "0", container.getName()); } }