From 1f5e30e6809d82853e525a94569118a6f46eb4b5 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Tue, 25 Jun 2024 08:19:54 +0000 Subject: [PATCH 1/4] Bump to version 2.15.1 [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi.json | 2 +- pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 9a0a8cf30..8e2cc59c6 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-selfcare-ms-backoffice description: Microservice that manage api keys for pagopa product from selfcare type: application -version: 0.348.0 -appVersion: "2.15.0" +version: 0.349.0 +appVersion: "2.15.1" dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 7a26c4fc5..a87c2e704 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.15.0" + tag: "2.15.1" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index f221922fa..358a30a38 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.15.0" #improve + tag: "2.15.1" #improve pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index a3b20f5a9..b5bc3322d 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.15.0" #improve + tag: "2.15.1" #improve pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi.json b/openapi/openapi.json index 0e9234432..b5a2065b7 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "description": "Microservice to manage PagoPA Backoffice", "termsOfService": "https://www.pagopa.gov.it/", "title": "SelfCare Backoffice", - "version": "2.15.0" + "version": "2.15.1" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 7ea14219c..8fd672ac1 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 2.5.14 pagopa-selfcare-ms-backoffice - 2.15.0 + 2.15.1 SelfCare Backoffice Microservice to manage PagoPA Backoffice From dac5d9db58604a1d8468d3b2adc8eff2cde4838f Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Tue, 25 Jun 2024 10:31:52 +0000 Subject: [PATCH 2/4] Bump to version 2.15.2 [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi.json | 2 +- pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 8e2cc59c6..ecf2ea5e9 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-selfcare-ms-backoffice description: Microservice that manage api keys for pagopa product from selfcare type: application -version: 0.349.0 -appVersion: "2.15.1" +version: 0.350.0 +appVersion: "2.15.2" dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index a87c2e704..c12616f14 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.15.1" + tag: "2.15.2" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 358a30a38..4486626af 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.15.1" #improve + tag: "2.15.2" #improve pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index b5bc3322d..e9dd4d545 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.15.1" #improve + tag: "2.15.2" #improve pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi.json b/openapi/openapi.json index b5a2065b7..79bccf2b3 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "description": "Microservice to manage PagoPA Backoffice", "termsOfService": "https://www.pagopa.gov.it/", "title": "SelfCare Backoffice", - "version": "2.15.1" + "version": "2.15.2" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 8fd672ac1..24361007b 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 2.5.14 pagopa-selfcare-ms-backoffice - 2.15.1 + 2.15.2 SelfCare Backoffice Microservice to manage PagoPA Backoffice From 8db578e0306f1e22792f4fce377b202e44ff0e7c Mon Sep 17 00:00:00 2001 From: Jacopo Carlini Date: Tue, 25 Jun 2024 17:03:08 +0200 Subject: [PATCH 3/4] [VAS-1141] Hotfix release (#443) Co-authored-by: pagopa-github-bot --- helm/Chart.yaml | 4 +- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi.json | 2 +- pom.xml | 2 +- .../entity/WrapperEntityStation.java | 37 +++++++ .../entity/WrapperEntityStations.java | 82 ++++++++++++++++ .../backoffice/mapper/StationMapper.java | 7 +- .../backoffice/mapper/StationMapperImpl.java | 10 +- .../connector/channel/WrapperStationList.java | 32 ++++++ .../repository/WrapperStationsRepository.java | 24 +++++ .../backoffice/service/StationService.java | 35 ++----- .../backoffice/service/WrapperService.java | 97 ++++++++++++++----- .../service/StationServiceTest.java | 66 +++++++------ .../service/WrapperServiceTest.java | 15 ++- 16 files changed, 319 insertions(+), 100 deletions(-) create mode 100644 src/main/java/it/pagopa/selfcare/pagopa/backoffice/entity/WrapperEntityStation.java create mode 100644 src/main/java/it/pagopa/selfcare/pagopa/backoffice/entity/WrapperEntityStations.java create mode 100644 src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/connector/channel/WrapperStationList.java create mode 100644 src/main/java/it/pagopa/selfcare/pagopa/backoffice/repository/WrapperStationsRepository.java diff --git a/helm/Chart.yaml b/helm/Chart.yaml index ecf2ea5e9..de8512a50 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-selfcare-ms-backoffice description: Microservice that manage api keys for pagopa product from selfcare type: application -version: 0.350.0 -appVersion: "2.15.2" +version: 0.354.0 +appVersion: "2.15.2-4-hotfix-release" dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index c12616f14..c03d85504 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.15.2" + tag: "2.15.2-4-hotfix-release" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 4486626af..71f49d78a 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.15.2" #improve + tag: "2.15.2-4-hotfix-release" #improve pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index e9dd4d545..b2dfde9e5 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.15.2" #improve + tag: "2.15.2-4-hotfix-release" #improve pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi.json b/openapi/openapi.json index 79bccf2b3..977accc17 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "description": "Microservice to manage PagoPA Backoffice", "termsOfService": "https://www.pagopa.gov.it/", "title": "SelfCare Backoffice", - "version": "2.15.2" + "version": "2.15.2-4-hotfix-release" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 24361007b..f4a94d136 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 2.5.14 pagopa-selfcare-ms-backoffice - 2.15.2 + 2.15.2-4-hotfix-release SelfCare Backoffice Microservice to manage PagoPA Backoffice diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/entity/WrapperEntityStation.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/entity/WrapperEntityStation.java new file mode 100644 index 000000000..a087aea8c --- /dev/null +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/entity/WrapperEntityStation.java @@ -0,0 +1,37 @@ +package it.pagopa.selfcare.pagopa.backoffice.entity; + +import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.StationDetails; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperStatus; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperType; +import lombok.*; + +import java.time.Instant; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class WrapperEntityStation { + + private String id; + private WrapperType type; + private WrapperStatus status; + private StationDetails entity; + + private Instant createdAt; + private Instant modifiedAt; + private String modifiedBy; + private String modifiedByOpt; + + private String note; + + + public WrapperEntityStation(StationDetails entity) { + this.createdAt = Instant.now(); + this.id = entity.getStationCode(); + this.type = WrapperType.STATION; + this.entity = entity; + } + + +} diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/entity/WrapperEntityStations.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/entity/WrapperEntityStations.java new file mode 100644 index 000000000..bbc08f66c --- /dev/null +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/entity/WrapperEntityStations.java @@ -0,0 +1,82 @@ +package it.pagopa.selfcare.pagopa.backoffice.entity; + + +import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperStatus; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperType; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.FieldNameConstants; +import org.springframework.data.annotation.*; +import org.springframework.data.domain.Persistable; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +@Data +@NoArgsConstructor +@EqualsAndHashCode(of = "id") +@Document("wrappers") +@FieldNameConstants(onlyExplicitlyIncluded = true) +public class WrapperEntityStations implements Persistable { + + @Id + private String id; + + private String brokerCode; + @FieldNameConstants.Include + private WrapperType type; + + @FieldNameConstants.Include + private WrapperStatus status; + + @LastModifiedDate + @FieldNameConstants.Include + private Instant modifiedAt; + @LastModifiedBy + @FieldNameConstants.Include + private String modifiedBy; + + @FieldNameConstants.Include + private String modifiedByOpt; + @CreatedDate + private Instant createdAt; + @CreatedBy + private String createdBy; + + private String note; + + private List entities; + + + public WrapperEntityStations(WrapperEntityStation wrapperEntity) { + this.createdAt = Instant.now(); + this.id = wrapperEntity.getEntity().getStationCode(); + this.type = WrapperType.STATION; + this.brokerCode = wrapperEntity.getEntity().getBrokerCode(); + this.status = wrapperEntity.getStatus(); + if(entities == null) { + entities = new ArrayList<>(); + } + entities.add(wrapperEntity); + } + + @Override + public boolean isNew() { + return false; + } + + + public void sortEntitiesById() { + this.entities.sort(Comparator.comparing(WrapperEntityStation::getId, Comparator.naturalOrder())); + } + + + public static class Fields { + public static String id = org.springframework.data.mongodb.core.aggregation.Fields.UNDERSCORE_ID; + } + +} diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/mapper/StationMapper.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/mapper/StationMapper.java index 24c229780..ac7643423 100644 --- a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/mapper/StationMapper.java +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/mapper/StationMapper.java @@ -1,7 +1,8 @@ package it.pagopa.selfcare.pagopa.backoffice.mapper; -import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntityOperations; +import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntityStation; import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.WrapperEntitiesList; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.WrapperStationList; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.Station; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.StationDetails; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.StationDetailsList; @@ -45,9 +46,9 @@ public interface StationMapper { WrapperStations toWrapperStations(Stations station); - WrapperStations toWrapperStations(WrapperEntitiesList wrapperEntitiesList); + WrapperStations toWrapperStations(WrapperStationList wrapperEntitiesList); - WrapperStation toWrapperStation(WrapperEntityOperations wrapperEntitiesList); + WrapperStation toWrapperStation(WrapperEntityStation wrapperEntityOperations); WrapperStationsResource toWrapperStationsResource(WrapperStations wrapperStations); diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/mapper/StationMapperImpl.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/mapper/StationMapperImpl.java index 45233ff79..00cd559eb 100644 --- a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/mapper/StationMapperImpl.java +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/mapper/StationMapperImpl.java @@ -1,8 +1,9 @@ package it.pagopa.selfcare.pagopa.backoffice.mapper; -import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntityOperations; +import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntityStation; import it.pagopa.selfcare.pagopa.backoffice.model.connector.broker.BrokerDetails; import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.WrapperEntitiesList; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.WrapperStationList; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.Station; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.StationDetails; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.StationDetailsList; @@ -17,6 +18,7 @@ import java.util.ArrayList; import java.util.List; +import static it.pagopa.selfcare.pagopa.backoffice.service.WrapperService.getStationWrapperEntityOperationsSortedList; import static it.pagopa.selfcare.pagopa.backoffice.service.WrapperService.getWrapperEntityOperationsSortedList; @@ -283,7 +285,7 @@ public WrapperStations toWrapperStations(Stations model) { } @Override - public WrapperStations toWrapperStations(WrapperEntitiesList wrapperEntitiesList) { + public WrapperStations toWrapperStations(WrapperStationList wrapperEntitiesList) { if(wrapperEntitiesList == null) { return null; } @@ -293,7 +295,7 @@ public WrapperStations toWrapperStations(WrapperEntitiesList wrapperEntitiesList wrapperEntitiesList.getWrapperEntities().forEach( ent -> { - WrapperStation wrapperStation = toWrapperStation((WrapperEntityOperations) getWrapperEntityOperationsSortedList(ent).get(0)); + WrapperStation wrapperStation = toWrapperStation(getStationWrapperEntityOperationsSortedList(ent).get(0)); wrapperStation.setCreatedAt(ent.getCreatedAt()); stationList.add(wrapperStation); }); @@ -305,7 +307,7 @@ public WrapperStations toWrapperStations(WrapperEntitiesList wrapperEntitiesList } @Override - public WrapperStation toWrapperStation(WrapperEntityOperations wrapperEntityOperations) { + public WrapperStation toWrapperStation(WrapperEntityStation wrapperEntityOperations) { if(wrapperEntityOperations == null) { return null; } diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/connector/channel/WrapperStationList.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/connector/channel/WrapperStationList.java new file mode 100644 index 000000000..f1395d723 --- /dev/null +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/connector/channel/WrapperStationList.java @@ -0,0 +1,32 @@ +package it.pagopa.selfcare.pagopa.backoffice.model.connector.channel; + +import com.fasterxml.jackson.annotation.JsonProperty; +import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntityStations; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.PageInfo; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotNull; +import java.util.List; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WrapperStationList { + + @JsonProperty("wrapper_entities") + @NotNull + private List wrapperEntities; + + @JsonProperty("page_info") + @NotNull + private PageInfo pageInfo; +} + + + + + diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/repository/WrapperStationsRepository.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/repository/WrapperStationsRepository.java new file mode 100644 index 000000000..ce954bce3 --- /dev/null +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/repository/WrapperStationsRepository.java @@ -0,0 +1,24 @@ +package it.pagopa.selfcare.pagopa.backoffice.repository; + +import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntityStations; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperStatus; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperType; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.mongodb.repository.MongoRepository; + +public interface WrapperStationsRepository extends MongoRepository { + + Page findByIdLikeAndTypeAndBrokerCodeAndStatusNot(String id, WrapperType wrapperType, String brokerCode, WrapperStatus status, Pageable pageable); + + Page findByTypeAndBrokerCodeAndStatusNot(WrapperType wrapperType, String brokerCode, WrapperStatus status, Pageable pageable); + + Page findByType(WrapperType wrapperType, Pageable pageable); + + Page findByIdLikeAndType(String idLike, WrapperType wrapperType, Pageable pageable); + + Page findByTypeAndBrokerCode(WrapperType wrapperType, String brokerCode, Pageable pageable); + + Page findByIdLikeAndTypeAndBrokerCode(String id, WrapperType wrapperType, String brokerCode, Pageable pageable); + +} diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/StationService.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/StationService.java index 634e28868..1a9a3b80b 100644 --- a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/StationService.java +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/StationService.java @@ -12,26 +12,16 @@ import it.pagopa.selfcare.pagopa.backoffice.mapper.StationMapper; import it.pagopa.selfcare.pagopa.backoffice.model.connector.PageInfo; import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.WrapperEntitiesList; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.WrapperStationList; import it.pagopa.selfcare.pagopa.backoffice.model.connector.creditorinstitution.CreditorInstitutions; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.Station; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.StationDetails; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.Stations; -import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.ConfigurationStatus; -import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperStation; -import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperStations; -import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperStatus; -import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperType; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.*; import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionsResource; import it.pagopa.selfcare.pagopa.backoffice.model.email.EmailMessageDetail; import it.pagopa.selfcare.pagopa.backoffice.model.institutions.SelfcareProductUser; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.StationCodeResource; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.StationDetailResource; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.StationDetailsDto; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.StationTestDto; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.TestResultEnum; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.TestStationResource; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.WrapperStationDetailsDto; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.WrapperStationsResource; +import it.pagopa.selfcare.pagopa.backoffice.model.stations.*; import org.mapstruct.factory.Mappers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -40,16 +30,10 @@ import javax.validation.Valid; import javax.validation.constraints.NotNull; import java.time.Instant; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; +import static it.pagopa.selfcare.pagopa.backoffice.service.WrapperService.getStationWrapperEntityOperationsSortedList; import static it.pagopa.selfcare.pagopa.backoffice.service.WrapperService.getWrapperEntityOperationsSortedList; import static it.pagopa.selfcare.pagopa.backoffice.util.Constants.REGEX_GENERATE; import static it.pagopa.selfcare.pagopa.backoffice.util.StringUtils.generator; @@ -150,7 +134,7 @@ public WrapperStationsResource getStations( Stations stations = this.apiConfigClient.getStations(limit, page, "DESC", brokerCode, null, stationCode); response = buildEnrichedWrapperStations(stations); } else { - WrapperEntitiesList wrapperStations = this.wrapperService.getWrapperStations(stationCode, brokerCode, page, limit); + WrapperStationList wrapperStations = this.wrapperService.getWrapperStationsList(stationCode, brokerCode, page, limit); response = this.stationMapper.toWrapperStations(wrapperStations); } return this.stationMapper.toWrapperStationsResource(response); @@ -171,16 +155,15 @@ public StationDetailResource getStationDetail(String stationCode) { String modifiedBy = ""; String note = ""; try { - WrapperEntities result = wrapperService.findById(stationCode); + var result = wrapperService.findStationById(stationCode); createdBy = result.getCreatedBy(); createdAt = result.getCreatedAt(); modifiedBy = result.getModifiedBy(); status = result.getStatus(); - WrapperEntityOperations wrapperEntity = getWrapperEntityOperationsSortedList(result).get(0); + var wrapperEntity = getStationWrapperEntityOperationsSortedList(result).get(0); stationDetails = wrapperEntity.getEntity(); note = wrapperEntity.getNote(); } catch (AppException e) { - stationDetails = apiConfigClient.getStation(stationCode); status = WrapperStatus.APPROVED; } @@ -290,7 +273,7 @@ public WrapperStationsResource getAllStationsMerged(Integer limit, String statio Stations stations = getStations(limit, page, sorting, brokerCode, null, stationCode); WrapperStations responseApiConfig = stationMapper.toWrapperStations(stations); - WrapperEntitiesList mongoList = wrapperService.findByIdLikeOrTypeOrBrokerCode(stationCode, WrapperType.STATION, brokerCode, page, limit); + var mongoList = wrapperService.findStationByIdLikeOrTypeOrBrokerCode(stationCode, WrapperType.STATION, brokerCode, page, limit); WrapperStations responseMongo = stationMapper.toWrapperStations(mongoList); diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperService.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperService.java index 05babb4b5..4e47afa4a 100644 --- a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperService.java +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperService.java @@ -1,38 +1,25 @@ package it.pagopa.selfcare.pagopa.backoffice.service; import it.pagopa.selfcare.pagopa.backoffice.client.ApiConfigClient; -import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntities; -import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntity; -import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntityOperations; +import it.pagopa.selfcare.pagopa.backoffice.entity.*; import it.pagopa.selfcare.pagopa.backoffice.exception.AppError; import it.pagopa.selfcare.pagopa.backoffice.exception.AppException; import it.pagopa.selfcare.pagopa.backoffice.model.connector.PageInfo; -import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.Channel; -import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.ChannelDetails; -import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.Channels; -import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.WrapperEntitiesList; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.*; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.Station; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.StationDetails; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.Stations; import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperStatus; import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperType; import it.pagopa.selfcare.pagopa.backoffice.repository.WrapperRepository; +import it.pagopa.selfcare.pagopa.backoffice.repository.WrapperStationsRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DuplicateKeyException; -import org.springframework.data.domain.AuditorAware; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; +import org.springframework.data.domain.*; import org.springframework.stereotype.Service; import java.time.Instant; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static it.pagopa.selfcare.pagopa.backoffice.util.Constants.REGEX_GENERATE; @@ -45,12 +32,15 @@ public class WrapperService { private final WrapperRepository repository; + private final WrapperStationsRepository wrapperStationsRepository; + private final AuditorAware auditorAware; @Autowired - public WrapperService(ApiConfigClient apiConfigClient, WrapperRepository repository, AuditorAware auditorAware) { + public WrapperService(ApiConfigClient apiConfigClient, WrapperRepository repository, WrapperStationsRepository wrapperStationsRepository, AuditorAware auditorAware) { this.apiConfigClient = apiConfigClient; this.repository = repository; + this.wrapperStationsRepository = wrapperStationsRepository; this.auditorAware = auditorAware; } @@ -59,6 +49,12 @@ public static List getWrapperEntityOperationsSortedList list.sort(Comparator.comparing(WrapperEntityOperations::getCreatedAt, Comparator.reverseOrder())); return list; + } + public static List getStationWrapperEntityOperationsSortedList(WrapperEntityStations wrapperEntities) { + List list = wrapperEntities.getEntities(); + list.sort(Comparator.comparing(WrapperEntityStation::getCreatedAt, Comparator.reverseOrder())); + return list; + } public static void updateCurrentWrapperEntity(WrapperEntities wrapperEntities, WrapperEntityOperations wrapperEntity, String status, String note, String modifiedByOpt) { @@ -274,6 +270,13 @@ public WrapperEntities findById(String id) { return response; } + public WrapperEntityStations findStationById(String id) { + var response = wrapperStationsRepository.findById(id) + .orElseThrow(() -> new AppException(AppError.WRAPPER_NOT_FOUND, id)); + response.sortEntitiesById(); + return response; + } + public Optional findByIdOptional(String id) { return repository.findById(id); } @@ -304,6 +307,32 @@ public WrapperEntitiesList findByIdLikeOrTypeOrBrokerCode(String idLike, Wrapper .build(); } + public WrapperStationList findStationByIdLikeOrTypeOrBrokerCode(String idLike, WrapperType wrapperType, String brokerCode, Integer page, Integer size) { + Pageable paging = PageRequest.of(page, size); + Page response; + + if (brokerCode == null && idLike == null) { + response = wrapperStationsRepository.findByType(wrapperType, paging); + } else if (brokerCode == null) { + response = wrapperStationsRepository.findByIdLikeAndType(idLike, wrapperType, paging); + } else if (idLike == null) { + response = wrapperStationsRepository.findByTypeAndBrokerCode(wrapperType, brokerCode, paging); + } else { + response = wrapperStationsRepository.findByIdLikeAndTypeAndBrokerCode(idLike, wrapperType, brokerCode, paging); + } + + return WrapperStationList.builder() + .wrapperEntities(response.getContent()) + .pageInfo(PageInfo.builder() + .page(page) + .limit(size) + .totalItems(response.getTotalElements()) + .totalPages(response.getTotalPages()) + .itemsFound(response.getNumberOfElements()) + .build()) + .build(); + } + /** * Retrieve a paginated list of wrapper station filtered by broker's code and optionally by station's code * @@ -337,12 +366,36 @@ public WrapperEntitiesList getWrapperStations(String stationCode, String brokerC .build(); } + public WrapperStationList getWrapperStationsList(String stationCode, String brokerCode, Integer page, Integer size) { + Pageable paging = PageRequest.of(page, size, Sort.by("id").descending()); + + Page response; + if (stationCode == null) { + response = this.wrapperStationsRepository + .findByTypeAndBrokerCodeAndStatusNot(WrapperType.STATION, brokerCode, WrapperStatus.APPROVED, paging); + } else { + response = this.wrapperStationsRepository + .findByIdLikeAndTypeAndBrokerCodeAndStatusNot(stationCode, WrapperType.STATION, brokerCode, WrapperStatus.APPROVED, paging); + } + + return WrapperStationList.builder() + .wrapperEntities(response.getContent()) + .pageInfo(PageInfo.builder() + .page(page) + .limit(size) + .totalItems(response.getTotalElements()) + .totalPages(response.getTotalPages()) + .itemsFound(response.getNumberOfElements()) + .build()) + .build(); + } + public String getFirstValidStationCodeV2(String taxCode) { Stations stations = apiConfigClient.getStations(100, 0, "DESC", null, null, taxCode); - WrapperEntitiesList stationMongoList = findByIdLikeOrTypeOrBrokerCode(taxCode, WrapperType.STATION, null, 0, 100); + var stationMongoList = findStationByIdLikeOrTypeOrBrokerCode(taxCode, WrapperType.STATION, null, 0, 100); List stationCodes = new LinkedList<>(); - stationCodes.addAll(stationMongoList.getWrapperEntities().stream().map(WrapperEntities::getId).toList()); + stationCodes.addAll(stationMongoList.getWrapperEntities().stream().map(WrapperEntityStations::getId).toList()); stationCodes.addAll(stations.getStationsList().stream().map(Station::getStationCode).toList()); Set validCodes = stationCodes.stream() @@ -353,7 +406,7 @@ public String getFirstValidStationCodeV2(String taxCode) { public String getFirstValidChannelCodeV2(String taxCode) { Channels channels = apiConfigClient.getChannels(100, 0, null, taxCode, "DESC"); - WrapperEntitiesList channelMongoList = findByIdLikeOrTypeOrBrokerCode(null, WrapperType.CHANNEL, taxCode, 0, 100); + var channelMongoList = findByIdLikeOrTypeOrBrokerCode(null, WrapperType.CHANNEL, taxCode, 0, 100); List channelCodes = new LinkedList<>(); channelCodes.addAll(channelMongoList.getWrapperEntities().stream().map(WrapperEntities::getId).toList()); diff --git a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/StationServiceTest.java b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/StationServiceTest.java index 086157356..7e31295a5 100644 --- a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/StationServiceTest.java +++ b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/StationServiceTest.java @@ -4,12 +4,11 @@ import it.pagopa.selfcare.pagopa.backoffice.client.AwsSesClient; import it.pagopa.selfcare.pagopa.backoffice.client.ForwarderClient; import it.pagopa.selfcare.pagopa.backoffice.client.JiraServiceManagerClient; -import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntities; -import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntity; -import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntityOperations; +import it.pagopa.selfcare.pagopa.backoffice.entity.*; import it.pagopa.selfcare.pagopa.backoffice.exception.AppException; import it.pagopa.selfcare.pagopa.backoffice.model.connector.PageInfo; import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.WrapperEntitiesList; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.WrapperStationList; import it.pagopa.selfcare.pagopa.backoffice.model.connector.creditorinstitution.CreditorInstitution; import it.pagopa.selfcare.pagopa.backoffice.model.connector.creditorinstitution.CreditorInstitutions; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.Station; @@ -20,14 +19,7 @@ import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperType; import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionResource; import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionsResource; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.StationCodeResource; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.StationDetailResource; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.StationDetailsDto; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.StationTestDto; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.TestResultEnum; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.TestStationResource; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.WrapperStationDetailsDto; -import it.pagopa.selfcare.pagopa.backoffice.model.stations.WrapperStationsResource; +import it.pagopa.selfcare.pagopa.backoffice.model.stations.*; import kong.unirest.HttpResponse; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; @@ -42,17 +34,9 @@ import java.util.Collections; import java.util.Optional; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @SpringBootTest(classes = {StationService.class}) class StationServiceTest { @@ -158,9 +142,9 @@ void getStationsActiveSuccessWithWrapperNotFound() { @Test void getStationsToBeValidatedSuccess() { - WrapperEntitiesList wrapperEntitiesList = buildWrapperEntitiesList(); + var wrapperEntitiesList = buildWrapperStationList(); - when(wrapperService.getWrapperStations(STATION_CODE, BROKER_CODE, PAGE, LIMIT)) + when(wrapperService.getWrapperStationsList(STATION_CODE, BROKER_CODE, PAGE, LIMIT)) .thenReturn(wrapperEntitiesList); WrapperStationsResource result = @@ -190,8 +174,8 @@ void getStationSuccess() { @Test void getStationDetailInWrapperSuccess() { - WrapperEntities entities = buildStationDetailsWrapperEntities(); - when(wrapperService.findById(STATION_CODE)).thenReturn((WrapperEntities) entities); + WrapperEntityStations entities = buildWrapperEntityStation(); + when(wrapperService.findStationById(STATION_CODE)).thenReturn(entities); StationDetailResource result = assertDoesNotThrow(() -> service.getStationDetail(STATION_CODE)); @@ -206,7 +190,7 @@ void getStationDetailInWrapperSuccess() { @Test void getStationDetailInApiConfigSuccess() { - when(wrapperService.findById(STATION_CODE)).thenThrow(AppException.class); + when(wrapperService.findStationById(STATION_CODE)).thenThrow(AppException.class); when(apiConfigClient.getStation(STATION_CODE)).thenReturn(buildStationDetails()); StationDetailResource result = assertDoesNotThrow(() -> service.getStationDetail(STATION_CODE)); @@ -388,8 +372,8 @@ void getWrapperEntitiesStationSuccess() { void getAllStationsMergedSuccess() { when(apiConfigClient.getStations(LIMIT, PAGE, SORTING_DESC, BROKER_CODE, null, STATION_CODE)) .thenReturn(buildStations("station")); - when(wrapperService.findByIdLikeOrTypeOrBrokerCode(STATION_CODE, WrapperType.STATION, BROKER_CODE, PAGE, LIMIT)) - .thenReturn(buildWrapperEntitiesList()); + when(wrapperService.findStationByIdLikeOrTypeOrBrokerCode(STATION_CODE, WrapperType.STATION, BROKER_CODE, PAGE, LIMIT)) + .thenReturn(buildWrapperStationList()); WrapperStationsResource result = assertDoesNotThrow(() -> service.getAllStationsMerged(LIMIT, STATION_CODE, BROKER_CODE, PAGE, SORTING_DESC) @@ -407,8 +391,8 @@ void getAllStationsMergedSuccess() { void getAllStationsMergedApiConfigNotFoundSuccess() { when(apiConfigClient.getStations(LIMIT, PAGE, SORTING_ASC, BROKER_CODE, null, STATION_CODE)) .thenThrow(new RuntimeException("[404 Not Found]")); - when(wrapperService.findByIdLikeOrTypeOrBrokerCode(STATION_CODE, WrapperType.STATION, BROKER_CODE, PAGE, LIMIT)) - .thenReturn(buildWrapperEntitiesList()); + when(wrapperService.findStationByIdLikeOrTypeOrBrokerCode(STATION_CODE, WrapperType.STATION, BROKER_CODE, PAGE, LIMIT)) + .thenReturn(buildWrapperStationList()); WrapperStationsResource result = assertDoesNotThrow(() -> service.getAllStationsMerged(LIMIT, STATION_CODE, BROKER_CODE, PAGE, SORTING_ASC) @@ -500,6 +484,19 @@ void testStationShouldReturnErrorOnNotFoundForwardCall(int httResponseStatus) { .build()); return wrapperEntitiesList; } + private @NotNull WrapperStationList buildWrapperStationList() { + var entities = buildWrapperEntityStation(); + WrapperStationList wrapperEntitiesList = new WrapperStationList(); + wrapperEntitiesList.setWrapperEntities(Collections.singletonList(entities)); + wrapperEntitiesList.setPageInfo(PageInfo.builder() + .itemsFound(1) + .totalPages(1) + .limit(LIMIT) + .page(PAGE) + .totalItems(1L) + .build()); + return wrapperEntitiesList; + } private @NotNull WrapperEntities buildStationDetailsWrapperEntities() { WrapperEntity entity = new WrapperEntity<>(); @@ -510,6 +507,15 @@ void testStationShouldReturnErrorOnNotFoundForwardCall(int httResponseStatus) { return entities; } + private @NotNull WrapperEntityStations buildWrapperEntityStation() { + WrapperEntityStation entity = new WrapperEntityStation(); + entity.setEntity(buildStationDetails()); + WrapperEntityStations entities = new WrapperEntityStations(); + entities.setCreatedAt(Instant.now()); + entities.setEntities(Collections.singletonList(entity)); + return entities; + } + private @NotNull StationDetails buildStationDetails() { StationDetails stationDetails = new StationDetails(); stationDetails.setStationCode(STATION_CODE); diff --git a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperServiceTest.java b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperServiceTest.java index a79384333..58cf52fe2 100644 --- a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperServiceTest.java +++ b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperServiceTest.java @@ -11,6 +11,7 @@ import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperStatus; import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperType; import it.pagopa.selfcare.pagopa.backoffice.repository.WrapperRepository; +import it.pagopa.selfcare.pagopa.backoffice.repository.WrapperStationsRepository; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -23,15 +24,10 @@ import java.util.Collections; import java.util.Optional; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @SpringBootTest(classes = WrapperService.class) class WrapperServiceTest { @@ -47,6 +43,9 @@ class WrapperServiceTest { @MockBean private WrapperRepository repository; + @MockBean + private WrapperStationsRepository wrapperStationsRepository; + @MockBean private AuditorAware auditorAware; @@ -166,4 +165,4 @@ void updateStationWithOperatorReviewSuccessFailNotFound() { stationDetails.setVersion(1L); return stationDetails; } -} \ No newline at end of file +} From 95df69d471df20639521aa0f78c2835688e92030 Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 26 Jun 2024 10:54:00 +0200 Subject: [PATCH 4/4] removed unused method --- .../backoffice/service/StationService.java | 2 +- .../backoffice/service/WrapperService.java | 58 +++++++------------ .../service/StationServiceTest.java | 2 +- .../service/WrapperServiceTest.java | 24 ++++++-- 4 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/StationService.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/StationService.java index 38e3fd54e..14493bef7 100644 --- a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/StationService.java +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/StationService.java @@ -133,7 +133,7 @@ public WrapperStationsResource getStations( Stations stations = this.apiConfigClient.getStations(limit, page, "DESC", brokerCode, null, stationCode); response = buildEnrichedWrapperStations(stations); } else { - WrapperStationList wrapperStations = this.wrapperService.getWrapperStationsList(stationCode, brokerCode, page, limit); + WrapperStationList wrapperStations = this.wrapperService.getWrapperStations(stationCode, brokerCode, limit, page); response = this.stationMapper.toWrapperStations(wrapperStations); } return this.stationMapper.toWrapperStationsResource(response); diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperService.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperService.java index 8db3a9673..e47dbb408 100644 --- a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperService.java +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperService.java @@ -417,7 +417,27 @@ public WrapperStationList findStationByIdLikeOrTypeOrBrokerCode(String idLike, W * @return the paginated list */ public WrapperEntitiesList getWrapperChannels(String channelCode, String brokerCode, Integer size, Integer page) { - return getWrapperEntities(WrapperType.CHANNEL, channelCode, brokerCode, size, page); + Pageable paging = PageRequest.of(page, size, Sort.by("id").descending()); + + Page> response; + if (channelCode == null) { + response = this.repository + .findByTypeAndBrokerCodeAndStatusNot(WrapperType.CHANNEL, brokerCode, WrapperStatus.APPROVED, paging); + } else { + response = this.repository + .findByIdLikeAndTypeAndBrokerCodeAndStatusNot(channelCode, WrapperType.CHANNEL, brokerCode, WrapperStatus.APPROVED, paging); + } + + return WrapperEntitiesList.builder() + .wrapperEntities(response.getContent()) + .pageInfo(PageInfo.builder() + .page(page) + .limit(size) + .totalItems(response.getTotalElements()) + .totalPages(response.getTotalPages()) + .itemsFound(response.getNumberOfElements()) + .build()) + .build(); } /** @@ -429,11 +449,7 @@ public WrapperEntitiesList getWrapperChannels(String channelCode, String brokerC * @param page page number * @return the paginated list */ - public WrapperEntitiesList getWrapperStations(String stationCode, String brokerCode, Integer size, Integer page) { - return getWrapperEntities(WrapperType.STATION, stationCode, brokerCode, size, page); - } - - public WrapperStationList getWrapperStationsList(String stationCode, String brokerCode, Integer page, Integer size) { + public WrapperStationList getWrapperStations(String stationCode, String brokerCode, Integer size, Integer page) { Pageable paging = PageRequest.of(page, size, Sort.by("id").descending()); Page response; @@ -573,34 +589,4 @@ private WrapperStatus getNewWrapperStatusForUpdate(String stationCode, WrapperSt } return newWrapperStatus; } - - private WrapperEntitiesList getWrapperEntities( - WrapperType wrapperType, - String code, - String brokerCode, - Integer size, - Integer page - ) { - Pageable paging = PageRequest.of(page, size, Sort.by("id").descending()); - - Page> response; - if (code == null) { - response = this.repository - .findByTypeAndBrokerCodeAndStatusNot(wrapperType, brokerCode, WrapperStatus.APPROVED, paging); - } else { - response = this.repository - .findByIdLikeAndTypeAndBrokerCodeAndStatusNot(code, wrapperType, brokerCode, WrapperStatus.APPROVED, paging); - } - - return WrapperEntitiesList.builder() - .wrapperEntities(response.getContent()) - .pageInfo(PageInfo.builder() - .page(page) - .limit(size) - .totalItems(response.getTotalElements()) - .totalPages(response.getTotalPages()) - .itemsFound(response.getNumberOfElements()) - .build()) - .build(); - } } diff --git a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/StationServiceTest.java b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/StationServiceTest.java index 9f78fdfb0..a4f902a82 100644 --- a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/StationServiceTest.java +++ b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/StationServiceTest.java @@ -144,7 +144,7 @@ void getStationsActiveSuccessWithWrapperNotFound() { void getStationsToBeValidatedSuccess() { var wrapperEntitiesList = buildWrapperStationList(); - when(wrapperService.getWrapperStationsList(STATION_CODE, BROKER_CODE, LIMIT, PAGE)) + when(wrapperService.getWrapperStations(STATION_CODE, BROKER_CODE, LIMIT, PAGE)) .thenReturn(wrapperEntitiesList); WrapperStationsResource result = diff --git a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperServiceTest.java b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperServiceTest.java index 7e18e7afd..d412b8d3a 100644 --- a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperServiceTest.java +++ b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/WrapperServiceTest.java @@ -3,6 +3,8 @@ import it.pagopa.selfcare.pagopa.backoffice.client.ApiConfigClient; import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntities; import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntity; +import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntityStation; +import it.pagopa.selfcare.pagopa.backoffice.entity.WrapperEntityStations; import it.pagopa.selfcare.pagopa.backoffice.exception.AppError; import it.pagopa.selfcare.pagopa.backoffice.exception.AppException; import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.Channel; @@ -10,6 +12,7 @@ import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.Channels; import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.Protocol; import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.WrapperEntitiesList; +import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.WrapperStationList; import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.StationDetails; import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperStatus; import it.pagopa.selfcare.pagopa.backoffice.model.connector.wrapper.WrapperType; @@ -85,15 +88,15 @@ void getFirstValidChannelCodeV2() { @Test void getWrapperStationsWithStationCodeSuccess() { - when(repository.findByIdLikeAndTypeAndBrokerCodeAndStatusNot( + when(wrapperStationsRepository.findByIdLikeAndTypeAndBrokerCodeAndStatusNot( eq(STATION_CODE), eq(WrapperType.STATION), eq(BROKER_CODE), eq(WrapperStatus.APPROVED), any()) - ).thenReturn(new PageImpl<>(Collections.singletonList(buildStationDetailsWrapperEntities()))); + ).thenReturn(new PageImpl<>(Collections.singletonList(buildWrapperEntityStations()))); - WrapperEntitiesList result = assertDoesNotThrow(() -> + WrapperStationList result = assertDoesNotThrow(() -> sut.getWrapperStations(STATION_CODE, BROKER_CODE, LIMIT, PAGE)); assertNotNull(result); @@ -113,14 +116,14 @@ void getWrapperStationsWithStationCodeSuccess() { @Test void getWrapperStationsWithoutStationCodeSuccess() { - when(repository.findByTypeAndBrokerCodeAndStatusNot( + when(wrapperStationsRepository.findByTypeAndBrokerCodeAndStatusNot( eq(WrapperType.STATION), eq(BROKER_CODE), eq(WrapperStatus.APPROVED), any()) - ).thenReturn(new PageImpl<>(Collections.singletonList(buildStationDetailsWrapperEntities()))); + ).thenReturn(new PageImpl<>(Collections.singletonList(buildWrapperEntityStations()))); - WrapperEntitiesList result = assertDoesNotThrow(() -> + WrapperStationList result = assertDoesNotThrow(() -> sut.getWrapperStations(null, BROKER_CODE, LIMIT, PAGE)); assertNotNull(result); @@ -367,6 +370,15 @@ void updateChannelWithOperatorReviewFailNotFound() { verify(repository, never()).save(any()); } + private WrapperEntityStations buildWrapperEntityStations() { + WrapperEntityStation entity = new WrapperEntityStation(); + entity.setEntity(buildStationDetails()); + entity.setStatus(WrapperStatus.TO_CHECK); + WrapperEntityStations entities = new WrapperEntityStations(); + entities.setEntities(Collections.singletonList(entity)); + return entities; + } + private WrapperEntities buildStationDetailsWrapperEntities() { WrapperEntity entity = new WrapperEntity<>(); entity.setEntity(buildStationDetails());