summaryrefslogtreecommitdiffstats
path: root/common-be/src/main
diff options
context:
space:
mode:
authorimamSidero <imam.hussain@est.tech>2023-04-12 16:02:46 +0100
committerMichael Morris <michael.morris@est.tech>2023-05-09 14:33:29 +0000
commita1ba3abf29613ee9e576a7c96a76ceb921086044 (patch)
treef3f9e4d9c98c6b5bc2d8aba1be01b327dd36b31d /common-be/src/main
parent3bc3a5c724e9a6ea8a112dca72a9a3128eddca19 (diff)
Support for addition of INDEX token to tosca functions
Providing the capability to add the index token to th tosca function of all types Issue-ID: SDC-4472 Signed-off-by: Imam hussain <imam.hussain@est.tech> Change-Id: Ib7ac80f31710101f50de76bdb7c79abdc637cfe3
Diffstat (limited to 'common-be/src/main')
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java17
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java25
2 files changed, 40 insertions, 2 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