diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 8e1152b..3c84e55 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-wisp-converter-technical-support description: A service that permits to handle converted WISP requests for technical support type: application -version: 0.28.0 -appVersion: 0.2.1 +version: 0.30.0 +appVersion: 0.2.1-2-fix-migration-to-new-statuses dependencies: - name: microservice-chart version: 3.0.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 66b98f5..dfffc87 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-wisp-converter-technical-support - tag: "0.2.1" + tag: "0.2.1-2-fix-migration-to-new-statuses" pullPolicy: Always livenessProbe: httpGet: @@ -69,6 +69,7 @@ microservice-chart: CORS_CONFIGURATION: '{"origins": ["*"], "methods": ["*"]}' SERVICE_NAME: "pagopa-wisp-converter-technical-support" COSMOS_URI: "https://pagopa-d-weu-nodo-wispconv-cosmos-account.documents.azure.com:443/" + COSMOS_READ_REGION: "West Europe" secretProvider: create: true envSecrets: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index a9408ff..7a7d74f 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-wisp-converter-technical-support - tag: "0.2.1" + tag: "0.2.1-2-fix-migration-to-new-statuses" pullPolicy: Always livenessProbe: httpGet: @@ -69,6 +69,7 @@ microservice-chart: CORS_CONFIGURATION: '{"origins": ["*"], "methods": ["*"]}' SERVICE_NAME: "pagopa-wisp-converter-technical-support" COSMOS_URI: "https://pagopa-p-weu-nodo-wispconv-cosmos-account.documents.azure.com:443/" + COSMOS_READ_REGION: "North Europe" secretProvider: create: true envSecrets: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 77e833c..d02ffdc 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-wisp-converter-technical-support - tag: "0.2.1" + tag: "0.2.1-2-fix-migration-to-new-statuses" pullPolicy: Always livenessProbe: httpGet: @@ -69,6 +69,7 @@ microservice-chart: CORS_CONFIGURATION: '{"origins": ["*"], "methods": ["*"]}' SERVICE_NAME: "pagopa-wisp-converter-technical-support" COSMOS_URI: "https://pagopa-u-weu-nodo-wispconv-cosmos-account.documents.azure.com:443/" + COSMOS_READ_REGION: "West Europe" secretProvider: create: true envSecrets: diff --git a/openapi/openapi.json b/openapi/openapi.json index e7e6687..86dfb07 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "description": "A service that permits to handle converted WISP requests for technical support", "termsOfService": "https://www.pagopa.gov.it/", "title": "wisp-converter-technical-support", - "version": "0.2.1" + "version": "0.2.1-2-fix-migration-to-new-statuses" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 28e9935..e0558bf 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ it.gov.pagopa wisp-converter-technical-support - 0.2.1 + 0.2.1-2-fix-migration-to-new-statuses pagoPA WISP Converter Technical support A service that permits to handle converted WISP requests for technical support diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/config/CosmosDBConfig.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/config/CosmosDBConfig.java index 0d8127d..b37608c 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/config/CosmosDBConfig.java +++ b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/config/CosmosDBConfig.java @@ -18,6 +18,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.lang.Nullable; +import java.util.List; + @Configuration @EnableCosmosRepositories("it.gov.pagopa.wispconverter.technicalsupport.repository") @EnableConfigurationProperties @@ -38,6 +40,9 @@ public class CosmosDBConfig extends AbstractCosmosConfiguration { @Value("${azure.cosmos.populate-query-metrics}") private Boolean cosmosQueryMetrics; + @Value("${azure.cosmos.read.region}") + private String readRegion; + @Bean public CosmosClientBuilder getCosmosClientBuilder() { var azureKeyCredential = new AzureKeyCredential(cosmosKey); @@ -46,6 +51,7 @@ public CosmosClientBuilder getCosmosClientBuilder() { return new CosmosClientBuilder() .endpoint(cosmosUri) .credential(azureKeyCredential) + .preferredRegions(List.of(readRegion)) .directMode(directConnectionConfig, gatewayConnectionConfig); } diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/TechnicalSupportController.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/TechnicalSupportController.java index d843200..038d46f 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/TechnicalSupportController.java +++ b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/TechnicalSupportController.java @@ -5,11 +5,9 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; -import it.gov.pagopa.wispconverter.technicalsupport.controller.mapper.TechnicalSupportMapperDto; import it.gov.pagopa.wispconverter.technicalsupport.controller.model.ReEvent; import it.gov.pagopa.wispconverter.technicalsupport.controller.model.ReEventResponse; import it.gov.pagopa.wispconverter.technicalsupport.service.ReService; -import it.gov.pagopa.wispconverter.technicalsupport.service.model.ReEventDto; import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; @@ -30,7 +28,6 @@ public class TechnicalSupportController { private final ReService reService; - private final TechnicalSupportMapperDto technicalSupportMapperDto; @ApiResponses(value = { @ApiResponse( @@ -40,13 +37,12 @@ public class TechnicalSupportController { }) @GetMapping(value = "/organizations/{" + ORGANIZATION + "}/notice-number/{" + NOTICE_NUMBER + "}", produces = MediaType.APPLICATION_JSON_VALUE) public ReEventResponse findByNoticeNumber( - @PathVariable(name = ORGANIZATION) @Schema(example = "12345678900", description = "Id dell'EC") String organizationId, - @PathVariable(name = NOTICE_NUMBER) @Schema(example = "3982273480765907", description = "Numero avviso") String noticeNumber, - @RequestParam(name = DATE_FROM) @Schema(example = "2024-03-18", description = "Data di ricerca DA") LocalDate dateFrom, - @RequestParam(name = DATE_TO) @Schema(example = "2024-03-18", description = "Data di ricerca A") LocalDate dateTo) { + @PathVariable(name = ORGANIZATION) @Schema(example = "12345678900", description = "Creditor institution identifier") String organizationId, + @PathVariable(name = NOTICE_NUMBER) @Schema(example = "3982273480765907", description = "NAV payment code") String noticeNumber, + @RequestParam(name = DATE_FROM) @Schema(example = "2024-03-18", description = "Lower limit date") LocalDate dateFrom, + @RequestParam(name = DATE_TO) @Schema(example = "2024-03-18", description = "Upper limit date") LocalDate dateTo) { - List byNoticeNumber = reService.findByNoticeNumber(dateFrom, dateTo, organizationId, noticeNumber); - List reEventList = technicalSupportMapperDto.toReEventList(byNoticeNumber); + List reEventList = reService.findByNoticeNumber(dateFrom, dateTo, organizationId, noticeNumber); return ReEventResponse.builder() .count(reEventList.size()) .data(reEventList) @@ -61,12 +57,12 @@ public ReEventResponse findByNoticeNumber( }) @GetMapping(value = "/organizations/{" + ORGANIZATION + "}/iuv/{" + IUV + "}", produces = MediaType.APPLICATION_JSON_VALUE) public ReEventResponse findByIuv( - @PathVariable(name = ORGANIZATION) @Schema(example = "12345678900", description = "Id dell'EC") String organizationId, - @PathVariable(name = IUV) @Schema(example = "982273480765907", description = "Identificativo univoco del versamento") String iuv, - @RequestParam(name = DATE_FROM) @Schema(example = "2024-03-18", description = "Data di ricerca DA") LocalDate dateFrom, - @RequestParam(name = DATE_TO) @Schema(example = "2024-03-18", description = "Data di ricerca A") LocalDate dateTo) { - List byNoticeNumber = reService.findByIuv(dateFrom, dateTo, organizationId, iuv); - List reEventList = technicalSupportMapperDto.toReEventList(byNoticeNumber); + @PathVariable(name = ORGANIZATION) @Schema(example = "12345678900", description = "Creditor institution identifier") String organizationId, + @PathVariable(name = IUV) @Schema(example = "982273480765907", description = "IUV payment code") String iuv, + @RequestParam(name = DATE_FROM) @Schema(example = "2024-03-18", description = "Lower limit date") LocalDate dateFrom, + @RequestParam(name = DATE_TO) @Schema(example = "2024-03-18", description = "Upper limit date") LocalDate dateTo) { + + List reEventList = reService.findByIuv(dateFrom, dateTo, organizationId, iuv); return ReEventResponse.builder() .count(reEventList.size()) .data(reEventList) @@ -84,31 +80,11 @@ public ReEventResponse findBySessionId( @PathVariable(name = SESSION_ID) @Schema(example = "12345678900_aa0518a9-194d-4de2-999f-e462c3746e24", description = "Session identifier of the flow") String sessionId, @RequestParam(name = DATE_FROM) @Schema(example = "2024-03-18", description = "Data di ricerca DA") LocalDate dateFrom, @RequestParam(name = DATE_TO) @Schema(example = "2024-03-18", description = "Data di ricerca A") LocalDate dateTo) { - List bySessionId = reService.findBySessionId(dateFrom, dateTo, sessionId); - List reEventList = technicalSupportMapperDto.toReEventList(bySessionId); - return ReEventResponse.builder() - .count(reEventList.size()) - .data(reEventList) - .build(); - } - @ApiResponses(value = { - @ApiResponse( - responseCode = "200", - description = "Successfully retrieved event", - content = @Content(schema = @Schema(implementation = ReEventResponse.class))) - }) - @GetMapping(value = "/operation-id/{" + OPERATION_ID + "}", produces = MediaType.APPLICATION_JSON_VALUE) - public ReEventResponse findByOperationId( - @PathVariable(name = OPERATION_ID) @Schema(example = "fcfcbe1e-987a-4914-8fd2-d1e7b67762bf", description = "Identificativo dell'operazione eseguita") String operationId, - @RequestParam(name = DATE_FROM) @Schema(example = "2024-03-18", description = "Data di ricerca DA") LocalDate dateFrom, - @RequestParam(name = DATE_TO) @Schema(example = "2024-03-18", description = "Data di ricerca A") LocalDate dateTo) { - List byNoticeNumber = reService.findByOperationId(dateFrom, dateTo, operationId); - List reEventList = technicalSupportMapperDto.toReEventList(byNoticeNumber); + List reEventList = reService.findBySessionId(dateFrom, dateTo, sessionId); return ReEventResponse.builder() .count(reEventList.size()) .data(reEventList) .build(); } - } diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/mapper/ReEventMapper.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/mapper/ReEventMapper.java new file mode 100644 index 0000000..8d418af --- /dev/null +++ b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/mapper/ReEventMapper.java @@ -0,0 +1,48 @@ +package it.gov.pagopa.wispconverter.technicalsupport.controller.mapper; + +import it.gov.pagopa.wispconverter.technicalsupport.controller.model.ReEvent; +import it.gov.pagopa.wispconverter.technicalsupport.repository.model.ReEventEntity; +import it.gov.pagopa.wispconverter.technicalsupport.util.Constants; +import org.mapstruct.*; + +import java.util.List; + +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public abstract class ReEventMapper { + + @Named("toDto") + @Mapping(target = "requestHeaders", expression = "java(obfuscateSecrets(reEventEntity.getRequestHeaders()))") + @Mapping(target = "responseHeaders", expression = "java(obfuscateSecrets(reEventEntity.getResponseHeaders()))") + @Mapping(target = "requestPayload", expression = "java(it.gov.pagopa.wispconverter.technicalsupport.util.CommonUtility.decompressGZip(reEventEntity.getRequestPayload()))") + @Mapping(target = "responsePayload", expression = "java(it.gov.pagopa.wispconverter.technicalsupport.util.CommonUtility.decompressGZip(reEventEntity.getResponsePayload()))") + @Mapping(target = "operationId", expression = "java(reEventEntity.getOperationId() != null ? reEventEntity.getOperationId() : reEventEntity.getSessionId())") + @Mapping(target = "insertedTimestamp", expression = "java(reEventEntity.getInsertedTimestamp().plus(1, java.time.temporal.ChronoUnit.HOURS))") + public abstract ReEvent toDto(ReEventEntity reEventEntity); + + @IterableMapping(qualifiedByName = "toDto") + public abstract List toDto(List reEventEntity); + + public void compact(ReEvent event) { + event.setId(null); + event.setOperationId(null); + event.setHttpMethod(null); + event.setExecutionTimeMs(null); + event.setRequestHeaders(null); + event.setResponseHeaders(null); + event.setOperationErrorLine(null); + event.setOperationErrorDetail(null); + event.setSessionId(null); + event.setPsp(null); + event.setChannel(null); + event.setInfo(null); + event.setRequestPayload(null); + event.setResponsePayload(null); + } + + public String obfuscateSecrets(String httpHeaders) { + if (httpHeaders != null) { + httpHeaders = httpHeaders.replaceAll(Constants.SUBSCRIPTION_KEY_PATTERN, "\"Ocp-Apim-Subscription-Key\": [***]"); + } + return httpHeaders; + } +} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/mapper/TechnicalSupportMapperDto.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/mapper/TechnicalSupportMapperDto.java deleted file mode 100644 index b0d2434..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/mapper/TechnicalSupportMapperDto.java +++ /dev/null @@ -1,17 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.controller.mapper; - -import it.gov.pagopa.wispconverter.technicalsupport.controller.model.ReEvent; -import it.gov.pagopa.wispconverter.technicalsupport.service.model.ReEventDto; -import org.mapstruct.Mapper; -import org.mapstruct.ReportingPolicy; - -import java.util.List; - -@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) -public interface TechnicalSupportMapperDto { - - ReEvent toReEvent(ReEventDto source); - - List toReEventList(List reEventDtoList); - -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/model/EventCategoryEnum.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/model/EventCategoryEnum.java new file mode 100644 index 0000000..ee2bbe3 --- /dev/null +++ b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/model/EventCategoryEnum.java @@ -0,0 +1,6 @@ +package it.gov.pagopa.wispconverter.technicalsupport.controller.model; + +public enum EventCategoryEnum { + INTERFACE, + INTERNAL +} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/model/ReEvent.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/model/ReEvent.java index b6f41cc..9c26f81 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/model/ReEvent.java +++ b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/controller/model/ReEvent.java @@ -1,8 +1,8 @@ package it.gov.pagopa.wispconverter.technicalsupport.controller.model; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import it.gov.pagopa.wispconverter.technicalsupport.service.model.*; import lombok.*; import java.time.Instant; @@ -14,97 +14,120 @@ @Builder @JsonInclude(JsonInclude.Include.NON_NULL) public class ReEvent { - //// START KEY + @Schema(example = "fcfcbe1e-987a-4914-8fd2-d1e7b67762bf", description = "Id") + @JsonProperty("id") private String id; - //// END KEY - //// START LOGICAL REF - @Schema(example = "fcfcbe1e-987a-4914-8fd2-d1e7b67762bf", description = "Request Id") - private String requestId; //gruppo, tutte le chiamate fatte con lo stesso X-Request-ID @Schema(example = "fcfcbe1e-987a-4914-8fd2-d1e7b67762bf", description = "Identificativo dell'operazione eseguita") - private String operationId; //id operation associato a un requestId - @Schema(example = "fcfcbe1e-987a-4914-8fd2-d1e7b67762bf", description = "Identificativo dell'operazione client eseguita") - private String clientOperationId; //id client operation associato a un operationId - @Schema(example = "WISP_CONVERTER", description = "Identifica chi ha scritto l'evento. Esempio: WISP_CONVERTER") - private ComponentEnum componente; //componente che scrive l'evento + @JsonProperty("operation_id") + private String operationId; + + @Schema(example = "nodoInviaRPT", description = "Campo che identifica il processo di business") + @JsonProperty("business_process") + private String businessProcess; + @Schema(example = "2024-03-18T09:04:27.42017Z", description = "Data di inserimento evento") - private Instant insertedTimestamp; //ora di inserimento evento - //// END LOGICAL REF + @JsonProperty("inserted_timestamp") + private Instant insertedTimestamp; - //// START FIELD FOR INTERFACE AND INTERN CHANGE - @Schema(example = "INTERFACE", description = "Identifica se è un evento ai morsetti, ovvero di interfaccia, o interno, come cambio stato. Esempio: INTERFACE, INTERN") + @Schema(example = "INTERFACE", description = "...") + @JsonProperty("event_category") private EventCategoryEnum eventCategory; - @Schema(example = "RESP", description = "Identifica il tipo di morsetto in base alla categoriaEvento. Esempio: REQ, RESP, INTERN") - private EventSubcategoryEnum eventSubcategory; - //// END FIELD FOR INTERFACE AND INTERN CHANGE - //// START FIELD FOR INTERFACE - @Schema(example = "SERVER", description = "Identifica il tipo di chiamata. Esempio: SERVER, CLIENT") - private CallTypeEnum callType; + @Schema(example = "EXTRACTED_DATA_FROM_RPT", description = "Stato dell'RPT o del Carrello se la categoriaEvento è INTERN, altrienti è null") + @JsonProperty("status") + private String status; - @Schema(example = "SEND", description = "Esito dell'operazione eseguita. Esempio: SEND, SEND_FAILURE, RECEIVED, RECEIVED_FAILURE, NEVER_RECEIVED, EXECUTED_INTERNAL_STEP") - private OutcomeEnum outcome; + @Schema(example = "OK", description = "Esito dell'operazione eseguita. Esempio: SEND, SEND_FAILURE, RECEIVED, RECEIVED_FAILURE, NEVER_RECEIVED, EXECUTED_INTERNAL_STEP") + @JsonProperty("outcome") + private String outcome; @Schema(example = "POST", description = "HTTP method") + @JsonProperty("http_method") private String httpMethod; + @Schema(example = "https://api.platform.pagopa.it/nodo/nodo-per-psp/v1", description = "HTTP URI") + @JsonProperty("http_uri") private String httpUri; - @Schema(example = "Accept-Encoding :[\"gzip, deflate, br\"]", description = "HTTP headers") - private String httpHeaders; - @Schema(example = "127.0.0.1", description = "HTTP remote address") - private String httpCallRemoteAddress; @Schema(example = "200", description = "HTTP status") + @JsonProperty("http_status_code") private Integer httpStatusCode; + @Schema(example = "456", description = "HTTP execution time") + @JsonProperty("execution_time") private Long executionTimeMs; + @Schema(example = "Accept-Encoding :[\"gzip, deflate, br\"]", description = "HTTP headers") + @JsonProperty("request_headers") + private String requestHeaders; + + @Schema(example = "Accept-Encoding :[\"gzip, deflate, br\"]", description = "HTTP headers") + @JsonProperty("response_headers") + private String responseHeaders; + @Schema(example = "abadasdbasbdasd", description = "HTTP payload compress GZIP") - private String compressedPayload; //zip+Base64 - @Schema(example = "454", description = "HTTP payload compress length") - private Integer compressedPayloadLength; + @JsonProperty("request_payload") + private String requestPayload; - @Schema(example = "nodoInviaRPT", description = "Campo che identifica il processo di business") - private String businessProcess; + @Schema(example = "abadasdbasbdasd", description = "HTTP payload compress GZIP") + @JsonProperty("response_payload") + private String responsePayload; - @Schema(example = "Success", description = "Stato complessivo. Success|Failed") - private String operationStatus; //dettaglio response in uscita - @Schema(example = "Generic parsing error", description = "Title se stato Failed") - private String operationErrorTitle; //dettaglio response in uscita - @Schema(example = "Error while parsing payload. {0}", description = "Detail se stato Failed") - private String operationErrorDetail; //dettaglio response in uscita @Schema(example = "WIC-1000", description = "Error code se stato Failed") + @JsonProperty("operation_error_code") private String operationErrorCode; //dettaglio response in uscita - //// END FIELD FOR INTERFACE - //// START FIELD FOR INTERN CHANGE - @Schema(example = "nodoInviaRPT", description = "Nome della primitiva") - private String primitive; + @Schema(example = "Generic parsing error", description = "Title se stato Failed") + @JsonProperty("operation_error_line") + private String operationErrorLine; + + @Schema(example = "Error while parsing payload. {0}", description = "Detail se stato Failed") + @JsonProperty("operation_error_detail") + private String operationErrorDetail; + @Schema(example = "982273480765907", description = "Identificativo dell'operazione asincrona già eseguita") + @JsonProperty("session_id") private String sessionId; + @Schema(example = "12345678900982273480765907-0001", description = "Identificativo del carrello") + @JsonProperty("cart_id") private String cartId; + @Schema(example = "982273480765907", description = "Identificativo univoco versamento") + @JsonProperty("iuv") private String iuv; + @Schema(example = "3982273480765907", description = "Numero avviso") + @JsonProperty("notice_number") private String noticeNumber; + @Schema(example = "12345678900", description = "Id dell'EC") + @JsonProperty("domain_id") private String domainId; + @Schema(example = "TEST_4178733642", description = "Codice contesto pagmaneto") + @JsonProperty("ccp") private String ccp; + @Schema(example = "60000000001", description = "Id del prestatore servizi di pagamento") + @JsonProperty("psp") private String psp; + @Schema(example = "11111111111_05", description = "Identificativo della stazione che eroga i servizi per la PA") + @JsonProperty("station") private String station; + @Schema(example = "60000000001_01", description = "Identificativo del canale che eroga i servizi per il PSP") + @JsonProperty("channel") private String channel; - @Schema(example = "EXTRACTED_DATA_FROM_RPT", description = "Stato dell'RPT o del Carrello se la categoriaEvento è INTERN, altrienti è null") - private String status; + @Schema(example = "AABB123", description = "Numero univoco del pagamento") + @JsonProperty("payment_token") private String paymentToken; + @Schema(example = "https://api.platform.pagopa.it/nodo/nodo-per-psp/v1", description = "Informazioni generiche, es URI di chi ha chiamato o di chi sta chiamando") + @JsonProperty("info") private String info; - //// END FIELD FOR INTERN CHANGE - } diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/ReEventRepository.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/ReEventRepository.java index 46dc71f..20edd6e 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/ReEventRepository.java +++ b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/ReEventRepository.java @@ -7,17 +7,19 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import java.util.List; import java.util.Set; @Repository public interface ReEventRepository extends CosmosRepository { - - @Query("select * from c where c.partitionKey >= @dateFrom and c.partitionKey <= @dateTo and c.operationId = @operationId") - List findByOperationId(@Param("dateFrom") String dateFrom, - @Param("dateTo") String dateTo, - @Param("operationId") String operationId); + @Query("SELECT * " + + "FROM c " + + "WHERE (c.partitionKey >= @dateFrom AND c.partitionKey <= @dateTo) " + + "AND c.sessionId = @sessionId " + + "ORDER BY c._ts ASC") + Set findBySessionId(@Param("dateFrom") String dateFrom, + @Param("dateTo") String dateTo, + @Param("sessionId") String sessionId); @Query("SELECT DISTINCT VALUE c.sessionId " + @@ -31,6 +33,7 @@ Set findSessionIdByIuvAndDomainId(@Param("dateFrom") String dateFrom, @Param("organizationId") String organizationId, @Param("iuv") String iuv); + @Query("SELECT DISTINCT VALUE c.sessionId " + "FROM c " + "WHERE (c.partitionKey >= @dateFrom AND c.partitionKey <= @dateTo) " + @@ -42,56 +45,4 @@ Set findSessionIdByNoticeNumberAndDomainId(@Param("dateFrom") String dat @Param("organizationId") String organizationId, @Param("noticeNumber") String noticeNumber); - @Query("SELECT DISTINCT VALUE c.noticeNumber " + - "FROM c " + - "WHERE (c.partitionKey >= @dateFrom AND c.partitionKey <= @dateTo) " + - "AND ARRAY_CONTAINS(@sessionIds, c.sessionId) " + - "AND IS_DEFINED(c.noticeNumber) AND c.noticeNumber != null") - Set findNoticeNumberBySessionId(@Param("dateFrom") String dateFrom, - @Param("dateTo") String dateTo, - @Param("sessionIds") Set sessionId); - - @Query("SELECT DISTINCT VALUE c.domainId " + - "FROM c " + - "WHERE (c.partitionKey >= @dateFrom AND c.partitionKey <= @dateTo) " + - "AND c.sessionId = @sessionId " + - "AND IS_DEFINED(c.domainId) AND c.domainId != null") - List findDomainIdBySessionId(@Param("dateFrom") String dateFrom, - @Param("dateTo") String dateTo, - @Param("sessionId") String sessionId); - - @Query("SELECT DISTINCT VALUE c.paymentToken " + - "FROM c " + - "WHERE (c.partitionKey >= @dateFrom AND c.partitionKey <= @dateTo) " + - "AND ARRAY_CONTAINS(@noticeNumbers, c.noticeNumber) " + - "AND c.domainId = @organizationId " + - "AND IS_DEFINED(c.paymentToken) AND c.paymentToken != null") - Set findPaymentTokenByNoticeNumber(@Param("dateFrom") String dateFrom, - @Param("dateTo") String dateTo, - @Param("organizationId") String organizationId, - @Param("noticeNumbers") Set noticeNumbers); - - @Query("SELECT DISTINCT VALUE c.operationId " + - "FROM c " + - "WHERE (c.partitionKey >= @dateFrom AND c.partitionKey <= @dateTo) " + - "AND (ARRAY_CONTAINS(@sessionIds, c.sessionId) " + - "OR ((ARRAY_CONTAINS(@noticeNumbers, c.noticeNumber) AND c.domainId = @organizationId) OR ARRAY_CONTAINS(@paymentTokens, c.paymentToken))) " + - "AND IS_DEFINED(c.operationId) AND c.operationId != null") - Set findOperationIdByFoundData(@Param("dateFrom") String dateFrom, - @Param("dateTo") String dateTo, - @Param("organizationId") String organizationId, - @Param("sessionIds") Set sessionIds, - @Param("noticeNumbers") Set noticeNumbers, - @Param("paymentTokens") Set paymentTokens); - - @Query("SELECT * " + - "FROM c " + - "WHERE (c.partitionKey >= @dateFrom AND c.partitionKey <= @dateTo) " + - "AND ARRAY_CONTAINS(@operationIds, c.operationId) " + - "OR ARRAY_CONTAINS(@sessionIds, c.sessionId) " + - "ORDER BY c._ts ASC") - List findByOperationIdAndSessionId(@Param("dateFrom") String dateFrom, - @Param("dateTo") String dateTo, - @Param("operationIds") Set operationIds, - @Param("sessionIds") Set sessionIds); } \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/ReEventEntity.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/ReEventEntity.java index c113249..e32aef9 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/ReEventEntity.java +++ b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/ReEventEntity.java @@ -1,11 +1,8 @@ package it.gov.pagopa.wispconverter.technicalsupport.repository.model; import com.azure.spring.data.cosmos.core.mapping.Container; +import com.azure.spring.data.cosmos.core.mapping.GeneratedValue; import com.azure.spring.data.cosmos.core.mapping.PartitionKey; -import it.gov.pagopa.wispconverter.technicalsupport.service.model.ComponentEnum; -import it.gov.pagopa.wispconverter.technicalsupport.service.model.EventCategoryEnum; -import it.gov.pagopa.wispconverter.technicalsupport.service.model.EventSubcategoryEnum; -import it.gov.pagopa.wispconverter.technicalsupport.service.model.OutcomeEnum; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -20,56 +17,37 @@ @AllArgsConstructor @NoArgsConstructor public class ReEventEntity { - //// START KEY + + /** + * The identifier of the single event. + */ @Id + @GeneratedValue private String id; + /** + * The partition key that refers to the single partition on which the event will be stored. + */ @PartitionKey private String partitionKey; - //// END KEY - - //// START LOGICAL REF - private String requestId; //gruppo, tutte le chiamate fatte con lo stesso X-Request-ID - private String operationId; //id operation associato a un requestId - private String clientOperationId; //id client operation associato a un operationId - private ComponentEnum component; //componente che scrive l'evento - private Instant insertedTimestamp; //ora di inserimento evento - //// END LOGICAL REF - - //// START FIELD FOR INTERFACE AND INTERN CHANGE - private EventCategoryEnum eventCategory; - private EventSubcategoryEnum eventSubcategory; - //// END FIELD FOR INTERFACE AND INTERN CHANGE - - //// START FIELD FOR INTERFACE - private it.gov.pagopa.wispconverter.technicalsupport.service.model.CallTypeEnum callType; - - private String consumer; - private String provider; - - private OutcomeEnum outcome; + private String operationId; + private Instant insertedTimestamp; + private String businessProcess; + private String eventCategory; + private String status; + private String outcome; private String httpMethod; private String httpUri; - private String httpHeaders; - private String httpCallRemoteAddress; - private Integer httpStatusCode; private Long executionTimeMs; - - private String compressedPayload; //zip+Base64 - private Integer compressedPayloadLength; - - private String businessProcess; - - private String operationStatus; //dettaglio response in uscita - private String operationErrorTitle; //dettaglio response in uscita - private String operationErrorDetail; //dettaglio response in uscita - private String operationErrorCode; //dettaglio response in uscita - //// END FIELD FOR INTERFACE - - //// START FIELD FOR INTERN CHANGE - private String primitive; + private String requestHeaders; + private String responseHeaders; + private String requestPayload; + private String responsePayload; + private String operationErrorCode; + private String operationErrorLine; + private String operationErrorDetail; private String sessionId; private String cartId; private String iuv; @@ -79,9 +57,11 @@ public class ReEventEntity { private String psp; private String station; private String channel; - private String status; private String paymentToken; private String info; - //// END FIELD FOR INTERN CHANGE + private Instant _ts; + public Instant getTimestamp() { + return this._ts; + } } diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/CallTypeEnum.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/CallTypeEnum.java deleted file mode 100644 index f7c79f6..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/CallTypeEnum.java +++ /dev/null @@ -1,6 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.repository.model.enumz; - -public enum CallTypeEnum { - SERVER, - CLIENT; -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/ComponentEnum.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/ComponentEnum.java deleted file mode 100644 index ed65464..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/ComponentEnum.java +++ /dev/null @@ -1,7 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.repository.model.enumz; - -public enum ComponentEnum { - // FESP, - WISP_SOAP_CONVERTER, - WISP_CONVERTER -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/EventCategoryEnum.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/EventCategoryEnum.java deleted file mode 100644 index 9a85ba3..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/EventCategoryEnum.java +++ /dev/null @@ -1,6 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.repository.model.enumz; - -public enum EventCategoryEnum { - INTERFACCIA, - INTERNO -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/EventSubcategoryEnum.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/EventSubcategoryEnum.java deleted file mode 100644 index 65e37b8..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/EventSubcategoryEnum.java +++ /dev/null @@ -1,7 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.repository.model.enumz; - -public enum EventSubcategoryEnum { - REQ, - RESP, - INTERN -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/OutcomeEnum.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/OutcomeEnum.java deleted file mode 100644 index 47f4ee7..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/repository/model/enumz/OutcomeEnum.java +++ /dev/null @@ -1,5 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.repository.model.enumz; - -public enum OutcomeEnum { - INVIATA, INVIATA_KO, RICEVUTA, RICEVUTA_KO, NO_RICEVUTA, CAMBIO_STATO -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/ReService.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/ReService.java index 1af55d2..e09ddc8 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/ReService.java +++ b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/ReService.java @@ -1,17 +1,16 @@ package it.gov.pagopa.wispconverter.technicalsupport.service; -import it.gov.pagopa.wispconverter.technicalsupport.exception.AppError; -import it.gov.pagopa.wispconverter.technicalsupport.exception.AppException; +import it.gov.pagopa.wispconverter.technicalsupport.controller.mapper.ReEventMapper; +import it.gov.pagopa.wispconverter.technicalsupport.controller.model.ReEvent; import it.gov.pagopa.wispconverter.technicalsupport.repository.ReEventRepository; import it.gov.pagopa.wispconverter.technicalsupport.repository.model.ReEventEntity; -import it.gov.pagopa.wispconverter.technicalsupport.service.mapper.ReEventMapper; -import it.gov.pagopa.wispconverter.technicalsupport.service.model.ReEventDto; +import it.gov.pagopa.wispconverter.technicalsupport.util.CommonUtility; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.time.LocalDate; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; +import java.util.Comparator; +import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -19,72 +18,51 @@ @RequiredArgsConstructor public class ReService { - static final String PATTERN_FORMAT = "yyyy-MM-dd"; - private final ReEventRepository reEventRepository; - private final ReEventMapper reEventMapper; - public static String partitionKeyFromInstant(LocalDate insertedTimestamp) { - return insertedTimestamp == null ? null : DateTimeFormatter - .ofPattern(PATTERN_FORMAT) - .withZone(ZoneId.systemDefault()) - .format(insertedTimestamp); - } + private final ReEventMapper reEventMapper; - public List findByNoticeNumber(LocalDate dateFromAsLocalDate, LocalDate dateToAsLocalDate, String organization, String noticeNumber) { + public List findByNoticeNumber(LocalDate dateFromAsLocalDate, LocalDate dateToAsLocalDate, String organization, String noticeNumber) { - String dateFrom = partitionKeyFromInstant(dateFromAsLocalDate); - String dateTo = partitionKeyFromInstant(dateToAsLocalDate); + String dateFrom = CommonUtility.partitionKeyFromInstant(dateFromAsLocalDate); + String dateTo = CommonUtility.partitionKeyFromInstant(dateToAsLocalDate); Set sessionIds = reEventRepository.findSessionIdByNoticeNumberAndDomainId(dateFrom, dateTo, organization, noticeNumber); - Set noticeNumbers = reEventRepository.findNoticeNumberBySessionId(dateFrom, dateTo, sessionIds); - Set paymentTokens = reEventRepository.findPaymentTokenByNoticeNumber(dateFrom, dateTo, organization, noticeNumbers); - Set operationIds = reEventRepository.findOperationIdByFoundData(dateFrom, dateTo, organization, sessionIds, noticeNumbers, paymentTokens); - List reEventEntities = reEventRepository.findByOperationIdAndSessionId(dateFrom, dateTo, operationIds, sessionIds); - return reEventMapper.toReEventDtoList(reEventEntities); + return extractReEventsFromWispDismantling(dateFrom, dateTo, sessionIds); } - public List findByIuv(LocalDate dateFromAsLocalDate, LocalDate dateToAsLocalDate, String organization, String iuv) { + public List findByIuv(LocalDate dateFromAsLocalDate, + LocalDate dateToAsLocalDate, + String organization, + String iuv) { - String dateFrom = partitionKeyFromInstant(dateFromAsLocalDate); - String dateTo = partitionKeyFromInstant(dateToAsLocalDate); + String dateFrom = CommonUtility.partitionKeyFromInstant(dateFromAsLocalDate); + String dateTo = CommonUtility.partitionKeyFromInstant(dateToAsLocalDate); Set sessionIds = reEventRepository.findSessionIdByIuvAndDomainId(dateFrom, dateTo, organization, iuv); - Set noticeNumbers = reEventRepository.findNoticeNumberBySessionId(dateFrom, dateTo, sessionIds); - Set paymentTokens = reEventRepository.findPaymentTokenByNoticeNumber(dateFrom, dateTo, organization, noticeNumbers); - Set operationIds = reEventRepository.findOperationIdByFoundData(dateFrom, dateTo, organization, sessionIds, noticeNumbers, paymentTokens); - List reEventEntities = reEventRepository.findByOperationIdAndSessionId(dateFrom, dateTo, operationIds, sessionIds); - return reEventMapper.toReEventDtoList(reEventEntities); + return extractReEventsFromWispDismantling(dateFrom, dateTo, sessionIds); } - public List findBySessionId(LocalDate dateFromAsLocalDate, LocalDate dateToAsLocalDate, String sessionId) { + public List findBySessionId(LocalDate dateFromAsLocalDate, LocalDate dateToAsLocalDate, String sessionId) { - String dateFrom = partitionKeyFromInstant(dateFromAsLocalDate); - String dateTo = partitionKeyFromInstant(dateToAsLocalDate); + String dateFrom = CommonUtility.partitionKeyFromInstant(dateFromAsLocalDate); + String dateTo = CommonUtility.partitionKeyFromInstant(dateToAsLocalDate); - Set sessionIds = Set.of(sessionId); - List organizations = reEventRepository.findDomainIdBySessionId(dateFrom, dateTo, sessionId); - if (organizations.size() != 1) { - throw new AppException(AppError.INVALID_SESSIONID); - } + return extractReEventsFromWispDismantling(dateFrom, dateTo, Set.of(sessionId)); + } - String organization = organizations.get(0); - Set noticeNumbers = reEventRepository.findNoticeNumberBySessionId(dateFrom, dateTo, sessionIds); - Set paymentTokens = reEventRepository.findPaymentTokenByNoticeNumber(dateFrom, dateTo, organization, noticeNumbers); - Set operationIds = reEventRepository.findOperationIdByFoundData(dateFrom, dateTo, organization, sessionIds, noticeNumbers, paymentTokens); - List reEventEntities = reEventRepository.findByOperationIdAndSessionId(dateFrom, dateTo, operationIds, sessionIds); + private List extractReEventsFromWispDismantling(String dateFrom, String dateTo, Set sessionIds) { - return reEventMapper.toReEventDtoList(reEventEntities); - } + List reEventEntities = new LinkedList<>(); + sessionIds.stream() + .flatMap(sessionId -> reEventRepository.findBySessionId(dateFrom, dateTo, sessionId).stream()) + .forEach(reEventEntities::add); - public List findByOperationId(LocalDate datefrom, LocalDate dateTo, String operationId) { - List reEventEntities = reEventRepository.findByOperationId( - partitionKeyFromInstant(datefrom), - partitionKeyFromInstant(dateTo), - operationId); - return reEventMapper.toReEventDtoList(reEventEntities); + // convert all entities to DTOs then sort them by inserted timestamp + List reEvents = reEventMapper.toDto(reEventEntities); + reEvents.sort(Comparator.comparing(ReEvent::getInsertedTimestamp)); + return reEvents; } - } diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/mapper/ReEventMapper.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/mapper/ReEventMapper.java deleted file mode 100644 index 576794b..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/mapper/ReEventMapper.java +++ /dev/null @@ -1,26 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.service.mapper; - -import it.gov.pagopa.wispconverter.technicalsupport.repository.model.ReEventEntity; -import it.gov.pagopa.wispconverter.technicalsupport.service.model.ReEventDto; -import it.gov.pagopa.wispconverter.technicalsupport.util.Constants; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.ReportingPolicy; - -import java.util.List; - -@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) -public abstract class ReEventMapper { - - @Mapping(target = "httpHeaders", expression = "java(obfuscateSecrets(reEventEntity.getHttpHeaders()))") - public abstract ReEventDto toReEventDto(ReEventEntity reEventEntity); - - public abstract List toReEventDtoList(List reEventEntity); - - public String obfuscateSecrets(String httpHeaders) { - if (httpHeaders != null) { - httpHeaders = httpHeaders.replaceAll(Constants.SUBSCRIPTION_KEY_PATTERN, "\"Ocp-Apim-Subscription-Key\": [***]"); - } - return httpHeaders; - } -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/CallTypeEnum.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/CallTypeEnum.java deleted file mode 100644 index 37b0753..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/CallTypeEnum.java +++ /dev/null @@ -1,6 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.service.model; - -public enum CallTypeEnum { - SERVER, - CLIENT; -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/ComponentEnum.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/ComponentEnum.java deleted file mode 100644 index 45c81ad..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/ComponentEnum.java +++ /dev/null @@ -1,7 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.service.model; - -public enum ComponentEnum { - // FESP, - WISP_SOAP_CONVERTER, - WISP_CONVERTER -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/EventCategoryEnum.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/EventCategoryEnum.java deleted file mode 100644 index 9ae3d23..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/EventCategoryEnum.java +++ /dev/null @@ -1,6 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.service.model; - -public enum EventCategoryEnum { - INTERFACE, - INTERNAL -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/EventSubcategoryEnum.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/EventSubcategoryEnum.java deleted file mode 100644 index d8295b8..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/EventSubcategoryEnum.java +++ /dev/null @@ -1,7 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.service.model; - -public enum EventSubcategoryEnum { - REQ, - RESP, - INTERN -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/OutcomeEnum.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/OutcomeEnum.java deleted file mode 100644 index 0c69bba..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/OutcomeEnum.java +++ /dev/null @@ -1,11 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.service.model; - -public enum OutcomeEnum { - SEND, - SEND_FAILURE, - RECEIVED, - RECEIVED_FAILURE, - NEVER_RECEIVED, - EXECUTED_INTERNAL_STEP, - EXCECUTED_INTERNAL_STEP, // TODO for avoid backward compatibility with wrong older RE events, to delete in future steps -} \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/ReEventDto.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/ReEventDto.java deleted file mode 100644 index 1b9c2e6..0000000 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/service/model/ReEventDto.java +++ /dev/null @@ -1,76 +0,0 @@ -package it.gov.pagopa.wispconverter.technicalsupport.service.model; - -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import lombok.*; - -import java.time.Instant; - -@Data -@EqualsAndHashCode -@AllArgsConstructor -@NoArgsConstructor -@Builder -@JsonPropertyOrder() -//@Accessors(fluent = true,chain = true) -public class ReEventDto { - //// START KEY - private String id; - //// END KEY - - //// START LOGICAL REF - private String requestId; //gruppo, tutte le chiamate fatte con lo stesso X-Request-ID - private String operationId; //id operation associato a un requestId - private String clientOperationId; //id client operation associato a un operationId - private ComponentEnum component; //componente che scrive l'evento - private Instant insertedTimestamp; //ora di inserimento evento - //// END LOGICAL REF - - //// START FIELD FOR INTERFACE AND INTERN CHANGE - private EventCategoryEnum eventCategory; - private EventSubcategoryEnum eventSubcategory; - //// END FIELD FOR INTERFACE AND INTERN CHANGE - - //// START FIELD FOR INTERFACE - private CallTypeEnum callType; - - private String consumer; - private String provider; - - private OutcomeEnum outcome; - - private String httpMethod; - private String httpUri; - private String httpHeaders; - private String httpCallRemoteAddress; - - private Integer httpStatusCode; - private Long executionTimeMs; - - private String compressedPayload; //zip+Base64 - private Integer compressedPayloadLength; - - private String businessProcess; - - private String operationStatus; //dettaglio response in uscita - private String operationErrorTitle; //dettaglio response in uscita - private String operationErrorDetail; //dettaglio response in uscita - private String operationErrorCode; //dettaglio response in uscita - //// END FIELD FOR INTERFACE - - //// START FIELD FOR INTERN CHANGE - private String primitive; - private String sessionId; - private String cartId; - private String iuv; - private String noticeNumber; - private String domainId; - private String ccp; - private String psp; - private String station; - private String channel; - private String status; - private String paymentToken; - private String info; - //// END FIELD FOR INTERN CHANGE - -} diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/util/CommonUtility.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/util/CommonUtility.java index 1f4f530..f2356d3 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/util/CommonUtility.java +++ b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/util/CommonUtility.java @@ -3,9 +3,16 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.Base64; import java.util.Calendar; import java.util.List; import java.util.Optional; +import java.util.zip.GZIPInputStream; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class CommonUtility { @@ -27,6 +34,14 @@ public static String deNull(Object value) { return Optional.ofNullable(value).orElse("").toString(); } + /** + * @param value value to nullify. + * @return return null string if value is null or empty + */ + public static String nullify(String value) { + return value == null || value.isEmpty() ? null : value; + } + /** * @param value value to deNullify. * @return return false if value is null @@ -51,5 +66,37 @@ public static long getTimelapse(long startTime) { return Calendar.getInstance().getTimeInMillis() - startTime; } + public static String partitionKeyFromInstant(LocalDate insertedTimestamp) { + return insertedTimestamp == null ? null : DateTimeFormatter + .ofPattern(Constants.PATTERN_FORMAT) + .withZone(ZoneId.systemDefault()) + .format(insertedTimestamp); + } + + public static String decompressGZip(String gzipContent) { + String result; + if (gzipContent == null || gzipContent.isEmpty()) { + result = ""; + } else { + + byte[] compressedData = Base64.getDecoder().decode(gzipContent); + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(compressedData); + + try (GZIPInputStream gzipInputStream = new GZIPInputStream(byteArrayInputStream)) { + + byte[] buffer = new byte[1024]; + StringBuilder output = new StringBuilder(); + int bytesRead; + while ((bytesRead = gzipInputStream.read(buffer)) != -1) { + output.append(new String(buffer, 0, bytesRead)); + } + result = output.toString(); + + } catch (IOException e) { + result = null; + } + } + return result; + } } diff --git a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/util/Constants.java b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/util/Constants.java index 6ad4311..dffad4d 100644 --- a/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/util/Constants.java +++ b/src/main/java/it/gov/pagopa/wispconverter/technicalsupport/util/Constants.java @@ -6,6 +6,7 @@ public class Constants { + public static final String PATTERN_FORMAT = "yyyy-MM-dd"; public static final String HEADER_REQUEST_ID = "X-Request-Id"; public static final String ORGANIZATION = "organizationId"; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b07865d..30bc760 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -34,5 +34,4 @@ azure.cosmos.uri=${COSMOS_URI:https://pagopa-d-weu-nodo-wispconv-cosmos-account. azure.cosmos.key=${COSMOS_KEY:na} azure.cosmos.populate-query-metrics=false azure.cosmos.database=wispconverter - - +azure.cosmos.read.region=${COSMOS_READ_REGION:West Europe} \ No newline at end of file diff --git a/src/test/java/it/gov/pagopa/wispconverter/technicalsupport/TechnicalSupportControllerTest.java b/src/test/java/it/gov/pagopa/wispconverter/technicalsupport/TechnicalSupportControllerTest.java index 0492dbd..7264505 100644 --- a/src/test/java/it/gov/pagopa/wispconverter/technicalsupport/TechnicalSupportControllerTest.java +++ b/src/test/java/it/gov/pagopa/wispconverter/technicalsupport/TechnicalSupportControllerTest.java @@ -200,8 +200,8 @@ void findByOperationIdVerifyPayloadOK() { List reEventEntityList = Collections.singletonList(ReEventEntity.builder() .partitionKey(dateFrom) .operationId(operationId) - .compressedPayload(compressedPayload) - .compressedPayloadLength(compressedPayloadLength) + //.compressedPayload(compressedPayload) + //.compressedPayloadLength(compressedPayloadLength) .build()); Mockito.when(reEventRepository.findByOperationId(any(), any(), any())).thenReturn(reEventEntityList); @@ -220,11 +220,11 @@ void findByOperationIdVerifyPayloadOK() { assertThat(reEventResponse.getData()).hasSize(1); assertThat(reEventResponse.getData().get(0).getOperationId()).isEqualTo(operationId); - assertThat(reEventResponse.getData().get(0).getCompressedPayload()).isEqualTo(compressedPayload); + /*assertThat(reEventResponse.getData().get(0).getCompressedPayload()).isEqualTo(compressedPayload); assertThat(reEventResponse.getData().get(0).getCompressedPayloadLength()).isEqualTo(compressedPayloadLength); String payloadReverse = getUtf8String(unzip(base64Decode(reEventResponse.getData().get(0).getCompressedPayload()))); - assertThat(payloadReverse).isEqualTo(payload); + assertThat(payloadReverse).isEqualTo(payload);*/ } }