From 2c30bf8b461108e687d874acad3b444fc732ef4c Mon Sep 17 00:00:00 2001 From: imamSidero Date: Wed, 8 Feb 2023 14:40:35 +0000 Subject: Provide tosca function to list of map values Providing the capability to add tosca function for list of map values Issue-ID: SDC-4379 Signed-off-by: Imam hussain Change-Id: Iec404ec27431eb2b5e085d3f9474e61fadab8d45 --- .../PropertyValueConstraintValidationUtil.java | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'catalog-be') 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 46bd763ec0..a25a332b9e 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 @@ -41,6 +41,7 @@ import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.PropertyConstraint; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; +import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; import org.openecomp.sdc.be.model.tosca.ToscaType; import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil; import org.openecomp.sdc.be.model.tosca.constraints.LengthConstraint; @@ -57,7 +58,9 @@ public class PropertyValueConstraintValidationUtil { private static final String UNDERSCORE = "_"; private static final String VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY = "%nValue provided in invalid format for %s property"; private static final Logger logger = LoggerFactory.getLogger(PropertyValueConstraintValidationUtil.class); - private static final String IGNORE_PROPERTY_VALUE_START_WITH = "{\"get_input\":"; + private static final String IGNORE_PROPERTY_VALUE_START_WITH_INPUT = "{\"get_input\":"; + private static final String IGNORE_PROPERTY_VALUE_START_WITH_PROPERTY = "{\"get_property\":"; + private static final String IGNORE_PROPERTY_VALUE_START_WITH_ATTRIBUTE = "{\"get_attribute\":"; private Map dataTypeDefinitionCache; private final ObjectMapper objectMapper = new ObjectMapper(); private final List errorMessages = new ArrayList<>(); @@ -153,7 +156,8 @@ public class PropertyValueConstraintValidationUtil { } private boolean isPropertyNotMappedAsInput(PropertyDefinition propertyDefinition) { - return !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH); + return !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_INPUT) && !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_PROPERTY) + && !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_ATTRIBUTE); } private void checkAndEvaluatePrimitiveProperty(PropertyDefinition propertyDefinition, DataTypeDefinition dataTypeDefinition) { @@ -203,21 +207,21 @@ public class PropertyValueConstraintValidationUtil { } } if (ToscaType.isPrimitiveType(prop.getType())) { - newPropertyWithValue = copyPropertyWithNewValue(prop, String.valueOf(valueMap.get(prop.getName()))); + newPropertyWithValue = copyPropertyWithNewValue(prop, String.valueOf(valueMap.get(prop.getName())), prop.getName()); if (isPropertyToEvaluate(newPropertyWithValue)) { evaluateConstraintsOnProperty(newPropertyWithValue); } } else if (ToscaType.isCollectionType(prop.getType())) { newPropertyWithValue = copyPropertyWithNewValue(prop, - objectMapper.writeValueAsString(valueMap.get(prop.getName()))); + objectMapper.writeValueAsString(valueMap.get(prop.getName())), prop.getName()); if (isPropertyToEvaluate(newPropertyWithValue)) { evaluateCollectionTypeProperties(newPropertyWithValue); } } else { newPropertyWithValue = copyPropertyWithNewValue(prop, - objectMapper.writeValueAsString(valueMap.get(prop.getName()))); + objectMapper.writeValueAsString(valueMap.get(prop.getName())), prop.getName()); if (isPropertyToEvaluate(newPropertyWithValue)) { evaluateComplexTypeProperties(newPropertyWithValue); } @@ -365,7 +369,7 @@ public class PropertyValueConstraintValidationUtil { final Object value = valueMap.get(mapKey); try { final PropertyDefinition propertyCopyWithNewValue = copyPropertyWithNewValue(propertyDefinition, - objectMapper.writeValueAsString(value)); + objectMapper.writeValueAsString(value),mapKey); propertyCopyWithNewValue.setToscaSubPath(mapKey); if (ToscaType.isPrimitiveType(schemaType)) { evaluateCollectionPrimitiveSchemaType(propertyCopyWithNewValue, schemaType); @@ -399,8 +403,16 @@ public class PropertyValueConstraintValidationUtil { return propertyName; } - private PropertyDefinition copyPropertyWithNewValue(final PropertyDefinition propertyToCopy, final String value) { + private PropertyDefinition copyPropertyWithNewValue(final PropertyDefinition propertyToCopy, final String value, final String key) { final var propertyDefinition = new PropertyDefinition(propertyToCopy); + if (key != null && propertyToCopy.getSubPropertyToscaFunctions() != null) { + propertyToCopy.getSubPropertyToscaFunctions().forEach(subPropertyToscaFunction -> { + final List subPropertyPath = subPropertyToscaFunction.getSubPropertyPath(); + if (subPropertyPath.get((subPropertyPath.size() - 1)).equals(key)) { + propertyDefinition.setToscaFunction(subPropertyToscaFunction.getToscaFunction()); + } + }); + } propertyDefinition.setValue(value); return propertyDefinition; } -- cgit 1.2.3-korg