aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java157
1 files changed, 112 insertions, 45 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 c6848030cd..8c27396e3b 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
@@ -28,13 +28,16 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
@@ -53,11 +56,11 @@ public class NodeFilterValidator {
private static final String SOURCE = "Source";
public static final Set<String> comparableTypes = ImmutableSet.of(ToscaPropertyType.STRING.getType(),
- ToscaPropertyType.INTEGER.getType(), ToscaPropertyType.FLOAT.getType());
+ ToscaPropertyType.INTEGER.getType(), ToscaPropertyType.FLOAT.getType());
public static final Set<String> schemableTypes =
- ImmutableSet.of(ToscaPropertyType.MAP.getType(), ToscaPropertyType.LIST.getType());
+ ImmutableSet.of(ToscaPropertyType.MAP.getType(), ToscaPropertyType.LIST.getType());
public static final Set<String> comparableConstraintsOperators =
- ImmutableSet.of(ConstraintConvertor.GREATER_THAN_OPERATOR, ConstraintConvertor.LESS_THAN_OPERATOR);
+ ImmutableSet.of(ConstraintConvertor.GREATER_THAN_OPERATOR, ConstraintConvertor.LESS_THAN_OPERATOR);
protected final ToscaOperationFacade toscaOperationFacade;
protected final ComponentsUtils componentsUtils;
@@ -78,8 +81,8 @@ public class NodeFilterValidator {
return getErrorResponse(ActionStatus.FILTER_NOT_FOUND);
}
if (CollectionUtils.isEmpty(component.getComponentInstances()) ||
- component.getComponentInstances().stream()
- .noneMatch(ci -> ci.getUniqueId().equals(componentInstanceId))) {
+ component.getComponentInstances().stream()
+ .noneMatch(ci -> ci.getUniqueId().equals(componentInstanceId))) {
LOGGER.error("Component Instance list is empty");
return getErrorResponse(ActionStatus.FILTER_NOT_FOUND);
}
@@ -94,20 +97,28 @@ public class NodeFilterValidator {
public Either<Boolean, ResponseFormat> validateFilter(final Component parentComponent,
final String componentInstanceId,
final List<String> uiConstraints,
- final NodeFilterConstraintAction action) {
+ final NodeFilterConstraintAction action,
+ final NodeFilterConstraintType nodeFilterConstraintType) {
try {
if (NodeFilterConstraintAction.ADD == action || NodeFilterConstraintAction.UPDATE == action) {
for (final String uiConstraint : uiConstraints) {
final UIConstraint constraint = new ConstraintConvertor().convert(uiConstraint);
if (ConstraintConvertor.PROPERTY_CONSTRAINT.equals(constraint.getSourceType())) {
final Either<Boolean, ResponseFormat> booleanResponseFormatEither =
- validatePropertyConstraint(parentComponent, componentInstanceId, constraint);
+ validatePropertyConstraint(parentComponent, componentInstanceId, constraint);
if (booleanResponseFormatEither.isRight()) {
return booleanResponseFormatEither;
}
} else if (ConstraintConvertor.STATIC_CONSTRAINT.equals(constraint.getSourceType())) {
- final Either<Boolean, ResponseFormat> booleanResponseFormatEither =
- validateStaticValueAndOperator(parentComponent, componentInstanceId, constraint);
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither;
+ if (NodeFilterConstraintType.PROPERTIES.equals(nodeFilterConstraintType)) {
+ booleanResponseFormatEither = isComponentPropertyFilterValid(
+ parentComponent, componentInstanceId, constraint);
+ } else {
+ booleanResponseFormatEither = isComponentCapabilityPropertyFilterValid(
+ parentComponent, componentInstanceId, constraint);
+ }
+
if (booleanResponseFormatEither.isRight()) {
return booleanResponseFormatEither;
}
@@ -122,6 +133,21 @@ public class NodeFilterValidator {
return Either.left(true);
}
+ private Either<Boolean, ResponseFormat> isComponentCapabilityPropertyFilterValid(final Component parentComponent,
+ final String componentInstanceId,
+ final UIConstraint uiConstraint) {
+
+ return validateStaticValueAndOperatorOfCapabilityProperties(parentComponent, componentInstanceId, uiConstraint);
+
+ }
+
+ private Either<Boolean, ResponseFormat> isComponentPropertyFilterValid(Component parentComponent,
+ String componentInstanceId,
+ UIConstraint constraint) {
+
+ return validateStaticValueAndOperator(parentComponent, componentInstanceId, constraint);
+ }
+
private Either<Boolean, ResponseFormat> validatePropertyConstraint(final Component parentComponent,
final String componentInstanceId,
final UIConstraint uiConstraint) {
@@ -130,36 +156,36 @@ public class NodeFilterValidator {
final List<PropertyDefinition> propertyDefinitions = parentComponent.getProperties();
List<? extends PropertyDefinition> sourcePropertyDefinition =
- parentComponent.getName().equals(uiConstraint.getSourceName()) &&
- propertyDefinitions != null ? propertyDefinitions : Collections.emptyList();
+ parentComponent.getName().equals(uiConstraint.getSourceName()) &&
+ propertyDefinitions != null ? propertyDefinitions : Collections.emptyList();
if (sourcePropertyDefinition.isEmpty() && !parentComponent.getName().equals(uiConstraint.getSourceName())) {
optionalComponentInstance = parentComponent.getComponentInstances().stream()
- .filter(componentInstance -> uiConstraint.getSourceName()
- .equals(componentInstance
- .getName()))
- .findFirst();
+ .filter(componentInstance -> uiConstraint.getSourceName()
+ .equals(componentInstance
+ .getName()))
+ .findFirst();
if (optionalComponentInstance.isPresent()) {
final List<ComponentInstanceProperty> componentInstanceProperties =
- parentComponent.getComponentInstancesProperties()
- .get(optionalComponentInstance.get().getUniqueId());
+ parentComponent.getComponentInstancesProperties()
+ .get(optionalComponentInstance.get().getUniqueId());
sourcePropertyDefinition =
- componentInstanceProperties == null ? new ArrayList<>() : componentInstanceProperties;
+ componentInstanceProperties == null ? new ArrayList<>() : componentInstanceProperties;
}
}
if (!CollectionUtils.isEmpty(sourcePropertyDefinition)) {
final Optional<? extends PropertyDefinition> sourceSelectedProperty = sourcePropertyDefinition.stream()
- .filter(property -> uiConstraint
- .getValue()
- .equals(property.getName()))
- .findFirst();
+ .filter(property -> uiConstraint
+ .getValue()
+ .equals(property.getName()))
+ .findFirst();
final Optional<? extends PropertyDefinition> targetComponentInstanceProperty =
- parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
- .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
- .findFirst();
+ parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
+ .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
+ .findFirst();
source = !targetComponentInstanceProperty.isPresent() ? "Target" : SOURCE;
if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) {
@@ -168,10 +194,10 @@ public class NodeFilterValidator {
}
final String missingProperty =
- source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
+ source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty));
+ componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty));
}
private Either<Boolean, ResponseFormat> validatePropertyData(UIConstraint uiConstraint,
@@ -188,48 +214,89 @@ public class NodeFilterValidator {
final SchemaDefinition targetSchemaDefinition = targetPropDefinition.getSchema();
if (!sourceSchemaDefinition.equals(targetSchemaDefinition)) {
return Either
- .right(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH,
- uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString()));
+ .right(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH,
+ uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString()));
}
}
return Either.left(Boolean.TRUE);
} else {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
- uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString()));
+ uiConstraint.getServicePropertyName(), uiConstraint.getValue().toString()));
}
} else {
LOGGER.debug(
- "Null value passed to `validatePropertyData` - sourceSelectedProperty: '{}' - targetComponentInstanceProperty: '{}'",
- sourceSelectedProperty, targetComponentInstanceProperty);
+ "Null value passed to `validatePropertyData` - sourceSelectedProperty: '{}' - targetComponentInstanceProperty: '{}'",
+ sourceSelectedProperty, targetComponentInstanceProperty);
return Either.right(componentsUtils
- .getResponseFormat(ActionStatus.GENERAL_ERROR, uiConstraint.getServicePropertyName(),
- uiConstraint.getValue().toString()));
+ .getResponseFormat(ActionStatus.GENERAL_ERROR, uiConstraint.getServicePropertyName(),
+ uiConstraint.getValue().toString()));
}
}
private Either<Boolean, ResponseFormat> validateStaticValueAndOperator(
- final Component parentComponent,
- final String componentInstanceId, final UIConstraint uiConstraint) {
+ final Component parentComponent,
+ final String componentInstanceId, final UIConstraint uiConstraint) {
if (!(Objects.nonNull(uiConstraint) && uiConstraint.getValue() instanceof String)) {
return Either.left(false);
}
+ //TODO: get capabilities properties when constraint type is capabilities
final Optional<ComponentInstanceProperty> componentInstanceProperty =
- parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
- .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
- .findFirst();
+ parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
+ .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
+ .findFirst();
if (!componentInstanceProperty.isPresent()) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT,
- uiConstraint.getServicePropertyName()));
+ uiConstraint.getServicePropertyName()));
}
if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes.contains(
- componentInstanceProperty.get().getType())) {
+ componentInstanceProperty.get().getType())) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED,
- uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator()));
+ uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator()));
}
return isValidValueCheck(componentInstanceProperty.get().getType(), String.valueOf(uiConstraint.getValue()),
- uiConstraint.getServicePropertyName());
+ uiConstraint.getServicePropertyName());
+ }
+
+ private Either<Boolean, ResponseFormat> validateStaticValueAndOperatorOfCapabilityProperties(
+ final Component parentComponent, final String componentInstanceId, final UIConstraint uiConstraint) {
+ if (!(Objects.nonNull(uiConstraint) && uiConstraint.getValue() instanceof String)) {
+ return Either.left(false);
+ }
+ Optional<ComponentInstanceProperty> optionalComponentInstanceProperty = Optional.empty();
+ final Optional<ComponentInstance> optionalComponentInstances = parentComponent.getComponentInstances().stream()
+ .filter(componentInstance -> componentInstanceId.equalsIgnoreCase(componentInstance.getUniqueId()))
+ .findFirst();
+ if (optionalComponentInstances.isPresent()) {
+ final Optional<List<CapabilityDefinition>> optionalCapabilityDefinitionList = optionalComponentInstances.get()
+ .getCapabilities().values().stream()
+ .filter(capabilityDefinitions -> capabilityDefinitions
+ .stream().allMatch(capabilityDefinition -> capabilityDefinition.getProperties() != null))
+ .collect(Collectors.toList())
+ .stream().filter(capabilityDefinitions -> capabilityDefinitions.stream().allMatch(
+ capabilityDefinition -> capabilityDefinition.getProperties().stream().anyMatch(
+ componentInstanceProperty -> uiConstraint.getServicePropertyName()
+ .equalsIgnoreCase(componentInstanceProperty.getName())))).findFirst();
+
+ if (optionalCapabilityDefinitionList.isPresent()) {
+ optionalComponentInstanceProperty = optionalCapabilityDefinitionList.get().stream().findAny()
+ .map(capabilityDefinition -> capabilityDefinition.getProperties().get(0));
+ }
+ }
+
+ if (optionalComponentInstanceProperty.isEmpty()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT,
+ uiConstraint.getServicePropertyName()));
+ }
+ if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes.contains(
+ optionalComponentInstanceProperty.get().getType())) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED,
+ uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator()));
+ }
+
+ return isValidValueCheck(optionalComponentInstanceProperty.get().getType(), String.valueOf(uiConstraint.getValue()),
+ uiConstraint.getServicePropertyName());
}
private Either<Boolean, ResponseFormat> isValidValueCheck(String type, String value, String propertyName) {
@@ -237,13 +304,13 @@ public class NodeFilterValidator {
ToscaPropertyType toscaPropertyType = ToscaPropertyType.isValidType(type);
if (Objects.isNull(toscaPropertyType)) {
return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_PROPERTY_TYPE, type, propertyName));
+ componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_PROPERTY_TYPE, type, propertyName));
}
if (toscaPropertyType.getValidator().isValid(value, null)) {
return Either.left(Boolean.TRUE);
}
return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, value));
+ componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, value));
}
public Either<Boolean, ResponseFormat> validateComponentFilter(final Component component,