Skip to content

Commit

Permalink
Update next with wrapper hotfix (#445)
Browse files Browse the repository at this point in the history
Co-authored-by: pagopa-github-bot <github-bot@pagopa.it>
Co-authored-by: Jacopo Carlini <jacopo.carlini@gmail.com>
  • Loading branch information
3 people authored Jun 26, 2024
1 parent 1b03b1b commit 6b0b08a
Show file tree
Hide file tree
Showing 10 changed files with 345 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}


}
Original file line number Diff line number Diff line change
@@ -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<String> {

@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<WrapperEntityStation> 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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -45,9 +46,9 @@ public interface StationMapper {

WrapperStations toWrapperStations(Stations station);

WrapperStations toWrapperStations(WrapperEntitiesList wrapperEntitiesList);
WrapperStations toWrapperStations(WrapperStationList wrapperEntitiesList);

WrapperStation toWrapperStation(WrapperEntityOperations<StationDetails> wrapperEntitiesList);
WrapperStation toWrapperStation(WrapperEntityStation wrapperEntityOperations);

WrapperStationsResource toWrapperStationsResource(WrapperStations wrapperStations);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;


Expand Down Expand Up @@ -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;
}
Expand All @@ -293,7 +295,7 @@ public WrapperStations toWrapperStations(WrapperEntitiesList wrapperEntitiesList

wrapperEntitiesList.getWrapperEntities().forEach(
ent -> {
WrapperStation wrapperStation = toWrapperStation((WrapperEntityOperations<StationDetails>) getWrapperEntityOperationsSortedList(ent).get(0));
WrapperStation wrapperStation = toWrapperStation(getStationWrapperEntityOperationsSortedList(ent).get(0));
wrapperStation.setCreatedAt(ent.getCreatedAt());
stationList.add(wrapperStation);
});
Expand All @@ -305,7 +307,7 @@ public WrapperStations toWrapperStations(WrapperEntitiesList wrapperEntitiesList
}

@Override
public WrapperStation toWrapperStation(WrapperEntityOperations<StationDetails> wrapperEntityOperations) {
public WrapperStation toWrapperStation(WrapperEntityStation wrapperEntityOperations) {
if(wrapperEntityOperations == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<WrapperEntityStations> wrapperEntities;

@JsonProperty("page_info")
@NotNull
private PageInfo pageInfo;
}





Original file line number Diff line number Diff line change
@@ -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<WrapperEntityStations, String> {

Page<WrapperEntityStations> findByIdLikeAndTypeAndBrokerCodeAndStatusNot(String id, WrapperType wrapperType, String brokerCode, WrapperStatus status, Pageable pageable);

Page<WrapperEntityStations> findByTypeAndBrokerCodeAndStatusNot(WrapperType wrapperType, String brokerCode, WrapperStatus status, Pageable pageable);

Page<WrapperEntityStations> findByType(WrapperType wrapperType, Pageable pageable);

Page<WrapperEntityStations> findByIdLikeAndType(String idLike, WrapperType wrapperType, Pageable pageable);

Page<WrapperEntityStations> findByTypeAndBrokerCode(WrapperType wrapperType, String brokerCode, Pageable pageable);

Page<WrapperEntityStations> findByIdLikeAndTypeAndBrokerCode(String id, WrapperType wrapperType, String brokerCode, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,16 @@
import it.pagopa.selfcare.pagopa.backoffice.mapper.CreditorInstitutionMapper;
import it.pagopa.selfcare.pagopa.backoffice.mapper.StationMapper;
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;
Expand All @@ -39,13 +29,10 @@
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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;
Expand Down Expand Up @@ -146,7 +133,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, limit, page);
WrapperStationList wrapperStations = this.wrapperService.getWrapperStations(stationCode, brokerCode, limit, page);
response = this.stationMapper.toWrapperStations(wrapperStations);
}
return this.stationMapper.toWrapperStationsResource(response);
Expand All @@ -173,12 +160,12 @@ public StationDetailResource getStationDetail(String stationCode) {
String modifiedBy = "";
String note = "";
try {
WrapperEntities<StationDetails> result = this.wrapperService.findById(stationCode);
var result = this.wrapperService.findStationById(stationCode);
createdBy = result.getCreatedBy();
createdAt = result.getCreatedAt();
modifiedBy = result.getModifiedBy();
status = result.getStatus();
WrapperEntityOperations<StationDetails> wrapperEntity = getWrapperEntityOperationsSortedList(result).get(0);
var wrapperEntity = getStationWrapperEntityOperationsSortedList(result).get(0);
stationDetails = wrapperEntity.getEntity();
note = wrapperEntity.getNote();
} catch (AppException e) {
Expand Down
Loading

0 comments on commit 6b0b08a

Please sign in to comment.