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-298] feat: relax checks on anonym debtor #108

Merged
merged 4 commits into from
Dec 21, 2023
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
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
Loading