aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-09-09 16:23:14 +0100
committerandre.schmid <andre.schmid@est.tech>2022-09-09 23:21:44 +0100
commit1db6e26a7fa6b1afcf1562b239866198dc54ed92 (patch)
tree4345cdb747865ae8f107c17a329152019e347a66
parentcc13802507c3787d341ac1a5d50b539fc1174987 (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>
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java42
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapper.java31
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/UIConstraintMapper.java49
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java8
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapperTest.java2
5 files changed, 123 insertions, 9 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java
index 87de704750..80c806f9c3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java
@@ -26,6 +26,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.Optional;
+import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
@@ -40,6 +41,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic;
@@ -59,7 +61,9 @@ import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
import org.openecomp.sdc.be.tosca.utils.NodeFilterConverter;
import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
+import org.openecomp.sdc.be.ui.mapper.UIConstraintMapper;
import org.openecomp.sdc.be.ui.model.UIConstraint;
+import org.openecomp.sdc.be.ui.model.UINodeFilter;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
import org.slf4j.Logger;
@@ -142,8 +146,11 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet {
LOGGER.error(FAILED_TO_CREATE_NODE_FILTER);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- new NodeFilterConverter().convertToUi(actionResponse.get()));
+ final UINodeFilter uiNodeFilter = new NodeFilterConverter().convertToUi(actionResponse.get());
+ if (uiConstraint.isLegacyGetFunction()) {
+ mapToLegacyResponse(uiNodeFilter);
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), uiNodeFilter);
} catch (final ComponentException e) {
throw e;
} catch (final BusinessLogicException e) {
@@ -187,21 +194,24 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet {
getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM, INVALID_NODE_FILTER_CONSTRAINT_TYPE, constraintType));
}
final ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- final Optional<UIConstraint> convertResponse = componentsUtils.parseToConstraint(constraintData, userModifier, componentTypeEnum);
- if (convertResponse.isEmpty()) {
+ final UIConstraint uiConstraint = componentsUtils.parseToConstraint(constraintData, userModifier, componentTypeEnum).orElse(null);
+ if (uiConstraint == null) {
LOGGER.error(FAILED_TO_PARSE_COMPONENT);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
final NodeFilterConstraintType nodeFilterConstraintType = nodeFilterConstraintTypeOptional.get();
final Optional<CINodeFilterDataDefinition> actionResponse = componentNodeFilterBusinessLogic
- .updateNodeFilter(componentId.toLowerCase(), componentInstanceId, convertResponse.get(), componentTypeEnum, nodeFilterConstraintType,
+ .updateNodeFilter(componentId.toLowerCase(), componentInstanceId, uiConstraint, componentTypeEnum, nodeFilterConstraintType,
index);
if (actionResponse.isEmpty()) {
LOGGER.error(FAILED_TO_UPDATE_NODE_FILTER);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- new NodeFilterConverter().convertToUi(actionResponse.get()));
+ final UINodeFilter uiNodeFilter = new NodeFilterConverter().convertToUi(actionResponse.get());
+ if (uiConstraint.isLegacyGetFunction()) {
+ mapToLegacyResponse(uiNodeFilter);
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), uiNodeFilter);
} catch (final Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(NODE_FILTER_UPDATE);
LOGGER.error(UPDATE_NODE_FILTER_WITH_AN_ERROR, e);
@@ -254,4 +264,22 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet {
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
+
+ private void mapToLegacyResponse(final UINodeFilter uiNodeFilter) {
+ if (CollectionUtils.isNotEmpty(uiNodeFilter.getProperties())) {
+ uiNodeFilter.setProperties(
+ uiNodeFilter.getProperties().stream()
+ .map(UIConstraintMapper::mapToLegacyConstraint)
+ .collect(Collectors.toList())
+ );
+ }
+ if (CollectionUtils.isNotEmpty(uiNodeFilter.getCapabilities())) {
+ uiNodeFilter.setCapabilities(
+ uiNodeFilter.getCapabilities().stream()
+ .map(UIConstraintMapper::mapToLegacyConstraint)
+ .collect(Collectors.toList())
+ );
+ }
+ }
+
}
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;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/UIConstraintMapper.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/UIConstraintMapper.java
new file mode 100644
index 0000000000..ffe668bb68
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/UIConstraintMapper.java
@@ -0,0 +1,49 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.ui.mapper;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.ui.model.UIConstraint;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class UIConstraintMapper {
+
+ public static UIConstraint mapToLegacyConstraint(final UIConstraint uiConstraint) {
+ final UIConstraint uiConstraint1 = new UIConstraint();
+ uiConstraint1.setCapabilityName(uiConstraint.getCapabilityName());
+ uiConstraint1.setServicePropertyName(uiConstraint.getServicePropertyName());
+ uiConstraint1.setConstraintOperator(uiConstraint.getConstraintOperator());
+ uiConstraint1.setSourceType(FilterValueType.STATIC.getName());
+ uiConstraint1.setSourceName(FilterValueType.STATIC.getName());
+ if (uiConstraint.getValue() instanceof ToscaGetFunctionDataDefinition) {
+ uiConstraint1.setValue(((ToscaGetFunctionDataDefinition) uiConstraint.getValue()).getValue());
+ } else {
+ uiConstraint1.setValue(uiConstraint.getValue());
+ }
+
+ return uiConstraint1;
+ }
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java
index 5618b3d478..401de95e71 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java
@@ -15,11 +15,13 @@
*/
package org.openecomp.sdc.be.ui.model;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
+import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
@Getter
@Setter
@@ -51,4 +53,10 @@ public class UIConstraint implements Serializable {
this.sourceName = sourceName;
this.value = value;
}
+
+ @JsonIgnore
+ public boolean isLegacyGetFunction() {
+ return FilterValueType.GET_INPUT.getLegacyName().equals(sourceType) || FilterValueType.GET_PROPERTY.getLegacyName().equals(sourceType);
+ }
+
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapperTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapperTest.java
index 1ea72937b9..3574c54740 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapperTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/FilterConstraintMapperTest.java
@@ -73,10 +73,10 @@ class FilterConstraintMapperTest {
assertEquals(propertyName, actualUiConstraint.getServicePropertyName());
assertEquals(capabilityName, actualUiConstraint.getCapabilityName());
assertEquals(filterValueType.getName(), actualUiConstraint.getSourceType());
+ assertEquals(filterValueType.getName(), actualUiConstraint.getSourceName());
assertTrue(actualUiConstraint.getValue() instanceof ToscaGetFunctionDataDefinition);
assertEquals(expectedValueToscaFunctionType, ((ToscaGetFunctionDataDefinition) actualUiConstraint.getValue()).getType());
assertEquals(operator.getType(), actualUiConstraint.getConstraintOperator());
- assertNull(actualUiConstraint.getSourceName());
}
@Test