diff options
Diffstat (limited to 'common-be/src/main')
2 files changed, 41 insertions, 24 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, diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java index 9396188fcc..5bd9fe33db 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java @@ -44,7 +44,7 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct private String sourceName; private ToscaGetFunctionType functionType; private List<String> propertyPathFromSource = new ArrayList<>(); - private Object toscaIndex; + private List<Object> toscaIndexList; public ToscaGetFunctionDataDefinition() { //necessary for JSON conversions @@ -89,10 +89,13 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct ); } if (propertySource == PropertySource.SELF) { - if (toscaIndex != null) { - Object toscaIndexValue = StringUtils.isNumeric(toscaIndex.toString()) ? Integer.parseInt(toscaIndex.toString()) : toscaIndex; + if (toscaIndexList.size() > 0) { + List<Object> parsedIndexList = new ArrayList<Object>(); + toscaIndexList.forEach((obj) -> { + parsedIndexList.add(StringUtils.isNumeric(obj.toString()) ? Integer.parseInt(obj.toString()) : obj); + }); return Map.of(functionType.getFunctionName(), - Stream.concat(Stream.of(PropertySource.SELF.getName()), Stream.concat(propertyPathFromSource.stream(),Stream.of(toscaIndexValue))).collect(Collectors.toList()) + Stream.concat(Stream.of(PropertySource.SELF.getName()), Stream.concat(propertyPathFromSource.stream(),parsedIndexList.stream())).collect(Collectors.toList()) ); } return Map.of(functionType.getFunctionName(), @@ -105,10 +108,13 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct String.format("sourceName is required in order to generate the %s from INSTANCE value", functionType.getFunctionName()) ); } - if (toscaIndex != null) { - Object toscaIndexValue = StringUtils.isNumeric(toscaIndex.toString()) ? Integer.parseInt(toscaIndex.toString()) : toscaIndex; + if (toscaIndexList.size() > 0) { + List<Object> parsedIndexList = new ArrayList<Object>(); + toscaIndexList.forEach((obj) -> { + parsedIndexList.add(StringUtils.isNumeric(obj.toString()) ? Integer.parseInt(obj.toString()) : obj); + }); return Map.of(functionType.getFunctionName(), - Stream.concat(Stream.of(sourceName), Stream.concat(propertyPathFromSource.stream(),Stream.of(toscaIndexValue))).collect(Collectors.toList()) + Stream.concat(Stream.of(sourceName), Stream.concat(propertyPathFromSource.stream(),parsedIndexList.stream())).collect(Collectors.toList()) ); } return Map.of(functionType.getFunctionName(), @@ -123,10 +129,9 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct List<Object> propertySourceCopy = new ArrayList<Object>(this.propertyPathFromSource); List<Object> propertySourceOneCopy = new ArrayList<>(); propertySourceOneCopy.add(this.propertyPathFromSource.get(0)); - if (toscaIndex != null) { - Object toscaIndexValue = StringUtils.isNumeric(toscaIndex.toString()) ? Integer.parseInt(toscaIndex.toString()) : toscaIndex; - propertySourceCopy.add(toscaIndexValue); - propertySourceOneCopy.add(toscaIndexValue); + if (toscaIndexList.size() > 0) { + propertySourceCopy.addAll(toscaIndexList); + propertySourceOneCopy.addAll(toscaIndexList); } if (this.propertyPathFromSource.size() == 1) { return Map.of(this.functionType.getFunctionName(), propertySourceOneCopy); |