From a522b7eb8346617883227c0a6621420cfdf44dc5 Mon Sep 17 00:00:00 2001 From: vasraz Date: Wed, 25 Jan 2023 19:09:41 +0000 Subject: Add TCs to cover Constraints Fix wrong Comparable Property Type and Comparable Constraint Type Signed-off-by: Vasyl Razinkov Change-Id: I59968861834a0f8859fcaf3e590c83bbf223338f Issue-ID: SDC-4347 --- .../components/validation/NodeFilterValidator.java | 39 ++++++++++++++-------- .../openecomp/sdc/be/tosca/PropertyConvertor.java | 1 - 2 files changed, 26 insertions(+), 14 deletions(-) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java index b7b2452189..86cedf26d7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java @@ -61,8 +61,15 @@ public class NodeFilterValidator { private static final String TARGET = "Target"; private static final String INPUT_NOT_FOUND_LOG = "Input '{}' not found in parent component '{}', unique id '{}'"; private static final Set TYPES_WITH_SCHEMA = Set.of(ToscaPropertyType.MAP.getType(), ToscaPropertyType.LIST.getType()); - private static final Set COMPARABLE_TYPES = Set - .of(ToscaPropertyType.STRING.getType(), ToscaPropertyType.INTEGER.getType(), ToscaPropertyType.FLOAT.getType()); + private static final Set COMPARABLE_TYPES = Set.of( + ToscaPropertyType.SCALAR_UNIT_SIZE.getType(), + ToscaPropertyType.SCALAR_UNIT_TIME.getType(), + ToscaPropertyType.SCALAR_UNIT_BITRATE.getType(), + ToscaPropertyType.SCALAR_UNIT_FREQUENCY.getType(), + ToscaPropertyType.BOOLEAN.getType(), + ToscaPropertyType.STRING.getType(), + ToscaPropertyType.INTEGER.getType(), + ToscaPropertyType.FLOAT.getType()); private final ComponentsUtils componentsUtils; private final ApplicationDataTypeCache applicationDataTypeCache; private final FilterConstraintValidator filterConstraintValidator; @@ -105,6 +112,7 @@ public class NodeFilterValidator { } return Either.left(true); } + public Either validateFilter(final Component parentComponent, final String componentInstanceId, final FilterConstraintDto filterConstraint) { validateFilterConstraint(filterConstraint); @@ -239,15 +247,15 @@ public class NodeFilterValidator { } return findSubProperty(propertyPath.subList(1, propertyPath.size()), propertyDefinition.getType(), modelDataTypes); } - + private Optional getInstanceProperties(final Component parentComponent, final String componentInstanceId, final String capabilityName, final String propertyName) { if (StringUtils.isEmpty(capabilityName)) { return parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream() - .filter(property -> propertyName.equals(property.getName())).findFirst(); + .filter(property -> propertyName.equals(property.getName())).findFirst(); } else { final Optional componentInstanceOptional = parentComponent.getComponentInstances().stream() - .filter(componentInstance -> componentInstance.getUniqueId().equals(componentInstanceId)).findAny(); + .filter(componentInstance -> componentInstance.getUniqueId().equals(componentInstanceId)).findAny(); if (componentInstanceOptional.isPresent()) { for (final List listOfCaps : componentInstanceOptional.get().getCapabilities().values()) { final Optional capDef = listOfCaps.stream().filter(cap -> cap.getName().equals(capabilityName)).findAny(); @@ -356,7 +364,8 @@ public class NodeFilterValidator { if (componentInstanceProperty == null) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, filterConstraint.getPropertyName())); } - if (filterConstraint.getOperator().isComparable() && !COMPARABLE_TYPES.contains(componentInstanceProperty.getType())) { + if (filterConstraint.getOperator().isComparable() && !TYPES_WITH_SCHEMA.contains(componentInstanceProperty.getType()) + && !COMPARABLE_TYPES.contains(componentInstanceProperty.getType())) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraint.getPropertyName(), filterConstraint.getOperator().getType())); } @@ -372,7 +381,8 @@ public class NodeFilterValidator { if (componentProperty == null) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, filterConstraint.getPropertyName())); } - if (filterConstraint.getOperator().isComparable() && !COMPARABLE_TYPES.contains(componentProperty.getType())) { + if (filterConstraint.getOperator().isComparable() && !TYPES_WITH_SCHEMA.contains(componentProperty.getType()) + && !COMPARABLE_TYPES.contains(componentProperty.getType())) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraint.getPropertyName(), filterConstraint.getOperator().getType())); } @@ -403,16 +413,17 @@ public class NodeFilterValidator { if (componentInstanceProperty == null) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, filterConstraint.getPropertyName())); } - if (filterConstraint.getOperator().isComparable() && !COMPARABLE_TYPES.contains(componentInstanceProperty.getType())) { + if (filterConstraint.getOperator().isComparable() && !TYPES_WITH_SCHEMA.contains(componentInstanceProperty.getType()) + && !COMPARABLE_TYPES.contains(componentInstanceProperty.getType())) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraint.getPropertyName(), filterConstraint.getOperator().getType())); } return isValidValueCheck(componentInstanceProperty.getType(), componentInstanceProperty.getSchemaType(), parentComponent.getModel(), filterConstraint.getValue(), filterConstraint.getPropertyName()); } - - private Optional getComponentInstanceProperty(CapabilityDefinition capabilityDefinition, final String propertyName){ - return capabilityDefinition.getProperties().stream().filter(property -> property.getName().equals(propertyName)).findAny(); + + private Optional getComponentInstanceProperty(CapabilityDefinition capabilityDefinition, final String propertyName) { + return capabilityDefinition.getProperties().stream().filter(property -> property.getName().equals(propertyName)).findAny(); } private Either isValidValueCheck(final String type, final String schemaType, final String model, @@ -433,7 +444,8 @@ public class NodeFilterValidator { valueAsJsonString = new Gson().toJson(value); } catch (final Exception e) { LOGGER.debug("Unsupported property filter value", e); - return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, String.valueOf(value))); + return Either.right( + componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, String.valueOf(value))); } if (toscaPropertyType != null) { if (toscaPropertyType.getValidator().isValid(valueAsJsonString, schemaType, modelDataTypesMap)) { @@ -448,7 +460,8 @@ public class NodeFilterValidator { return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, valueAsJsonString)); } - public Either validateSubstitutionFilter(final Component component, final List filterConstraintList) { + public Either validateSubstitutionFilter(final Component component, + final List filterConstraintList) { if (CollectionUtils.isEmpty(filterConstraintList)) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.CONSTRAINT_FORMAT_INCORRECT)); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java index 9b92adbe6a..75385d1f43 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java @@ -78,7 +78,6 @@ import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; import org.springframework.stereotype.Service; import org.yaml.snakeyaml.Yaml; - @Service public class PropertyConvertor { -- cgit 1.2.3-korg