Search in sources :

Example 1 with DeleteLastApplicationEnvironmentException

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();
}
Also used : ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeleteLastApplicationEnvironmentException(alien4cloud.exception.DeleteLastApplicationEnvironmentException) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Audit (alien4cloud.audit.annotation.Audit)1 DeleteLastApplicationEnvironmentException (alien4cloud.exception.DeleteLastApplicationEnvironmentException)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 ApiOperation (io.swagger.annotations.ApiOperation)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1