diff --git a/README.md b/README.md
index 1d2a87c..6821ce6 100644
--- a/README.md
+++ b/README.md
@@ -79,36 +79,38 @@ On terminal type:
then replace env variables with correct values
(if there is NO default value, the variable HAS to be defined)
-| VARIABLE | USAGE | DEFAULT VALUE |
-|---------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------:|
-| `RECEIPTS_STORAGE_CONN_STRING` | Connection string to the Receipt Queue | |
-| `RECEIPT_QUEUE_TOPIC` | Topic name of the Receipt Queue | |
-| `COSMOS_BIZ_EVENT_CONN_STRING` | Connection string to the BizEvent CosmosDB | |
-| `COSMOS_BIZ_EVENT_SERVICE_ENDPOINT` | Endpoint to the BizEvent CosmosDB | |
-| `COSMOS_BIZ_EVENT_DB_NAME` | Database name of the BizEvent database in CosmosDB | |
-| `COSMOS_BIZ_EVENT_CONTAINER_NAME` | Container name of the BizEvent container in CosmosDB | |
-| `COSMOS_RECEIPTS_CONN_STRING` | Connection string to the Receipt CosmosDB | |
-| `COSMOS_RECEIPT_SERVICE_ENDPOINT` | Endpoint to the Receipt CosmosDB | |
-| `COSMOS_RECEIPT_KEY` | Key to the Receipt CosmosDB | |
-| `COSMOS_RECEIPT_DB_NAME` | Database name of the Receipt database in CosmosDB | |
-| `COSMOS_RECEIPT_CONTAINER_NAME` | Container name of the Receipt container in CosmosDB | |
-| `COSMOS_RECEIPT_ERROR_CONTAINER_NAME` | Container name of the Receipt-message-error container in CosmosDB | |
-| `BLOB_STORAGE_ACCOUNT_ENDPOINT` | Endpoint to the Receipt Blob Storage | |
-| `BLOB_STORAGE_CONTAINER_NAME` | Container name of the Blob Storage containing the pdf attachments | |
-| `BLOB_STORAGE_DOWNLOAD_TIMEOUT` | Timeout for the call to retrieve the attachment from the blob storage | 10 |
-| `BLOB_STORAGE_DOWNLOAD_MAX_RETRY` | Max number of retry for the call to retrieve the attachment from the blob storage | 5 |
-| `PDV_TOKENIZER_BASE_PATH` | PDV Tokenizer API base path | "https://api.uat.tokenizer.pdv.pagopa.it/tokenizer/v1" |
-| `PDV_TOKENIZER_SEARCH_TOKEN_ENDPOINT` | PDV Tokenizer API search token endpoint | "/tokens/search" |
-| `PDV_TOKENIZER_FIND_PII_ENDPOINT` | PDV Tokenizer API find pii endpoint | "/tokens/%s/pii" |
-| `PDV_TOKENIZER_CREATE_TOKEN_ENDPOINT` | PDV Tokenizer API create token endpoint | "/tokens" |
-| `PDV_TOKENIZER_SUBSCRIPTION_KEY` | API azure ocp apim subscription key | |
-| `PDV_TOKENIZER_INITIAL_INTERVAL` | PDV Tokenizer initial interval for retry a request that fail with 429 status code | 200 |
-| `PDV_TOKENIZER_MULTIPLIER` | PDV Tokenizer interval multiplier for subsequent request retry | 2.0 |
-| `PDV_TOKENIZER_RANDOMIZATION_FACTOR` | PDV Tokenizer randomization factor for interval retry calculation | 0.6 |
-| `PDV_TOKENIZER_MAX_RETRIES` | PDV Tokenizer max request retry | 3 |
-| `TOKENIZER_APIM_HEADER_KEY` | Tokenizer APIM header key | x-api-key |
-| `MAX_DATE_DIFF_MILLIS` | Difference in millis between the current time and the date from witch the
receipts will be fetched in massive recover operation | 360000 |
-| `RECOVER_FAILED_CRON` | CRON expression for timer trigger function that recover failed receipt | |
+| VARIABLE | USAGE | DEFAULT VALUE |
+|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------:|
+| `RECEIPTS_STORAGE_CONN_STRING` | Connection string to the Receipt Queue | |
+| `RECEIPT_QUEUE_TOPIC` | Topic name of the Receipt Queue | |
+| `COSMOS_BIZ_EVENT_CONN_STRING` | Connection string to the BizEvent CosmosDB | |
+| `COSMOS_BIZ_EVENT_SERVICE_ENDPOINT` | Endpoint to the BizEvent CosmosDB | |
+| `COSMOS_BIZ_EVENT_DB_NAME` | Database name of the BizEvent database in CosmosDB | |
+| `COSMOS_BIZ_EVENT_CONTAINER_NAME` | Container name of the BizEvent container in CosmosDB | |
+| `COSMOS_RECEIPTS_CONN_STRING` | Connection string to the Receipt CosmosDB | |
+| `COSMOS_RECEIPT_SERVICE_ENDPOINT` | Endpoint to the Receipt CosmosDB | |
+| `COSMOS_RECEIPT_KEY` | Key to the Receipt CosmosDB | |
+| `COSMOS_RECEIPT_DB_NAME` | Database name of the Receipt database in CosmosDB | |
+| `COSMOS_RECEIPT_CONTAINER_NAME` | Container name of the Receipt container in CosmosDB | |
+| `COSMOS_RECEIPT_ERROR_CONTAINER_NAME` | Container name of the Receipt-message-error container in CosmosDB | |
+| `BLOB_STORAGE_ACCOUNT_ENDPOINT` | Endpoint to the Receipt Blob Storage | |
+| `BLOB_STORAGE_CONTAINER_NAME` | Container name of the Blob Storage containing the pdf attachments | |
+| `BLOB_STORAGE_DOWNLOAD_TIMEOUT` | Timeout for the call to retrieve the attachment from the blob storage | 10 |
+| `BLOB_STORAGE_DOWNLOAD_MAX_RETRY` | Max number of retry for the call to retrieve the attachment from the blob storage | 5 |
+| `PDV_TOKENIZER_BASE_PATH` | PDV Tokenizer API base path | "https://api.uat.tokenizer.pdv.pagopa.it/tokenizer/v1" |
+| `PDV_TOKENIZER_SEARCH_TOKEN_ENDPOINT` | PDV Tokenizer API search token endpoint | "/tokens/search" |
+| `PDV_TOKENIZER_FIND_PII_ENDPOINT` | PDV Tokenizer API find pii endpoint | "/tokens/%s/pii" |
+| `PDV_TOKENIZER_CREATE_TOKEN_ENDPOINT` | PDV Tokenizer API create token endpoint | "/tokens" |
+| `PDV_TOKENIZER_SUBSCRIPTION_KEY` | API azure ocp apim subscription key | |
+| `PDV_TOKENIZER_INITIAL_INTERVAL` | PDV Tokenizer initial interval for retry a request that fail with 429 status code | 200 |
+| `PDV_TOKENIZER_MULTIPLIER` | PDV Tokenizer interval multiplier for subsequent request retry | 2.0 |
+| `PDV_TOKENIZER_RANDOMIZATION_FACTOR` | PDV Tokenizer randomization factor for interval retry calculation | 0.6 |
+| `PDV_TOKENIZER_MAX_RETRIES` | PDV Tokenizer max request retry | 3 |
+| `TOKENIZER_APIM_HEADER_KEY` | Tokenizer APIM header key | x-api-key |
+| `MAX_DATE_DIFF_MILLIS` | Difference in millis between the current time and the date from witch the
receipts will be fetched in massive recover operation | 360000 |
+| `MAX_DATE_DIFF_NOTIFY_MILLIS` | Difference in millis between the current time and the date from witch the
receipts to notify will be fetched in massive recover operation | 360000 |
+| `RECOVER_FAILED_CRON` | CRON expression for timer trigger function that recover failed receipt | |
+| `TRIGGER_GEN_SCHEDULE` | CRON expression for timer trigger function that recover nor notified generater receipt | |
> to doc details about AZ fn config
> see [here](https://stackoverflow.com/questions/62669672/azure-functions-what-is-the-purpose-of-having-host-json-and-local-settings-jso)
diff --git a/helm/Chart.yaml b/helm/Chart.yaml
index 0742553..af24bf5 100644
--- a/helm/Chart.yaml
+++ b/helm/Chart.yaml
@@ -2,8 +2,8 @@ apiVersion: v2
name: pagopareceiptpdfhelpdesk
description: Microservice description
type: application
-version: 0.105.0
-appVersion: 0.6.4
+version: 0.119.0
+appVersion: 0.6.18-fix-schedule-env-vars
dependencies:
- name: microservice-chart
version: 2.4.0
diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml
index 86661bc..136321a 100644
--- a/helm/values-dev.yaml
+++ b/helm/values-dev.yaml
@@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk
- tag: "0.6.4"
+ tag: "0.6.18-fix-schedule-env-vars"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
@@ -57,8 +57,8 @@ microservice-chart:
memory: "768Mi"
cpu: "300m"
limits:
- memory: "768Mi"
- cpu: "400m"
+ memory: "1512Mi"
+ cpu: "700m"
autoscaling:
enable: true
minReplica: 1
@@ -109,11 +109,14 @@ microservice-chart:
OTEL_TRACES_SAMPLER: "always_on"
MAX_DATE_DIFF_MILLIS: "360000"
MAX_DATE_DIFF_NOTIFY_MILLIS: "360000"
- TRIGGER_NOTIFY_REC_SCHEDULE: "0 0 */6 * * *"
- RECOVER_FAILED_CRON: "0 0 /12 * * *"
+ TRIGGER_GEN_SCHEDULE: "0 0 */6 * * *"
+ RECOVER_FAILED_CRON: "0 0 */12 * * *"
AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/opentelemetry-javaagent.jar -Xmx768m -XX:+UseG1GC"
FAILED_AUTORECOVER_ENABLED: "true"
NOT_NOTIFIED_AUTORECOVER_ENABLED: "true"
+ envConfigMapExternals:
+ template-maps:
+ BRAND_LOGO_MAP: brand-logo-map
envFieldRef:
APP_NAME: "metadata.labels['app.kubernetes.io/instance']"
APP_VERSION: "metadata.labels['app.kubernetes.io/version']"
@@ -121,11 +124,15 @@ microservice-chart:
APPLICATIONINSIGHTS_CONNECTION_STRING: "ai-d-connection-string"
COSMOS_RECEIPTS_CONN_STRING: "cosmos-receipt-connection-string"
RECEIPTS_STORAGE_CONN_STRING: "receipts-storage-account-connection-string"
+ AzureWebJobsStorage: "receipts-storage-account-connection-string"
COSMOS_BIZ_EVENT_CONN_STRING: "cosmos-biz-event-d-connection-string"
COSMOS_RECEIPT_KEY: "cosmos-receipt-pkey"
COSMOS_BIZ_EVENT_KEY: "cosmos-bizevent-pkey"
OTEL_EXPORTER_OTLP_HEADERS: 'elastic-otl-secret-token'
PDV_TOKENIZER_SUBSCRIPTION_KEY: "tokenizer-api-key"
+ OCP_APIM_SUBSCRIPTION_KEY: "shared-apim-d-subscription-key"
+ AES_SECRET_KEY: "aes-secret-key"
+ AES_SALT: "aes-salt"
keyvault:
name: "pagopa-d-receipts-kv"
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml
index a1fd574..6cd1ab8 100644
--- a/helm/values-prod.yaml
+++ b/helm/values-prod.yaml
@@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk
- tag: "0.6.4"
+ tag: "0.6.18-fix-schedule-env-vars"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
@@ -109,11 +109,14 @@ microservice-chart:
OTEL_TRACES_SAMPLER: "always_on"
MAX_DATE_DIFF_MILLIS: "360000"
MAX_DATE_DIFF_NOTIFY_MILLIS: "360000"
- TRIGGER_NOTIFY_REC_SCHEDULE: "0 0 */6 * * *"
- RECOVER_FAILED_CRON: "0 0 /12 * * *"
+ TRIGGER_GEN_SCHEDULE: "0 0 */6 * * *"
+ RECOVER_FAILED_CRON: "0 0 */12 * * *"
AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/opentelemetry-javaagent.jar -Xmx768m -XX:+UseG1GC"
FAILED_AUTORECOVER_ENABLED: "false"
NOT_NOTIFIED_AUTORECOVER_ENABLED: "false"
+ envConfigMapExternals:
+ template-maps:
+ BRAND_LOGO_MAP: brand-logo-map
envFieldRef:
APP_NAME: "metadata.labels['app.kubernetes.io/instance']"
APP_VERSION: "metadata.labels['app.kubernetes.io/version']"
@@ -121,11 +124,15 @@ microservice-chart:
APPLICATIONINSIGHTS_CONNECTION_STRING: "ai-p-connection-string"
COSMOS_RECEIPTS_CONN_STRING: "cosmos-receipt-connection-string"
RECEIPTS_STORAGE_CONN_STRING: "receipts-storage-account-connection-string"
+ AzureWebJobsStorage: "receipts-storage-account-connection-string"
+ OCP_APIM_SUBSCRIPTION_KEY: "shared-apim-p-subscription-key"
COSMOS_BIZ_EVENT_CONN_STRING: "cosmos-biz-event-p-connection-string"
COSMOS_RECEIPT_KEY: "cosmos-receipt-pkey"
COSMOS_BIZ_EVENT_KEY: "cosmos-bizevent-pkey"
OTEL_EXPORTER_OTLP_HEADERS: "elastic-otl-secret-token"
PDV_TOKENIZER_SUBSCRIPTION_KEY: "tokenizer-api-key"
+ AES_SECRET_KEY: "aes-secret-key"
+ AES_SALT: "aes-salt"
keyvault:
name: "pagopa-p-receipts-kv"
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml
index 5552a12..2062dd4 100644
--- a/helm/values-uat.yaml
+++ b/helm/values-uat.yaml
@@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk
- tag: "0.6.4"
+ tag: "0.6.18-fix-schedule-env-vars"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
@@ -109,11 +109,14 @@ microservice-chart:
OTEL_TRACES_SAMPLER: "always_on"
MAX_DATE_DIFF_MILLIS: "360000"
MAX_DATE_DIFF_NOTIFY_MILLIS: "360000"
- TRIGGER_NOTIFY_REC_SCHEDULE: "0 0 */6 * * *"
- RECOVER_FAILED_CRON: "0 0 /12 * * *"
+ TRIGGER_GEN_SCHEDULE: "0 0 */6 * * *"
+ RECOVER_FAILED_CRON: "0 0 */12 * * *"
AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/opentelemetry-javaagent.jar -Xmx768m -XX:+UseG1GC"
FAILED_AUTORECOVER_ENABLED: "true"
NOT_NOTIFIED_AUTORECOVER_ENABLED: "true"
+ envConfigMapExternals:
+ template-maps:
+ BRAND_LOGO_MAP: brand-logo-map
envFieldRef:
APP_NAME: "metadata.labels['app.kubernetes.io/instance']"
APP_VERSION: "metadata.labels['app.kubernetes.io/version']"
@@ -121,11 +124,15 @@ microservice-chart:
APPLICATIONINSIGHTS_CONNECTION_STRING: "ai-u-connection-string"
COSMOS_RECEIPTS_CONN_STRING: "cosmos-receipt-connection-string"
RECEIPTS_STORAGE_CONN_STRING: "receipts-storage-account-connection-string"
+ AzureWebJobsStorage: "receipts-storage-account-connection-string"
COSMOS_BIZ_EVENT_CONN_STRING: "cosmos-biz-event-u-connection-string"
COSMOS_RECEIPT_KEY: "cosmos-receipt-pkey"
COSMOS_BIZ_EVENT_KEY: "cosmos-bizevent-pkey"
OTEL_EXPORTER_OTLP_HEADERS: "elastic-otl-secret-token"
PDV_TOKENIZER_SUBSCRIPTION_KEY: "tokenizer-api-key"
+ OCP_APIM_SUBSCRIPTION_KEY: "shared-apim-u-subscription-key"
+ AES_SECRET_KEY: "aes-secret-key"
+ AES_SALT: "aes-salt"
keyvault:
name: "pagopa-u-receipts-kv"
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
diff --git a/openapi/openapi.json b/openapi/openapi.json
index 170f932..15fb207 100644
--- a/openapi/openapi.json
+++ b/openapi/openapi.json
@@ -4,7 +4,7 @@
"title": "Receipts Helpdesk",
"description": "Microservice for exposing REST APIs about receipts helpdesk.",
"termsOfService": "https://www.pagopa.gov.it/",
- "version": "0.6.4"
+ "version": "0.6.18-fix-schedule-env-vars"
},
"servers": [
{
diff --git a/pom.xml b/pom.xml
index 0718454..9a14263 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
it.gov.pagopa.receipt
receipt-pdf-helpdesk
- 0.6.4
+ 0.6.18-fix-schedule-env-vars
jar
pagopa-receipt-pdf-helpdesk
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 444dec7..302578f 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
@@ -8,8 +8,10 @@
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.ReceiptError;
+import it.gov.pagopa.receipt.pdf.helpdesk.exception.Aes256Exception;
import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException;
import it.gov.pagopa.receipt.pdf.helpdesk.model.ProblemJson;
+import it.gov.pagopa.receipt.pdf.helpdesk.utils.Aes256Utils;
import java.util.Base64;
import java.util.Optional;
@@ -49,10 +51,9 @@ public HttpResponseMessage run (
try {
ReceiptError receiptError = receiptCosmosClient.getReceiptError(eventId);
try {
- receiptError.setMessagePayload(new String(
- Base64.getMimeDecoder().decode(receiptError.getMessagePayload()))
+ receiptError.setMessagePayload(Aes256Utils.decrypt(receiptError.getMessagePayload())
);
- } catch (IllegalArgumentException ignored) {}
+ } catch (IllegalArgumentException | Aes256Exception ignored) {}
return request.createResponseBuilder(HttpStatus.OK)
.body(receiptError)
.build();
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 a2d68f4..6c77baa 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
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.nio.file.Path;
+import java.time.LocalDateTime;
import java.util.Optional;
import static it.gov.pagopa.receipt.pdf.helpdesk.utils.GenerateReceiptUtils.*;
@@ -32,18 +33,15 @@
*/
public class RegenerateReceiptPdf {
-
-
private final Logger logger = LoggerFactory.getLogger(RegenerateReceiptPdf.class);
private final BizEventCosmosClient bizEventCosmosClient;
private final ReceiptCosmosClient receiptCosmosClient;
-
private final GenerateReceiptPdfService generateReceiptPdfService;
public RegenerateReceiptPdf(){
- this.generateReceiptPdfService = new GenerateReceiptPdfServiceImpl();
- this.receiptCosmosClient = ReceiptCosmosClientImpl.getInstance();
this.bizEventCosmosClient = BizEventCosmosClientImpl.getInstance();
+ this.receiptCosmosClient = ReceiptCosmosClientImpl.getInstance();
+ this.generateReceiptPdfService = new GenerateReceiptPdfServiceImpl();
}
RegenerateReceiptPdf(BizEventCosmosClient bizEventCosmosClient,
@@ -60,33 +58,37 @@ public RegenerateReceiptPdf(){
*
* @return response with HttpStatus.OK
*/
- @FunctionName("RegenerateReceiptPdf")
+ @FunctionName("RegenerateReceiptFunc")
public HttpResponseMessage run (
- @HttpTrigger(name = "RegenerateReceiptPdfTrigger",
+ @HttpTrigger(name = "RegenerateReceiptPdfFuncTrigger",
methods = {HttpMethod.POST},
- route = "/receipts/{bizevent-id}/regenerate-receipt-pdf",
+ route = "receipts/{bizeventid}/regenerate-receipt-pdf",
authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage> request,
- @BindingName("bizevent-id") String eventId,
+ @BindingName("bizeventid") String eventId,
final ExecutionContext context) {
- try {
+ logger.info("[{}] function called at {}", context.getFunctionName(), LocalDateTime.now());
+
+ if (eventId != null) {
- if (eventId != null) {
+ try {
BizEvent bizEvent = bizEventCosmosClient.getBizEventDocument(eventId);
//Retrieve receipt's data from CosmosDB
Receipt receipt = getReceipt(context, bizEvent, receiptCosmosClient, logger);
-
//Verify receipt status
- if (receipt.getEventData() != null && isHasAllAttachments(receipt)) {
+ if (receipt.getEventData() != null
+ && isHasAllAttachments(receipt)
+ ) {
logger.info("[{}] Generating pdf for Receipt with id {} and bizEvent with id {}",
context.getFunctionName(),
receipt.getId(),
bizEvent.getId());
+
//Generate and save PDF
PdfGeneration pdfGeneration;
Path workingDirPath = createWorkingDirectory();
@@ -94,13 +96,12 @@ public HttpResponseMessage run (
pdfGeneration = generateReceiptPdfService.generateReceipts(receipt, bizEvent, workingDirPath);
//Verify PDF generation success
- boolean success;
+ boolean success = true;
success = generateReceiptPdfService.verifyAndUpdateReceipt(receipt, pdfGeneration);
return success ?
request.createResponseBuilder(HttpStatus.OK)
- .body("OK")
- .build() :
+ .body("OK").build() :
request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
.body(ProblemJson.builder()
.title(HttpStatus.INTERNAL_SERVER_ERROR.name())
@@ -119,47 +120,49 @@ public HttpResponseMessage run (
.build())
.build();
} finally {
- deleteTempFolder(workingDirPath, logger);
+ deleteTempFolder(workingDirPath, logger);
}
}
+ } catch (ReceiptNotFoundException | BizEventNotFoundException exception) {
+ logger.error(exception.getMessage(), exception);
+ String message = "Missing required informations";
+ if (exception.getClass().equals(ReceiptNotFoundException.class)) {
+ message = "Receipt not found with event-id " + eventId;
+ } else if (exception.getClass().equals(BizEventNotFoundException.class)) {
+ message = "BizEvent not found with event-id " + eventId;
+ }
+ return request
+ .createResponseBuilder(HttpStatus.BAD_REQUEST)
+ .body(ProblemJson.builder()
+ .title(HttpStatus.BAD_REQUEST.name())
+ .detail(message)
+ .status(HttpStatus.BAD_REQUEST.value())
+ .build())
+ .build();
}
-
- return request.createResponseBuilder(HttpStatus.BAD_REQUEST)
- .body(ProblemJson.builder()
- .title(HttpStatus.BAD_REQUEST.name())
- .detail("Missing valid eventId paramater")
- .status(HttpStatus.BAD_REQUEST.value())
- .build())
- .build();
-
- } catch (ReceiptNotFoundException | BizEventNotFoundException exception) {
- logger.error(exception.getMessage(), exception);
- String message = "Missing required informations";
- if (exception.getClass().equals(ReceiptNotFoundException.class)) {
- message = "Receipt not found with event-id " + eventId;
- } else if (exception.getClass().equals(BizEventNotFoundException.class)) {
- message = "BizEvent not found with event-id " + eventId;
+ catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
+ .body(ProblemJson.builder()
+ .title(HttpStatus.INTERNAL_SERVER_ERROR.name())
+ .detail("Unexpected error while managing the receipt file")
+ .status(HttpStatus.INTERNAL_SERVER_ERROR.value())
+ .build())
+ .build();
}
- return request
- .createResponseBuilder(HttpStatus.BAD_REQUEST)
- .body(ProblemJson.builder()
- .title(HttpStatus.BAD_REQUEST.name())
- .detail(message)
- .status(HttpStatus.BAD_REQUEST.value())
- .build())
- .build();
- } catch (IOException e) {
- logger.error(e.getMessage(), e);
- return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
- .body(ProblemJson.builder()
- .title(HttpStatus.INTERNAL_SERVER_ERROR.name())
- .detail("Unexpected error while managing the receipt file")
- .status(HttpStatus.INTERNAL_SERVER_ERROR.value())
- .build())
- .build();
+
}
+
+ return request.createResponseBuilder(HttpStatus.BAD_REQUEST)
+ .body(ProblemJson.builder()
+ .title(HttpStatus.BAD_REQUEST.name())
+ .detail("Missing valid eventId paramater")
+ .status(HttpStatus.BAD_REQUEST.value())
+ .build())
+ .build();
+
}
private static boolean isHasAllAttachments(Receipt receipt) {
diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java
index 2b94db3..b3ae0a1 100644
--- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java
+++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java
@@ -106,7 +106,7 @@ public Iterable> getInsertedReceiptDocuments(String contin
CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerId);
//Build query
- String query = String.format("SELECT * FROM c WHERE (c.status= = '%s' AND ( %s - c.inserted_at) >= %s)",
+ String query = String.format("SELECT * FROM c WHERE (c.status = '%s' AND ( %s - c.inserted_at) >= %s)",
ReceiptStatusType.INSERTED, OffsetDateTime.now().toInstant().toEpochMilli(), millisDiff);
//Query the container
diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/model/template/ReceiptPDFTemplate.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/model/template/ReceiptPDFTemplate.java
index e6b9991..d577f96 100644
--- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/model/template/ReceiptPDFTemplate.java
+++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/model/template/ReceiptPDFTemplate.java
@@ -15,6 +15,7 @@
@JsonInclude(Include.NON_NULL)
public class ReceiptPDFTemplate {
+ private String serviceCustomerId;
private Transaction transaction;
private User user;
private Cart cart;
diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/BuildTemplateService.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/BuildTemplateService.java
index cb93235..b2206fb 100644
--- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/BuildTemplateService.java
+++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/BuildTemplateService.java
@@ -1,6 +1,7 @@
package it.gov.pagopa.receipt.pdf.helpdesk.service;
import it.gov.pagopa.receipt.pdf.helpdesk.entity.event.BizEvent;
+import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt;
import it.gov.pagopa.receipt.pdf.helpdesk.exception.TemplateDataMappingException;
import it.gov.pagopa.receipt.pdf.helpdesk.model.template.ReceiptPDFTemplate;
@@ -11,11 +12,11 @@ public interface BuildTemplateService {
*
* @param bizEvent Biz-event from queue message
* @param partialTemplate boolean that indicates the type of template
+ * @param receipt Receipt from CosmosDB
* @return {@link ReceiptPDFTemplate} compiled template
* @throws {@link TemplateDataMappingException} when mandatory fields are missing
*/
- ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTemplate) throws TemplateDataMappingException;
-
+ ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTemplate, Receipt receipt) throws TemplateDataMappingException;
}
diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BuildTemplateServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BuildTemplateServiceImpl.java
index c1293f2..593de0a 100644
--- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BuildTemplateServiceImpl.java
+++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BuildTemplateServiceImpl.java
@@ -2,6 +2,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import it.gov.pagopa.receipt.pdf.helpdesk.entity.event.BizEvent;
+import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt;
import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReasonErrorCode;
import it.gov.pagopa.receipt.pdf.helpdesk.exception.PdfJsonMappingException;
import it.gov.pagopa.receipt.pdf.helpdesk.exception.TemplateDataMappingException;
@@ -14,11 +15,11 @@
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.NumberFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
+import java.time.DateTimeException;
import java.time.LocalDateTime;
-import java.time.ZoneOffset;
+import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -35,7 +36,6 @@ public class BuildTemplateServiceImpl implements BuildTemplateService {
private static final String PAGO_PA_CHANNEL_IO = "IO";
private static final String PAGO_PA_CHANNEL_IO_PAY = "IO-PAY";
private static final String RECEIPT_DATE_FORMAT = "dd MMMM yyyy, HH:mm:ss";
- private static final String ZONED_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
/**
* Hide from public usage.
@@ -43,6 +43,8 @@ public class BuildTemplateServiceImpl implements BuildTemplateService {
private static final Map brandLogoMap;
private static final Map pspMap;
+ public static final String MODEL_TYPE_IUV = "1";
+ public static final String MODEL_TYPE_NOTICE = "2";
static {
try {
@@ -54,7 +56,7 @@ public class BuildTemplateServiceImpl implements BuildTemplateService {
}
static {
- try (InputStream data = BuildTemplateServiceImpl.class.getClassLoader().getResourceAsStream(PSP_CONFIG_FILE_JSON_FILE_NAME)) {
+ try (InputStream data = BuildTemplateServiceImpl.class.getClassLoader().getResourceAsStream(PSP_CONFIG_FILE_JSON_FILE_NAME)) {
if (data == null) {
throw new IOException("PSP config file not found");
}
@@ -68,10 +70,12 @@ public class BuildTemplateServiceImpl implements BuildTemplateService {
* {@inheritDoc}
*/
@Override
- public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTemplate) throws TemplateDataMappingException {
+ public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean isGeneratingDebtor, Receipt receipt) throws TemplateDataMappingException {
+ boolean requestedByDebtor = getRequestByDebtor(isGeneratingDebtor, bizEvent);
+
return ReceiptPDFTemplate.builder()
+ .serviceCustomerId(getServiceCustomerId(bizEvent))
.transaction(Transaction.builder()
- .id(getId(bizEvent))
.timestamp(getTimestamp(bizEvent))
.amount(getAmount(bizEvent))
.psp(getPsp(bizEvent))
@@ -82,10 +86,10 @@ public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTempla
.accountHolder(getPaymentMethodAccountHolder(bizEvent))
.build())
.authCode(getAuthCode(bizEvent))
- .requestedByDebtor(partialTemplate)
+ .requestedByDebtor(requestedByDebtor)
.processedByPagoPA(getProcessedByPagoPA(bizEvent))
.build())
- .user(partialTemplate ?
+ .user(requestedByDebtor ?
null :
User.builder()
.data(UserData.builder()
@@ -108,7 +112,7 @@ public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTempla
.name(getPayeeName(bizEvent))
.taxCode(getPayeeTaxCode(bizEvent))
.build())
- .subject(getItemSubject(bizEvent))
+ .subject(getItemSubject(receipt))
.amount(getItemAmount(bizEvent))
.build()
))
@@ -118,23 +122,11 @@ public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTempla
.build();
}
- private String getId(BizEvent event) throws TemplateDataMappingException {
- if (
- event.getTransactionDetails() != null &&
- event.getTransactionDetails().getTransaction() != null &&
- event.getTransactionDetails().getTransaction().getIdTransaction() != 0L
- ) {
- return String.valueOf(event.getTransactionDetails().getTransaction().getIdTransaction());
- }
- if (event.getPaymentInfo() != null) {
- if (event.getPaymentInfo().getPaymentToken() != null) {
- return event.getPaymentInfo().getPaymentToken();
- }
- if (event.getPaymentInfo().getIUR() != null) {
- return event.getPaymentInfo().getIUR();
- }
+ private String getServiceCustomerId(BizEvent event) throws TemplateDataMappingException {
+ if (event.getId() != null) {
+ return event.getId();
}
- throw new TemplateDataMappingException(formatErrorMessage(TemplateDataField.TRANSACTION_ID), ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode());
+ throw new TemplateDataMappingException(formatErrorMessage(TemplateDataField.SERVICE_CUSTOMER_ID), ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode());
}
private String getTimestamp(BizEvent event) throws TemplateDataMappingException {
@@ -221,6 +213,16 @@ private String getPaymentMethodAccountHolder(BizEvent event) {
}
private String getUserFullName(BizEvent event) throws TemplateDataMappingException {
+ if (
+ event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getUser() != null &&
+ event.getTransactionDetails().getUser().getName() != null &&
+ event.getTransactionDetails().getUser().getSurname() != null
+ ) {
+ return String.format("%s %s",
+ event.getTransactionDetails().getUser().getName(),
+ event.getTransactionDetails().getUser().getSurname());
+ }
if (event.getPayer() != null && event.getPayer().getFullName() != null) {
return event.getPayer().getFullName();
}
@@ -228,6 +230,13 @@ private String getUserFullName(BizEvent event) throws TemplateDataMappingExcepti
}
private String getUserTaxCode(BizEvent event) throws TemplateDataMappingException {
+ if (
+ event.getTransactionDetails() != null &&
+ event.getTransactionDetails().getUser() != null &&
+ event.getTransactionDetails().getUser().getFiscalCode() != null
+ ) {
+ return event.getTransactionDetails().getUser().getFiscalCode();
+ }
if (event.getPayer() != null && event.getPayer().getEntityUniqueIdentifierValue() != null) {
return event.getPayer().getEntityUniqueIdentifierValue();
}
@@ -236,19 +245,24 @@ private String getUserTaxCode(BizEvent event) throws TemplateDataMappingExceptio
private String getRefNumberType(BizEvent event) throws TemplateDataMappingException {
if (event.getDebtorPosition() != null && event.getDebtorPosition().getModelType() != null) {
- if (event.getDebtorPosition().getModelType().equals("1")) {
- return REF_TYPE_NOTICE;
- }
- if (event.getDebtorPosition().getModelType().equals("2")) {
+ if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_IUV)) {
return REF_TYPE_IUV;
}
+ if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_NOTICE)) {
+ return REF_TYPE_NOTICE;
+ }
}
throw new TemplateDataMappingException(formatErrorMessage(TemplateDataField.CART_ITEM_REF_NUMBER_TYPE), ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode());
}
private String getRefNumberValue(BizEvent event) throws TemplateDataMappingException {
- if (event.getDebtorPosition() != null && event.getDebtorPosition().getIuv() != null) {
- return event.getDebtorPosition().getIuv();
+ if (event.getDebtorPosition() != null && event.getDebtorPosition().getModelType() != null) {
+ if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_IUV) && event.getDebtorPosition().getIuv() != null) {
+ return event.getDebtorPosition().getIuv();
+ }
+ if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_NOTICE) && event.getDebtorPosition().getNoticeNumber() != null) {
+ return event.getDebtorPosition().getNoticeNumber();
+ }
}
throw new TemplateDataMappingException(formatErrorMessage(TemplateDataField.CART_ITEM_REF_NUMBER_VALUE), ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode());
}
@@ -275,9 +289,12 @@ private String getPayeeTaxCode(BizEvent event) throws TemplateDataMappingExcepti
throw new TemplateDataMappingException(formatErrorMessage(TemplateDataField.CART_ITEM_PAYEE_TAX_CODE), ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode());
}
- private String getItemSubject(BizEvent event) {
- if (event.getPaymentInfo() != null && event.getPaymentInfo().getRemittanceInformation() != null) {
- return event.getPaymentInfo().getRemittanceInformation();
+ private String getItemSubject(Receipt receipt) {
+ if (receipt.getEventData() != null &&
+ !receipt.getEventData().getCart().isEmpty() &&
+ receipt.getEventData().getCart().get(0) != null
+ ) {
+ return receipt.getEventData().getCart().get(0).getSubject();
}
return null;
@@ -332,15 +349,40 @@ private String getOrThrow(LinkedHashMap map, String key, String
return value;
}
- public boolean getProcessedByPagoPA(BizEvent event) {
- if (event.getTransactionDetails() != null && event.getTransactionDetails().getWallet() != null) {
- String onboardingChannel = event.getTransactionDetails().getWallet().getOnboardingChannel();
- return onboardingChannel != null &&
- (onboardingChannel.equals(PAGO_PA_CHANNEL_IO) ||
- onboardingChannel.equals(PAGO_PA_CHANNEL_IO_PAY)
- );
+ private boolean getProcessedByPagoPA(BizEvent event) {
+ if (event.getTransactionDetails() != null) {
+ if (event.getTransactionDetails().getTransaction() != null &&
+ event.getTransactionDetails().getTransaction().getOrigin() != null) {
+ return true;
+ }
+ if (event.getTransactionDetails().getInfo() != null &&
+ event.getTransactionDetails().getInfo().getClientId() != null) {
+ return true;
+ }
}
+ return false;
+ }
+ private boolean getRequestByDebtor(boolean isGeneratingDebtor, BizEvent event) {
+ if (isGeneratingDebtor) {
+ String debtorFiscalCode = event.getDebtor().getEntityUniqueIdentifierValue();
+
+ String fiscalCodeFromPayer = event.getPayer() != null ? event.getPayer().getEntityUniqueIdentifierValue() : null;
+ String fiscalCodeFromUser = event.getTransactionDetails() != null && event.getTransactionDetails().getUser() != null ?
+ event.getTransactionDetails().getUser().getFiscalCode() : null;
+ //Check if payer's and user's fiscal codes exist
+ if (fiscalCodeFromPayer == null && fiscalCodeFromUser == null) {
+ return true;
+ }
+ //Check if payer's fiscal code exists and is different from debtor's
+ if (fiscalCodeFromPayer != null && !fiscalCodeFromPayer.equals(debtorFiscalCode)) {
+ return true;
+ }
+ //Check if user's fiscal code exists and is different from debtor's
+ if (fiscalCodeFromUser != null && !fiscalCodeFromUser.equals(debtorFiscalCode)) {
+ return true;
+ }
+ }
return false;
}
@@ -353,21 +395,26 @@ private String currencyFormat(String value) {
}
private String dateFormatZoned(String date) throws TemplateDataMappingException {
- SimpleDateFormat stringDateFormat = new SimpleDateFormat(ZONED_DATE_FORMAT, Locale.ITALY);
- stringDateFormat.setTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC));
- Date parsed;
+ DateTimeFormatter formatter = new DateTimeFormatterBuilder()
+ .append(DateTimeFormatter.ofPattern(RECEIPT_DATE_FORMAT))
+ .toFormatter(Locale.ITALY)
+ .withZone(TimeZone.getTimeZone("Europe/Rome").toZoneId());
try {
- parsed = stringDateFormat.parse(date);
- } catch (ParseException e) {
+ return OffsetDateTime.parse(date).format(formatter);
+ } catch (DateTimeException e) {
String errMsg = String.format("Error mapping bizEvent data to template, parse failed for property %s", TemplateDataField.TRANSACTION_TIMESTAMP);
throw new TemplateDataMappingException(errMsg, ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e);
}
- SimpleDateFormat dateFormat = new SimpleDateFormat(RECEIPT_DATE_FORMAT, Locale.ITALY);
- return dateFormat.format(parsed);
}
- private String dateFormat(String date) {
+
+ private String dateFormat(String date) throws TemplateDataMappingException {
DateTimeFormatter simpleDateFormat = DateTimeFormatter.ofPattern(RECEIPT_DATE_FORMAT).withLocale(Locale.ITALY);
- return LocalDateTime.parse(date).format(simpleDateFormat);
+ try {
+ return LocalDateTime.parse(date).format(simpleDateFormat);
+ } catch (DateTimeException e) {
+ String errMsg = String.format("Error mapping bizEvent data to template, parse failed for property %s", TemplateDataField.TRANSACTION_TIMESTAMP);
+ throw new TemplateDataMappingException(errMsg, ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e);
+ }
}
private String formatErrorMessage(String missingProperty) {
@@ -385,6 +432,6 @@ private String formatFullName(String fullName, String fiscalCode) {
return null;
}
- return fullName.replaceAll("[,;:]+", " ");
+ return fullName.replaceAll("[,;:/]+", " ");
}
}
diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/GenerateReceiptPdfServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/GenerateReceiptPdfServiceImpl.java
index 95342b9..d340fa6 100644
--- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/GenerateReceiptPdfServiceImpl.java
+++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/GenerateReceiptPdfServiceImpl.java
@@ -6,7 +6,6 @@
import it.gov.pagopa.receipt.pdf.helpdesk.client.impl.ReceiptBlobClientImpl;
import it.gov.pagopa.receipt.pdf.helpdesk.entity.event.BizEvent;
import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt;
-import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.ReceiptMetadata;
import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReasonErrorCode;
import it.gov.pagopa.receipt.pdf.helpdesk.exception.GeneratePDFException;
import it.gov.pagopa.receipt.pdf.helpdesk.exception.PDFReceiptGenerationException;
@@ -21,7 +20,6 @@
import it.gov.pagopa.receipt.pdf.helpdesk.service.BuildTemplateService;
import it.gov.pagopa.receipt.pdf.helpdesk.service.GenerateReceiptPdfService;
import it.gov.pagopa.receipt.pdf.helpdesk.utils.ObjectMapperUtils;
-import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,10 +35,6 @@ public class GenerateReceiptPdfServiceImpl implements GenerateReceiptPdfService
private final Logger logger = LoggerFactory.getLogger(GenerateReceiptPdfServiceImpl.class);
- private static final String TEMPLATE_PREFIX = "pagopa-ricevuta";
- private static final String PAYER_TEMPLATE_SUFFIX = "p";
- private static final String DEBTOR_TEMPLATE_SUFFIX = "d";
-
public static final int ALREADY_CREATED = 208;
private final PdfEngineClient pdfEngineClient;
@@ -74,13 +68,13 @@ public PdfGeneration generateReceipts(Receipt receipt, BizEvent bizEvent, Path w
if (payerCF.equals(debtorCF)) {
pdfGeneration.setGenerateOnlyDebtor(true);
//Generate debtor's complete PDF
- PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt.getMdAttach().getName(), false, workingDirPath);
+ PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt, receipt.getMdAttach().getName(), false, workingDirPath);
pdfGeneration.setDebtorMetadata(generationResult);
return pdfGeneration;
}
//Generate payer's complete PDF
- PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt.getMdAttachPayer().getName(), false, workingDirPath);
+ PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt, receipt.getMdAttachPayer().getName(), false, workingDirPath);
pdfGeneration.setPayerMetadata(generationResult);
} else {
@@ -88,7 +82,7 @@ public PdfGeneration generateReceipts(Receipt receipt, BizEvent bizEvent, Path w
}
//Generate debtor's partial PDF
- PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt.getMdAttach().getName(), true, workingDirPath);
+ PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt, receipt.getMdAttach().getName(), true, workingDirPath);
pdfGeneration.setDebtorMetadata(generationResult);
@@ -130,9 +124,9 @@ public boolean verifyAndUpdateReceipt(Receipt receipt, PdfGeneration pdfGenerati
return result;
}
- private PdfMetadata generateAndSavePDFReceipt(BizEvent bizEvent, String blobName, boolean partialTemplate, Path workingDirPath) {
+ private PdfMetadata generateAndSavePDFReceipt(BizEvent bizEvent, Receipt receipt, String blobName, boolean isGeneratingDebtor, Path workingDirPath) {
try {
- ReceiptPDFTemplate template = buildTemplateService.buildTemplate(bizEvent, partialTemplate);
+ ReceiptPDFTemplate template = buildTemplateService.buildTemplate(bizEvent, isGeneratingDebtor, receipt);
PdfEngineResponse pdfEngineResponse = generatePDFReceipt(template, workingDirPath);
return saveToBlobStorage(pdfEngineResponse, blobName);
} catch (PDFReceiptGenerationException e) {
@@ -193,12 +187,4 @@ private String parseTemplateDataToString(ReceiptPDFTemplate template) throws Gen
}
}
- private boolean receiptAlreadyCreated(ReceiptMetadata receiptMetadata) {
- return receiptMetadata != null
- && receiptMetadata.getUrl() != null
- && receiptMetadata.getName() != null
- && !receiptMetadata.getUrl().isEmpty()
- && !receiptMetadata.getName().isEmpty();
- }
-
}
diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/Aes256Utils.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/Aes256Utils.java
new file mode 100644
index 0000000..bcd1e29
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/Aes256Utils.java
@@ -0,0 +1,91 @@
+package it.gov.pagopa.receipt.pdf.helpdesk.utils;
+
+import it.gov.pagopa.receipt.pdf.helpdesk.exception.Aes256Exception;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
+import java.security.SecureRandom;
+import java.security.spec.KeySpec;
+import java.util.Base64;
+
+public class Aes256Utils {
+
+ private static final String AES_SECRET_KEY = System.getenv().getOrDefault("AES_SECRET_KEY", "");
+ private static final String AES_SALT = System.getenv().getOrDefault("AES_SALT", "");
+ private static final int KEY_LENGTH = 256;
+ private static final int ITERATION_COUNT = 65536;
+ public static final String PBKDF_2_WITH_HMAC_SHA_256 = "PBKDF2WithHmacSHA256";
+ public static final String AES_CBC_PKCS_5_PADDING = "AES/CBC/PKCS5Padding";
+
+ public static final String ALGORITHM = "AES";
+
+ private static final int AES_UNEXPECTED_ERROR = 701;
+
+
+ /**
+ * Hide from public usage.
+ */
+ private Aes256Utils() {
+ }
+
+ public static String encrypt(String strToEncrypt) throws Aes256Exception {
+
+ try {
+
+ SecureRandom secureRandom = new SecureRandom();
+ byte[] iv = new byte[16];
+ secureRandom.nextBytes(iv);
+ IvParameterSpec ivspec = new IvParameterSpec(iv);
+
+ SecretKeyFactory factory = SecretKeyFactory.getInstance(PBKDF_2_WITH_HMAC_SHA_256);
+ KeySpec spec = new PBEKeySpec(AES_SECRET_KEY.toCharArray(), AES_SALT.getBytes(), ITERATION_COUNT, KEY_LENGTH);
+ SecretKey tmp = factory.generateSecret(spec);
+ SecretKeySpec secretKeySpec = new SecretKeySpec(tmp.getEncoded(), ALGORITHM);
+
+ //Padding vulnerability rule java:S5542 ignored because encryption is used inside application workflow
+ Cipher cipher = Cipher.getInstance(AES_CBC_PKCS_5_PADDING);
+ cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivspec);
+
+ byte[] cipherText = cipher.doFinal(strToEncrypt.getBytes(StandardCharsets.UTF_8));
+ byte[] encryptedData = new byte[iv.length + cipherText.length];
+ System.arraycopy(iv, 0, encryptedData, 0, iv.length);
+ System.arraycopy(cipherText, 0, encryptedData, iv.length, cipherText.length);
+
+ return Base64.getEncoder().encodeToString(encryptedData);
+ } catch (Exception e) {
+ throw new Aes256Exception("Unexpected error when encrypting the given string", AES_UNEXPECTED_ERROR, e);
+ }
+ }
+
+ public static String decrypt(String strToDecrypt) throws Aes256Exception {
+ try{
+ byte[] encryptedData = Base64.getDecoder().decode(strToDecrypt);
+ byte[] iv = new byte[16];
+ System.arraycopy(encryptedData, 0, iv, 0, iv.length);
+ IvParameterSpec ivspec = new IvParameterSpec(iv);
+
+ SecretKeyFactory factory = SecretKeyFactory.getInstance(PBKDF_2_WITH_HMAC_SHA_256);
+ KeySpec spec = new PBEKeySpec(AES_SECRET_KEY.toCharArray(), AES_SALT.getBytes(), ITERATION_COUNT, KEY_LENGTH);
+ SecretKey tmp = factory.generateSecret(spec);
+ SecretKeySpec secretKeySpec = new SecretKeySpec(tmp.getEncoded(), ALGORITHM);
+
+ //Padding vulnerability rule java:S5542 ignored because decryption is used inside application workflow
+ Cipher cipher = Cipher.getInstance(AES_CBC_PKCS_5_PADDING);
+ cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivspec);
+
+ byte[] cipherText = new byte[encryptedData.length - 16];
+ System.arraycopy(encryptedData, 16, cipherText, 0, cipherText.length);
+
+ byte[] decryptedText = cipher.doFinal(cipherText);
+ return new String(decryptedText, StandardCharsets.UTF_8);
+ } catch (Exception e) {
+ throw new Aes256Exception("Unexpected error when decrypting the given string", AES_UNEXPECTED_ERROR, e);
+ }
+ }
+}
+
diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/TemplateDataField.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/TemplateDataField.java
index df279a1..9be4ef1 100644
--- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/TemplateDataField.java
+++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/TemplateDataField.java
@@ -2,7 +2,7 @@
public class TemplateDataField {
public static final String ERROR_MAPPING_MESSAGE = "Error mapping bizEvent data to template, missing property %s";
- public static final String TRANSACTION_ID = "transaction.id";
+ public static final String SERVICE_CUSTOMER_ID = "serviceCustomerId";
public static final String TRANSACTION_TIMESTAMP = "transaction.timestamp";
public static final String TRANSACTION_AMOUNT = "transaction.amount";
public static final String TRANSACTION_RRN = "transaction.rrn";
diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptErrorTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptErrorTest.java
index a19147a..42422bc 100644
--- a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptErrorTest.java
+++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/GetReceiptErrorTest.java
@@ -8,10 +8,12 @@
import it.gov.pagopa.receipt.pdf.helpdesk.client.ReceiptCosmosClient;
import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.ReceiptError;
import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptErrorStatusType;
+import it.gov.pagopa.receipt.pdf.helpdesk.exception.Aes256Exception;
import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException;
import it.gov.pagopa.receipt.pdf.helpdesk.model.ProblemJson;
import it.gov.pagopa.receipt.pdf.helpdesk.service.GenerateReceiptPdfService;
import it.gov.pagopa.receipt.pdf.helpdesk.util.HttpResponseMessageMock;
+import it.gov.pagopa.receipt.pdf.helpdesk.utils.Aes256Utils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -20,6 +22,9 @@
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.stubbing.Answer;
+import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
+import uk.org.webcompere.systemstubs.jupiter.SystemStub;
+import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import java.util.Optional;
@@ -29,17 +34,26 @@
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
+@ExtendWith(SystemStubsExtension.class)
class GetReceiptErrorTest {
+ private final String AES_SALT = "salt";
+ private final String AES_KEY = "key";
+
+ @SystemStub
+ private EnvironmentVariables environment = new EnvironmentVariables("AES_SALT", AES_SALT, "AES_SECRET_KEY", AES_KEY);
+
String INVALID_DATA_BASE64 = "==eyJkYXRhIjoidGVzdCJ9";
- String VALID_DATA_BASE64 = "eyJkYXRhIjoidGVzdCJ9";
String VALID_DATA = "{\"data\":\"test\"}";
private ReceiptCosmosClient receiptCosmosClient;
private ExecutionContext executionContextMock;
private GetReceiptError sut;
+ GetReceiptErrorTest() throws Aes256Exception {
+ }
+
@BeforeEach
void setUp() {
receiptCosmosClient = mock(ReceiptCosmosClient.class);
@@ -49,7 +63,7 @@ void setUp() {
}
@Test
- void shouldReturnPlainDataOnValidInput() throws ReceiptNotFoundException {
+ void shouldReturnPlainDataOnValidInput() throws ReceiptNotFoundException, Aes256Exception {
@SuppressWarnings("unchecked")
HttpRequestMessage> request = mock(HttpRequestMessage.class);
@@ -175,13 +189,13 @@ void shouldReturnErrorOnMissingRequestData() {
}
- public ReceiptError getValidBase64ReceiptError() {
+ public ReceiptError getValidBase64ReceiptError() throws Aes256Exception {
return ReceiptError.builder()
.id("1")
.bizEventId("1")
.messageError("test")
.status(ReceiptErrorStatusType.TO_REVIEW)
- .messagePayload(VALID_DATA_BASE64)
+ .messagePayload(Aes256Utils.encrypt("{\"data\":\"test\"}"))
.build();
}
diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BuildTemplateServiceImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BuildTemplateServiceImplTest.java
index 26bf7a4..0578607 100644
--- a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BuildTemplateServiceImplTest.java
+++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BuildTemplateServiceImplTest.java
@@ -2,6 +2,9 @@
import it.gov.pagopa.receipt.pdf.helpdesk.entity.event.*;
import it.gov.pagopa.receipt.pdf.helpdesk.entity.event.enumeration.BizEventStatusType;
+import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.CartItem;
+import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.EventData;
+import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt;
import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReasonErrorCode;
import it.gov.pagopa.receipt.pdf.helpdesk.exception.TemplateDataMappingException;
import it.gov.pagopa.receipt.pdf.helpdesk.model.template.ReceiptPDFTemplate;
@@ -9,6 +12,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.jupiter.api.Assertions.*;
@@ -19,8 +23,8 @@ class BuildTemplateServiceImplTest {
public static final String ID_PSP = "ID_PSP";
public static final String DEBTOR_FULL_NAME = "John Doe";
public static final String DEBTOR_FULL_NAME_INVALID = "-- --";
- public static final String DEBTOR_FULL_NAME_SPECIAL_CHAR = "John,Doe:Megacorp;SRL::Avenue;";
- public static final String DEBTOR_FULL_NAME_SPECIAL_CHAR_FORMATTED = "John Doe Megacorp SRL Avenue ";
+ public static final String DEBTOR_FULL_NAME_SPECIAL_CHAR = "John,Doe:Megacorp;SRL::Avenue;Street/";
+ public static final String DEBTOR_FULL_NAME_SPECIAL_CHAR_FORMATTED = "John Doe Megacorp SRL Avenue Street ";
public static final String DEBTOR_VALID_CF = "CF_DEBTOR";
public static final String PAYER_FULL_NAME = "John Doe PAYER";
public static final String PAYER_VALID_CF = "CF_PAYER";
@@ -40,10 +44,14 @@ class BuildTemplateServiceImplTest {
public static final long ID_TRANSACTION = 1L;
public static final String RRN = "rrn";
public static final String AUTH_CODE = "authCode";
- public static final String DATE_TIME_TIMESTAMP_MILLISECONDS = "2023-11-14T19:31:55.484065";
- public static final String DATE_TIME_TIMESTAMP_ZONED = "2023-11-14T18:31:55Z";
- public static final boolean PARTIAL_TEMPLATE = true;
- public static final boolean COMPLETE_TEMPLATE = false;
+ public static final String DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER = "2023-11-14T19:31:55.484065";
+ public static final String DATE_TIME_TIMESTAMP_MILLISECONDS_DST_SUMMER = "2023-08-05T11:11:54.484065";
+ public static final String DATE_TIME_TIMESTAMP_ZONED_DST_WINTER = "2023-11-14T18:31:55Z";
+ public static final String DATE_TIME_TIMESTAMP_ZONED_DST_SUMMER = "2023-08-05T09:11:54Z";
+ public static final String DATE_TIME_TIMESTAMP_ZONED_MILLISECONDS_DST_WINTER = "2023-11-14T18:31:55.306516999Z";
+ public static final String DATE_TIME_TIMESTAMP_ZONED_MILLISECONDS_DST_SUMMER = "2023-08-05T09:11:54.306516999Z";
+ public static final boolean GENERATED_BY_DEBTOR = true;
+ public static final boolean GENERATED_BY_PAYER = false;
public static final String PSP_NAME = "name";
public static final String PSP_LOGO = "logo";
public static final String PSP_COMPANY = "companyName";
@@ -54,16 +62,23 @@ class BuildTemplateServiceImplTest {
public static final String PSP_PROVINCE = "province";
public static final String BRAND_ASSET_URL = "/asset";
private static final String IUV = "02119891614290410";
+ private static final String NOTICE_NUMBER = "valid notice number";
private static final String BIZ_EVENT_ID = "biz-event-id";
- private static final String MODEL_TYPE_NOTICE_CODE = "1";
- private static final String MODEL_TYPE_IUV_CODE = "2";
+ private static final String MODEL_TYPE_IUV_CODE = "1";
+ private static final String MODEL_TYPE_NOTICE_CODE = "2";
private static final String MODEL_TYPE_NOTICE_TEXT = "codiceAvviso";
private static final String MODEL_TYPE_IUV_TEXT = "IUV";
- private static final String DATE_TIME_TIMESTAMP_FORMATTED = "14 novembre 2023, 19:31:55";
+ private static final String DATE_TIME_TIMESTAMP_FORMATTED_DST_WINTER = "14 novembre 2023, 19:31:55";
+ private static final String DATE_TIME_TIMESTAMP_FORMATTED_DST_SUMMER = "05 agosto 2023, 11:11:54";
private static final String PAGO_PA_CHANNEL_IO = "IO";
private static final String PAGO_PA_CHANNEL_IO_PAY = "IO-PAY";
private static final String NOT_PAGO_PA_CHANNEL = "NOT_PAGO_PA_CHANNEL";
- public static final String ID_PA = "idPa";
+ private static final String ID_PA = "idPa";
+ private static final String USER_NAME = "user_name";
+ private static final String USER_SURNAME = "user_surname";
+ private static final String USER_FORMATTED_FULL_NAME = "user_name user_surname";
+ private static final String USER_TAX_CODE = "user tax code";
+ public static final String PAGOPA_PA_CHANNEL_ID = "pagopa channel";
private BuildTemplateServiceImpl buildTemplateService;
@BeforeEach
@@ -76,9 +91,10 @@ void setUp() throws Exception {
}
@Test
- void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception {
+ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
+ .idPaymentManager(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.modelType(MODEL_TYPE_IUV_CODE)
@@ -97,7 +113,7 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception
.build())
.payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
.paymentInfo(PaymentInfo.builder()
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.paymentToken(PAYMENT_TOKEN)
.amount(AMOUNT_WITHOUT_CENTS)
.fee(FEE_WITH_SINGLE_DIGIT_CENTS)
@@ -116,21 +132,27 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception
.fee(FEE_LONG)
.rrn(RRN)
.numAut(AUTH_CODE)
- .creationDate(DATE_TIME_TIMESTAMP_ZONED)
+ .creationDate(DATE_TIME_TIMESTAMP_ZONED_DST_WINTER)
.psp(TransactionPsp.builder()
.businessName(PSP_NAME)
.build())
+ .origin(PAGOPA_PA_CHANNEL_ID)
.build())
.build())
.eventStatus(BizEventStatusType.DONE)
.build();
- ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE);
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
+
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
+
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
- assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId());
- assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp());
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_WINTER, transaction.getTimestamp());
assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
@@ -146,12 +168,10 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception
assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
assertEquals(AUTH_CODE, transaction.getAuthCode());
- assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
assertTrue(transaction.isProcessedByPagoPA());
- it.gov.pagopa.receipt.pdf.helpdesk.model.template.UserData userData = receiptPdfTemplate.getUser().getData();
- assertEquals(PAYER_VALID_CF, userData.getTaxCode());
- assertEquals(PAYER_FULL_NAME, userData.getFullName());
+ assertNull(receiptPdfTemplate.getUser());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
@@ -166,9 +186,10 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception
}
@Test
- void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Exception {
+ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannelAndDateZonedDSTWinter() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
+ .idPaymentManager(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.modelType(MODEL_TYPE_IUV_CODE)
@@ -187,7 +208,7 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Excepti
.build())
.payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
.paymentInfo(PaymentInfo.builder()
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.paymentToken(PAYMENT_TOKEN)
.amount(AMOUNT_WITHOUT_CENTS)
.fee(FEE_WITH_SINGLE_DIGIT_CENTS)
@@ -197,7 +218,7 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Excepti
.transactionDetails(TransactionDetails.builder()
.wallet(WalletItem.builder()
.info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build())
- .onboardingChannel(PAGO_PA_CHANNEL_IO_PAY)
+ .onboardingChannel(PAGO_PA_CHANNEL_IO)
.build())
.transaction(Transaction.builder()
.idTransaction(ID_TRANSACTION)
@@ -206,21 +227,27 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Excepti
.fee(FEE_LONG)
.rrn(RRN)
.numAut(AUTH_CODE)
- .creationDate(DATE_TIME_TIMESTAMP_ZONED)
+ .creationDate(DATE_TIME_TIMESTAMP_ZONED_DST_WINTER)
.psp(TransactionPsp.builder()
.businessName(PSP_NAME)
.build())
+ .origin(PAGOPA_PA_CHANNEL_ID)
.build())
.build())
.eventStatus(BizEventStatusType.DONE)
.build();
- ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE);
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
+
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
+
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
- assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId());
- assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp());
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_WINTER, transaction.getTimestamp());
assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
@@ -236,12 +263,10 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Excepti
assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
assertEquals(AUTH_CODE, transaction.getAuthCode());
- assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
assertTrue(transaction.isProcessedByPagoPA());
- it.gov.pagopa.receipt.pdf.helpdesk.model.template.UserData userData = receiptPdfTemplate.getUser().getData();
- assertEquals(PAYER_VALID_CF, userData.getTaxCode());
- assertEquals(PAYER_FULL_NAME, userData.getFullName());
+ assertNull(receiptPdfTemplate.getUser());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
@@ -256,12 +281,13 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Excepti
}
@Test
- void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exception {
+ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannelAndDateZonedDSTSummer() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
+ .idPaymentManager(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
- .modelType(MODEL_TYPE_NOTICE_CODE)
+ .modelType(MODEL_TYPE_IUV_CODE)
.build())
.creditor(Creditor.builder()
.companyName(COMPANY_NAME)
@@ -277,7 +303,7 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce
.build())
.payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
.paymentInfo(PaymentInfo.builder()
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.paymentToken(PAYMENT_TOKEN)
.amount(AMOUNT_WITHOUT_CENTS)
.fee(FEE_WITH_SINGLE_DIGIT_CENTS)
@@ -287,7 +313,7 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce
.transactionDetails(TransactionDetails.builder()
.wallet(WalletItem.builder()
.info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build())
- .onboardingChannel(NOT_PAGO_PA_CHANNEL)
+ .onboardingChannel(PAGO_PA_CHANNEL_IO)
.build())
.transaction(Transaction.builder()
.idTransaction(ID_TRANSACTION)
@@ -296,21 +322,27 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce
.fee(FEE_LONG)
.rrn(RRN)
.numAut(AUTH_CODE)
- .creationDate(DATE_TIME_TIMESTAMP_ZONED)
+ .creationDate(DATE_TIME_TIMESTAMP_ZONED_DST_SUMMER)
.psp(TransactionPsp.builder()
.businessName(PSP_NAME)
.build())
+ .origin(PAGOPA_PA_CHANNEL_ID)
.build())
.build())
.eventStatus(BizEventStatusType.DONE)
.build();
- ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, PARTIAL_TEMPLATE);
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
+
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
+
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
- assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId());
- assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp());
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_SUMMER, transaction.getTimestamp());
assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
@@ -326,11 +358,10 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce
assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
assertEquals(AUTH_CODE, transaction.getAuthCode());
- assertEquals(PARTIAL_TEMPLATE, transaction.isRequestedByDebtor());
- assertFalse(transaction.isProcessedByPagoPA());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
+ assertTrue(transaction.isProcessedByPagoPA());
- it.gov.pagopa.receipt.pdf.helpdesk.model.template.User user = receiptPdfTemplate.getUser();
- assertNull(user);
+ assertNull(receiptPdfTemplate.getUser());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
@@ -340,14 +371,15 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce
assertEquals(REMITTANCE_INFORMATION, cart.getItems().get(0).getSubject());
assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getName());
assertEquals(ID_PA, cart.getItems().get(0).getPayee().getTaxCode());
- assertEquals(MODEL_TYPE_NOTICE_TEXT, cart.getItems().get(0).getRefNumber().getType());
+ assertEquals(MODEL_TYPE_IUV_TEXT, cart.getItems().get(0).getRefNumber().getType());
assertEquals(IUV, cart.getItems().get(0).getRefNumber().getValue());
}
@Test
- void mapTemplateWithoutTransactionDetailsSuccess() throws Exception {
+ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannelAndDateZonedWithMillisecondsDSTWinter() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
+ .idPaymentManager(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.modelType(MODEL_TYPE_IUV_CODE)
@@ -366,25 +398,49 @@ void mapTemplateWithoutTransactionDetailsSuccess() throws Exception {
.build())
.payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
.paymentInfo(PaymentInfo.builder()
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.paymentToken(PAYMENT_TOKEN)
.amount(AMOUNT_WITHOUT_CENTS)
.fee(FEE_WITH_SINGLE_DIGIT_CENTS)
.remittanceInformation(REMITTANCE_INFORMATION)
.IUR(IUR)
.build())
+ .transactionDetails(TransactionDetails.builder()
+ .wallet(WalletItem.builder()
+ .info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build())
+ .onboardingChannel(PAGO_PA_CHANNEL_IO)
+ .build())
+ .transaction(Transaction.builder()
+ .idTransaction(ID_TRANSACTION)
+ .grandTotal(GRAND_TOTAL_LONG)
+ .amount(AMOUNT_LONG)
+ .fee(FEE_LONG)
+ .rrn(RRN)
+ .numAut(AUTH_CODE)
+ .creationDate(DATE_TIME_TIMESTAMP_ZONED_MILLISECONDS_DST_WINTER)
+ .psp(TransactionPsp.builder()
+ .businessName(PSP_NAME)
+ .build())
+ .origin(PAGOPA_PA_CHANNEL_ID)
+ .build())
+ .build())
.eventStatus(BizEventStatusType.DONE)
.build();
- ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE);
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
+
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
+
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
- assertEquals(PAYMENT_TOKEN, transaction.getId());
- assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp());
- assertEquals(FORMATTED_AMOUNT, transaction.getAmount());
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_WINTER, transaction.getTimestamp());
+ assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
- assertNull(transaction.getPsp().getFee().getAmount());
+ assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
assertEquals(PSP_NAME, transaction.getPsp().getName());
assertEquals(PSP_CITY, transaction.getPsp().getCity());
assertEquals(PSP_COMPANY, transaction.getPsp().getCompanyName());
@@ -392,17 +448,15 @@ void mapTemplateWithoutTransactionDetailsSuccess() throws Exception {
assertEquals(PSP_ADDRESS, transaction.getPsp().getAddress());
assertEquals(PSP_BUILDING_NUMBER, transaction.getPsp().getBuildingNumber());
assertEquals(PSP_PROVINCE, transaction.getPsp().getProvince());
- assertEquals(PAYMENT_TOKEN, transaction.getRrn());
- assertNull(transaction.getPaymentMethod().getName());
- assertNull(transaction.getPaymentMethod().getLogo());
- assertNull(transaction.getPaymentMethod().getAccountHolder());
- assertNull(transaction.getAuthCode());
- assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor());
- assertFalse(transaction.isProcessedByPagoPA());
+ assertEquals(RRN, transaction.getRrn());
+ assertEquals(BRAND, transaction.getPaymentMethod().getName());
+ assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
+ assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
+ assertEquals(AUTH_CODE, transaction.getAuthCode());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
+ assertTrue(transaction.isProcessedByPagoPA());
- it.gov.pagopa.receipt.pdf.helpdesk.model.template.UserData userData = receiptPdfTemplate.getUser().getData();
- assertEquals(PAYER_VALID_CF, userData.getTaxCode());
- assertEquals(PAYER_FULL_NAME, userData.getFullName());
+ assertNull(receiptPdfTemplate.getUser());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
@@ -417,9 +471,10 @@ void mapTemplateWithoutTransactionDetailsSuccess() throws Exception {
}
@Test
- void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() throws Exception {
+ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannelAndDateZonedWithMillisecondsDSTSummer() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
+ .idPaymentManager(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.modelType(MODEL_TYPE_IUV_CODE)
@@ -438,24 +493,49 @@ void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() throws Excepti
.build())
.payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
.paymentInfo(PaymentInfo.builder()
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .paymentToken(PAYMENT_TOKEN)
.amount(AMOUNT_WITHOUT_CENTS)
.fee(FEE_WITH_SINGLE_DIGIT_CENTS)
.remittanceInformation(REMITTANCE_INFORMATION)
.IUR(IUR)
.build())
+ .transactionDetails(TransactionDetails.builder()
+ .wallet(WalletItem.builder()
+ .info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build())
+ .onboardingChannel(PAGO_PA_CHANNEL_IO)
+ .build())
+ .transaction(Transaction.builder()
+ .idTransaction(ID_TRANSACTION)
+ .grandTotal(GRAND_TOTAL_LONG)
+ .amount(AMOUNT_LONG)
+ .fee(FEE_LONG)
+ .rrn(RRN)
+ .numAut(AUTH_CODE)
+ .creationDate(DATE_TIME_TIMESTAMP_ZONED_MILLISECONDS_DST_SUMMER)
+ .psp(TransactionPsp.builder()
+ .businessName(PSP_NAME)
+ .build())
+ .origin(PAGOPA_PA_CHANNEL_ID)
+ .build())
+ .build())
.eventStatus(BizEventStatusType.DONE)
.build();
- ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE);
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
+
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
+
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
- assertEquals(IUR, transaction.getId());
- assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp());
- assertEquals(FORMATTED_AMOUNT, transaction.getAmount());
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_SUMMER, transaction.getTimestamp());
+ assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
- assertNull(transaction.getPsp().getFee().getAmount());
+ assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
assertEquals(PSP_NAME, transaction.getPsp().getName());
assertEquals(PSP_CITY, transaction.getPsp().getCity());
assertEquals(PSP_COMPANY, transaction.getPsp().getCompanyName());
@@ -463,16 +543,15 @@ void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() throws Excepti
assertEquals(PSP_ADDRESS, transaction.getPsp().getAddress());
assertEquals(PSP_BUILDING_NUMBER, transaction.getPsp().getBuildingNumber());
assertEquals(PSP_PROVINCE, transaction.getPsp().getProvince());
- assertEquals(IUR, transaction.getRrn());
- assertNull(transaction.getPaymentMethod().getName());
- assertNull(transaction.getPaymentMethod().getLogo());
- assertNull(transaction.getPaymentMethod().getAccountHolder());
- assertNull(transaction.getAuthCode());
- assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor());
+ assertEquals(RRN, transaction.getRrn());
+ assertEquals(BRAND, transaction.getPaymentMethod().getName());
+ assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
+ assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
+ assertEquals(AUTH_CODE, transaction.getAuthCode());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
+ assertTrue(transaction.isProcessedByPagoPA());
- it.gov.pagopa.receipt.pdf.helpdesk.model.template.UserData userData = receiptPdfTemplate.getUser().getData();
- assertEquals(PAYER_VALID_CF, userData.getTaxCode());
- assertEquals(PAYER_FULL_NAME, userData.getFullName());
+ assertNull(receiptPdfTemplate.getUser());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
@@ -487,9 +566,10 @@ void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() throws Excepti
}
@Test
- void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception {
+ void mapTemplateAllFieldsSuccessCompleteTemplateAndPagoPaChannelOnTransactionOrigin() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
+ .idPaymentManager(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.modelType(MODEL_TYPE_IUV_CODE)
@@ -503,12 +583,12 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception {
.psp(PSP_NAME)
.build())
.debtor(Debtor.builder()
- .fullName(DEBTOR_FULL_NAME_INVALID)
+ .fullName(DEBTOR_FULL_NAME)
.entityUniqueIdentifierValue(DEBTOR_VALID_CF)
.build())
.payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
.paymentInfo(PaymentInfo.builder()
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.paymentToken(PAYMENT_TOKEN)
.amount(AMOUNT_WITHOUT_CENTS)
.fee(FEE_WITH_SINGLE_DIGIT_CENTS)
@@ -518,7 +598,7 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception {
.transactionDetails(TransactionDetails.builder()
.wallet(WalletItem.builder()
.info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build())
- .onboardingChannel(PAGO_PA_CHANNEL_IO)
+ .onboardingChannel(PAGO_PA_CHANNEL_IO_PAY)
.build())
.transaction(Transaction.builder()
.idTransaction(ID_TRANSACTION)
@@ -527,21 +607,27 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception {
.fee(FEE_LONG)
.rrn(RRN)
.numAut(AUTH_CODE)
- .creationDate(DATE_TIME_TIMESTAMP_ZONED)
+ .creationDate(DATE_TIME_TIMESTAMP_ZONED_DST_WINTER)
.psp(TransactionPsp.builder()
.businessName(PSP_NAME)
.build())
+ .origin(PAGOPA_PA_CHANNEL_ID)
.build())
.build())
.eventStatus(BizEventStatusType.DONE)
.build();
- ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE);
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
+
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
+
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
- assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId());
- assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp());
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_WINTER, transaction.getTimestamp());
assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
@@ -557,17 +643,15 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception {
assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
assertEquals(AUTH_CODE, transaction.getAuthCode());
- assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
assertTrue(transaction.isProcessedByPagoPA());
- it.gov.pagopa.receipt.pdf.helpdesk.model.template.UserData userData = receiptPdfTemplate.getUser().getData();
- assertEquals(PAYER_VALID_CF, userData.getTaxCode());
- assertEquals(PAYER_FULL_NAME, userData.getFullName());
+ assertNull(receiptPdfTemplate.getUser());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
assertEquals(FORMATTED_AMOUNT, cart.getItems().get(0).getAmount());
- assertNull(cart.getItems().get(0).getDebtor().getFullName());
+ assertEquals(DEBTOR_FULL_NAME, cart.getItems().get(0).getDebtor().getFullName());
assertEquals(DEBTOR_VALID_CF, cart.getItems().get(0).getDebtor().getTaxCode());
assertEquals(REMITTANCE_INFORMATION, cart.getItems().get(0).getSubject());
assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getName());
@@ -577,9 +661,10 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() throws Exception {
}
@Test
- void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception {
+ void mapTemplateAllFieldsSuccessCompleteTemplateAndPagoPaChannelOnChannelId() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
+ .idPaymentManager(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.modelType(MODEL_TYPE_IUV_CODE)
@@ -593,12 +678,12 @@ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception
.psp(PSP_NAME)
.build())
.debtor(Debtor.builder()
- .fullName(DEBTOR_FULL_NAME_SPECIAL_CHAR)
+ .fullName(DEBTOR_FULL_NAME)
.entityUniqueIdentifierValue(DEBTOR_VALID_CF)
.build())
.payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
.paymentInfo(PaymentInfo.builder()
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.paymentToken(PAYMENT_TOKEN)
.amount(AMOUNT_WITHOUT_CENTS)
.fee(FEE_WITH_SINGLE_DIGIT_CENTS)
@@ -608,8 +693,9 @@ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception
.transactionDetails(TransactionDetails.builder()
.wallet(WalletItem.builder()
.info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build())
- .onboardingChannel(PAGO_PA_CHANNEL_IO)
+ .onboardingChannel(PAGO_PA_CHANNEL_IO_PAY)
.build())
+ .info(InfoTransaction.builder().clientId(PAGOPA_PA_CHANNEL_ID).build())
.transaction(Transaction.builder()
.idTransaction(ID_TRANSACTION)
.grandTotal(GRAND_TOTAL_LONG)
@@ -617,7 +703,7 @@ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception
.fee(FEE_LONG)
.rrn(RRN)
.numAut(AUTH_CODE)
- .creationDate(DATE_TIME_TIMESTAMP_ZONED)
+ .creationDate(DATE_TIME_TIMESTAMP_ZONED_DST_WINTER)
.psp(TransactionPsp.builder()
.businessName(PSP_NAME)
.build())
@@ -625,13 +711,18 @@ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception
.build())
.eventStatus(BizEventStatusType.DONE)
.build();
- ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE);
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
+
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
+
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
- assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId());
- assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp());
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_WINTER, transaction.getTimestamp());
assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
@@ -647,17 +738,15 @@ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception
assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
assertEquals(AUTH_CODE, transaction.getAuthCode());
- assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
assertTrue(transaction.isProcessedByPagoPA());
- it.gov.pagopa.receipt.pdf.helpdesk.model.template.UserData userData = receiptPdfTemplate.getUser().getData();
- assertEquals(PAYER_VALID_CF, userData.getTaxCode());
- assertEquals(PAYER_FULL_NAME, userData.getFullName());
+ assertNull(receiptPdfTemplate.getUser());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
assertEquals(FORMATTED_AMOUNT, cart.getItems().get(0).getAmount());
- assertEquals(DEBTOR_FULL_NAME_SPECIAL_CHAR_FORMATTED, cart.getItems().get(0).getDebtor().getFullName());
+ assertEquals(DEBTOR_FULL_NAME, cart.getItems().get(0).getDebtor().getFullName());
assertEquals(DEBTOR_VALID_CF, cart.getItems().get(0).getDebtor().getTaxCode());
assertEquals(REMITTANCE_INFORMATION, cart.getItems().get(0).getSubject());
assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getName());
@@ -667,12 +756,12 @@ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() throws Exception
}
@Test
- void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() throws Exception {
+ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
- .iuv(IUV)
- .modelType(MODEL_TYPE_IUV_CODE)
+ .noticeNumber(NOTICE_NUMBER)
+ .modelType(MODEL_TYPE_NOTICE_CODE)
.build())
.creditor(Creditor.builder()
.companyName(COMPANY_NAME)
@@ -683,48 +772,35 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() throws Exceptio
.psp(PSP_NAME)
.build())
.debtor(Debtor.builder()
- .fullName(DEBTOR_VALID_CF)
+ .fullName(DEBTOR_FULL_NAME)
.entityUniqueIdentifierValue(DEBTOR_VALID_CF)
.build())
.payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
.paymentInfo(PaymentInfo.builder()
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.paymentToken(PAYMENT_TOKEN)
.amount(AMOUNT_WITHOUT_CENTS)
.fee(FEE_WITH_SINGLE_DIGIT_CENTS)
.remittanceInformation(REMITTANCE_INFORMATION)
.IUR(IUR)
.build())
- .transactionDetails(TransactionDetails.builder()
- .wallet(WalletItem.builder()
- .info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build())
- .onboardingChannel(PAGO_PA_CHANNEL_IO)
- .build())
- .transaction(Transaction.builder()
- .idTransaction(ID_TRANSACTION)
- .grandTotal(GRAND_TOTAL_LONG)
- .amount(AMOUNT_LONG)
- .fee(FEE_LONG)
- .rrn(RRN)
- .numAut(AUTH_CODE)
- .creationDate(DATE_TIME_TIMESTAMP_ZONED)
- .psp(TransactionPsp.builder()
- .businessName(PSP_NAME)
- .build())
- .build())
- .build())
.eventStatus(BizEventStatusType.DONE)
.build();
- ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE);
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
+
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
+
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
- assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId());
- assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp());
- assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_WINTER, transaction.getTimestamp());
+ assertEquals(FORMATTED_AMOUNT, transaction.getAmount());
assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
- assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
+ assertNull(transaction.getPsp().getFee().getAmount());
assertEquals(PSP_NAME, transaction.getPsp().getName());
assertEquals(PSP_CITY, transaction.getPsp().getCity());
assertEquals(PSP_COMPANY, transaction.getPsp().getCompanyName());
@@ -732,109 +808,860 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() throws Exceptio
assertEquals(PSP_ADDRESS, transaction.getPsp().getAddress());
assertEquals(PSP_BUILDING_NUMBER, transaction.getPsp().getBuildingNumber());
assertEquals(PSP_PROVINCE, transaction.getPsp().getProvince());
- assertEquals(RRN, transaction.getRrn());
- assertEquals(BRAND, transaction.getPaymentMethod().getName());
- assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
- assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
- assertEquals(AUTH_CODE, transaction.getAuthCode());
- assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor());
- assertTrue(transaction.isProcessedByPagoPA());
+ assertEquals(PAYMENT_TOKEN, transaction.getRrn());
+ assertNull(transaction.getPaymentMethod().getName());
+ assertNull(transaction.getPaymentMethod().getLogo());
+ assertNull(transaction.getPaymentMethod().getAccountHolder());
+ assertNull(transaction.getAuthCode());
+ assertTrue(transaction.isRequestedByDebtor());
+ assertFalse(transaction.isProcessedByPagoPA());
- it.gov.pagopa.receipt.pdf.helpdesk.model.template.UserData userData = receiptPdfTemplate.getUser().getData();
- assertEquals(PAYER_VALID_CF, userData.getTaxCode());
- assertEquals(PAYER_FULL_NAME, userData.getFullName());
+ it.gov.pagopa.receipt.pdf.helpdesk.model.template.User user = receiptPdfTemplate.getUser();
+ assertNull(user);
it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
assertEquals(FORMATTED_AMOUNT, cart.getItems().get(0).getAmount());
- assertNull(cart.getItems().get(0).getDebtor().getFullName());
+ assertEquals(DEBTOR_FULL_NAME, cart.getItems().get(0).getDebtor().getFullName());
assertEquals(DEBTOR_VALID_CF, cart.getItems().get(0).getDebtor().getTaxCode());
assertEquals(REMITTANCE_INFORMATION, cart.getItems().get(0).getSubject());
assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getName());
assertEquals(ID_PA, cart.getItems().get(0).getPayee().getTaxCode());
- assertEquals(MODEL_TYPE_IUV_TEXT, cart.getItems().get(0).getRefNumber().getType());
- assertEquals(IUV, cart.getItems().get(0).getRefNumber().getValue());
+ assertEquals(MODEL_TYPE_NOTICE_TEXT, cart.getItems().get(0).getRefNumber().getType());
+ assertEquals(NOTICE_NUMBER, cart.getItems().get(0).getRefNumber().getValue());
}
@Test
- void mapTemplateLeastAmountOfInfoSuccess() {
+ void mapTemplateWithoutTransactionDetailsSuccess() {
BizEvent event = BizEvent.builder()
- .paymentInfo(PaymentInfo.builder()
- .IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
- .remittanceInformation(REMITTANCE_INFORMATION)
- .amount(AMOUNT_WITHOUT_CENTS)
+ .id(BIZ_EVENT_ID)
+ .debtorPosition(DebtorPosition.builder()
+ .iuv(IUV)
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .build())
+ .creditor(Creditor.builder()
+ .companyName(COMPANY_NAME)
+ .idPA(ID_PA)
.build())
.psp(Psp.builder()
.idPsp(ID_PSP)
.psp(PSP_NAME)
.build())
- .payer(Payer.builder()
- .fullName(PAYER_FULL_NAME)
- .entityUniqueIdentifierValue(PAYER_VALID_CF)
- .build())
- .debtorPosition(DebtorPosition.builder()
- .modelType(MODEL_TYPE_IUV_CODE)
- .iuv(IUV)
- .build())
.debtor(Debtor.builder()
+ .fullName(DEBTOR_FULL_NAME)
.entityUniqueIdentifierValue(DEBTOR_VALID_CF)
.build())
- .creditor(Creditor.builder()
- .idPA(ID_PA)
+ .payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
+ .paymentInfo(PaymentInfo.builder()
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .paymentToken(PAYMENT_TOKEN)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .fee(FEE_WITH_SINGLE_DIGIT_CENTS)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .IUR(IUR)
.build())
- .transactionDetails(TransactionDetails.builder()
- .transaction(Transaction.builder()
- .grandTotal(GRAND_TOTAL_LONG).build()
- )
- .build()
- )
+ .eventStatus(BizEventStatusType.DONE)
.build();
- assertDoesNotThrow(() -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
- }
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
- @Test
- void mapTemplateNoTransactionIdError() {
- BizEvent event = new BizEvent();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
- assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
- assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_ID), e.getMessage());
- }
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
- @Test
- void mapTemplateNoTransactionTimestampError() {
- BizEvent event = BizEvent.builder().paymentInfo(PaymentInfo.builder().IUR(IUR).build()).build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
- assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
- assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_TIMESTAMP), e.getMessage());
+ it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_WINTER, transaction.getTimestamp());
+ assertEquals(FORMATTED_AMOUNT, transaction.getAmount());
+ assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
+ assertNull(transaction.getPsp().getFee().getAmount());
+ assertEquals(PSP_NAME, transaction.getPsp().getName());
+ assertEquals(PSP_CITY, transaction.getPsp().getCity());
+ assertEquals(PSP_COMPANY, transaction.getPsp().getCompanyName());
+ assertEquals(PSP_POSTAL_CODE, transaction.getPsp().getPostalCode());
+ assertEquals(PSP_ADDRESS, transaction.getPsp().getAddress());
+ assertEquals(PSP_BUILDING_NUMBER, transaction.getPsp().getBuildingNumber());
+ assertEquals(PSP_PROVINCE, transaction.getPsp().getProvince());
+ assertEquals(PAYMENT_TOKEN, transaction.getRrn());
+ assertNull(transaction.getPaymentMethod().getName());
+ assertNull(transaction.getPaymentMethod().getLogo());
+ assertNull(transaction.getPaymentMethod().getAccountHolder());
+ assertNull(transaction.getAuthCode());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
+ assertFalse(transaction.isProcessedByPagoPA());
+
+ assertNull(receiptPdfTemplate.getUser());
+
+ it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
+ assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
+ assertEquals(FORMATTED_AMOUNT, cart.getItems().get(0).getAmount());
+ assertEquals(DEBTOR_FULL_NAME, cart.getItems().get(0).getDebtor().getFullName());
+ assertEquals(DEBTOR_VALID_CF, cart.getItems().get(0).getDebtor().getTaxCode());
+ assertEquals(REMITTANCE_INFORMATION, cart.getItems().get(0).getSubject());
+ assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getName());
+ assertEquals(ID_PA, cart.getItems().get(0).getPayee().getTaxCode());
+ assertEquals(MODEL_TYPE_IUV_TEXT, cart.getItems().get(0).getRefNumber().getType());
+ assertEquals(IUV, cart.getItems().get(0).getRefNumber().getValue());
}
@Test
- void mapTemplateNoTransactionAmountError() {
+ void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .debtorPosition(DebtorPosition.builder()
+ .iuv(IUV)
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .build())
+ .creditor(Creditor.builder()
+ .companyName(COMPANY_NAME)
+ .idPA(ID_PA)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtor(Debtor.builder()
+ .fullName(DEBTOR_FULL_NAME)
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
.paymentInfo(PaymentInfo.builder()
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_SUMMER)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .fee(FEE_WITH_SINGLE_DIGIT_CENTS)
+ .remittanceInformation(REMITTANCE_INFORMATION)
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
.build())
+ .eventStatus(BizEventStatusType.DONE)
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
- assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
- assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_AMOUNT), e.getMessage());
- }
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
- @Test
- void mapTemplateNoPspError() {
- BizEvent event = BizEvent.builder()
- .paymentInfo(PaymentInfo.builder()
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
+
+ assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
+
+ it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_SUMMER, transaction.getTimestamp());
+ assertEquals(FORMATTED_AMOUNT, transaction.getAmount());
+ assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
+ assertNull(transaction.getPsp().getFee().getAmount());
+ assertEquals(PSP_NAME, transaction.getPsp().getName());
+ assertEquals(PSP_CITY, transaction.getPsp().getCity());
+ assertEquals(PSP_COMPANY, transaction.getPsp().getCompanyName());
+ assertEquals(PSP_POSTAL_CODE, transaction.getPsp().getPostalCode());
+ assertEquals(PSP_ADDRESS, transaction.getPsp().getAddress());
+ assertEquals(PSP_BUILDING_NUMBER, transaction.getPsp().getBuildingNumber());
+ assertEquals(PSP_PROVINCE, transaction.getPsp().getProvince());
+ assertEquals(IUR, transaction.getRrn());
+ assertNull(transaction.getPaymentMethod().getName());
+ assertNull(transaction.getPaymentMethod().getLogo());
+ assertNull(transaction.getPaymentMethod().getAccountHolder());
+ assertNull(transaction.getAuthCode());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
+
+ assertNull(receiptPdfTemplate.getUser());
+
+ it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
+ assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
+ assertEquals(FORMATTED_AMOUNT, cart.getItems().get(0).getAmount());
+ assertEquals(DEBTOR_FULL_NAME, cart.getItems().get(0).getDebtor().getFullName());
+ assertEquals(DEBTOR_VALID_CF, cart.getItems().get(0).getDebtor().getTaxCode());
+ assertEquals(REMITTANCE_INFORMATION, cart.getItems().get(0).getSubject());
+ assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getName());
+ assertEquals(ID_PA, cart.getItems().get(0).getPayee().getTaxCode());
+ assertEquals(MODEL_TYPE_IUV_TEXT, cart.getItems().get(0).getRefNumber().getType());
+ assertEquals(IUV, cart.getItems().get(0).getRefNumber().getValue());
+ }
+
+ @Test
+ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .idPaymentManager(BIZ_EVENT_ID)
+ .debtorPosition(DebtorPosition.builder()
+ .iuv(IUV)
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .build())
+ .creditor(Creditor.builder()
+ .companyName(COMPANY_NAME)
+ .idPA(ID_PA)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtor(Debtor.builder()
+ .fullName(DEBTOR_FULL_NAME_INVALID)
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
+ .paymentInfo(PaymentInfo.builder()
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .paymentToken(PAYMENT_TOKEN)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .fee(FEE_WITH_SINGLE_DIGIT_CENTS)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .IUR(IUR)
+ .build())
+ .transactionDetails(TransactionDetails.builder()
+ .wallet(WalletItem.builder()
+ .info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build())
+ .onboardingChannel(PAGO_PA_CHANNEL_IO)
+ .build())
+ .transaction(Transaction.builder()
+ .idTransaction(ID_TRANSACTION)
+ .grandTotal(GRAND_TOTAL_LONG)
+ .amount(AMOUNT_LONG)
+ .fee(FEE_LONG)
+ .rrn(RRN)
+ .numAut(AUTH_CODE)
+ .creationDate(DATE_TIME_TIMESTAMP_ZONED_DST_WINTER)
+ .psp(TransactionPsp.builder()
+ .businessName(PSP_NAME)
+ .build())
+ .origin(PAGOPA_PA_CHANNEL_ID)
+ .build())
+ .build())
+ .eventStatus(BizEventStatusType.DONE)
+ .build();
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
+
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
+
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
+
+ assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
+
+ it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_WINTER, transaction.getTimestamp());
+ assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
+ assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
+ assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
+ assertEquals(PSP_NAME, transaction.getPsp().getName());
+ assertEquals(PSP_CITY, transaction.getPsp().getCity());
+ assertEquals(PSP_COMPANY, transaction.getPsp().getCompanyName());
+ assertEquals(PSP_POSTAL_CODE, transaction.getPsp().getPostalCode());
+ assertEquals(PSP_ADDRESS, transaction.getPsp().getAddress());
+ assertEquals(PSP_BUILDING_NUMBER, transaction.getPsp().getBuildingNumber());
+ assertEquals(PSP_PROVINCE, transaction.getPsp().getProvince());
+ assertEquals(RRN, transaction.getRrn());
+ assertEquals(BRAND, transaction.getPaymentMethod().getName());
+ assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
+ assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
+ assertEquals(AUTH_CODE, transaction.getAuthCode());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
+ assertTrue(transaction.isProcessedByPagoPA());
+
+ assertNull(receiptPdfTemplate.getUser());
+
+ it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
+ assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
+ assertEquals(FORMATTED_AMOUNT, cart.getItems().get(0).getAmount());
+ assertNull(cart.getItems().get(0).getDebtor().getFullName());
+ assertEquals(DEBTOR_VALID_CF, cart.getItems().get(0).getDebtor().getTaxCode());
+ assertEquals(REMITTANCE_INFORMATION, cart.getItems().get(0).getSubject());
+ assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getName());
+ assertEquals(ID_PA, cart.getItems().get(0).getPayee().getTaxCode());
+ assertEquals(MODEL_TYPE_IUV_TEXT, cart.getItems().get(0).getRefNumber().getType());
+ assertEquals(IUV, cart.getItems().get(0).getRefNumber().getValue());
+ }
+
+ @Test
+ void mapTemplateAllFieldsSuccessDebtorFullNameWithSpecialChar() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .idPaymentManager(BIZ_EVENT_ID)
+ .debtorPosition(DebtorPosition.builder()
+ .iuv(IUV)
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .build())
+ .creditor(Creditor.builder()
+ .companyName(COMPANY_NAME)
+ .idPA(ID_PA)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtor(Debtor.builder()
+ .fullName(DEBTOR_FULL_NAME_SPECIAL_CHAR)
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
+ .paymentInfo(PaymentInfo.builder()
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .paymentToken(PAYMENT_TOKEN)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .fee(FEE_WITH_SINGLE_DIGIT_CENTS)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .IUR(IUR)
+ .build())
+ .transactionDetails(TransactionDetails.builder()
+ .wallet(WalletItem.builder()
+ .info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build())
+ .onboardingChannel(PAGO_PA_CHANNEL_IO)
+ .build())
+ .transaction(Transaction.builder()
+ .idTransaction(ID_TRANSACTION)
+ .grandTotal(GRAND_TOTAL_LONG)
+ .amount(AMOUNT_LONG)
+ .fee(FEE_LONG)
+ .rrn(RRN)
+ .numAut(AUTH_CODE)
+ .creationDate(DATE_TIME_TIMESTAMP_ZONED_DST_WINTER)
+ .psp(TransactionPsp.builder()
+ .businessName(PSP_NAME)
+ .build())
+ .origin(PAGOPA_PA_CHANNEL_ID)
+ .build())
+ .build())
+ .eventStatus(BizEventStatusType.DONE)
+ .build();
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
+
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
+
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
+
+ assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
+
+ it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_WINTER, transaction.getTimestamp());
+ assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
+ assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
+ assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
+ assertEquals(PSP_NAME, transaction.getPsp().getName());
+ assertEquals(PSP_CITY, transaction.getPsp().getCity());
+ assertEquals(PSP_COMPANY, transaction.getPsp().getCompanyName());
+ assertEquals(PSP_POSTAL_CODE, transaction.getPsp().getPostalCode());
+ assertEquals(PSP_ADDRESS, transaction.getPsp().getAddress());
+ assertEquals(PSP_BUILDING_NUMBER, transaction.getPsp().getBuildingNumber());
+ assertEquals(PSP_PROVINCE, transaction.getPsp().getProvince());
+ assertEquals(RRN, transaction.getRrn());
+ assertEquals(BRAND, transaction.getPaymentMethod().getName());
+ assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
+ assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
+ assertEquals(AUTH_CODE, transaction.getAuthCode());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
+ assertTrue(transaction.isProcessedByPagoPA());
+
+ assertNull(receiptPdfTemplate.getUser());
+
+ it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
+ assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
+ assertEquals(FORMATTED_AMOUNT, cart.getItems().get(0).getAmount());
+ assertEquals(DEBTOR_FULL_NAME_SPECIAL_CHAR_FORMATTED, cart.getItems().get(0).getDebtor().getFullName());
+ assertEquals(DEBTOR_VALID_CF, cart.getItems().get(0).getDebtor().getTaxCode());
+ assertEquals(REMITTANCE_INFORMATION, cart.getItems().get(0).getSubject());
+ assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getName());
+ assertEquals(ID_PA, cart.getItems().get(0).getPayee().getTaxCode());
+ assertEquals(MODEL_TYPE_IUV_TEXT, cart.getItems().get(0).getRefNumber().getType());
+ assertEquals(IUV, cart.getItems().get(0).getRefNumber().getValue());
+ }
+
+ @Test
+ void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .idPaymentManager(BIZ_EVENT_ID)
+ .debtorPosition(DebtorPosition.builder()
+ .iuv(IUV)
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .build())
+ .creditor(Creditor.builder()
+ .companyName(COMPANY_NAME)
+ .idPA(ID_PA)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtor(Debtor.builder()
+ .fullName(DEBTOR_VALID_CF)
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
+ .paymentInfo(PaymentInfo.builder()
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .paymentToken(PAYMENT_TOKEN)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .fee(FEE_WITH_SINGLE_DIGIT_CENTS)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .IUR(IUR)
+ .build())
+ .transactionDetails(TransactionDetails.builder()
+ .wallet(WalletItem.builder()
+ .info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build())
+ .onboardingChannel(PAGO_PA_CHANNEL_IO)
+ .build())
+ .transaction(Transaction.builder()
+ .idTransaction(ID_TRANSACTION)
+ .grandTotal(GRAND_TOTAL_LONG)
+ .amount(AMOUNT_LONG)
+ .fee(FEE_LONG)
+ .rrn(RRN)
+ .numAut(AUTH_CODE)
+ .creationDate(DATE_TIME_TIMESTAMP_ZONED_DST_WINTER)
+ .psp(TransactionPsp.builder()
+ .businessName(PSP_NAME)
+ .build())
+ .origin(PAGOPA_PA_CHANNEL_ID)
+ .build())
+ .build())
+ .eventStatus(BizEventStatusType.DONE)
+ .build();
+ Receipt receipt = Receipt.builder().eventData(EventData.builder().cart(List.of(CartItem.builder().subject(REMITTANCE_INFORMATION).build())).build()).build();
+
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, receipt)));
+
+ ReceiptPDFTemplate receiptPdfTemplate = atomicReference.get();
+
+ assertNotNull(receiptPdfTemplate);
+ assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId());
+
+ it.gov.pagopa.receipt.pdf.helpdesk.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
+ assertEquals(DATE_TIME_TIMESTAMP_FORMATTED_DST_WINTER, transaction.getTimestamp());
+ assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
+ assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
+ assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
+ assertEquals(PSP_NAME, transaction.getPsp().getName());
+ assertEquals(PSP_CITY, transaction.getPsp().getCity());
+ assertEquals(PSP_COMPANY, transaction.getPsp().getCompanyName());
+ assertEquals(PSP_POSTAL_CODE, transaction.getPsp().getPostalCode());
+ assertEquals(PSP_ADDRESS, transaction.getPsp().getAddress());
+ assertEquals(PSP_BUILDING_NUMBER, transaction.getPsp().getBuildingNumber());
+ assertEquals(PSP_PROVINCE, transaction.getPsp().getProvince());
+ assertEquals(RRN, transaction.getRrn());
+ assertEquals(BRAND, transaction.getPaymentMethod().getName());
+ assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
+ assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
+ assertEquals(AUTH_CODE, transaction.getAuthCode());
+ assertEquals(GENERATED_BY_DEBTOR, transaction.isRequestedByDebtor());
+ assertTrue(transaction.isProcessedByPagoPA());
+
+ assertNull(receiptPdfTemplate.getUser());
+
+ it.gov.pagopa.receipt.pdf.helpdesk.model.template.Cart cart = receiptPdfTemplate.getCart();
+ assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
+ assertEquals(FORMATTED_AMOUNT, cart.getItems().get(0).getAmount());
+ assertNull(cart.getItems().get(0).getDebtor().getFullName());
+ assertEquals(DEBTOR_VALID_CF, cart.getItems().get(0).getDebtor().getTaxCode());
+ assertEquals(REMITTANCE_INFORMATION, cart.getItems().get(0).getSubject());
+ assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getName());
+ assertEquals(ID_PA, cart.getItems().get(0).getPayee().getTaxCode());
+ assertEquals(MODEL_TYPE_IUV_TEXT, cart.getItems().get(0).getRefNumber().getType());
+ assertEquals(IUV, cart.getItems().get(0).getRefNumber().getValue());
+ }
+
+ @Test
+ void mapTemplateLeastAmountOfInfoSuccessPayer() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
+ .IUR(IUR)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .payer(Payer.builder()
+ .fullName(PAYER_FULL_NAME)
+ .entityUniqueIdentifierValue(PAYER_VALID_CF)
+ .build())
+ .debtorPosition(DebtorPosition.builder()
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .iuv(IUV)
+ .build())
+ .debtor(Debtor.builder()
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .creditor(Creditor.builder()
+ .idPA(ID_PA)
+ .build())
+ .build();
+ assertDoesNotThrow(() -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
+ }
+
+ @Test
+ void mapTemplateLeastAmountOfInfoSuccessDebtor() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
+ .IUR(IUR)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtorPosition(DebtorPosition.builder()
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .iuv(IUV)
+ .build())
+ .debtor(Debtor.builder()
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .creditor(Creditor.builder()
+ .idPA(ID_PA)
+ .build())
+ .build();
+ assertDoesNotThrow(() -> buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, Receipt.builder().build()));
+ }
+
+ @Test
+ void mapTemplateSuccessRequestByDebtorTrueWithoutPayerAndUserFiscalCode() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
+ .IUR(IUR)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtorPosition(DebtorPosition.builder()
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .iuv(IUV)
+ .build())
+ .debtor(Debtor.builder()
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .creditor(Creditor.builder()
+ .idPA(ID_PA)
+ .build())
+ .transactionDetails(TransactionDetails.builder()
+ .transaction(Transaction.builder()
+ .grandTotal(GRAND_TOTAL_LONG).build()
+ )
+ .build()
+ )
+ .build();
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, Receipt.builder().build())));
+
+ ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get();
+ assertTrue(receiptPDFTemplate.getTransaction().isRequestedByDebtor());
+ }
+
+ @Test
+ void mapTemplateSuccessRequestByDebtorTrueWithPayerFiscalCodeDifferent() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
+ .IUR(IUR)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtorPosition(DebtorPosition.builder()
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .iuv(IUV)
+ .build())
+ .debtor(Debtor.builder()
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .payer(Payer.builder()
+ .entityUniqueIdentifierValue(PAYER_VALID_CF)
+ .build())
+ .creditor(Creditor.builder()
+ .idPA(ID_PA)
+ .build())
+ .transactionDetails(TransactionDetails.builder()
+ .transaction(Transaction.builder()
+ .grandTotal(GRAND_TOTAL_LONG).build()
+ )
+ .build()
+ )
+ .build();
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, Receipt.builder().build())));
+
+ ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get();
+ assertTrue(receiptPDFTemplate.getTransaction().isRequestedByDebtor());
+ }
+
+ @Test
+ void mapTemplateSuccessRequestByDebtorTrueWithUserFiscalCodeDifferent() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
+ .IUR(IUR)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtorPosition(DebtorPosition.builder()
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .iuv(IUV)
+ .build())
+ .debtor(Debtor.builder()
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .creditor(Creditor.builder()
+ .idPA(ID_PA)
+ .build())
+ .transactionDetails(TransactionDetails.builder()
+ .transaction(Transaction.builder()
+ .grandTotal(GRAND_TOTAL_LONG).build()
+ )
+ .user(User.builder().fiscalCode(PAYER_VALID_CF).build())
+ .build()
+ )
+ .build();
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, Receipt.builder().build())));
+
+ ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get();
+ assertTrue(receiptPDFTemplate.getTransaction().isRequestedByDebtor());
+ }
+
+ @Test
+ void mapTemplateSuccessRequestByDebtorFalseWithPayerAndUserFiscalCodeEqual() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
+ .IUR(IUR)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtorPosition(DebtorPosition.builder()
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .iuv(IUV)
+ .build())
+ .debtor(Debtor.builder()
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .payer(Payer.builder()
+ .fullName(PAYER_FULL_NAME)
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .creditor(Creditor.builder()
+ .idPA(ID_PA)
+ .build())
+ .transactionDetails(TransactionDetails.builder()
+ .transaction(Transaction.builder()
+ .grandTotal(GRAND_TOTAL_LONG).build()
+ )
+ .user(User.builder().fiscalCode(DEBTOR_VALID_CF).build())
+ .build()
+ )
+ .build();
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_DEBTOR, Receipt.builder().build())));
+
+ ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get();
+ assertFalse(receiptPDFTemplate.getTransaction().isRequestedByDebtor());
+ }
+
+ @Test
+ void mapTemplateSuccessRequestByDebtorFalseWhenGeneratedByPayer() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
+ .IUR(IUR)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtorPosition(DebtorPosition.builder()
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .iuv(IUV)
+ .build())
+ .debtor(Debtor.builder()
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .payer(Payer.builder()
+ .fullName(PAYER_FULL_NAME)
+ .entityUniqueIdentifierValue(PAYER_VALID_CF)
+ .build())
+ .creditor(Creditor.builder()
+ .idPA(ID_PA)
+ .build())
+ .transactionDetails(TransactionDetails.builder()
+ .transaction(Transaction.builder()
+ .grandTotal(GRAND_TOTAL_LONG).build()
+ )
+ .build()
+ )
+ .build();
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())));
+
+ ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get();
+ assertFalse(receiptPDFTemplate.getTransaction().isRequestedByDebtor());
+ }
+
+ @Test
+ void mapTemplateSuccessWithUserNameAndSurname() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
+ .IUR(IUR)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtorPosition(DebtorPosition.builder()
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .iuv(IUV)
+ .build())
+ .debtor(Debtor.builder()
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .payer(Payer.builder()
+ .entityUniqueIdentifierValue(PAYER_VALID_CF)
+ .build())
+ .creditor(Creditor.builder()
+ .idPA(ID_PA)
+ .build())
+ .transactionDetails(TransactionDetails.builder()
+ .transaction(Transaction.builder()
+ .grandTotal(GRAND_TOTAL_LONG).build()
+ )
+ .user(User.builder()
+ .name(USER_NAME)
+ .surname(USER_SURNAME)
+ .build())
+ .build()
+ )
+ .build();
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())));
+
+ ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get();
+ assertEquals(USER_FORMATTED_FULL_NAME, receiptPDFTemplate.getUser().getData().getFullName());
+ }
+
+ @Test
+ void mapTemplateSuccessWithUserTaxCodeFromTransaction() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
+ .IUR(IUR)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .remittanceInformation(REMITTANCE_INFORMATION)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .debtorPosition(DebtorPosition.builder()
+ .modelType(MODEL_TYPE_IUV_CODE)
+ .iuv(IUV)
+ .build())
+ .debtor(Debtor.builder()
+ .entityUniqueIdentifierValue(DEBTOR_VALID_CF)
+ .build())
+ .payer(Payer.builder()
+ .entityUniqueIdentifierValue(PAYER_VALID_CF)
+ .build())
+ .creditor(Creditor.builder()
+ .idPA(ID_PA)
+ .build())
+ .transactionDetails(TransactionDetails.builder()
+ .transaction(Transaction.builder()
+ .grandTotal(GRAND_TOTAL_LONG).build()
+ )
+ .user(User.builder()
+ .name(USER_NAME)
+ .surname(USER_SURNAME)
+ .fiscalCode(USER_TAX_CODE)
+ .build())
+ .build()
+ )
+ .build();
+ AtomicReference atomicReference = new AtomicReference<>();
+ assertDoesNotThrow(() -> atomicReference.set(buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build())));
+
+ ReceiptPDFTemplate receiptPDFTemplate = atomicReference.get();
+ assertEquals(USER_TAX_CODE, receiptPDFTemplate.getUser().getData().getTaxCode());
+ }
+
+ @Test
+ void mapTemplateNoServiceCustomerIdError() {
+ BizEvent event = new BizEvent();
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
+
+ assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
+ assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.SERVICE_CUSTOMER_ID), e.getMessage());
+ }
+
+ @Test
+ void mapTemplateNoTransactionTimestampError() {
+ BizEvent event = BizEvent.builder().id(BIZ_EVENT_ID).paymentInfo(PaymentInfo.builder().IUR(IUR).build()).build();
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
+
+ assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
+ assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_TIMESTAMP), e.getMessage());
+ }
+
+ @Test
+ void mapTemplateNoTransactionAmountError() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
+ .IUR(IUR)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .build())
+ .build();
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
+
+ assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
+ assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_AMOUNT), e.getMessage());
+ }
+
+ @Test
+ void mapTemplateNoPspError() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP), e.getMessage());
@@ -843,16 +1670,17 @@ void mapTemplateNoPspError() {
@Test
void mapTemplateNoPspNameError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
.idPsp("noName")
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_NAME), e.getMessage());
@@ -861,9 +1689,10 @@ void mapTemplateNoPspNameError() {
@Test
void mapTemplateNoPspCompanyNameError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -871,7 +1700,7 @@ void mapTemplateNoPspCompanyNameError() {
.psp(PSP_NAME)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_COMPANY_NAME), e.getMessage());
@@ -880,9 +1709,10 @@ void mapTemplateNoPspCompanyNameError() {
@Test
void mapTemplateNoPspAddressError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -890,7 +1720,7 @@ void mapTemplateNoPspAddressError() {
.psp(PSP_NAME)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_ADDRESS), e.getMessage());
@@ -899,9 +1729,10 @@ void mapTemplateNoPspAddressError() {
@Test
void mapTemplateNoPspCityError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -909,7 +1740,7 @@ void mapTemplateNoPspCityError() {
.psp(PSP_NAME)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_CITY), e.getMessage());
@@ -918,9 +1749,10 @@ void mapTemplateNoPspCityError() {
@Test
void mapTemplateNoPspProvinceError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -928,7 +1760,7 @@ void mapTemplateNoPspProvinceError() {
.psp(PSP_NAME)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_PROVINCE), e.getMessage());
@@ -937,9 +1769,10 @@ void mapTemplateNoPspProvinceError() {
@Test
void mapTemplateNoPspBuildingNumberError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -947,7 +1780,7 @@ void mapTemplateNoPspBuildingNumberError() {
.psp(PSP_NAME)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_BUILDING_NUMBER), e.getMessage());
@@ -956,9 +1789,10 @@ void mapTemplateNoPspBuildingNumberError() {
@Test
void mapTemplateNoPspPostalCodeError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -966,7 +1800,7 @@ void mapTemplateNoPspPostalCodeError() {
.psp(PSP_NAME)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_POSTAL_CODE), e.getMessage());
@@ -975,9 +1809,10 @@ void mapTemplateNoPspPostalCodeError() {
@Test
void mapTemplateNoPspLogoError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -990,7 +1825,7 @@ void mapTemplateNoPspLogoError() {
.build())
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_LOGO), e.getMessage());
@@ -999,8 +1834,9 @@ void mapTemplateNoPspLogoError() {
@Test
void mapTemplateNoRrnError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -1013,7 +1849,7 @@ void mapTemplateNoRrnError() {
.build())
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_RRN), e.getMessage());
@@ -1022,9 +1858,10 @@ void mapTemplateNoRrnError() {
@Test
void mapTemplateNoUserDataFullNameError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -1032,7 +1869,7 @@ void mapTemplateNoUserDataFullNameError() {
.psp(PSP_NAME)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.USER_DATA_FULL_NAME), e.getMessage());
@@ -1041,9 +1878,10 @@ void mapTemplateNoUserDataFullNameError() {
@Test
void mapTemplateNoUserDataTaxCodeError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -1054,7 +1892,7 @@ void mapTemplateNoUserDataTaxCodeError() {
.fullName(PAYER_FULL_NAME)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.USER_DATA_TAX_CODE), e.getMessage());
@@ -1063,9 +1901,10 @@ void mapTemplateNoUserDataTaxCodeError() {
@Test
void mapTemplateNoCartItemRefNumberTypeError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -1077,18 +1916,19 @@ void mapTemplateNoCartItemRefNumberTypeError() {
.entityUniqueIdentifierValue(PAYER_VALID_CF)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_REF_NUMBER_TYPE), e.getMessage());
}
@Test
- void mapTemplateNoCartItemRefNumberValueError() {
+ void mapTemplateNoCartItemRefNumberValueIUVError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -1103,7 +1943,35 @@ void mapTemplateNoCartItemRefNumberValueError() {
.modelType(MODEL_TYPE_IUV_CODE)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
+
+ assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
+ assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_REF_NUMBER_VALUE), e.getMessage());
+ }
+
+ @Test
+ void mapTemplateWrongModelTypeError() {
+ BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
+ .paymentInfo(PaymentInfo.builder()
+ .IUR(IUR)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
+ .amount(AMOUNT_WITHOUT_CENTS)
+ .build())
+ .psp(Psp.builder()
+ .idPsp(ID_PSP)
+ .psp(PSP_NAME)
+ .build())
+ .payer(Payer.builder()
+ .fullName(PAYER_FULL_NAME)
+ .entityUniqueIdentifierValue(PAYER_VALID_CF)
+ .build())
+ .debtorPosition(DebtorPosition.builder()
+ .iuv(IUV)
+ .modelType(MODEL_TYPE_NOTICE_CODE)
+ .build())
+ .build();
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_REF_NUMBER_VALUE), e.getMessage());
@@ -1112,9 +1980,10 @@ void mapTemplateNoCartItemRefNumberValueError() {
@Test
void mapTemplateNoCartItemDebtorTaxCodeValueError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -1130,7 +1999,7 @@ void mapTemplateNoCartItemDebtorTaxCodeValueError() {
.iuv(IUV)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_DEBTOR_TAX_CODE), e.getMessage());
@@ -1139,9 +2008,10 @@ void mapTemplateNoCartItemDebtorTaxCodeValueError() {
@Test
void mapTemplateNoCartItemPayeeTaxCodeValueError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
@@ -1160,7 +2030,7 @@ void mapTemplateNoCartItemPayeeTaxCodeValueError() {
.entityUniqueIdentifierValue(DEBTOR_VALID_CF)
.build())
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_PAYEE_TAX_CODE), e.getMessage());
@@ -1169,9 +2039,10 @@ void mapTemplateNoCartItemPayeeTaxCodeValueError() {
@Test
void mapTemplateNoCartItemAmountValueError() {
BizEvent event = BizEvent.builder()
+ .id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
- .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
+ .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS_DST_WINTER)
.remittanceInformation(REMITTANCE_INFORMATION)
.build())
.psp(Psp.builder()
@@ -1200,7 +2071,7 @@ void mapTemplateNoCartItemAmountValueError() {
.build()
)
.build();
- TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE));
+ TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_AMOUNT), e.getMessage());
diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/GenerateReceiptPdfServiceImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/GenerateReceiptPdfServiceImplTest.java
index be1fef1..8e9ba4c 100644
--- a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/GenerateReceiptPdfServiceImplTest.java
+++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/GenerateReceiptPdfServiceImplTest.java
@@ -97,7 +97,7 @@ void generateReceiptsPayerNullWithSuccess() throws Exception {
doReturn(getBlobStorageResponse(com.microsoft.azure.functions.HttpStatus.CREATED.value()))
.when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
doReturn(new ReceiptPDFTemplate())
- .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp"));
@@ -110,7 +110,7 @@ void generateReceiptsPayerNullWithSuccess() throws Exception {
assertEquals(SC_OK, pdfGeneration.getDebtorMetadata().getStatusCode());
assertNull(pdfGeneration.getPayerMetadata());
- verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
verify(pdfEngineClientMock).generatePDF(any(), any());
verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
}
@@ -125,7 +125,7 @@ void generateReceiptsSameDebtorPayerWithSuccess() throws Exception {
doReturn(getBlobStorageResponse(com.microsoft.azure.functions.HttpStatus.CREATED.value()))
.when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
doReturn(new ReceiptPDFTemplate())
- .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp"));
@@ -138,7 +138,7 @@ void generateReceiptsSameDebtorPayerWithSuccess() throws Exception {
assertEquals(SC_OK, pdfGeneration.getDebtorMetadata().getStatusCode());
assertNull(pdfGeneration.getPayerMetadata());
- verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
verify(pdfEngineClientMock).generatePDF(any(), any());
verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
}
@@ -155,7 +155,7 @@ void generateReceiptsDifferentDebtorPayerWithSuccess() throws Exception {
getBlobStorageResponse(com.microsoft.azure.functions.HttpStatus.CREATED.value()))
.when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
doReturn(new ReceiptPDFTemplate())
- .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp"));
@@ -172,7 +172,7 @@ void generateReceiptsDifferentDebtorPayerWithSuccess() throws Exception {
assertNotNull(pdfGeneration.getPayerMetadata().getDocumentUrl());
assertEquals(SC_OK, pdfGeneration.getPayerMetadata().getStatusCode());
- verify(buildTemplateServiceMock, times(2)).buildTemplate(any(), anyBoolean());
+ verify(buildTemplateServiceMock, times(2)).buildTemplate(any(), anyBoolean(), any());
verify(pdfEngineClientMock, times(2)).generatePDF(any(), any());
verify(receiptBlobClientMock, times(2)).savePdfToBlobStorage(any(), anyString());
}
@@ -185,7 +185,7 @@ void generateReceiptsPayerNullFailPDFEngineCallReturn500() throws Exception {
doReturn(getPdfEngineResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, ""))
.when(pdfEngineClientMock).generatePDF(any(), any());
doReturn(new ReceiptPDFTemplate())
- .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp"));
@@ -198,7 +198,7 @@ void generateReceiptsPayerNullFailPDFEngineCallReturn500() throws Exception {
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, pdfGeneration.getDebtorMetadata().getStatusCode());
assertNull(pdfGeneration.getPayerMetadata());
- verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
verify(pdfEngineClientMock).generatePDF(any(), any());
verify(receiptBlobClientMock, never()).savePdfToBlobStorage(any(), anyString());
}
@@ -209,7 +209,7 @@ void generateReceiptsPayerNullFailBuildTemplateData() throws Exception {
BizEvent bizEventOnly = getBizEventWithOnlyDebtor();
doThrow(new TemplateDataMappingException("error message", ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode()))
- .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp"));
@@ -222,7 +222,7 @@ void generateReceiptsPayerNullFailBuildTemplateData() throws Exception {
assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), pdfGeneration.getDebtorMetadata().getStatusCode());
assertNull(pdfGeneration.getPayerMetadata());
- verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
verify(pdfEngineClientMock, never()).generatePDF(any(), any());
verify(receiptBlobClientMock, never()).savePdfToBlobStorage(any(), anyString());
}
@@ -236,7 +236,7 @@ void generateReceiptsPayerNullFailSaveToBlobStorageThrowsException() throws Exce
.when(pdfEngineClientMock).generatePDF(any(), any());
doThrow(RuntimeException.class).when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
doReturn(new ReceiptPDFTemplate())
- .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp"));
@@ -249,7 +249,7 @@ void generateReceiptsPayerNullFailSaveToBlobStorageThrowsException() throws Exce
assertEquals(ReasonErrorCode.ERROR_BLOB_STORAGE.getCode(), pdfGeneration.getDebtorMetadata().getStatusCode());
assertNull(pdfGeneration.getPayerMetadata());
- verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
verify(pdfEngineClientMock).generatePDF(any(), any());
verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
}
@@ -264,7 +264,7 @@ void generateReceiptsPayerNullFailSaveToBlobStorageReturn500() throws Exception
doReturn(getBlobStorageResponse(com.microsoft.azure.functions.HttpStatus.INTERNAL_SERVER_ERROR.value()))
.when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
doReturn(new ReceiptPDFTemplate())
- .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ .when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp"));
@@ -277,7 +277,7 @@ void generateReceiptsPayerNullFailSaveToBlobStorageReturn500() throws Exception
assertEquals(ReasonErrorCode.ERROR_BLOB_STORAGE.getCode(), (pdfGeneration.getDebtorMetadata().getStatusCode()));
assertNull((pdfGeneration.getPayerMetadata()));
- verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean());
+ verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any());
verify(pdfEngineClientMock).generatePDF(any(), any());
verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
}