private void fillLocationResourceTypes(Collection<String> exposedTypes, LocationResourceTypes locationResourceTypes, Set<CSARDependency> dependencies, IResourceTypeAdder resourceTypeAdder) { if (CollectionUtils.isEmpty(exposedTypes) || CollectionUtils.isEmpty(dependencies)) { // Protect as in some case this method is called even if there's nothing to fill in return; } exposedTypes.forEach(exposedType -> resourceTypeAdder.process(exposedType)); Map<String, DataType> allDataTypes = new HashMap<>(locationResourceTypes.getDataTypes()); DataTypesFetcher.DataTypeFinder dataTypeFinder = (type, id) -> csarRepoSearchService.getElementInDependencies(type, id, dependencies); allDataTypes.putAll(DataTypesFetcher.getDataTypesDependencies(locationResourceTypes.getNodeTypes().values(), dataTypeFinder)); allDataTypes.putAll(DataTypesFetcher.getDataTypesDependencies(locationResourceTypes.getCapabilityTypes().values(), dataTypeFinder)); allDataTypes.putAll(DataTypesFetcher.getDataTypesDependencies(locationResourceTypes.getOnDemandTypes().values(), dataTypeFinder)); allDataTypes.putAll(DataTypesFetcher.getDataTypesDependencies(locationResourceTypes.getConfigurationTypes().values(), dataTypeFinder)); allDataTypes.putAll(DataTypesFetcher.getDataTypesDependencies(locationResourceTypes.getPolicyTypes().values(), dataTypeFinder)); locationResourceTypes.setDataTypes(allDataTypes); }
private Map<String, DataType> getDataTypes(AbstractTopologyDTO topologyDTO) { Map<String, DataType> indexedDataTypes = Maps.newHashMap(); DataTypesFetcher.DataTypeFinder dataTypeFinder = (type, id) -> ToscaContext.get(type, id); if (MapUtils.isNotEmpty(topologyDTO.getNodeTypes())) { indexedDataTypes.putAll(DataTypesFetcher.getDataTypesDependencies(topologyDTO.getNodeTypes().values(), dataTypeFinder)); } if (MapUtils.isNotEmpty(topologyDTO.getRelationshipTypes())) { indexedDataTypes.putAll(DataTypesFetcher.getDataTypesDependencies(topologyDTO.getRelationshipTypes().values(), dataTypeFinder)); } if (MapUtils.isNotEmpty(topologyDTO.getCapabilityTypes())) { indexedDataTypes.putAll(DataTypesFetcher.getDataTypesDependencies(topologyDTO.getCapabilityTypes().values(), dataTypeFinder)); } return indexedDataTypes; } }
private TypeWithDependenciesResult buildNodeTypeWithDependencies(NodeType nodeType) { TypeWithDependenciesResult result = new TypeWithDependenciesResult(); result.setToscaType(nodeType); for (CapabilityDefinition capabilityDefinition : nodeType.getCapabilities()) { result.add(ToscaContext.getOrFail(CapabilityType.class, capabilityDefinition.getType())); } for (RequirementDefinition requirementDefinition : nodeType.getRequirements()) { CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, requirementDefinition.getType()); if (capabilityType != null) { result.add(capabilityType); } else { // requirements are authorized to be a node type rather than a capability type TODO is it still possible in TOSCA ? result.add(ToscaContext.get(NodeType.class, requirementDefinition.getType())); } } result.setDependencies(ToscaContext.get().getDependencies()); // Fetch data types for the given type DataTypesFetcher.getDataTypesDependencies(Collections.singleton(nodeType), ToscaContext::get).values().forEach(result::add); return result; } }