diff options
author | vasraz <vasyl.razinkov@est.tech> | 2023-01-25 19:09:41 +0000 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-01-27 15:06:22 +0000 |
commit | a522b7eb8346617883227c0a6621420cfdf44dc5 (patch) | |
tree | 975c31e045de5042c6d18432d0f8c324f82d7f81 /catalog-be/src/main | |
parent | 8571d98d5b0eb81a80c35b07ae0d0bc7b16948ab (diff) |
Add TCs to cover Constraints
Fix wrong Comparable Property Type and Comparable Constraint Type
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I59968861834a0f8859fcaf3e590c83bbf223338f
Issue-ID: SDC-4347
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java | 39 | ||||
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java | 1 |
2 files changed, 26 insertions, 14 deletions
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<String> TYPES_WITH_SCHEMA = Set.of(ToscaPropertyType.MAP.getType(), ToscaPropertyType.LIST.getType()); - private static final Set<String> COMPARABLE_TYPES = Set - .of(ToscaPropertyType.STRING.getType(), ToscaPropertyType.INTEGER.getType(), ToscaPropertyType.FLOAT.getType()); + private static final Set<String> 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<Boolean, ResponseFormat> 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<ComponentInstanceProperty> 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<ComponentInstance> componentInstanceOptional = parentComponent.getComponentInstances().stream() - .filter(componentInstance -> componentInstance.getUniqueId().equals(componentInstanceId)).findAny(); + .filter(componentInstance -> componentInstance.getUniqueId().equals(componentInstanceId)).findAny(); if (componentInstanceOptional.isPresent()) { for (final List<CapabilityDefinition> listOfCaps : componentInstanceOptional.get().getCapabilities().values()) { final Optional<CapabilityDefinition> 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<ComponentInstanceProperty> getComponentInstanceProperty(CapabilityDefinition capabilityDefinition, final String propertyName){ - return capabilityDefinition.getProperties().stream().filter(property -> property.getName().equals(propertyName)).findAny(); + + private Optional<ComponentInstanceProperty> getComponentInstanceProperty(CapabilityDefinition capabilityDefinition, final String propertyName) { + return capabilityDefinition.getProperties().stream().filter(property -> property.getName().equals(propertyName)).findAny(); } private Either<Boolean, ResponseFormat> 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<Boolean, ResponseFormat> validateSubstitutionFilter(final Component component, final List<FilterConstraintDto> filterConstraintList) { + public Either<Boolean, ResponseFormat> validateSubstitutionFilter(final Component component, + final List<FilterConstraintDto> 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 { |