summaryrefslogtreecommitdiffstats
path: root/common-be/src/main/java/org/openecomp
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-07-07 17:17:52 +0100
committerMichael Morris <michael.morris@est.tech>2022-07-18 14:22:12 +0000
commit68733163804ed2efed8223a04ab0a7a0714a8b33 (patch)
tree013f4d25042aa776120971a612a52d64db52f7a7 /common-be/src/main/java/org/openecomp
parent4e4ec8e9c21acf7f9210aaebf8f13a60542737fc (diff)
Support for concat TOSCA function
Adds support for the concat TOSCA function in an instance property. Refactors the TOSCA function structure so it can be more generic to support other functions in the future. Change-Id: I338e4138d26afe21779da57c4eeb3f2d486c20a9 Issue-ID: SDC-4095 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'common-be/src/main/java/org/openecomp')
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java46
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java40
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaConcatFunction.java56
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunction.java32
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java151
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionParameter.java30
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionType.java45
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java34
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaStringParameter.java44
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/PropertySource.java6
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaGetFunctionType.java21
11 files changed, 492 insertions, 13 deletions
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java
new file mode 100644
index 0000000000..84543e29f7
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java
@@ -0,0 +1,46 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.elements;
+
+import lombok.Setter;
+import org.yaml.snakeyaml.Yaml;
+
+@Setter
+public class CustomYamlFunction implements ToscaFunction, ToscaFunctionParameter {
+
+ private Object yamlValue;
+
+ @Override
+ public ToscaFunctionType getType() {
+ return ToscaFunctionType.YAML;
+ }
+
+ @Override
+ public String getValue() {
+ return new Yaml().dump(yamlValue);
+ }
+
+ @Override
+ public Object getJsonObjectValue() {
+ return yamlValue;
+ }
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java
index 845eee808a..f88514ac49 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.datatypes.elements;
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -56,11 +57,16 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
private Boolean immutable = Boolean.FALSE;
private Boolean mappedToComponentProperty = Boolean.TRUE;
/**
- * @deprecated use {@link #toscaGetFunction#functionType} instead
+ * @deprecated use {@link #toscaFunction} instead
*/
@Deprecated
private ToscaGetFunctionType toscaGetFunctionType;
+ /**
+ * @deprecated use {@link #toscaFunction} instead
+ */
+ @Deprecated
private ToscaGetFunctionDataDefinition toscaGetFunction;
+ private ToscaFunction toscaFunction;
private String inputPath;
private String status;
@@ -115,8 +121,9 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
this.setModel(propertyDataDefinition.getModel());
this.setPropertyId(propertyDataDefinition.getPropertyId());
- this.setToscaGetFunctionType(propertyDataDefinition.getToscaGetFunctionType());
this.setToscaGetFunction(propertyDataDefinition.getToscaGetFunction());
+ this.setToscaGetFunctionType(propertyDataDefinition.getToscaGetFunctionType());
+ this.setToscaFunction(propertyDataDefinition.getToscaFunction());
this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
if (isNotEmpty(propertyDataDefinition.annotations)) {
@@ -166,10 +173,14 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
}
public ToscaGetFunctionType getToscaGetFunctionType() {
- if (toscaGetFunction != null) {
- return toscaGetFunction.getFunctionType();
+ if (isToscaGetFunction()) {
+ if (toscaFunction != null) {
+ return ((ToscaGetFunctionDataDefinition) toscaFunction).getFunctionType();
+ }
+ return toscaGetFunctionType;
}
- return toscaGetFunctionType;
+
+ return null;
}
public Boolean isHidden() {
@@ -318,12 +329,23 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);
}
- public boolean isGetFunction() {
- return this.toscaGetFunctionType != null || this.toscaGetFunction != null;
+ @JsonIgnoreProperties
+ public boolean isToscaFunction() {
+ return this.toscaGetFunctionType != null || this.toscaFunction != null;
+ }
+
+
+ @JsonIgnoreProperties
+ public boolean isToscaGetFunction() {
+ return this.toscaGetFunctionType != null || (this.toscaFunction != null
+ && (this.toscaFunction.getType() == ToscaFunctionType.GET_ATTRIBUTE
+ || this.toscaFunction.getType() == ToscaFunctionType.GET_INPUT
+ || this.toscaFunction.getType() == ToscaFunctionType.GET_PROPERTY));
}
- public boolean hasGetFunction() {
- return this.toscaGetFunction != null;
+ @JsonIgnoreProperties
+ public boolean hasToscaFunction() {
+ return this.toscaFunction != null;
}
}
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
new file mode 100644
index 0000000000..62307fb4be
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaConcatFunction.java
@@ -0,0 +1,56 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.elements;
+
+import com.google.gson.Gson;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class ToscaConcatFunction implements ToscaFunction, ToscaFunctionParameter {
+
+ private List<ToscaFunctionParameter> parameters = new ArrayList<>();
+
+ @Override
+ public ToscaFunctionType getType() {
+ return ToscaFunctionType.CONCAT;
+ }
+
+ @Override
+ public String getValue() {
+ return new Gson().toJson(getJsonObjectValue());
+ }
+
+ @Override
+ public Object getJsonObjectValue() {
+ return Map.of(
+ ToscaFunctionType.CONCAT.getName(),
+ parameters.stream().map(ToscaFunctionParameter::getJsonObjectValue).collect(Collectors.toList())
+ );
+ }
+
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunction.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunction.java
new file mode 100644
index 0000000000..40664a133c
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunction.java
@@ -0,0 +1,32 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.elements;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+
+@JsonDeserialize(using = ToscaFunctionJsonDeserializer.class)
+public interface ToscaFunction {
+
+ ToscaFunctionType getType();
+ String getValue();
+
+}
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
new file mode 100644
index 0000000000..74aed12471
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java
@@ -0,0 +1,151 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.elements;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.datatypes.enums.PropertySource;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
+import org.yaml.snakeyaml.Yaml;
+
+public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction> {
+
+ public ToscaFunctionJsonDeserializer() {
+ this(null);
+ }
+
+ public ToscaFunctionJsonDeserializer(Class<?> vc) {
+ super(vc);
+ }
+
+ @Override
+ public ToscaFunction deserialize(final JsonParser jsonParser, final DeserializationContext context) throws IOException {
+ final JsonNode node = jsonParser.getCodec().readTree(jsonParser);
+ return deserializeToscaFunction(node, context);
+ }
+
+ private ToscaFunction deserializeToscaFunction(final JsonNode node, final DeserializationContext context) throws IOException {
+ final String functionType;
+ if (node.get("type") != null) {
+ functionType = node.get("type").asText();
+ } else if (node.get("functionType") != null) {
+ //support for legacy tosca function
+ functionType = node.get("functionType").asText();
+ } else {
+ throw context.instantiationException(ToscaFunction.class, "Attribute type not provided");
+ }
+ final ToscaFunctionType toscaFunctionType = ToscaFunctionType.findType(functionType)
+ .orElseThrow(() -> context.instantiationException(ToscaFunction.class,
+ String.format("Invalid function type '%s' or attribute type not provided", functionType))
+ );
+ if (toscaFunctionType == ToscaFunctionType.GET_INPUT || toscaFunctionType == ToscaFunctionType.GET_ATTRIBUTE
+ || toscaFunctionType == ToscaFunctionType.GET_PROPERTY) {
+ return deserializeToscaGetFunction(toscaFunctionType, node, context);
+ }
+
+ if (toscaFunctionType == ToscaFunctionType.CONCAT) {
+ return this.deserializeConcatFunction(node, context);
+ }
+
+ if (toscaFunctionType == ToscaFunctionType.YAML) {
+ return this.deserializeYamlFunction(node);
+ }
+
+ return null;
+ }
+
+ private ToscaFunction deserializeYamlFunction(JsonNode node) {
+ var yamlFunction = new CustomYamlFunction();
+ final Object value = new Yaml().load(node.get("value").asText());
+ yamlFunction.setYamlValue(value);
+ return yamlFunction;
+ }
+
+ private ToscaGetFunctionDataDefinition deserializeToscaGetFunction(final ToscaFunctionType toscaFunctionType, final JsonNode node,
+ 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();
+ if (StringUtils.isNotEmpty(propertySource)) {
+ final PropertySource propertySource1 = PropertySource.findType(propertySource).orElseThrow(() ->
+ context.instantiationException(ToscaGetFunctionDataDefinition.class,
+ String.format("Invalid propertySource '%s'", propertySource))
+ );
+ 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()) {
+ throw context.instantiationException(ToscaGetFunctionDataDefinition.class, "Expecting an array for propertyPathFromSource attribute");
+ }
+ final List<String> pathFromSource = new ArrayList<>();
+ propertyPathFromSourceNode.forEach(jsonNode -> pathFromSource.add(jsonNode.asText()));
+ toscaGetFunction.setPropertyPathFromSource(pathFromSource);
+ }
+
+ return toscaGetFunction;
+ }
+
+ private ToscaConcatFunction deserializeConcatFunction(final JsonNode concatFunctionJsonNode,
+ final DeserializationContext context) throws IOException {
+ final var toscaConcatFunction = new ToscaConcatFunction();
+ final List<ToscaFunctionParameter> functionParameterList = new ArrayList<>();
+ final JsonNode parametersNode = concatFunctionJsonNode.get("parameters");
+ if (!parametersNode.isArray()) {
+ throw context.instantiationException(List.class, "");
+ }
+ for (final JsonNode parameterNode : parametersNode) {
+ final JsonNode typeJsonNode = parameterNode.get("type");
+ if (typeJsonNode == null) {
+ throw context.instantiationException(ToscaConcatFunction.class, "TOSCA concat function parameter type attribute not provided");
+ }
+ final String parameterType = typeJsonNode.asText();
+ final ToscaFunctionType toscaFunctionType = ToscaFunctionType.findType(parameterType)
+ .orElseThrow(() -> context.instantiationException(ToscaConcatFunction.class,
+ String.format("Invalid TOSCA concat function parameter type '%s'", parameterType))
+ );
+ if (toscaFunctionType == ToscaFunctionType.STRING) {
+ final ToscaStringParameter toscaStringParameter = new ToscaStringParameter();
+ toscaStringParameter.setValue(parameterNode.get("value").asText());
+ functionParameterList.add(toscaStringParameter);
+ } else {
+ final ToscaFunction toscaFunction = this.deserializeToscaFunction(parameterNode, context);
+ functionParameterList.add((ToscaFunctionParameter) toscaFunction);
+ }
+ }
+ toscaConcatFunction.setParameters(functionParameterList);
+ return toscaConcatFunction;
+ }
+
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionParameter.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionParameter.java
new file mode 100644
index 0000000000..4d4c7b0a68
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionParameter.java
@@ -0,0 +1,30 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.elements;
+
+public interface ToscaFunctionParameter {
+
+ String getValue();
+ ToscaFunctionType getType();
+ Object getJsonObjectValue();
+
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionType.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionType.java
new file mode 100644
index 0000000000..4579ac2410
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionType.java
@@ -0,0 +1,45 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.elements;
+
+import java.util.Arrays;
+import java.util.Optional;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@AllArgsConstructor
+@Getter
+public enum ToscaFunctionType {
+
+ GET_INPUT("get_input"),
+ GET_PROPERTY("get_property"),
+ GET_ATTRIBUTE("get_attribute"),
+ CONCAT("concat"),
+ YAML("yaml"),
+ STRING("string");
+
+ private final String name;
+
+ public static Optional<ToscaFunctionType> findType(final String functionType) {
+ return Arrays.stream(values()).filter(toscaFunctionType -> toscaFunctionType.getName().equalsIgnoreCase(functionType)).findFirst();
+ }
+}
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 0741d6849e..f19217e69c 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
@@ -33,7 +33,7 @@ import org.openecomp.sdc.be.datatypes.enums.PropertySource;
import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
@Data
-public class ToscaGetFunctionDataDefinition {
+public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunctionParameter {
private String propertyUniqueId;
private String propertyName;
@@ -55,6 +55,11 @@ public class ToscaGetFunctionDataDefinition {
* Builds the value of a property based on the TOSCA get function information.
*/
public String generatePropertyValue() {
+ return new Gson().toJson(getJsonObjectValue());
+ }
+
+ @Override
+ public Object getJsonObjectValue() {
if (functionType == null) {
throw new IllegalStateException("functionType is required in order to generate the get function value");
}
@@ -62,12 +67,11 @@ public class ToscaGetFunctionDataDefinition {
throw new IllegalStateException("propertyPathFromSource is required in order to generate the get function value");
}
- final var gson = new Gson();
if (functionType == ToscaGetFunctionType.GET_PROPERTY || functionType == ToscaGetFunctionType.GET_ATTRIBUTE) {
- return gson.toJson(buildFunctionValueWithPropertySource());
+ return buildFunctionValueWithPropertySource();
}
if (functionType == ToscaGetFunctionType.GET_INPUT) {
- return gson.toJson(buildGetInputFunctionValue());
+ return buildGetInputFunctionValue();
}
throw new UnsupportedOperationException(String.format("ToscaGetFunctionType '%s' is not supported yet", functionType));
@@ -105,4 +109,26 @@ public class ToscaGetFunctionDataDefinition {
return Map.of(this.functionType.getFunctionName(), this.propertyPathFromSource);
}
+ @Override
+ public ToscaFunctionType getType() {
+ if (functionType == null) {
+ return null;
+ }
+ switch (functionType) {
+ case GET_INPUT:
+ return ToscaFunctionType.GET_INPUT;
+ case GET_PROPERTY:
+ return ToscaFunctionType.GET_PROPERTY;
+ case GET_ATTRIBUTE:
+ return ToscaFunctionType.GET_ATTRIBUTE;
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public String getValue() {
+ return this.generatePropertyValue();
+ }
+
}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaStringParameter.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaStringParameter.java
new file mode 100644
index 0000000000..d6d5d9f8ad
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaStringParameter.java
@@ -0,0 +1,44 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.elements;
+
+import lombok.Setter;
+
+@Setter
+public class ToscaStringParameter implements ToscaFunctionParameter {
+ private String value;
+
+ @Override
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public ToscaFunctionType getType() {
+ return ToscaFunctionType.STRING;
+ }
+
+ @Override
+ public Object getJsonObjectValue() {
+ return getValue();
+ }
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/PropertySource.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/PropertySource.java
index 8086d22815..d2e15039d3 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/PropertySource.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/PropertySource.java
@@ -21,6 +21,8 @@
package org.openecomp.sdc.be.datatypes.enums;
+import java.util.Arrays;
+import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -31,4 +33,8 @@ public enum PropertySource {
private final String name;
+ public static Optional<PropertySource> findType(final String propertySource) {
+ return Arrays.stream(values()).filter(propertySource1 -> propertySource1.getName().equalsIgnoreCase(propertySource)).findFirst();
+ }
+
}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaGetFunctionType.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaGetFunctionType.java
index bb85ceb0fc..d84c86a38d 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaGetFunctionType.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaGetFunctionType.java
@@ -19,8 +19,10 @@
package org.openecomp.sdc.be.datatypes.tosca;
+import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Getter;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
@AllArgsConstructor
@Getter
@@ -31,4 +33,23 @@ public enum ToscaGetFunctionType {
private final String functionName;
private final String propertyType;
+
+ /**
+ * Converts a {@link ToscaFunctionType} to a {@link ToscaGetFunctionType}
+ * @param toscaFunctionType the tosca function type to convert
+ * @return the respective {@link ToscaGetFunctionType}
+ */
+ public static Optional<ToscaGetFunctionType> fromToscaFunctionType(final ToscaFunctionType toscaFunctionType) {
+ switch (toscaFunctionType) {
+ case GET_INPUT:
+ return Optional.of(GET_INPUT);
+ case GET_PROPERTY:
+ return Optional.of(GET_PROPERTY);
+ case GET_ATTRIBUTE:
+ return Optional.of(GET_ATTRIBUTE);
+ default:
+ return Optional.empty();
+ }
+ }
+
}