From 73b0001703ddcbf671b9bc0917ddebb47d42fa0c Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 28 May 2024 14:04:11 +0200 Subject: [PATCH] Fix prior notification seafront calculation --- .../GetPriorNotification.kt | 2 +- .../GetPriorNotifications.kt | 2 +- .../testdata/V0.221.0__Insert_port_codes.sql | 59 ++++++++++--------- ...6.5.1__Insert_more_pno_logbook_reports.sql | 7 +++ ...5.1__Insert_more_pno_logbook_reports.jsonc | 33 ++++++++++- .../repositories/JpaPortRepositoryITests.kt | 2 +- 6 files changed, 73 insertions(+), 32 deletions(-) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotification.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotification.kt index 0755b5e852..a067350da8 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotification.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotification.kt @@ -56,7 +56,7 @@ class GetPriorNotification( null } - val seafront = port?.facade?.let { Seafront.valueOf(it) } + val seafront: Seafront? = port?.facade?.let { Seafront.from(it) } // Default to UNKNOWN vessel when null or not found val vessel = priorNotification.logbookMessageTyped.logbookMessage diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt index ce3ab0aa6b..6761c63aa9 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt @@ -55,7 +55,7 @@ class GetPriorNotifications( allRiskFactors.find { it.internalReferenceNumber == vesselInternalReferenceNumber } } - val seafront: Seafront? = port?.facade?.let { Seafront.valueOf(it) } + val seafront: Seafront? = port?.facade?.let { Seafront.from(it) } val finalPriorNotification = priorNotification.copy( port = port, diff --git a/backend/src/main/resources/db/testdata/V0.221.0__Insert_port_codes.sql b/backend/src/main/resources/db/testdata/V0.221.0__Insert_port_codes.sql index 01752d0c7a..628831eb05 100644 --- a/backend/src/main/resources/db/testdata/V0.221.0__Insert_port_codes.sql +++ b/backend/src/main/resources/db/testdata/V0.221.0__Insert_port_codes.sql @@ -1,29 +1,32 @@ -insert into ports (country_code_iso2, facade, region, locode, port_name, latitude, longitude, fao_areas, is_active) -values ('AD', null, null, 'ADALV', 'Andorra la Vella', 42.5, 1.01666666666667, ARRAY ['27.8'], true), - ('FR', 'Guadeloupe', null, 'FRZEG', 'Auray', 47.666491, -2.983767, ARRAY ['27.7', '27.7.b'], true), - ('AE', 'Guadeloupe', null, 'AEABU', 'Abu al Bukhoosh', 25.4833333333333, 53.05, null, true), - ('AE', 'Guadeloupe', 'AZ', 'AEAUH', 'Abu Dhabi', 24.4666666666667, 54.0666666666667, null, false), - ('AE', 'Guadeloupe', null, 'AEAMU', 'Abu Musa', 25.8666666666667, 55.0833333333333, null, true), - ('AE', null, 'AZ', 'AEARP', 'Ahmed Bin Rashid Port', 25.5333333333333, 55.0833333333333, null, true), - ('AE', 'NAMO', null, 'AEAJM', 'Ajman', null, null, null, true), - ('AE', 'NAMO', 'FU', 'AEFJR', 'Al Fujayrah', 25.1166666666667, 56.1, null, true), - ('AE', 'NAMO', 'RK', 'AEJAZ', 'Al Jazeera Port', 25.7166666666667, 55.0833333333333, null, true), - ('AE', 'NAMO', 'RK', 'AEAJP', 'Al Jeer Port', 26.0333333333333, 56.1, null, true), - ('AE', 'NAMO', null, 'AERUW', 'Ar Ruways', 24.1166666666667, 52.0333333333333, null, true), - ('AE', null, null, 'AEARZ', 'Arzanah Island', null, null, null, true), - ('AE', null, null, 'AEDAS', 'Das Island', null, null, null, false), - ('AE', 'SA', 'SH', 'AEDBP', 'Dibba', 25.6166666666667, 56.1, null, true), - ('AE', 'SA', 'DU', 'AEDXB', 'Dubai', 25.25, 55.0833333333333, null, true), - ('AE', 'SA', 'AZ', 'AEEND', 'Esnnad', 24.3166666666667, 54.0666666666667, null, false), - ('AE', 'SA', null, 'AEFAT', 'Fateh Terminal', null, null, null, true), - ('AE', 'SA', 'DU', 'AEFRP', 'Free Port', 25.25, 55.0833333333333, null, true), - ('AE', null, 'DU', 'AEHZP', 'Hamriya Free Zone Port', 25.3, 55.0833333333333, null, true), - ('AE', null, 'DU', 'AEHSN', 'Hassyan', 24.9, 54.0666666666667, null, false), - ('AE', null, null, 'AEHTL', 'Hulaylah Terminal', 25.9833333333333, 55.0833333333333, null, true), +INSERT INTO ports ( + country_code_iso2, facade, region, locode, port_name, latitude, longitude, fao_areas, is_active) +VALUES + ( 'AD', null, null, 'ADALV', 'Andorra la Vella', 42.5, 1.01666666666667, ARRAY ['27.8'], true), + ( 'FR', 'Guadeloupe', null, 'FRZEG', 'Auray', 47.666491, -2.983767, ARRAY ['27.7', '27.7.b'], true), + ( 'AE', 'Guadeloupe', null, 'AEABU', 'Abu al Bukhoosh', 25.4833333333333, 53.05, null, true), + ( 'AE', 'Guadeloupe', 'AZ', 'AEAUH', 'Abu Dhabi', 24.4666666666667, 54.0666666666667, null, false), + ( 'AE', 'Guadeloupe', null, 'AEAMU', 'Abu Musa', 25.8666666666667, 55.0833333333333, null, true), + ( 'AE', null, 'AZ', 'AEARP', 'Ahmed Bin Rashid Port', 25.5333333333333, 55.0833333333333, null, true), + ( 'AE', 'NAMO', null, 'AEAJM', 'Ajman', null, null, null, true), + ( 'AE', 'NAMO', 'FU', 'AEFJR', 'Al Fujayrah', 25.1166666666667, 56.1, null, true), + ( 'AE', 'NAMO', 'RK', 'AEJAZ', 'Al Jazeera Port', 25.7166666666667, 55.0833333333333, null, true), + ( 'AE', 'NAMO', 'RK', 'AEAJP', 'Al Jeer Port', 26.0333333333333, 56.1, null, true), + ( 'AE', 'NAMO', null, 'AERUW', 'Ar Ruways', 24.1166666666667, 52.0333333333333, null, true), + ( 'AE', null, null, 'AEARZ', 'Arzanah Island', null, null, null, true), + ( 'AE', null, null, 'AEDAS', 'Das Island', null, null, null, false), + ( 'AE', 'SA', 'SH', 'AEDBP', 'Dibba', 25.6166666666667, 56.1, null, true), + ( 'AE', 'SA', 'DU', 'AEDXB', 'Dubai', 25.25, 55.0833333333333, null, true), + ( 'AE', 'SA', 'AZ', 'AEEND', 'Esnnad', 24.3166666666667, 54.0666666666667, null, false), + ( 'AE', 'SA', null, 'AEFAT', 'Fateh Terminal', null, null, null, true), + ( 'AE', 'SA', 'DU', 'AEFRP', 'Free Port', 25.25, 55.0833333333333, null, true), + ( 'AE', null, 'DU', 'AEHZP', 'Hamriya Free Zone Port', 25.3, 55.0833333333333, null, true), + ( 'AE', null, 'DU', 'AEHSN', 'Hassyan', 24.9, 54.0666666666667, null, false), + ( 'AE', null, null, 'AEHTL', 'Hulaylah Terminal', 25.9833333333333, 55.0833333333333, null, true), - -- https://service.unece.org/trade/locode/fr.htm - ('FR', 'NAMO', '29', 'FRBES', 'Brest', 48.24, 4.29, null, true), - ('FR', 'MEMN', '13', 'FRMRS', 'Marseille', 43.18, 5.24, null, true), - ('FR', 'MEMN', '06', 'FRNCE', 'Nice', 43.42, 7.16, null, true), - ('FR', 'NAMO', '35', 'FRSML', 'Saint-Malo', 48.39, 2.01, null, true), - ('FR', 'NAMO', '56', 'FRVNE', 'Vannes', 47.39, 2.46, null, true); + -- https://service.unece.org/trade/locode/fr.htm + ( 'FR', 'NAMO', '29', 'FRBES', 'Brest', 48.24, 4.29, null, true), + ( 'FR', 'MEMN', '13', 'FRMRS', 'Marseille', 43.18, 5.24, null, true), + ( 'FR', 'MEMN', '06', 'FRNCE', 'Nice', 43.42, 7.16, null, true), + ( 'FR', 'NAMO', '35', 'FRSML', 'Saint-Malo', 48.39, 2.01, null, true), + ( 'FR', 'NAMO', '56', 'FRVNE', 'Vannes', 47.39, 2.46, null, true), + ( 'RE', 'Sud Océan Indien', '974', 'REZSE', 'Saint-Denis De La Réunion', -20.88, 55.45, ARRAY ['51.6', '51.7'], true); diff --git a/backend/src/main/resources/db/testdata/V666.5.1__Insert_more_pno_logbook_reports.sql b/backend/src/main/resources/db/testdata/V666.5.1__Insert_more_pno_logbook_reports.sql index 4e0709bbb5..0c641800dd 100644 --- a/backend/src/main/resources/db/testdata/V666.5.1__Insert_more_pno_logbook_reports.sql +++ b/backend/src/main/resources/db/testdata/V666.5.1__Insert_more_pno_logbook_reports.sql @@ -37,6 +37,8 @@ INSERT INTO logbook_raw_messages (operation_number, xml_message) VALUES ('FAKE_O INSERT INTO logbook_raw_messages (operation_number, xml_message) VALUES ('FAKE_OPERATION_114', 'Message FLUX xml'); +INSERT INTO logbook_raw_messages (operation_number, xml_message) VALUES ('FAKE_OPERATION_115', 'Message FLUX xml'); + INSERT INTO logbook_reports (id, report_id, referenced_report_id, cfr, enriched, flag_state, integration_datetime_utc, log_type, operation_datetime_utc, operation_number, operation_type, report_datetime_utc, transmission_format, vessel_name, trip_gears, trip_segments, value) VALUES (101, 'FAKE_OPERATION_101', NULL, 'FAK000999999', true, 'FRA', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'PNO', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'FAKE_OPERATION_101', 'DAT', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'ERS', 'PHENOMENE', '[{"gear":"TBN","mesh":100,"dimensions":"250;180"},{"gear":"OTT","mesh":120.5,"dimensions":"250;280"}]', '[{"segment":"SWW04","segmentName":"Chaluts pélagiques"},{"segment":"SWW06","segmentName":"Sennes"}]', '{"catchOnboard":[{"weight":25,"nbFish":null,"species":"COD","faoZone":"27.8.a","effortZone":"C","economicZone":"FRA","statisticalRectangle":"23E6"}],"pnoTypes":[{"pnoTypeName":"Préavis type A","minimumNotificationPeriod":4,"hasDesignatedPorts":false},{"pnoTypeName":"Préavis type B","minimumNotificationPeriod":8,"hasDesignatedPorts":true}],"port":"FRSML","predictedArrivalDatetimeUtc":null,"predictedLandingDatetimeUtc":null,"purpose":"LAN","tripStartDate":null}'); UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 101; UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3.5 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 101; @@ -108,3 +110,8 @@ INSERT INTO logbook_reports (id, report_id, referenced_report_id, cfr, enriched, UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '1 hour', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 114; UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '2 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 114; UPDATE logbook_reports SET value = JSONB_SET(value, '{tripStartDate}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '20 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 114; + +INSERT INTO logbook_reports (id, report_id, referenced_report_id, cfr, enriched, flag_state, integration_datetime_utc, log_type, operation_datetime_utc, operation_number, operation_type, report_datetime_utc, transmission_format, vessel_name, trip_gears, trip_segments, value) VALUES (115, 'FAKE_OPERATION_115', NULL, 'CFR110', true, 'FRA', NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours', 'PNO', NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours', 'FAKE_OPERATION_115', 'DAT', NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours', 'ERS', 'LA MER À BOIRE', '[]', '[]', '{"catchOnboard":[],"pnoTypes":[],"port":"REZSE","predictedArrivalDatetimeUtc":null,"predictedLandingDatetimeUtc":null,"purpose":"LAN","tripStartDate":null}'); +UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '1 hour', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 115; +UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '2 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 115; +UPDATE logbook_reports SET value = JSONB_SET(value, '{tripStartDate}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '20 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 115; diff --git a/backend/src/main/resources/db/testdata/json/V666.5.1__Insert_more_pno_logbook_reports.jsonc b/backend/src/main/resources/db/testdata/json/V666.5.1__Insert_more_pno_logbook_reports.jsonc index f70a138d10..8fa143c8f5 100644 --- a/backend/src/main/resources/db/testdata/json/V666.5.1__Insert_more_pno_logbook_reports.jsonc +++ b/backend/src/main/resources/db/testdata/json/V666.5.1__Insert_more_pno_logbook_reports.jsonc @@ -19,7 +19,8 @@ { "operation_number": "FAKE_OPERATION_111_COR_ORPHAN", "xml_message": "Message FLUX xml" }, { "operation_number": "FAKE_OPERATION_112", "xml_message": "Message FLUX xml" }, { "operation_number": "FAKE_OPERATION_113", "xml_message": "Message FLUX xml" }, - { "operation_number": "FAKE_OPERATION_114", "xml_message": "Message FLUX xml" } + { "operation_number": "FAKE_OPERATION_114", "xml_message": "Message FLUX xml" }, + { "operation_number": "FAKE_OPERATION_115", "xml_message": "Message FLUX xml" } ] }, { @@ -842,6 +843,36 @@ "purpose": "LAN", "tripStartDate:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '20 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')" } + }, + + // - Vessel: LA MER À BOIRE + // - Port: Saint-Denis De La Réunion (Sud Océan Indien) + { + "id": 115, + "report_id": "FAKE_OPERATION_115", + "referenced_report_id": null, + "cfr": "CFR110", + "enriched": true, + "flag_state": "FRA", + "integration_datetime_utc:sql": "NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours'", + "log_type": "PNO", + "operation_datetime_utc:sql": "NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours'", + "operation_number": "FAKE_OPERATION_115", + "operation_type": "DAT", + "report_datetime_utc:sql": "NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours'", + "transmission_format": "ERS", + "vessel_name": "LA MER À BOIRE", + "trip_gears:jsonb": [], + "trip_segments:jsonb": [], + "value:jsonb": { + "catchOnboard": [], + "pnoTypes": [], + "port": "REZSE", + "predictedArrivalDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '1 hour', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')", + "predictedLandingDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '2 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')", + "purpose": "LAN", + "tripStartDate:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '20 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')" + } } ] } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPortRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPortRepositoryITests.kt index 4fecb01366..f13f279c87 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPortRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPortRepositoryITests.kt @@ -16,7 +16,7 @@ class JpaPortRepositoryITests : AbstractDBTests() { val activePorts = jpaPortRepository.findAllActive().sortedBy { it.locode } // Then - assertThat(activePorts).hasSize(22) + assertThat(activePorts).hasSize(23) assertThat(activePorts.first().locode).isEqualTo("ADALV") assertThat(activePorts.first().name).isEqualTo("Andorra la Vella") assertThat(activePorts.first().faoAreas.first()).isEqualTo("27.8")