Skip to content

Commit

Permalink
Add last positions and ers messages date time query before now
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Jul 2, 2021
1 parent fe5af3d commit 53b79f0
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface DBERSRepository : CrudRepository<ERSEntity, Long>, JpaSpecificationExe
"UNION ALL SELECT * from del", nativeQuery = true)
fun findERSMessagesAfterOperationDateTime(internalReferenceNumber: String, afterDateTime: Instant, beforeDateTime: Instant): List<ERSEntity>

@Query("select operation_datetime_utc from ers order by operation_datetime_utc desc limit 1", nativeQuery = true)
@Query("select operation_datetime_utc from ers where operation_datetime_utc < now() order by operation_datetime_utc desc limit 1", nativeQuery = true)
fun findLastOperationDateTime(): Instant

@Query("select * from ers where ers_id in " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ import java.time.ZonedDateTime
interface DBLastPositionRepository : JpaRepository<LastPositionEntity, Int> {
fun findAllByDateTimeGreaterThanEqual(dateTime: ZonedDateTime) : List<LastPositionEntity>

@Query("select last_position_datetime_utc from last_positions order by last_position_datetime_utc desc limit 1", nativeQuery = true)
@Query("select last_position_datetime_utc from last_positions where last_position_datetime_utc < now() order by last_position_datetime_utc desc limit 1", nativeQuery = true)
fun findLastPositionDateTime(): Instant
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ interface DBPositionRepository : CrudRepository<PositionEntity, Long> {
nativeQuery = true)
fun findLastByIrcs(ircs: String, from: ZonedDateTime, to: ZonedDateTime): List<PositionEntity>

@Query("select date_time from positions order by date_time desc limit 1", nativeQuery = true)
@Query("select date_time from positions where date_time < now() order by date_time desc limit 1", nativeQuery = true)
fun findLastPositionDateTime(): Instant
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

COPY public.positions (internal_reference_number, external_reference_number, mmsi, ircs, vessel_name, flag_state, from_country, destination_country, trip_number, latitude, longitude, speed, course, date_time, position_type) FROM stdin;
\N ARSH PE 1316 \N YYP 5012 EL LATINO VE FR DE \N 10.9610000000000003 -64.179000000000002 0.5 0 2020-12-21 15:01:00 VMS
\N ARSH PE 1316 \N YYP 5012 EL LATINO VE FR DE \N 10.9610000000000003 -64.179000000000002 0.5 0 2100-12-21 15:01:00 VMS
\N \N \N \N LA SOBERANA VE FR DE \N 11.0239999999999991 -64.3780000000000001 0.5 154 2020-12-21 20:26:00 VMS
\N PY2045 \N FQKJ TUAHITI PF FR DE \N -14.9830000000000005 -145.15100000000001 6 248 2020-12-23 12:20:00 VMS
\N PY2192 \N FZWR MOOREA RAVA'AI 6 PF FR DE \N -14.9239999999999995 -146.77600000000001 8.59999999999999964 224 2020-12-21 22:59:00 VMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31762,7 +31762,7 @@ COPY public.last_positions (id, cfr, external_immatriculation, mmsi, ircs, vesse
31760 FRA000775473 CH775473 \N FSGQ CHARLEVY FR \N 49.2710000000000008 -0.252000000000000002 0 0 2021-01-15 08:12:00 00:40:00 2020-12-21 15:01:00 14.3 5.2 {"NWW10", "PEL 03"} [{"gear": "OTB", "mesh": 70.0, "dimensions": 45.0}] [{ "gear": "OTB","faoZone": "27.8.b","species": "BLI","weight": 13.46 },{ "gear": "OTB","faoZone": "27.8.c","species": "HKE","weight": 235.6 }] CAEN CN 2020-12-22 08:59:00 true Pas de com INTERNAL_REFERENCE_NUMBER 49.9123 -0.0123
31761 ESP000024732 3-ST-44-00 \N EBRC VILABOA UNO ES \N 44.0159999999999982 -2.1339999999999999 2.39999999999999991 210 2021-01-15 00:06:00 00:40:00 2020-12-21 15:01:00 14.3 5.2 {"NWW10", "PEL 03"} [{"gear": "OTB", "mesh": 70.0, "dimensions": 45.0}] [{ "gear": "OTB","faoZone": "27.8.b","species": "BLI","weight": 13.46 },{ "gear": "OTB","faoZone": "27.8.c","species": "HKE","weight": 235.6 }] CAEN CN 2020-12-22 08:59:00 true Pas de com INTERNAL_REFERENCE_NUMBER 44.4123 -2.2123
31762 ESP000022984 BA929520 \N FLTR FERREIRA MARTINEZ FR \N 52.6300000000000026 -11.8330000000000002 0 356 2021-01-15 08:11:00 00:40:00 2020-12-21 15:01:00 14.3 5.2 {"NWW10", "PEL 03"} [{"gear": "OTB", "mesh": 70.0, "dimensions": 45.0}] [{ "gear": "OTB","faoZone": "27.8.b","species": "BLI","weight": 13.46 },{ "gear": "OTB","faoZone": "27.8.c","species": "HKE","weight": 235.6 }] CAEN CN 2020-12-22 08:59:00 true Pas de com INTERNAL_REFERENCE_NUMBER 52.2123 -11.1123
31763 FRA000579737 LR579737 \N FING LAGARDERE 2 FR \N 44.732999999999997 -1.46599999999999997 3 93 2021-01-15 08:13:00 00:40:00 2020-12-21 15:01:00 14.3 5.2 {"NWW10", "PEL 03"} [{"gear": "OTB", "mesh": 70.0, "dimensions": 45.0}] [{ "gear": "OTB","faoZone": "27.8.b","species": "BLI","weight": 13.46 },{ "gear": "OTB","faoZone": "27.8.c","species": "HKE","weight": 235.6 }] CAEN CN 2020-12-22 08:59:00 true Pas de com INTERNAL_REFERENCE_NUMBER 44.4123 -1.1123
31763 FRA000579737 LR579737 \N FING LAGARDERE 2 FR \N 44.732999999999997 -1.46599999999999997 3 93 2106-01-15 08:13:00 00:40:00 2020-12-21 15:01:00 14.3 5.2 {"NWW10", "PEL 03"} [{"gear": "OTB", "mesh": 70.0, "dimensions": 45.0}] [{ "gear": "OTB","faoZone": "27.8.b","species": "BLI","weight": 13.46 },{ "gear": "OTB","faoZone": "27.8.c","species": "HKE","weight": 235.6 }] CAEN CN 2020-12-22 08:59:00 true Pas de com INTERNAL_REFERENCE_NUMBER 44.4123 -1.1123
31764 DNK000032228 H218 \N OWIN METTE DK \N 56.4209999999999994 11.9689999999999994 3.60000000000000009 169 2021-01-15 04:34:00 00:40:00 2020-12-21 15:01:00 14.3 5.2 {"NWW10", "PEL 03"} [{"gear": "OTB", "mesh": 70.0, "dimensions": 45.0}] [{ "gear": "OTB","faoZone": "27.8.b","species": "BLI","weight": 13.46 },{ "gear": "OTB","faoZone": "27.8.c","species": "HKE","weight": 235.6 }] CAEN CN 2020-12-22 08:59:00 true Pas de com INTERNAL_REFERENCE_NUMBER 56.6123 11.1123
31765 FRA000561949 DP561949 \N FIMA AN DAOUZEG ABOSTOL FR \N 49.9269999999999996 1.08299999999999996 0 0 2021-01-15 08:13:00 00:40:00 2020-12-21 15:01:00 14.3 5.2 {"NWW10", "PEL 03"} [{"gear": "OTB", "mesh": 70.0, "dimensions": 45.0}] [{ "gear": "OTB","faoZone": "27.8.b","species": "BLI","weight": 13.46 },{ "gear": "OTB","faoZone": "27.8.c","species": "HKE","weight": 235.6 }] CAEN CN 2020-12-22 08:59:00 true Pas de com INTERNAL_REFERENCE_NUMBER 49.9123 1.9123
31766 FRA000651332 CH651332 \N FIAX HERA FR \N 48.8359999999999985 -1.60299999999999998 0 28 2021-01-15 08:13:00 00:40:00 2020-12-21 15:01:00 14.3 5.2 {"NWW10", "PEL 03"} [{"gear": "OTB", "mesh": 70.0, "dimensions": 45.0}] [{ "gear": "OTB","faoZone": "27.8.b","species": "BLI","weight": 13.46 },{ "gear": "OTB","faoZone": "27.8.c","species": "HKE","weight": 235.6 }] CAEN CN 2020-12-22 08:59:00 true Pas de com INTERNAL_REFERENCE_NUMBER 48.8123 -1.1123
Expand All @@ -31776,4 +31776,5 @@ update last_positions set last_control_datetime_utc = now() where cfr = 'GBR000B
update last_positions set post_control_comments = 'Tout va bien' where cfr = 'GBR000B14430';
update last_positions set last_position_datetime_utc = now() where cfr = 'FRA000738677';
update last_positions set last_control_datetime_utc = null where cfr = 'FRA000738677';
update last_positions set last_control_datetime_utc = '2106-01-15 08:13:00' where cfr = 'FRA000651332';

4 changes: 2 additions & 2 deletions backend/src/main/resources/db/testdata/V666.5__Insert_ers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ VALUES ('OOF20190126059903', 9463713, 'OOF', '2019-01-26T11:45:00Z', 'DAT', 'OOF
'GBR000B14430', 'MVGM5', 'AR865', 'CABO ORTEGAL', 'FRA', null, 'LAN',
'{"port": "AEAJM", "sender": "MAS", "catchLanded": [{"weight": 20.0, "conversionFactor": 1.0, "nbFish": null, "species": "SLS", "faoZone": "27.8.a", "effortZone": "C", "economicZone": "FRA", "statisticalRectangle": "23E6"}, {"weight": 180.0, "nbFish": null, "species": "HKC", "faoZone": "27.8.a", "effortZone": "C", "economicZone": "FRA", "statisticalRectangle": "23E6"}, {"weight": 1500.0, "nbFish": null, "species": "BON", "faoZone": "27.8.a", "effortZone": "C", "economicZone": "FRA", "statisticalRectangle": "23E6"}, {"weight": 200.0, "nbFish": null, "species": "SCR", "faoZone": "27.8.a", "freshness": null, "packaging": "CNT", "effortZone": "C", "presentation": "WHL", "economicZone": "FRA", "preservationState": "ALI", "statisticalRectangle": "24E6"}, {"weight": 6.0, "nbFish": null, "species": "LBE", "faoZone": "27.8.a", "freshness": null, "packaging": "CNT", "effortZone": "C", "presentation": "WHL", "economicZone": "FRA", "preservationState": "ALI", "statisticalRectangle": "24E6"}], "landingDatetimeUtc": "2019-10-22T11:06:00Z"}',
'2021-01-18T07:17:28.2717Z'),
('OOF22103048321399', null, 'OOF', '2019-10-17T11:36:00Z', 'RET', null, 'OOF20190627059908',
'2019-10-30T11:32:00Z',
('OOF22103048321399', null, 'OOF', '2106-10-17T11:36:00Z', 'RET', null, 'OOF20190627059908',
'2106-10-30T11:32:00Z',
null, null, null, null, null, null, '',
'{"returnStatus": "000"}', '2021-01-18T07:19:28.384921Z'),
('OOF22103048321399', null, 'OOF', '2019-10-17T11:36:00Z', 'DEL', null, 'OOF20190627059908',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class JpaERSRepositoryITests : AbstractDBTests() {

@Test
@Transactional
fun `findLastMessageDate Should find the last message datetime`() {
fun `findLastMessageDate Should find the last message datetime before now and not a datetime in the future`() {
// When
val dateTime = jpaERSRepository.findLastMessageDate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class JpaLastPositionRepositoryITests : AbstractDBTests() {

@Test
@Transactional
fun `findLastPositionDate Should find the last position date`() {
fun `findLastPositionDate Should find the last position date before now and not a date in the future`() {
// Then
val dateTime = jpaLastPositionRepository.findLastPositionDate()

// Then
assertThat(dateTime).isAfter(ZonedDateTime.parse("2020-12-21T15:01:00Z"))
assertThat(dateTime).isNotEqualTo(ZonedDateTime.parse("2106-01-15T08:13:00Z"))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ class JpaPositionRepositoryITests : AbstractDBTests() {

@Test
@Transactional
fun `findLastPositionDate Should find the last position date`() {
fun `findLastPositionDate Should find the last position date before now and not a date in the future`() {
// Then
val dateTime = jpaPositionRepository.findLastPositionDate()

// Then
assertThat(dateTime).isAfter(ZonedDateTime.parse("2020-12-21T15:01:00Z"))
assertThat(dateTime).isNotEqualTo(ZonedDateTime.parse("2100-12-21T15:01Z"))
}
}

0 comments on commit 53b79f0

Please sign in to comment.