Skip to content

Commit

Permalink
Merge pull request #108 from pagopa/PRDP-298-feat-relax-checks-on-ano…
Browse files Browse the repository at this point in the history
…nym-debtor

[PRDP-298] feat: relax checks on anonym debtor
  • Loading branch information
pasqualespica authored Dec 21, 2023
2 parents b05fbe8 + 7fbddaf commit 8bf5923
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void processGenerateReceipt(
}

String debtorCF = receipt.getEventData().getDebtorFiscalCode();
if (debtorCF == null) {
if (debtorCF == null && receipt.getEventData().getPayerFiscalCode() == null) {
String errorMessage = String.format(
"Error processing receipt with id %s : debtor's fiscal code is null",
receipt.getEventId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ public ReceiptPDFTemplate buildTemplate(BizEvent bizEvent, boolean isGeneratingD
.type(getRefNumberType(bizEvent))
.value(getRefNumberValue(bizEvent))
.build())
.debtor(Debtor.builder()
.fullName(getDebtorFullName(bizEvent))
.taxCode(getDebtorTaxCode(bizEvent))
.build())
.debtor("ANONIMO".equals(receipt.getEventData().getDebtorFiscalCode()) ?
null :
Debtor.builder()
.fullName(getDebtorFullName(bizEvent))
.taxCode(getDebtorTaxCode(bizEvent))
.build())
.payee(Payee.builder()
.name(getPayeeName(bizEvent))
.taxCode(getPayeeTaxCode(bizEvent))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public PdfGeneration generateReceipts(Receipt receipt, BizEvent bizEvent, Path w
//Generate debtor's partial PDF
if (receiptAlreadyCreated(receipt.getMdAttach())) {
pdfGeneration.setDebtorMetadata(PdfMetadata.builder().statusCode(ALREADY_CREATED).build());
} else {
} else if (!"ANONIMO".equals(debtorCF)) {
PdfMetadata generationResult = generateAndSavePDFReceipt(bizEvent, receipt, DEBTOR_TEMPLATE_SUFFIX, true, workingDirPath);
pdfGeneration.setDebtorMetadata(generationResult);
}
Expand All @@ -119,16 +119,18 @@ public boolean verifyAndUpdateReceipt(Receipt receipt, PdfGeneration pdfGenerati
return false;
}

if (debtorMetadata.getStatusCode() == HttpStatus.SC_OK) {
ReceiptMetadata receiptMetadata = new ReceiptMetadata();
receiptMetadata.setName(debtorMetadata.getDocumentName());
receiptMetadata.setUrl(debtorMetadata.getDocumentUrl());

receipt.setMdAttach(receiptMetadata);
} else if (debtorMetadata.getStatusCode() != ALREADY_CREATED) {
ReasonError reasonError = new ReasonError(debtorMetadata.getStatusCode(), debtorMetadata.getErrorMessage());
receipt.setReasonErr(reasonError);
result = false;
if (receipt.getEventData() != null && !"ANONIMO".equals(receipt.getEventData().getDebtorFiscalCode())) {
if (debtorMetadata.getStatusCode() == HttpStatus.SC_OK) {
ReceiptMetadata receiptMetadata = new ReceiptMetadata();
receiptMetadata.setName(debtorMetadata.getDocumentName());
receiptMetadata.setUrl(debtorMetadata.getDocumentUrl());

receipt.setMdAttach(receiptMetadata);
} else if (debtorMetadata.getStatusCode() != ALREADY_CREATED) {
ReasonError reasonError = new ReasonError(debtorMetadata.getStatusCode(), debtorMetadata.getErrorMessage());
receipt.setReasonErr(reasonError);
result = false;
}
}

if (pdfGeneration.isGenerateOnlyDebtor()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,37 @@ void generateReceiptsDifferentDebtorPayerWithSuccess() throws Exception {
verify(receiptBlobClientMock, times(2)).savePdfToBlobStorage(any(), anyString());
}

@Test
void generateReceiptsDifferentDebtorPayerWithSuccessOnDebtAnonym() throws Exception {
Receipt receiptOnly = getReceiptWithDebtorPayer(VALID_CF_PAYER, false, false);
BizEvent bizEventOnly = getBizEventWithDebtorPayer(VALID_CF_PAYER);

receiptOnly.getEventData().setDebtorFiscalCode("ANONIMO");

doReturn(getPdfEngineResponse(HttpStatus.SC_OK, outputPdfDebtor.getPath()),
getPdfEngineResponse(HttpStatus.SC_OK, outputPdfPayer.getPath()))
.when(pdfEngineClientMock).generatePDF(any(), any());
doReturn(getBlobStorageResponse(com.microsoft.azure.functions.HttpStatus.CREATED.value()),
getBlobStorageResponse(com.microsoft.azure.functions.HttpStatus.CREATED.value()))
.when(receiptBlobClientMock).savePdfToBlobStorage(any(), anyString());
doReturn(new ReceiptPDFTemplate())
.when(buildTemplateServiceMock).buildTemplate(any(), anyBoolean(), any(Receipt.class));

PdfGeneration pdfGeneration = sut.generateReceipts(receiptOnly, bizEventOnly,Path.of("/tmp"));

assertNotNull(pdfGeneration);
assertFalse(pdfGeneration.isGenerateOnlyDebtor());
assertNotNull(pdfGeneration.getPayerMetadata());
assertNull(pdfGeneration.getPayerMetadata().getErrorMessage());
assertNotNull(pdfGeneration.getPayerMetadata().getDocumentName());
assertNotNull(pdfGeneration.getPayerMetadata().getDocumentUrl());
assertEquals(HttpStatus.SC_OK, pdfGeneration.getPayerMetadata().getStatusCode());

verify(buildTemplateServiceMock, times(1)).buildTemplate(any(), anyBoolean(), any(Receipt.class));
verify(pdfEngineClientMock, times(1)).generatePDF(any(), any());
verify(receiptBlobClientMock, times(1)).savePdfToBlobStorage(any(), anyString());
}

@Test
void generateReceiptsPayerNullReceiptAlreadyCreatedWithSuccess() throws TemplateDataMappingException {
Receipt receiptOnly = getReceiptWithOnlyDebtor(true);
Expand Down Expand Up @@ -784,6 +815,7 @@ private Receipt buildReceiptForVerify(boolean debtorAlreadyCreated, boolean paye
.id("id")
.mdAttach(buildMetadata(debtorAlreadyCreated))
.mdAttachPayer(buildMetadata(payerAlreadyCreated))
.eventData(EventData.builder().debtorFiscalCode("DEBTOR").build())
.numRetry(0)
.generated_at(1L)
.inserted_at(1L)
Expand Down

0 comments on commit 8bf5923

Please sign in to comment.