Skip to content

Commit

Permalink
FIx migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron authored and VincentAntoine committed May 24, 2024
1 parent 0c6598b commit 1cc04bb
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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<FaoZonesAndSpecy>) {
MEDITERRANEAN_AND_EASTERN_ATLANTIC(MEDITERRANEAN_AND_EASTERN_ATLANTIC_SPECIES),
NORTH_SEA(NORTH_SEA_SPECIES),
Expand All @@ -18,7 +20,7 @@ enum class JointDeploymentPlan(private val species: List<FaoZonesAndSpecy>) {
* 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<String>, tripFaoCodes: List<String>): Boolean {
fun isLandControlApplicable(flagState: CountryCode, speciesOnboardCodes: List<String>, tripFaoCodes: List<String>): Boolean {
val isThirdCountryVessel = EU_THIRD_COUNTRIES.contains(flagState)

val hasSpeciesInJdp = this.species.any { (jdpFaoZones, jdpSpecy) ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep

import com.neovisionaries.i18n.CountryCode

typealias FaoZones = List<String>
typealias FaoZonesAndSpecy = Pair<FaoZones, String>

Expand Down Expand Up @@ -156,7 +158,7 @@ val WESTERN_WATERS_SPECIES: List<FaoZonesAndSpecy> = 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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -41,6 +42,8 @@ object TestUtils {
hasSomeSpeciesSeized = false,
isFromPoseidon = false,
completion = Completion.TO_COMPLETE,
userTrigram = "LTH",
flagState = CountryCode.FR,
)
}
}.flatten()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -153,6 +153,8 @@ class MissionsControllerITests {
hasSomeSpeciesSeized = false,
isFromPoseidon = false,
completion = Completion.TO_COMPLETE,
flagState = CountryCode.FR,
userTrigram = "LTH",
),
),
),
Expand Down

0 comments on commit 1cc04bb

Please sign in to comment.