Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improvements on RE events info #182

Merged
merged 7 commits into from
Dec 17, 2024
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 @@ -451,6 +451,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 @@ -481,6 +482,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 @@ -25,7 +25,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -367,7 +366,7 @@ private void generateRe(
.uri(request.getURI().toString())
.method(request.getMethod())
.headers(request.getHeaders())
.payload(Arrays.toString(body))
.payload(new String(body))
.build();
}
ReResponseContext responseContext = null;
Expand All @@ -380,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);
}


}
Loading