Support for addition of INDEX token to tosca functions
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / ToscaFunctionJsonDeserializer.java
index ec34599..2e57a41 100644 (file)
@@ -113,6 +113,7 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction
         toscaGetFunction.setSourceUniqueId(getAsTextOrElseNull(node, "sourceUniqueId"));
         toscaGetFunction.setPropertyName(getAsTextOrElseNull(node, "propertyName"));
         toscaGetFunction.setPropertyUniqueId(getAsTextOrElseNull(node, "propertyUniqueId"));
+        toscaGetFunction.setToscaIndex(getNumberAsTextOrElseNull(node, "toscaIndex"));
         final String propertySource = getAsTextOrElseNull(node, "propertySource");
         if (StringUtils.isNotEmpty(propertySource)) {
             final PropertySource propertySource1 = PropertySource.findType(propertySource).orElseThrow(() ->
@@ -145,6 +146,22 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction
         return jsonNode.asText();
     }
 
+    private Object getNumberAsTextOrElseNull(final JsonNode node, final String fieldName) {
+        final JsonNode jsonNode = node.get(fieldName);
+        if (jsonNode == null) {
+            return null;
+        }
+        if (jsonNode.asText().equalsIgnoreCase("INDEX")) {
+            return jsonNode.asText();
+        }
+        try {
+            Integer.parseInt(jsonNode.asText());
+        } catch(Exception e) {
+            return null;
+        }
+        return Integer.parseInt(jsonNode.asText());
+    }
+
     private ToscaConcatFunction deserializeConcatFunction(final JsonNode concatFunctionJsonNode,
                                                           final DeserializationContext context) throws IOException {
         final var toscaConcatFunction = new ToscaConcatFunction();