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

[PPANTT-107] feat: add station creation date #321

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
29,221 changes: 13,892 additions & 15,329 deletions openapi/openapi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<postgresql-version>42.5.5</postgresql-version>
<azure.storage.table.version>8.6.6</azure.storage.table.version>
<testcontainer.version>1.17.6</testcontainer.version>
<starter.version>1.22.2</starter.version>
<starter.version>1.22.3</starter.version>
</properties>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.apiconfig.core.model.ProblemJson;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.StationCreditorInstitution;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.StationCreditorInstitutions;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.StationDetails;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.Stations;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.*;
import it.gov.pagopa.apiconfig.core.model.filterandorder.Order;
import it.gov.pagopa.apiconfig.core.service.StationsService;
import it.gov.pagopa.apiconfig.core.util.CommonUtil;
Expand All @@ -21,6 +18,7 @@
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.data.domain.Sort;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -40,6 +38,7 @@
import javax.validation.constraints.Positive;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;
import java.time.OffsetDateTime;

@RestController()
@RequestMapping(path = "/stations")
Expand Down Expand Up @@ -131,6 +130,12 @@ public ResponseEntity<Stations> getStations(
String creditorInstitutionCode,
@RequestParam(required = false, name = "code") @Parameter(description = "Filter by code")
String filterByCode,
@Parameter(description = "Used to retrieve all stations that where created after the provided date (yyyy-MM-dd'T'HH:mm:ss.SSSXXX)", example = "2024-04-01T10:00:00.000+02:00")
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime createDateAfter,
@Parameter(description = "Used to retrieve all stations that where created before the provided date (yyyy-MM-dd'T'HH:mm:ss.SSSXXX)", example = "2024-04-01T13:00:00.000+02:00")
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime createDateBefore,
@Parameter(description = "Connection type filter (NONE | SYNC| ASYNC)")
@RequestParam(required = false, defaultValue = "NONE") StationConnectionTypeFilter connectionTypeFilter,
@RequestParam(required = false, name = "ordering", defaultValue = "DESC")
@Parameter(description = "Direction of ordering. Results are ordered by code")
Sort.Direction ordering) {
Expand All @@ -141,6 +146,9 @@ public ResponseEntity<Stations> getStations(
brokerCode,
brokerDescription,
creditorInstitutionCode,
createDateAfter,
createDateBefore,
connectionTypeFilter,
CommonUtil.getFilterAndOrder(filterByCode, null, Order.Station.CODE, ordering)));
}

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

import it.gov.pagopa.apiconfig.core.model.creditorinstitution.Protocol;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.StationDetails;
import it.gov.pagopa.apiconfig.core.util.CommonUtil;
import it.gov.pagopa.apiconfig.starter.entity.IntermediariPa;
import it.gov.pagopa.apiconfig.starter.entity.Stazioni;
import javax.validation.Valid;
Expand Down Expand Up @@ -52,6 +53,7 @@ public Stazioni convert(MappingContext<StationDetails, Stazioni> context) {
.rtEnabled(true)
.invioRtIstantaneo(source.getRtInstantaneousDispatch())
.versionePrimitive(source.getPrimitiveVersion())
.dataCreazione(CommonUtil.toTimestamp(source.getCreateDate()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.validation.Valid;

import static it.gov.pagopa.apiconfig.core.util.CommonUtil.isConnectionSync;
import static it.gov.pagopa.apiconfig.core.util.CommonUtil.toOffsetDateTime;

public class ConvertStazioniToStation implements Converter<Stazioni, Station> {

Expand All @@ -20,6 +21,7 @@ public Station convert(MappingContext<Stazioni, Station> context) {
.brokerDescription(source.getIntermediarioPa().getCodiceIntermediario())
.version(source.getVersione())
.isConnectionSync(isConnectionSync(source))
.createDate(toOffsetDateTime(source.getDataCreazione()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.validation.Valid;

import static it.gov.pagopa.apiconfig.core.util.CommonUtil.isConnectionSync;
import static it.gov.pagopa.apiconfig.core.util.CommonUtil.toOffsetDateTime;

public class ConvertStazioniToStationDetails implements Converter<Stazioni, StationDetails> {

Expand Down Expand Up @@ -61,6 +62,7 @@ public StationDetails convert(MappingContext<Stazioni, StationDetails> context)
.rtInstantaneousDispatch(source.getInvioRtIstantaneo())
.primitiveVersion(source.getVersionePrimitive())
.isConnectionSync(isConnectionSync(source))
.createDate(toOffsetDateTime(source.getDataCreazione()))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package it.gov.pagopa.apiconfig.core.model.creditorinstitution;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.OffsetDateTimeSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import it.gov.pagopa.apiconfig.core.util.Constants;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.OffsetDateTime;

/** Station */
@Data
Expand Down Expand Up @@ -51,4 +59,12 @@ public class Station {
@Schema(description = "Describe the station connection's type, true synchronous, false asynchronous")
@JsonProperty("is_connection_sync")
private Boolean isConnectionSync;

@JsonProperty("create_date")
@Schema(description = "Station creation date")
@JsonFormat(pattern = Constants.DateTimeFormat.DATE_TIME_FORMAT)
@JsonSerialize(using = OffsetDateTimeSerializer.class)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private OffsetDateTime createDate;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.gov.pagopa.apiconfig.core.model.creditorinstitution;

public enum StationConnectionTypeFilter {

NONE,
SYNC,
ASYNC

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package it.gov.pagopa.apiconfig.core.model.creditorinstitution;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.OffsetDateTimeSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import it.gov.pagopa.apiconfig.core.util.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.OffsetDateTime;

/** StationDetails */
@EqualsAndHashCode(callSuper = true)
Expand Down Expand Up @@ -163,4 +171,5 @@ public class StationDetails extends Station {
@Schema(required = true, description = "Primitive number version")
@JsonProperty("primitive_version")
private Integer primitiveVersion;

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package it.gov.pagopa.apiconfig.core.service;

import io.swagger.v3.oas.annotations.Parameter;
import it.gov.pagopa.apiconfig.core.exception.AppError;
import it.gov.pagopa.apiconfig.core.exception.AppException;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.Station;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.StationCreditorInstitution;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.StationCreditorInstitutions;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.StationDetails;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.Stations;
import it.gov.pagopa.apiconfig.core.model.creditorinstitution.*;
import it.gov.pagopa.apiconfig.core.model.filterandorder.FilterAndOrder;
import it.gov.pagopa.apiconfig.core.specification.PaStazionePaSpecification;
import it.gov.pagopa.apiconfig.core.util.CommonUtil;
Expand All @@ -24,13 +21,18 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -78,6 +80,9 @@ public Stations getStations(
@Nullable String brokerCode,
@Nullable String brokerDescription,
@Nullable String creditorInstitutionCode,
@Nullable OffsetDateTime createDateAfter,
@Nullable OffsetDateTime createDateBefore,
@Nullable StationConnectionTypeFilter connectionTypeFilter,
@Valid FilterAndOrder filterAndOrder) {
Pageable pageable = PageRequest.of(pageNumber, limit);
// convert code to FK
Expand All @@ -91,7 +96,10 @@ public Stations getStations(
.orElse(null);

Page<Stazioni> page =
queryStazioni(fkIntermediario, fkPa, brokerDescription, filterAndOrder, pageable);
queryStazioni(
fkIntermediario, fkPa, brokerDescription,
createDateAfter, createDateBefore,
connectionTypeFilter, filterAndOrder, pageable);
return Stations.builder()
.stationsList(getStationsList(page))
.pageInfo(CommonUtil.buildPageInfo(page))
Expand All @@ -109,6 +117,7 @@ public StationDetails createStation(@NotNull StationDetails stationDetails) {
}
brokerCodeToObjId(stationDetails);
Stazioni stazioni = modelMapper.map(stationDetails, Stazioni.class);
stazioni.setDataCreazione(Timestamp.from(Instant.now()));
stazioniRepository.save(stazioni);
return stationDetails;
}
Expand Down Expand Up @@ -310,21 +319,30 @@ private Page<Stazioni> queryStazioni(
Long fkIntermediario,
Long fkPa,
String brokerDescription,
OffsetDateTime createDateAfter,
OffsetDateTime createDateBefore,
StationConnectionTypeFilter connectionTypeFilter,
FilterAndOrder filterAndOrder,
Pageable pageable) {
if (StringUtils.isEmpty(brokerDescription)) { // avoiding unnecessary table join
return queryStazioni(fkIntermediario, fkPa, filterAndOrder, pageable);
return queryStazioni(fkIntermediario, fkPa, createDateAfter, createDateBefore, connectionTypeFilter, filterAndOrder, pageable);
} else {
if (fkPa != null) {
return stazioniRepository.findAllByFilters(
fkIntermediario,
fkPa,
filterAndOrder.getFilter().getCode(),
brokerDescription,
createDateBefore,
createDateAfter,
Optional.ofNullable(connectionTypeFilter).orElse(StationConnectionTypeFilter.NONE).name(),
pageable);
} else {
return stazioniRepository.findAllByFilters(
fkIntermediario, filterAndOrder.getFilter().getCode(), brokerDescription, pageable);
fkIntermediario, filterAndOrder.getFilter().getCode(),
brokerDescription, createDateAfter, createDateBefore,
Optional.ofNullable(connectionTypeFilter).orElse(StationConnectionTypeFilter.NONE).name(),
pageable);
}
}
}
Expand All @@ -337,13 +355,23 @@ private Page<Stazioni> queryStazioni(
* @return the result page of the query
*/
private Page<Stazioni> queryStazioni(
Long fkIntermediario, Long fkPa, FilterAndOrder filterAndOrder, Pageable pageable) {
Long fkIntermediario,
Long fkPa,
OffsetDateTime createDateAfter,
OffsetDateTime createDateBefore,
StationConnectionTypeFilter connectionTypeFilter,
FilterAndOrder filterAndOrder,
Pageable pageable) {
if (fkPa != null) {
return stazioniRepository.findAllByFilters(
fkIntermediario, fkPa, filterAndOrder.getFilter().getCode(), pageable);
fkIntermediario, fkPa, filterAndOrder.getFilter().getCode(), createDateBefore, createDateAfter,
Optional.ofNullable(connectionTypeFilter).orElse(StationConnectionTypeFilter.NONE).name(),
pageable);
} else {
return stazioniRepository.findAllByFilters(
fkIntermediario, filterAndOrder.getFilter().getCode(), pageable);
fkIntermediario, filterAndOrder.getFilter().getCode(), createDateBefore, createDateAfter,
Optional.ofNullable(connectionTypeFilter).orElse(StationConnectionTypeFilter.NONE).name(),
pageable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ public static Timestamp toTimestamp(XMLGregorianCalendar calendar) {
* @return convert offsetDateTime to {@link Timestamp}
*/
public static Timestamp toTimestamp(OffsetDateTime offsetDateTime) {
return Timestamp.from(offsetDateTime.toInstant());
return offsetDateTime != null ?
Timestamp.from(offsetDateTime.toInstant())
: null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class StationsControllerTest {
@BeforeEach
void setUp() {
when(stationsService.getStations(
anyInt(), anyInt(), isNull(), isNull(), isNull(), any(FilterAndOrder.class)))
anyInt(), anyInt(), isNull(), isNull(), isNull(), isNull(), isNull(), any(), any(FilterAndOrder.class)))
.thenReturn(getMockStations());
when(stationsService.getStation(anyString())).thenReturn(getMockStationDetails());
when(stationsService.createStation(any(StationDetails.class)))
Expand Down
Loading
Loading