Skip to content

Commit

Permalink
fix: updated handling of IUV/NAV codes on RE events
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-deri committed Dec 16, 2024
1 parent c46954d commit 93068cb
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}


}

0 comments on commit 93068cb

Please sign in to comment.