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

[PRDP-224] Changed Remittance Information retrieve #80

Merged
merged 5 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void processManageReceiptPoisonQueue(
bizEvent = ObjectMapperUtils.mapString(errorMessage, BizEvent.class);
logger.info("[{}] function called at {} recognized as valid BizEvent with id {}",
context.getFunctionName(), LocalDateTime.now(), bizEvent.getId());
if (bizEvent.getAttemptedPoisonRetry()) {
if (Boolean.TRUE.equals(bizEvent.getAttemptedPoisonRetry())) {
logger.info("[{}] function called at {} for event with id {} has ingestion already retried, sending to review",
context.getFunctionName(), LocalDateTime.now(), bizEvent.getId());
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.gov.pagopa.receipt.pdf.generator.service;

import it.gov.pagopa.receipt.pdf.generator.entity.event.BizEvent;
import it.gov.pagopa.receipt.pdf.generator.entity.receipt.Receipt;
import it.gov.pagopa.receipt.pdf.generator.exception.TemplateDataMappingException;
import it.gov.pagopa.receipt.pdf.generator.model.template.ReceiptPDFTemplate;

Expand All @@ -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;
}


Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import it.gov.pagopa.receipt.pdf.generator.entity.event.BizEvent;
import it.gov.pagopa.receipt.pdf.generator.entity.receipt.Receipt;
import it.gov.pagopa.receipt.pdf.generator.entity.receipt.enumeration.ReasonErrorCode;
import it.gov.pagopa.receipt.pdf.generator.exception.PdfJsonMappingException;
import it.gov.pagopa.receipt.pdf.generator.exception.TemplateDataMappingException;
Expand Down Expand Up @@ -70,7 +71,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");
}
Expand All @@ -84,7 +85,7 @@ public class BuildTemplateServiceImpl implements BuildTemplateService {
* {@inheritDoc}
*/
@Override
public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTemplate) throws TemplateDataMappingException {
public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean partialTemplate, Receipt receipt) throws TemplateDataMappingException {
return ReceiptPDFTemplate.builder()
.transaction(Transaction.builder()
.id(getId(bizEvent))
Expand Down Expand Up @@ -124,7 +125,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()
))
Expand Down Expand Up @@ -291,11 +292,14 @@ 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public PdfGeneration generateReceipts(Receipt receipt, BizEvent bizEvent, Path w
pdfGeneration.setDebtorMetadata(PdfMetadata.builder().statusCode(ALREADY_CREATED).build());
return pdfGeneration;
}
PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, PAYER_TEMPLATE_SUFFIX, false, workingDirPath);
PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt, PAYER_TEMPLATE_SUFFIX, false, workingDirPath);
pdfGeneration.setDebtorMetadata(generationResult);
return pdfGeneration;
}
Expand All @@ -89,7 +89,7 @@ public PdfGeneration generateReceipts(Receipt receipt, BizEvent bizEvent, Path w
pdfGeneration.setPayerMetadata(PdfMetadata.builder().statusCode(ALREADY_CREATED).build());
} else {

PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, PAYER_TEMPLATE_SUFFIX, false, workingDirPath);
PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt, PAYER_TEMPLATE_SUFFIX, false, workingDirPath);
pdfGeneration.setPayerMetadata(generationResult);
}
} else {
Expand All @@ -100,7 +100,7 @@ public PdfGeneration generateReceipts(Receipt receipt, BizEvent bizEvent, Path w
if (receiptAlreadyCreated(receipt.getMdAttach())) {
pdfGeneration.setDebtorMetadata(PdfMetadata.builder().statusCode(ALREADY_CREATED).build());
} else {
PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, DEBTOR_TEMPLATE_SUFFIX, true, workingDirPath);
PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt, DEBTOR_TEMPLATE_SUFFIX, true, workingDirPath);
pdfGeneration.setDebtorMetadata(generationResult);
}

Expand Down Expand Up @@ -166,9 +166,9 @@ public boolean verifyAndUpdateReceipt(Receipt receipt, PdfGeneration pdfGenerati
return result;
}

private PdfMetadata generateAndSavePDFReceipt(BizEvent bizEvent, String templateSuffix, boolean partialTemplate, Path workingDirPath) {
private PdfMetadata generateAndSavePDFReceipt(BizEvent bizEvent, Receipt receipt, String templateSuffix, boolean partialTemplate, Path workingDirPath) {
try {
ReceiptPDFTemplate template = buildTemplateService.buildTemplate(bizEvent, partialTemplate);
ReceiptPDFTemplate template = buildTemplateService.buildTemplate(bizEvent, partialTemplate, receipt);
String dateFormatted = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd"));
String blobName = String.format("%s-%s-%s-%s", TEMPLATE_PREFIX, dateFormatted, bizEvent.getId(), templateSuffix);
PdfEngineResponse pdfEngineResponse = generatePDFReceipt(template, workingDirPath);
Expand Down
Loading
Loading