aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
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 /catalog-be
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 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java22
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaFunctionExceptionSupplier.java36
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java3
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java15
6 files changed, 71 insertions, 24 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
index 4bf81727e6..dcccfd961d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
@@ -48,6 +48,7 @@ import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ToscaFunctionExceptionSupplier;
import org.openecomp.sdc.be.components.impl.exceptions.ToscaGetFunctionExceptionSupplier;
import org.openecomp.sdc.be.components.impl.instance.ComponentInstanceChangeOperationOrchestrator;
import org.openecomp.sdc.be.components.impl.utils.DirectivesUtil;
@@ -1960,9 +1961,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
validateMandatoryFields(property);
validatePropertyExistsOnComponent(property, containerComponent, foundResourceInstance);
String propertyParentUniqueId = property.getParentUniqueId();
- if (property.isGetFunction()) {
- validateToscaGetFunction(property, containerComponent);
- property.setValue(property.getToscaGetFunction().generatePropertyValue());
+ if (property.isToscaFunction()) {
+ if (property.getToscaFunction().getType() == null) {
+ throw ToscaFunctionExceptionSupplier.missingFunctionType().get();
+ }
+ if (property.isToscaGetFunction()) {
+ validateToscaGetFunction(property, containerComponent);
+ }
+ property.setValue(property.getToscaFunction().getValue());
}
Either<String, ResponseFormat> updatedPropertyValue = updatePropertyObjectValue(property, containerComponent.getModel());
if (updatedPropertyValue.isRight()) {
@@ -2297,7 +2303,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
// Specific Update Logic
String newValue = property.getValue();
- if (property.hasGetFunction()) {
+ if (property.hasToscaFunction()) {
return Either.left(newValue);
}
@@ -2369,7 +2375,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
private <T extends PropertyDefinition> void validateToscaGetFunction(T property, Component parentComponent) {
- final ToscaGetFunctionDataDefinition toscaGetFunction = property.getToscaGetFunction();
+ final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) property.getToscaFunction();
validateGetToscaFunctionAttributes(toscaGetFunction);
validateGetPropertySource(toscaGetFunction.getFunctionType(), toscaGetFunction.getPropertySource());
if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_INPUT) {
@@ -2407,7 +2413,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
private <T extends PropertyDefinition> void validateGetFunction(final T property,
final List<? extends ToscaPropertyData> parentProperties,
final String model) {
- final ToscaGetFunctionDataDefinition toscaGetFunction = property.getToscaGetFunction();
+ final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) property.getToscaFunction();
if (CollectionUtils.isEmpty(parentProperties)) {
throw ToscaGetFunctionExceptionSupplier
.propertyNotFoundOnTarget(toscaGetFunction.getPropertyName(), toscaGetFunction.getPropertySource(),
@@ -2428,11 +2434,11 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (!property.getType().equals(referredProperty.getType())) {
throw ToscaGetFunctionExceptionSupplier
- .propertyTypeDiverge(toscaGetFunction.getFunctionType(), referredProperty.getType(), property.getType()).get();
+ .propertyTypeDiverge(toscaGetFunction.getType(), referredProperty.getType(), property.getType()).get();
}
if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) {
throw ToscaGetFunctionExceptionSupplier
- .propertySchemaDiverge(toscaGetFunction.getFunctionType(), referredProperty.getSchemaType(), property.getSchemaType()).get();
+ .propertySchemaDiverge(toscaGetFunction.getType(), referredProperty.getSchemaType(), property.getSchemaType()).get();
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java
index 7c01a35a32..e810999504 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java
@@ -140,8 +140,8 @@ public class GroupBusinessLogicNew {
if (!isOnlyGroupPropertyValueChanged(gp, originalProperties.get(updatedPropertyName))) {
throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY, updatedPropertyName);
}
- if (gp.hasGetFunction()) {
- gp.setValue(gp.getToscaGetFunction().generatePropertyValue());
+ if (gp.hasToscaFunction()) {
+ gp.setValue(gp.getToscaFunction().getValue());
}
if (StringUtils.isEmpty(gp.getValue())) {
gp.setValue(originalProperties.get(updatedPropertyName).getDefaultValue());
@@ -237,13 +237,13 @@ public class GroupBusinessLogicNew {
groupProperty1Duplicate.setValue(null);
groupProperty1Duplicate.setSchema(null);
groupProperty1Duplicate.setParentUniqueId(null);
- groupProperty1Duplicate.setToscaGetFunction(null);
+ groupProperty1Duplicate.setToscaFunction(null);
groupProperty1Duplicate.setToscaGetFunctionType(null);
GroupProperty groupProperty2Duplicate = new GroupProperty(groupProperty2);
groupProperty2Duplicate.setValue(null);
groupProperty2Duplicate.setSchema(null);
groupProperty2Duplicate.setParentUniqueId(null);
- groupProperty2Duplicate.setToscaGetFunction(null);
+ groupProperty2Duplicate.setToscaFunction(null);
groupProperty2Duplicate.setToscaGetFunctionType(null);
return StringUtils.equals(groupProperty1Duplicate.getValueUniqueUid(), groupProperty2Duplicate.getValueUniqueUid()) && groupProperty1Duplicate
.equals(groupProperty2Duplicate);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaFunctionExceptionSupplier.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaFunctionExceptionSupplier.java
new file mode 100644
index 0000000000..2ba72ab80b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaFunctionExceptionSupplier.java
@@ -0,0 +1,36 @@
+/*
+ * -
+ * ============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.components.impl.exceptions;
+
+import java.util.function.Supplier;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class ToscaFunctionExceptionSupplier {
+
+ public static Supplier<ByActionStatusComponentException> missingFunctionType() {
+ return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "type");
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java
index 44d6f50740..7adc93765a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java
@@ -26,7 +26,7 @@ import java.util.function.Supplier;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
import org.openecomp.sdc.be.datatypes.enums.PropertySource;
import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
@@ -38,6 +38,7 @@ public class ToscaGetFunctionExceptionSupplier {
final String errorMsg = String.format("%s on %s", toscaGetFunctionType.getFunctionName(), propertySource.getName());
return () -> new ByActionStatusComponentException(ActionStatus.NOT_SUPPORTED, errorMsg);
}
+
public static Supplier<ByActionStatusComponentException> propertyNotFoundOnTarget(final String propertyName,
final PropertySource propertySource,
final ToscaGetFunctionType functionType) {
@@ -106,21 +107,21 @@ public class ToscaGetFunctionExceptionSupplier {
return () -> new ByActionStatusComponentException(ActionStatus.NOT_SUPPORTED, "Tosca function " + functionType.getFunctionName());
}
- public static Supplier<ByActionStatusComponentException> propertyTypeDiverge(final ToscaGetFunctionType functionType,
+ public static Supplier<ByActionStatusComponentException> propertyTypeDiverge(final ToscaFunctionType functionType,
final String referredPropertyType,
final String propertyType) {
return () -> new ByActionStatusComponentException(
ActionStatus.TOSCA_GET_FUNCTION_TYPE_DIVERGE,
- functionType.getFunctionName(), referredPropertyType, propertyType
+ functionType.getName(), referredPropertyType, propertyType
);
}
- public static Supplier<ByActionStatusComponentException> propertySchemaDiverge(final ToscaGetFunctionType functionType,
+ public static Supplier<ByActionStatusComponentException> propertySchemaDiverge(final ToscaFunctionType functionType,
final String referredPropertySchemaType,
final String propertySchemaType) {
return () -> new ByActionStatusComponentException(
ActionStatus.TOSCA_GET_FUNCTION_SCHEMA_DIVERGE,
- functionType.getFunctionName(), referredPropertySchemaType, propertySchemaType
+ functionType.getName(), referredPropertySchemaType, propertySchemaType
);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
index c1f45fe7ad..7d58687bfd 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
@@ -83,6 +83,8 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionJsonDeserializer;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -228,6 +230,7 @@ public class ComponentsUtils {
log.trace("convert json to object. json=\n{}", data);
SimpleModule module = new SimpleModule("customDeserializationModule");
module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
+ module.addDeserializer(ToscaFunction.class, new ToscaFunctionJsonDeserializer());
mapper.registerModule(module);
component = mapper.readValue(data, clazz);
if (component == null) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
index cd916d0d1e..96c6762d74 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
@@ -73,6 +73,7 @@ import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ToscaFunctionExceptionSupplier;
import org.openecomp.sdc.be.components.impl.exceptions.ToscaGetFunctionExceptionSupplier;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
@@ -385,7 +386,7 @@ class ComponentInstanceBusinessLogicTest {
propertyGetInput.setType("list");
final SchemaDefinition listStringPropertySchema = createSchema(schemaType);
propertyGetInput.setSchema(listStringPropertySchema);
- propertyGetInput.setToscaGetFunction(
+ propertyGetInput.setToscaFunction(
createGetToscaFunction(inputName, inputId, List.of(propertyGetInput.getName()), PropertySource.SELF, ToscaGetFunctionType.GET_INPUT,
containerComponentId, containerComponentName)
);
@@ -552,7 +553,7 @@ class ComponentInstanceBusinessLogicTest {
componentInstanceProperty.setSchema(schemaDefinition);
}
if (toscaGetFunction != null) {
- componentInstanceProperty.setToscaGetFunction(toscaGetFunction);
+ componentInstanceProperty.setToscaFunction(toscaGetFunction);
}
return componentInstanceProperty;
@@ -612,7 +613,7 @@ class ComponentInstanceBusinessLogicTest {
final ResponseFormat actualResponse = responseFormatEither.right().value();
final ResponseFormat expectedResponse =
ToscaGetFunctionExceptionSupplier
- .propertySchemaDiverge(propertyGetInput.getToscaGetFunction().getFunctionType(), inputDefinition.getSchemaType(),
+ .propertySchemaDiverge(propertyGetInput.getToscaFunction().getType(), inputDefinition.getSchemaType(),
propertyGetInput.getSchemaType())
.get().getResponseFormat();
assertEquals(expectedResponse.getFormattedMessage(), actualResponse.getFormattedMessage());
@@ -672,7 +673,7 @@ class ComponentInstanceBusinessLogicTest {
final ResponseFormat actualResponse = responseFormatEither.right().value();
final ResponseFormat expectedResponse =
ToscaGetFunctionExceptionSupplier
- .propertyTypeDiverge(propertyGetInput.getToscaGetFunction().getFunctionType(), inputDefinition.getType(), propertyGetInput.getType())
+ .propertyTypeDiverge(propertyGetInput.getToscaFunction().getType(), inputDefinition.getType(), propertyGetInput.getType())
.get().getResponseFormat();
assertEquals(expectedResponse.getFormattedMessage(), actualResponse.getFormattedMessage());
assertEquals(expectedResponse.getStatus(), actualResponse.getStatus());
@@ -689,7 +690,7 @@ class ComponentInstanceBusinessLogicTest {
final List<ComponentInstanceProperty> properties = new ArrayList<>();
final ComponentInstanceProperty propertyGetInput = new ComponentInstanceProperty();
propertyGetInput.setName("anyName");
- propertyGetInput.setToscaGetFunction(toscaGetFunction);
+ propertyGetInput.setToscaFunction(toscaGetFunction);
properties.add(propertyGetInput);
final Component component = new Service();
@@ -2659,8 +2660,8 @@ class ComponentInstanceBusinessLogicTest {
private static Stream<Arguments> getToscaFunctionForValidation() {
final var toscaGetFunction1 = new ToscaGetFunctionDataDefinition();
- final ResponseFormat expectedResponse1 = ToscaGetFunctionExceptionSupplier
- .targetFunctionTypeNotFound().get().getResponseFormat();
+ final ResponseFormat expectedResponse1 = ToscaFunctionExceptionSupplier
+ .missingFunctionType().get().getResponseFormat();
final var toscaGetFunction2 = new ToscaGetFunctionDataDefinition();
toscaGetFunction2.setFunctionType(ToscaGetFunctionType.GET_INPUT);