use of io.apiman.manager.api.rest.exceptions.EntityStillActiveException in project apiman by apiman.
the class OrganizationResourceImpl method deleteClient.
/**
* @see IOrganizationResource#deleteClient(java.lang.String, java.lang.String)
*/
@Override
public void deleteClient(@PathParam("organizationId") String organizationId, @PathParam("clientId") String clientId) throws OrganizationNotFoundException, NotAuthorizedException, EntityStillActiveException {
securityContext.checkPermissions(PermissionType.clientAdmin, organizationId);
try {
storage.beginTx();
ClientBean client = getClientFromStorage(organizationId, clientId);
Iterator<ClientVersionBean> clientVersions = storage.getAllClientVersions(organizationId, clientId);
Iterable<ClientVersionBean> iterable = () -> clientVersions;
List<ClientVersionBean> registeredElems = StreamSupport.stream(iterable.spliterator(), false).filter(clientVersion -> clientVersion.getStatus() == ClientStatus.Registered).limit(5).collect(toList());
if (!registeredElems.isEmpty()) {
throw ExceptionFactory.entityStillActiveExceptionClientVersions(registeredElems);
}
storage.deleteClient(client);
storage.commitTx();
// $NON-NLS-1$
log.debug("Deleted ClientApp: " + client.getName());
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.EntityStillActiveException in project apiman by apiman.
the class OrganizationResourceImpl method deleteApi.
/**
* @see IOrganizationResource#deleteApi(java.lang.String, java.lang.String)
*/
@Override
public void deleteApi(@PathParam("organizationId") String organizationId, @PathParam("apiId") String apiId) throws OrganizationNotFoundException, NotAuthorizedException, EntityStillActiveException {
securityContext.checkPermissions(PermissionType.apiAdmin, organizationId);
try {
storage.beginTx();
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);
storage.commitTx();
// $NON-NLS-1$
log.debug("Deleted API: " + api.getName());
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.EntityStillActiveException in project apiman by apiman.
the class OrganizationResourceImpl method delete.
/**
* @see IOrganizationResource#delete(java.lang.String)
*/
@Override
public void delete(@PathParam("organizationId") String organizationId) throws OrganizationNotFoundException, NotAuthorizedException, EntityStillActiveException {
securityContext.checkPermissions(PermissionType.orgAdmin, organizationId);
try {
storage.beginTx();
OrganizationBean organizationBean = getOrganizationFromStorage(organizationId);
// Any active app versions?
Iterator<ClientVersionBean> clientAppsVers = storage.getAllClientVersions(organizationBean, ClientStatus.Registered, 5);
if (clientAppsVers.hasNext()) {
throw ExceptionFactory.entityStillActiveExceptionClientVersions(clientAppsVers);
}
// Any active API versions?
Iterator<ApiVersionBean> apiVers = storage.getAllApiVersions(organizationBean, ApiStatus.Published, 5);
if (apiVers.hasNext()) {
throw ExceptionFactory.entityStillActiveExceptionApiVersions(apiVers);
}
// Any unbroken contracts?
Iterator<ContractBean> contracts = storage.getAllContracts(organizationBean, 5);
if (contracts.hasNext()) {
throw ExceptionFactory.entityStillActiveExceptionContracts(contracts);
}
// Any active plans versions?
Iterator<PlanVersionBean> planVers = storage.getAllPlanVersions(organizationBean, 5);
if (planVers.hasNext()) {
// $NON-NLS-1$
log.warn("There are locked plans(s): these will be deleted.");
}
// Delete org
storage.deleteOrganization(organizationBean);
storage.commitTx();
// $NON-NLS-1$
log.debug("Deleted Organization: " + organizationBean.getName());
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
Aggregations