diff options
author | imamSidero <imam.hussain@est.tech> | 2023-02-08 14:40:35 +0000 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-02-16 09:30:47 +0000 |
commit | 2c30bf8b461108e687d874acad3b444fc732ef4c (patch) | |
tree | c829bbff40a176edb9b5afac82e256738bc8ba9a /catalog-be/src/main/java | |
parent | 59148be1a5a9beea5a157ace746eea3c969f5ed4 (diff) |
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 <imam.hussain@est.tech>
Change-Id: Iec404ec27431eb2b5e085d3f9474e61fadab8d45
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java | 26 |
1 files changed, 19 insertions, 7 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 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<String, DataTypeDefinition> dataTypeDefinitionCache; private final ObjectMapper objectMapper = new ObjectMapper(); private final List<String> 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<String> subPropertyPath = subPropertyToscaFunction.getSubPropertyPath(); + if (subPropertyPath.get((subPropertyPath.size() - 1)).equals(key)) { + propertyDefinition.setToscaFunction(subPropertyToscaFunction.getToscaFunction()); + } + }); + } propertyDefinition.setValue(value); return propertyDefinition; } |