diff --git a/src/main/java/it/gov/pagopa/wispconverter/controller/RecoveryController.java b/src/main/java/it/gov/pagopa/wispconverter/controller/RecoveryController.java index 04898ae9..695c776b 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/controller/RecoveryController.java +++ b/src/main/java/it/gov/pagopa/wispconverter/controller/RecoveryController.java @@ -132,12 +132,12 @@ public ResponseEntity recoverReceiptToBeReSentByP } } - @Operation(summary = "Execute reconciliation for OK receipts by sessionId.", description = "Execute reconciliation of all receipts related to the sessionIds of the request", security = {@SecurityRequirement(name = "ApiKey")}, tags = {"Recovery"}) + @Operation(summary = "Execute reconciliation for OK receipts by sessionId.", description = "Execute reconciliation of all OK receipts related to the sessionIds of the request", security = {@SecurityRequirement(name = "ApiKey")}, tags = {"Recovery"}) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Reconciliation scheduled") }) @PostMapping(value = "/sessionIds/ok") - public ResponseEntity recoverReceiptToBeReSentBySessionId(@RequestBody RecoveryReceiptBySessionIdRequest request) { + public ResponseEntity recoverOkReceiptToBeReSentBySessionId(@RequestBody RecoveryReceiptBySessionIdRequest request) { try { log.debug("Invoking API operation recoverReceiptToBeReSentBySessionId - args: {}", sanitizeInput(request.toString())); return ResponseEntity.ok(recoveryService.recoverReceiptOkToBeReSentBySessionIds(request)); @@ -150,4 +150,23 @@ public ResponseEntity recoverReceiptToBeReSentByS throw ex; } } + + @Operation(summary = "Execute reconciliation for KO receipts by sessionId.", description = "Execute reconciliation of all KO receipts related to the sessionIds of the request", security = {@SecurityRequirement(name = "ApiKey")}, tags = {"Recovery"}) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Reconciliation scheduled") + }) + @PostMapping(value = "/sessionIds/ko") + public ResponseEntity recoverKoReceiptToBeReSentBySessionId(@RequestBody RecoveryReceiptBySessionIdRequest request) { + try { + log.debug("Invoking API operation recoverReceiptToBeReSentBySessionId - args: {}", sanitizeInput(request.toString())); + return ResponseEntity.ok(recoveryService.recoverReceiptKoToBeReSentBySessionIds(request)); + } catch (Exception ex) { + String operationId = MDC.get(Constants.MDC_OPERATION_ID); + log.error(String.format("GenericException: operation-id=[%s]", operationId != null ? operationId : "n/a"), ex); + AppException appException = new AppException(ex, AppErrorCodeMessageEnum.ERROR, ex.getMessage()); + ErrorResponse errorResponse = errorUtil.forAppException(appException); + log.error("Failed API operation recoverReceiptToBeReSentBySessionId - error: {}", errorResponse); + throw ex; + } + } } diff --git a/src/main/java/it/gov/pagopa/wispconverter/repository/model/enumz/InternalStepStatus.java b/src/main/java/it/gov/pagopa/wispconverter/repository/model/enumz/InternalStepStatus.java index 3338a15c..b34f3f4d 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/repository/model/enumz/InternalStepStatus.java +++ b/src/main/java/it/gov/pagopa/wispconverter/repository/model/enumz/InternalStepStatus.java @@ -30,6 +30,7 @@ public enum InternalStepStatus { RT_SEND_RESCHEDULING_FAILURE, RT_SEND_RESCHEDULING_REACHED_MAX_RETRIES, RT_SEND_RESCHEDULING_SUCCESS, + RT_RECONCILIATION_PROCESS, RT_START_RECONCILIATION_PROCESS, RT_END_RECONCILIATION_PROCESS, RT_DEAD_LETTER_SAVED, diff --git a/src/main/java/it/gov/pagopa/wispconverter/service/RecoveryService.java b/src/main/java/it/gov/pagopa/wispconverter/service/RecoveryService.java index 3940cf23..313cf174 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/service/RecoveryService.java +++ b/src/main/java/it/gov/pagopa/wispconverter/service/RecoveryService.java @@ -313,6 +313,24 @@ public RecoveryReceiptReportResponse recoverReceiptOkToBeReSentBySessionIds(Reco } } + @Transactional + public RecoveryReceiptReportResponse recoverReceiptKoToBeReSentBySessionIds(RecoveryReceiptBySessionIdRequest request) { + List> receiptStatus = new ArrayList<>(); + try { + for (String sessionId : request.getSessionIds()) { + receiptService.sendRTKoFromSessionId(sessionId, InternalStepStatus.RT_RECONCILIATION_PROCESS); + receiptStatus.add(Pair.of(sessionId, "SCHEDULED")); + } + + return RecoveryReceiptReportResponse.builder() + .receiptStatus(receiptStatus) + .build(); + } + catch (Exception e) { + throw new AppException(AppErrorCodeMessageEnum.ERROR, "Problem with KO receipt"); + } + } + public RecoveryReceiptReportResponse recoverReceiptToBeReSentByPartition(RecoveryReceiptByPartitionRequest request) { List receiptsIds = request.getPartitionKeys().stream()