diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceipt.java index 36fa381..4ba230d 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceipt.java @@ -1,10 +1,6 @@ package it.gov.pagopa.receipt.pdf.helpdesk; -import com.microsoft.azure.functions.ExecutionContext; -import com.microsoft.azure.functions.HttpMethod; -import com.microsoft.azure.functions.HttpRequestMessage; -import com.microsoft.azure.functions.HttpResponseMessage; -import com.microsoft.azure.functions.HttpStatus; +import com.microsoft.azure.functions.*; import com.microsoft.azure.functions.annotation.AuthorizationLevel; import com.microsoft.azure.functions.annotation.BindingName; import com.microsoft.azure.functions.annotation.FunctionName; @@ -58,7 +54,7 @@ public HttpResponseMessage run( if (eventId == null || eventId.isBlank()) { return request - .createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + .createResponseBuilder(HttpStatus.BAD_REQUEST) .body(ProblemJson.builder() .title(HttpStatus.BAD_REQUEST.name()) .detail("Please pass a valid biz-event id") @@ -76,7 +72,14 @@ public HttpResponseMessage run( } catch (ReceiptNotFoundException e) { String responseMsg = String.format("Unable to retrieve the receipt with eventId %s", eventId); logger.error("[{}] {}", context.getFunctionName(), responseMsg, e); - return request.createResponseBuilder(HttpStatus.NOT_FOUND).body(responseMsg).build(); + return request + .createResponseBuilder(HttpStatus.NOT_FOUND) + .body(ProblemJson.builder() + .title(HttpStatus.NOT_FOUND.name()) + .detail(responseMsg) + .status(HttpStatus.NOT_FOUND.value()) + .build()) + .build(); } } } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptByOrganizationFiscalCodeAndIUV.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptByOrganizationFiscalCodeAndIUV.java index 7ae965c..b9878c0 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptByOrganizationFiscalCodeAndIUV.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptByOrganizationFiscalCodeAndIUV.java @@ -70,7 +70,7 @@ public HttpResponseMessage run( || iuv.isBlank() ) { return request - .createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + .createResponseBuilder(HttpStatus.BAD_REQUEST) .body(ProblemJson.builder() .title(HttpStatus.BAD_REQUEST.name()) .detail("Please pass a valid organization fiscal code and iuv") @@ -87,7 +87,14 @@ public HttpResponseMessage run( String responseMsg = String.format("Unable to retrieve the biz-event with organization fiscal code %s and iuv %s", organizationFiscalCode, iuv); logger.error("[{}] {}", context.getFunctionName(), responseMsg, e); - return request.createResponseBuilder(HttpStatus.NOT_FOUND).body(responseMsg).build(); + return request + .createResponseBuilder(HttpStatus.NOT_FOUND) + .body(ProblemJson.builder() + .title(HttpStatus.NOT_FOUND.name()) + .detail(responseMsg) + .status(HttpStatus.NOT_FOUND.value()) + .build()) + .build(); } try { @@ -99,7 +106,14 @@ public HttpResponseMessage run( } catch (ReceiptNotFoundException e) { String responseMsg = String.format("Unable to retrieve the receipt with eventId %s", bizEvent.getId()); logger.error("[{}] {}", context.getFunctionName(), responseMsg, e); - return request.createResponseBuilder(HttpStatus.NOT_FOUND).body(responseMsg).build(); + return request + .createResponseBuilder(HttpStatus.NOT_FOUND) + .body(ProblemJson.builder() + .title(HttpStatus.NOT_FOUND.name()) + .detail(responseMsg) + .status(HttpStatus.NOT_FOUND.value()) + .build()) + .build(); } } } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptError.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptError.java index af2a412..8d3d2f8 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptError.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptError.java @@ -7,7 +7,6 @@ import com.microsoft.azure.functions.annotation.HttpTrigger; import it.gov.pagopa.receipt.pdf.helpdesk.client.ReceiptCosmosClient; import it.gov.pagopa.receipt.pdf.helpdesk.client.impl.ReceiptCosmosClientImpl; -import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.ReceiptError; import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.model.ProblemJson; @@ -58,7 +57,8 @@ public HttpResponseMessage run ( .body(receiptError) .build(); } catch (ReceiptNotFoundException e) { - return request.createResponseBuilder(HttpStatus.OK) + return request + .createResponseBuilder(HttpStatus.OK) .body(ProblemJson.builder() .title(HttpStatus.NOT_FOUND.name()) .detail("No Receipt Error to process on bizEvent with id " + eventId) @@ -76,7 +76,7 @@ public HttpResponseMessage run ( } } - return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + return request.createResponseBuilder(HttpStatus.BAD_REQUEST) .body(ProblemJson.builder() .title(HttpStatus.BAD_REQUEST.name()) .detail("Missing valid search parameter") diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptPdf.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptPdf.java index ea29314..40bef35 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptPdf.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptPdf.java @@ -70,21 +70,24 @@ public HttpResponseMessage run( try { File pdfFile = this.receiptBlobClient.getAttachmentFromBlobStorage(fileName); FileInputStream inputStream = new FileInputStream(pdfFile); - byte [] result = IOUtils.toByteArray(inputStream); + byte[] result = IOUtils.toByteArray(inputStream); Files.deleteIfExists(pdfFile.toPath()); return request .createResponseBuilder(HttpStatus.OK) .body(result) .build(); + } catch (BlobStorageClientException | IOException e) { String responseMsg = String.format("Unable to retrieve the receipt pdf with file name %s", fileName); logger.error("[{}] {}", context.getFunctionName(), responseMsg, e); - return request.createResponseBuilder(HttpStatus.NOT_FOUND) + return request + .createResponseBuilder(HttpStatus.NOT_FOUND) .body(ProblemJson.builder() - .title(HttpStatus.NOT_FOUND.name()) - .detail(responseMsg) - .status(HttpStatus.NOT_FOUND.value()) - .build()).build(); + .title(HttpStatus.NOT_FOUND.name()) + .detail(responseMsg) + .status(HttpStatus.NOT_FOUND.value()) + .build()) + .build(); } } } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedReceipt.java index fe4bb63..5d9db64 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedReceipt.java @@ -78,7 +78,7 @@ public HttpResponseMessage run ( if (eventId == null || eventId.isBlank()) { return request - .createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + .createResponseBuilder(HttpStatus.BAD_REQUEST) .body(ProblemJson.builder() .title(HttpStatus.BAD_REQUEST.name()) .detail("Please pass a valid biz-event id") @@ -102,7 +102,11 @@ public HttpResponseMessage run ( logger.error(msg, exception); return request .createResponseBuilder(HttpStatus.NOT_FOUND) - .body(msg) + .body(ProblemJson.builder() + .title(HttpStatus.NOT_FOUND.name()) + .detail(msg) + .status(HttpStatus.NOT_FOUND.value()) + .build()) .build(); } catch (PDVTokenizerException | JsonProcessingException e) { logger.error(e.getMessage(), e); diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedReceiptMassive.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedReceiptMassive.java index 2f1577d..7f5f2c9 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedReceiptMassive.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedReceiptMassive.java @@ -81,7 +81,7 @@ public HttpResponseMessage run ( String status = request.getQueryParameters().get("status"); if (status == null) { return request - .createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + .createResponseBuilder(HttpStatus.BAD_REQUEST) .body(ProblemJson.builder() .title(HttpStatus.BAD_REQUEST.name()) .detail("Please pass a status to recover") @@ -95,7 +95,7 @@ public HttpResponseMessage run ( statusType = ReceiptStatusType.valueOf(status); } catch (IllegalArgumentException e) { return request - .createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + .createResponseBuilder(HttpStatus.BAD_REQUEST) .body(ProblemJson.builder() .title(HttpStatus.BAD_REQUEST.name()) .detail("Please pass a valid status to recover") diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceipt.java index ba95681..0b138c2 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceipt.java @@ -74,7 +74,7 @@ public HttpResponseMessage run( if (eventId == null || eventId.isBlank()) { return request - .createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + .createResponseBuilder(HttpStatus.BAD_REQUEST) .body(ProblemJson.builder() .title(HttpStatus.BAD_REQUEST.name()) .detail("Please pass a valid biz-event id") @@ -89,7 +89,14 @@ public HttpResponseMessage run( } catch (ReceiptNotFoundException e) { String responseMsg = String.format("Unable to retrieve the receipt with eventId %s", eventId); logger.error("[{}] {}", context.getFunctionName(), responseMsg, e); - return request.createResponseBuilder(HttpStatus.NOT_FOUND).body(responseMsg).build(); + return request + .createResponseBuilder(HttpStatus.NOT_FOUND) + .body(ProblemJson.builder() + .title(HttpStatus.NOT_FOUND.name()) + .detail(responseMsg) + .status(HttpStatus.NOT_FOUND.value()) + .build()) + .build(); } if (!receipt.getStatus().equals(ReceiptStatusType.IO_ERROR_TO_NOTIFY) && !receipt.getStatus().equals(ReceiptStatusType.GENERATED)) { diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptMassive.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptMassive.java index 29148ed..9a6ba36 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptMassive.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptMassive.java @@ -74,7 +74,7 @@ public HttpResponseMessage run( String status = request.getQueryParameters().get("status"); if (status == null) { return request - .createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + .createResponseBuilder(HttpStatus.BAD_REQUEST) .body(ProblemJson.builder() .title(HttpStatus.BAD_REQUEST.name()) .detail("Please pass a status to recover") @@ -88,7 +88,7 @@ public HttpResponseMessage run( statusType = ReceiptStatusType.valueOf(status); } catch (IllegalArgumentException e) { return request - .createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + .createResponseBuilder(HttpStatus.BAD_REQUEST) .body(ProblemJson.builder() .title(HttpStatus.BAD_REQUEST.name()) .detail("Please pass a valid status to recover") diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RegenerateReceiptPdf.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RegenerateReceiptPdf.java index 222e20f..a2d68f4 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RegenerateReceiptPdf.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RegenerateReceiptPdf.java @@ -126,7 +126,7 @@ public HttpResponseMessage run ( } - return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + return request.createResponseBuilder(HttpStatus.BAD_REQUEST) .body(ProblemJson.builder() .title(HttpStatus.BAD_REQUEST.name()) .detail("Missing valid eventId paramater") @@ -143,7 +143,7 @@ public HttpResponseMessage run ( message = "BizEvent not found with event-id " + eventId; } return request - .createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + .createResponseBuilder(HttpStatus.BAD_REQUEST) .body(ProblemJson.builder() .title(HttpStatus.BAD_REQUEST.name()) .detail(message)