Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: [PagoPA-1954] - duplicated pdf file #76

Merged
merged 3 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: pagopareceiptpdfhelpdesk
description: Microservice description
type: application
version: 0.166.0
appVersion: 0.9.21-1
version: 0.167.0
appVersion: 0.10.0
dependencies:
- name: microservice-chart
version: 2.4.0
Expand Down
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk
tag: "0.9.21-1"
tag: "0.10.0"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk
tag: "0.9.21-1"
tag: "0.10.0"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk
tag: "0.9.21-1"
tag: "0.10.0"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "Receipts Helpdesk",
"description": "Microservice for exposing REST APIs about receipts helpdesk.",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "0.9.21-1"
"version": "0.10.0"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>it.gov.pagopa.receipt</groupId>
<artifactId>receipt-pdf-helpdesk</artifactId>
<version>0.9.21-1</version>
<version>0.10.0</version>
<packaging>jar</packaging>

<name>pagopa-receipt-pdf-helpdesk</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,30 +238,35 @@ private static void checkOrCreateAttachments(Receipt receipt) {
String debtorCF = receipt.getEventData().getDebtorFiscalCode();
String payerCF = receipt.getEventData().getPayerFiscalCode();
if (payerCF != null) {
if (payerCF.equals(debtorCF) && !receiptMetadataExist(receipt.getMdAttach())) {
String dateFormatted = LocalDate.now().format(DateTimeFormatter.ofPattern(blobNameDateFormat));
String blobName = String.format(blobNameFormat, TEMPLATE_PREFIX, dateFormatted, receipt.getEventId(), PAYER_TEMPLATE_SUFFIX);
receipt.setMdAttach(ReceiptMetadata.builder().name(blobName).build());
} else {
if (!receiptMetadataExist(receipt.getMdAttachPayer())){
String dateFormatted = LocalDate.now().format(DateTimeFormatter.ofPattern(blobNameDateFormat));
String blobName = String.format(blobNameFormat, TEMPLATE_PREFIX, dateFormatted, receipt.getEventId(), PAYER_TEMPLATE_SUFFIX);
receipt.setMdAttachPayer(ReceiptMetadata.builder().name(blobName).build());
}
if (!receiptMetadataExist(receipt.getMdAttach())) {
String dateFormatted = LocalDate.now().format(DateTimeFormatter.ofPattern(blobNameDateFormat));
String blobName = String.format(blobNameFormat, TEMPLATE_PREFIX, dateFormatted, receipt.getEventId(), DEBTOR_TEMPLATE_SUFFIX);
receipt.setMdAttach(ReceiptMetadata.builder().name(blobName).build());
}
}
createPayerAndDebtorMdAttach(receipt, blobNameFormat, blobNameDateFormat, debtorCF, payerCF);
} else {
if (!receiptMetadataExist(receipt.getMdAttach())) {
if (!"ANONIMO".equals(debtorCF) && !receiptMetadataExist(receipt.getMdAttach())) {
String dateFormatted = LocalDate.now().format(DateTimeFormatter.ofPattern(blobNameDateFormat));
String blobName = String.format(blobNameFormat, TEMPLATE_PREFIX, dateFormatted, receipt.getEventId(), DEBTOR_TEMPLATE_SUFFIX);
receipt.setMdAttach(ReceiptMetadata.builder().name(blobName).build());
}
}
}

private static void createPayerAndDebtorMdAttach(Receipt receipt, final String blobNameFormat,
final String blobNameDateFormat, String debtorCF, String payerCF) {
if (payerCF.equals(debtorCF) && !receiptMetadataExist(receipt.getMdAttach())) {
String dateFormatted = LocalDate.now().format(DateTimeFormatter.ofPattern(blobNameDateFormat));
String blobName = String.format(blobNameFormat, TEMPLATE_PREFIX, dateFormatted, receipt.getEventId(), PAYER_TEMPLATE_SUFFIX);
receipt.setMdAttach(ReceiptMetadata.builder().name(blobName).build());
} else {
if (!receiptMetadataExist(receipt.getMdAttachPayer())){
String dateFormatted = LocalDate.now().format(DateTimeFormatter.ofPattern(blobNameDateFormat));
String blobName = String.format(blobNameFormat, TEMPLATE_PREFIX, dateFormatted, receipt.getEventId(), PAYER_TEMPLATE_SUFFIX);
receipt.setMdAttachPayer(ReceiptMetadata.builder().name(blobName).build());
}
if (!"ANONIMO".equals(debtorCF) && !receiptMetadataExist(receipt.getMdAttach())) {
String dateFormatted = LocalDate.now().format(DateTimeFormatter.ofPattern(blobNameDateFormat));
String blobName = String.format(blobNameFormat, TEMPLATE_PREFIX, dateFormatted, receipt.getEventId(), DEBTOR_TEMPLATE_SUFFIX);
receipt.setMdAttach(ReceiptMetadata.builder().name(blobName).build());
}
}
}

private void updateReceiptInfo(OutputBinding<Receipt> documentdb, boolean isCart, boolean isToUpdateMetadata, BizEvent bizEvent,
List<BizEvent> listBizEvent, Receipt receipt, PdfGeneration pdfGeneration) throws PDVTokenizerException, JsonProcessingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import it.gov.pagopa.receipt.pdf.helpdesk.client.ReceiptBlobClient;
import it.gov.pagopa.receipt.pdf.helpdesk.exception.BlobStorageClientException;
import it.gov.pagopa.receipt.pdf.helpdesk.model.response.BlobStorageResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -76,7 +77,7 @@ public BlobStorageResponse savePdfToBlobStorage(InputStream pdf, String fileName

//Create the container and return a container client object
BlobContainerClient blobContainerClient = this.blobServiceClient.getBlobContainerClient(containerName);
String fileNamePdf = fileName + FILE_EXTENSION;
String fileNamePdf = fileName.substring(fileName.lastIndexOf(".") + 1).equalsIgnoreCase(FILE_EXTENSION) ? fileName : fileName + FILE_EXTENSION;

//Get a reference to a blob
BlobClient blobClient = blobContainerClient.getBlobClient(fileNamePdf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import io.micrometer.core.instrument.util.StringUtils;

import java.io.BufferedInputStream;
Expand All @@ -34,6 +35,7 @@
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static org.apache.http.HttpStatus.SC_OK;

Expand Down Expand Up @@ -103,10 +105,9 @@ public boolean verifyAndUpdateReceipt(Receipt receipt, PdfGeneration pdfGenerati

this.payerMetadataManagment(receipt, payerMetadata);

if (debtorMetadata.getStatusCode() != SC_OK
|| payerMetadata.getStatusCode() != SC_OK) {
if ((debtorMetadata != null && debtorMetadata.getStatusCode() != SC_OK) || payerMetadata.getStatusCode() != SC_OK) {
String errMsg = String.format("Receipt generation fail for debtor (status: %s) and/or payer (status: %s)",
debtorMetadata.getStatusCode(), payerMetadata.getStatusCode());
Optional.ofNullable(debtorMetadata).map(d -> d.getStatusCode()).orElse(null), payerMetadata.getStatusCode());
throw new ReceiptGenerationNotToRetryException(errMsg);
}
return result;
Expand Down
Loading