Skip to content

Commit

Permalink
fix: WIC-1412 (#189)
Browse files Browse the repository at this point in the history
Co-authored-by: pagopa-github-bot <github-bot@pagopa.it>
Co-authored-by: Andrea De Rinaldis <andrea.derinaldis@pagopa.it>
  • Loading branch information
3 people authored Dec 18, 2024
1 parent f94a0df commit ef176b1
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 31 deletions.
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: pagopa-wisp-converter
description: A service that permits to handle nodoInviaRPT and nodoInviaCarrelloRPT request from WISP, interfacing them with GPD system
type: application
version: 0.291.0
appVersion: 1.0.4
version: 0.294.0
appVersion: 1.0.4-3-fix-illegal-chars-replace
dependencies:
- name: microservice-chart
version: 3.0.0
Expand Down
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart: &microservice-chart
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-wisp-converter
tag: "1.0.4"
tag: "1.0.4-3-fix-illegal-chars-replace"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart: &microservice-chart
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-wisp-converter
tag: "1.0.4"
tag: "1.0.4-3-fix-illegal-chars-replace"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart: &microservice-chart
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-wisp-converter
tag: "1.0.4"
tag: "1.0.4-3-fix-illegal-chars-replace"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion openapi/openapi_redirect.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.1",
"info": {
"title": "WISP-Converter-redirect",
"version": "1.0.4"
"version": "1.0.4-3-fix-illegal-chars-replace"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>it.gov.pagopa</groupId>
<artifactId>wisp-converter</artifactId>
<version>1.0.4</version>
<version>1.0.4-3-fix-illegal-chars-replace</version>
<name>pagoPA WISP Converter</name>
<description>A service that permits to handle nodoInviaRPT and nodoInviaCarrelloRPT request from WISP, converting them in NMU payments.</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import it.gov.pagopa.wispconverter.exception.AppErrorCodeMessageEnum;
import it.gov.pagopa.wispconverter.exception.AppException;
import it.gov.pagopa.wispconverter.repository.model.enumz.WorkflowStatus;
import it.gov.pagopa.wispconverter.service.*;
import it.gov.pagopa.wispconverter.service.RPTExtractorService;
import it.gov.pagopa.wispconverter.service.ReceiptTimerService;
import it.gov.pagopa.wispconverter.service.RtReceiptCosmosService;
import it.gov.pagopa.wispconverter.service.model.ReceiptDto;
import it.gov.pagopa.wispconverter.service.model.session.SessionDataDTO;
import it.gov.pagopa.wispconverter.util.EndpointRETrace;
Expand Down Expand Up @@ -79,7 +81,7 @@ public void deleteTimer(@RequestParam() String paymentTokens) {
// set receipts-rt status to PAYING stands for waiting SendPaymentOutcome and then paSendRTV2 (after the latter, the state will change to SENDING -> SENT)
// Get sessionData for the first ReceiptDTO because by design session-id is equal for all paymentTokens in input
ReceiptDto receiptDto = receiptTimerService.peek(tokens.get(0));
if(receiptDto != null) {
if (receiptDto != null) {
String sessionId = receiptDto.getSessionId();
SessionDataDTO sessionDataDTO = rptExtractorService.getSessionDataFromSessionId(sessionId);
// Update receipts-rt status to PAYING
Expand All @@ -90,7 +92,7 @@ public void deleteTimer(@RequestParam() String paymentTokens) {
} catch (Exception e) {
throw new AppException(AppErrorCodeMessageEnum.RECEIPT_RT_STATUS_TO_PAYING_FAILURE, e);
} finally {
// cancel scheduled message if PAYING status transition goes in exception
// cancel scheduled message, either if PAYING status transition goes in exception or not
receiptTimerService.cancelScheduledMessage(tokens);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public enum AppErrorCodeMessageEnum {
RECEIPT_KO_NOT_GENERATED_BUT_MAYBE_RESCHEDULED(1409, "KO Receipt not generated", "Error while generating KO receipt. It is not possible to generate the receipt and it could be scheduled for a next send.", HttpStatus.UNPROCESSABLE_ENTITY, "An error occurred while generating a negative RT (aka a KO receipt). The receipt could be sent lately to creditor institution but for better understanding the cause, please use the Technical Support's APIs."),
RECEIPT_OK_NOT_GENERATED_BUT_MAYBE_RESCHEDULED(1410, "OK Receipt not generated", "Error while generating OK receipt. It is not possible to generate the receipt and it could be scheduled for a next send.", HttpStatus.UNPROCESSABLE_ENTITY, "An error occurred while generating a positive RT (aka a OK receipt). The receipt could be sent lately to creditor institution but for better understanding the cause, please use the Technical Support's APIs."),
RECEIPT_GENERATION_ERROR_DEAD_LETTER(1411, "Receipt generation not completed", "Error while generating receipt. The creditor institution sent an error response related to the sent RT: [Outcome: {0}, Fault code: {1}, Fault string: {2}, Fault description: {3}].", HttpStatus.UNPROCESSABLE_ENTITY, "An error occurred while generating an RT (aka a receipt). Specifically, the creditor institution response status has not been recognized, for this reason the RT has been placed in the dead letter container."),
RECEIPT_RT_STATUS_TO_PAYING_FAILURE(1412, "Receipt status update error", "Error while trying to update receipt status to PAYING at the time of DELETE receipt/time call.", HttpStatus.INTERNAL_SERVER_ERROR, "An error occurred while trying to update receipt status to PAYING at the time of DELETE receipt/timer i.e. ClosePayment inbound. This error may cause side effects such as sending ko if paSendRTV2 (ie.SendPaymentOutcome sending) is received with a n-hour delay."),
RECEIPT_RT_STATUS_TO_PAYING_FAILURE(1412, "Receipt status update error", "Error while trying to update receipt status to PAYING at the time of DELETE receipt/timer call.", HttpStatus.INTERNAL_SERVER_ERROR, "An error occurred while trying to update receipt status to PAYING at the time of DELETE receipt/timer i.e. ClosePayment inbound. This error may cause 1 side effect e.g. sending ko (by cron) if paSendRTV2 (ie.SendPaymentOutcome sending) is received with a n-hour delay."),
// --- DB and storage interaction errors ---
PERSISTENCE_SAVING_RE_ERROR(2000, "Impossible to save event", "Error while trying to store an event in Registro Eventi. Impossible to store event: {0}.", HttpStatus.INTERNAL_SERVER_ERROR, "An error occurred wile trying to store a new event in the Registro Eventi storage. The error is somewhat related to a persistence problem of the used storage and in the majority of the cases is temporary (maybe a 429 HTTP code). This error currently does not blocks the entire flow but, for better understanding the cause, please execute a search in the log provider (Application Insights, Kibana, etc)."),
PERSISTENCE_RPT_NOT_FOUND(2001, "RPT not found", "Error while retrieving RPT. RPT with sessionId [{0}] not found.", HttpStatus.NOT_FOUND, "An error occurred while trying to retrieve the RPT content saved in storage by WISP SOAP Converter. This can be related either with the use of a wrong sessionId or a missed persistence from WISP SOAP Converter, so it is better to analyze the entire flow using Technical Support's APIs. This block totally the conversion of the RPTs in GPD's payment positions, so the whole process is discarded."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -48,14 +47,14 @@ public class ReceiptTimerService {
public void post() {
ServiceBusClientBuilder builder = new ServiceBusClientBuilder();
serviceBusSenderClient = builder.connectionString(connectionString)
.sender()
.queueName(queueName)
.buildClient();
.sender()
.queueName(queueName)
.buildClient();

serviceBusReceiverClient = builder.connectionString(connectionString)
.receiver()
.queueName(queueName)
.buildClient();
.receiver()
.queueName(queueName)
.buildClient();
}

public void sendMessage(ReceiptTimerRequest message) {
Expand Down Expand Up @@ -112,15 +111,20 @@ public ReceiptDto peek(String paymentToken) {
// read sequence number from redis cache
String sequenceNumberKey = String.format(CACHING_KEY_TEMPLATE, paymentToken);
String sequenceNumberString = cacheRepository.read(sequenceNumberKey, String.class);
// read message without changing the service bus state
ServiceBusReceivedMessage message = serviceBusReceiverClient.peekMessage(Long.parseLong(sequenceNumberString));
log.debug("Get message. Session: {}, Sequence #: {}. Contents: {}", message.getMessageId(), message.getSequenceNumber(), message.getBody());
try {
return mapper.readValue(message.getBody().toStream(), ReceiptDto.class);
} catch (Exception e) {
log.error("Error when read ReceiptDto value from message: '{}'. Body: '{}'", message.getMessageId(), message.getBody());
return null;
ReceiptDto receiptDto = null;
if (sequenceNumberString != null) {
// read message without changing the service bus state
ServiceBusReceivedMessage message = serviceBusReceiverClient.peekMessage(Long.parseLong(sequenceNumberString));
if (message != null) {
try {
log.debug("Get message. Session: {}, Sequence #: {}. Contents: {}", message.getMessageId(), message.getSequenceNumber(), message.getBody());
receiptDto = mapper.readValue(message.getBody().toStream(), ReceiptDto.class);
} catch (Exception e) {
log.error("Error when read ReceiptDto value from message: '{}'. Body: '{}'", message.getMessageId(), message.getBody());
}
}
}
return receiptDto;
}

public void cancelScheduledMessage(List<String> paymentTokens) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ public boolean updateStatusToPaying(RPTContentDTO rptContentDTO) {
}

public Optional<RTEntity> findById(String domainId, String iuv, String ccp) {
String id = String.format("%s_%s_%s", domainId, iuv, ccp);
// Remove illegal characters ['/', '\', '#'] because cannot be used in Resource ID
String id = getId(domainId, iuv, ccp);
return rtRepository.findById(id, new PartitionKey(id));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void setInMDCAfterClientResponse(String payload) {
if (payload != null && !payload.isBlank()) {
Matcher matcher = navPattern.matcher(payload);
if (matcher.find()) {
String noticeNumber = matcher.group(0);
String noticeNumber = matcher.group(1);
if (noticeNumber != null && !noticeNumber.isBlank()) {
MDC.put(Constants.MDC_NOTICE_NUMBER, noticeNumber);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected void setInMDCAfterClientResponse(String payload) {
if (payload != null && !payload.isBlank()) {
Matcher matcher = iuvPattern.matcher(payload);
if (matcher.find()) {
String noticeNumber = matcher.group(0);
String noticeNumber = matcher.group(1);
if (noticeNumber != null && !noticeNumber.isBlank()) {
MDC.put(Constants.MDC_NOTICE_NUMBER, noticeNumber);
}
Expand Down

0 comments on commit ef176b1

Please sign in to comment.