diff options
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java | 61 |
1 files changed, 18 insertions, 43 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java index c2e668c049..4d94ffc8d7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java @@ -18,7 +18,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.servlets; import fj.data.Either; @@ -74,24 +73,17 @@ public class ComponentInterfaceOperationServlet extends AbstractValidationsServl private static final Logger LOGGER = LoggerFactory.getLogger(ComponentInterfaceOperationServlet.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_UPDATE_INTERFACE_OPERATION = - "failed to update Interface Operation on component instance {}"; + private static final String FAILED_TO_UPDATE_INTERFACE_OPERATION = "failed to update Interface Operation on component instance {}"; private static final String UPDATE_INTERFACE_OPERATION = "Update Interface Operation on Component Instance"; - private static final String FAILED_TO_UPDATE_INTERFACE_OPERATION_WITH_ERROR = - "Failed to update Interface Operation with an error"; + private static final String FAILED_TO_UPDATE_INTERFACE_OPERATION_WITH_ERROR = "Failed to update Interface Operation with an error"; private static final String INTERFACE_OPERATION_CONTENT_INVALID = "Interface Operation content is invalid - {}"; private static final String UNSUPPORTED_COMPONENT_TYPE = "Unsupported component type {}"; - private static final String INTERFACE_OPERATION_SUCCESSFULLY_UPDATED = - "Interface Operation successfully updated on component instance with id {}"; - + private static final String INTERFACE_OPERATION_SUCCESSFULLY_UPDATED = "Interface Operation successfully updated on component instance with id {}"; private final ComponentInterfaceOperationBusinessLogic componentInterfaceOperationBusinessLogic; @Autowired - public ComponentInterfaceOperationServlet(final UserBusinessLogic userBusinessLogic, - final ComponentInstanceBusinessLogic componentInstanceBL, - final ComponentsUtils componentsUtils, - final ServletUtils servletUtils, + public ComponentInterfaceOperationServlet(final UserBusinessLogic userBusinessLogic, final ComponentInstanceBusinessLogic componentInstanceBL, + final ComponentsUtils componentsUtils, final ServletUtils servletUtils, final ResourceImportManager resourceImportManager, final ComponentInterfaceOperationBusinessLogic componentInterfaceOperationBusinessLogic) { super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); @@ -101,43 +93,32 @@ public class ComponentInterfaceOperationServlet extends AbstractValidationsServl @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "Update Interface Operation", method = "PUT", - summary = "Update Interface Operation on ComponentInstance", responses = { + @Operation(description = "Update Interface Operation", method = "PUT", summary = "Update Interface Operation on ComponentInstance", responses = { @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))), @ApiResponse(responseCode = "201", description = "Update Interface Operation"), @ApiResponse(responseCode = "403", description = "Restricted operation"), @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response updateComponentInstanceInterfaceOperation( - @Parameter(description = "valid values: resources / services", - schema = @Schema(allowableValues = { - ComponentTypeEnum.RESOURCE_PARAM_NAME, - ComponentTypeEnum.SERVICE_PARAM_NAME})) - @PathParam("componentType") final String componentType, - @Parameter(description = "Component Id") - @PathParam("componentId") String componentId, - @Parameter(description = "Component Instance Id") - @PathParam("componentInstanceId") String componentInstanceId, - @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) - throws IOException { - + @Parameter(description = "valid values: resources / services", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME, + ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("componentType") final String componentType, + @Parameter(description = "Component Id") @PathParam("componentId") String componentId, + @Parameter(description = "Component Instance Id") @PathParam("componentInstanceId") String componentInstanceId, + @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException { LOGGER.debug(START_HANDLE_REQUEST_OF, request.getMethod(), request.getRequestURI()); LOGGER.debug(MODIFIER_ID_IS, userId); - final User userModifier = componentInterfaceOperationBusinessLogic.validateUser(userId); final ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType); if (componentTypeEnum == null) { LOGGER.debug(UNSUPPORTED_COMPONENT_TYPE, componentType); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, componentType)); } - final byte[] bytes = IOUtils.toByteArray(request.getInputStream()); if (bytes == null || bytes.length == 0) { LOGGER.error(INTERFACE_OPERATION_CONTENT_INVALID); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)); } final String data = new String(bytes); - final Optional<InterfaceDefinition> mappedInterfaceOperationData = getMappedInterfaceData(data, userModifier, componentTypeEnum); if (mappedInterfaceOperationData.isEmpty()) { LOGGER.error(INTERFACE_OPERATION_CONTENT_INVALID, data); @@ -145,10 +126,9 @@ public class ComponentInterfaceOperationServlet extends AbstractValidationsServl } final Wrapper<ResponseFormat> errorWrapper = new Wrapper<>(); try { - final Optional<ComponentInstance> actionResponse = componentInterfaceOperationBusinessLogic - .updateComponentInstanceInterfaceOperation(componentId, componentInstanceId, mappedInterfaceOperationData.get(), - componentTypeEnum, errorWrapper, true); - + final Optional<ComponentInstance> actionResponse = componentInterfaceOperationBusinessLogic + .updateComponentInstanceInterfaceOperation(componentId, componentInstanceId, mappedInterfaceOperationData.get(), componentTypeEnum, + errorWrapper, true); final Response response; if (actionResponse.isEmpty()) { LOGGER.error(FAILED_TO_UPDATE_INTERFACE_OPERATION, componentInstanceId); @@ -157,9 +137,7 @@ public class ComponentInterfaceOperationServlet extends AbstractValidationsServl LOGGER.debug(INTERFACE_OPERATION_SUCCESSFULLY_UPDATED, componentInstanceId); response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.get()); } - return response; - } catch (final Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_INTERFACE_OPERATION); LOGGER.error(FAILED_TO_UPDATE_INTERFACE_OPERATION_WITH_ERROR, e); @@ -167,13 +145,10 @@ public class ComponentInterfaceOperationServlet extends AbstractValidationsServl } } - private Optional<InterfaceDefinition> getMappedInterfaceData(final String inputJson, - final User user, - final ComponentTypeEnum componentTypeEnum) { - final Either<UiComponentDataTransfer, ResponseFormat> uiComponentEither = - getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user, - UiComponentDataTransfer.class, AuditingActionEnum.UPDATE_RESOURCE_METADATA, componentTypeEnum); + private Optional<InterfaceDefinition> getMappedInterfaceData(final String inputJson, final User user, final ComponentTypeEnum componentTypeEnum) { + final Either<UiComponentDataTransfer, ResponseFormat> uiComponentEither = getComponentsUtils() + .convertJsonToObjectUsingObjectMapper(inputJson, user, UiComponentDataTransfer.class, AuditingActionEnum.UPDATE_RESOURCE_METADATA, + componentTypeEnum); return uiComponentEither.left().value().getInterfaces().values().stream().findFirst(); } - } |