aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInterfaceOperationServlet.java
diff options
context:
space:
mode:
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.java61
1 files changed, 57 insertions, 4 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 83ee15240f..3b8bfe5bd7 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
@@ -36,6 +36,7 @@ import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
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;
@@ -138,9 +139,8 @@ 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);
if (actionResponse.isEmpty()) {
LOGGER.error(FAILED_TO_UPDATE_INTERFACE_OPERATION, componentInstanceId);
return buildErrorResponse(errorWrapper.getInnerElement());
@@ -186,7 +186,60 @@ public class ComponentInterfaceOperationServlet extends AbstractValidationsServl
final Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
try {
final Optional<Component> actionResponse = componentInterfaceOperationBusinessLogic
- .updateResourceInterfaceOperation(componentId, mappedInterfaceOperationData.get(), componentTypeEnum, errorWrapper, true);
+ .updateResourceInterfaceOperation(componentId, mappedInterfaceOperationData.get(), componentTypeEnum,
+ errorWrapper, true);
+ if (actionResponse.isEmpty()) {
+ LOGGER.error(FAILED_TO_UPDATE_INTERFACE_OPERATION, componentId);
+ return buildErrorResponse(errorWrapper.getInnerElement());
+ } else {
+ LOGGER.debug(INTERFACE_OPERATION_SUCCESSFULLY_UPDATED, componentId);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.get());
+ }
+ } catch (final Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_INTERFACE_OPERATION);
+ LOGGER.error(FAILED_TO_UPDATE_INTERFACE_OPERATION_WITH_ERROR, e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Path("/{componentType}/{componentId}/resource/interfaceOperation")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Interface Operation", method = "POST", summary = "Create Interface Operation on ComponentInstance", responses = {
+ @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+ @ApiResponse(responseCode = "201", description = "Create Interface Operation"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createInterfaceOperationInResource(
+ @Parameter(description = "valid values: resources", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME}))
+ @PathParam("componentType") final String componentType,
+ @Parameter(description = "Component Id") @PathParam("componentId") String componentId,
+ @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);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ final Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ try {
+ final Optional<Component> actionResponse = componentInterfaceOperationBusinessLogic.createInterfaceOperationInResource(
+ componentId, mappedInterfaceOperationData.get(), componentTypeEnum, errorWrapper, true);
if (actionResponse.isEmpty()) {
LOGGER.error(FAILED_TO_UPDATE_INTERFACE_OPERATION, componentId);
return buildErrorResponse(errorWrapper.getInnerElement());