Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix flag async sync #405

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -11369,6 +11369,10 @@
"ip_4mod": {
"type": "string"
},
"is_connection_sync": {
"type": "boolean",
"readOnly": true
},
"new_password": {
"type": "string"
},
Expand Down Expand Up @@ -13166,4 +13170,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public StationDetailResource toResource(StationDetails model) {
stationDetailResource.setTargetPortPof(model.getTargetPortPof());
stationDetailResource.setTargetPathPof(model.getTargetPathPof());
stationDetailResource.setPrimitiveVersion(model.getPrimitiveVersion());
stationDetailResource.setIsConnectionSync(model.getIsConnectionSync());

BrokerDetailsResource brokerDetailsResource = new BrokerDetailsResource();
BrokerDetails brokerDetails = model.getIntermediarioPa();
Expand Down Expand Up @@ -145,7 +146,7 @@ public StationDetailResource toResource(StationDetails model, WrapperStatus stat
stationDetailResource.setModifiedBy(modifiedBy);
stationDetailResource.setCreatedAt(createdAt);

stationDetailResource.setIsConnectionSync(Utility.isConnectionSync(model));
stationDetailResource.setIsConnectionSync(model.getIsConnectionSync() != null ? model.getIsConnectionSync() : Utility.isConnectionSync(model));
stationDetailResource.setNote(note);

BrokerDetailsResource brokerDetailsResource = new BrokerDetailsResource();
Expand Down Expand Up @@ -258,6 +259,7 @@ public WrapperStation toWrapperStation(Station model) {
wrapperStation.setVersion(model.getVersion());
wrapperStation.setActivationDate(model.getActivationDate());
wrapperStation.setAssociatedCreditorInstitutions(model.getAssociatedCreditorInstitutions());
wrapperStation.setIsConnectionSync(model.getIsConnectionSync());
//default per gli ogetti di apiconfig poiche non hanno questi campi
wrapperStation.setWrapperStatus(WrapperStatus.APPROVED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.NotBlank;
Expand All @@ -26,6 +27,10 @@ public class Station {
@NotNull
protected Long version;

@JsonProperty("is_connection_sync")
@Schema(accessMode = Schema.AccessMode.READ_ONLY)
private Boolean isConnectionSync;
gioelemella marked this conversation as resolved.
Show resolved Hide resolved

@JsonIgnore
private Integer associatedCreditorInstitutions = 0;
@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class StationDetailResource extends StationResource {
@Schema(description = "Last user that modified the station")
private String modifiedBy;
@Schema(description = "Describe the station connection's type, true synchronous, false asynchronous")
private Boolean isConnectionSync;
private Boolean isConnectionSync = true;
@Schema(description = "Operator review note")
private String note;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ public class WrapperStationResource {
@Schema(description = "Station's target path POF")
private String targetPathPof;
@Schema(description = "Describe the station connection's type, true synchronous, false asynchronous")
private Boolean isConnectionSync;
private Boolean isConnectionSync = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@
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.*;
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.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.*;
import it.pagopa.selfcare.pagopa.backoffice.util.Utility;
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 org.mapstruct.factory.Mappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -30,7 +40,14 @@
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.time.Instant;
import java.util.*;
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.stream.Collectors;

import static it.pagopa.selfcare.pagopa.backoffice.service.WrapperService.getWrapperEntityOperationsSortedList;
Expand Down Expand Up @@ -129,7 +146,7 @@ public WrapperStationsResource getStations(
Integer page
) {
WrapperStations response;
if(status.equals(ConfigurationStatus.ACTIVE)) {
if (status.equals(ConfigurationStatus.ACTIVE)) {
Stations stations = this.apiConfigClient.getStations(limit, page, "DESC", brokerCode, null, stationCode);
response = buildEnrichedWrapperStations(stations);
} else {
Expand Down Expand Up @@ -172,7 +189,7 @@ public StationDetailResource getStationDetail(String stationCode) {
}

public StationCodeResource getStationCode(String ecCode, Boolean v2) {
if(Boolean.TRUE.equals(v2)) {
if (Boolean.TRUE.equals(v2)) {
return new StationCodeResource(wrapperService.getFirstValidStationCodeV2(ecCode));
} else {
return new StationCodeResource(getFirstValidStationCodeAux(ecCode));
Expand Down Expand Up @@ -247,9 +264,9 @@ public TestStationResource testStation(StationTestDto stationTestDto) {
stationTestDto.getHostPath(),
stationTestDto.getTestStationType()
);
if(response.getStatus() == 200) {
if (response.getStatus() == 200) {
return TestStationResource.builder().testResult(TestResultEnum.SUCCESS).message("OK").build();
} else if(response.getStatus() == 401) {
} else if (response.getStatus() == 401) {
return TestStationResource.builder().testResult(TestResultEnum.CERTIFICATE_ERROR)
.message("Connection error due to invalid connection on the station endpoint").build();
} else {
Expand All @@ -273,7 +290,7 @@ private Context buildStationHtmlEmailBodyContext(String stationCode) {
private String getFirstValidStationCodeAux(String ecCode) {
WrapperEntitiesList entitiesList = wrapperService.findByStatusAndTypeAndBrokerCodeAndIdLike(WrapperStatus.TO_CHECK, WrapperType.STATION, null, ecCode, 0, 1, "ASC");
WrapperEntitiesList entitiesList2 = wrapperService.findByStatusAndTypeAndBrokerCodeAndIdLike(WrapperStatus.TO_FIX, WrapperType.STATION, null, ecCode, 0, 1, "ASC");
if(!entitiesList.getWrapperEntities().isEmpty() || !entitiesList2.getWrapperEntities().isEmpty())
if (!entitiesList.getWrapperEntities().isEmpty() || !entitiesList2.getWrapperEntities().isEmpty())
throw new AppException(AppError.STATION_CONFLICT);
return generateStationCode(ecCode);
}
Expand All @@ -283,7 +300,7 @@ private Stations getStations(Integer limit, Integer page, String sort, String br
try {
response = apiConfigClient.getStations(limit, page, sort, brokerCode, ecCode, stationCode);
} catch (Exception e) {
if(e.getMessage().contains("[404 Not Found]")) {
if (e.getMessage().contains("[404 Not Found]")) {
response = new Stations();
response.setStationsList(new ArrayList<>());
PageInfo pageInfo = new PageInfo();
Expand Down Expand Up @@ -319,9 +336,9 @@ private WrapperStations mergeAndSortWrapperStations(WrapperStations wrapperStati
.toList()
);

if("asc".equalsIgnoreCase(sorting)) {
if ("asc".equalsIgnoreCase(sorting)) {
mergedList.sort(Comparator.comparing(WrapperStation::getStationCode));
} else if("desc".equalsIgnoreCase(sorting)) {
} else if ("desc".equalsIgnoreCase(sorting)) {
mergedList.sort(Comparator.comparing(WrapperStation::getStationCode, Comparator.reverseOrder()));
}
WrapperStations result = new WrapperStations();
Expand All @@ -342,11 +359,9 @@ private WrapperStations buildEnrichedWrapperStations(Stations stations) {
.map(station -> {
WrapperStation wrapperStation = this.stationMapper.toWrapperStation(station);
Optional<WrapperEntities> optionalWrapperEntities = this.wrapperService.findByIdOptional(station.getStationCode());
if(optionalWrapperEntities.isPresent()) {
if (optionalWrapperEntities.isPresent()) {
WrapperEntities<StationDetails> wrapperEntities = optionalWrapperEntities.get();
StationDetails stationDetails = (StationDetails) getWrapperEntityOperationsSortedList(wrapperEntities).get(0).getEntity();
wrapperStation.setCreatedAt(wrapperEntities.getCreatedAt());
wrapperStation.setIsConnectionSync(Utility.isConnectionSync(stationDetails));
}
return wrapperStation;
}).toList();
Expand Down
Loading