aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2020-06-24 08:34:22 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-07-09 09:34:30 +0000
commitbdeb28f273da2494d7eeabbb5329222dfd168e3b (patch)
tree2cf9e54e83db704ee7215b033a2abde9ab8adee7 /catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
parent0132d3637a889f84897d6a08688b20ff6f606041 (diff)
Add support for substitution_filter business logic
Tosca simple YAML profile allows for substitution_filter to be specified for a topology template to provide processing instructions to the orchestrator. Issue-ID: SDC-3147 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: Ia94b8c447d3157e614f9d1524ad4520b3980ba4d
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.java98
1 files changed, 49 insertions, 49 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 30632e9012..9716dfae23 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
@@ -53,11 +53,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;
@@ -75,13 +75,13 @@ public class NodeFilterValidator {
final String componentInstanceId) {
if (component == null || StringUtils.isEmpty(componentInstanceId)) {
LOGGER.error("Input data cannot be empty");
- return getErrorResponse(ActionStatus.NODE_FILTER_NOT_FOUND);
+ return getErrorResponse(ActionStatus.FILTER_NOT_FOUND);
}
if (CollectionUtils.isEmpty(component.getComponentInstances()) ||
component.getComponentInstances().stream()
.noneMatch(ci -> ci.getUniqueId().equals(componentInstanceId))) {
LOGGER.error("Component Instance list is empty");
- return getErrorResponse(ActionStatus.NODE_FILTER_NOT_FOUND);
+ return getErrorResponse(ActionStatus.FILTER_NOT_FOUND);
}
return Either.left(Boolean.TRUE);
}
@@ -91,10 +91,10 @@ public class NodeFilterValidator {
return Either.right(errorResponse);
}
- public Either<Boolean, ResponseFormat> validateNodeFilter(final Component parentComponent,
- final String componentInstanceId,
- final List<String> uiConstraints,
- final NodeFilterConstraintAction action) {
+ public Either<Boolean, ResponseFormat> validateFilter(final Component parentComponent,
+ final String componentInstanceId,
+ final List<String> uiConstraints,
+ final NodeFilterConstraintAction action) {
try {
if (NodeFilterConstraintAction.ADD == action || NodeFilterConstraintAction.UPDATE == action) {
for (final String uiConstraint : uiConstraints) {
@@ -122,44 +122,44 @@ public class NodeFilterValidator {
return Either.left(true);
}
- private Either<Boolean, ResponseFormat> validatePropertyConstraint(
- final Component parentComponent,
- final String componentInstanceId, final UIConstraint uiConstraint) {
+ private Either<Boolean, ResponseFormat> validatePropertyConstraint(final Component parentComponent,
+ final String componentInstanceId,
+ final UIConstraint uiConstraint) {
String source = SOURCE;
- final Optional<ComponentInstance> brotherComponentInstance;
+ final Optional<ComponentInstance> optionalComponentInstance;
+ final List<PropertyDefinition> propertyDefinitions = parentComponent.getProperties();
List<? extends PropertyDefinition> sourcePropertyDefinition =
- parentComponent.getName().equals(uiConstraint.getSourceName()) ? parentComponent.getProperties() :
- Collections.emptyList();
-
+ parentComponent.getName().equals(uiConstraint.getSourceName()) &&
+ propertyDefinitions != null ? propertyDefinitions : Collections.emptyList();
if (sourcePropertyDefinition.isEmpty() && !parentComponent.getName().equals(uiConstraint.getSourceName())) {
- brotherComponentInstance = parentComponent.getComponentInstances().stream()
- .filter(componentInstance -> uiConstraint.getSourceName()
- .equals(componentInstance
- .getName()))
- .findFirst();
+ optionalComponentInstance = parentComponent.getComponentInstances().stream()
+ .filter(componentInstance -> uiConstraint.getSourceName()
+ .equals(componentInstance
+ .getName()))
+ .findFirst();
- if (brotherComponentInstance.isPresent()) {
+ if (optionalComponentInstance.isPresent()) {
final List<ComponentInstanceProperty> componentInstanceProperties =
- parentComponent.getComponentInstancesProperties()
- .get(brotherComponentInstance.get().getUniqueId());
+ parentComponent.getComponentInstancesProperties()
+ .get(optionalComponentInstance.get().getUniqueId());
sourcePropertyDefinition =
- componentInstanceProperties == null ? new ArrayList<>() : componentInstanceProperties;
+ componentInstanceProperties == null ? new ArrayList<>() : componentInstanceProperties;
}
}
if (!CollectionUtils.isEmpty(sourcePropertyDefinition)) {
- Optional<? extends PropertyDefinition> sourceSelectedProperty = sourcePropertyDefinition.stream()
- .filter(property -> uiConstraint
- .getValue()
- .equals(property.getName()))
- .findFirst();
+ final Optional<? extends PropertyDefinition> sourceSelectedProperty = sourcePropertyDefinition.stream()
+ .filter(property -> uiConstraint
+ .getValue()
+ .equals(property.getName()))
+ .findFirst();
- Optional<? extends PropertyDefinition> targetComponentInstanceProperty =
- parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
- .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
- .findFirst();
+ final Optional<? extends PropertyDefinition> targetComponentInstanceProperty =
+ parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
+ .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
+ .findFirst();
source = !targetComponentInstanceProperty.isPresent() ? "Target" : SOURCE;
if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) {
@@ -167,16 +167,16 @@ public class NodeFilterValidator {
}
}
- String missingProperty =
- source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
+ final String missingProperty =
+ 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,
- Optional<? extends PropertyDefinition> sourceSelectedProperty,
- Optional<? extends PropertyDefinition> targetComponentInstanceProperty) {
+ Optional<? extends PropertyDefinition> sourceSelectedProperty,
+ Optional<? extends PropertyDefinition> targetComponentInstanceProperty) {
if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) {
final PropertyDefinition sourcePropDefinition = sourceSelectedProperty.get();
final String sourceType = sourcePropDefinition.getType();
@@ -208,28 +208,28 @@ public class NodeFilterValidator {
}
private Either<Boolean, ResponseFormat> validateStaticValueAndOperator(
- final Component parentComponent,
+ final Component parentComponent,
final String componentInstanceId, final UIConstraint uiConstraint) {
if (!(Objects.nonNull(uiConstraint) && uiConstraint.getValue() instanceof String)) {
return Either.left(false);
}
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> isValidValueCheck(String type, String value, String propertyName) {
@@ -237,13 +237,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));
}