From d5edf5274286e9808dfabf2f49a03a1ba235b70c Mon Sep 17 00:00:00 2001 From: aribeiro Date: Thu, 18 Nov 2021 10:29:39 +0000 Subject: Add node filter with getInput function Support get_input functions for creating node and substitution filters Issue-ID: SDC-3793 Signed-off-by: aribeiro Change-Id: Ie00f621be8418b4a9c88afcbbc07d80c22165e9b --- .../components/validation/NodeFilterValidator.java | 33 +++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'catalog-be/src') 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 6bfe26aab0..eddc8ffcee 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,6 +28,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.components.impl.ResponseFormatManager; import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction; @@ -40,6 +41,7 @@ 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; +import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; @@ -48,7 +50,6 @@ import org.openecomp.sdc.exception.ResponseFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; @org.springframework.stereotype.Component("NodeFilterValidator") public class NodeFilterValidator { @@ -100,7 +101,15 @@ public class NodeFilterValidator { if (booleanResponseFormatEither.isRight()) { return booleanResponseFormatEither; } - } else if (ConstraintConvertor.STATIC_CONSTRAINT.equals(constraint.getSourceType())) { + } + else if (ConstraintConvertor.SERVICE_INPUT_CONSTRAINT.equals(constraint.getSourceType())) { + final Either booleanResponseFormatEither = validateInputConstraint(parentComponent, + componentInstanceId, constraint); + if (booleanResponseFormatEither.isRight()) { + return booleanResponseFormatEither; + } + } + else if (ConstraintConvertor.STATIC_CONSTRAINT.equals(constraint.getSourceType())) { Either booleanResponseFormatEither; if (NodeFilterConstraintType.PROPERTIES.equals(nodeFilterConstraintType)) { booleanResponseFormatEither = isComponentPropertyFilterValid(parentComponent, componentInstanceId, constraint); @@ -148,7 +157,7 @@ public class NodeFilterValidator { sourcePropertyDefinition = componentInstanceProperties == null ? new ArrayList<>() : componentInstanceProperties; } } - if (!CollectionUtils.isEmpty(sourcePropertyDefinition)) { + if (CollectionUtils.isNotEmpty(sourcePropertyDefinition)) { final Optional sourceSelectedProperty = sourcePropertyDefinition.stream() .filter(property -> uiConstraint.getValue().equals(property.getName())).findFirst(); final Optional targetComponentInstanceProperty = parentComponent.getComponentInstancesProperties() @@ -162,6 +171,22 @@ public class NodeFilterValidator { return Either.right(componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty)); } + private Either validateInputConstraint(final Component parentComponent, final String componentInstanceId, + final UIConstraint uiConstraint) { + final List sourceInputDefinition = parentComponent.getInputs(); + if (CollectionUtils.isNotEmpty(sourceInputDefinition)) { + final Optional sourceSelectedProperty = sourceInputDefinition.stream() + .filter(input -> uiConstraint.getValue().equals(input.getName())).findFirst(); + final Optional targetComponentInstanceProperty = parentComponent.getComponentInstancesProperties() + .get(componentInstanceId).stream().filter(property -> uiConstraint.getServicePropertyName().equals(property.getName())).findFirst(); + if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) { + return validatePropertyData(uiConstraint, sourceSelectedProperty, targetComponentInstanceProperty); + } + } + LOGGER.debug("Parent component does not have inputs", parentComponent); + return Either.right(componentsUtils.getResponseFormat(ActionStatus.INPUTS_NOT_FOUND)); + } + private Either validatePropertyData(UIConstraint uiConstraint, Optional sourceSelectedProperty, Optional targetComponentInstanceProperty) { @@ -292,7 +317,7 @@ public class NodeFilterValidator { final List propertyDefinitions = component.getProperties(); List sourcePropertyDefinition = component.getName().equals(uiConstraint.getSourceName()) && propertyDefinitions != null ? propertyDefinitions : Collections.emptyList(); - if (!CollectionUtils.isEmpty(sourcePropertyDefinition)) { + if (CollectionUtils.isNotEmpty(sourcePropertyDefinition)) { final Optional sourceSelectedProperty = sourcePropertyDefinition.stream() .filter(property -> uiConstraint.getValue().equals(property.getName())).findFirst(); final Optional targetComponentProperty = component.getProperties().stream() -- cgit 1.2.3-korg