Skip to content

Commit

Permalink
Merge pull request #76 from pagopa/PAGOPA-1954-duplicated-pdf-file
Browse files Browse the repository at this point in the history
bug: [PagoPA-1954] - duplicated pdf file
  • Loading branch information
pasqualespica authored Jul 13, 2024
2 parents a5d96f5 + cadb8db commit 7c3231e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
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

0 comments on commit 7c3231e

Please sign in to comment.