/** * Generate resources related to a csar list * * @param csars * @return */ public List<Usage> generateCsarsInfo(Csar[] csars) { String resourceName; String resourceId; List<Usage> resourceList = Lists.newArrayList(); for (Csar csar : csars) { if (ArchiveDelegateType.APPLICATION.toString().equals(csar.getDelegateType())) { Application application = applicationService.checkAndGetApplication(csar.getDelegateId()); resourceName = application.getName(); } else { resourceName = csar.getName(); } Usage temp = new Usage(resourceName, Csar.class.getSimpleName().toLowerCase(), csar.getId(), csar.getWorkspace()); resourceList.add(temp); } return resourceList; }
/** * Generate resources (application or template) related to a topology list * * @param topologies * @return */ public List<Usage> generateTopologiesInfo(Topology[] topologies) { List<Usage> resourceList = Lists.newArrayList(); List<Csar> topologiesCsar = getTopologiesCsar(topologies); for (Csar csar : topologiesCsar) { if (Objects.equals(csar.getDelegateType(), ArchiveDelegateType.APPLICATION.toString())) { // get the related application Application application = applicationService.checkAndGetApplication(csar.getDelegateId()); resourceList.add(new Usage(application.getName(), csar.getDelegateType(), csar.getDelegateId(), csar.getWorkspace())); } else { resourceList.add(new Usage(csar.getName() + "[" + csar.getVersion() + "]", "topologyTemplate", csar.getId(), csar.getWorkspace())); } } return resourceList; } }
Application application = applicationService.getOrFail(csar.getDelegateId()); velocityCtx.put("topology_description", application.getDescription());
/** * 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); } }
Application application = applicationService.checkAndGetApplication(csar.getDelegateId()); archiveUsageRequestEvent .addUsage(new Usage(application.getName(), Application.class.getSimpleName().toLowerCase(), csar.getDelegateId(), csar.getWorkspace()));