From f7fac88023c4f99775e9d5ae008b7141d42fbf3d Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Thu, 28 Apr 2022 16:46:13 +0100 Subject: Fix Node Filter string property value displayed as object Issue-ID: SDC-3987 Signed-off-by: JvD_Ericsson Change-Id: I4575e8b52e1279339abf557baece60eee960227c --- .../components/impl/ComponentNodeFilterBusinessLogic.java | 15 ++++++++++++++- .../sdc/be/datamodel/utils/ConstraintConvertor.java | 14 ++++++++++++++ .../openecomp/sdc/be/tosca/utils/NodeFilterConverter.java | 8 ++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java index c1669d18f6..e60ced5cc7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java @@ -28,7 +28,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; -import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.utils.CINodeFilterUtils; @@ -44,6 +43,7 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType; 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.UploadNodeFilterInfo; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations; @@ -156,6 +156,18 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic { return Optional.ofNullable(result.left().value()); } + private String getComponentInstancePropertyType(Component component, String componentInstanceId, String propertyName) { + List componentInstanceProperties = component.getComponentInstancesProperties().get(componentInstanceId); + if (!componentInstanceProperties.isEmpty()) { + for (ComponentInstanceProperty componentInstanceProperty : componentInstanceProperties) { + if (componentInstanceProperty.getName().equals(propertyName)) { + return componentInstanceProperty.getType(); + } + } + } + return null; + } + public Optional addNodeFilter(final String componentId, final String componentInstanceId, final NodeFilterConstraintAction action, final String propertyName, final String constraint, final boolean shouldLock, @@ -174,6 +186,7 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic { final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition(); requirementNodeFilterPropertyDataDefinition.setName(propertyName); requirementNodeFilterPropertyDataDefinition.setConstraints(Collections.singletonList(constraint)); + requirementNodeFilterPropertyDataDefinition.setType(getComponentInstancePropertyType(component, componentInstanceId, propertyName)); final Either result = addNewNodeFilter(componentId, componentInstanceId, nodeFilterConstraintType, nodeFilterDataDefinition, requirementNodeFilterPropertyDataDefinition, capabilityName); if (result.isRight()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java index 0fcbdd7768..a2c7aa2502 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java @@ -32,6 +32,7 @@ import org.openecomp.sdc.be.ui.model.UIConstraint; import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; public class ConstraintConvertor { @@ -51,6 +52,10 @@ public class ConstraintConvertor { .of(ToscaFunctions.GET_INPUT.getFunctionName(), ToscaFunctions.GET_PROPERTY.getFunctionName()); public UIConstraint convert(String inConstraint) { + return convert(inConstraint, ""); + } + + public UIConstraint convert(String inConstraint, String valueType) { Yaml yamlSource = new Yaml(); UIConstraint uiConstraint = new UIConstraint(); Object content1 = yamlSource.load(inConstraint); @@ -82,6 +87,15 @@ public class ConstraintConvertor { uiConstraint.setSourceName(STATIC_CONSTRAINT); uiConstraint.setValue(list1); return uiConstraint; + } else if (valueType != null && valueType.equals("string")) { + uiConstraint.setSourceType(STATIC_CONSTRAINT); + uiConstraint.setSourceName(STATIC_CONSTRAINT); + DumperOptions options = new DumperOptions(); + options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW); + Yaml yaml = new Yaml(options); + String yamlString = yaml.dump(content3); + uiConstraint.setValue(yamlString); + return uiConstraint; } else if (content3 instanceof Map) { return handleMap(uiConstraint, content3); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java index cd1a1c6a55..63093ebd9a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java @@ -38,8 +38,12 @@ public class NodeFilterConverter { final ConstraintConvertor constraintConvertor = new ConstraintConvertor(); final ListDataDefinition nodeFilterProperties = inNodeFilter.getProperties(); if (nodeFilterProperties != null && !nodeFilterProperties.isEmpty()) { - final List propertiesConstraint = nodeFilterProperties.getListToscaDataDefinition().stream() - .map(property -> property.getConstraints().iterator().next()).map(constraintConvertor::convert).collect(Collectors.toList()); + final List propertiesConstraint = nodeFilterProperties.getListToscaDataDefinition().stream().map(property -> { + if(property.getType() != null) { + return constraintConvertor.convert(property.getConstraints().iterator().next(), property.getType()); + } else { + return constraintConvertor.convert(property.getConstraints().iterator().next()); + }}).collect(Collectors.toList()); uiNodeFilter.setProperties(propertiesConstraint); } final ListDataDefinition nodeFilterCapabilities = inNodeFilter.getCapabilities(); -- cgit 1.2.3-korg