From e73bd45cba5a8b04b69bcbe8a89c7965e31bf060 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Thu, 1 Feb 2024 18:25:23 +0100 Subject: [PATCH 01/14] Replace flag state string by country code --- .../mission/mission_actions/MissionAction.kt | 11 +- .../api/input/AddMissionActionDataInput.kt | 5 +- .../api/outputs/MissionActionDataOutput.kt | 5 +- .../database/entities/MissionActionEntity.kt | 7 +- ...V0.244.1__Update_mission_actions_table.sql | 20 ++++ ....0__Insert_dummy_actions_for_migration.sql | 13 +++ .../testdata/V666.9__Insert_dummy_actions.sql | 6 +- .../mission_actions/MissionActionUTests.kt | 8 +- .../mission_actions/AddMissionActionUTests.kt | 3 + .../DeleteMissionActionUTests.kt | 3 + .../GetActivityReportsUTests.kt | 16 +++ .../GetMissionActionSeafrontUTests.kt | 11 ++ .../GetVesselControlsUTests.kt | 7 ++ .../UpdateMissionActionUTests.kt | 3 + .../use_cases/mission_actions/TestUtils.kt | 0 ...s.kt => MissionActionsControllerITests.kt} | 100 ++++++++++++------ .../api/bff/MissionsControllerITests.kt | 3 + .../PublicMissionActionsControllerITests.kt | 3 + .../JpaMissionActionRepositoryITests.kt | 3 +- .../database/repositories/TestUtils.kt | 3 +- .../mission_form/sea_control.spec.ts | 2 +- frontend/src/domain/entities/vessel/vessel.ts | 2 +- frontend/src/domain/shared_slices/Vessel.ts | 2 +- frontend/src/features/VesselList/index.tsx | 9 +- 24 files changed, 190 insertions(+), 55 deletions(-) create mode 100644 backend/src/main/resources/db/migration/internal/V0.244.1__Update_mission_actions_table.sql create mode 100644 backend/src/main/resources/db/testdata/V0.244.0__Insert_dummy_actions_for_migration.sql create mode 100644 backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/TestUtils.kt rename backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/{PublicMissionActionsControllerITests.kt => MissionActionsControllerITests.kt} (83%) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt index 4c393edfc4..97e6754c51 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions +import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit import java.time.ZonedDateTime @@ -11,7 +12,7 @@ data class MissionAction( val internalReferenceNumber: String? = null, val externalReferenceNumber: String? = null, val ircs: String? = null, - val flagState: String? = null, + val flagState: CountryCode, val districtCode: String? = null, val faoAreas: List = listOf(), val actionType: MissionActionType, @@ -35,7 +36,7 @@ data class MissionAction( val unitWithoutOmegaGauge: Boolean? = null, val controlQualityComments: String? = null, val feedbackSheetRequired: Boolean? = null, - val userTrigram: String? = null, + val userTrigram: String, val segments: List = listOf(), val facade: String? = null, val longitude: Double? = null, @@ -92,17 +93,11 @@ data class MissionAction( require(this.latitude != null) { "A control must specify a position: the `latitude` must be given." } - require(this.userTrigram != null) { - "A control must specify a user trigram: the `userTrigram` must be given." - } } private fun checkControlPort() { require(this.portLocode != null) { "A land control must specify a port: the `portLocode` must be given." } - require(this.userTrigram != null) { - "A control must specify a user trigram: the `userTrigram` must be given." - } } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt index 23bdb22e79..22035d1a0c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.input +import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Completion import java.time.ZonedDateTime @@ -11,7 +12,7 @@ data class AddMissionActionDataInput( var internalReferenceNumber: String? = null, var externalReferenceNumber: String? = null, var ircs: String? = null, - var flagState: String? = null, + var flagState: CountryCode, var districtCode: String? = null, var faoAreas: List = listOf(), var flightGoals: List = listOf(), @@ -43,7 +44,7 @@ data class AddMissionActionDataInput( var seizureAndDiversionComments: String? = null, var otherComments: String? = null, var gearOnboard: List = listOf(), - var userTrigram: String? = null, + var userTrigram: String, var speciesOnboard: List = listOf(), var vesselTargeted: ControlCheck? = null, var hasSomeGearsSeized: Boolean = false, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt index bcb0e6cf6a..583fcb14da 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs +import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Completion @@ -12,7 +13,7 @@ data class MissionActionDataOutput( val internalReferenceNumber: String? = null, val externalReferenceNumber: String? = null, val ircs: String? = null, - val flagState: String? = null, + val flagState: CountryCode, val districtCode: String? = null, val faoAreas: List = listOf(), val flightGoals: List = listOf(), @@ -48,7 +49,7 @@ data class MissionActionDataOutput( val gearOnboard: List = listOf(), val speciesOnboard: List = listOf(), val controlUnits: List = listOf(), - val userTrigram: String? = null, + val userTrigram: String, val vesselTargeted: ControlCheck? = null, val hasSomeGearsSeized: Boolean, val hasSomeSpeciesSeized: Boolean, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt index 03a25a708f..cff32fbbeb 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt @@ -1,6 +1,8 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.entities import com.fasterxml.jackson.databind.ObjectMapper +import com.neovisionaries.i18n.CountryCode +import fr.gouv.cnsp.monitorfish.domain.entities.facade.Facade import fr.gouv.cnsp.monitorfish.domain.entities.facade.Seafront import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import io.hypersistence.utils.hibernate.type.json.JsonBinaryType @@ -31,7 +33,8 @@ class MissionActionEntity( @Column(name = "ircs") val ircs: String? = null, @Column(name = "flag_state") - val flagState: String? = null, + @Enumerated(EnumType.STRING) + val flagState: CountryCode, @Column(name = "district_code") val districtCode: String? = null, @Column(name = "flight_goals", columnDefinition = "varchar(100)[]") @@ -93,7 +96,7 @@ class MissionActionEntity( @Column(name = "is_from_poseidon") val isFromPoseidon: Boolean, @Column(name = "user_trigram") - val userTrigram: String? = null, + val userTrigram: String, @Type(JsonBinaryType::class) @Column(name = "segments", columnDefinition = "jsonb") val segments: String? = null, diff --git a/backend/src/main/resources/db/migration/internal/V0.244.1__Update_mission_actions_table.sql b/backend/src/main/resources/db/migration/internal/V0.244.1__Update_mission_actions_table.sql new file mode 100644 index 0000000000..982370aa41 --- /dev/null +++ b/backend/src/main/resources/db/migration/internal/V0.244.1__Update_mission_actions_table.sql @@ -0,0 +1,20 @@ +ALTER TABLE mission_actions +ALTER COLUMN user_trigram SET NOT NULL; + +UPDATE mission_actions +SET flag_state = 'UNDEFINED' +WHERE flag_state = 'UNKNOWN'; + +UPDATE mission_actions +SET flag_state = 'UNDEFINED' +WHERE flag_state = 'X'; + +UPDATE mission_actions +SET flag_state = 'UNDEFINED' +WHERE flag_state IS NULL; + +UPDATE mission_actions +SET flag_state = upper(flag_state); + +ALTER TABLE mission_actions +ALTER COLUMN flag_state SET NOT NULL; diff --git a/backend/src/main/resources/db/testdata/V0.244.0__Insert_dummy_actions_for_migration.sql b/backend/src/main/resources/db/testdata/V0.244.0__Insert_dummy_actions_for_migration.sql new file mode 100644 index 0000000000..cccf3a0600 --- /dev/null +++ b/backend/src/main/resources/db/testdata/V0.244.0__Insert_dummy_actions_for_migration.sql @@ -0,0 +1,13 @@ +INSERT INTO mission_actions ( + vessel_id, cfr, vessel_name, flag_state, mission_id, action_type, action_datetime_utc, has_some_gears_seized, has_some_species_seized, facade, longitude, latitude, port_locode, vessel_targeted, seizure_and_diversion, seizure_and_diversion_comments, other_comments, closed_by, gear_onboard, gear_infractions, species_onboard, species_infractions, species_observations, other_infractions, fao_areas, segments, emits_vms, emits_ais, logbook_matches_activity, licences_match_activity, species_weight_controlled, species_size_controlled, separate_stowage_of_preserved_species, logbook_infractions, licences_and_logbook_observations, number_of_vessels_flown_over, unit_without_omega_gauge, control_quality_comments, feedback_sheet_required, is_from_poseidon, user_trigram, is_deleted) +VALUES + ( 1, 'FAK000999999', 'PHENOMENE', 'gb', 1, 'SEA_CONTROL', NOW() - ('1 YEAR')::interval, FALSE, FALSE, 'NAMO', -8.52, 51.58, NULL, 'YES', False, NULL, 'Commentaires post contrôle', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '{27.7.c}', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, true, 'ABC', false), + ( 1, 'FAK000999999', 'PHENOMENE', 'gb', 2, 'SEA_CONTROL', NOW(), FALSE, TRUE, 'NAMO', -0.52, 47.44, NULL, 'NO', True, 'Saisie de la pêche', 'Commentaires post contrôle', 'XYZ', '[{"gearCode": "OTB", "gearName": "Chaluts de fond à panneaux", "declaredMesh": 60.0, "controlledMesh": null, "hasUncontrolledMesh": true, "gearWasControlled": false}, {"gearCode": "OTM", "gearName": "Chaluts pélagiques à panneaux", "declaredMesh": 60.0, "controlledMesh": 52.8, "hasUncontrolledMesh": false, "gearWasControlled": true}]', '[{"infractionType": "WITH_RECORD", "natinf": 23581, "comments": "Maille trop petite"}, {"infractionType": "PENDING", "natinf": 27724, "comments": "Engin non conforme"}]', '[{"speciesCode": "MNZ", "declaredWeight": 302.5, "controlledWeight": 450, "underSized": true}, {"speciesCode": "CRF", "declaredWeight": 40, "controlledWeight": 40, "underSized": false}]', '[{"infractionType": "WITHOUT_RECORD", "natinf": 28346, "comments": "Sous taille de 8cm"}]', 'Saisie de l''ensemble des captures à bord', '[{"infractionType": "WITH_RECORD", "natinf": 23588, "comments": "Chalutage répété dans les 3 milles sur Piste VMS - confirmé de visu"}, {"infractionType": "PENDING", "natinf": 23584, "comments": "Absence d''équipement AIS à bord"}]', '{27.7.d,27.7.e}', '[{"segment": "SWW04", "segmentName": "Midwater trawls", "faoAreas": ["27.8c", "27.8"]}, {"segment": "PEL03", "segmentName": "Polyvalent - Bottom trawl", "faoAreas": ["27.3.a", "27.7", "27.8", "27.9"]}]', 'YES', 'NOT_APPLICABLE', 'NO', 'NO', true, true, 'YES', '[{"infractionType": "WITH_RECORD", "natinf": 27689, "comments": "Poids à bord MNZ supérieur de 50% au poids déclaré"}]', 'C''est pas très très bien réglo toute cette poissecalle non déclarée', NULL, false, 'Ciblage CNSP non respecté', true, false, 'DEF', false), + ( 1, 'FAK000999999', 'PHENOMENE', 'GB', 3, 'SEA_CONTROL', NOW() - ('1 YEAR')::interval - ('1 MONTH')::interval, FALSE, FALSE, 'NAMO', -8.52, 51.58, NULL, 'YES', False, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'NO', 'YES', NULL, 'YES', false, false, NULL, NULL, NULL, NULL, true, NULL, false, false, 'GHI', false), + ( 2, 'U_W0NTFINDME', 'MALOTRU', 'X', 4, 'SEA_CONTROL', NOW() - ('1 YEAR')::interval, FALSE, FALSE, 'MEMN', -10.85, 53.35, NULL, 'YES', False, NULL, 'Commentaires post contrôle', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '{27.8.a}', NULL, 'NOT_APPLICABLE', NULL, 'NOT_APPLICABLE', 'NOT_APPLICABLE', NULL, NULL, 'NO', NULL, NULL, NULL, false, NULL, false, false, 'JKL', false), + ( 1, 'FAK000999999', 'PHENOMENE', 'UNKNOWN', 5, 'LAND_CONTROL', '2020-01-18T07:19:28.384921Z', FALSE, FALSE, 'MEMN', NULL, NULL, 'AEFAT', 'YES', False, NULL, 'Documents pas à jour', NULL, '[{"gearCode": "OTB", "gearName": "Chaluts de fond à panneaux", "declaredMesh": 60.0, "controlledMesh": 58.9, "hasUncontrolledMesh": false, "gearWasControlled": true}]', NULL, '[{"speciesCode": "JAX", "declaredWeight": 302.5, "controlledWeight": 450, "underSized": true}, {"speciesCode": "CRF", "declaredWeight": 40, "controlledWeight": 40, "underSized": false}]', NULL, NULL, NULL, '{27.4.a}', NULL, NULL, 'NO', 'NO', NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, false, false, 'MNO', false), + ( 1, 'FAK000999999', 'PHENOMENE', 'GB', 6, 'AIR_SURVEILLANCE', '2021-02-10T12:11:18.884456Z', FALSE, FALSE, 'MED', NULL, NULL, NULL, NULL, NULL, NULL, '1 navire / 26 en défaut AIS', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '[{"segment": "MED01", "segmentName": "All Trawls 1", "faoAreas": ["37.1", "37.2", "37.3"]}, {"segment": "MED02", "segmentName": "All Traws 2", "faoAreas": ["37.1", "37.2", "37.3"]}]', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 26, NULL, 'Bonne coordinnation avec le CNSP', false, false, 'PQR', false), + ( 1, 'FAK000999999', 'PHENOMENE', 'GB', 6, 'AIR_CONTROL', '2021-02-10T12:11:18.884456Z', FALSE, FALSE, 'MED', 4.789730, 42.73183, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '[{"infractionType": "WITHOUT_RECORD", "natinf": 23584, "comments": "Non émission AIS"}]', '{37.1.1}', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, 'PQR', false), + ( 123, NULL, NULL, NULL, 43, 'AIR_CONTROL', '2021-02-10T12:11:18.884456Z', FALSE, FALSE, 'MED', 4.789730, 42.73183, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '[{"infractionType": "WITH_RECORD", "natinf": 23584, "comments": "Non émission AIS"}]', '{37.1.1}', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, 'PQR', false), + ( 1234, NULL, NULL, NULL, 34, 'SEA_CONTROL', '2019-01-18T07:19:28.384921Z', FALSE, FALSE, 'Sud Océan Indien', -0.56, 49.44, NULL, 'YES', False, NULL, 'Commentaires post contrôle', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '{27.8.a}', NULL, 'NOT_APPLICABLE', NULL, 'NOT_APPLICABLE', 'NOT_APPLICABLE', NULL, NULL, 'NO', NULL, NULL, NULL, false, NULL, false, false, 'JKL', false), + ( 9999, NULL, NULL, NULL, 34, 'SEA_CONTROL', '2019-01-19T07:19:28.384921Z', FALSE, FALSE, 'MEMN', -0.56, 49.44, NULL, 'YES', False, NULL, 'Action supprimée', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '{27.8.a}', NULL, 'NOT_APPLICABLE', NULL, 'NOT_APPLICABLE', 'NOT_APPLICABLE', NULL, NULL, 'NO', NULL, NULL, NULL, false, NULL, false, false, 'JKL', true); diff --git a/backend/src/main/resources/db/testdata/V666.9__Insert_dummy_actions.sql b/backend/src/main/resources/db/testdata/V666.9__Insert_dummy_actions.sql index 5cd0ff8b77..3a2da48e79 100644 --- a/backend/src/main/resources/db/testdata/V666.9__Insert_dummy_actions.sql +++ b/backend/src/main/resources/db/testdata/V666.9__Insert_dummy_actions.sql @@ -24,6 +24,6 @@ VALUES ( 1, 'FAK000999999', 'PHENOMENE', 'GB', 5, 'LAND_CONTROL', '2020-01-18T07:19:28.384921Z', FALSE, FALSE, 'MEMN', NULL, NULL, 'AEFAT', 'YES', False, NULL, 'Documents pas à jour', 'TO_COMPLETE', NULL, '[{"gearCode": "OTB", "gearName": "Chaluts de fond à panneaux", "declaredMesh": 60.0, "controlledMesh": 58.9, "hasUncontrolledMesh": false, "gearWasControlled": true}]', NULL, '[{"speciesCode": "JAX", "declaredWeight": 302.5, "controlledWeight": 450, "underSized": true}, {"speciesCode": "CRF", "declaredWeight": 40, "controlledWeight": 40, "underSized": false}]', NULL, NULL, NULL, '{27.4.a}', NULL, NULL, 'NO', 'NO', NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, false, false, 'MNO', false), ( 1, 'FAK000999999', 'PHENOMENE', 'GB', 6, 'AIR_SURVEILLANCE', '2021-02-10T12:11:18.884456Z', FALSE, FALSE, 'MED', NULL, NULL, NULL, NULL, NULL, NULL, '1 navire / 26 en défaut AIS', 'TO_COMPLETE', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '[{"segment": "MED01", "segmentName": "All Trawls 1", "faoAreas": ["37.1", "37.2", "37.3"]}, {"segment": "MED02", "segmentName": "All Traws 2", "faoAreas": ["37.1", "37.2", "37.3"]}]', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 26, NULL, 'Bonne coordinnation avec le CNSP', false, false, 'PQR', false), ( 1, 'FAK000999999', 'PHENOMENE', 'GB', 6, 'AIR_CONTROL', '2021-02-10T12:11:18.884456Z', FALSE, FALSE, 'MED', 4.789730, 42.73183, NULL, NULL, NULL, NULL, NULL, 'TO_COMPLETE', NULL, NULL, NULL, NULL, NULL, NULL, '[{"infractionType": "WITHOUT_RECORD", "natinf": 23584, "comments": "Non émission AIS"}]', '{37.1.1}', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, 'PQR', false), - ( 123, NULL, NULL, NULL, 43, 'AIR_CONTROL', '2021-02-10T12:11:18.884456Z', FALSE, FALSE, 'MED', 4.789730, 42.73183, NULL, NULL, NULL, NULL, NULL, 'TO_COMPLETE', NULL, NULL, NULL, NULL, NULL, NULL, '[{"infractionType": "WITH_RECORD", "natinf": 23584, "comments": "Non émission AIS"}]', '{37.1.1}', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, 'PQR', false), - ( 1234, NULL, NULL, NULL, 34, 'SEA_CONTROL', '2019-01-18T07:19:28.384921Z', FALSE, FALSE, 'Sud Océan Indien', -0.56, 49.44, NULL, 'YES', False, NULL, 'Commentaires post contrôle', 'TO_COMPLETE', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '{27.8.a}', NULL, 'NOT_APPLICABLE', NULL, 'NOT_APPLICABLE', 'NOT_APPLICABLE', NULL, NULL, 'NO', NULL, NULL, NULL, false, NULL, false, false, 'JKL', false), - ( 9999, NULL, NULL, NULL, 34, 'SEA_CONTROL', '2019-01-19T07:19:28.384921Z', FALSE, FALSE, 'MEMN', -0.56, 49.44, NULL, 'YES', False, NULL, 'Action supprimée', 'TO_COMPLETE', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '{27.8.a}', NULL, 'NOT_APPLICABLE', NULL, 'NOT_APPLICABLE', 'NOT_APPLICABLE', NULL, NULL, 'NO', NULL, NULL, NULL, false, NULL, false, false, 'JKL', true); + ( 123, NULL, NULL, 'UNDEFINED', 43, 'AIR_CONTROL', '2021-02-10T12:11:18.884456Z', FALSE, FALSE, 'MED', 4.789730, 42.73183, NULL, NULL, NULL, NULL, NULL, 'TO_COMPLETE', NULL, NULL, NULL, NULL, NULL, NULL, '[{"infractionType": "WITH_RECORD", "natinf": 23584, "comments": "Non émission AIS"}]', '{37.1.1}', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, 'PQR', false), + ( 1234, NULL, NULL, 'UNDEFINED', 34, 'SEA_CONTROL', '2019-01-18T07:19:28.384921Z', FALSE, FALSE, 'Sud Océan Indien', -0.56, 49.44, NULL, 'YES', False, NULL, 'Commentaires post contrôle', 'TO_COMPLETE', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '{27.8.a}', NULL, 'NOT_APPLICABLE', NULL, 'NOT_APPLICABLE', 'NOT_APPLICABLE', NULL, NULL, 'NO', NULL, NULL, NULL, false, NULL, false, false, 'JKL', false), + ( 9999, NULL, NULL, 'UNDEFINED', 34, 'SEA_CONTROL', '2019-01-19T07:19:28.384921Z', FALSE, FALSE, 'MEMN', -0.56, 49.44, NULL, 'YES', False, NULL, 'Action supprimée', 'TO_COMPLETE', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '{27.8.a}', NULL, 'NOT_APPLICABLE', NULL, 'NOT_APPLICABLE', 'NOT_APPLICABLE', NULL, NULL, 'NO', NULL, NULL, NULL, false, NULL, false, false, 'JKL', true); diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt index 5303b5d6e8..a3281c001c 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions +import com.neovisionaries.i18n.CountryCode import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable import org.junit.jupiter.api.Test @@ -30,6 +31,7 @@ class MissionActionUTests { completedBy = "XYZ", isFromPoseidon = false, completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, ) // When @@ -60,7 +62,8 @@ class MissionActionUTests { completedBy = "XYZ", isFromPoseidon = false, completion = Completion.TO_COMPLETE, - ) + flagState = CountryCode.FR, + ) // When val throwable = catchThrowable { action.verify() } @@ -93,6 +96,7 @@ class MissionActionUTests { hasSomeSpeciesSeized = false, completedBy = "XYZ", isFromPoseidon = false, + flagState = CountryCode.FR, completion = Completion.TO_COMPLETE, ) @@ -124,6 +128,7 @@ class MissionActionUTests { hasSomeSpeciesSeized = false, completedBy = "XYZ", isFromPoseidon = false, + flagState = CountryCode.FR, completion = Completion.TO_COMPLETE, ) @@ -155,6 +160,7 @@ class MissionActionUTests { hasSomeSpeciesSeized = false, completedBy = "XYZ", isFromPoseidon = false, + flagState = CountryCode.FR, completion = Completion.TO_COMPLETE, ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionActionUTests.kt index a9c4af49f0..fb255f4666 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionActionUTests.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions +import com.neovisionaries.i18n.CountryCode import com.nhaarman.mockitokotlin2.anyOrNull import com.nhaarman.mockitokotlin2.argumentCaptor import com.nhaarman.mockitokotlin2.given @@ -46,6 +47,7 @@ class AddMissionActionUTests { hasSomeSpeciesSeized = false, completedBy = "XYZ", isFromPoseidon = false, + flagState = CountryCode.FR, completion = Completion.TO_COMPLETE, ) @@ -80,6 +82,7 @@ class AddMissionActionUTests { hasSomeSpeciesSeized = false, completedBy = "XYZ", isFromPoseidon = false, + flagState = CountryCode.FR, completion = Completion.TO_COMPLETE, ) given(missionActionsRepository.save(anyOrNull())).willReturn(action) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionActionUTests.kt index 7e77562a22..3bca5b0599 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionActionUTests.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions +import com.neovisionaries.i18n.CountryCode import com.nhaarman.mockitokotlin2.* import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Completion import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction @@ -35,6 +36,8 @@ class DeleteMissionActionUTests { hasSomeSpeciesSeized = false, completedBy = "XYZ", isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ) given(missionActionsRepository.findById(any())).willReturn(action) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt index d66fc80dec..c0f7603a19 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt @@ -66,6 +66,8 @@ class GetActivityReportsUTests { hasSomeSpeciesSeized = false, isFromPoseidon = false, completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", ), MissionAction( id = 2, @@ -79,6 +81,8 @@ class GetActivityReportsUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), MissionAction( @@ -93,6 +97,8 @@ class GetActivityReportsUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), ) @@ -194,6 +200,8 @@ class GetActivityReportsUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), MissionAction( @@ -208,6 +216,8 @@ class GetActivityReportsUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), MissionAction( @@ -222,6 +232,8 @@ class GetActivityReportsUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), ) @@ -313,6 +325,8 @@ class GetActivityReportsUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), MissionAction( @@ -327,6 +341,8 @@ class GetActivityReportsUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionSeafrontUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionSeafrontUTests.kt index cd5d964401..354eae21e2 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionSeafrontUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionSeafrontUTests.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions +import com.neovisionaries.i18n.CountryCode import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.given import fr.gouv.cnsp.monitorfish.domain.entities.facade.FacadeArea @@ -44,6 +45,8 @@ class GetMissionActionSeafrontUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ) given(portRepository.findByLocode(any())).willReturn(Port("AEFAT", name = "Dummy name", facade = "NAMO")) @@ -71,6 +74,8 @@ class GetMissionActionSeafrontUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ) @@ -98,6 +103,8 @@ class GetMissionActionSeafrontUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ) given(facadeAreasRepository.findByIncluding(any())).willReturn( @@ -135,6 +142,8 @@ class GetMissionActionSeafrontUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ) @@ -162,6 +171,8 @@ class GetMissionActionSeafrontUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ) given(facadeAreasRepository.findByIncluding(any())).willReturn(listOf()) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControlsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControlsUTests.kt index 9423746fc8..f146c48f4d 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControlsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControlsUTests.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions +import com.neovisionaries.i18n.CountryCode import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.eq import fr.gouv.cnsp.monitorfish.domain.entities.gear.Gear @@ -68,6 +69,8 @@ class GetVesselControlsUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), MissionAction( @@ -82,6 +85,8 @@ class GetVesselControlsUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), MissionAction( @@ -96,6 +101,8 @@ class GetVesselControlsUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt index b0b0cb389b..71a620b572 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt @@ -3,6 +3,7 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Completion import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType +import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable @@ -37,6 +38,8 @@ class UpdateMissionActionUTests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/TestUtils.kt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt similarity index 83% rename from backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt rename to backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt index 40dae28bd1..0e2edd30ab 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt @@ -28,14 +28,13 @@ import org.springframework.context.annotation.Import import org.springframework.http.MediaType import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.* -import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath -import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* import java.time.ZonedDateTime @Import(SentryConfig::class) @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(MissionActionsController::class)]) -class PublicMissionActionsControllerITests { +class MissionActionsControllerITests { @Autowired private lateinit var api: MockMvc @@ -86,6 +85,8 @@ class PublicMissionActionsControllerITests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = true, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), ), @@ -121,6 +122,8 @@ class PublicMissionActionsControllerITests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = true, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), ), @@ -182,6 +185,8 @@ class PublicMissionActionsControllerITests { isComplianceWithWaterRegulationsControl = true, isSafetyEquipmentAndStandardsComplianceControl = true, isSeafarersControl = true, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), ), @@ -216,7 +221,7 @@ class PublicMissionActionsControllerITests { fun `Should update a mission action`() { // Given val dateTime = ZonedDateTime.parse("2022-05-05T03:04:05.000Z") - val newMission = TestUtils.getDummyMissionAction(dateTime) + val newMission = TestUtils.getDummyMissionAction(dateTime).copy(flagState = CountryCode.UNDEFINED) given(updateMissionAction.execute(any(), any())).willReturn(newMission) val gearControl = GearControl() @@ -259,6 +264,8 @@ class PublicMissionActionsControllerITests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = true, + flagState = CountryCode.UNDEFINED, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), ), @@ -269,6 +276,7 @@ class PublicMissionActionsControllerITests { .andExpect(status().isCreated) .andExpect(jsonPath("$.missionId", equalTo(2))) .andExpect(jsonPath("$.vesselId", equalTo(2))) + .andExpect(jsonPath("$.flagState", equalTo("UNDEFINED"))) .andExpect(jsonPath("$.isFromPoseidon", equalTo(true))) .andExpect(jsonPath("$.actionDatetimeUtc", equalTo("2022-05-05T03:04:05Z"))) .andExpect(jsonPath("$.faoAreas[0]", equalTo("25.6.9"))) @@ -289,6 +297,36 @@ class PublicMissionActionsControllerITests { } } + @Test + fun `Should not update a mission action with a missing flagState`() { + // When + api.perform( + put("/bff/v1/mission_actions/123") + .content( + """ + { + "id": 3540, + "vesselId": 1778775, + "vesselName": "TEST", + "internalReferenceNumber": "FRA000936666", + "externalReferenceNumber": "SEGESGES", + "ircs": "FEFGEGSGE", + "flagState": null", + "districtCode": "AD", + "faoAreas": [], + "flightGoals": [], + "missionId": 10556, + "actionType": "LAND_CONTROL", + "actionDatetimeUtc": "2024-02-01T14:29:00Z", + } + """.trimIndent(), + ) + .contentType(MediaType.APPLICATION_JSON), + ) + // Then + .andExpect(status().isBadRequest) + } + @Test fun `Should delete a mission action`() { // When @@ -303,33 +341,33 @@ class PublicMissionActionsControllerITests { fun `Should get all activity reports for a given date range and JDP`() { // Given given(getActivityReports.execute(any(), any(), any())).willReturn( - ActivityReports( - activityReports = listOf( - ActivityReport( - action = MissionAction( - 1, - 1, - 1, - actionType = MissionActionType.SEA_CONTROL, - actionDatetimeUtc = ZonedDateTime.now(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = true, - completion = Completion.TO_COMPLETE, - ), - activityCode = ActivityCode.FIS, - vesselNationalIdentifier = "AYFR000654", - controlUnits = listOf(ControlUnit(1234, "DIRM", false, "Cross Etel", listOf())), - vessel = Vessel( - id = 1, - internalReferenceNumber = "FR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - ), + listOf( + ActivityReport( + action = MissionAction( + 1, + 1, + 1, + actionType = MissionActionType.SEA_CONTROL, + actionDatetimeUtc = ZonedDateTime.now(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = true, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + activityCode = ActivityCode.FIS, + vesselNationalIdentifier = "AYFR000654", + controlUnits = listOf(ControlUnit(1234, "DIRM", false, "Cross Etel", listOf())), + vessel = Vessel( + id = 1, + internalReferenceNumber = "FR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", ), ), jdpSpecies = listOf("BSS", "MAK", "LTH"), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt index e31f11a9d4..7650aafde6 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt @@ -1,6 +1,7 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.bff import com.nhaarman.mockitokotlin2.any +import com.neovisionaries.i18n.CountryCode import com.nhaarman.mockitokotlin2.anyOrNull import com.nhaarman.mockitokotlin2.given import fr.gouv.cnsp.monitorfish.config.SentryConfig @@ -80,6 +81,8 @@ class MissionsControllerITests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), ), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt index 55e161e084..aed5923c0e 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.public_api +import com.neovisionaries.i18n.CountryCode import com.nhaarman.mockitokotlin2.any import fr.gouv.cnsp.monitorfish.config.SentryConfig import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Completion @@ -50,6 +51,8 @@ class PublicMissionActionsControllerITests { hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isFromPoseidon = true, + flagState = CountryCode.FR, + userTrigram = "LTH", completion = Completion.TO_COMPLETE, ), ), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt index 950c3bc830..1c1bf75e74 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.repositories +import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.TestUtils.getDummyMissionAction import org.assertj.core.api.Assertions.assertThat @@ -216,7 +217,7 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { facade = "Sud Océan Indien", faoAreas = listOf(), feedbackSheetRequired = false, - flagState = "FR", + flagState = CountryCode.FR, flightGoals = listOf(), gearInfractions = listOf(), gearOnboard = listOf(), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt index 75bafc76e6..eaf34ddaf6 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.repositories +import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Completion import java.time.ZonedDateTime @@ -14,7 +15,7 @@ object TestUtils { internalReferenceNumber = "FR0564654", externalReferenceNumber = "FDEY874", ircs = "FDZFEE", - flagState = "FR", + flagState = CountryCode.FR, actionType = MissionActionType.SEA_CONTROL, flightGoals = listOf( FlightGoal.CLOSED_AREA, diff --git a/frontend/cypress/e2e/side_window/mission_form/sea_control.spec.ts b/frontend/cypress/e2e/side_window/mission_form/sea_control.spec.ts index 67200d99d4..4ba73777f0 100644 --- a/frontend/cypress/e2e/side_window/mission_form/sea_control.spec.ts +++ b/frontend/cypress/e2e/side_window/mission_form/sea_control.spec.ts @@ -42,7 +42,7 @@ context('Side Window > Mission Form > Sea Control', () => { { body: { externalReferenceNumber: 'UNKNOWN', - flagState: 'UNKNOWN', + flagState: 'UNDEFINED', internalReferenceNumber: 'UNKNOWN', ircs: 'UNKNOWN', vesselId: -1, diff --git a/frontend/src/domain/entities/vessel/vessel.ts b/frontend/src/domain/entities/vessel/vessel.ts index ae30ff1a72..fb0c3c4ec9 100644 --- a/frontend/src/domain/entities/vessel/vessel.ts +++ b/frontend/src/domain/entities/vessel/vessel.ts @@ -277,7 +277,7 @@ export enum FishingActivitiesTab { */ export const UNKNOWN_VESSEL: VesselIdentity = { externalReferenceNumber: 'UNKNOWN', - flagState: 'UNKNOWN', + flagState: 'UNDEFINED', internalReferenceNumber: 'UNKNOWN', ircs: 'UNKNOWN', vesselId: -1, diff --git a/frontend/src/domain/shared_slices/Vessel.ts b/frontend/src/domain/shared_slices/Vessel.ts index 18cd4cc53e..da9f6f1f86 100644 --- a/frontend/src/domain/shared_slices/Vessel.ts +++ b/frontend/src/domain/shared_slices/Vessel.ts @@ -542,7 +542,7 @@ const vesselSlice = createSlice({ vesselFeatureId: Vessel.getVesselFeatureId(vessel), vesselProperties: { ...vessel, - flagState: vessel.flagState?.toLowerCase(), + flagState: vessel.flagState, fleetSegmentsArray: vessel.segments ? vessel.segments.map(segment => segment.replace(' ', '')) : [], gearsArray: vessel.gearOnboard ? Array.from(new Set(vessel.gearOnboard.map(gear => gear.gear))) : [], hasAlert: !!vessel.alerts?.length, diff --git a/frontend/src/features/VesselList/index.tsx b/frontend/src/features/VesselList/index.tsx index 472b98f19d..14f93ee666 100644 --- a/frontend/src/features/VesselList/index.tsx +++ b/frontend/src/features/VesselList/index.tsx @@ -178,7 +178,14 @@ export function VesselList({ namespace }) { } setTimeout(() => { dispatch(getFilteredVessels(checkedVessels, filters)).then(_filteredVessels => { - setFilteredVessels(_filteredVessels) + const nextVessels = _filteredVessels.map(vessel => ({ + ...vessel, + vesselProperties: { + ...vessel.vesselProperties, + flagState: vessel.vesselProperties.flagState.toLowerCase() + } + })) + setFilteredVessels(nextVessels) setVesselsCountShowed(_filteredVessels.length) }) }, 0) From c43c95260298cf93678e60b3f13dd0d0f2776b6e Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Fri, 26 Apr 2024 10:06:34 +0200 Subject: [PATCH 02/14] FIx migrations --- .../mission/mission_actions/MissionAction.kt | 4 ++ .../actrep/JointDeploymentPlan.kt | 4 +- .../mission/mission_actions/actrep/species.kt | 4 +- ...0.253.1__Update_mission_actions_table.sql} | 0 ...0__Insert_dummy_actions_for_migration.sql} | 2 +- .../mission_actions/MissionActionUTests.kt | 4 +- .../actrep/JointDeploymentPlanUTests.kt | 11 ++-- .../domain/use_cases/mission/TestUtils.kt | 3 + .../UpdateMissionActionUTests.kt | 2 +- .../api/bff/MissionActionsControllerITests.kt | 56 ++++++++++--------- .../api/bff/MissionsControllerITests.kt | 4 +- 11 files changed, 55 insertions(+), 39 deletions(-) rename backend/src/main/resources/db/migration/internal/{V0.244.1__Update_mission_actions_table.sql => V0.253.1__Update_mission_actions_table.sql} (100%) rename backend/src/main/resources/db/testdata/{V0.244.0__Insert_dummy_actions_for_migration.sql => V0.253.0__Insert_dummy_actions_for_migration.sql} (99%) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt index 97e6754c51..cc7ac93ab5 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt @@ -77,6 +77,10 @@ data class MissionAction( "A control must specify a vessel: the `vesselId` must be given." } + require(this.userTrigram.isNotEmpty()) { + "A control must specify a user trigram: the `userTrigram` must be given." + } + when (this.actionType) { MissionActionType.AIR_CONTROL -> checkControlPosition() MissionActionType.SEA_CONTROL -> checkControlPosition() diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlan.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlan.kt index 17ce37f7dd..79545d1407 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlan.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlan.kt @@ -1,5 +1,7 @@ package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep +import com.neovisionaries.i18n.CountryCode + enum class JointDeploymentPlan(private val species: List) { MEDITERRANEAN_AND_EASTERN_ATLANTIC(MEDITERRANEAN_AND_EASTERN_ATLANTIC_SPECIES), NORTH_SEA(NORTH_SEA_SPECIES), @@ -18,7 +20,7 @@ enum class JointDeploymentPlan(private val species: List) { * See "DÉCISION D’EXÉCUTION (UE) 2023/2376 DE LA COMMISSION": * https://extranet.legipeche.metier.developpement-durable.gouv.fr/fichier/pdf/oj_l_202302376_fr_txt_cle6b198e.pdf?arg=24774&cle=7d14626b709ff7e8c62586bcd8683e7e9fcaa348&file=pdf%2Foj_l_202302376_fr_txt_cle6b198e.pdf */ - fun isLandControlApplicable(flagState: String?, speciesOnboardCodes: List, tripFaoCodes: List): Boolean { + fun isLandControlApplicable(flagState: CountryCode, speciesOnboardCodes: List, tripFaoCodes: List): Boolean { val isThirdCountryVessel = EU_THIRD_COUNTRIES.contains(flagState) val hasSpeciesInJdp = this.species.any { (jdpFaoZones, jdpSpecy) -> diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/species.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/species.kt index 67308060d8..13945bb2d6 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/species.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/species.kt @@ -1,5 +1,7 @@ package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep +import com.neovisionaries.i18n.CountryCode + typealias FaoZones = List typealias FaoZonesAndSpecy = Pair @@ -156,7 +158,7 @@ val WESTERN_WATERS_SPECIES: List = listOf( ), ) -val EU_THIRD_COUNTRIES = listOf("GB") +val EU_THIRD_COUNTRIES = listOf(CountryCode.GB) /** * See species detailed in p.26 ("CARTES DES ESPÈCES SOUMISES A QUOTAS") diff --git a/backend/src/main/resources/db/migration/internal/V0.244.1__Update_mission_actions_table.sql b/backend/src/main/resources/db/migration/internal/V0.253.1__Update_mission_actions_table.sql similarity index 100% rename from backend/src/main/resources/db/migration/internal/V0.244.1__Update_mission_actions_table.sql rename to backend/src/main/resources/db/migration/internal/V0.253.1__Update_mission_actions_table.sql diff --git a/backend/src/main/resources/db/testdata/V0.244.0__Insert_dummy_actions_for_migration.sql b/backend/src/main/resources/db/testdata/V0.253.0__Insert_dummy_actions_for_migration.sql similarity index 99% rename from backend/src/main/resources/db/testdata/V0.244.0__Insert_dummy_actions_for_migration.sql rename to backend/src/main/resources/db/testdata/V0.253.0__Insert_dummy_actions_for_migration.sql index cccf3a0600..63fcbb1c23 100644 --- a/backend/src/main/resources/db/testdata/V0.244.0__Insert_dummy_actions_for_migration.sql +++ b/backend/src/main/resources/db/testdata/V0.253.0__Insert_dummy_actions_for_migration.sql @@ -1,5 +1,5 @@ INSERT INTO mission_actions ( - vessel_id, cfr, vessel_name, flag_state, mission_id, action_type, action_datetime_utc, has_some_gears_seized, has_some_species_seized, facade, longitude, latitude, port_locode, vessel_targeted, seizure_and_diversion, seizure_and_diversion_comments, other_comments, closed_by, gear_onboard, gear_infractions, species_onboard, species_infractions, species_observations, other_infractions, fao_areas, segments, emits_vms, emits_ais, logbook_matches_activity, licences_match_activity, species_weight_controlled, species_size_controlled, separate_stowage_of_preserved_species, logbook_infractions, licences_and_logbook_observations, number_of_vessels_flown_over, unit_without_omega_gauge, control_quality_comments, feedback_sheet_required, is_from_poseidon, user_trigram, is_deleted) + vessel_id, cfr, vessel_name, flag_state, mission_id, action_type, action_datetime_utc, has_some_gears_seized, has_some_species_seized, facade, longitude, latitude, port_locode, vessel_targeted, seizure_and_diversion, seizure_and_diversion_comments, other_comments,completed_by, gear_onboard, gear_infractions, species_onboard, species_infractions, species_observations, other_infractions, fao_areas, segments, emits_vms, emits_ais, logbook_matches_activity, licences_match_activity, species_weight_controlled, species_size_controlled, separate_stowage_of_preserved_species, logbook_infractions, licences_and_logbook_observations, number_of_vessels_flown_over, unit_without_omega_gauge, control_quality_comments, feedback_sheet_required, is_from_poseidon, user_trigram, is_deleted) VALUES ( 1, 'FAK000999999', 'PHENOMENE', 'gb', 1, 'SEA_CONTROL', NOW() - ('1 YEAR')::interval, FALSE, FALSE, 'NAMO', -8.52, 51.58, NULL, 'YES', False, NULL, 'Commentaires post contrôle', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '{27.7.c}', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, true, 'ABC', false), ( 1, 'FAK000999999', 'PHENOMENE', 'gb', 2, 'SEA_CONTROL', NOW(), FALSE, TRUE, 'NAMO', -0.52, 47.44, NULL, 'NO', True, 'Saisie de la pêche', 'Commentaires post contrôle', 'XYZ', '[{"gearCode": "OTB", "gearName": "Chaluts de fond à panneaux", "declaredMesh": 60.0, "controlledMesh": null, "hasUncontrolledMesh": true, "gearWasControlled": false}, {"gearCode": "OTM", "gearName": "Chaluts pélagiques à panneaux", "declaredMesh": 60.0, "controlledMesh": 52.8, "hasUncontrolledMesh": false, "gearWasControlled": true}]', '[{"infractionType": "WITH_RECORD", "natinf": 23581, "comments": "Maille trop petite"}, {"infractionType": "PENDING", "natinf": 27724, "comments": "Engin non conforme"}]', '[{"speciesCode": "MNZ", "declaredWeight": 302.5, "controlledWeight": 450, "underSized": true}, {"speciesCode": "CRF", "declaredWeight": 40, "controlledWeight": 40, "underSized": false}]', '[{"infractionType": "WITHOUT_RECORD", "natinf": 28346, "comments": "Sous taille de 8cm"}]', 'Saisie de l''ensemble des captures à bord', '[{"infractionType": "WITH_RECORD", "natinf": 23588, "comments": "Chalutage répété dans les 3 milles sur Piste VMS - confirmé de visu"}, {"infractionType": "PENDING", "natinf": 23584, "comments": "Absence d''équipement AIS à bord"}]', '{27.7.d,27.7.e}', '[{"segment": "SWW04", "segmentName": "Midwater trawls", "faoAreas": ["27.8c", "27.8"]}, {"segment": "PEL03", "segmentName": "Polyvalent - Bottom trawl", "faoAreas": ["27.3.a", "27.7", "27.8", "27.9"]}]', 'YES', 'NOT_APPLICABLE', 'NO', 'NO', true, true, 'YES', '[{"infractionType": "WITH_RECORD", "natinf": 27689, "comments": "Poids à bord MNZ supérieur de 50% au poids déclaré"}]', 'C''est pas très très bien réglo toute cette poissecalle non déclarée', NULL, false, 'Ciblage CNSP non respecté', true, false, 'DEF', false), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt index a3281c001c..9f598c0ce1 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt @@ -56,14 +56,14 @@ class MissionActionUTests { gearOnboard = listOf(), seizureAndDiversion = true, isDeleted = false, - userTrigram = null, + userTrigram = "", hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, completedBy = "XYZ", isFromPoseidon = false, completion = Completion.TO_COMPLETE, flagState = CountryCode.FR, - ) + ) // When val throwable = catchThrowable { action.verify() } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlanUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlanUTests.kt index cc4e11540a..00d9661086 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlanUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlanUTests.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep +import com.neovisionaries.i18n.CountryCode import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -15,7 +16,7 @@ class JointDeploymentPlanUTests { val species = listOf("HKE", "ANN", "BOR") // When - val isLandControlConcerned = jdp.isLandControlApplicable("FR", species, faoCodes) + val isLandControlConcerned = jdp.isLandControlApplicable(CountryCode.FR, species, faoCodes) // Then assertThat(isLandControlConcerned).isTrue() @@ -30,7 +31,7 @@ class JointDeploymentPlanUTests { val species = listOf("ANN", "BOR") // When - val isLandControlConcerned = jdp.isLandControlApplicable("FR", species, faoCodes) + val isLandControlConcerned = jdp.isLandControlApplicable(CountryCode.FR, species, faoCodes) // Then assertThat(isLandControlConcerned).isFalse() @@ -45,7 +46,7 @@ class JointDeploymentPlanUTests { val species = listOf("HKE", "ANN", "BOR") // When - val isLandControlConcerned = jdp.isLandControlApplicable("FR", species, faoCodes) + val isLandControlConcerned = jdp.isLandControlApplicable(CountryCode.FR, species, faoCodes) // Then assertThat(isLandControlConcerned).isFalse() @@ -60,7 +61,7 @@ class JointDeploymentPlanUTests { val species = listOf("HKE", "ANN", "BOR", "ALB") // When - val isLandControlConcerned = jdp.isLandControlApplicable("GB", species, faoCodes) + val isLandControlConcerned = jdp.isLandControlApplicable(CountryCode.GB, species, faoCodes) // Then assertThat(isLandControlConcerned).isTrue() @@ -74,7 +75,7 @@ class JointDeploymentPlanUTests { val species = listOf("HKE", "ANN", "BOR") // When - val isLandControlConcerned = jdp.isLandControlApplicable("GB", species, faoCodes) + val isLandControlConcerned = jdp.isLandControlApplicable(CountryCode.GB, species, faoCodes) // Then assertThat(isLandControlConcerned).isFalse() diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/TestUtils.kt index 9d3a75a6cb..b66cce8974 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/TestUtils.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.mission +import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.mission.Mission import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionSource import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionType @@ -41,6 +42,8 @@ object TestUtils { hasSomeSpeciesSeized = false, isFromPoseidon = false, completion = Completion.TO_COMPLETE, + userTrigram = "LTH", + flagState = CountryCode.FR, ) } }.flatten() diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt index 71a620b572..556394edeb 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt @@ -1,9 +1,9 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions +import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Completion import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType -import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt index 0e2edd30ab..c1f4c1bfd1 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt @@ -341,33 +341,35 @@ class MissionActionsControllerITests { fun `Should get all activity reports for a given date range and JDP`() { // Given given(getActivityReports.execute(any(), any(), any())).willReturn( - listOf( - ActivityReport( - action = MissionAction( - 1, - 1, - 1, - actionType = MissionActionType.SEA_CONTROL, - actionDatetimeUtc = ZonedDateTime.now(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = true, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - activityCode = ActivityCode.FIS, - vesselNationalIdentifier = "AYFR000654", - controlUnits = listOf(ControlUnit(1234, "DIRM", false, "Cross Etel", listOf())), - vessel = Vessel( - id = 1, - internalReferenceNumber = "FR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", + ActivityReports( + activityReports = listOf( + ActivityReport( + action = MissionAction( + 1, + 1, + 1, + actionType = MissionActionType.SEA_CONTROL, + actionDatetimeUtc = ZonedDateTime.now(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = true, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + activityCode = ActivityCode.FIS, + vesselNationalIdentifier = "AYFR000654", + controlUnits = listOf(ControlUnit(1234, "DIRM", false, "Cross Etel", listOf())), + vessel = Vessel( + id = 1, + internalReferenceNumber = "FR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + ), ), ), jdpSpecies = listOf("BSS", "MAK", "LTH"), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt index 7650aafde6..3c5dd459d3 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt @@ -1,7 +1,7 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.bff -import com.nhaarman.mockitokotlin2.any import com.neovisionaries.i18n.CountryCode +import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.anyOrNull import com.nhaarman.mockitokotlin2.given import fr.gouv.cnsp.monitorfish.config.SentryConfig @@ -153,6 +153,8 @@ class MissionsControllerITests { hasSomeSpeciesSeized = false, isFromPoseidon = false, completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", ), ), ), From c486e55ce0f00ff85f08d55b17c34960f2139e33 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Fri, 26 Apr 2024 10:38:57 +0200 Subject: [PATCH 03/14] Add country code to prior notifications --- .../api/outputs/PriorNotificationDataOutput.kt | 5 +++-- frontend/src/components/CountryFlag/index.tsx | 14 +++----------- frontend/src/components/CountryFlag/utils.ts | 4 ++++ .../LogbookMessages/messages/LogbookMessage.tsx | 1 + 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt index 6329e81919..64189b82a0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs +import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.facade.Seafront import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookOperationType import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotification @@ -29,7 +30,7 @@ data class PriorNotificationDataOutput( val types: List, val vesselId: Int?, val vesselExternalReferenceNumber: String?, - val vesselFlagCountryCode: String?, + val vesselFlagCountryCode: CountryCode, val vesselInternalReferenceNumber: String?, val vesselIrcs: String?, val vesselLastControlDate: String?, @@ -85,7 +86,7 @@ data class PriorNotificationDataOutput( types, vesselId = priorNotification.vessel.id, vesselExternalReferenceNumber = priorNotification.vessel.externalReferenceNumber, - vesselFlagCountryCode = priorNotification.vessel.flagState.toString(), + vesselFlagCountryCode = priorNotification.vessel.flagState, vesselInternalReferenceNumber = priorNotification.vessel.internalReferenceNumber, vesselIrcs = priorNotification.vessel.ircs, vesselLastControlDate = priorNotification.vesselRiskFactor?.lastControlDatetime?.toString(), diff --git a/frontend/src/components/CountryFlag/index.tsx b/frontend/src/components/CountryFlag/index.tsx index 54262ff6e5..3e335c699d 100644 --- a/frontend/src/components/CountryFlag/index.tsx +++ b/frontend/src/components/CountryFlag/index.tsx @@ -5,6 +5,8 @@ import { getAlpha2CodeFromAlpha2or3Code } from './utils' import type { CSSProperties } from 'react' +const MIN_DEFAULT_WIDTH = 24 + type CountryFlagProps = Readonly<{ className?: string | undefined countryCode: string | undefined @@ -18,7 +20,7 @@ export function CountryFlag({ countryCode, size, ...nativeProps }: CountryFlagPr const url = countryAlpha2Code ? `${window.location.origin}/flags/${countryAlpha2Code}.svg` - : `https://placehold.co/${width}x${height}?text=%3F` + : `https://placehold.co/${width < MIN_DEFAULT_WIDTH ? MIN_DEFAULT_WIDTH : width}x${height}?text=%3F` if (!countryAlpha2Code || countryAlpha2Code === 'undefined') { return @@ -36,13 +38,3 @@ const Img = styled.img<{ height: ${p => p.$height}px; width: ${p => p.$width}px; ` - -const Unknown = styled.span<{ - $height: number - $width: number -}>` - background-color: black; - display: inline-block; - height: ${p => p.$height}px; - width: ${p => p.$width}px; -` diff --git a/frontend/src/components/CountryFlag/utils.ts b/frontend/src/components/CountryFlag/utils.ts index be3d885c0b..6b144b3cc8 100644 --- a/frontend/src/components/CountryFlag/utils.ts +++ b/frontend/src/components/CountryFlag/utils.ts @@ -5,6 +5,10 @@ export function getAlpha2CodeFromAlpha2or3Code(countryCode: string | undefined): return undefined } + if (countryCode === 'UNDEFINED') { + return undefined + } + try { return (countryCode.length === 3 ? countries.alpha3ToAlpha2(countryCode) : countryCode).toLowerCase() } catch (err) { diff --git a/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/LogbookMessage.tsx b/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/LogbookMessage.tsx index 8ca874a336..04e079fbfc 100644 --- a/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/LogbookMessage.tsx +++ b/frontend/src/features/Logbook/components/VesselLogbook/LogbookMessages/messages/LogbookMessage.tsx @@ -251,6 +251,7 @@ const VoyageNumber = styled(BodyHeaderBlock)` ` const Acknowledge = styled(BodyHeaderBlock)` flex-grow: 4; + width: 25px; margin-left: 10px; ` From 0c46a4db5c97f5b58c843eb3ea61420337ed5383 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 24 May 2024 15:01:48 +0200 Subject: [PATCH 04/14] Renumber migrations --- ...tions_table.sql => V0.254.1__Update_mission_actions_table.sql} | 0 ...ation.sql => V0.254.0__Insert_dummy_actions_for_migration.sql} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename backend/src/main/resources/db/migration/internal/{V0.253.1__Update_mission_actions_table.sql => V0.254.1__Update_mission_actions_table.sql} (100%) rename backend/src/main/resources/db/testdata/{V0.253.0__Insert_dummy_actions_for_migration.sql => V0.254.0__Insert_dummy_actions_for_migration.sql} (100%) diff --git a/backend/src/main/resources/db/migration/internal/V0.253.1__Update_mission_actions_table.sql b/backend/src/main/resources/db/migration/internal/V0.254.1__Update_mission_actions_table.sql similarity index 100% rename from backend/src/main/resources/db/migration/internal/V0.253.1__Update_mission_actions_table.sql rename to backend/src/main/resources/db/migration/internal/V0.254.1__Update_mission_actions_table.sql diff --git a/backend/src/main/resources/db/testdata/V0.253.0__Insert_dummy_actions_for_migration.sql b/backend/src/main/resources/db/testdata/V0.254.0__Insert_dummy_actions_for_migration.sql similarity index 100% rename from backend/src/main/resources/db/testdata/V0.253.0__Insert_dummy_actions_for_migration.sql rename to backend/src/main/resources/db/testdata/V0.254.0__Insert_dummy_actions_for_migration.sql From 0d19f4a43f234d4b59295e4ec5ff9375ced68416 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 24 May 2024 15:04:57 +0200 Subject: [PATCH 05/14] Rewrite migration --- .../V0.254.1__Update_mission_actions_table.sql | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/backend/src/main/resources/db/migration/internal/V0.254.1__Update_mission_actions_table.sql b/backend/src/main/resources/db/migration/internal/V0.254.1__Update_mission_actions_table.sql index 982370aa41..b7cd766e87 100644 --- a/backend/src/main/resources/db/migration/internal/V0.254.1__Update_mission_actions_table.sql +++ b/backend/src/main/resources/db/migration/internal/V0.254.1__Update_mission_actions_table.sql @@ -3,15 +3,9 @@ ALTER COLUMN user_trigram SET NOT NULL; UPDATE mission_actions SET flag_state = 'UNDEFINED' -WHERE flag_state = 'UNKNOWN'; - -UPDATE mission_actions -SET flag_state = 'UNDEFINED' -WHERE flag_state = 'X'; - -UPDATE mission_actions -SET flag_state = 'UNDEFINED' -WHERE flag_state IS NULL; +WHERE + flag_state IS NULL + OR flag_state IN ('UNKNOWN', 'X'); UPDATE mission_actions SET flag_state = upper(flag_state); From 2f8bc12bd6059050569ed9e7b382865ab654af26 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 24 May 2024 15:30:06 +0200 Subject: [PATCH 06/14] Update test data --- .../V666.14__Reset_test_actions.sql | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/datascience/tests/test_data/remote_database/V666.14__Reset_test_actions.sql b/datascience/tests/test_data/remote_database/V666.14__Reset_test_actions.sql index 4b2de1d418..685eed0fc2 100644 --- a/datascience/tests/test_data/remote_database/V666.14__Reset_test_actions.sql +++ b/datascience/tests/test_data/remote_database/V666.14__Reset_test_actions.sql @@ -1,29 +1,29 @@ DELETE FROM mission_actions; INSERT INTO mission_actions -( id, vessel_id, mission_id, action_type, action_datetime_utc, facade, longitude, latitude, port_locode, seizure_and_diversion, seizure_and_diversion_comments, other_comments, gear_onboard, gear_infractions, has_some_gears_seized, species_onboard, species_infractions, has_some_species_seized, species_observations, segments, other_infractions, fao_areas, is_from_poseidon, is_deleted) VALUES -(-199999, 483, -199999, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '3 months 1 day', NULL, 53.12, 6.85, NULL, true, NULL, 'Contrôle Poséidon à ne pas mettre à jour', '[]', '[]', false, '[]', '[]', false, NULL, '[]', '[]', '{}', true, false), -(-144762, 483, -144762, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '3 months', NULL, 53.12, 6.85, NULL, true, NULL, 'Contrôle Poséidon à mettre à jour', '[]', '[]', false, '[]', '[]', false, NULL, '[]', '[]', '{}', true, false), -( 1, 1, 1, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '3 weeks', 'SA', -1.566, 46, NULL, false, NULL, 'OTB 70MM DÉCLARÉ - signaux pyrotechniques périmés', '[{"gearCode": "OTB", "declaredMesh": 71.0, "controlledMesh": null, "gearWasControlled": true, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 125.0, "controlledWeight": 125.0, "speciesCode": "BSS", "underSized": false}, {"declaredWeight": 65.0, "controlledWeight": 65.0, "speciesCode": "MGR", "underSized": false}, {"declaredWeight": 60.0, "controlledWeight": 60.0, "speciesCode": "OMZ", "underSized": false}, {"declaredWeight": 5.0, "controlledWeight": 5.0, "speciesCode": "MUL", "underSized": false}, {"declaredWeight": 5.0, "controlledWeight": 5.0, "speciesCode": "SOL", "underSized": false}, {"declaredWeight": 15.0, "controlledWeight": 15.0, "speciesCode": "COE", "underSized": false}]', '[{"comments": "Infraction espèces 1", "natinf": 17}, {"natinf": 1030}, {"natinf": 1031}]', false, NULL, '[{"segment": "SWW01/02/03", "segmentName": "Sud Ouest 1 2 3"}]', '[{"infractionType": "WITH_RECORD", "natinf": 22206, "comments": "Infraction 1"}]', '{27.8.a}', false, false), -( 2, 1, 2, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 years 1 month', 'MED', 3.1833, 42.5167, NULL, false, NULL, 'GTR 50 mm maille carrée déclaré', '[{"gearCode": "GTR", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 2.0, "controlledWeight": 2.0, "speciesCode": "SOL", "underSized": false}, {"declaredWeight": 5.0, "controlledWeight": 5.0, "speciesCode": "ANF", "underSized": false}]', '[]', false, NULL, '[{"segment": "MED07", "segmentName": "Méditerranée 7"}]', '[{"infractionType": "WITH_RECORD", "natinf": 22182, "comments": "Infraction 2"}]', '{37.1.2}', false, false), -( 3, 1, 3, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 years 6 months', 'MED', 5.3666, 43.1833, NULL, true, NULL, 'LLS - pas de pêche à bord', '[{"gearCode": "LLS", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, 'null', '[]', false, 'Pas d''espèces à bord', '[{"segment": "MED05", "segmentName": "Méditerranée 5"}]', '[{"infractionType": "WITH_RECORD", "natinf": 20233, "comments": "Infraction 3"}]', '{37.1.2}', false, false), -( 4, 1, 4, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 years 3 months', 'MEMN', -1.8832, 48.8832, NULL, false, NULL, 'FPO - 300 KG WHE PERMIS NAV ECHU', '[{"gearCode": "FPO", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 300.0, "controlledWeight": 300.0, "speciesCode": "WHE", "underSized": false}]', '[]', false, NULL, '[]', 'null', '{27.7.e}', false, false), -( 5, 1, 5, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '5 years 3 months', 'SA', -2.6667, 44.6499, NULL, true, 'APPREHENSION NAVIRE + PECHE', 'NAVIRE SURVOLE EN TRAIN DE PROCEDER A UN TRANSBORDEMENT ILLICITE', '[{"gearCode": "PS", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 1.0, "controlledWeight": 1.0, "speciesCode": "ANE", "underSized": false}]', '[]', false, NULL, '[{"segment": "PEL05", "segmentName": "Pélagique 5"}]', '[{"infractionType": "WITH_RECORD", "natinf": 27717, "comments": "Infraction 5"}]', '{27.8.b}', false, false), -( 6, 1, 6, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '9 months', 'MEMN', NULL, NULL, 'FRCQF', true, 'PECHE PLUS ENGIN NON CONFORME', 'GTR 90MM DECLARE CONTROLE 92 ET 88.2', '[{"gearCode": "GTR", "declaredMesh": 92.0, "controlledMesh": null, "gearWasControlled": true, "hasUncontrollerMesh": true}, {"gearCode": "GTR", "declaredMesh": 88.2, "controlledMesh": null, "gearWasControlled": true, "hasUncontrollerMesh": true}]', '[{"infractionType": "WITHOUT_RECORD", "comments": "Infraction engin", "natinf": 27724}]', true, '[{"declaredWeight": 240.0, "controlledWeight": 240.0, "speciesCode": "SOL", "underSized": false}, {"declaredWeight": 40.0, "controlledWeight": 40.0, "speciesCode": "PLE", "underSized": false}]', '[]', false, NULL, '[{"segment": "NS13"}, {"segment": "NWW08", "segmentName": "Nord Ouest 8"}]', '[{"natinf": 2606}, {"natinf": 4761}, {"natinf": 22206}]', '{27.7.d,27.4.c}', false, false), -( 7, 1, 7, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '4 years 3 months', 'NAMO', NULL, NULL, 'FRBES', false, NULL, 'NON DECLARATION DE 460KG DE SCE', '[{"gearCode": "OTB", "declaredMesh": 80.0, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 6738.0, "controlledWeight": 6738.0, "speciesCode": "ANF", "underSized": false}, {"declaredWeight": 75.0, "controlledWeight": 75.0, "speciesCode": "HKE", "underSized": false}, {"declaredWeight": 8260.0, "controlledWeight": 8260.0, "speciesCode": "LEZ", "underSized": false}, {"declaredWeight": 330.0, "controlledWeight": 330.0, "speciesCode": "JOD", "underSized": false}, {"declaredWeight": 15.0, "controlledWeight": 15.0, "speciesCode": "POL", "underSized": false}, {"declaredWeight": 1450.0, "controlledWeight": 1450.0, "speciesCode": "COE", "underSized": false}, {"declaredWeight": 168.0, "controlledWeight": 168.0, "speciesCode": "LIN", "underSized": false}, {"declaredWeight": 147.0, "controlledWeight": 147.0, "speciesCode": "OCM", "underSized": false}, {"declaredWeight": 360.0, "controlledWeight": 360.0, "speciesCode": "RJN", "underSized": false}, {"declaredWeight": 90.0, "controlledWeight": 90.0, "speciesCode": "RJO", "underSized": false}]', '[{"infractionType": "PENDING", "comments": "Infraction espèces 1", "natinf": 17}]', false, 'Sous taille', '[{"segment": "NWW01/02", "segmentName": "Nord Ouest 1 2"}, {"segment": "SWW01/02/03", "segmentName": "Sud Ouest 1 2 3"}]', NULL, '{27.8.a,27.7.h,27.7.e}', false, false), -( 8, 1, 8, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '3 years 3 months', 'MEMN', NULL, NULL, 'FRDPE', false, NULL, 'DRB 3550 SCE DECLARE SUR JPE', '[{"gearCode": "DRB", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 3700.0, "controlledWeight": 3700.0, "speciesCode": "SCE", "underSized": false}]', '[{"infractionType": "WITH_RECORD", "comments": "Infraction espèces 2", "natinf": 1030}]', true, NULL, '[{"segment": "FR_SCE", "segmentName": "Coquille"}]', '[]', '{27.7.d}', false, false), -( 9, 1, 9, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '6 years 3 months', 'MEMN', NULL, NULL, 'FRDKK', false, NULL, 'ENTRAVE AU CONTROLE ', '[{"gearCode": "GTR", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, 'null', '[]', false, NULL, '[]', '[{"infractionType": "WITH_RECORD", "natinf": 2606, "comments": "Infraction 6"}]', '{27.7.d,27.4.c}', false, true), -( 10, 2, 10, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 weeks', 'MEMN', NULL, NULL, 'FRLEH', true, 'APPREHNTION DE 1600 KG DE SCE', 'PECHE DE LA SCE EN ZONE 5 FERMEE - APPREHENTION DE 1600 KG DE SCE', '[{"gearCode": "DRB", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 1600.0, "controlledWeight": 1600.0, "speciesCode": "SCE", "underSized": false}]', '[]', false, NULL, '[{"segment": "FR_SCE", "segmentName": "Coquille"}]', '[{"infractionType": "WITH_RECORD", "natinf": 7061, "comments": "Infraction 7"}]', '{27.7.d}', false, false), -( 11, 2, 11, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '5 months', NULL, NULL, NULL, NULL, NULL, NULL, 'MGS22', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{}', false, false), -( 12, 2, 12, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 years 9 months', NULL, NULL, NULL, NULL, NULL, NULL, '9405 ANE', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{}', false, false), -( 13, 2, 13, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 3 months', NULL, NULL, NULL, NULL, NULL, NULL, 'ALB 2420', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{}', false, false), -( 14, 2, 14, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 4 months', NULL, NULL, NULL, NULL, NULL, NULL, 'ALB1470KG', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{}', false, false), -( 15, 2, 15, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 6 months', NULL, NULL, NULL, NULL, NULL, NULL, 'ENGIN NC- CTC 160/PLE 2/SOL 2', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{}', false, false), -( 16, 2, 16, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 8 months', 'SA', NULL, NULL, 'FRZJZ', NULL, NULL, '96 POISSONS 7544 KG', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b,27.8.c}', false, false), -( 17, 2, 17, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 9 months', 'SA', NULL, NULL, 'FRZJZ', NULL, NULL, '2 BFT 8-30 KG : POIDS 34.2KG - BON 8.6 K', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b,27.8.c}', false, false), -( 18, 2, 18, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 10 months', 'SA', NULL, NULL, 'FRZJZ', NULL, NULL, '2 BFT POUR 13.7KG - ENGIN NON CONTROLE', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b,27.8.c}', false, false), -( 19, 2, 19, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 11 months', 'SA', NULL, NULL, 'FRZJZ', NULL, NULL, '28 BFT 300KG', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b,27.8.c}', false, false), -( 20, 2, 20, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 years', 'SA', NULL, NULL, 'FRZJZ', NULL, NULL, '28 POISSONS 2368 KG', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b,27.8.c}', false, false), -( 21, 3, 21, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 week', 'SA', NULL, NULL, 'FRDKK', NULL, NULL, NULL, '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b}', false, false), -( 22, 4, 22, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 week 3 days', 'NAMO', NULL, NULL, 'FRZJZ', NULL, NULL, 'RAS', '[]', '[]', false, 'null', '[]', false, NULL, NULL, '[{"infractionType": "WITH_RECORD", "natinf": 7061, "comments": "Infraction 7"}]', '{27.8.c}', false, false), -( 23, 4, 22, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 week 2 days', 'NAMO', NULL, NULL, 'FRZJZ', NULL, NULL, 'RAS', '[]', '[]', false, 'null', '[]', false, NULL, 'null', '[]', '{27.8.c}', false, false); +( id, vessel_id, flag_state, mission_id, action_type, action_datetime_utc, facade, longitude, latitude, port_locode, seizure_and_diversion, seizure_and_diversion_comments, other_comments, gear_onboard, gear_infractions, has_some_gears_seized, species_onboard, species_infractions, has_some_species_seized, species_observations, segments, other_infractions, fao_areas, is_from_poseidon, is_deleted, user_trigram) VALUES +(-199999, 483, 'UNDEFINED', -199999, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '3 months 1 day', NULL, 53.12, 6.85, NULL, true, NULL, 'Contrôle Poséidon à ne pas mettre à jour', '[]', '[]', false, '[]', '[]', false, NULL, '[]', '[]', '{}', true, false, 'ABC'), +(-144762, 483, 'UNDEFINED', -144762, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '3 months', NULL, 53.12, 6.85, NULL, true, NULL, 'Contrôle Poséidon à mettre à jour', '[]', '[]', false, '[]', '[]', false, NULL, '[]', '[]', '{}', true, false, 'ABC'), +( 1, 1, 'FR', 1, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '3 weeks', 'SA', -1.566, 46, NULL, false, NULL, 'OTB 70MM DÉCLARÉ - signaux pyrotechniques périmés', '[{"gearCode": "OTB", "declaredMesh": 71.0, "controlledMesh": null, "gearWasControlled": true, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 125.0, "controlledWeight": 125.0, "speciesCode": "BSS", "underSized": false}, {"declaredWeight": 65.0, "controlledWeight": 65.0, "speciesCode": "MGR", "underSized": false}, {"declaredWeight": 60.0, "controlledWeight": 60.0, "speciesCode": "OMZ", "underSized": false}, {"declaredWeight": 5.0, "controlledWeight": 5.0, "speciesCode": "MUL", "underSized": false}, {"declaredWeight": 5.0, "controlledWeight": 5.0, "speciesCode": "SOL", "underSized": false}, {"declaredWeight": 15.0, "controlledWeight": 15.0, "speciesCode": "COE", "underSized": false}]', '[{"comments": "Infraction espèces 1", "natinf": 17}, {"natinf": 1030}, {"natinf": 1031}]', false, NULL, '[{"segment": "SWW01/02/03", "segmentName": "Sud Ouest 1 2 3"}]', '[{"infractionType": "WITH_RECORD", "natinf": 22206, "comments": "Infraction 1"}]', '{27.8.a}', false, false, 'ABC'), +( 2, 1, 'FR', 2, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 years 1 month', 'MED', 3.1833, 42.5167, NULL, false, NULL, 'GTR 50 mm maille carrée déclaré', '[{"gearCode": "GTR", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 2.0, "controlledWeight": 2.0, "speciesCode": "SOL", "underSized": false}, {"declaredWeight": 5.0, "controlledWeight": 5.0, "speciesCode": "ANF", "underSized": false}]', '[]', false, NULL, '[{"segment": "MED07", "segmentName": "Méditerranée 7"}]', '[{"infractionType": "WITH_RECORD", "natinf": 22182, "comments": "Infraction 2"}]', '{37.1.2}', false, false, 'ABC'), +( 3, 1, 'FR', 3, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 years 6 months', 'MED', 5.3666, 43.1833, NULL, true, NULL, 'LLS - pas de pêche à bord', '[{"gearCode": "LLS", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, 'null', '[]', false, 'Pas d''espèces à bord', '[{"segment": "MED05", "segmentName": "Méditerranée 5"}]', '[{"infractionType": "WITH_RECORD", "natinf": 20233, "comments": "Infraction 3"}]', '{37.1.2}', false, false, 'ABC'), +( 4, 1, 'FR', 4, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 years 3 months', 'MEMN', -1.8832, 48.8832, NULL, false, NULL, 'FPO - 300 KG WHE PERMIS NAV ECHU', '[{"gearCode": "FPO", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 300.0, "controlledWeight": 300.0, "speciesCode": "WHE", "underSized": false}]', '[]', false, NULL, '[]', 'null', '{27.7.e}', false, false, 'ABC'), +( 5, 1, 'FR', 5, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '5 years 3 months', 'SA', -2.6667, 44.6499, NULL, true, 'APPREHENSION NAVIRE + PECHE', 'NAVIRE SURVOLE EN TRAIN DE PROCEDER A UN TRANSBORDEMENT ILLICITE', '[{"gearCode": "PS", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 1.0, "controlledWeight": 1.0, "speciesCode": "ANE", "underSized": false}]', '[]', false, NULL, '[{"segment": "PEL05", "segmentName": "Pélagique 5"}]', '[{"infractionType": "WITH_RECORD", "natinf": 27717, "comments": "Infraction 5"}]', '{27.8.b}', false, false, 'ABC'), +( 6, 1, 'FR', 6, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '9 months', 'MEMN', NULL, NULL, 'FRCQF', true, 'PECHE PLUS ENGIN NON CONFORME', 'GTR 90MM DECLARE CONTROLE 92 ET 88.2', '[{"gearCode": "GTR", "declaredMesh": 92.0, "controlledMesh": null, "gearWasControlled": true, "hasUncontrollerMesh": true}, {"gearCode": "GTR", "declaredMesh": 88.2, "controlledMesh": null, "gearWasControlled": true, "hasUncontrollerMesh": true}]', '[{"infractionType": "WITHOUT_RECORD", "comments": "Infraction engin", "natinf": 27724}]', true, '[{"declaredWeight": 240.0, "controlledWeight": 240.0, "speciesCode": "SOL", "underSized": false}, {"declaredWeight": 40.0, "controlledWeight": 40.0, "speciesCode": "PLE", "underSized": false}]', '[]', false, NULL, '[{"segment": "NS13"}, {"segment": "NWW08", "segmentName": "Nord Ouest 8"}]', '[{"natinf": 2606}, {"natinf": 4761}, {"natinf": 22206}]', '{27.7.d,27.4.c}', false, false, 'ABC'), +( 7, 1, 'FR', 7, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '4 years 3 months', 'NAMO', NULL, NULL, 'FRBES', false, NULL, 'NON DECLARATION DE 460KG DE SCE', '[{"gearCode": "OTB", "declaredMesh": 80.0, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 6738.0, "controlledWeight": 6738.0, "speciesCode": "ANF", "underSized": false}, {"declaredWeight": 75.0, "controlledWeight": 75.0, "speciesCode": "HKE", "underSized": false}, {"declaredWeight": 8260.0, "controlledWeight": 8260.0, "speciesCode": "LEZ", "underSized": false}, {"declaredWeight": 330.0, "controlledWeight": 330.0, "speciesCode": "JOD", "underSized": false}, {"declaredWeight": 15.0, "controlledWeight": 15.0, "speciesCode": "POL", "underSized": false}, {"declaredWeight": 1450.0, "controlledWeight": 1450.0, "speciesCode": "COE", "underSized": false}, {"declaredWeight": 168.0, "controlledWeight": 168.0, "speciesCode": "LIN", "underSized": false}, {"declaredWeight": 147.0, "controlledWeight": 147.0, "speciesCode": "OCM", "underSized": false}, {"declaredWeight": 360.0, "controlledWeight": 360.0, "speciesCode": "RJN", "underSized": false}, {"declaredWeight": 90.0, "controlledWeight": 90.0, "speciesCode": "RJO", "underSized": false}]', '[{"infractionType": "PENDING", "comments": "Infraction espèces 1", "natinf": 17}]', false, 'Sous taille', '[{"segment": "NWW01/02", "segmentName": "Nord Ouest 1 2"}, {"segment": "SWW01/02/03", "segmentName": "Sud Ouest 1 2 3"}]', NULL, '{27.8.a,27.7.h,27.7.e}', false, false, 'ABC'), +( 8, 1, 'FR', 8, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '3 years 3 months', 'MEMN', NULL, NULL, 'FRDPE', false, NULL, 'DRB 3550 SCE DECLARE SUR JPE', '[{"gearCode": "DRB", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 3700.0, "controlledWeight": 3700.0, "speciesCode": "SCE", "underSized": false}]', '[{"infractionType": "WITH_RECORD", "comments": "Infraction espèces 2", "natinf": 1030}]', true, NULL, '[{"segment": "FR_SCE", "segmentName": "Coquille"}]', '[]', '{27.7.d}', false, false, 'ABC'), +( 9, 1, 'FR', 9, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '6 years 3 months', 'MEMN', NULL, NULL, 'FRDKK', false, NULL, 'ENTRAVE AU CONTROLE ', '[{"gearCode": "GTR", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, 'null', '[]', false, NULL, '[]', '[{"infractionType": "WITH_RECORD", "natinf": 2606, "comments": "Infraction 6"}]', '{27.7.d,27.4.c}', false, true, 'ABC'), +( 10, 2, 'FR', 10, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 weeks', 'MEMN', NULL, NULL, 'FRLEH', true, 'APPREHNTION DE 1600 KG DE SCE', 'PECHE DE LA SCE EN ZONE 5 FERMEE - APPREHENTION DE 1600 KG DE SCE', '[{"gearCode": "DRB", "declaredMesh": null, "controlledMesh": null, "gearWasControlled": false, "hasUncontrollerMesh": true}]', '[]', false, '[{"declaredWeight": 1600.0, "controlledWeight": 1600.0, "speciesCode": "SCE", "underSized": false}]', '[]', false, NULL, '[{"segment": "FR_SCE", "segmentName": "Coquille"}]', '[{"infractionType": "WITH_RECORD", "natinf": 7061, "comments": "Infraction 7"}]', '{27.7.d}', false, false, 'ABC'), +( 11, 2, 'FR', 11, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '5 months', NULL, NULL, NULL, NULL, NULL, NULL, 'MGS22', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{}', false, false, 'ABC'), +( 12, 2, 'FR', 12, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 years 9 months', NULL, NULL, NULL, NULL, NULL, NULL, '9405 ANE', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{}', false, false, 'ABC'), +( 13, 2, 'FR', 13, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 3 months', NULL, NULL, NULL, NULL, NULL, NULL, 'ALB 2420', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{}', false, false, 'ABC'), +( 14, 2, 'FR', 14, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 4 months', NULL, NULL, NULL, NULL, NULL, NULL, 'ALB1470KG', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{}', false, false, 'ABC'), +( 15, 2, 'FR', 15, 'SEA_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 6 months', NULL, NULL, NULL, NULL, NULL, NULL, 'ENGIN NC- CTC 160/PLE 2/SOL 2', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{}', false, false, 'ABC'), +( 16, 2, 'FR', 16, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 8 months', 'SA', NULL, NULL, 'FRZJZ', NULL, NULL, '96 POISSONS 7544 KG', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b,27.8.c}', false, false, 'ABC'), +( 17, 2, 'FR', 17, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 9 months', 'SA', NULL, NULL, 'FRZJZ', NULL, NULL, '2 BFT 8-30 KG : POIDS 34.2KG - BON 8.6 K', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b,27.8.c}', false, false, 'ABC'), +( 18, 2, 'FR', 18, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 10 months', 'SA', NULL, NULL, 'FRZJZ', NULL, NULL, '2 BFT POUR 13.7KG - ENGIN NON CONTROLE', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b,27.8.c}', false, false, 'ABC'), +( 19, 2, 'FR', 19, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 years 11 months', 'SA', NULL, NULL, 'FRZJZ', NULL, NULL, '28 BFT 300KG', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b,27.8.c}', false, false, 'ABC'), +( 20, 2, 'FR', 20, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '2 years', 'SA', NULL, NULL, 'FRZJZ', NULL, NULL, '28 POISSONS 2368 KG', '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b,27.8.c}', false, false, 'ABC'), +( 21, 3, 'NL', 21, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 week', 'SA', NULL, NULL, 'FRDKK', NULL, NULL, NULL, '[]', '[]', false, 'null', '[]', false, NULL, '[]', '[]', '{27.8.b}', false, false, 'ABC'), +( 22, 4, 'FR', 22, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 week 3 days', 'NAMO', NULL, NULL, 'FRZJZ', NULL, NULL, 'RAS', '[]', '[]', false, 'null', '[]', false, NULL, NULL, '[{"infractionType": "WITH_RECORD", "natinf": 7061, "comments": "Infraction 7"}]', '{27.8.c}', false, false, 'ABC'), +( 23, 4, 'FR', 22, 'LAND_CONTROL', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP - INTERVAL '1 week 2 days', 'NAMO', NULL, NULL, 'FRZJZ', NULL, NULL, 'RAS', '[]', '[]', false, 'null', '[]', false, NULL, 'null', '[]', '{27.8.c}', false, false, 'ABC'); From 20398236f4af473c9514c5e74423ffef604fc681 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 24 May 2024 15:40:55 +0200 Subject: [PATCH 07/14] Map null and unknown flag states to UNDEFINED in vessels flow --- datascience/src/pipeline/queries/ocan/non_eu_vessels.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/datascience/src/pipeline/queries/ocan/non_eu_vessels.sql b/datascience/src/pipeline/queries/ocan/non_eu_vessels.sql index 6192b6522d..5837d62936 100644 --- a/datascience/src/pipeline/queries/ocan/non_eu_vessels.sql +++ b/datascience/src/pipeline/queries/ocan/non_eu_vessels.sql @@ -6,7 +6,13 @@ SELECT f.nom_navire AS vessel_name, f.indicatif_radio AS ircs, f.numero_mmsi AS mmsi, - cp.code_pays_iso2 AS flag_state, + COALESCE( + CASE + WHEN cp.code_pays_iso2 = 'X' THEN 'UNDEFINED' + ELSE cp.code_pays_iso2 + END, + 'UNDEFINED' + ) AS flag_state, ne.longueur_hors_tout AS length, nep.jauge_ums AS gauge, nep.puissance_propulsion AS power, From 5595a8815be65f806e90ef942d32f7e47cadc5af Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 24 May 2024 15:54:17 +0200 Subject: [PATCH 08/14] Fix backend test --- .../mission/mission_actions/GetActivityReportsUTests.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt index c0f7603a19..49edbe2983 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt @@ -421,6 +421,8 @@ class GetActivityReportsUTests { hasSomeSpeciesSeized = false, isFromPoseidon = false, completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "CPAMOI" ), ) given(missionActionsRepository.findControlsInDates(any(), any())).willReturn(controls) From 0555352e226f4f2f6a9ba6da49d9f958d367a9f6 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Mon, 27 May 2024 16:33:47 +0200 Subject: [PATCH 09/14] Add a CountryCode converter --- .../database/entities/MissionActionEntity.kt | 3 ++- .../database/entities/PendingAlertEntity.kt | 3 ++- .../database/entities/PositionEntity.kt | 7 +++--- .../database/entities/ReportingEntity.kt | 3 ++- .../database/entities/SilencedAlertEntity.kt | 3 ++- .../database/entities/VesselEntity.kt | 13 ++++------ .../converters/CountryCodeConverter.kt | 24 +++++++++++++++++++ .../V0.254__Update_flag_state_column.sql | 10 ++++++++ .../V666.20__Insert_dummy_silenced_alerts.sql | 2 +- 9 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/converters/CountryCodeConverter.kt create mode 100644 backend/src/main/resources/db/migration/internal/V0.254__Update_flag_state_column.sql diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt index cff32fbbeb..ba24d037f6 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt @@ -5,6 +5,7 @@ import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.facade.Facade import fr.gouv.cnsp.monitorfish.domain.entities.facade.Seafront import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* +import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters.CountryCodeConverter import io.hypersistence.utils.hibernate.type.json.JsonBinaryType import jakarta.persistence.* import org.hibernate.annotations.JdbcType @@ -33,7 +34,7 @@ class MissionActionEntity( @Column(name = "ircs") val ircs: String? = null, @Column(name = "flag_state") - @Enumerated(EnumType.STRING) + @Convert(converter = CountryCodeConverter::class) val flagState: CountryCode, @Column(name = "district_code") val districtCode: String? = null, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PendingAlertEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PendingAlertEntity.kt index 65163c5378..39713e3714 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PendingAlertEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PendingAlertEntity.kt @@ -5,6 +5,7 @@ import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.alerts.PendingAlert import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.AlertType import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselIdentifier +import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters.CountryCodeConverter import io.hypersistence.utils.hibernate.type.json.JsonBinaryType import jakarta.persistence.* import org.hibernate.annotations.JdbcType @@ -35,7 +36,7 @@ data class PendingAlertEntity( @JdbcType(PostgreSQLEnumJdbcType::class) val vesselIdentifier: VesselIdentifier, @Column(name = "flag_state") - @Enumerated(EnumType.STRING) + @Convert(converter = CountryCodeConverter::class) val flagState: CountryCode, @Column(name = "creation_date", nullable = false) val creationDate: ZonedDateTime, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PositionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PositionEntity.kt index f76536747c..34b11f1ecd 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PositionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PositionEntity.kt @@ -3,6 +3,7 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.entities import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.position.Position import fr.gouv.cnsp.monitorfish.domain.entities.position.PositionType +import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters.CountryCodeConverter import jakarta.persistence.* import java.time.ZonedDateTime @@ -27,8 +28,8 @@ data class PositionEntity( @Column(name = "vessel_name") val vesselName: String? = null, @Column(name = "flag_state") - @Enumerated(EnumType.STRING) - val flagState: CountryCode? = null, + @Convert(converter = CountryCodeConverter::class) + val flagState: CountryCode, @Column(name = "from_country") @Enumerated(EnumType.STRING) val from: CountryCode? = null, @@ -92,7 +93,7 @@ data class PositionEntity( vesselName = position.vesselName, speed = position.speed, course = position.course, - flagState = position.flagState, + flagState = position.flagState ?: CountryCode.UNDEFINED, destination = position.destination, from = position.from, tripNumber = position.tripNumber, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ReportingEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ReportingEntity.kt index ff7ee786af..83a7e82ea4 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ReportingEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ReportingEntity.kt @@ -7,6 +7,7 @@ import fr.gouv.cnsp.monitorfish.domain.entities.reporting.Reporting import fr.gouv.cnsp.monitorfish.domain.entities.reporting.ReportingType import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselIdentifier import fr.gouv.cnsp.monitorfish.domain.mappers.ReportingMapper +import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters.CountryCodeConverter import io.hypersistence.utils.hibernate.type.json.JsonBinaryType import jakarta.persistence.* import org.hibernate.annotations.JdbcType @@ -41,7 +42,7 @@ data class ReportingEntity( @Column(name = "vessel_identifier", columnDefinition = "vessel_identifier") val vesselIdentifier: VesselIdentifier? = null, @Column(name = "flag_state") - @Enumerated(EnumType.STRING) + @Convert(converter = CountryCodeConverter::class) val flagState: CountryCode, @Column(name = "creation_date", nullable = false) val creationDate: ZonedDateTime, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SilencedAlertEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SilencedAlertEntity.kt index d0b2bbbcf0..c85e3b2f00 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SilencedAlertEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SilencedAlertEntity.kt @@ -6,6 +6,7 @@ import fr.gouv.cnsp.monitorfish.domain.entities.alerts.PendingAlert import fr.gouv.cnsp.monitorfish.domain.entities.alerts.SilencedAlert import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.AlertType import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselIdentifier +import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters.CountryCodeConverter import io.hypersistence.utils.hibernate.type.json.JsonBinaryType import jakarta.persistence.* import org.hibernate.annotations.JdbcType @@ -36,7 +37,7 @@ data class SilencedAlertEntity( @Column(name = "vessel_identifier", columnDefinition = "vessel_identifier") val vesselIdentifier: VesselIdentifier, @Column(name = "flag_state") - @Enumerated(EnumType.STRING) + @Convert(converter = CountryCodeConverter::class) val flagState: CountryCode, @Column(name = "silenced_before_date", nullable = false) val silencedBeforeDate: ZonedDateTime, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/VesselEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/VesselEntity.kt index a068978f26..e91ffa2028 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/VesselEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/VesselEntity.kt @@ -2,6 +2,7 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.entities import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.vessel.Vessel +import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters.CountryCodeConverter import jakarta.persistence.* import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -35,7 +36,8 @@ data class VesselEntity( val vesselName: String? = null, // ISO Alpha-2 country code @Column(name = "flag_state") - val flagState: String? = null, + @Convert(converter = CountryCodeConverter::class) + val flagState: CountryCode, @Column(name = "width") val width: Double? = null, @Column(name = "length") @@ -87,14 +89,7 @@ data class VesselEntity( mmsi = mmsi, externalReferenceNumber = externalReferenceNumber, vesselName = vesselName, - flagState = flagState?.let { - try { - CountryCode.valueOf(flagState) - } catch (e: IllegalArgumentException) { - logger.warn(e.message) - CountryCode.UNDEFINED - } - } ?: CountryCode.UNDEFINED, + flagState = flagState, width = width, length = length, district = district, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/converters/CountryCodeConverter.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/converters/CountryCodeConverter.kt new file mode 100644 index 0000000000..2837229e71 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/converters/CountryCodeConverter.kt @@ -0,0 +1,24 @@ +package fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters + +import com.neovisionaries.i18n.CountryCode +import jakarta.persistence.AttributeConverter +import jakarta.persistence.Converter + +@Converter(autoApply = true) +class CountryCodeConverter : AttributeConverter { + override fun convertToDatabaseColumn(attribute: CountryCode?): String? { + return attribute?.name + } + + override fun convertToEntityAttribute(dbData: String?): CountryCode? { + if (dbData == null) { + return CountryCode.UNDEFINED + } + + return try { + CountryCode.valueOf(dbData) + } catch (e: Throwable) { + return CountryCode.UNDEFINED + } + } +} diff --git a/backend/src/main/resources/db/migration/internal/V0.254__Update_flag_state_column.sql b/backend/src/main/resources/db/migration/internal/V0.254__Update_flag_state_column.sql new file mode 100644 index 0000000000..ced3918fa7 --- /dev/null +++ b/backend/src/main/resources/db/migration/internal/V0.254__Update_flag_state_column.sql @@ -0,0 +1,10 @@ +-- We now store `UNDEFINED` from `com.neovisionaries.i18n.CountryCode` library + +ALTER TABLE pending_alerts + ALTER COLUMN flag_state SET DATA TYPE varchar(10); + +ALTER TABLE silenced_alerts + ALTER COLUMN flag_state SET DATA TYPE varchar(10); + +ALTER TABLE reportings + ALTER COLUMN flag_state SET DATA TYPE varchar(10); diff --git a/backend/src/main/resources/db/testdata/V666.20__Insert_dummy_silenced_alerts.sql b/backend/src/main/resources/db/testdata/V666.20__Insert_dummy_silenced_alerts.sql index 7d013c948e..48d11c3e9a 100644 --- a/backend/src/main/resources/db/testdata/V666.20__Insert_dummy_silenced_alerts.sql +++ b/backend/src/main/resources/db/testdata/V666.20__Insert_dummy_silenced_alerts.sql @@ -23,7 +23,7 @@ VALUES ('NATUREL NON FUIR', 'ABC000571489', 'IS726385', 'LRED', 'INTERNAL_REFERE '"natinfCode": 27689' || '}')::jsonb), ('FORTUNE ARME ABATTRE', 'ABC000677933', 'IG415546', 'UTIG', 'INTERNAL_REFERENCE_NUMBER', - 'FR', NOW() + ('24 HOURS')::interval, ('{' || + 'X', NOW() + ('24 HOURS')::interval, ('{' || '"seaFront": "NAMO",' || '"riskFactor": 3.6947,' || '"type": "THREE_MILES_TRAWLING_ALERT",' || From 3236b9993df8807399c0fc463b1acf84912b1fc6 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Mon, 27 May 2024 16:48:59 +0200 Subject: [PATCH 10/14] Fix migration number --- ...ag_state_column.sql => V0.255__Update_flag_state_column.sql} | 0 .../mission/mission_actions/GetActivityReportsUTests.kt | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename backend/src/main/resources/db/migration/internal/{V0.254__Update_flag_state_column.sql => V0.255__Update_flag_state_column.sql} (100%) diff --git a/backend/src/main/resources/db/migration/internal/V0.254__Update_flag_state_column.sql b/backend/src/main/resources/db/migration/internal/V0.255__Update_flag_state_column.sql similarity index 100% rename from backend/src/main/resources/db/migration/internal/V0.254__Update_flag_state_column.sql rename to backend/src/main/resources/db/migration/internal/V0.255__Update_flag_state_column.sql diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt index 49edbe2983..2f87c09a05 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt @@ -422,7 +422,7 @@ class GetActivityReportsUTests { isFromPoseidon = false, completion = Completion.TO_COMPLETE, flagState = CountryCode.FR, - userTrigram = "CPAMOI" + userTrigram = "CPAMOI", ), ) given(missionActionsRepository.findControlsInDates(any(), any())).willReturn(controls) From b3b1358ee17e72bc96b58b4326dcdde80a233174 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Mon, 27 May 2024 16:52:22 +0200 Subject: [PATCH 11/14] Fix typo --- .../infrastructure/api/bff/MissionActionsControllerITests.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt index c1f4c1bfd1..5afcfaa35e 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt @@ -311,7 +311,7 @@ class MissionActionsControllerITests { "internalReferenceNumber": "FRA000936666", "externalReferenceNumber": "SEGESGES", "ircs": "FEFGEGSGE", - "flagState": null", + "flagState": null, "districtCode": "AD", "faoAreas": [], "flightGoals": [], From e3a0f2751d0bcbf2da58c07e74a2d9095aed47a8 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Tue, 28 May 2024 15:53:41 +0200 Subject: [PATCH 12/14] Fix cypress tests with flag states --- .../e2e/vessels/vessel_filters.spec.ts | 2 +- frontend/src/constants/index.ts | 2 +- .../VesselFilters/SaveVesselFiltersModal.tsx | 43 ++++++++++--------- .../MapButtons/VesselFilters/TagList.tsx | 20 +++++---- .../features/VesselList/VesselListFilters.tsx | 4 +- frontend/src/features/VesselList/index.tsx | 28 ++++++++---- 6 files changed, 59 insertions(+), 40 deletions(-) diff --git a/frontend/cypress/e2e/vessels/vessel_filters.spec.ts b/frontend/cypress/e2e/vessels/vessel_filters.spec.ts index e0a8b4c026..b2535b0398 100644 --- a/frontend/cypress/e2e/vessels/vessel_filters.spec.ts +++ b/frontend/cypress/e2e/vessels/vessel_filters.spec.ts @@ -16,7 +16,7 @@ context('Vessel filters', () => { // When cy.get('*[data-cy^="save-filter-modal"]').click({ timeout: 10000 }) - cy.get('*[class^="rs-input"]').last().type('Navires FR') + cy.get('[name="vessel-filter"]').type('Navires FR') cy.get('*[data-cy="save-filter"]').click({ timeout: 10000 }) // Then diff --git a/frontend/src/constants/index.ts b/frontend/src/constants/index.ts index a8c9b391e1..347c55b99d 100644 --- a/frontend/src/constants/index.ts +++ b/frontend/src/constants/index.ts @@ -15,7 +15,7 @@ export const FIVE_MINUTES = 5 * 60 * 1000 export const COUNTRIES_AS_ALPHA2_OPTIONS: Option[] = Object.keys(Countries.getAlpha2Codes()).map(code => ({ label: Countries.getName(code, 'fr'), - value: code.toLowerCase() + value: code })) export const COUNTRIES_AS_ALPHA3_OPTIONS: Option[] = Object.keys(Countries.getAlpha3Codes()).map(code => ({ diff --git a/frontend/src/features/MainWindow/components/MapButtons/VesselFilters/SaveVesselFiltersModal.tsx b/frontend/src/features/MainWindow/components/MapButtons/VesselFilters/SaveVesselFiltersModal.tsx index 89c784c78b..d1b0f78cd5 100644 --- a/frontend/src/features/MainWindow/components/MapButtons/VesselFilters/SaveVesselFiltersModal.tsx +++ b/frontend/src/features/MainWindow/components/MapButtons/VesselFilters/SaveVesselFiltersModal.tsx @@ -1,18 +1,13 @@ import { COLORS } from '@constants/constants' +import { StyledModalHeader } from '@features/commonComponents/StyledModalHeader' +import { TextInput, Icon, Size } from '@mtes-mct/monitor-ui' import { useState } from 'react' import { CirclePicker } from 'react-color' -import { Input, InputGroup, Modal } from 'rsuite' +import { Modal } from 'rsuite' import styled from 'styled-components' import { v4 as uuidv4 } from 'uuid' import { TagList } from './TagList' -import { StyledModalHeader } from '../../../../commonComponents/StyledModalHeader' -import FilterSVG from '../../../../icons/Icone_filtres_dark.svg?react' - -const styles = { - marginBottom: 20, - width: 200 -} type SaveVesselFiltersModalProps = Readonly<{ addFilter: (filter: { color: string; filters: any; name: string; showed: boolean; uuid: string }) => void @@ -28,10 +23,14 @@ export function SaveVesselFiltersModal({ isOpen, setIsOpen }: SaveVesselFiltersModalProps) { - const [filterName, setFilterName] = useState('') + const [filterName, setFilterName] = useState(undefined) const [filterColor, setFilterColor] = useState('#2c6e49') const save = () => { + if (!filterName) { + return + } + const filter = { color: filterColor, filters, @@ -61,13 +60,17 @@ export function SaveVesselFiltersModal({ - - - - - - - + + Couleur des navires du filtre @@ -100,6 +103,10 @@ export function SaveVesselFiltersModal({ ) } +const StyledTagList = styled(TagList)` + margin-top: 12px; +` + const SelectedFilterColor = styled.div` margin: 10px 0 10px 0; font-size: 13px; @@ -151,7 +158,3 @@ const CancelButton = styled.button` color: ${COLORS.lightGray}; } ` - -const Filter = styled(FilterSVG)` - width: 16px; -` diff --git a/frontend/src/features/MainWindow/components/MapButtons/VesselFilters/TagList.tsx b/frontend/src/features/MainWindow/components/MapButtons/VesselFilters/TagList.tsx index 7c009d5266..b53b697c08 100644 --- a/frontend/src/features/MainWindow/components/MapButtons/VesselFilters/TagList.tsx +++ b/frontend/src/features/MainWindow/components/MapButtons/VesselFilters/TagList.tsx @@ -1,3 +1,4 @@ +import { CountryFlag } from '@components/CountryFlag' import { COLORS } from '@constants/constants' import countries from 'i18n-iso-countries' import { useEffect, useState } from 'react' @@ -10,6 +11,7 @@ import { vesselSize } from '../../../../../domain/entities/vessel/vessel' import type { FilterValues } from 'domain/types/filter' type TagListProps = Readonly<{ + className?: string | undefined filters: FilterValues removeTagFromFilter?: (removeObject: { type: string | undefined @@ -18,7 +20,7 @@ type TagListProps = Readonly<{ }) => void uuid?: string }> -export function TagList({ filters, removeTagFromFilter, uuid }: TagListProps) { +export function TagList({ className, filters, removeTagFromFilter, uuid }: TagListProps) { const [tags, setTags] = useState< Array<{ iconElement: JSX.Element @@ -38,7 +40,7 @@ export function TagList({ filters, removeTagFromFilter, uuid }: TagListProps) { if (filters.countriesFiltered?.length) { const countriesTags = filters.countriesFiltered.map(country => ({ - iconElement: , + iconElement: , text: countries.getName(country, 'fr'), type: 'countriesFiltered', value: country @@ -134,7 +136,7 @@ export function TagList({ filters, removeTagFromFilter, uuid }: TagListProps) { }, [filters]) return ( - + {tags?.length ? ( <> {tags.map(tag => ( @@ -156,16 +158,16 @@ export function TagList({ filters, removeTagFromFilter, uuid }: TagListProps) { ) } +const StyledCountryFlag = styled(CountryFlag)` + margin-right: 8px; + vertical-align: -2px; +` + const List = styled.div` display: inline-block; width: 100%; text-align: center; -` - -const Flag = styled.img` - height: 14px; - margin-bottom: 3px; - margin-right: 5px; + line-height: 24px; ` const NoTag = styled.div` diff --git a/frontend/src/features/VesselList/VesselListFilters.tsx b/frontend/src/features/VesselList/VesselListFilters.tsx index f39033090c..af1f7c3439 100644 --- a/frontend/src/features/VesselList/VesselListFilters.tsx +++ b/frontend/src/features/VesselList/VesselListFilters.tsx @@ -137,7 +137,9 @@ function UnmemoizedVesselListFilters({ })) zones.setZonesFilter(nextZonesWithoutNulls) - }, [dispatch, zones]) + // Having a dependency on `zones` trigger an infinite re-render + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [dispatch, zones.setZonesFilter]) useEffect(() => { getZones() diff --git a/frontend/src/features/VesselList/index.tsx b/frontend/src/features/VesselList/index.tsx index 14f93ee666..c1e8a0760e 100644 --- a/frontend/src/features/VesselList/index.tsx +++ b/frontend/src/features/VesselList/index.tsx @@ -351,6 +351,25 @@ export function VesselList({ namespace }) { [dispatch, namespace, zonesFilter, zonesSelected] ) + const zones = useMemo( + () => ({ + administrativeZonesFiltered, + callRemoveZoneSelected, + setAdministrativeZonesFiltered, + setZonesFilter: setZonesFilterCallback, + zonesFilter, + zonesSelected + }), + [ + administrativeZonesFiltered, + callRemoveZoneSelected, + setAdministrativeZonesFiltered, + setZonesFilterCallback, + zonesFilter, + zonesSelected + ] + ) + const isRightMenuShrinked = !rightMenuIsOpen return ( @@ -439,14 +458,7 @@ export function VesselList({ namespace }) { species, speciesFiltered }} - zones={{ - administrativeZonesFiltered, - callRemoveZoneSelected, - setAdministrativeZonesFiltered, - setZonesFilter: setZonesFilterCallback, - zonesFilter, - zonesSelected - }} + zones={zones} /> Date: Tue, 28 May 2024 16:06:23 +0200 Subject: [PATCH 13/14] Re-add missing styled component --- .../database/entities/MissionActionEntity.kt | 1 - frontend/src/components/CountryFlag/index.tsx | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt index ba24d037f6..01438f24c4 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt @@ -2,7 +2,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.entities import com.fasterxml.jackson.databind.ObjectMapper import com.neovisionaries.i18n.CountryCode -import fr.gouv.cnsp.monitorfish.domain.entities.facade.Facade import fr.gouv.cnsp.monitorfish.domain.entities.facade.Seafront import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters.CountryCodeConverter diff --git a/frontend/src/components/CountryFlag/index.tsx b/frontend/src/components/CountryFlag/index.tsx index 3e335c699d..ae31650b60 100644 --- a/frontend/src/components/CountryFlag/index.tsx +++ b/frontend/src/components/CountryFlag/index.tsx @@ -38,3 +38,13 @@ const Img = styled.img<{ height: ${p => p.$height}px; width: ${p => p.$width}px; ` + +const Unknown = styled.span<{ + $height: number + $width: number +}>` + background-color: black; + display: inline-block; + height: ${p => p.$height}px; + width: ${p => p.$width}px; +` From 79a9297b95657fc21c8530071450d01ed40788f8 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Tue, 28 May 2024 16:16:26 +0200 Subject: [PATCH 14/14] Add unit test for country code converter --- .../converters/CountryCodeConverterUTests.kt | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/converters/CountryCodeConverterUTests.kt diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/converters/CountryCodeConverterUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/converters/CountryCodeConverterUTests.kt new file mode 100644 index 0000000000..1bc3a4db01 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/converters/CountryCodeConverterUTests.kt @@ -0,0 +1,54 @@ +package fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters + +import com.neovisionaries.i18n.CountryCode +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class CountryCodeConverterUTests { + private val converter = CountryCodeConverter() + + @Test + fun `convertToDatabaseColumn should return enum name`() { + // When + val result = converter.convertToDatabaseColumn(CountryCode.US) + + // Then + assertThat(result).isEqualTo("US") + } + + @Test + fun `convertToDatabaseColumn should return null for null attribute`() { + // When + val result = converter.convertToDatabaseColumn(null) + + // Then + assertThat(result).isEqualTo(null) + } + + @Test + fun `convertToEntityAttribute should return enum for valid dbData`() { + // When + val result = converter.convertToEntityAttribute("US") + + // Then + assertThat(result).isEqualTo(CountryCode.US) + } + + @Test + fun `convertToEntityAttribute should return UNDEFINED for invalid dbData`() { + // When + val result = converter.convertToEntityAttribute("INVALID_CODE") + + // Then + assertThat(result).isEqualTo(CountryCode.UNDEFINED) + } + + @Test + fun `convertToEntityAttribute should return UNDEFINED for null dbData`() { + // When + val result = converter.convertToEntityAttribute(null) + + // Then + assertThat(result).isEqualTo(CountryCode.UNDEFINED) + } +}