From 190b8527836df872fa1844c0e5763542bcff78f0 Mon Sep 17 00:00:00 2001 From: svariant Date: Tue, 23 Jan 2024 10:03:53 +0100 Subject: [PATCH] [fix] Fixed payer fiscal code control when discarding events --- .../utils/BizEventToReceiptUtils.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java index a777b51..790e7bd 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java @@ -147,7 +147,7 @@ public static MassiveRecoverResult massiveRecoverByStatus( try { Receipt restored = getEvent(receipt.getEventId(), context, bizEventToReceiptService, bizEventCosmosClient, receiptCosmosService, receipt, logger, receipt.getIsCart() != null ? - receipt.getIsCart() : false); + receipt.getIsCart() : false); receiptList.add(restored); } catch (Exception e) { logger.error(e.getMessage(), e); @@ -233,11 +233,7 @@ public static boolean isBizEventInvalid(BizEvent bizEvent, ExecutionContext cont return true; } - if ( - (bizEvent.getDebtor() == null || !isValidFiscalCode(bizEvent.getDebtor().getEntityUniqueIdentifierValue())) - && - (bizEvent.getPayer() == null || !isValidFiscalCode(bizEvent.getPayer().getEntityUniqueIdentifierValue())) - ) { + if (!hasValidFiscalCode(bizEvent)) { logger.debug("[{}] event with id {} discarded because debtor's and payer's identifiers are missing or not valid", context.getFunctionName(), bizEvent.getId()); return true; @@ -272,6 +268,23 @@ public static boolean isBizEventInvalid(BizEvent bizEvent, ExecutionContext cont return false; } + private static boolean hasValidFiscalCode(BizEvent bizEvent) { + boolean isValidDebtor = false; + boolean isValidPayer = false; + + if(bizEvent.getDebtor() != null && isValidFiscalCode(bizEvent.getDebtor().getEntityUniqueIdentifierValue())){ + isValidDebtor = true; + } + if(bizEvent.getTransactionDetails() != null && bizEvent.getTransactionDetails().getUser() != null && isValidFiscalCode(bizEvent.getTransactionDetails().getUser().getFiscalCode())){ + isValidPayer = true; + } + if(bizEvent.getPayer() != null && isValidFiscalCode(bizEvent.getPayer().getEntityUniqueIdentifierValue())){ + isValidPayer = true; + } + + return isValidDebtor || isValidPayer; + } + public static void tokenizeReceipt(BizEventToReceiptService service, List bizEvents, Receipt receipt) throws PDVTokenizerException, JsonProcessingException { BizEvent firstEvent = bizEvents.get(0); @@ -447,5 +460,6 @@ public static boolean isValidFiscalCode(String fiscalCode) { return false; } - private BizEventToReceiptUtils() {} + private BizEventToReceiptUtils() { + } }