aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel
diff options
context:
space:
mode:
authorimamSidero <imam.hussain@est.tech>2022-12-21 17:51:43 +0000
committerimamSidero <imam.hussain@est.tech>2023-01-03 15:03:15 +0000
commitdb3e2ef238fa29e06cec3cb3f5b11fb407b161ce (patch)
tree1dbca1372aa87c881a4ed93a8788e3eff0d38e9d /catalog-be/src/main/java/org/openecomp/sdc/be/datamodel
parent5b1a92cea1fb437c236a77468f3e8e351e25a990 (diff)
Provide tosca function to custom datatypes of list and map
Providing the capability to add tosca function as the custom datatypes of list and map Issue-ID: SDC-4311 Signed-off-by: Imam hussain <imam.hussain@est.tech> Change-Id: I7ec8943d8008440b091fc4eaa2aba49cdadcda8d
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/datamodel')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java35
1 files changed, 29 insertions, 6 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
index 6aa59e4844..19fe69e421 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
@@ -34,6 +34,7 @@ import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubPropertyToscaFunction;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
@@ -186,6 +187,21 @@ public class PropertyValueConstraintValidationUtil {
try {
PropertyDefinition newPropertyWithValue;
if (valueMap.containsKey(prop.getName())) {
+ if (propertyDefinition.getSubPropertyToscaFunctions() != null) {
+ for (SubPropertyToscaFunction subPropertyToscaFunction : propertyDefinition.getSubPropertyToscaFunctions()) {
+ final List<String> path = subPropertyToscaFunction.getSubPropertyPath();
+ if (path.size() == 1) {
+ if (path.get(0).equals(prop.getName())) {
+ return;
+ }
+ }
+ if (path.size() > 1) {
+ if (path.get(0).equals(propertyDefinition.getToscaSubPath()) && path.get(1).equals(prop.getName())) {
+ return;
+ }
+ }
+ }
+ }
if (ToscaType.isPrimitiveType(prop.getType())) {
newPropertyWithValue = copyPropertyWithNewValue(prop, String.valueOf(valueMap.get(prop.getName())));
if (isPropertyToEvaluate(newPropertyWithValue)) {
@@ -297,9 +313,14 @@ public class PropertyValueConstraintValidationUtil {
if (propertyDefinition.getSchemaType() == null) {
propertyDefinition.setSchema(createStringSchema());
}
- Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
- });
- evaluateCollectionType(propertyDefinition, list);
+ Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
+ final Map<String, Object> map = new HashMap<>();
+ int index = 0;
+ for (Object obj : list) {
+ map.put(String.valueOf(index),obj);
+ index++;
+ }
+ evaluateCollectionType(propertyDefinition, map);
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
logger.debug(e.getMessage(), e);
errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
@@ -321,7 +342,7 @@ public class PropertyValueConstraintValidationUtil {
}
final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
});
- evaluateCollectionType(propertyDefinition, map.values());
+ evaluateCollectionType(propertyDefinition, map);
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
logger.debug(e.getMessage(), e);
errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
@@ -338,12 +359,14 @@ public class PropertyValueConstraintValidationUtil {
}
}
- private void evaluateCollectionType(final PropertyDefinition propertyDefinition, final Collection<Object> valueList) {
+ private void evaluateCollectionType(final PropertyDefinition propertyDefinition, final Map<String, Object> valueMap) {
final String schemaType = propertyDefinition.getSchemaType();
- for (final Object value : valueList) {
+ for (String mapKey : valueMap.keySet()) {
+ final Object value = valueMap.get(mapKey);
try {
final PropertyDefinition propertyCopyWithNewValue = copyPropertyWithNewValue(propertyDefinition,
objectMapper.writeValueAsString(value));
+ propertyCopyWithNewValue.setToscaSubPath(mapKey);
if (ToscaType.isPrimitiveType(schemaType)) {
evaluateCollectionPrimitiveSchemaType(propertyCopyWithNewValue, schemaType);
} else if (ToscaType.isCollectionType(schemaType)) {