From 0f5b8c32136dff354a4347a209ff55add746e978 Mon Sep 17 00:00:00 2001 From: Alessio Cialini <63233981+alessio-cialini@users.noreply.github.com> Date: Fri, 13 Oct 2023 11:09:57 +0200 Subject: [PATCH] Feat: add discarder for anonym debtor (#77) * fix: attempting to use configurations and enviornment variables to avoid classloading issue on opentelemetry agent * feat: add discarder check for anonymous or missing debtor --------- Co-authored-by: acialini --- .../pdf/datastore/BizEventToReceipt.java | 7 ++++ .../pdf/datastore/BizEventToReceiptTest.java | 41 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceipt.java index 0e15c69a..fbf73c72 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceipt.java @@ -149,6 +149,13 @@ private boolean isBizEventInvalid(BizEvent bizEvent, ExecutionContext context) { return true; } + if (bizEvent.getDebtor().getEntityUniqueIdentifierValue() == null || + bizEvent.getDebtor().getEntityUniqueIdentifierValue().equals("ANONIMO")) { + logger.debug("[{}] event with id {} discarded because debtor identifier is missing or ANONIMO", + context.getFunctionName(), bizEvent.getId()); + return true; + } + if (bizEvent.getPaymentInfo() != null) { String totalNotice = bizEvent.getPaymentInfo().getTotalNotice(); diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceiptTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceiptTest.java index 66be7004..22eb319b 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceiptTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceiptTest.java @@ -123,6 +123,20 @@ void runDiscardedWithEventNotDONE() { verify(documentdb, never()).setValue(any()); } + @Test + void runDiscardedWithAnonymousDebtor() { + List bizEventItems = new ArrayList<>(); + bizEventItems.add(generateAnonymDebtorBizEvent("1")); + + @SuppressWarnings("unchecked") + OutputBinding> documentdb = (OutputBinding>) spy(OutputBinding.class); + + // test execution + assertDoesNotThrow(() -> function.processBizEventToReceipt(bizEventItems, documentdb, context)); + + verify(documentdb, never()).setValue(any()); + } + @Test void runDiscardedWithEventNull() { List bizEventItems = new ArrayList<>(); @@ -259,6 +273,33 @@ private BizEvent generateValidBizEvent(String totalNotice){ return item; } + private BizEvent generateAnonymDebtorBizEvent(String totalNotice){ + BizEvent item = new BizEvent(); + + Payer payer = new Payer(); + payer.setEntityUniqueIdentifierValue(PAYER_FISCAL_CODE); + Debtor debtor = new Debtor(); + debtor.setEntityUniqueIdentifierValue("ANONIMO"); + + TransactionDetails transactionDetails = new TransactionDetails(); + Transaction transaction = new Transaction(); + transaction.setCreationDate(String.valueOf(LocalDateTime.now())); + transactionDetails.setTransaction(transaction); + + PaymentInfo paymentInfo = new PaymentInfo(); + paymentInfo.setTotalNotice(totalNotice); + + item.setEventStatus(BizEventStatusType.DONE); + item.setId(EVENT_ID); + item.setPayer(payer); + item.setDebtor(debtor); + item.setTransactionDetails(transactionDetails); + item.setPaymentInfo(paymentInfo); + + return item; + } + + private BizEvent generateNotDoneBizEvent(){ BizEvent item = new BizEvent();