use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.
the class TopologyLocationMatchingController method match.
@ApiOperation(value = "Retrieve the list of locations on which the current user can deploy the topology.")
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<List<ILocationMatch>> match(@PathVariable String topologyId, @RequestParam(required = false) String environmentId) {
List<ILocationMatch> matchedLocation;
if (StringUtils.isNotBlank(environmentId)) {
ApplicationEnvironment environment = applicationEnvironmentService.getOrFail(environmentId);
Application application = applicationService.getOrFail(environment.getApplicationId());
AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.DEPLOYMENT_MANAGER);
matchedLocation = locationMatchingService.match(topologyId, environment);
} else {
matchedLocation = locationMatchingService.match(topologyId, null);
}
return RestResponseBuilder.<List<ILocationMatch>>builder().data(matchedLocation).build();
}
use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.
the class TopologyService method checkAuthorizations.
/**
* Check that the user has enough rights for a given topology.
*
* @param topology The topology for which to check roles.
* @param applicationRoles The roles required to edit the topology for an application.
*/
private void checkAuthorizations(Topology topology, ApplicationRole[] applicationRoles, Role[] roles) {
Csar relatedCsar = ToscaContext.get().getArchive(topology.getArchiveName(), topology.getArchiveVersion());
if (Objects.equals(relatedCsar.getDelegateType(), ArchiveDelegateType.APPLICATION.toString())) {
String applicationId = relatedCsar.getDelegateId();
Application application = appService.getOrFail(applicationId);
AuthorizationUtil.checkAuthorizationForApplication(application, applicationRoles);
} else {
AuthorizationUtil.checkHasOneRoleIn(roles);
}
}
use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.
the class ApplicationService method update.
/**
* Update the name and description of an application.
*
* @param applicationId The application id.
* @param newName The new name for the application.
* @param newDescription The new description for the application.
*/
public void update(String applicationId, String newName, String newDescription) {
Application application = checkAndGetApplication(applicationId, ApplicationRole.APPLICATION_MANAGER);
if (newName != null && !newName.isEmpty() && !application.getName().equals(newName)) {
checkApplicationName(newName);
application.setName(newName);
}
if (newDescription != null) {
application.setDescription(newDescription);
}
alienDAO.save(application);
}
use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.
the class ApplicationService method create.
/**
* Create a new application and return it's id
*
* @param user The user that is creating the application (will be APPLICATION_MANAGER)
* @param archiveName The unique archive name (and if for the application).
* @param name The name of the new application.
* @param description The description of the new application.
* @return The id of the newly created application.
*/
public String create(String user, String archiveName, String name, String description) {
checkApplicationId(archiveName);
checkApplicationName(name);
Application application = new Application();
application.setId(archiveName);
Map<String, Set<String>> userRoles = Maps.newHashMap();
userRoles.put(user, Sets.newHashSet(ApplicationRole.APPLICATION_MANAGER.toString()));
application.setUserRoles(userRoles);
application.setName(name);
application.setDescription(description);
application.setTags(Lists.newArrayList());
application.setMetaProperties(Maps.newHashMap());
alienDAO.save(application);
resourceUpdateInterceptor.runOnNewApplication(application);
return archiveName;
}
use of alien4cloud.model.application.Application in project alien4cloud by alien4cloud.
the class SecuredResourceStepDefinition method getResourceRequest.
private String getResourceRequest(String resourceTypeId, String resourceName) throws Throwable {
String request = null;
String orchestratorName = LocationsDefinitionsSteps.DEFAULT_ORCHESTRATOR_NAME;
switch(RESOURCE_TYPE.valueOf(resourceTypeId)) {
case APPLICATION:
request = "/rest/v1/applications/" + Context.getInstance().getApplicationId(resourceName);
break;
case ENVIRONMENT:
Application application = ApplicationStepDefinitions.CURRENT_APPLICATION;
request = "/rest/v1/applications/" + Context.getInstance().getApplicationId(resourceName) + "/environments/" + Context.getInstance().getApplicationEnvironmentId(application.getName(), resourceName);
break;
case LOCATION:
request = "/rest/v1/orchestrators/" + Context.getInstance().getOrchestratorId(orchestratorName) + "/locations/" + LocationsDefinitionsSteps.getLocationIdFromName(orchestratorName, resourceName);
break;
case ORCHESTRATOR:
request = "/rest/v1/orchestrators/" + Context.getInstance().getOrchestratorId(orchestratorName);
break;
default:
}
return request;
}
Aggregations