diff options
author | 2022-09-09 16:23:14 +0100 | |
---|---|---|
committer | 2022-09-09 23:21:44 +0100 | |
commit | 1db6e26a7fa6b1afcf1562b239866198dc54ed92 (patch) | |
tree | 4345cdb747865ae8f107c17a329152019e347a66 /catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java | |
parent | cc13802507c3787d341ac1a5d50b539fc1174987 (diff) |
Fix node filter API payload retro-compatibility1.11.8
The create/edit API was not converting properly a legacy payload and
the request was failing.
Also, the create/edit response was not being handled as previously
when the legacy payload was given.
Change-Id: Ic0832cd31ca450806a053ae96889538bf7e8daca
Issue-ID: SDC-4174
Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java')
-rw-r--r-- | catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java index da486e47f5..9c1b6c9f48 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java @@ -23,15 +23,19 @@ package org.openecomp.sdc.be.ui.mapper; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; +import java.util.List; import java.util.Map; import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ToscaFunction; import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; +import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.datatypes.enums.FilterValueType; import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType; +import org.openecomp.sdc.be.datatypes.enums.PropertySource; +import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; import org.openecomp.sdc.be.model.dto.FilterConstraintDto; import org.openecomp.sdc.be.ui.model.UIConstraint; @@ -44,10 +48,34 @@ public class FilterConstraintMapper { filterConstraint.setPropertyName(uiConstraint.getServicePropertyName()); filterConstraint.setTargetType(StringUtils.isEmpty(uiConstraint.getCapabilityName()) ? PropertyFilterTargetType.PROPERTY : PropertyFilterTargetType.CAPABILITY); FilterValueType.findByName(uiConstraint.getSourceType()).ifPresent(filterConstraint::setValueType); - filterConstraint.setValue(parseValueFromUiConstraint(uiConstraint.getValue())); + filterConstraint.setValue(mapValueFrom(uiConstraint)); return filterConstraint; } + private Object mapValueFrom(final UIConstraint uiConstraint) { + if (FilterValueType.GET_INPUT.getLegacyName().equals(uiConstraint.getSourceType())) { + final ToscaGetFunctionDataDefinition toscaGetFunctionDataDefinition = new ToscaGetFunctionDataDefinition(); + toscaGetFunctionDataDefinition.setPropertySource(PropertySource.SELF); + final String value = (String) uiConstraint.getValue(); + toscaGetFunctionDataDefinition.setPropertyName(value); + toscaGetFunctionDataDefinition.setFunctionType(ToscaGetFunctionType.GET_INPUT); + toscaGetFunctionDataDefinition.setPropertyPathFromSource(List.of(value)); + return toscaGetFunctionDataDefinition; + } + + if (FilterValueType.GET_PROPERTY.getLegacyName().equals(uiConstraint.getSourceType())) { + final ToscaGetFunctionDataDefinition toscaGetFunctionDataDefinition = new ToscaGetFunctionDataDefinition(); + toscaGetFunctionDataDefinition.setPropertySource(PropertySource.SELF); + final String value = (String) uiConstraint.getValue(); + toscaGetFunctionDataDefinition.setPropertyName(value); + toscaGetFunctionDataDefinition.setFunctionType(ToscaGetFunctionType.GET_PROPERTY); + toscaGetFunctionDataDefinition.setPropertyPathFromSource(List.of(value)); + return toscaGetFunctionDataDefinition; + } + + return parseValueFromUiConstraint(uiConstraint.getValue()); + } + public FilterConstraintDto mapFrom(final PropertyFilterConstraintDataDefinition propertyFilterConstraint) { var filterConstraintDto = new FilterConstraintDto(); filterConstraintDto.setTargetType(propertyFilterConstraint.getTargetType()); @@ -77,6 +105,7 @@ public class FilterConstraintMapper { uiConstraint.setCapabilityName(filterConstraintDto.getCapabilityName()); uiConstraint.setServicePropertyName(filterConstraintDto.getPropertyName()); uiConstraint.setSourceType(filterConstraintDto.getValueType().getName()); + uiConstraint.setSourceName(uiConstraint.getSourceType()); return uiConstraint; } |