From 468d0770593e167990df815e45cde717bd845d18 Mon Sep 17 00:00:00 2001 From: franciscovila Date: Tue, 21 Mar 2023 16:54:46 +0000 Subject: Support TOSCA functions in operation inputs Issue-ID: SDC-4442 Signed-off-by: franciscovila Change-Id: I1e6135da6f41d512a7758d5494df12da874d7146 --- .../jsonjanusgraph/operations/ToscaOperationFacade.java | 3 ++- .../model/tosca/converters/ToscaMapValueConverter.java | 17 +++++++++++------ .../model/tosca/converters/ToscaValueBaseConverter.java | 6 ++++-- 3 files changed, 17 insertions(+), 9 deletions(-) (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index af1749fb34..42781b21d8 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -1669,10 +1669,11 @@ public class ToscaOperationFacade { GraphVertex vertex = getVertexEither.left().value(); Map instInterfacesMap = new HashMap<>(); if (instInterfaces != null) { - MapInterfaceDataDefinition interfacesMap = new MapInterfaceDataDefinition(); + for (Map.Entry> entryInstances : instInterfaces.entrySet()) { Map incomingInterfacesMap = entryInstances.getValue().entrySet().stream() .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); + MapInterfaceDataDefinition interfacesMap = new MapInterfaceDataDefinition(); interfacesMap.setMapToscaDataDefinition(incomingInterfacesMap); instInterfacesMap.put(entryInstances.getKey(), interfacesMap); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java index 5edd08237d..0ea73711a7 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java @@ -131,12 +131,13 @@ public class ToscaMapValueConverter extends ToscaValueBaseConverter implements T } } } - final Object convertedValue = convertDataTypeToToscaObject(propType, dataTypes, innerConverterProp, scalar, e.getValue(), false); + final Object convertedValue = convertDataTypeToToscaObject(propType, dataTypes, innerConverterProp, scalar, e.getValue(), false, false); toscaMap.put(e.getKey(), convertedValue); } public Object convertDataTypeToToscaObject(String innerType, Map dataTypes, ToscaValueConverter innerConverter, - final boolean isScalarF, JsonElement entryValue, boolean preserveEmptyValue) { + final boolean isScalarF, JsonElement entryValue, boolean preserveEmptyValue, + final boolean isToscaFunction) { Object convertedValue; if (isScalarF && isJsonElementAJsonPrimitive(entryValue)) { return innerConverter.convertToToscaValue(entryValue.getAsString(), innerType, dataTypes); @@ -149,25 +150,29 @@ public class ToscaMapValueConverter extends ToscaValueBaseConverter implements T ArrayList toscaObjectPresentationArray = new ArrayList<>(); JsonArray jsonArray = entryValue.getAsJsonArray(); for (JsonElement jsonElement : jsonArray) { - Object convertedDataTypeToToscaMap = convertDataTypeToToscaMap(innerType, dataTypes, isScalarF, jsonElement, preserveEmptyValue); + Object convertedDataTypeToToscaMap = convertDataTypeToToscaMap(innerType, dataTypes, isScalarF, jsonElement, preserveEmptyValue, + isToscaFunction); toscaObjectPresentationArray.add(convertedDataTypeToToscaMap); } convertedValue = toscaObjectPresentationArray; } else { - convertedValue = convertDataTypeToToscaMap(innerType, dataTypes, isScalarF, entryValue, preserveEmptyValue); + convertedValue = convertDataTypeToToscaMap(innerType, dataTypes, isScalarF, entryValue, preserveEmptyValue, isToscaFunction); } } return convertedValue; } private Object convertDataTypeToToscaMap(String innerType, Map dataTypes, final boolean isScalarF, - JsonElement entryValue, boolean preserveEmptyValue) { + JsonElement entryValue, boolean preserveEmptyValue, final boolean isToscaFunction) { Object convertedValue; if (entryValue.isJsonPrimitive()) { return json2JavaPrimitive(entryValue.getAsJsonPrimitive()); } JsonObject asJsonObjectIn = entryValue.getAsJsonObject(); - DataTypePropertyConverter.getInstance().mergeDataTypeDefaultValuesWithPropertyValue(asJsonObjectIn, innerType, dataTypes); + if (!isToscaFunction) { + DataTypePropertyConverter.getInstance() + .mergeDataTypeDefaultValuesWithPropertyValue(asJsonObjectIn, innerType, dataTypes); + } Map toscaObjectPresentation = new HashMap<>(); Set> entrySetIn = asJsonObjectIn.entrySet(); for (Entry entry : entrySetIn) { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaValueBaseConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaValueBaseConverter.java index c9b5db8e87..e8d342aaec 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaValueBaseConverter.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaValueBaseConverter.java @@ -34,6 +34,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.apache.commons.lang3.math.NumberUtils; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; @@ -134,10 +135,11 @@ public class ToscaValueBaseConverter { if (jsonPrimitive.isBoolean()) { return jsonPrimitive.getAsBoolean(); } - if (jsonPrimitive.isString()) { + if (jsonPrimitive.isString() && !NumberUtils.isCreatable(jsonPrimitive.getAsString())) { return jsonPrimitive.getAsString(); } - if (jsonPrimitive.isNumber()) { + if (jsonPrimitive.isNumber() || + (jsonPrimitive.isString() && NumberUtils.isCreatable(jsonPrimitive.getAsString()))) { if (jsonPrimitive.getAsString().contains(".")) { return jsonPrimitive.getAsDouble(); } -- cgit 1.2.3-korg