public void deleteApi(String organizationId, String apiId)
        throws OrganizationNotFoundException, NotAuthorizedException, EntityStillActiveException {
        tryAction(() -> {
            ApiBean api = getApiFromStorage(organizationId, apiId);

            Iterator<ApiVersionBean> apiVersions = storage.getAllApiVersions(organizationId, apiId);
            Iterable<ApiVersionBean> iterable = () -> apiVersions;

            List<ApiVersionBean> apiVersionBeans = StreamSupport.stream(iterable.spliterator(), false)
                .collect(toList());

            List<ApiVersionBean> registeredElems = apiVersionBeans.stream()
                .filter(clientVersion -> clientVersion.getStatus() == ApiStatus.Published)
                .limit(5)
                .collect(toList());

            if (!registeredElems.isEmpty()) {
                throw ExceptionFactory.entityStillActiveExceptionApiVersions(registeredElems);
            }

            for (ApiVersionBean apiVersion : apiVersionBeans) {
                // add apiBean to apiVersionBean, otherwise deleteApiDefinition fails for EsStorage
                apiVersion.setApi(api);
                if (apiVersionHasApiDefinition(apiVersion)) {
                    storage.deleteApiDefinition(apiVersion);
                }
            }
            storage.deleteApi(api);
            if (api.getImage() != null) {
                blobStore.remove(api.getImage());
            }
            LOGGER.debug("Deleted API: {0}", api.getName()); //$NON-NLS-1$
        });
    }
@author Marc Savy {@literal <marc@blackparrotlabs.io>}
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/ApiService.java