use of alien4cloud.exception.DeleteLastApplicationEnvironmentException in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentController method delete.
/**
* Delete an application environment based on it's id.
*
* @param applicationEnvironmentId
* @return
*/
@ApiOperation(value = "Delete an application environment from its id", notes = "The logged-in user must have the application manager role for this application. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Boolean> delete(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) {
// Only APPLICATION_MANAGER on the underlying application can delete an application environment
ApplicationEnvironment environmentToDelete = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER);
int countEnvironment = applicationEnvironmentService.getByApplicationId(environmentToDelete.getApplicationId()).length;
if (countEnvironment == 1) {
throw new DeleteLastApplicationEnvironmentException("Application environment with id <" + applicationEnvironmentId + "> cannot be deleted as it's the last one for the application id <" + environmentToDelete.getApplicationId() + ">");
}
applicationEnvironmentService.delete(applicationEnvironmentId);
return RestResponseBuilder.<Boolean>builder().data(true).build();
}
Aggregations