diff options
Diffstat (limited to 'common-be')
3 files changed, 42 insertions, 4 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 ec3459989e..2e57a4158a 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 @@ -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(); 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 4fe3f3ae13..0ef417f8e2 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 @@ -30,6 +30,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import lombok.Data; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.datatypes.enums.PropertySource; import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; @@ -43,6 +44,7 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct private String sourceName; private ToscaGetFunctionType functionType; private List<String> propertyPathFromSource = new ArrayList<>(); + private Object toscaIndex; public ToscaGetFunctionDataDefinition() { //necessary for JSON conversions @@ -87,6 +89,12 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct ); } if (propertySource == PropertySource.SELF) { + if (toscaIndex != null) { + Object toscaIndexValue = StringUtils.isNumeric(toscaIndex.toString()) ? Integer.parseInt(toscaIndex.toString()) : toscaIndex; + return Map.of(functionType.getFunctionName(), + Stream.concat(Stream.of(PropertySource.SELF.getName()), Stream.concat(propertyPathFromSource.stream(),Stream.of(toscaIndexValue))).collect(Collectors.toList()) + ); + } return Map.of(functionType.getFunctionName(), Stream.concat(Stream.of(PropertySource.SELF.getName()), propertyPathFromSource.stream()).collect(Collectors.toList()) ); @@ -97,6 +105,12 @@ 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; + return Map.of(functionType.getFunctionName(), + Stream.concat(Stream.of(sourceName), Stream.concat(propertyPathFromSource.stream(),Stream.of(toscaIndexValue))).collect(Collectors.toList()) + ); + } return Map.of(functionType.getFunctionName(), Stream.concat(Stream.of(sourceName), propertyPathFromSource.stream()).collect(Collectors.toList()) ); @@ -106,10 +120,17 @@ public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunct } private Map<String, Object> buildGetInputFunctionValue() { + List<Object> propertySourceCopy = new ArrayList<Object>(this.propertyPathFromSource); + List<Object> propertySourceOneCopy = new ArrayList<>(); + propertySourceOneCopy.add(this.propertyPathFromSource.get(0)); + if (toscaIndex != null) { + propertySourceCopy.add(toscaIndex); + propertySourceOneCopy.add(toscaIndex); + } if (this.propertyPathFromSource.size() == 1) { - return Map.of(this.functionType.getFunctionName(), this.propertyPathFromSource.get(0)); + return Map.of(this.functionType.getFunctionName(), propertySourceOneCopy); } - return Map.of(this.functionType.getFunctionName(), this.propertyPathFromSource); + return Map.of(this.functionType.getFunctionName(), propertySourceCopy); } @Override diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java index 5daeaa5aad..581f62a91f 100644 --- a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java +++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java @@ -61,8 +61,8 @@ class ToscaGetFunctionDataDefinitionTest { final Map<?, ?> getInputJsonAsMap = convertJsonStringToMap(actualValue); assertTrue(getInputJsonAsMap.containsKey(ToscaGetFunctionType.GET_INPUT.getFunctionName())); final Object value = getInputJsonAsMap.get(ToscaGetFunctionType.GET_INPUT.getFunctionName()); - assertTrue(value instanceof String); - assertEquals(value, propertyName); + assertTrue(value instanceof List); + assertEquals(((List<String>)value).get(0), propertyName); } @Test |