package org.openecomp.sdc.be.tosca.utils;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
-import org.openecomp.sdc.be.model.tosca.ToscaFunctions;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.tosca.PropertyConvertor;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.be.components.utils.PropertiesUtils.resolvePropertyValueFromInput;
+
public class ToscaExportUtils {
private ToscaExportUtils() {
if (Objects.isNull(proxyComponent) || MapUtils.isEmpty(proxyComponent.getInterfaces())) {
return Optional.empty();
}
+ Map<String, InterfaceDefinition> proxyComponentInterfaces = proxyComponent.getInterfaces();
+ //Unset artifact path for operation implementation for proxy node types as for operations with artifacts it is
+ // always available in the proxy node template
+ removeOperationImplementationForProxyNodeType(proxyComponentInterfaces);
return Optional.ofNullable(InterfacesOperationsToscaUtil
- .getInterfacesMap(proxyComponent, null, proxyComponent.getInterfaces(), dataTypes, false, false));
+ .getInterfacesMap(proxyComponent, null, proxyComponentInterfaces, dataTypes, false, false));
}
public static Optional<Map<String, ToscaProperty>> getProxyNodeTypeProperties(Component proxyComponent,
addInputsToProperties(dataTypes, proxyComponent.getInputs(), proxyProperties);
if (CollectionUtils.isNotEmpty(proxyComponent.getProperties())) {
proxyProperties.putAll(proxyComponent.getProperties().stream()
+ .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition,
+ proxyComponent.getInputs()))
.collect(Collectors.toMap(PropertyDataDefinition::getName,
property -> PropertyConvertor.getInstance().convertProperty(dataTypes, property,
PropertyConvertor.PropertyType.PROPERTY))));
}
- resolvePropertyDefaultValueFromInput(proxyComponent.getInputs(), proxyProperties, dataTypes);
-
return MapUtils.isNotEmpty(proxyProperties) ? Optional.of(proxyProperties) : Optional.empty();
}
-
- public static void resolvePropertyDefaultValueFromInput(List<InputDefinition> componentInputs,
- Map<String, ToscaProperty> mergedProperties,
- Map<String, DataTypeDefinition> dataTypes) {
- if (MapUtils.isEmpty(mergedProperties) || CollectionUtils.isEmpty(componentInputs)) {
- return;
- }
- for (Map.Entry<String, ToscaProperty> mergedPropertyEntry : mergedProperties.entrySet()) {
- ToscaProperty value = mergedPropertyEntry.getValue();
- if (Objects.nonNull(value) && value.getDefaultp() instanceof Map) {
- Map<String, String> valueAsMap = (Map<String, String>) value.getDefaultp();
- String inputName = valueAsMap.get(ToscaFunctions.GET_INPUT.getFunctionName());
- Optional<InputDefinition> matchedInputDefinition = componentInputs.stream()
- .filter(componentInput -> componentInput.getName().equals(inputName))
- .findFirst();
- if (matchedInputDefinition.isPresent()) {
- InputDefinition matchedInput = matchedInputDefinition.get();
- Object resolvedDefaultValue = new PropertyConvertor().convertToToscaObject(matchedInput.getType(),
- matchedInput.getDefaultValue(), matchedInput.getSchemaType(), dataTypes, false);
- value.setDefaultp(resolvedDefaultValue);
- mergedProperties.put(mergedPropertyEntry.getKey(), value);
- }
- }
- }
- }
-
public static void addInputsToProperties(Map<String, DataTypeDefinition> dataTypes,
List<InputDefinition> componentInputs,
Map<String, ToscaProperty> mergedProperties) {
}
}
+ private static void removeOperationImplementationForProxyNodeType(Map<String, InterfaceDefinition>
+ proxyComponentInterfaces) {
+ if (MapUtils.isEmpty(proxyComponentInterfaces)) {
+ return;
+ }
+ proxyComponentInterfaces.values().stream()
+ .map(InterfaceDataDefinition::getOperations)
+ .filter(MapUtils::isNotEmpty)
+ .forEach(operations -> operations.values()
+ .forEach(operation -> operation.setImplementation(null)));
+ }
}