X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-be%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Ftosca%2Futils%2FToscaExportUtils.java;h=beb9dab7e8e4c73b168856878ce7b2e696e5fc4f;hb=f70e2b5f66493822b512767d504ae26275cb16a2;hp=20e069827652287fbadef23f4c45e5afa9c43ae0;hpb=f3a1aa08a8339ce312013154550c8e8b637f0fc3;p=sdc.git diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java index 20e0698276..beb9dab7e8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java @@ -16,23 +16,26 @@ 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() { @@ -44,8 +47,12 @@ public class ToscaExportUtils { if (Objects.isNull(proxyComponent) || MapUtils.isEmpty(proxyComponent.getInterfaces())) { return Optional.empty(); } + Map 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> getProxyNodeTypeProperties(Component proxyComponent, @@ -58,41 +65,15 @@ public class ToscaExportUtils { 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 componentInputs, - Map mergedProperties, - Map dataTypes) { - if (MapUtils.isEmpty(mergedProperties) || CollectionUtils.isEmpty(componentInputs)) { - return; - } - for (Map.Entry mergedPropertyEntry : mergedProperties.entrySet()) { - ToscaProperty value = mergedPropertyEntry.getValue(); - if (Objects.nonNull(value) && value.getDefaultp() instanceof Map) { - Map valueAsMap = (Map) value.getDefaultp(); - String inputName = valueAsMap.get(ToscaFunctions.GET_INPUT.getFunctionName()); - Optional 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 dataTypes, List componentInputs, Map mergedProperties) { @@ -106,4 +87,15 @@ public class ToscaExportUtils { } } + private static void removeOperationImplementationForProxyNodeType(Map + proxyComponentInterfaces) { + if (MapUtils.isEmpty(proxyComponentInterfaces)) { + return; + } + proxyComponentInterfaces.values().stream() + .map(InterfaceDataDefinition::getOperations) + .filter(MapUtils::isNotEmpty) + .forEach(operations -> operations.values() + .forEach(operation -> operation.setImplementation(null))); + } }