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); }
/** * Get all data types that the given inheritable types depends on (in properties definitions) * * @param elements the types to search for data types * @param <T> the type of inheritable type (node type, data type, capability type ...) * @return a map of type id to data type */ public static <T extends AbstractInheritableToscaType> Map<String, DataType> getDataTypesDependencies(Collection<T> elements, DataTypeFinder dataTypeFinder) { Map<String, DataType> indexedDataTypes = new HashMap<>(); for (AbstractInheritableToscaType indexedNodeType : elements) { if (indexedNodeType != null) { if (indexedNodeType.getProperties() != null) { for (PropertyDefinition propertyDefinition : indexedNodeType.getProperties().values()) { getDataTypeDependency(indexedDataTypes, propertyDefinition.getType(), dataTypeFinder); } } if (indexedNodeType instanceof AbstractInstantiableToscaType && ((AbstractInstantiableToscaType) indexedNodeType).getAttributes() != null) { for (IValue attributeDefinition : ((AbstractInstantiableToscaType) indexedNodeType).getAttributes().values()) { if (attributeDefinition instanceof AttributeDefinition) { getDataTypeDependency(indexedDataTypes, ((AttributeDefinition) attributeDefinition).getType(), dataTypeFinder); } } } } } return indexedDataTypes; }
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; } }