Add PUT API for OrchestrationTask
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / onap / so / apihandlerinfra / OrchestrationTasks.java
index fc57696..4a591db 100644 (file)
@@ -138,4 +138,39 @@ public class OrchestrationTasks {
         }
     }
 
+    @PUT
+    @Path("/{version:[vV][4-7]}/{taskId}")
+    @Operation(description = "Update an Orchestrated Task", responses = @ApiResponse(
+            content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+    @Produces(MediaType.APPLICATION_JSON)
+    @Transactional
+    public Response UpdateOrchestrationTask(@PathParam("taskId") String taskId, String requestJson,
+            @PathParam("version") String version) {
+        try {
+            OrchestrationTask orchestrationTask = requestsDbClient.getOrchestrationTask(taskId);
+        } catch (Exception e) {
+            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA,
+                    ErrorCode.AvailabilityError.getValue(),
+                    "Exception while communciate with Request DB - Orchestration Task Update", e);
+            Response response =
+                    msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,
+                            e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version);
+            return response;
+        }
+
+        try {
+            OrchestrationTask orchestrationTask = mapper.readValue(requestJson, OrchestrationTask.class);
+            requestsDbClient.updateOrchestrationTask(taskId, orchestrationTask);
+            return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationTask, version);
+        } catch (Exception e) {
+            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA,
+                    ErrorCode.AvailabilityError.getValue(),
+                    "Exception while communciate with Request DB - Orchestration Task Update", e);
+            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR,
+                    MsoException.ServiceException, e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null,
+                    version);
+            return response;
+        }
+    }
+
 }