aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java48
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServlet.java59
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServlet.java269
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java18
4 files changed, 335 insertions, 59 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
index 3479c5f700..c94f0d7a7c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
@@ -34,6 +34,8 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
@@ -112,6 +114,7 @@ import org.openecomp.sdc.be.tosca.ToscaError;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.ui.model.UiLeftPaletteComponent;
import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.enums.LogLevel;
import org.openecomp.sdc.common.log.enums.Severity;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -1433,7 +1436,7 @@ public class ComponentsUtils {
}
public ActionStatus convertFromStorageResponseForConsumer(StorageOperationStatus storageResponse) {
- ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+ ActionStatus responseEnum;
switch (storageResponse) {
case OK:
@@ -1724,4 +1727,47 @@ public class ComponentsUtils {
public F<StorageOperationStatus, ResponseFormat> toResponseFormat() {
return sos -> getResponseFormat(convertFromStorageResponse(sos));
}
+
+
+ public Optional<UIConstraint> parseToConstraint(final String componentJson,
+ final User user,
+ final ComponentTypeEnum componentTypeEnum) {
+ final Either<UIConstraint, ResponseFormat> uiConstraintResponseFormatEither =
+ convertJsonToObjectUsingObjectMapper(componentJson, user, UIConstraint.class,
+ AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
+ if (uiConstraintResponseFormatEither.isRight()) {
+ return Optional.empty();
+ }
+ return Optional.of(uiConstraintResponseFormatEither.left().value());
+ }
+
+ private Either<List, ResponseFormat> parseToConstraints(final String componentJson,
+ final User user,
+ final ComponentTypeEnum componentTypeEnum) {
+ return convertJsonToObjectUsingObjectMapper(componentJson, user, List.class, AuditingActionEnum.CREATE_RESOURCE,
+ componentTypeEnum);
+ }
+
+ public List<UIConstraint> validateAndParseConstraint(final ComponentTypeEnum componentTypeEnum,
+ final String constraintData,
+ final User userModifier) {
+
+ final String FAILED_TO_PARSE_CONSTRAINT_DATA = "Failed to Parse Constraint Data {}";
+ final Either<List, ResponseFormat> convertResponse = parseToConstraints(constraintData, userModifier, componentTypeEnum);
+ if (convertResponse.isRight()) {
+ log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData,
+ convertResponse.right().value());
+ return Collections.emptyList();
+ }
+ final List<Map<String, String>> uiConstraintsMaps = (List<Map<String, String>>) convertResponse.left().value();
+ if (uiConstraintsMaps == null) {
+ log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData);
+ return Collections.emptyList();
+ }
+
+ return uiConstraintsMaps.stream().map(dataMap -> new org.codehaus.jackson.map.ObjectMapper()
+ .convertValue(dataMap, UIConstraint.class)).collect(Collectors.toList());
+ }
+
+
}
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 7141379fe3..aa9b931057 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
@@ -19,7 +19,6 @@
package org.openecomp.sdc.be.servlets;
-import fj.data.Either;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
@@ -27,9 +26,7 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
-import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
@@ -44,7 +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.codehaus.jackson.map.ObjectMapper;
+import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
@@ -59,13 +56,11 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.tosca.utils.NodeFilterConverter;
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.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -134,17 +129,13 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet {
final ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
try {
- final Either<UIConstraint, ResponseFormat> convertResponse = parseToConstraint(constraintData, userModifier,
- componentTypeEnum);
- if (convertResponse.isRight()) {
+ final Optional<UIConstraint> convertResponse = componentsUtils
+ .parseToConstraint(constraintData, userModifier, componentTypeEnum);
+ if (!convertResponse.isPresent()) {
LOGGER.error(FAILED_TO_PARSE_COMPONENT);
- return buildErrorResponse(convertResponse.right().value());
- }
- final UIConstraint uiConstraint = convertResponse.left().value();
- if (uiConstraint == null) {
- LOGGER.debug(FAILED_TO_PARSE_COMPONENT);
- return buildErrorResponse(convertResponse.right().value());
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
+ final UIConstraint uiConstraint = convertResponse.get();
final String constraint = new ConstraintConvertor().convert(uiConstraint);
final Optional<CINodeFilterDataDefinition> actionResponse = componentNodeFilterBusinessLogic
@@ -193,25 +184,12 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet {
try {
final ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- final Either<List, ResponseFormat> convertResponse = parseToConstraints(constraintData, userModifier,
- componentTypeEnum);
- if (convertResponse.isRight()) {
- LOGGER.error(FAILED_TO_PARSE_COMPONENT);
- return buildErrorResponse(convertResponse.right().value());
- }
- final List<Map<String, String>> uiConstraintsMaps = (List<Map<String, String>>) convertResponse.left()
- .value();
- if (uiConstraintsMaps == null) {
- LOGGER.debug("failed to parse data");
- return buildErrorResponse(convertResponse.right().value());
- }
- final ObjectMapper objectMapper = new ObjectMapper();
- final List<UIConstraint> uiConstraints = uiConstraintsMaps.stream()
- .map(dataMap -> objectMapper.convertValue(dataMap, UIConstraint.class)).collect(
- Collectors.toList());
- if (uiConstraints == null) {
- LOGGER.debug("failed to parse data");
- return buildErrorResponse(convertResponse.right().value());
+ final List<UIConstraint> uiConstraints = componentsUtils
+ .validateAndParseConstraint(componentTypeEnum, constraintData, userModifier);
+ if (CollectionUtils.isEmpty(uiConstraints)) {
+ LOGGER.error("Failed to Parse Constraint data {} when executing {} ", constraintData, NODE_FILTER_UPDATE);
+ return buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR,
+ "Failed to parse constraint data", constraintData));
}
final List<String> constraints = new ConstraintConvertor().convertToList(uiConstraints);
final Optional<CINodeFilterDataDefinition> actionResponse = componentNodeFilterBusinessLogic
@@ -279,17 +257,4 @@ public class ComponentNodeFilterServlet extends AbstractValidationsServlet {
}
}
- private Either<UIConstraint, ResponseFormat> parseToConstraint(final String componentJson,
- final User user,
- final ComponentTypeEnum componentTypeEnum) {
- return getComponentsUtils().convertJsonToObjectUsingObjectMapper(componentJson, user, UIConstraint.class,
- AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
- }
-
- private Either<List, ResponseFormat> parseToConstraints(final String componentJson,
- final User user,
- final ComponentTypeEnum componentTypeEnum) {
- return getComponentsUtils().convertJsonToObjectUsingObjectMapper(componentJson, user, List.class,
- AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
- }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServlet.java
new file mode 100644
index 0000000000..b451b33fb9
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentSubstitutionFilterServlet.java
@@ -0,0 +1,269 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.servlets;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import java.util.List;
+import java.util.Optional;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+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.collections.CollectionUtils;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentSubstitutionFilterBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.tosca.utils.SubstitutionFilterConverter;
+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;
+import org.slf4j.LoggerFactory;
+
+@Path("/v1/catalog/{componentType}/{componentId}/resourceInstances/{componentInstanceId}/substitutionFilter")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@Singleton
+public class ComponentSubstitutionFilterServlet extends AbstractValidationsServlet {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ComponentSubstitutionFilterServlet.class);
+ private static final String START_HANDLE_REQUEST_OF = "Start handle {} request of {}";
+ private static final String MODIFIER_ID_IS = "Modifier id is {}";
+ private static final String FAILED_TO_PARSE_COMPONENT = "Failed to parse component";
+
+ private static final String FAILED_TO_ADD_SUBSTITUTION_FILTER = "Failed to add substitution filter";
+ private static final String ADD_SUBSTITUTION_FILTER = "Add Substitution Filter";
+ private static final String ADD_SUBSTITUTION_FILTER_WITH_AN_ERROR = "Add substitution filter with an error";
+
+ private static final String FAILED_TO_UPDATE_SUBSTITUTION_FILTER = "Failed to update substitution filter";
+ private static final String SUBSTITUTION_FILTER_UPDATE = "Substitution Filter Update";
+ private static final String UPDATE_SUBSTITUTION_FILTER_WITH_AN_ERROR = "Update substitution filter with an error {}";
+
+ private static final String FAILED_TO_DELETE_SUBSTITUTION_FILTER = "Failed to delete substitution filter";
+ private static final String SUBSTITUTION_FILTER_DELETE = "Substitution Filter Delete";
+ private static final String DELETE_SUBSTITUTION_FILTER_WITH_AN_ERROR = "Delete substitution filter with an error";
+
+ private final ComponentSubstitutionFilterBusinessLogic componentSubstitutionFilterBusinessLogic;
+
+ @Inject
+ public ComponentSubstitutionFilterServlet(final UserBusinessLogic userBusinessLogic,
+ final ComponentInstanceBusinessLogic componentInstanceBL,
+ final ComponentsUtils componentsUtils,
+ final ServletUtils servletUtils,
+ final ResourceImportManager resourceImportManager,
+ final ComponentSubstitutionFilterBusinessLogic componentSubstitutionFilterBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.componentSubstitutionFilterBusinessLogic = componentSubstitutionFilterBusinessLogic;
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/")
+ @Operation(description = "Add Component Substitution Filter Constraint", method = "POST",
+ summary = "Add Component Substitution Filter Constraint", responses = {
+ @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+ @ApiResponse(responseCode = "201", description = "Add Substitution Filter Constraint"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response addSubstitutionFilter(
+ @Parameter(description = "UIConstraint data", required = true) String constraintData,
+ @Parameter(description = "Component Id") @PathParam("componentId") String componentId,
+ @Parameter(description = "Component Instance Id") @PathParam("componentInstanceId") String componentInstanceId,
+ @Parameter(description = "valid value: services",
+ schema = @Schema(allowableValues = {
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("componentType") final String componentType,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ LOGGER.debug(START_HANDLE_REQUEST_OF, request.getMethod(), request.getRequestURI());
+ LOGGER.debug(MODIFIER_ID_IS, userId);
+ final User userModifier = componentSubstitutionFilterBusinessLogic.validateUser(userId);
+
+ final ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ try {
+ final Optional<UIConstraint> convertResponse = componentsUtils
+ .parseToConstraint(constraintData, userModifier, componentTypeEnum);
+ if (!convertResponse.isPresent()) {
+ LOGGER.error(FAILED_TO_PARSE_COMPONENT);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ final Optional<SubstitutionFilterDataDefinition> substitutionFilter =
+ componentSubstitutionFilterBusinessLogic.createSubstitutionFilterIfNotExist(componentId,
+ componentInstanceId, true, componentTypeEnum);
+ if (!substitutionFilter.isPresent()) {
+ LOGGER.error("Failed to create substitution filter.");
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(ADD_SUBSTITUTION_FILTER);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ final UIConstraint uiConstraint = convertResponse.get();
+ final String constraint = new ConstraintConvertor().convert(uiConstraint);
+
+ final Optional<SubstitutionFilterDataDefinition> actionResponse = componentSubstitutionFilterBusinessLogic
+ .addSubstitutionFilter(componentId.toLowerCase(), componentInstanceId, NodeFilterConstraintAction.ADD,
+ uiConstraint.getServicePropertyName(), constraint, true, componentTypeEnum);
+
+ if (!actionResponse.isPresent()) {
+ LOGGER.error(FAILED_TO_ADD_SUBSTITUTION_FILTER);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ final UINodeFilter uiFilter = new SubstitutionFilterConverter().convertToUi(actionResponse.get());
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), uiFilter);
+
+ } catch (final Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(ADD_SUBSTITUTION_FILTER);
+ LOGGER.error(ADD_SUBSTITUTION_FILTER_WITH_AN_ERROR, e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @PUT
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/")
+ @Operation(description = "Update Component Substitution Filter Constraint", method = "PUT",
+ summary = "Update Component Substitution Filter Constraint", responses = {
+ @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+ @ApiResponse(responseCode = "201", description = "Update Substitution Filter Constraint"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateSubstitutionFilter(
+ @Parameter(description = "UIConstraint data", required = true) String constraintData,
+ @Parameter(description = "Component Id") @PathParam("componentId") String componentId,
+ @Parameter(description = "Component Instance Id") @PathParam("componentInstanceId") String componentInstanceId,
+ @Parameter(description = "valid value: services",
+ schema = @Schema(allowableValues = {
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("componentType") final String componentType,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ LOGGER.debug(START_HANDLE_REQUEST_OF, request.getMethod(), request.getRequestURI());
+ LOGGER.debug(MODIFIER_ID_IS, userId);
+ final User userModifier = componentSubstitutionFilterBusinessLogic.validateUser(userId);
+
+ try {
+ final ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ final List<UIConstraint> uiConstraints = componentsUtils
+ .validateAndParseConstraint(componentTypeEnum, constraintData, userModifier);
+ if (CollectionUtils.isEmpty(uiConstraints)) {
+ LOGGER.error("Failed to Parse Constraint data {} when executing {} ",
+ constraintData, SUBSTITUTION_FILTER_UPDATE);
+ return buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR,
+ "Failed to parse constraint data"));
+ }
+
+ final List<String> constraints = new ConstraintConvertor().convertToList(uiConstraints);
+ final Optional<SubstitutionFilterDataDefinition> actionResponse = componentSubstitutionFilterBusinessLogic
+ .updateSubstitutionFilter(componentId.toLowerCase(), componentInstanceId, constraints,
+ true, componentTypeEnum);
+
+ if (!actionResponse.isPresent()) {
+ LOGGER.error(FAILED_TO_UPDATE_SUBSTITUTION_FILTER);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ new SubstitutionFilterConverter().convertToUi(actionResponse.get()));
+
+ } catch (final Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(SUBSTITUTION_FILTER_UPDATE);
+ LOGGER.error(UPDATE_SUBSTITUTION_FILTER_WITH_AN_ERROR, e.getMessage(), e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/{constraintIndex}")
+ @Operation(description = "Delete Component Substitution Filter Constraint", method = "Delete",
+ summary = "Delete Component Substitution Filter Constraint", responses = {
+ @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+ @ApiResponse(responseCode = "201", description = "Delete Substitution Filter Constraint"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteSubstitutionFilterConstraint(
+ @Parameter(description = "Component Id") @PathParam("componentId") String componentId,
+ @Parameter(description = "Component Instance Id") @PathParam("componentInstanceId") String componentInstanceId,
+ @Parameter(description = "Constraint Index") @PathParam("constraintIndex") int index,
+ @Parameter(description = "valid value: services",
+ schema = @Schema(allowableValues = {
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("componentType") final String componentType,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ LOGGER.debug(START_HANDLE_REQUEST_OF, request.getMethod(), request.getRequestURI());
+ LOGGER.debug(MODIFIER_ID_IS, userId);
+ componentSubstitutionFilterBusinessLogic.validateUser(userId);
+
+ try {
+ final Optional<SubstitutionFilterDataDefinition> actionResponse = componentSubstitutionFilterBusinessLogic
+ .deleteSubstitutionFilter(componentId.toLowerCase(), componentInstanceId,
+ NodeFilterConstraintAction.DELETE,
+ null, index, true, ComponentTypeEnum.findByParamName(componentType));
+
+ if (!actionResponse.isPresent()) {
+ LOGGER.debug(FAILED_TO_DELETE_SUBSTITUTION_FILTER);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ new SubstitutionFilterConverter().convertToUi(actionResponse.get()));
+
+ } catch (final Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(SUBSTITUTION_FILTER_DELETE);
+ LOGGER.debug(DELETE_SUBSTITUTION_FILTER_WITH_AN_ERROR, e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
index dcd8a3b9c5..08890ef3e7 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java
@@ -159,9 +159,9 @@ public class ComponentNodeFilterServletTest extends JerseyTest {
assertThat(sourceType).isEqualToIgnoringCase(uiConstraint.getSourceType());
assertThat(sourceName).isEqualToIgnoringCase(uiConstraint.getSourceName());
assertThat(propertyValue).isEqualToIgnoringCase(uiConstraint.getValue().toString());
- when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class),
- ArgumentMatchers.<Class<UIConstraint>>any(),
- nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class))).thenReturn(Either.left(uiConstraint));
+
+ when(componentsUtils.parseToConstraint(anyString(), any(User.class),ArgumentMatchers.any(ComponentTypeEnum.class)))
+ .thenReturn(Optional.of(uiConstraint));
assertNotNull(constraint);
assertNotNull(ciNodeFilterDataDefinition);
@@ -314,10 +314,8 @@ public class ComponentNodeFilterServletTest extends JerseyTest {
when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
- when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class),
- ArgumentMatchers.<Class<List>>any(),
- nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class)))
- .thenReturn(Either.left(Arrays.asList(new ObjectMapper().convertValue(uiConstraint, Map.class))));
+ when(componentsUtils.validateAndParseConstraint(ArgumentMatchers.any(ComponentTypeEnum.class), anyString(), any(User.class)))
+ .thenReturn(Collections.singletonList(uiConstraint));
when(componentNodeFilterBusinessLogic
.updateNodeFilter(componentId, componentInstance, Collections.singletonList(constraint),
@@ -347,10 +345,8 @@ public class ComponentNodeFilterServletTest extends JerseyTest {
when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
- when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class),
- ArgumentMatchers.<Class<List>>any(),
- nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class)))
- .thenReturn(Either.right(new ResponseFormat(HttpStatus.INTERNAL_SERVER_ERROR_500)));
+ when(componentsUtils.validateAndParseConstraint(ArgumentMatchers.any(ComponentTypeEnum.class), anyString(), any(User.class)))
+ .thenReturn(Collections.emptyList());
final Response response = target()
.path(path)