diff options
author | andre.schmid <andre.schmid@est.tech> | 2022-07-29 20:39:23 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-08-06 22:43:00 +0000 |
commit | 7b0009c2bebe54214f920baf6b2aa4058921777b (patch) | |
tree | 1e5a24cea14540b1e6b8777719487aa47497fa42 /common-be/src | |
parent | c2f19bdcf5b5d5647770a5d3435d942fb3dd0efa (diff) |
Support for TOSCA functions for Service Import
Reads, interprets and persists property values that uses TOSCA functions
during a Service import.
Change-Id: I6943c447cc743213cb9807d6433cb25fa5effbc3
Issue-ID: SDC-4120
Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'common-be/src')
2 files changed, 20 insertions, 6 deletions
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaConcatFunction.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaConcatFunction.java index 62307fb4be..975721be26 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaConcatFunction.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaConcatFunction.java @@ -53,4 +53,8 @@ public class ToscaConcatFunction implements ToscaFunction, ToscaFunctionParamete ); } + public void addParameter(final ToscaFunctionParameter functionParameter) { + this.parameters.add(functionParameter); + } + } 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 fda832b98e..363af1cdeb 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 @@ -105,9 +105,11 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction final DeserializationContext context) throws JsonMappingException { final ToscaGetFunctionDataDefinition toscaGetFunction = new ToscaGetFunctionDataDefinition(); toscaGetFunction.setFunctionType(ToscaGetFunctionType.fromToscaFunctionType(toscaFunctionType).orElse(null)); - toscaGetFunction.setSourceName(node.get("sourceName").asText()); - toscaGetFunction.setPropertyUniqueId(node.get("propertyUniqueId").asText()); - final String propertySource = node.get("propertySource").asText(); + toscaGetFunction.setSourceName(getAsTextOrElseNull(node, "sourceName")); + toscaGetFunction.setSourceUniqueId(getAsTextOrElseNull(node, "sourceUniqueId")); + toscaGetFunction.setPropertyName(getAsTextOrElseNull(node, "propertyName")); + toscaGetFunction.setPropertyUniqueId(getAsTextOrElseNull(node, "propertyUniqueId")); + final String propertySource = getAsTextOrElseNull(node, "propertySource"); if (StringUtils.isNotEmpty(propertySource)) { final PropertySource propertySource1 = PropertySource.findType(propertySource).orElseThrow(() -> context.instantiationException(ToscaGetFunctionDataDefinition.class, @@ -115,9 +117,6 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction ); toscaGetFunction.setPropertySource(propertySource1); } - toscaGetFunction.setPropertyName(node.get("propertyName").asText()); - toscaGetFunction.setSourceName(node.get("sourceName").asText()); - toscaGetFunction.setSourceUniqueId(node.get("sourceUniqueId").asText()); final JsonNode propertyPathFromSourceNode = node.get("propertyPathFromSource"); if (propertyPathFromSourceNode != null) { if (!propertyPathFromSourceNode.isArray()) { @@ -131,6 +130,17 @@ public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction return toscaGetFunction; } + private String getAsTextOrElseNull(final JsonNode node, final String fieldName) { + final JsonNode jsonNode = node.get(fieldName); + if (jsonNode == null) { + return null; + } + if (!jsonNode.isTextual()) { + return null; + } + return jsonNode.asText(); + } + private ToscaConcatFunction deserializeConcatFunction(final JsonNode concatFunctionJsonNode, final DeserializationContext context) throws IOException { final var toscaConcatFunction = new ToscaConcatFunction(); |