/** * Delete an archive an all its registered / saved elements * Abort the deletion if the archive is used by some resources * * @param csar * @return A List of {@link Usage} representing the resources using this archive. */ public List<Usage> deleteCsarWithElements(Csar csar) { // if the csar is bound to an application, then do not allow the process if (Objects.equals(csar.getDelegateType(), ArchiveDelegateType.APPLICATION.toString())) { throw new UnsupportedOperationException("Cannot delete an application csar from here "); } List<Usage> relatedResourceList = getCsarRelatedResourceList(csar); if (relatedResourceList.isEmpty()) { deleteCsar(csar); } return relatedResourceList; }
/** * 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; } }
if (topology.getDescription() == null && ArchiveDelegateType.APPLICATION.toString().equals(csar.getDelegateType())) {
/** * 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); } }
if (Objects.equals(csar.getDelegateType(), ArchiveDelegateType.APPLICATION.toString())) {
/** * Build a topology dto (topology and all used types) out of a topology. * * @param context The edition context from which to build the dto. */ @ToscaContextual public TopologyDTO buildTopologyDTO(EditionContext context) { TopologyDTO topologyDTO = new TopologyDTO(); initTopologyDTO(context.getTopology(), topologyDTO); topologyDTO.setArchiveContentTree(context.getArchiveContentTree()); topologyDTO.setLastOperationIndex(context.getLastOperationIndex()); topologyDTO.setOperations(context.getOperations()); topologyDTO.setDelegateType(context.getCsar().getDelegateType()); topologyDTO.setDependencyConflicts(getDependencyConflictDTOs(context)); // FIXME add validation information return topologyDTO; }