diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/config/ContentNegotiationConf.java b/src/main/java/it/gov/pagopa/bizeventsservice/config/ContentNegotiationConf.java
new file mode 100644
index 00000000..5a4296dd
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/bizeventsservice/config/ContentNegotiationConf.java
@@ -0,0 +1,25 @@
+package it.gov.pagopa.bizeventsservice.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.MediaType;
+import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * This configuration is required ignore the 'accept' header in the request.
+ * If the client uses a different value of the response then SpringBoot goes wrong because the response type doesn't match.
+ * We can ignore the accept header from the client.
+ *
+ * see more information in this GitHub issue
+ */
+// TODO should I remove this configuration?
+@Configuration
+public class ContentNegotiationConf implements WebMvcConfigurer {
+
+ @Override
+ public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
+ configurer
+ .ignoreAcceptHeader(true)
+ .defaultContentType(MediaType.ALL);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/controller/IPaidNoticeController.java b/src/main/java/it/gov/pagopa/bizeventsservice/controller/IPaidNoticeController.java
index a515b865..9de922c0 100644
--- a/src/main/java/it/gov/pagopa/bizeventsservice/controller/IPaidNoticeController.java
+++ b/src/main/java/it/gov/pagopa/bizeventsservice/controller/IPaidNoticeController.java
@@ -2,6 +2,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -9,10 +10,12 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.bizeventsservice.model.ProblemJson;
+import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
+import org.springframework.core.io.Resource;
import javax.validation.constraints.NotBlank;
@@ -37,5 +40,20 @@ ResponseEntity disablePaidNotice(
@RequestHeader(X_FISCAL_CODE) @NotBlank String fiscalCode,
@Parameter(description = "The id of the paid event.", required = true) @NotBlank @PathVariable("event-id") String eventId);
+ @Operation(summary = "Retrieve the PDF receipt given event id.", security = {
+ @SecurityRequirement(name = "ApiKey")}, operationId = "generatePDF")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Obtained the PDF receipt.",
+ headers = {@Header(name = HttpHeaders.CONTENT_DISPOSITION, description = "Content disposition with name of the file", schema = @Schema(type = "string"))},
+ content = {@Content(mediaType = MediaType.APPLICATION_PDF_VALUE, schema = @Schema(implementation = Resource.class)),}),
+ @ApiResponse(responseCode = "401", description = "Wrong or missing function key.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)),
+ @ApiResponse(responseCode = "404", description = "Not found the receipt.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
+ @ApiResponse(responseCode = "422", description = "Unprocessable receipt.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class))),
+ @ApiResponse(responseCode = "429", description = "Too many requests.", content = @Content(schema = @Schema())),
+ @ApiResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))})
+ @GetMapping(value = "/{event-id}/pdf", produces = {MediaType.APPLICATION_PDF_VALUE, MediaType.APPLICATION_JSON_VALUE})
+ ResponseEntity generatePDF(
+ @RequestHeader(X_FISCAL_CODE) @NotBlank String fiscalCode,
+ @Parameter(description = "The id of the paid event.", required = true) @NotBlank @PathVariable("event-id") String eventId);
}
diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/controller/ITransactionController.java b/src/main/java/it/gov/pagopa/bizeventsservice/controller/ITransactionController.java
index 0b73c1e1..539034e5 100644
--- a/src/main/java/it/gov/pagopa/bizeventsservice/controller/ITransactionController.java
+++ b/src/main/java/it/gov/pagopa/bizeventsservice/controller/ITransactionController.java
@@ -138,7 +138,8 @@ ResponseEntity disableTransaction(
@RequestHeader("x-fiscal-code") @NotBlank String fiscalCode,
@Parameter(description = "The id of the transaction.", required = true) @NotBlank @PathVariable("transaction-id") String transactionId);
- @Operation(summary = "Retrieve the PDF receipt given event id.", security = {
+ @Operation(summary = "Retrieve the PDF receipt given event id.", deprecated = true,
+ description = "This operation is deprecated. Use Paid Notice APIs instead", security = {
@SecurityRequirement(name = "ApiKey")}, operationId = "getPDFReceipt")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Obtained the PDF receipt.", content = @Content(mediaType = MediaType.APPLICATION_PDF_VALUE, schema = @Schema(type = "string", format = "binary"))),
@@ -148,6 +149,7 @@ ResponseEntity disableTransaction(
@ApiResponse(responseCode = "429", description = "Too many requests.", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))})
@GetMapping(value = "/{event-id}/pdf")
+ @Deprecated(forRemoval = false)
ResponseEntity getPDFReceipt(
@RequestHeader("x-fiscal-code") @NotBlank String fiscalCode,
@Parameter(description = "The id of the event.", required = true) @NotBlank @PathVariable("event-id") String eventId);
diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/controller/impl/PaidNoticeController.java b/src/main/java/it/gov/pagopa/bizeventsservice/controller/impl/PaidNoticeController.java
index beb5cb5a..2d2809a7 100644
--- a/src/main/java/it/gov/pagopa/bizeventsservice/controller/impl/PaidNoticeController.java
+++ b/src/main/java/it/gov/pagopa/bizeventsservice/controller/impl/PaidNoticeController.java
@@ -1,12 +1,17 @@
package it.gov.pagopa.bizeventsservice.controller.impl;
import it.gov.pagopa.bizeventsservice.controller.IPaidNoticeController;
+import it.gov.pagopa.bizeventsservice.service.IBizEventsService;
import it.gov.pagopa.bizeventsservice.service.ITransactionService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.Resource;
+import org.springframework.http.*;
import org.springframework.web.bind.annotation.RestController;
+import javax.validation.constraints.NotBlank;
+import java.io.ByteArrayInputStream;
+
/**
* Implementation of {@link IPaidNoticeController} that contains the Rest Controller
* for events services
@@ -15,10 +20,12 @@
public class PaidNoticeController implements IPaidNoticeController {
private final ITransactionService transactionService;
+ private final IBizEventsService bizEventsService;
@Autowired
- public PaidNoticeController(ITransactionService transactionService) {
+ public PaidNoticeController(ITransactionService transactionService, IBizEventsService bizEventsService) {
this.transactionService = transactionService;
+ this.bizEventsService = bizEventsService;
}
@@ -28,5 +35,17 @@ public ResponseEntity disablePaidNotice(String fiscalCode, String transact
return new ResponseEntity<>(HttpStatus.OK);
}
+ @Override
+ public ResponseEntity generatePDF(@NotBlank String fiscalCode, @NotBlank String eventId) {
+ // to check if is an OLD event present only on the PM --> the receipt is not available for events present exclusively on the PM
+ bizEventsService.getBizEvent(eventId);
+ byte[] receiptFile = transactionService.getPDFReceipt(fiscalCode, eventId);
+ return ResponseEntity
+ .ok()
+ .contentLength(receiptFile.length)
+ .contentType(MediaType.APPLICATION_PDF)
+ .header(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.inline().filename("Receipt.pdf").build().toString())
+ .body(new ByteArrayResource(receiptFile));
+ }
}
diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/model/ProblemJson.java b/src/main/java/it/gov/pagopa/bizeventsservice/model/ProblemJson.java
index b82e63d8..a6017191 100644
--- a/src/main/java/it/gov/pagopa/bizeventsservice/model/ProblemJson.java
+++ b/src/main/java/it/gov/pagopa/bizeventsservice/model/ProblemJson.java
@@ -3,11 +3,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.ToString;
+import lombok.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml
index 1f186113..7e0a2215 100644
--- a/src/main/resources/logback-spring.xml
+++ b/src/main/resources/logback-spring.xml
@@ -1,6 +1,6 @@
-
+
@@ -18,7 +18,7 @@
-
+