Skip to content

Commit

Permalink
Merge branch 'main' into PAGOPA-2261
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-ang authored Oct 18, 2024
2 parents d24d8a3 + c67e8a1 commit 6015b7d
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 9 deletions.
2 changes: 1 addition & 1 deletion helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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.242.0
appVersion: 0.4.12-1-PAGOPA-2261
appVersion: 0.4.13
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: "0.4.12-1-PAGOPA-2261"
tag: "0.4.13"
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: "0.4.12-1-PAGOPA-2261"
tag: "0.4.13"
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: "0.4.12-1-PAGOPA-2261"
tag: "0.4.13"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
70 changes: 68 additions & 2 deletions 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": "0.4.12-1-PAGOPA-2261"
"version": "0.4.13"
},
"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>0.4.12-1-PAGOPA-2261</version>
<version>0.4.13</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 @@ -7,6 +7,7 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.wispconverter.controller.model.RecoveryReceiptByPartitionRequest;
import it.gov.pagopa.wispconverter.controller.model.RecoveryReceiptBySessionIdRequest;
import it.gov.pagopa.wispconverter.controller.model.RecoveryReceiptReportResponse;
import it.gov.pagopa.wispconverter.controller.model.RecoveryReceiptRequest;
import it.gov.pagopa.wispconverter.controller.model.RecoveryReceiptResponse;
Expand Down Expand Up @@ -130,4 +131,23 @@ public ResponseEntity<RecoveryReceiptReportResponse> recoverReceiptToBeReSentByP
throw ex;
}
}

@Operation(summary = "Execute reconciliation for OK receipts by sessionId.", description = "Execute reconciliation of all receipts related to the sessionIds of the request", security = {@SecurityRequirement(name = "ApiKey")}, tags = {"Recovery"})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Reconciliation scheduled")
})
@PostMapping(value = "/sessionIds/ok")
public ResponseEntity<RecoveryReceiptReportResponse> recoverReceiptToBeReSentBySessionId(@RequestBody RecoveryReceiptBySessionIdRequest request) {
try {
log.debug("Invoking API operation recoverReceiptToBeReSentBySessionId - args: {}", sanitizeInput(request.toString()));
return ResponseEntity.ok(recoveryService.recoverReceiptOkToBeReSentBySessionIds(request));
} catch (Exception ex) {
String operationId = MDC.get(Constants.MDC_OPERATION_ID);
log.error(String.format("GenericException: operation-id=[%s]", operationId != null ? operationId : "n/a"), ex);
AppException appException = new AppException(ex, AppErrorCodeMessageEnum.ERROR, ex.getMessage());
ErrorResponse errorResponse = errorUtil.forAppException(appException);
log.error("Failed API operation recoverReceiptToBeReSentBySessionId - error: {}", errorResponse);
throw ex;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package it.gov.pagopa.wispconverter.controller.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.List;

@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
public class RecoveryReceiptBySessionIdRequest {

private List<String> sessionIds;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.gov.pagopa.wispconverter.secondary;

import com.azure.spring.data.cosmos.repository.CosmosRepository;
import it.gov.pagopa.wispconverter.repository.model.IdempotencyKeyEntity;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

@Repository
@Qualifier("secondaryCosmosTemplate")
public interface IdempotencyKeyRepositorySecondary extends CosmosRepository<IdempotencyKeyEntity, String> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ List<ReEventEntity> findBySessionIdAndStatusAndPartitionKey(@Param("date") Strin
@Param("sessionId") String sessionId,
@Param("status") String status);

@Query("SELECT * FROM c " +
"WHERE c.sessionId = @sessionId " +
"AND c.component = 'WISP_SOAP_CONVERTER' " +
"AND c.status = 'RPT_ACCETTATA_NODO' ORDER BY c._ts")
List<ReEventEntity> findRptAccettataNodoBySessionId(@Param("sessionId") String sessionId);

@Query(
"SELECT wispSession.sessionId " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import it.gov.pagopa.wispconverter.repository.RPTRequestRepository;
import it.gov.pagopa.wispconverter.repository.RTRetryRepository;
import it.gov.pagopa.wispconverter.repository.model.*;
import it.gov.pagopa.wispconverter.repository.model.enumz.IdempotencyStatusEnum;
import it.gov.pagopa.wispconverter.repository.model.enumz.InternalStepStatus;
import it.gov.pagopa.wispconverter.repository.model.enumz.ReceiptStatusEnum;
import it.gov.pagopa.wispconverter.repository.model.enumz.ReceiptTypeEnum;
import it.gov.pagopa.wispconverter.secondary.IdempotencyKeyRepositorySecondary;
import it.gov.pagopa.wispconverter.secondary.RTRepositorySecondary;
import it.gov.pagopa.wispconverter.secondary.ReEventRepositorySecondary;
import it.gov.pagopa.wispconverter.service.model.re.ReEventDto;
Expand All @@ -31,6 +33,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.net.InetSocketAddress;
Expand All @@ -43,6 +46,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -74,6 +78,8 @@ public class RecoveryService {

private final ReEventRepositorySecondary reEventRepository;

private final IdempotencyKeyRepositorySecondary idempotencyKeyRepositorySecondary;

private final ReceiptService receiptService;

private final RPTRequestRepository rptRequestRepository;
Expand Down Expand Up @@ -250,6 +256,63 @@ private void generateRE(String primitive, String operationStatus, InternalStepSt
reService.addRe(reEvent);
}

@Transactional
public RecoveryReceiptReportResponse recoverReceiptOkToBeReSentBySessionIds(RecoveryReceiptBySessionIdRequest request) {
List<String> receiptsIds = new ArrayList<>();
try {
for (String sessionId : request.getSessionIds()) {
// extract rpt from re
List<ReEventEntity> reItems = reEventRepository.findRptAccettataNodoBySessionId(sessionId);
for(ReEventEntity reItem : reItems) {
String[] brokerEC = reItem.getStation().split("_");
String receiptId = brokerEC[0] + "_" + UUID.randomUUID();
IdempotencyKeyEntity idempotencyKey = IdempotencyKeyEntity.builder()
.id(String.format("%s_%s_%s", reItem.getSessionId(), reItem.getIuv(), reItem.getDomainId()))
.partitionKey(reItem.getPartitionKey())
.receiptType(ReceiptTypeEnum.OK)
.sessionId(reItem.getSessionId())
.status(IdempotencyStatusEnum.FAILED)
.build();
idempotencyKeyRepositorySecondary.save(idempotencyKey);
String payload = "<soapenv:Envelope\n" +
"\txmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
"\txmlns:ns2=\"http://ws.pagamenti.telematici.gov/ppthead\"\n" +
"\txmlns:ns3=\"http://ws.pagamenti.telematici.gov/\"><soapenv:Header><ns2:intestazionePPT\n" +
"\t\t\txmlns:ns4=\"http://schemas.xmlsoap.org/soap/envelope/\"><identificativoIntermediarioPA></identificativoIntermediarioPA><identificativoStazioneIntermediarioPA></identificativoStazioneIntermediarioPA><identificativoDominio>DOMINIO</identificativoDominio><identificativoUnivocoVersamento>IUV</identificativoUnivocoVersamento><codiceContestoPagamento></codiceContestoPagamento></ns2:intestazionePPT></soapenv:Header><soapenv:Body><ns3:paaInviaRT><tipoFirma/><rt></rt></ns3:paaInviaRT></soapenv:Body></soapenv:Envelope>"
.replace("DOMINIO", reItem.getDomainId())
.replace("IUV", reItem.getIuv());

// create a RTRequestEntity to generate the ok receipt
RTRequestEntity receipt = RTRequestEntity.builder()
.id(receiptId)
.partitionKey(reItem.getPartitionKey())
.domainId(reItem.getDomainId())
.idempotencyKey(idempotencyKey.getId())
.iuv(reItem.getIuv())
.ccp(reItem.getCcp())
.sessionId(sessionId)
.payload(AppBase64Util.base64Encode(ZipUtil.zip(payload)))
.primitive(reItem.getPrimitive())
.receiptType(ReceiptTypeEnum.OK)
.station(reItem.getStation())
.build();
rtRetryRepository.save(receipt);
receiptsIds.add(receiptId);
}
}


RecoveryReceiptRequest req = RecoveryReceiptRequest.builder()
.receiptIds(receiptsIds)
.build();

return recoverReceiptToBeReSent(req);
}
catch (IOException e) {
throw new AppException(AppErrorCodeMessageEnum.ERROR, "Problem with receipt payload");
}
}

public RecoveryReceiptReportResponse recoverReceiptToBeReSentByPartition(RecoveryReceiptByPartitionRequest request) {

List<String> receiptsIds = request.getPartitionKeys().stream()
Expand Down Expand Up @@ -348,11 +411,12 @@ public RecoveryReceiptReportResponse recoverReceiptToBeReSent(RecoveryReceiptReq
rtRequestEntity.setId(overriddenReceiptId);
rtRequestEntity.setDomainId(domainId);
rtRequestEntity.setIdempotencyKey(overriddenIdempotencyKey);
rtRequestEntity.setSessionId(sessionId);
rtRequestEntity.setRetry(0);
rtRequestEntity.setPayload(AppBase64Util.base64Encode(ZipUtil.zip(payload)));
rtRetryRepository.save(rtRequestEntity);

String compositedIdForReceipt = String.format("%s_%s", rtRequestEntity.getPartitionKey(), rtRequestEntity.getId());
String compositedIdForReceipt = String.format("%s_%s", rtRequestEntity.getPartitionKey(), overriddenReceiptId);
serviceBusService.sendMessage(compositedIdForReceipt, null);
generateRE(null, "Success", InternalStepStatus.RT_SEND_RESCHEDULING_SUCCESS,
null, null, null, sessionId, String.format("Generated receipt: %s", overriddenReceiptId));
Expand Down

0 comments on commit 6015b7d

Please sign in to comment.