Add PUT API for OrchestrationTask

Issue-ID: SO-2368

Add method for update a OrchestrationTask

Change-Id: I96cc8354d070ec64e61ca6aa23129ef6f9880e7a
Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java
index fc57696..4a591db 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java
@@ -138,4 +138,39 @@
         }
     }
 
+    @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;
+        }
+    }
+
 }