From 899c2dabcf3d47bbcd34e2ded5daa384900a885d Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 7 Jan 2025 11:55:33 +0100 Subject: [PATCH 1/2] feat(AEM): v2 of AEM base on mission-action - Create V2 of every cell of tableau export - Create a V2 for TableauExport class - Create a V2 test for every class --- .../entities/aem/v2/AEMCulturalMaritime2.kt | 37 +++++ .../domain/entities/aem/v2/AEMEnvTraffic2.kt | 38 +++++ .../domain/entities/aem/v2/AEMIllegalFish2.kt | 76 ++++++++++ .../entities/aem/v2/AEMIllegalImmigration2.kt | 51 +++++++ .../entities/aem/v2/AEMMigrationRescue2.kt | 57 ++++++++ .../v2/AEMNotPollutionControlSurveillance2.kt | 50 +++++++ .../aem/v2/AEMOutOfMigrationRescue2.kt | 31 ++++ .../v2/AEMPollutionControlSurveillance2.kt | 109 +++++++++++++++ .../domain/entities/aem/v2/AEMSeaSafety2.kt | 39 ++++++ .../entities/aem/v2/AEMSovereignProtect2.kt | 66 +++++++++ .../domain/entities/aem/v2/AEMTableExport2.kt | 58 ++++++++ .../entities/aem/v2/AEMVesselRescue2.kt | 36 +++++ .../mission/export/v2/ExportMissionAEM2.kt | 93 ++++++++++++ .../domain/use_cases/utils/FillAEMExcelRow.kt | 128 +++++++++++++++++ .../rapportnav/domain/utils/AEMUtils.kt | 12 ++ .../aem/v2/AEMCulturalMaritimeTest2.kt | 57 ++++++++ .../entities/aem/v2/AEMEnvTrafficTest2.kt | 56 ++++++++ .../entities/aem/v2/AEMIllegalFishTest2.kt | 68 +++++++++ .../aem/v2/AEMIllegalImmigrationTest2.kt | 66 +++++++++ .../aem/v2/AEMMigrationRescueTest2.kt | 73 ++++++++++ ...AEMNotPollutionControlSurveillanceTest2.kt | 84 +++++++++++ .../aem/v2/AEMOutOfMigrationRescue2Test.kt | 132 ++++++++++++++++++ .../AEMPolllutionControlSurveillanceTest2.kt | 123 ++++++++++++++++ .../entities/aem/v2/AEMSeaSafetyTest2.kt | 73 ++++++++++ .../aem/v2/AEMSovereignProtectTest2.kt | 116 +++++++++++++++ .../entities/aem/v2/AEMTableExportTest2.kt | 76 ++++++++++ .../entities/aem/v2/AEMVesselRescueTest2.kt | 75 ++++++++++ 27 files changed, 1880 insertions(+) create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMCulturalMaritime2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMEnvTraffic2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMIllegalFish2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMIllegalImmigration2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMMigrationRescue2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMNotPollutionControlSurveillance2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMOutOfMigrationRescue2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMPollutionControlSurveillance2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMSeaSafety2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMSovereignProtect2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMTableExport2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMVesselRescue2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/export/v2/ExportMissionAEM2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMCulturalMaritimeTest2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMEnvTrafficTest2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMIllegalFishTest2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMIllegalImmigrationTest2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMMigrationRescueTest2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMNotPollutionControlSurveillanceTest2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMOutOfMigrationRescue2Test.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMPolllutionControlSurveillanceTest2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMSeaSafetyTest2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMSovereignProtectTest2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMTableExportTest2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMVesselRescueTest2.kt diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMCulturalMaritime2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMCulturalMaritime2.kt new file mode 100644 index 000000000..fb99f9d2b --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMCulturalMaritime2.kt @@ -0,0 +1,37 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils + +data class AEMCulturalMaritime2( + val nbrOfHourAtSea: Double? = 0.0, //4.4.1 + val nbrOfScientificOperation: Double? = 0.0, // 4.4.2 + val nbrOfBCMPoliceOperation: Double? = 0.0, // 4.4.3 +) { + constructor( + envActions: List + ) : this( + nbrOfScientificOperation = scientificCampaignActionEntities(envActions).size.toDouble(), + nbrOfBCMPoliceOperation = culturalMaritimeActionEntities(envActions).size.toDouble(), + nbrOfHourAtSea = AEMUtils.getDurationInHours2(culturalMaritimeActionEntities(envActions)), + ) + + companion object { + private val scientificCampaignControlPlanSubThemeIds = listOf(165); + private val culturalMaritimeWellBeingControlPlanThemeIds = listOf(104); + private fun culturalMaritimeActionEntities(envActions: List): List { + return envActions.filter { action -> + action?.controlPlans?.map { c -> c.themeId } + ?.intersect(culturalMaritimeWellBeingControlPlanThemeIds)?.isEmpty() == false + } + } + + private fun scientificCampaignActionEntities(envActions: List): List { + return envActions.filter { action -> + action?.controlPlans?.flatMap { it.subThemeIds!! } + ?.intersect(scientificCampaignControlPlanSubThemeIds)?.isEmpty() == false + } + } + } +} + diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMEnvTraffic2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMEnvTraffic2.kt new file mode 100644 index 000000000..96cfea518 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMEnvTraffic2.kt @@ -0,0 +1,38 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils + +data class AEMEnvTraffic2( + val nbrOfHourAtSea: Double? = 0.0, //3.3.1 + val nbrOfRedirectShip: Double? = 0.0, // 3.3.3 + val nbrOfSeizure: Double? = 0.0 // 3.3.4 +) { + constructor( + envActions: List + ) : this( + nbrOfHourAtSea = AEMUtils.getDurationInHours2(protectedSpeciesActionEntities(envActions)), + nbrOfRedirectShip = getNbrRedirectShip(envActions), + nbrOfSeizure = getNbrOfSeizure(envActions) + ) {} + companion object { + private val protectedSpeciesControlPlanThemeIds = listOf(103); + fun getNbrRedirectShip(envActions: List): Double { + return 0.0; //TODO Complete from MonitorEnv + } + + fun getNbrOfSeizure(envActions: List): Double { + return 0.0; //TODO Complete from MonitorEnv + } + + fun protectedSpeciesActionEntities(envActions: List): List { + + val protectedSpeciesActions = envActions.filter { + it?.controlPlans?.map { c -> c.themeId } + ?.intersect(protectedSpeciesControlPlanThemeIds)?.isEmpty() == false + } + return protectedSpeciesActions; + } + + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMIllegalFish2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMIllegalFish2.kt new file mode 100644 index 000000000..c0875c350 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMIllegalFish2.kt @@ -0,0 +1,76 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.InfractionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionFishActionEntity +import fr.gouv.dgampa.rapportnav.domain.utils.ComputeDurationUtils + +data class AEMIllegalFish2( + val nbrOfHourAtSea: Double? = 0.0, //4.3.1 + val nbrOfPolFishAction: Double? = 0.0, // 4.3.3 + val nbrOfTargetedVessel: Double? = 0.0, // 4.3.5 + val nbrOfInfractionWithPV: Double? = 0.0, // 4.3.6 + val nbrOfInfraction: Double? = 0.0, // 4.3.7 + val nbrOfSeizureAndDiversionVessel: Double? = 0.0, // 4.3.8 + val quantityOfFish: Double? = 0.0 //4.3.9 +) { + constructor( + fishActions: List + ) : this( + nbrOfHourAtSea = getNbrOfHourAtSea(fishActions), + nbrOfPolFishAction = fishActions.size.toDouble(), + nbrOfTargetedVessel = fishActions.size.toDouble(), + nbrOfInfraction = getNbrOfInfraction(fishActions), + nbrOfInfractionWithPV = getNbrOfInfractionWithPV(fishActions), + nbrOfSeizureAndDiversionVessel = getNbrOfSeizureAndDiversionVessel(fishActions), + quantityOfFish = getQuantityOfFish(fishActions) + ) { + } + + companion object { + fun getNbrOfHourAtSea(fishActions: List): Double { + return fishActions.fold(0.0) { acc, fishAction -> + acc.plus( + ComputeDurationUtils.durationInHours( + startDateTimeUtc = fishAction?.startDateTimeUtc, + endDateTimeUtc = fishAction?.endDateTimeUtc + ) + ) + }; + } + + fun getNbrOfInfraction(fishActions: List): Double { + return fishActions.filterNotNull().fold(0.0) { acc, c -> + acc.plus(c.gearInfractions?.count { it.natinf != null } ?: 0) + .plus(c.otherInfractions?.count { it.natinf != null } ?: 0) + .plus(c.speciesInfractions?.count { it.natinf != null } ?: 0) + .plus(c.logbookInfractions?.count { it.natinf != null } ?: 0) + }; + } + + fun getNbrOfInfractionWithPV(fishActions: List): Double { + return fishActions.filterNotNull() + .fold(0.0) { acc, c -> + acc.plus(c.gearInfractions?.filter { g -> g.infractionType == InfractionType.WITH_RECORD }?.size ?: 0) + .plus( + c.otherInfractions?.filter { o -> o.infractionType == InfractionType.WITH_RECORD }?.size ?: 0 + ) + .plus( + c.speciesInfractions?.filter { s -> s.infractionType == InfractionType.WITH_RECORD }?.size ?: 0 + ) + .plus( + c.logbookInfractions?.filter { l -> l.infractionType == InfractionType.WITH_RECORD }?.size ?: 0 + ) + }; + } + + fun getNbrOfSeizureAndDiversionVessel(fishActions: List): Double { + return fishActions.filter { it?.seizureAndDiversion == true }.size.toDouble(); + } + + fun getQuantityOfFish(fishActions: List): Double { + return fishActions + .filterNotNull() + .sumOf { it.speciesQuantitySeized?.toDouble() ?: 0.0 } } + + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMIllegalImmigration2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMIllegalImmigration2.kt new file mode 100644 index 000000000..95323caad --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMIllegalImmigration2.kt @@ -0,0 +1,51 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils + +data class AEMIllegalImmigration2( + val nbrOfHourAtSea: Double? = 0.0, //3.4.1 + val nbrOfInterceptedVessel: Double? = 0.0, // 3.4.3 + val nbrOfInterceptedMigrant: Double? = 0.0, // 3.4.4 + val nbrOfSuspectedSmuggler: Double? = 0.0 // 3.4.4 +) { + constructor( + navActions: List + ) : this( + nbrOfHourAtSea = AEMUtils.getDurationInHours2(getIllegalActions(navActions)), + nbrOfInterceptedVessel = getNbrOfInterceptedVessel(getIllegalActions(navActions)), + nbrOfInterceptedMigrant = getNbrOfInterceptedMigrant(getIllegalActions(navActions)), + nbrOfSuspectedSmuggler = getNbrOfSuspectedSmuggler(getIllegalActions(navActions)) + ) {} + + companion object { + fun getNbrOfInterceptedVessel(illegalActions: List): Double { + return illegalActions.fold(0.0) { acc, illegalAction -> + acc.plus( + illegalAction?.nbOfInterceptedVessels ?: 0 + ) + } + } + + fun getNbrOfInterceptedMigrant(illegalActions: List): Double { + return illegalActions.fold(0.0) { acc, illegalAction -> + acc.plus( + illegalAction?.nbOfInterceptedMigrants ?: 0 + ) + } + } + + fun getNbrOfSuspectedSmuggler(illegalActions: List): Double { + return illegalActions.fold(0.0) { acc, illegalAction -> + acc.plus( + illegalAction?.nbOfSuspectedSmugglers ?: 0 + ) + } + } + + private fun getIllegalActions(navActions: List): List { + return navActions.filter { it.actionType == ActionType.ILLEGAL_IMMIGRATION } + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMMigrationRescue2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMMigrationRescue2.kt new file mode 100644 index 000000000..f60173119 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMMigrationRescue2.kt @@ -0,0 +1,57 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils + +data class AEMMigrationRescue2( + val nbrOfHourAtSea: Double? = 0.0, // 1.2.1 + val nbrOfOperation: Double? = 0.0,// 1.2.3 + val nbrOfVesselsTrackedWithoutIntervention: Double? = 0.0, //1.2.4 + val nbrAssistedVesselsReturningToShore: Double? = 0.0, //1.2.5 + val nbrOfRescuedOperation: Double? = 0.0, //1.2.6 + val nbrPersonsRescued: Double? = 0.0,// 1.2.7 +) { + constructor( + navActions: List + ) : this( + nbrOfRescuedOperation = getMigrationRescueActions(navActions).size.toDouble(), + nbrOfHourAtSea = AEMUtils.getDurationInHours2(getMigrationRescueActions(navActions)), + nbrPersonsRescued = getNbrPersonsRescued(getMigrationRescueActions(navActions)), + nbrOfOperation = getMigrationRescueActions(navActions).size.toDouble(), //TODO: Define correctly what that means + nbrAssistedVesselsReturningToShore = getAssistedVesselsReturningToShore(getMigrationRescueActions(navActions)), + nbrOfVesselsTrackedWithoutIntervention = getNbrOfVesselsTrackedWithoutIntervention( + getMigrationRescueActions( + navActions + ) + ) + + ) + + companion object { + fun getNbrPersonsRescued(actionRescues: List): Double { + return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued ?: 0) } + } + + fun getNbrOfVesselsTrackedWithoutIntervention(actionRescues: List): Double { + return actionRescues.fold(0.0) { acc, actionRescue -> + acc.plus( + actionRescue?.nbOfVesselsTrackedWithoutIntervention ?: 0 + ) + } + } + + fun getAssistedVesselsReturningToShore(actionRescues: List): Double { + return actionRescues.fold(0.0) { acc, actionRescue -> + acc.plus( + actionRescue?.nbAssistedVesselsReturningToShore ?: 0 + ) + } + } + + private fun getMigrationRescueActions(navActions: List): List { + return navActions.filter { it.actionType == ActionType.RESCUE } + .filter { it.isMigrationRescue == true } + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMNotPollutionControlSurveillance2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMNotPollutionControlSurveillance2.kt new file mode 100644 index 000000000..1f4184b2d --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMNotPollutionControlSurveillance2.kt @@ -0,0 +1,50 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.InfractionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils + +data class AEMNotPollutionControlSurveillance2( + val nbrOfHourAtSea: Double? = 0.0, //4.1.1 + val nbrOfAction: Double? = 0.0, // 4.1.3 + val nbrOfInfraction: Double? = 0.0, // 4.1.4 + val nbrOfInfractionWithNotice: Double? = 0.0 // 4.1.5 +) { + constructor( + envActions: List + ) : this( + nbrOfHourAtSea = AEMUtils.getDurationInHours2(getNotPollutionActions(envActions)), + nbrOfAction = getNotPollutionActions(envActions).size.toDouble(), + nbrOfInfraction = getNbrOfInfraction(getNotPollutionActions(envActions)), + nbrOfInfractionWithNotice = getNbrOfInfractionWithNotice(getNotPollutionActions(envActions)) + ) { + + } + + companion object { + + fun getNbrOfInfraction(notPollutionActions: List): Double { + return notPollutionActions + .fold(0.0) { acc, c -> + acc.plus(c?.envInfractions?.flatMap { it.natinf ?: listOf() }?.size ?: 0) + } + } + + fun getNbrOfInfractionWithNotice(notPollutionActions: List): Double { + return notPollutionActions.fold(0.0) { acc, c -> + acc.plus( + c?.envInfractions?.filter { it.infractionType == InfractionTypeEnum.WITH_REPORT }?.size ?: 0 + ) + } + } + + private fun getNotPollutionActions(envActions: List): List { + val illicitRejects = listOf(19, 102); + return envActions.filter { + it?.controlPlans?.map { c -> c.themeId }?.intersect(illicitRejects)?.isEmpty() == true + } + } + + } +} + diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMOutOfMigrationRescue2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMOutOfMigrationRescue2.kt new file mode 100644 index 000000000..86cde7b6d --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMOutOfMigrationRescue2.kt @@ -0,0 +1,31 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils + +data class AEMOutOfMigrationRescue2( + val nbrOfHourAtSea: Double? = 0.0, //1.1.1 + val nbrOfRescuedOperation: Double? = 0.0, //1.1.3. + val nbrPersonsRescued: Double? = 0.0, //1.1.4 +) { + constructor( + navActions: List + ) : this( + nbrOfRescuedOperation = getMigrationRescueActions(navActions).size.toDouble(), + nbrPersonsRescued = getNbrPersonsRescued(getMigrationRescueActions(navActions)), + nbrOfHourAtSea = AEMUtils.getDurationInHours2(getMigrationRescueActions(navActions)), + ) { + } + + companion object { + fun getNbrPersonsRescued(actionRescues: List): Double { + return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued ?: 0) } + } + + private fun getMigrationRescueActions(navActions: List): List { + return navActions.filter { it.actionType == ActionType.RESCUE } + .filter { it.isMigrationRescue != true }; + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMPollutionControlSurveillance2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMPollutionControlSurveillance2.kt new file mode 100644 index 000000000..82d8ca8da --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMPollutionControlSurveillance2.kt @@ -0,0 +1,109 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.InfractionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils + +data class AEMPollutionControlSurveillance2( + val nbrOfHourAtSea: Double? = 0.0, //4.2.1 + val nbrOfSimpleBrewingOperation: Double? = 0.0, // 4.2.3 + val nbrOfAntiPolDeviceDeployed: Double? = 0.0, // 4.2.4 + val nbrOfInfraction: Double? = 0.0, // 4.2.5 + val nbrOfInfractionWithNotice: Double? = 0.0, // 4.2.6 + val nbrOfDiversionCarriedOut: Double? = 0.0, // 4.2.7 + val nbrOfPollutionObservedByAuthorizedAgent: Double? = 0.0 //4.2.8 +) { + constructor( + navActions: List, + envActions: List + ) : this( + nbrOfHourAtSea = getNbrOfHourAtSea( + getIllicitRejectActions(envActions), + getAntiPollutionActions(navActions) + ), + nbrOfSimpleBrewingOperation = getNbrOfSimpleBrewingOperation(getAntiPollutionActions(navActions)), + nbrOfAntiPolDeviceDeployed = getNbrOfAntiPolDeviceDeployed(getAntiPollutionActions(navActions)), + nbrOfInfraction = getNbrOfInfraction(getIllicitRejectActions(envActions)), + nbrOfInfractionWithNotice = getNbrOfInfractionWithNotice(getIllicitRejectActions(envActions)), + nbrOfDiversionCarriedOut = getNbrOfDiversionCarriedOut( + getIllicitRejectActions(envActions), + getAntiPollutionActions(navActions) + ), + nbrOfPollutionObservedByAuthorizedAgent = getNbrOfPollutionObservedByAuthorizedAgent( + getIllicitRejectActions(envActions), + getAntiPollutionActions(navActions) + ), + ) { + } + + companion object { + fun getNbrOfHourAtSea( + illicitRejectsActions: List, + antiPollutionActions: List + ): Double { + val nbrOfHourAntiPollution = AEMUtils.getDurationInHours2(antiPollutionActions); + val nbrEnvOfHourAntiPollution = AEMUtils.getDurationInHours2(illicitRejectsActions); + return nbrOfHourAntiPollution.plus(nbrEnvOfHourAntiPollution); + } + + fun getNbrOfSimpleBrewingOperation(antiPollutionActions: List): Double { + return antiPollutionActions.filter { it?.isSimpleBrewingOperationDone == true }.size.toDouble(); + } + + fun getNbrOfAntiPolDeviceDeployed(antiPollutionActions: List): Double { + return antiPollutionActions.filter { it?.isAntiPolDeviceDeployed == true }.size.toDouble(); + } + + fun getNbrOfInfraction(illicitRejectsActions: List,): Double { + return illicitRejectsActions.fold(0.0) { acc, envAction -> + acc.plus( + envAction?.envInfractions?.flatMap { it.natinf ?: listOf() }?.size ?: 0 + ) + } + } + + fun getNbrOfInfractionWithNotice(illicitRejectsActions: List,): Double { + return illicitRejectsActions.fold(0.0) { acc, envAction -> + acc.plus( + envAction?.envInfractions?.filter { it.infractionType == InfractionTypeEnum.WITH_REPORT }?.size + ?: 0 + ) + } + } + //it.infractionType == InfractionTypeEnum.WITH_REPORT + + fun getNbrOfDiversionCarriedOut( + illicitRejectsActions: List, + antiPollutionActions: List + ): Double { + val envNbrOfDiversionCarriedOut = 0.0; //TODO: diversionCarriedOut from Env + val navNbrOfDiversionCarriedOut = antiPollutionActions.filter { it?.diversionCarriedOut == true }.size; + + return envNbrOfDiversionCarriedOut.plus(navNbrOfDiversionCarriedOut); + } + + fun getNbrOfPollutionObservedByAuthorizedAgent( + illicitRejectsActions: List, + antiPollutionActions: List + ): Double { + val envNbrOfPollutionObservedByAuthorizedAgent = 0.0; //TODO: pollutionObservedByAuthorizedAgent from env + val navNbrOfPollutionObservedByAuthorizedAgent = + antiPollutionActions.filter { it?.pollutionObservedByAuthorizedAgent == true }.size; + return envNbrOfPollutionObservedByAuthorizedAgent.plus(navNbrOfPollutionObservedByAuthorizedAgent); + } + + private fun getAntiPollutionActions(navActions: List): List { + return navActions.filter { it.actionType == ActionType.ANTI_POLLUTION }; + } + + private fun getIllicitRejectActions(envActions: List): List { + val illicitRejects = listOf(19, 102); + return envActions.filter { + it?.controlPlans?.map { c -> c.themeId }?.intersect(illicitRejects) + ?.isEmpty() == false + }; + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMSeaSafety2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMSeaSafety2.kt new file mode 100644 index 000000000..1eb604534 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMSeaSafety2.kt @@ -0,0 +1,39 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.* +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils + +data class AEMSeaSafety2( + val nbrOfHourAtSea: Double? = 0.0, // 5.1 + val nbrOfHourPublicOrder: Double? = 0.0, // 5.3 + val nbrOfPublicOrderOperation: Double? = 0.0, // 5.4 +) { + constructor( + navActions: List + ) : this( + nbrOfHourAtSea = getNbrOfHourAtSea(navActions), + nbrOfPublicOrderOperation = getPublicOrderActions(navActions).size.toDouble(), + nbrOfHourPublicOrder = AEMUtils.getDurationInHours2(getPublicOrderActions(navActions)), + ) { + } + + companion object { + fun getNbrOfHourAtSea( + navActions: List + ): Double { + val otherActions = getOtherTargetActions(navActions) + val publicOrderActions = getPublicOrderActions(navActions) + return 0.0.plus(AEMUtils.getDurationInHours2(otherActions)) + .plus(AEMUtils.getDurationInHours2(publicOrderActions)) + } + + private fun getPublicOrderActions(navActions: List): List { + return navActions.filter { listOf(ActionType.PUBLIC_ORDER).contains(it.actionType) } + } + + private fun getOtherTargetActions(navActions: List): List { + return navActions.filter { listOf(ActionType.VIGIMER,ActionType.BAAEM_PERMANENCE, ActionType.NAUTICAL_EVENT).contains(it.actionType) } + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMSovereignProtect2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMSovereignProtect2.kt new file mode 100644 index 000000000..3c7370757 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMSovereignProtect2.kt @@ -0,0 +1,66 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VehicleTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionFishActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils +import java.time.Instant + +data class AEMSovereignProtect2( + val nbrOfHourAtSea: Double? = 0.0, // 7.1 + var nbrOfRecognizedVessel: Double? = 0.0, // 7.3 + val nbrOfControlledVessel: Double? = 0.0, // 7.4 +) { + constructor( + navActions: List, + envActions: List, + fishActions: List, + missionEndDateTime: Instant? + ) : this( + nbrOfHourAtSea = getNbrHourAtSea(navActions, missionEndDateTime), + nbrOfRecognizedVessel = getNbOfRecognizedVessel(navActions), + nbrOfControlledVessel = getNbrOfControlledVessel(navActions, envActions, fishActions) + ) + + companion object { + fun getNbrHourAtSea( + navActions: List, + missionEndDateTime: Instant? + ): Double { + val sortedStatusActions = + navActions.filter { it.actionType == ActionType.STATUS } + .sortedBy { it.startDateTimeUtc } + + sortedStatusActions.windowed(2) + .forEach { (first, second) -> first.endDateTimeUtc = second.startDateTimeUtc } + + if (sortedStatusActions.isNotEmpty()) sortedStatusActions.last().endDateTimeUtc = missionEndDateTime + val statusActions = getAnchoredActions(sortedStatusActions) + getNavigationActions(sortedStatusActions) + return AEMUtils.getDurationInHours2(statusActions) + } + + fun getNbOfRecognizedVessel(navActions: List): Double { + return 0.0 + } + + fun getNbrOfControlledVessel( + navActions: List, + envActions: List, + fishActions: List + ): Double { + return 0.0.plus(fishActions.size).plus(navActions.filter { it.actionType == ActionType.CONTROL }.size) + .plus(envActions.filter { it?.vehicleType == VehicleTypeEnum.VESSEL }.size) + } + + private fun getNavigationActions(navActions: List): List { + return navActions.filter { it?.status == ActionStatusType.NAVIGATING } + } + + private fun getAnchoredActions(navActions: List): List { + return navActions.filter { it?.status == ActionStatusType.ANCHORED } + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMTableExport2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMTableExport2.kt new file mode 100644 index 000000000..c06020f28 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMTableExport2.kt @@ -0,0 +1,58 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionFishActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import org.slf4j.LoggerFactory +import java.time.Instant + +data class AEMTableExport2( + val outOfMigrationRescue: AEMOutOfMigrationRescue2?, //1.1 + val migrationRescue: AEMMigrationRescue2?, //1.2 + val vesselRescue: AEMVesselRescue2?, // 2 + val envTraffic: AEMEnvTraffic2?, // 3.3 + val illegalImmigration: AEMIllegalImmigration2?, // 3.4 + val notPollutionControlSurveillance: AEMNotPollutionControlSurveillance2?, //4.1 + val pollutionControlSurveillance: AEMPollutionControlSurveillance2?, // 4.2 + val illegalFish: AEMIllegalFish2?, // 4.3 + val culturalMaritime: AEMCulturalMaritime2?, //4.4 + val seaSafety: AEMSeaSafety2?, // 5. + val sovereignProtect: AEMSovereignProtect2? // 7. +) { + private val logger = LoggerFactory.getLogger(AEMTableExport2::class.java) + + companion object { + fun fromMissionAction(navActions: List, + envActions: List, + fishActions: List, + missionEndDateTimeUtc: Instant?, + nbrOfRecognizedVessel: Double?): AEMTableExport2 { + return getAemTableExport2(navActions, envActions, fishActions, missionEndDateTimeUtc, nbrOfRecognizedVessel) + } + + private fun getAemTableExport2( + navActions: List, + envActions: List, + fishActions: List, + missionEndDateTimeUtc: Instant?, + nbrOfRecognizedVessel: Double? + ): AEMTableExport2 { + val tableExport = AEMTableExport2( + seaSafety = AEMSeaSafety2(navActions), + envTraffic = AEMEnvTraffic2(envActions), + illegalFish = AEMIllegalFish2(fishActions), + vesselRescue = AEMVesselRescue2(navActions), + migrationRescue = AEMMigrationRescue2(navActions), + culturalMaritime = AEMCulturalMaritime2(envActions), + illegalImmigration = AEMIllegalImmigration2(navActions), + outOfMigrationRescue = AEMOutOfMigrationRescue2(navActions), + sovereignProtect = AEMSovereignProtect2(navActions, envActions, fishActions, missionEndDateTimeUtc), + notPollutionControlSurveillance = AEMNotPollutionControlSurveillance2(envActions), + pollutionControlSurveillance = AEMPollutionControlSurveillance2(navActions, envActions) + ) + tableExport.sovereignProtect?.nbrOfRecognizedVessel = nbrOfRecognizedVessel + return tableExport + } + + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMVesselRescue2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMVesselRescue2.kt new file mode 100644 index 000000000..862c495ba --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/aem/v2/AEMVesselRescue2.kt @@ -0,0 +1,36 @@ +package fr.gouv.dgampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import fr.gouv.dgampa.rapportnav.domain.utils.AEMUtils + +data class AEMVesselRescue2( + val nbrOfHourAtSea: Double? = 0.0, // 2.1 + val nbrOfRescuedOperation: Double? = 0.0,// 2.3 + val nbrOfNoticedVessel: Double? = 0.0, // 2.4 + val nbrOfTowedVessel: Double? = 0.0, //2.7 +) { + constructor( + navActions: List + ) : this( + nbrOfRescuedOperation = getRescueActions(navActions).size.toDouble(), + nbrOfTowedVessel = getNbrOfTowedVessel(getRescueActions(navActions)), + nbrOfNoticedVessel = getNbrOfNoticedVessel(getRescueActions(navActions)), + nbrOfHourAtSea = AEMUtils.getDurationInHours2(getRescueActions(navActions)) + ) { + } + + companion object { + fun getNbrOfNoticedVessel(actionRescues: List): Double { + return actionRescues.filter { it?.isVesselNoticed == true }.size.toDouble(); + } + + fun getNbrOfTowedVessel(actionRescues: List): Double { + return actionRescues.filter { it?.isVesselTowed == true }.size.toDouble(); + } + + private fun getRescueActions(navActions: List): List { + return navActions.filter { it.actionType == ActionType.RESCUE && it.isVesselRescue == true } + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/export/v2/ExportMissionAEM2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/export/v2/ExportMissionAEM2.kt new file mode 100644 index 000000000..2c022fe9c --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/export/v2/ExportMissionAEM2.kt @@ -0,0 +1,93 @@ +package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.export.v2 + +import fr.gouv.dgampa.rapportnav.config.UseCase +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMTableExport2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.export.MissionExportEntity +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.GetEnvActionListByMissionId +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.GetEnvMissionById +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.GetFishActionListByMissionId +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.GetNavActionListByMissionId +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.generalInfo.GetMissionGeneralInfoByMissionId +import fr.gouv.dgampa.rapportnav.domain.use_cases.utils.FillAEMExcelRow +import fr.gouv.dgampa.rapportnav.infrastructure.utils.Base64Converter +import fr.gouv.dgampa.rapportnav.infrastructure.utils.office.ExportExcelFile +import fr.gouv.dgampa.rapportnav.infrastructure.utils.office.OfficeConverter +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Value +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.StandardCopyOption + +@UseCase +class ExportMissionAEM2( + @Value("\${rapportnav.aem.template.path}") private val aemTemplatePath: String, + @Value("\${rapportnav.aem.tmp_xlsx.path}") private val aemTmpXLSXPath: String, + @Value("\${rapportnav.aem.tmp_ods.path}") private val aemTmpODSPath: String, + private val fillAEMExcelRow: FillAEMExcelRow, + private val getEnvMissionById: GetEnvMissionById, + private val getEnvActionByMissionId: GetEnvActionListByMissionId, + private val getNavActionByMissionId: GetNavActionListByMissionId, + private val getFIshListActionByMissionId: GetFishActionListByMissionId, + private val getMissionGeneralInfoByMissionId: GetMissionGeneralInfoByMissionId, +) { + private val logger: Logger = LoggerFactory.getLogger(ExportMissionAEM2::class.java) + + fun execute(missionIds: List): MissionExportEntity? { + + val tableExportList = getAemTableExport(missionIds) + + return try { + val inputStream = javaClass.getResourceAsStream(aemTemplatePath) + ?: throw IllegalArgumentException("Template file not found: $aemTemplatePath") + + val tmpPath = Path.of(aemTmpXLSXPath) + Files.copy(inputStream, tmpPath, StandardCopyOption.REPLACE_EXISTING) + inputStream.close() + + logger.info("Template file copied to temporary path: $tmpPath") + + val excelFile = ExportExcelFile(tmpPath.toString()) + if (tableExportList.isNotEmpty()) { + var rowStart = 3 + + for (tableExport in tableExportList) { + fillAEMExcelRow.fill(tableExport, excelFile, "Synthese", rowStart) + rowStart++ + } + excelFile.save() + + logger.info("Excel file processed and saved for export on missions list") + + val odsFile = OfficeConverter().convert(tmpPath.toString(), aemTmpODSPath) + val base64Content = Base64Converter().convertToBase64(odsFile) + + return MissionExportEntity( + fileName = "Rapport_AEM.ods", + fileContent = base64Content + ) + } + + logger.error("Actions in missions list are null") + null + } catch (e: Exception) { + logger.error("An error occurred during mission processing", e) + null + } + } + + private fun getAemTableExport(missionIds: List) = missionIds.map { + val envMission = getEnvMissionById.execute(it) + val envActions = getEnvActionByMissionId.execute(it) + val navActions = getNavActionByMissionId.execute(it) + val fishActions = getFIshListActionByMissionId.execute(it) + val generalInfo = getMissionGeneralInfoByMissionId.execute(it) + AEMTableExport2.fromMissionAction( + navActions = navActions, + envActions = envActions, + fishActions = fishActions, + missionEndDateTimeUtc = envMission?.endDateTimeUtc, + nbrOfRecognizedVessel = generalInfo?.nbrOfRecognizedVessel?.toDouble() + ) + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/utils/FillAEMExcelRow.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/utils/FillAEMExcelRow.kt index 36923d3c2..6fe5f1170 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/utils/FillAEMExcelRow.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/utils/FillAEMExcelRow.kt @@ -2,6 +2,7 @@ package fr.gouv.dgampa.rapportnav.domain.use_cases.utils import fr.gouv.dgampa.rapportnav.config.UseCase import fr.gouv.dgampa.rapportnav.domain.entities.aem.AEMTableExport +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMTableExport2 import fr.gouv.dgampa.rapportnav.infrastructure.utils.office.ExportExcelFile @UseCase @@ -35,6 +36,133 @@ class FillAEMExcelRow { tableExport.migrationRescue?.nbrPersonsRescued?.let { excelFile.writeToCell(sheetName, "S$row", it) } + // 2 Assistance aux navires en difficulté et sécurité maritime + tableExport.vesselRescue?.nbrOfHourAtSea?.let { excelFile.writeToCell(sheetName, "U$row", it) } + tableExport.vesselRescue?.nbrOfRescuedOperation?.let { excelFile.writeToCell(sheetName, "W$row", it) } + tableExport.vesselRescue?.nbrOfNoticedVessel?.let { excelFile.writeToCell(sheetName, "X$row", it) } + tableExport.vesselRescue?.nbrOfTowedVessel?.let { excelFile.writeToCell(sheetName, "AA$row", it) } + + // 3.3) Lutte contre le trafic en mer d’espèces protégées + tableExport.envTraffic?.nbrOfHourAtSea?.let { excelFile.writeToCell(sheetName, "AV$row", it) } + tableExport.envTraffic?.nbrOfRedirectShip?.let { excelFile.writeToCell(sheetName, "AX$row", it) } + tableExport.envTraffic?.nbrOfSeizure?.let { excelFile.writeToCell(sheetName, "AY$row", it) } + + // 4.1) Surveillance et contrôles pour la protection de l'environnement (hors rejets illicites) + tableExport.notPollutionControlSurveillance?.nbrOfHourAtSea?.let { + excelFile.writeToCell( + sheetName, + "BH$row", + it + ) + } + tableExport.notPollutionControlSurveillance?.nbrOfAction?.let { excelFile.writeToCell(sheetName, "BJ$row", it) } + tableExport.notPollutionControlSurveillance?.nbrOfInfraction?.let { + excelFile.writeToCell( + sheetName, + "BK$row", + it + ) + } + tableExport.notPollutionControlSurveillance?.nbrOfInfractionWithNotice?.let { + excelFile.writeToCell( + sheetName, + "BL$row", + it + ) + } + + // 4.2) Répression contre les rejets illicites, lutte contre les pollutions + tableExport.pollutionControlSurveillance?.nbrOfHourAtSea?.let { excelFile.writeToCell(sheetName, "BN$row", it) } + tableExport.pollutionControlSurveillance?.nbrOfSimpleBrewingOperation?.let { + excelFile.writeToCell( + sheetName, + "BP$row", + it + ) + } + tableExport.pollutionControlSurveillance?.nbrOfAntiPolDeviceDeployed?.let { + excelFile.writeToCell( + sheetName, + "BQ$row", + it + ) + } + tableExport.pollutionControlSurveillance?.nbrOfInfraction?.let { + excelFile.writeToCell( + sheetName, + "BR$row", + it + ) + } + tableExport.pollutionControlSurveillance?.nbrOfInfractionWithNotice?.let { + excelFile.writeToCell( + sheetName, + "BS$row", + it + ) + } + tableExport.pollutionControlSurveillance?.nbrOfDiversionCarriedOut?.let { + excelFile.writeToCell( + sheetName, + "BT$row", + it + ) + } + tableExport.pollutionControlSurveillance?.nbrOfPollutionObservedByAuthorizedAgent?.let { + excelFile.writeToCell( + sheetName, + "BU$row", + it + ) + } + + // 4.3) Lutte contre les activités de pêche illégale + tableExport.illegalFish?.nbrOfHourAtSea?.let { excelFile.writeToCell(sheetName, "BW$row", it) } + tableExport.illegalFish?.nbrOfPolFishAction?.let { excelFile.writeToCell(sheetName, "BY$row", it) } + tableExport.illegalFish?.nbrOfTargetedVessel?.let { excelFile.writeToCell(sheetName, "CA$row", it) } + tableExport.illegalFish?.nbrOfInfractionWithPV?.let { excelFile.writeToCell(sheetName, "CB$row", it) } + tableExport.illegalFish?.nbrOfInfraction?.let { excelFile.writeToCell(sheetName, "CC$row", it) } + tableExport.illegalFish?.nbrOfSeizureAndDiversionVessel?.let { excelFile.writeToCell(sheetName, "CD$row", it) } + tableExport.illegalFish?.quantityOfFish?.let { excelFile.writeToCell(sheetName, "CE$row", it) } + + // 4.4) Protection des biens culturels maritimes + + // 7) Souveraineté et protection des intérêts nationaux + tableExport.sovereignProtect?.nbrOfHourAtSea?.let { excelFile.writeToCell(sheetName, "DA$row", it) } + tableExport.sovereignProtect?.nbrOfRecognizedVessel?.let { excelFile.writeToCell(sheetName, "DC$row", it) } + tableExport.sovereignProtect?.nbrOfControlledVessel?.let { excelFile.writeToCell(sheetName, "DD$row", it) } + } + + + //TODO: Remove as soon as there is just One AEMTableExport + fun fill(tableExport: AEMTableExport2, excelFile: ExportExcelFile, sheetName: String, row: Int) { + + //1.1 Sauvegarde de la vie humaine hors cadre d'un phénomène migratoire + tableExport.outOfMigrationRescue?.nbrOfHourAtSea?.let { excelFile.writeToCell(sheetName, "H$row", it) } + tableExport.outOfMigrationRescue?.nbrOfRescuedOperation?.let { excelFile.writeToCell(sheetName, "J$row", it) } + tableExport.outOfMigrationRescue?.nbrPersonsRescued?.let { excelFile.writeToCell(sheetName, "K$row", it) } + + //1.2 Sauvegarde de la vie humaine dans le cadre d'un phénomène migratoire + tableExport.migrationRescue?.nbrOfHourAtSea?.let { excelFile.writeToCell(sheetName, "M$row", it) } + tableExport.migrationRescue?.nbrOfOperation?.let { excelFile.writeToCell(sheetName, "O$row", it) } + tableExport.migrationRescue?.nbrOfVesselsTrackedWithoutIntervention?.let { + excelFile.writeToCell( + sheetName, + "P$row", + it + ) + } + tableExport.migrationRescue?.nbrAssistedVesselsReturningToShore?.let { + excelFile.writeToCell( + sheetName, + "Q$row", + it + ) + } + tableExport.migrationRescue?.nbrOfRescuedOperation?.let { excelFile.writeToCell(sheetName, "R$row", it) } + tableExport.migrationRescue?.nbrPersonsRescued?.let { excelFile.writeToCell(sheetName, "S$row", it) } + + // 2 Assistance aux navires en difficulté et sécurité maritime tableExport.vesselRescue?.nbrOfHourAtSea?.let { excelFile.writeToCell(sheetName, "U$row", it) } tableExport.vesselRescue?.nbrOfRescuedOperation?.let { excelFile.writeToCell(sheetName, "W$row", it) } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/utils/AEMUtils.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/utils/AEMUtils.kt index ba601c41e..8127249a2 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/utils/AEMUtils.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/utils/AEMUtils.kt @@ -2,6 +2,7 @@ package fr.gouv.dgampa.rapportnav.domain.utils import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.BaseAction import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ExtendedEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionActionEntity class AEMUtils { companion object { @@ -31,5 +32,16 @@ class AEMUtils { ) } } + + fun getDurationInHours2(actions: List): Double { + return actions.fold(0.0) { acc, action -> + acc.plus( + ComputeDurationUtils.durationInHours( + startDateTimeUtc = action?.startDateTimeUtc, + endDateTimeUtc = action?.endDateTimeUtc + ) + ) + } + } } } diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMCulturalMaritimeTest2.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMCulturalMaritimeTest2.kt new file mode 100644 index 000000000..87a261a84 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMCulturalMaritimeTest2.kt @@ -0,0 +1,57 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMCulturalMaritime2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.ActionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionControlPlanEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + +@SpringBootTest(classes = [AEMCulturalMaritime2::class]) +class AEMCulturalMaritimeTest2 { + + @Test + fun `Should init Cultural Maritime with different values`() { + val actions = extendedEnvActionEntities() + val culturalMaritime = AEMCulturalMaritime2(envActions = actions); + + assertThat(culturalMaritime).isNotNull(); + assertThat(culturalMaritime.nbrOfHourAtSea).isNotNull() + assertThat(culturalMaritime.nbrOfHourAtSea).isEqualTo(4.0); + assertThat(culturalMaritime.nbrOfBCMPoliceOperation).isEqualTo(2.0); + assertThat(culturalMaritime.nbrOfScientificOperation).isEqualTo(1.0); + } + + private fun extendedEnvActionEntities(): List { + val actions = listOf( + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.CONTROL, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 104, subThemeIds = listOf(143))), + startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + ), + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.SURVEILLANCE, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 101, subThemeIds = listOf(165))), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + ), + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.SURVEILLANCE, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 104, subThemeIds = listOf(67))), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T05:00:00.000+01:00"), + ) + ); + return actions + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMEnvTrafficTest2.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMEnvTrafficTest2.kt new file mode 100644 index 000000000..92f5c16ff --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMEnvTrafficTest2.kt @@ -0,0 +1,56 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.AEMEnvTraffic +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMEnvTraffic2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.ActionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionControlEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionControlPlanEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionSurveillanceEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ExtendedEnvActionControlEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ExtendedEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ExtendedEnvActionSurveillanceEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import fr.gouv.gmampa.rapportnav.mocks.mission.action.ExtendedEnvActionEntityMock +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + +@SpringBootTest(classes = [AEMEnvTraffic2::class]) +class AEMEnvTrafficTest2 { + + @Test + fun `Should init Env traffic with different values`() { + val actions = extendedEnvActionEntities() + val envTraffic = AEMEnvTraffic2(envActions = actions); + + assertThat(envTraffic).isNotNull(); + assertThat(envTraffic.nbrOfHourAtSea).isNotNull() + assertThat(envTraffic.nbrOfHourAtSea).isEqualTo(2.0); + assertThat(envTraffic.nbrOfSeizure).isEqualTo(0.0); + assertThat(envTraffic.nbrOfRedirectShip).isEqualTo(0.0); + } + + private fun extendedEnvActionEntities(): List { + val actions = listOf( + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.CONTROL, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 101)), + startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + ), + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.SURVEILLANCE, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 103)), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + ) + ); + return actions + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMIllegalFishTest2.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMIllegalFishTest2.kt new file mode 100644 index 000000000..30e2fcbb5 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMIllegalFishTest2.kt @@ -0,0 +1,68 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.AEMIllegalFish +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMIllegalFish2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.ActionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.* +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ExtendedFishActionControlEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ExtendedFishActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionFishActionEntity +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionFishAction +import fr.gouv.gmampa.rapportnav.mocks.mission.action.ExtendedFishActionEntityMock +import fr.gouv.gmampa.rapportnav.mocks.mission.action.FishActionControlMock +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + + +@SpringBootTest(classes = [AEMIllegalFish2::class]) +class AEMIllegalFishTest2 { + + @Test + fun `Should init illegal fish with different values`() { + val actions = extendedFishActionEntities() + val illegalImmigration = AEMIllegalFish2(fishActions = actions); + + assertThat(illegalImmigration).isNotNull(); + assertThat(illegalImmigration.quantityOfFish).isEqualTo(6.0); + assertThat(illegalImmigration.nbrOfHourAtSea).isEqualTo(3.0); + assertThat(illegalImmigration.nbrOfInfraction).isEqualTo(4.0); + assertThat(illegalImmigration.nbrOfPolFishAction).isEqualTo(2.0); + assertThat(illegalImmigration.nbrOfInfractionWithPV).isEqualTo(4.0); + } + + private fun extendedFishActionEntities(): List { + val actions = listOf( + MissionFishActionEntity( + missionId = 761, + id = 234, + fishActionType = MissionActionType.SEA_CONTROL, + speciesInfractions = listOf(), + gearInfractions = listOf(GearInfraction(infractionType = InfractionType.WITH_RECORD)), + otherInfractions = listOf(OtherInfraction()), + logbookInfractions = listOf(LogbookInfraction(infractionType = InfractionType.WITHOUT_RECORD, natinf = 27688)), + actionDatetimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + actionEndDatetimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + speciesQuantitySeized = 4 + ), + MissionFishActionEntity( + missionId = 761, + id = 234, + fishActionType = MissionActionType.SEA_CONTROL, + logbookInfractions = listOf(LogbookInfraction()), + gearInfractions = listOf(GearInfraction(infractionType = InfractionType.WITH_RECORD, natinf = 49558)), + otherInfractions = listOf(OtherInfraction(infractionType = InfractionType.WITH_RECORD, natinf = 98308)), + speciesInfractions = listOf( + SpeciesInfraction(infractionType = InfractionType.WITH_RECORD), + SpeciesInfraction(infractionType = InfractionType.WITHOUT_RECORD, natinf = 203839) + ), + actionDatetimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + actionEndDatetimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + speciesQuantitySeized = 2 + ) + ); + return actions + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMIllegalImmigrationTest2.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMIllegalImmigrationTest2.kt new file mode 100644 index 000000000..e93c70038 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMIllegalImmigrationTest2.kt @@ -0,0 +1,66 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.AEMIllegalImmigration +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMIllegalImmigration2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionIllegalImmigrationEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.NavActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + +@SpringBootTest(classes = [AEMIllegalImmigration2::class]) +class AEMIllegalImmigrationTest2 { + + @Test + fun `Should init illegal immigration with different values`() { + val nbrOfHourAtSea = 3.0; + val nbrOfInterceptedVessel = 5.0; + val nbrOfInterceptedMigrant = 14.0; + val nbrOfSuspectedSmuggler = 2.0; + val actions = navActionEntities() + val illegalImmigration = AEMIllegalImmigration2(navActions = actions); + + assertThat(illegalImmigration).isNotNull(); + assertThat(illegalImmigration.nbrOfHourAtSea).isEqualTo(nbrOfHourAtSea); + assertThat(illegalImmigration.nbrOfInterceptedVessel).isEqualTo(nbrOfInterceptedVessel); + assertThat(illegalImmigration.nbrOfInterceptedMigrant).isEqualTo(nbrOfInterceptedMigrant); + assertThat(illegalImmigration.nbrOfSuspectedSmuggler).isEqualTo(nbrOfSuspectedSmuggler); + } + + private fun navActionEntities(): List { + val actions = listOf( + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.RESCUE, + startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00") + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ILLEGAL_IMMIGRATION, + startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + nbOfInterceptedVessels = 1, + nbOfInterceptedMigrants = 5, + nbOfSuspectedSmugglers = 0, + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ILLEGAL_IMMIGRATION, + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + nbOfInterceptedVessels = 4, + nbOfInterceptedMigrants = 9, + nbOfSuspectedSmugglers = 2, + ) + ); + return actions + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMMigrationRescueTest2.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMMigrationRescueTest2.kt new file mode 100644 index 000000000..84de50221 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMMigrationRescueTest2.kt @@ -0,0 +1,73 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMMigrationRescue2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + + +@SpringBootTest(classes = [AEMMigrationRescue2::class]) +class AEMMigrationRescueTest2 { + + @Test + fun `Should init migration rescue with different values`() { + val nbrOfHourAtSea = 2.0; + val nbrOfOperation = 1.0; + val nbrPersonsRescued = 2.0; + val nbrAssistedVesselsReturningToShore = 1.0; + val nbrOfVesselsTrackedWithoutIntervention = 5.0; + + val actions = navActionEntities() + val migrationRescue = AEMMigrationRescue2(navActions = actions); + + assertThat(migrationRescue).isNotNull(); + assertThat(migrationRescue.nbrOfHourAtSea).isEqualTo(nbrOfHourAtSea); + assertThat(migrationRescue.nbrPersonsRescued).isEqualTo(nbrPersonsRescued); + assertThat(migrationRescue.nbrOfOperation).isEqualTo(nbrOfOperation); + assertThat(migrationRescue.nbrAssistedVesselsReturningToShore).isEqualTo(nbrAssistedVesselsReturningToShore); + assertThat(migrationRescue.nbrOfVesselsTrackedWithoutIntervention).isEqualTo( + nbrOfVesselsTrackedWithoutIntervention + ); + } + + private fun navActionEntities(): List { + val actions = listOf( + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ILLEGAL_IMMIGRATION, + startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00") + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ILLEGAL_IMMIGRATION, + startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + observations = "", + numberPersonsRescued = 0, + numberOfDeaths = 0, + isMigrationRescue = false + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.RESCUE, + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + observations = "", + numberPersonsRescued = 2, + numberOfDeaths = 0, + isMigrationRescue = true, + nbAssistedVesselsReturningToShore = 1, + nbOfVesselsTrackedWithoutIntervention = 5 + ) + ); + return actions + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMNotPollutionControlSurveillanceTest2.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMNotPollutionControlSurveillanceTest2.kt new file mode 100644 index 000000000..f518c7236 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMNotPollutionControlSurveillanceTest2.kt @@ -0,0 +1,84 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMNotPollutionControlSurveillance2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.* +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + +@SpringBootTest(classes = [AEMNotPollutionControlSurveillance2::class]) +class AEMNotPollutionControlSurveillanceTest2 { + + @Test + fun `Should init not pollution control surveillance with different values`() { + val nbrOfHourAtSea = 4.5 + val nbrOfInfraction = 6.0 + val nbrOfInfractionWithNotice = 2.0 + + val actions = extendedEnvActionEntities() + val notPollution = AEMNotPollutionControlSurveillance2(envActions = actions) + + assertThat(notPollution).isNotNull() + assertThat(notPollution.nbrOfHourAtSea).isEqualTo(nbrOfHourAtSea) + assertThat(notPollution.nbrOfInfraction).isEqualTo(nbrOfInfraction) + assertThat(notPollution.nbrOfInfractionWithNotice).isEqualTo(nbrOfInfractionWithNotice) + } + + private fun extendedEnvActionEntities(): List { + val actions = listOf( + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.CONTROL, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 101)), + startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T04:30:00.000+01:00"), + envInfractions = listOf( + InfractionEntity( + id = "", + toProcess = false, + formalNotice = FormalNoticeEnum.YES, + infractionType = InfractionTypeEnum.WITH_REPORT, + natinf = listOf("natinf-1", "natinf-2", "natinf-3"), + ), + InfractionEntity( + id = "", + toProcess = false, + formalNotice = FormalNoticeEnum.NO, + infractionType = InfractionTypeEnum.WITHOUT_REPORT, + natinf = listOf("natinf-1") + + ), + InfractionEntity( + id = "", + toProcess = false, + formalNotice = FormalNoticeEnum.YES, + infractionType = InfractionTypeEnum.WITH_REPORT, + natinf = listOf("natinf-1", "natinf-2") + ) + ) + ), + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.SURVEILLANCE, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 19)), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + ), + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.SURVEILLANCE, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 102)), + startDateTimeUtc = Instant.parse("2019-09-09T12:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T16:00:00.000+01:00"), + ) + + ) + return actions + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMOutOfMigrationRescue2Test.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMOutOfMigrationRescue2Test.kt new file mode 100644 index 000000000..b337af5b1 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMOutOfMigrationRescue2Test.kt @@ -0,0 +1,132 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMOutOfMigrationRescue2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionRescueEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.NavActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + + +@SpringBootTest(classes = [AEMOutOfMigrationRescue2::class]) +class AEMOutOfMigrationRescue2Test { + + @Test + fun `Should init out fo migration rescue with different values`() { + val nbrOfHourAtSea = 3.0; + val nbrPersonsRescued = 4.0; + val nbrOfRescuedOperation = 1.0; + + val actions = navActionEntities() + val migrationRescue = AEMOutOfMigrationRescue2(navActions = actions); + + assertThat(migrationRescue).isNotNull(); + assertThat(migrationRescue.nbrOfHourAtSea).isEqualTo(nbrOfHourAtSea); + assertThat(migrationRescue.nbrPersonsRescued).isEqualTo(nbrPersonsRescued); + assertThat(migrationRescue.nbrOfRescuedOperation).isEqualTo(nbrOfRescuedOperation); + } + + @Test + fun `Should not thow null pointer exception event if nbrPersonsRescued is null`() { + val action = MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ILLEGAL_IMMIGRATION, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + numberPersonsRescued = null, + numberOfDeaths = 0, + isMigrationRescue = false, + ) + val migrationRescue = AEMOutOfMigrationRescue2(navActions = listOf(action)); + assertThat(migrationRescue).isNotNull(); + assertThat(migrationRescue.nbrPersonsRescued).isEqualTo(0.0); + } + + private fun navActionEntities(): List { + val actions = listOf( + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ILLEGAL_IMMIGRATION, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00") + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.RESCUE, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + observations = "", + numberPersonsRescued = 4, + numberOfDeaths = 0, + isMigrationRescue = false + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.RESCUE, + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + observations = "", + numberPersonsRescued = 2, + numberOfDeaths = 0, + isMigrationRescue = true, + nbAssistedVesselsReturningToShore = 1, + nbOfVesselsTrackedWithoutIntervention = 5 + ) + ); + return actions + } +} + +val actions = listOf( + NavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ILLEGAL_IMMIGRATION, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00") + ), + NavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ILLEGAL_IMMIGRATION, + startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + rescueAction = ActionRescueEntity( + missionId = 761, + id = UUID.randomUUID(), + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + observations = "", + numberPersonsRescued = 4, + numberOfDeaths = 0, + isMigrationRescue = false + ) + ), + NavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.RESCUE, + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + rescueAction = ActionRescueEntity( + missionId = 761, + id = UUID.randomUUID(), + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + observations = "", + numberPersonsRescued = 2, + numberOfDeaths = 0, + isMigrationRescue = true, + nbAssistedVesselsReturningToShore = 1, + nbOfVesselsTrackedWithoutIntervention = 5 + ) + ) +); diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMPolllutionControlSurveillanceTest2.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMPolllutionControlSurveillanceTest2.kt new file mode 100644 index 000000000..252eccf25 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMPolllutionControlSurveillanceTest2.kt @@ -0,0 +1,123 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMPollutionControlSurveillance2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.* +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.* +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + + +@SpringBootTest(classes = [AEMPollutionControlSurveillance2::class]) +class AEMPolllutionControlSurveillanceTest2 { + + @Test + fun `Should init pollution control surveillance with different values`() { + val nbrOfHourAtSea = 8.0; + val nbrOfInfraction = 5.0; + val nbrOfInfractionWithNotice = 1.0; + val nbrOfDiversionCarriedOut = 1.0; + val nbrOfSimpleBrewingOperation = 2.0; + val nbrOfAntiPolDeviceDeployed = 1.0; + val nbrOfPollutionObservedByAuthorizedAgent = 1.0; + + val actions = navActionEntities(); + val extendedActions = extendedEnvActionEntities(); + val pollutionControl = AEMPollutionControlSurveillance2(navActions = actions, envActions = extendedActions); + + assertThat(pollutionControl).isNotNull(); + assertThat(pollutionControl.nbrOfHourAtSea).isEqualTo(nbrOfHourAtSea); + assertThat(pollutionControl.nbrOfInfraction).isEqualTo(nbrOfInfraction); + assertThat(pollutionControl.nbrOfInfractionWithNotice).isEqualTo(nbrOfInfractionWithNotice); + assertThat(pollutionControl.nbrOfDiversionCarriedOut).isEqualTo(nbrOfDiversionCarriedOut); + assertThat(pollutionControl.nbrOfSimpleBrewingOperation).isEqualTo(nbrOfSimpleBrewingOperation); + assertThat(pollutionControl.nbrOfAntiPolDeviceDeployed).isEqualTo(nbrOfAntiPolDeviceDeployed); + assertThat(pollutionControl.nbrOfPollutionObservedByAuthorizedAgent).isEqualTo( + nbrOfPollutionObservedByAuthorizedAgent + ); + } + + private fun extendedEnvActionEntities(): List { + val actions = listOf( + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.CONTROL, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 102)), + startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + envInfractions = listOf( + InfractionEntity( + id = "", + infractionType = InfractionTypeEnum.WITH_REPORT, + formalNotice = FormalNoticeEnum.YES, + toProcess = false, + natinf = listOf("natinf-1", "natinf-2", "natinf-3"), + ), + InfractionEntity( + id = "", + infractionType = InfractionTypeEnum.WITHOUT_REPORT, + formalNotice = FormalNoticeEnum.NO, + toProcess = false, + natinf = listOf("natinf-1", "natinf-2"), + ) + ), + ), + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.SURVEILLANCE, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 19)), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + ), + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.SURVEILLANCE, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 100)), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + ) + ); + return actions + } + + private fun navActionEntities(): List { + val actions = listOf( + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ILLEGAL_IMMIGRATION, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00") + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ANTI_POLLUTION, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + observations = "", + isAntiPolDeviceDeployed = true, + isSimpleBrewingOperationDone = true, + diversionCarriedOut = true + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ANTI_POLLUTION, + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + observations = "", + isSimpleBrewingOperationDone = true, + pollutionObservedByAuthorizedAgent = true + ) + ); + return actions + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMSeaSafetyTest2.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMSeaSafetyTest2.kt new file mode 100644 index 000000000..7c8908924 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMSeaSafetyTest2.kt @@ -0,0 +1,73 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMSeaSafety2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + + +@SpringBootTest(classes = [AEMSeaSafety2::class]) +class AEMSeaSafetyTest2 { + + @Test + fun `Should init Sea safety with different values`() { + val nbrOfHourAtSea = 14.0; + val nbrOfHourPublicOrder = 5.0; + val nbrOfPublicOrderOperation = 2.0; + + val actions = navActionEntities(); + val seaSafety = AEMSeaSafety2(navActions = actions); + + assertThat(seaSafety).isNotNull(); + assertThat(seaSafety.nbrOfHourAtSea).isEqualTo(nbrOfHourAtSea); + assertThat(seaSafety.nbrOfHourPublicOrder).isEqualTo(nbrOfHourPublicOrder); + assertThat(seaSafety.nbrOfPublicOrderOperation).isEqualTo(nbrOfPublicOrderOperation); + } + + private fun navActionEntities(): List { + val actions = listOf( + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.BAAEM_PERMANENCE, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00") + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.VIGIMER, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.NAUTICAL_EVENT, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.PUBLIC_ORDER, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + observations = "", + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.PUBLIC_ORDER, + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + observations = "" + ) + ); + return actions + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMSovereignProtectTest2.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMSovereignProtectTest2.kt new file mode 100644 index 000000000..132ebdfa4 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMSovereignProtectTest2.kt @@ -0,0 +1,116 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMSovereignProtect2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.ActionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionControlPlanEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VehicleTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.MissionActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.* +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlMethod +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionFishActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + + +@SpringBootTest(classes = [AEMSovereignProtect2::class]) +class AEMSovereignProtectTest2 { + + @Test + fun `Should init sovereign protect with different values`() { + val nbrOfHourAtSea = 147.0; + val nbrOfRecognizedVessel = 0.0; + val nbrOfControlledVessel = 4.0; + + val navActions = getNavActions(); + val envActions = getEnvActions(); + val fishActions = getFishActions(); + val missionEndDate = Instant.parse("2019-09-15T01:00:00.000+01:00"); + + val sovereign = AEMSovereignProtect2(navActions, envActions, fishActions, missionEndDate); + + assertThat(sovereign).isNotNull(); + assertThat(sovereign.nbrOfHourAtSea).isEqualTo(nbrOfHourAtSea); + assertThat(sovereign.nbrOfRecognizedVessel).isEqualTo(nbrOfRecognizedVessel); + assertThat(sovereign.nbrOfControlledVessel).isEqualTo(nbrOfControlledVessel); + } + + private fun getNavActions(): List { + val actions = listOf( + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.CONTROL, + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + controlMethod = ControlMethod.SEA + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.STATUS, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + status = ActionStatusType.ANCHORED + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.STATUS, + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + status = ActionStatusType.NAVIGATING + ) + ); + return actions + } + + private fun getEnvActions(): List { + val actions = listOf( + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.CONTROL, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 102)), + startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + vehicleType = VehicleTypeEnum.VEHICLE_LAND + ), + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.CONTROL, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 102)), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + vehicleType = VehicleTypeEnum.VESSEL + ) + ); + return actions + } + + private fun getFishActions(): List { + val actions = listOf( + MissionFishActionEntity( + missionId = 761, + id = 234, + fishActionType = MissionActionType.SEA_CONTROL, + actionDatetimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + actionEndDatetimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + ), + MissionFishActionEntity( + missionId = 761, + id = 234, + fishActionType = MissionActionType.SEA_CONTROL, + actionDatetimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + actionEndDatetimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + ) + ); + return actions + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMTableExportTest2.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMTableExportTest2.kt new file mode 100644 index 000000000..c37a7064f --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMTableExportTest2.kt @@ -0,0 +1,76 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMTableExport2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.ActionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionControlPlanEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.* +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.* +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionFishActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + + +@SpringBootTest(classes = [AEMTableExport2::class]) +class AEMTableExportTest2 { + + @Test + fun `Should init Table export with different values from mission entity with nbrOfVesselRecognized`() { + val nbrOfRecognizedVessel = 9; + val envActions = listOf( + MissionEnvActionEntity( + missionId = 761, + id = UUID.randomUUID(), + envActionType = ActionTypeEnum.CONTROL, + controlPlans = listOf(EnvActionControlPlanEntity(themeId = 101)), + startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + ) + ) + val navActions = listOf( + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ILLEGAL_IMMIGRATION, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + ) + ) + val fishActions = listOf(MissionFishActionEntity( + missionId = 761, + id = 234, + fishActionType = MissionActionType.SEA_CONTROL, + speciesInfractions = listOf(), + otherInfractions = listOf(OtherInfraction()), + actionDatetimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"), + actionEndDatetimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + gearInfractions = listOf(GearInfraction(infractionType = InfractionType.WITH_RECORD)), + logbookInfractions = listOf(LogbookInfraction(infractionType = InfractionType.WITHOUT_RECORD)) + )) + + val export = AEMTableExport2.fromMissionAction( + fishActions = fishActions, + navActions = navActions, + envActions = envActions, + nbrOfRecognizedVessel = nbrOfRecognizedVessel.toDouble(), + missionEndDateTimeUtc = Instant.parse("2019-09-17T01:00:00.000+01:00") + ) + assertThat(export).isNotNull(); + assertThat(export.seaSafety).isNotNull(); + assertThat(export.envTraffic).isNotNull(); + assertThat(export.illegalFish).isNotNull(); + assertThat(export.vesselRescue).isNotNull(); + assertThat(export.migrationRescue).isNotNull(); + assertThat(export.sovereignProtect).isNotNull(); + assertThat(export.culturalMaritime).isNotNull(); + assertThat(export.illegalImmigration).isNotNull(); + assertThat(export.outOfMigrationRescue).isNotNull(); + assertThat(export.pollutionControlSurveillance).isNotNull(); + assertThat(export.notPollutionControlSurveillance).isNotNull(); + assertThat(export.sovereignProtect?.nbrOfRecognizedVessel).isEqualTo(nbrOfRecognizedVessel.toDouble()); + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMVesselRescueTest2.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMVesselRescueTest2.kt new file mode 100644 index 000000000..ae016a53f --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/aem/v2/AEMVesselRescueTest2.kt @@ -0,0 +1,75 @@ +package fr.gouv.gmampa.rapportnav.domain.entities.aem.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.aem.AEMVesselRescue +import fr.gouv.dgampa.rapportnav.domain.entities.aem.v2.AEMVesselRescue2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionRescueEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.NavActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest +import java.time.Instant +import java.util.* + + +@SpringBootTest(classes = [AEMVesselRescue2::class]) +class AEMVesselRescueTest2 { + + @Test + fun `Should init vessel rescue with different values`() { + val nbrOfHourAtSea = 5.0; + val nbrOfTowedVessel = 2.0; + val nbrOfNoticedVessel = 1.0; + val nbrOfRescuedOperation = 2.0; + + val actions = getNavActions() + val vesselRescue = AEMVesselRescue2(navActions = actions); + + assertThat(vesselRescue).isNotNull(); + assertThat(vesselRescue.nbrOfHourAtSea).isEqualTo(nbrOfHourAtSea); + assertThat(vesselRescue.nbrOfTowedVessel).isEqualTo(nbrOfTowedVessel); + assertThat(vesselRescue.nbrOfNoticedVessel).isEqualTo(nbrOfNoticedVessel); + assertThat(vesselRescue.nbrOfRescuedOperation).isEqualTo(nbrOfRescuedOperation); + } + + private fun getNavActions(): List { + val actions = listOf( + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.ILLEGAL_IMMIGRATION, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00") + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.RESCUE, + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + observations = "", + numberPersonsRescued = 4, + numberOfDeaths = 0, + isVesselRescue = true, + isVesselTowed = true, + isVesselNoticed = true + ), + MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.RESCUE, + endDateTimeUtc = Instant.parse("2019-09-09T04:00:00.000+01:00"), + startDateTimeUtc = Instant.parse("2019-09-09T02:00:00.000+01:00"), + observations = "", + numberPersonsRescued = 2, + numberOfDeaths = 0, + isVesselRescue = true, + isVesselTowed = true, + isVesselNoticed = false + ) + ); + return actions + } +} From d071f8ab1c7578cbfc591e2c1708fad6ada5d0c9 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 7 Jan 2025 12:07:20 +0100 Subject: [PATCH 2/2] feat(env-mission): getEnv Mission -Just getEnv mission without any composition --- .../mission/action/v2/GetEnvMissionById.kt | 28 ++++++++++ .../mission/v2/GetEnvMissionByIdTest.kt | 52 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/GetEnvMissionById.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/v2/GetEnvMissionByIdTest.kt diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/GetEnvMissionById.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/GetEnvMissionById.kt new file mode 100644 index 000000000..77927e2d9 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/GetEnvMissionById.kt @@ -0,0 +1,28 @@ +package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2 + +import fr.gouv.dgampa.rapportnav.config.UseCase +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionEntity +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.IEnvMissionRepository +import org.slf4j.LoggerFactory +import org.springframework.cache.annotation.Cacheable + +@UseCase +class GetEnvMissionById( + private val monitorEnvApiRepo: IEnvMissionRepository +) { + private val logger = LoggerFactory.getLogger(GetEnvMissionById::class.java) + + @Cacheable(value = ["envMission"], key = "#missionId") + fun execute(missionId: Int?): MissionEntity? { + if (missionId == null) { + logger.error("GetEnvMissionById received a null missionId") + throw IllegalArgumentException("GetEnvMissionById should not receive null missionId") + } + return try { + monitorEnvApiRepo.findMissionById(missionId = missionId) + } catch (e: Exception) { + logger.error("GetEnvMissionById failed loading mission", e) + return null + } + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/v2/GetEnvMissionByIdTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/v2/GetEnvMissionByIdTest.kt new file mode 100644 index 000000000..43f1b0936 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/v2/GetEnvMissionByIdTest.kt @@ -0,0 +1,52 @@ +package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.IEnvMissionRepository +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.GetEnvMissionById +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Test +import org.mockito.Mockito.* +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.boot.test.mock.mockito.MockBean +import java.time.Instant + +@SpringBootTest(classes = [GetEnvMissionById::class]) +class GetEnvMissionByIdTest { + + @Autowired + private lateinit var getEnvMissionById: GetEnvMissionById + + @MockBean + private lateinit var monitorEnvApiRepo: IEnvMissionRepository + + @Test + fun `execute should return extended mission from inputEnvMission`() { + val missionId = 761 + // Given + val missionEntity = MissionEntity( + missionTypes = listOf(MissionTypeEnum.SEA), + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + hasMissionOrder = false, + envActions = listOf(), + isDeleted = false, + isUnderJdp = false, + isGeometryComputedFromControls = false, + missionSource = MissionSourceEnum.MONITORENV + ) + + // Mock behavior of findMissionById to return a MissionEntity + `when`(monitorEnvApiRepo.findMissionById(missionId)).thenReturn(missionEntity) + + getEnvMissionById = GetEnvMissionById(monitorEnvApiRepo) + + // When + val result = getEnvMissionById.execute(missionId) + + // Then + assertNotNull(result) + } + +}