diff options
Diffstat (limited to 'common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java')
-rw-r--r-- | common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java index de8e30b897..f77c6f949b 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java @@ -116,7 +116,8 @@ 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")); + toscaGetFunction.setToscaIndexList(getNumberAsTextOrElseNull(node, "toscaIndexList", context)); + final String propertySource = getAsTextOrElseNull(node, "propertySource"); if (StringUtils.isNotEmpty(propertySource)) { final PropertySource propertySource1 = PropertySource.findType(propertySource).orElseThrow(() -> @@ -149,20 +150,31 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction return jsonNode.asText(); } - private Object getNumberAsTextOrElseNull(final JsonNode node, final String fieldName) { + private List<Object> getNumberAsTextOrElseNull(final JsonNode node, final String fieldName, final DeserializationContext context) throws JsonMappingException{ + List<Object> toscaIndexList = new ArrayList<Object>(); 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; + if (jsonNode != null) { + if (!jsonNode.isArray()) { + throw context.instantiationException(ToscaGetFunctionDataDefinition.class, "Expecting an array for toscaIndexList attribute"); + } + for (int index=0;index<jsonNode.size();index++) { + String textValue = jsonNode.get(index).asText(); + if (index%2 == 0) { + if (textValue.equalsIgnoreCase("INDEX")) { + toscaIndexList.add(textValue); + } else { + try { + toscaIndexList.add(Integer.parseInt(textValue)); + } catch(Exception e) { + throw context.instantiationException(ToscaGetFunctionDataDefinition.class, "Expecting a valid value for toscaIndex attribute"); + } + } + } else { + toscaIndexList.add(textValue); + } + } } - return Integer.parseInt(jsonNode.asText()); + return toscaIndexList; } private ToscaConcatFunction deserializeConcatFunction(final JsonNode concatFunctionJsonNode, |