diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/ManageReceiptPoisonQueue.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/ManageReceiptPoisonQueue.java index 7e05a1b9..d55d95a2 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/ManageReceiptPoisonQueue.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/ManageReceiptPoisonQueue.java @@ -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 { diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/BuildTemplateService.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/BuildTemplateService.java index 359cfd7a..6951c0da 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/BuildTemplateService.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/BuildTemplateService.java @@ -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; @@ -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/generator/service/impl/BuildTemplateServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImpl.java index d64fbd4c..aef8dd60 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImpl.java @@ -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; @@ -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"); } @@ -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() .serviceCustomerId(getServiceCustomerId(bizEvent)) .transaction(Transaction.builder() @@ -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() )) @@ -279,9 +280,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; diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java index 210e2a60..e7936dbc 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImpl.java @@ -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; } @@ -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 { @@ -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); } @@ -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); diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImplTest.java index fe47fb2b..6dadd2e5 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/BuildTemplateServiceImplTest.java @@ -2,6 +2,9 @@ import it.gov.pagopa.receipt.pdf.generator.entity.event.*; import it.gov.pagopa.receipt.pdf.generator.entity.event.enumeration.BizEventStatusType; +import it.gov.pagopa.receipt.pdf.generator.entity.receipt.CartItem; +import it.gov.pagopa.receipt.pdf.generator.entity.receipt.EventData; +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.TemplateDataMappingException; import it.gov.pagopa.receipt.pdf.generator.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.*; @@ -124,7 +128,8 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() 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(); + ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -214,7 +219,8 @@ void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Excepti .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(); + ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -304,7 +310,8 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce .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(); + ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, PARTIAL_TEMPLATE, receipt); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -375,7 +382,8 @@ void mapTemplateWithoutTransactionDetailsSuccess() 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(); + ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -446,7 +454,8 @@ void mapTemplateWithoutTransactionDetailsAndPaymentTokenSuccess() throws Excepti .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(); + ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -535,7 +544,8 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEmpty() 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(); + ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -625,7 +635,8 @@ 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(); + ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -715,7 +726,8 @@ void mapTemplateAllFieldsSuccessDebtorFullNameEqualsFiscalCode() throws Exceptio .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(); + ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, receipt); assertNotNull(receiptPdfTemplate); assertEquals(BIZ_EVENT_ID, receiptPdfTemplate.getServiceCustomerId()); @@ -791,13 +803,13 @@ void mapTemplateLeastAmountOfInfoSuccess() { .build() ) .build(); - assertDoesNotThrow(() -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE)); + assertDoesNotThrow(() -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); } @Test void mapTemplateNoServiceCustomerIdError() { BizEvent event = new BizEvent(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE)); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.SERVICE_CUSTOMER_ID), e.getMessage()); @@ -806,7 +818,7 @@ void mapTemplateNoServiceCustomerIdError() { @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, COMPLETE_TEMPLATE)); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_TIMESTAMP), e.getMessage()); @@ -821,7 +833,7 @@ void mapTemplateNoTransactionAmountError() { .paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE)); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_AMOUNT), e.getMessage()); @@ -837,7 +849,7 @@ void mapTemplateNoPspError() { .amount(AMOUNT_WITHOUT_CENTS) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE)); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP), e.getMessage()); @@ -856,7 +868,7 @@ void mapTemplateNoPspNameError() { .idPsp("noName") .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE)); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_NAME), e.getMessage()); @@ -876,7 +888,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, COMPLETE_TEMPLATE, 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()); @@ -896,7 +908,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, COMPLETE_TEMPLATE, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_ADDRESS), e.getMessage()); @@ -916,7 +928,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, COMPLETE_TEMPLATE, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_CITY), e.getMessage()); @@ -936,7 +948,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, COMPLETE_TEMPLATE, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_PROVINCE), e.getMessage()); @@ -956,7 +968,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, COMPLETE_TEMPLATE, 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()); @@ -976,7 +988,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, COMPLETE_TEMPLATE, 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()); @@ -1001,7 +1013,7 @@ void mapTemplateNoPspLogoError() { .build()) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE)); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_PSP_LOGO), e.getMessage()); @@ -1025,7 +1037,7 @@ void mapTemplateNoRrnError() { .build()) .build()) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE)); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build())); assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode()); assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.TRANSACTION_RRN), e.getMessage()); @@ -1045,7 +1057,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, COMPLETE_TEMPLATE, 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()); @@ -1068,7 +1080,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, COMPLETE_TEMPLATE, 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()); @@ -1092,7 +1104,7 @@ 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, COMPLETE_TEMPLATE, 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()); @@ -1119,7 +1131,7 @@ 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, COMPLETE_TEMPLATE, 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()); @@ -1147,7 +1159,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, COMPLETE_TEMPLATE, 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()); @@ -1178,7 +1190,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, COMPLETE_TEMPLATE, 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()); @@ -1219,7 +1231,7 @@ void mapTemplateNoCartItemAmountValueError() { .build() ) .build(); - TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE)); + TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, 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/generator/service/impl/GenerateReceiptPdfServiceImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImplTest.java index 97af3831..9911a3aa 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/generator/service/impl/GenerateReceiptPdfServiceImplTest.java @@ -119,7 +119,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(Receipt.class)); PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")); @@ -132,7 +132,7 @@ void generateReceiptsPayerNullWithSuccess() throws Exception { assertEquals(HttpStatus.SC_OK, pdfGeneration.getDebtorMetadata().getStatusCode()); assertNull(pdfGeneration.getPayerMetadata()); - verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean()); + verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any(Receipt.class)); verify(pdfEngineClientMock).generatePDF(any(), any()); verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString()); } @@ -147,7 +147,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(Receipt.class)); PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")); @@ -160,7 +160,7 @@ void generateReceiptsSameDebtorPayerWithSuccess() throws Exception { assertEquals(HttpStatus.SC_OK, pdfGeneration.getDebtorMetadata().getStatusCode()); assertNull(pdfGeneration.getPayerMetadata()); - verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean()); + verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any(Receipt.class)); verify(pdfEngineClientMock).generatePDF(any(), any()); verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString()); } @@ -177,7 +177,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(Receipt.class)); PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")); @@ -194,7 +194,7 @@ void generateReceiptsDifferentDebtorPayerWithSuccess() throws Exception { assertNotNull(pdfGeneration.getPayerMetadata().getDocumentUrl()); assertEquals(HttpStatus.SC_OK, pdfGeneration.getPayerMetadata().getStatusCode()); - verify(buildTemplateServiceMock, times(2)).buildTemplate(any(), anyBoolean()); + verify(buildTemplateServiceMock, times(2)).buildTemplate(any(), anyBoolean(), any(Receipt.class)); verify(pdfEngineClientMock, times(2)).generatePDF(any(), any()); verify(receiptBlobClientMock, times(2)).savePdfToBlobStorage(any(), anyString()); } @@ -215,7 +215,7 @@ void generateReceiptsPayerNullReceiptAlreadyCreatedWithSuccess() throws Template assertEquals(ALREADY_CREATED, pdfGeneration.getDebtorMetadata().getStatusCode()); assertNull(pdfGeneration.getPayerMetadata()); - verify(buildTemplateServiceMock, never()).buildTemplate(any(), anyBoolean()); + verify(buildTemplateServiceMock, never()).buildTemplate(any(), anyBoolean(), any(Receipt.class)); verify(pdfEngineClientMock, never()).generatePDF(any(), any()); verify(receiptBlobClientMock, never()).savePdfToBlobStorage(any(), anyString()); } @@ -236,7 +236,7 @@ void generateReceiptsSameDebtorPayerAndDebtorReceiptAlreadyCreatedWithSuccess() assertEquals(ALREADY_CREATED, pdfGeneration.getDebtorMetadata().getStatusCode()); assertNull(pdfGeneration.getPayerMetadata()); - verify(buildTemplateServiceMock, never()).buildTemplate(any(), anyBoolean()); + verify(buildTemplateServiceMock, never()).buildTemplate(any(), anyBoolean(), any(Receipt.class)); verify(pdfEngineClientMock, never()).generatePDF(any(), any()); verify(receiptBlobClientMock, never()).savePdfToBlobStorage(any(), anyString()); } @@ -251,7 +251,7 @@ void generateReceiptsDifferentDebtorPayerAndPayerReceiptAlreadyCreatedWithSucces 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(Receipt.class)); PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")); @@ -268,7 +268,7 @@ void generateReceiptsDifferentDebtorPayerAndPayerReceiptAlreadyCreatedWithSucces assertNull(pdfGeneration.getPayerMetadata().getDocumentUrl()); assertEquals(ALREADY_CREATED, pdfGeneration.getPayerMetadata().getStatusCode()); - verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean()); + verify(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any(Receipt.class)); verify(pdfEngineClientMock).generatePDF(any(), any()); verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString()); } @@ -281,7 +281,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(Receipt.class)); PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")); @@ -294,7 +294,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(Receipt.class)); verify(pdfEngineClientMock).generatePDF(any(), any()); verify(receiptBlobClientMock, never()).savePdfToBlobStorage(any(), anyString()); } @@ -305,7 +305,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(Receipt.class)); PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")); @@ -318,7 +318,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(Receipt.class)); verify(pdfEngineClientMock, never()).generatePDF(any(), any()); verify(receiptBlobClientMock, never()).savePdfToBlobStorage(any(), anyString()); } @@ -332,7 +332,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(Receipt.class)); PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")); @@ -345,7 +345,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(Receipt.class)); verify(pdfEngineClientMock).generatePDF(any(), any()); verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString()); } @@ -360,7 +360,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(Receipt.class)); PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp")); @@ -373,7 +373,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(Receipt.class)); verify(pdfEngineClientMock).generatePDF(any(), any()); verify(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString()); }