use of alien4cloud.model.application.ApplicationEnvironment 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();
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentController method update.
/**
* Update application environment
*
* @param applicationEnvironmentId
* @param request
* @return
*/
@ApiOperation(value = "Updates by merging the given request into the given application environment", notes = "The logged-in user must have the application manager role for this application. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> update(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId, @RequestBody UpdateApplicationEnvironmentRequest request) throws OrchestratorDisabledException {
// Only APPLICATION_MANAGER on the underlying application can update an application environment
ApplicationEnvironment applicationEnvironment = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER);
if (applicationEnvironment == null) {
return RestResponseBuilder.<Void>builder().data(null).error(RestErrorBuilder.builder(RestErrorCode.APPLICATION_ENVIRONMENT_ERROR).message("Application environment with id <" + applicationEnvironmentId + "> does not exist").build()).build();
}
applicationEnvironmentService.ensureNameUnicity(applicationEnvironment.getApplicationId(), request.getName());
ReflectionUtil.mergeObject(request, applicationEnvironment);
if (applicationEnvironment.getName() == null || applicationEnvironment.getName().isEmpty()) {
throw new UnsupportedOperationException("Application environment name cannot be set to null or empty");
}
if (request.getCurrentVersionId() != null) {
// update the version of the environment
ApplicationVersion applicationVersion = applicationVersionService.getOrFailByArchiveId(Csar.createId(applicationEnvironment.getApplicationId(), request.getCurrentVersionId()));
applicationEnvironment.setVersion(applicationVersion.getVersion());
applicationEnvironment.setTopologyVersion(request.getCurrentVersionId());
}
alienDAO.save(applicationEnvironment);
return RestResponseBuilder.<Void>builder().build();
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentRolesController method addUserRole.
/**
* Add a role to a user on a specific application environment
*
* @param applicationEnvironmentId application environment id
* @param username user for who to add role
* @param role the application role to add to this user
* @return A {@link Void} {@link RestResponse}.
*/
@ApiOperation(value = "Add a role to a user on a specific application environment", notes = "Any user with application role APPLICATION_MANAGER can assign any role to another user. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/users/{username}/{role}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> addUserRole(@PathVariable String applicationEnvironmentId, @PathVariable String username, @PathVariable String role) {
ApplicationEnvironment applicationEnvironment = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER);
resourceRoleService.addUserRole(applicationEnvironment, username, role);
handleAddUserRoleOnApplication(applicationEnvironment.getApplicationId(), username);
return RestResponseBuilder.<Void>builder().build();
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentRolesController method addGroupRole.
/**
* Add a role to a group on a specific application environment
*
* @param applicationEnvironmentId application environment id
* @param groupId The id of the group to update roles
* @param role The role to add to the group on the application environment from {@link ApplicationEnvironmentRole}
* @return A {@link Void} {@link RestResponse}.
*/
@ApiOperation(value = "Add a role to a group on a specific application environment", notes = "Any user with application role APPLICATION_MANAGER can assign any role to a group of users. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/groups/{groupId}/{role}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> addGroupRole(@PathVariable String applicationEnvironmentId, @PathVariable String groupId, @PathVariable String role) {
ApplicationEnvironment applicationEnvironment = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER);
resourceRoleService.addGroupRole(applicationEnvironment, groupId, role);
handleAddGrpRoleOnApplication(applicationEnvironment.getApplicationId(), groupId);
return RestResponseBuilder.<Void>builder().build();
}
use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentRolesController method handleRemoveUserRoleOnApplication.
/**
* Handle remove roles on the targeted application
*
* @param applicationId
* @param username
*/
private void handleRemoveUserRoleOnApplication(String applicationId, String username) {
Application application = applicationService.getOrFail(applicationId);
// Check if user has at least one role on the application or the environments
Set<String> applicationRoles = application.getUserRoles() != null ? application.getUserRoles().get(username) : new HashSet<>();
List<Set<String>> environmentRoles = Arrays.stream(applicationEnvironmentService.getByApplicationId(applicationId)).map(applicationEnvironment -> applicationEnvironment.getUserRoles() != null ? applicationEnvironment.getUserRoles().get(username) : null).filter(roles -> roles != null).collect(Collectors.toList());
if (mustRemoveApplicationUserRole(applicationRoles, environmentRoles)) {
// If we are here, it means that we must take out the APPLICATION_USER role for application as user does not have any other role than that
resourceRoleService.removeUserRole(application, username, ApplicationRole.APPLICATION_USER.toString());
}
}
Aggregations