From 93068cb1929e8b3def6aa74d331b34e0cabe8474 Mon Sep 17 00:00:00 2001 From: Andrea De Rinaldis Date: Mon, 16 Dec 2024 09:33:05 +0100 Subject: [PATCH] fix: updated handling of IUV/NAV codes on RE events --- .../service/ConverterService.java | 1 - .../service/DebtPositionService.java | 2 ++ .../AbstractAppClientLoggingInterceptor.java | 6 ++++ ...piConfigCacheClientLoggingInterceptor.java | 10 ++++++ .../CheckoutClientLoggingInterceptor.java | 10 ++++++ ...ouplerCachingClientLoggingInterceptor.java | 10 ++++++ .../gpd/GpdClientLoggingInterceptor.java | 29 +++++++++++++++++ .../IuvGeneratorClientLoggingInterceptor.java | 31 +++++++++++++++++++ 8 files changed, 98 insertions(+), 1 deletion(-) diff --git a/src/main/java/it/gov/pagopa/wispconverter/service/ConverterService.java b/src/main/java/it/gov/pagopa/wispconverter/service/ConverterService.java index bd9d8342..ef26c903 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/service/ConverterService.java +++ b/src/main/java/it/gov/pagopa/wispconverter/service/ConverterService.java @@ -53,7 +53,6 @@ public String convert(String sessionId) { try { // unmarshalling and mapping RPT content from request entity, generating session data SessionDataDTO sessionData = this.rptExtractorService.extractSessionData(rptRequestEntity.getPrimitive(), rptRequestEntity.getPayload()); - // this.rptExtractorService.sendEventForExtractedRPTs(sessionData.getAllRPTs()); commented for more reducing logged statuses // prepare receipt-rt saving (nodoChiediCopiaRT) rtReceiptCosmosService.saveRTEntity(sessionData, ReceiptStatusEnum.REDIRECT); diff --git a/src/main/java/it/gov/pagopa/wispconverter/service/DebtPositionService.java b/src/main/java/it/gov/pagopa/wispconverter/service/DebtPositionService.java index 41d386f7..7036afc9 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/service/DebtPositionService.java +++ b/src/main/java/it/gov/pagopa/wispconverter/service/DebtPositionService.java @@ -457,6 +457,7 @@ private void handleNewPaymentPosition(SessionDataDTO sessionData, PaymentPositio String nav = generateNavCodeFromIuvGenerator(creditorInstitutionId); if (!Constants.NODO_INVIA_CARRELLO_RPT.equals(MDC.get(Constants.MDC_PRIMITIVE))) { MDC.put(Constants.MDC_NOTICE_NUMBER, nav); + MDC.put(Constants.MDC_IUV, iuv); } // update the payment option to be used in bulk insert with the newly generated NAV code @@ -487,6 +488,7 @@ private String generateNavCodeFromIuvGenerator(String creditorInstitutionId) { // generating NAV code using standard AUX digit and the generated IUV code navCode = this.auxDigit + response.getIuv(); + } catch (RestClientException e) { throw new AppException(AppErrorCodeMessageEnum.CLIENT_IUVGENERATOR, String.format(REST_CLIENT_LOG_STRING, e.getCause().getClass().getCanonicalName(), e.getMessage())); diff --git a/src/main/java/it/gov/pagopa/wispconverter/util/client/AbstractAppClientLoggingInterceptor.java b/src/main/java/it/gov/pagopa/wispconverter/util/client/AbstractAppClientLoggingInterceptor.java index 5470f523..59b65371 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/util/client/AbstractAppClientLoggingInterceptor.java +++ b/src/main/java/it/gov/pagopa/wispconverter/util/client/AbstractAppClientLoggingInterceptor.java @@ -379,9 +379,15 @@ private void generateRe( .build(); } if (this.mustPersistEventOnRE) { + setInMDCAfterClientResponse(new String(body)); reService.sendEvent(status, null, outcome, requestContext, responseContext); + deleteFromMDCAfterClientResponse(); } } protected abstract WorkflowStatus getOperationStatus(String url, HttpMethod httpMethod); + + protected abstract void setInMDCAfterClientResponse(String payload); + + protected abstract void deleteFromMDCAfterClientResponse(); } diff --git a/src/main/java/it/gov/pagopa/wispconverter/util/client/apiconfigcache/ApiConfigCacheClientLoggingInterceptor.java b/src/main/java/it/gov/pagopa/wispconverter/util/client/apiconfigcache/ApiConfigCacheClientLoggingInterceptor.java index c31f6f15..94d7483e 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/util/client/apiconfigcache/ApiConfigCacheClientLoggingInterceptor.java +++ b/src/main/java/it/gov/pagopa/wispconverter/util/client/apiconfigcache/ApiConfigCacheClientLoggingInterceptor.java @@ -22,4 +22,14 @@ public ApiConfigCacheClientLoggingInterceptor(RequestResponseLoggingProperties c protected WorkflowStatus getOperationStatus(String url, HttpMethod httpMethod) { return WorkflowStatus.COMMUNICATION_WITH_APICONFIG_CACHE_PROCESSED; } + + @Override + protected void setInMDCAfterClientResponse(String payload) { + // nothing to do + } + + @Override + protected void deleteFromMDCAfterClientResponse() { + // nothing to do + } } diff --git a/src/main/java/it/gov/pagopa/wispconverter/util/client/checkout/CheckoutClientLoggingInterceptor.java b/src/main/java/it/gov/pagopa/wispconverter/util/client/checkout/CheckoutClientLoggingInterceptor.java index fb081122..aeb4dae4 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/util/client/checkout/CheckoutClientLoggingInterceptor.java +++ b/src/main/java/it/gov/pagopa/wispconverter/util/client/checkout/CheckoutClientLoggingInterceptor.java @@ -24,4 +24,14 @@ public CheckoutClientLoggingInterceptor(RequestResponseLoggingProperties clientL protected WorkflowStatus getOperationStatus(String url, HttpMethod httpMethod) { return WorkflowStatus.COMMUNICATION_WITH_CHECKOUT_FOR_CART_CREATION_PROCESSED; } + + @Override + protected void setInMDCAfterClientResponse(String payload) { + // nothing to do + } + + @Override + protected void deleteFromMDCAfterClientResponse() { + // nothing to do + } } diff --git a/src/main/java/it/gov/pagopa/wispconverter/util/client/decouplercaching/DecouplerCachingClientLoggingInterceptor.java b/src/main/java/it/gov/pagopa/wispconverter/util/client/decouplercaching/DecouplerCachingClientLoggingInterceptor.java index 6ecb0e57..b3b9e25e 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/util/client/decouplercaching/DecouplerCachingClientLoggingInterceptor.java +++ b/src/main/java/it/gov/pagopa/wispconverter/util/client/decouplercaching/DecouplerCachingClientLoggingInterceptor.java @@ -33,4 +33,14 @@ protected WorkflowStatus getOperationStatus(String url, HttpMethod httpMethod) { } return status; } + + @Override + protected void setInMDCAfterClientResponse(String payload) { + // nothing to do + } + + @Override + protected void deleteFromMDCAfterClientResponse() { + // nothing to do + } } diff --git a/src/main/java/it/gov/pagopa/wispconverter/util/client/gpd/GpdClientLoggingInterceptor.java b/src/main/java/it/gov/pagopa/wispconverter/util/client/gpd/GpdClientLoggingInterceptor.java index b5ee4eb9..972b7159 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/util/client/gpd/GpdClientLoggingInterceptor.java +++ b/src/main/java/it/gov/pagopa/wispconverter/util/client/gpd/GpdClientLoggingInterceptor.java @@ -2,15 +2,22 @@ import it.gov.pagopa.wispconverter.repository.model.enumz.WorkflowStatus; import it.gov.pagopa.wispconverter.service.ReService; +import it.gov.pagopa.wispconverter.util.Constants; import it.gov.pagopa.wispconverter.util.client.AbstractAppClientLoggingInterceptor; import it.gov.pagopa.wispconverter.util.client.ClientServiceEnum; import it.gov.pagopa.wispconverter.util.client.RequestResponseLoggingProperties; import lombok.extern.slf4j.Slf4j; +import org.slf4j.MDC; import org.springframework.http.HttpMethod; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + @Slf4j public class GpdClientLoggingInterceptor extends AbstractAppClientLoggingInterceptor { + private final Pattern navPattern = Pattern.compile("\\\\\"nav\\\\\":\\\\\"([0-9]+)\\\\\""); + public GpdClientLoggingInterceptor(RequestResponseLoggingProperties clientLoggingProperties, ReService reService, Boolean isTracingOfClientOnREEnabled) { super(clientLoggingProperties, reService, ClientServiceEnum.GPD); @@ -32,4 +39,26 @@ protected WorkflowStatus getOperationStatus(String url, HttpMethod httpMethod) { } return status; } + + @Override + protected void setInMDCAfterClientResponse(String payload) { + try { + if (payload != null && !payload.isBlank()) { + Matcher matcher = navPattern.matcher(payload); + if (matcher.find()) { + String noticeNumber = matcher.group(0); + if (noticeNumber != null && !noticeNumber.isBlank()) { + MDC.put(Constants.MDC_NOTICE_NUMBER, noticeNumber); + } + } + } + } catch (Exception e) { + // catch this but do nothing, as nothing is required to do + } + } + + @Override + protected void deleteFromMDCAfterClientResponse() { + MDC.remove(Constants.MDC_NOTICE_NUMBER); + } } diff --git a/src/main/java/it/gov/pagopa/wispconverter/util/client/iuvgenerator/IuvGeneratorClientLoggingInterceptor.java b/src/main/java/it/gov/pagopa/wispconverter/util/client/iuvgenerator/IuvGeneratorClientLoggingInterceptor.java index afa6a299..408af0d6 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/util/client/iuvgenerator/IuvGeneratorClientLoggingInterceptor.java +++ b/src/main/java/it/gov/pagopa/wispconverter/util/client/iuvgenerator/IuvGeneratorClientLoggingInterceptor.java @@ -2,15 +2,22 @@ import it.gov.pagopa.wispconverter.repository.model.enumz.WorkflowStatus; import it.gov.pagopa.wispconverter.service.ReService; +import it.gov.pagopa.wispconverter.util.Constants; import it.gov.pagopa.wispconverter.util.client.AbstractAppClientLoggingInterceptor; import it.gov.pagopa.wispconverter.util.client.ClientServiceEnum; import it.gov.pagopa.wispconverter.util.client.RequestResponseLoggingProperties; import lombok.extern.slf4j.Slf4j; +import org.slf4j.MDC; import org.springframework.http.HttpMethod; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + @Slf4j public class IuvGeneratorClientLoggingInterceptor extends AbstractAppClientLoggingInterceptor { + private final Pattern iuvPattern = Pattern.compile("\\\\\"iuv\\\\\":\\\\\"([0-9]+)\\\\\""); + public IuvGeneratorClientLoggingInterceptor(RequestResponseLoggingProperties clientLoggingProperties, ReService reService, Boolean isTracingOfClientOnREEnabled) { super(clientLoggingProperties, reService, ClientServiceEnum.IUV_GENERATOR); @@ -24,4 +31,28 @@ public IuvGeneratorClientLoggingInterceptor(RequestResponseLoggingProperties cli protected WorkflowStatus getOperationStatus(String url, HttpMethod httpMethod) { return WorkflowStatus.COMMUNICATION_WITH_IUVGENERATOR_FOR_NAV_CREATION_PROCESSED; } + + @Override + protected void setInMDCAfterClientResponse(String payload) { + try { + if (payload != null && !payload.isBlank()) { + Matcher matcher = iuvPattern.matcher(payload); + if (matcher.find()) { + String noticeNumber = matcher.group(0); + if (noticeNumber != null && !noticeNumber.isBlank()) { + MDC.put(Constants.MDC_NOTICE_NUMBER, noticeNumber); + } + } + } + } catch (Exception e) { + // catch this but do nothing, as nothing is required to do + } + } + + @Override + protected void deleteFromMDCAfterClientResponse() { + MDC.remove(Constants.MDC_NOTICE_NUMBER); + } + + }