Skip to content

Commit

Permalink
Merge pull request #64 from pagopa/fix-discard-event-payer-invalid
Browse files Browse the repository at this point in the history
[fix] Fixed payer fiscal code check when discarding events
  • Loading branch information
pasqualespica authored Jan 23, 2024
2 parents 5d6a11f + 190b852 commit 1ed6448
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,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);
Expand Down Expand Up @@ -234,11 +234,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;
Expand Down Expand Up @@ -273,6 +269,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<BizEvent> bizEvents, Receipt receipt)
throws PDVTokenizerException, JsonProcessingException {
BizEvent firstEvent = bizEvents.get(0);
Expand Down Expand Up @@ -456,5 +469,6 @@ public static boolean isValidFiscalCode(String fiscalCode) {
return false;
}

private BizEventToReceiptUtils() {}
private BizEventToReceiptUtils() {
}
}

0 comments on commit 1ed6448

Please sign in to comment.