Delete ApiDefinition files in storage if the whole API gets deleted
MODIFY
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/OrganizationResourceImpl.java
@@ -304,7 +304,8 @@ public class OrganizationResourceImpl implements IOrganizationResource {
Iterator<ApiVersionBean> apiVersions = storage.getAllApiVersions(organizationId, apiId);
Iterable<ApiVersionBean> iterable = () -> apiVersions;
- List<ApiVersionBean> registeredElems = StreamSupport.stream(iterable.spliterator(), false)
+ 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());
@@ -312,6 +313,13 @@ public class OrganizationResourceImpl implements IOrganizationResource {
if (!registeredElems.isEmpty()) {
throw ExceptionFactory.entityStillActiveExceptionApiVersions(registeredElems);
}
+
+ for (ApiVersionBean apiVersion : apiVersionBeans) {
+ // add apiBean to apiVerionBean, otherwise deleteApiDefinition fails for EsStorage
+ apiVersion.setApi(api);
+ storage.deleteApiDefinition(apiVersion);
+ }
+
storage.deleteApi(api);
storage.commitTx();
log.debug("Deleted API: " + api.getName()); //$NON-NLS-1$

Delete ApiDefinition files in storage if the whole API gets deleted (#765)