From 8163bee7690c229cbe9dec6c18030e6935644f3a Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 11 Dec 2024 09:47:49 +0100 Subject: [PATCH 1/9] feat(action): update mission action - GraphQl definition of controller method and input - useCase of update env, nav, fish - useCase of compute controls - useCase of compute infractions - useCase of compute infraction env target - Tests --- .../mission/nav/control/BaseControlEntity.kt | 19 ++ .../control/ControlAdministrativeEntity.kt | 21 ++- .../nav/control/ControlGensDeMerEntity.kt | 21 ++- .../nav/control/ControlNavigationEntity.kt | 15 +- .../nav/control/ControlSecurityEntity.kt | 15 +- .../nav/control/v2/ActionControlEntity.kt | 23 +++ .../mission/v2/BaseMissionFishAction.kt | 36 ++-- .../mission/v2/MissionFishActionEntity.kt | 118 ++++++------- .../mission/action/v2/GetEnvActionById.kt | 15 ++ .../mission/action/v2/UpdateEnvAction.kt | 44 +++++ .../mission/action/v2/UpdateFishAction.kt | 43 +++++ .../mission/action/v2/UpdateNavAction.kt | 34 ++++ .../control/v2/ProcessMissionActionControl.kt | 98 +++++++++++ .../v2/ProcessMissionActionInfraction.kt | 38 ++++ ...ProcessMissionActionInfractionEnvTarget.kt | 58 ++++++ .../v2/BaseMissionNavActionDataInput.kt | 39 +++++ .../bff/adapters/v2/MissionActionDataInput.kt | 17 ++ .../api/bff/adapters/v2/MissionActionInput.kt | 15 ++ .../adapters/v2/MissionEnvActionDataInput.kt | 48 +++++ .../adapters/v2/MissionFishActionDataInput.kt | 48 +++++ .../adapters/v2/MissionNavActionDataInput.kt | 106 +++++++++++ .../v2/BaseMissionFishActionDataOutput.kt | 28 +-- .../api/bff/model/v2/MissionActionOutput.kt | 3 +- .../model/v2/MissionFishActionDataOutput.kt | 14 +- .../bff/model/v2/MissionFishActionOutput.kt | 16 +- .../bff/{ => v2}/MissionActionController.kt | 8 +- .../ControlAdministrativeEntityTest.kt | 30 ++++ .../nav/control/ControlGensDeMerEntityTest.kt | 32 ++++ .../control/ControlNavigationEntityTest.kt | 27 +++ .../nav/control/ControlSecurityEntityTest.kt | 26 +++ .../mission/action/GetEnvActionByIdTest.kt | 12 +- .../action/ProcessMissionActionControlTest.kt | 96 ++++++++++ ...ssMissionActionInfractionEnvTargetTest .kt | 165 ++++++++++++++++++ .../ProcessMissionActionInfractionTest.kt | 130 ++++++++++++++ .../mission/action/UpdateEnvActionTest.kt | 68 ++++++++ .../mission/action/UpdateFishActionTest.kt | 66 +++++++ .../mission/action/UpdateNavActionTest.kt | 101 +++++++++++ ...trolTest.kt => AddOrProcessControlTest.kt} | 2 +- .../mocks/mission/action/ControlMock.kt | 38 ++-- 39 files changed, 1603 insertions(+), 130 deletions(-) create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateEnvAction.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateFishAction.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateNavAction.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControl.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfraction.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfractionEnvTarget.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/BaseMissionNavActionDataInput.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionInput.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt rename backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/{ => v2}/MissionActionController.kt (83%) create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionControlTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionEnvTargetTest .kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateNavActionTest.kt rename backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/control/{AddOrUpdateControlTest.kt => AddOrProcessControlTest.kt} (99%) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/BaseControlEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/BaseControlEntity.kt index 58b01535..a30f480c 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/BaseControlEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/BaseControlEntity.kt @@ -12,4 +12,23 @@ abstract class BaseControlEntity { open val observations: String? = null open val hasBeenDone: Boolean? = null abstract fun shouldToggleOnUnitHasConfirmed(): Boolean + + + override fun hashCode(): Int { + var result = id.hashCode() + result = 31 * result + actionControlId.hashCode() + result = 31 * result + (observations?.hashCode() ?: 0) + result = 31 * result + (hasBeenDone?.hashCode() ?: 0) + return result + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + other as BaseControlEntity + return (id == other.id + && hasBeenDone == other.hasBeenDone + && observations == other.observations + && actionControlId == other.actionControlId) + } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlAdministrativeEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlAdministrativeEntity.kt index 325c14dc..6e28cf4d 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlAdministrativeEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlAdministrativeEntity.kt @@ -15,7 +15,7 @@ data class ControlAdministrativeEntity( val compliantSecurityDocuments: ControlResult? = null, override val observations: String? = null, override val hasBeenDone: Boolean? = null, - override val infractions: List? = null + override var infractions: List? = null ) : BaseControlEntity() { override fun shouldToggleOnUnitHasConfirmed(): Boolean = unitShouldConfirm == true && @@ -26,4 +26,23 @@ data class ControlAdministrativeEntity( infractions?.isNotEmpty() == true || observations != null ) + + override fun hashCode(): Int { + var result = missionId.hashCode() + result = 31 * result + amountOfControls + result = 31 * result + (compliantOperatingPermit?.hashCode() ?: 0) + result = 31 * result + (upToDateNavigationPermit?.hashCode() ?: 0) + result = 31 * result + (compliantSecurityDocuments?.hashCode() ?: 0) + return super.hashCode() + result + } + + override fun equals(other: Any?): Boolean { + if (!super.equals(other)) return false + other as ControlAdministrativeEntity + return (missionId == other.missionId + && amountOfControls == other.amountOfControls + && compliantOperatingPermit == other.compliantOperatingPermit + && upToDateNavigationPermit == other.upToDateNavigationPermit + && compliantSecurityDocuments == other.compliantSecurityDocuments) + } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlGensDeMerEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlGensDeMerEntity.kt index 9ae67692..5d026243 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlGensDeMerEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlGensDeMerEntity.kt @@ -15,7 +15,7 @@ data class ControlGensDeMerEntity( val knowledgeOfFrenchLawAndLanguage: ControlResult? = null, override val observations: String? = null, override val hasBeenDone: Boolean? = null, - override val infractions: List? = null + override var infractions: List? = null ) : BaseControlEntity() { override fun shouldToggleOnUnitHasConfirmed(): Boolean = unitShouldConfirm == true && @@ -26,4 +26,23 @@ data class ControlGensDeMerEntity( infractions?.isNotEmpty() == true || observations != null ) + + override fun hashCode(): Int { + var result = missionId.hashCode() + result = 31 * result + amountOfControls + result = 31 * result + (staffOutnumbered?.hashCode() ?: 0) + result = 31 * result + (upToDateMedicalCheck?.hashCode() ?: 0) + result = 31 * result + (knowledgeOfFrenchLawAndLanguage?.hashCode() ?: 0) + return super.hashCode() + result + } + + override fun equals(other: Any?): Boolean { + if (!super.equals(other)) return false + other as ControlGensDeMerEntity + return (missionId == other.missionId + && amountOfControls == other.amountOfControls + && staffOutnumbered == other.staffOutnumbered + && upToDateMedicalCheck == other.upToDateMedicalCheck + && knowledgeOfFrenchLawAndLanguage == other.knowledgeOfFrenchLawAndLanguage) + } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlNavigationEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlNavigationEntity.kt index 4a62ff7b..ba4cdb79 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlNavigationEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlNavigationEntity.kt @@ -12,7 +12,7 @@ data class ControlNavigationEntity( override var unitHasConfirmed: Boolean? = null, override val observations: String? = null, override val hasBeenDone: Boolean? = null, - override val infractions: List? = null + override var infractions: List? = null ) : BaseControlEntity() { override fun shouldToggleOnUnitHasConfirmed(): Boolean = unitShouldConfirm == true && @@ -21,4 +21,17 @@ data class ControlNavigationEntity( infractions?.isNotEmpty() == true || observations != null ) + + override fun hashCode(): Int { + var result = missionId.hashCode() + result = 31 * result + amountOfControls + return super.hashCode() + result + } + + override fun equals(other: Any?): Boolean { + if (!super.equals(other)) return false + other as ControlNavigationEntity + return (missionId == other.missionId + && amountOfControls == other.amountOfControls) + } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlSecurityEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlSecurityEntity.kt index 37405bdc..b22a28d0 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlSecurityEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/ControlSecurityEntity.kt @@ -12,7 +12,7 @@ data class ControlSecurityEntity( override var unitHasConfirmed: Boolean? = null, override val observations: String? = null, override val hasBeenDone: Boolean? = null, - override val infractions: List? = null + override var infractions: List? = null ) : BaseControlEntity() { override fun shouldToggleOnUnitHasConfirmed(): Boolean = unitShouldConfirm == true && @@ -21,4 +21,17 @@ data class ControlSecurityEntity( infractions?.isNotEmpty() == true || observations != null ) + + override fun hashCode(): Int { + var result = missionId.hashCode() + result = 31 * result + amountOfControls + return super.hashCode() + result + } + + override fun equals(other: Any?): Boolean { + if (!super.equals(other)) return false + other as ControlSecurityEntity + return (missionId == other.missionId + && amountOfControls == other.amountOfControls) + } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/v2/ActionControlEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/v2/ActionControlEntity.kt index 7b8aa35a..5ef92dca 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/v2/ActionControlEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/v2/ActionControlEntity.kt @@ -4,6 +4,7 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlAdmi import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlGensDeMerEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavigationEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlSecurityEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity data class ActionControlEntity( var controlAdministrative: ControlAdministrativeEntity? = null, @@ -11,4 +12,26 @@ data class ActionControlEntity( var controlSecurity: ControlSecurityEntity? = null, var controlNavigation: ControlNavigationEntity? = null ) { + + fun computeInfractionControlId() { + controlSecurity?.infractions?.forEach { it.controlId = controlSecurity?.id } + controlGensDeMer?.infractions?.forEach { it.controlId = controlGensDeMer?.id } + controlNavigation?.infractions?.forEach { it.controlId = controlNavigation?.id } + controlAdministrative?.infractions?.forEach { it.controlId = controlAdministrative?.id } + } + + fun getControlInfractions(): List { + val genDeMerInfractions = controlGensDeMer?.infractions ?: listOf() + val securityInfractions = controlSecurity?.infractions ?: listOf() + val navigationInfractions = controlNavigation?.infractions ?: listOf() + val administrativeInfractions = controlAdministrative?.infractions ?: listOf() + return genDeMerInfractions + securityInfractions + navigationInfractions + administrativeInfractions + } + + fun processInfractions(infractions: List?) { + controlSecurity?.infractions = infractions?.filter { it.controlId == controlSecurity?.id } + controlGensDeMer?.infractions = infractions?.filter { it.controlId == controlGensDeMer?.id } + controlNavigation?.infractions = infractions?.filter { it.controlId == controlNavigation?.id } + controlAdministrative?.infractions = infractions?.filter { it.controlId == controlAdministrative?.id } + } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/BaseMissionFishAction.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/BaseMissionFishAction.kt index 6c4059b6..3a7d5baa 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/BaseMissionFishAction.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/BaseMissionFishAction.kt @@ -13,33 +13,33 @@ interface BaseMissionFishAction { val internalReferenceNumber: String? val externalReferenceNumber: String? val ircs: String? - val flagState: CountryCode + val flagState: CountryCode? val districtCode: String? - val faoAreas: List + val faoAreas: List? val fishActionType: MissionActionType - val actionDatetimeUtc: Instant + val actionDatetimeUtc: Instant? val actionEndDatetimeUtc: Instant? val emitsVms: ControlCheck? val emitsAis: ControlCheck? - val flightGoals: List + val flightGoals: List? val logbookMatchesActivity: ControlCheck? val licencesMatchActivity: ControlCheck? val speciesWeightControlled: Boolean? val speciesSizeControlled: Boolean? val separateStowageOfPreservedSpecies: ControlCheck? - val logbookInfractions: List + val logbookInfractions: List? val licencesAndLogbookObservations: String? - val gearInfractions: List - val speciesInfractions: List + val gearInfractions: List? + val speciesInfractions: List? val speciesObservations: String? val seizureAndDiversion: Boolean? - val otherInfractions: List + val otherInfractions: List? val numberOfVesselsFlownOver: Int? val unitWithoutOmegaGauge: Boolean? val controlQualityComments: String? val feedbackSheetRequired: Boolean? - val userTrigram: String - val segments: List + val userTrigram: String? + val segments: List? val facade: String? val longitude: Double? val latitude: Double? @@ -49,19 +49,19 @@ interface BaseMissionFishAction { val vesselTargeted: ControlCheck? val seizureAndDiversionComments: String? val otherComments: String? - val gearOnboard: List - val speciesOnboard: List - val isFromPoseidon: Boolean + val gearOnboard: List? + val speciesOnboard: List? + val isFromPoseidon: Boolean? /** * This field is only used by the `GetVesselControls` use-case. * /!\ Do not use it to get `controlUnits` as the field will be empty be default. */ - var controlUnits: List - val isDeleted: Boolean - val hasSomeGearsSeized: Boolean - val hasSomeSpeciesSeized: Boolean + var controlUnits: List? + val isDeleted: Boolean? + val hasSomeGearsSeized: Boolean? + val hasSomeSpeciesSeized: Boolean? val completedBy: String? - val completion: Completion + val completion: Completion? var observationsByUnit: String? var speciesQuantitySeized: Int ? } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/MissionFishActionEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/MissionFishActionEntity.kt index e659e998..8eead379 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/MissionFishActionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/MissionFishActionEntity.kt @@ -14,61 +14,61 @@ data class FishInfraction(val natinf: Int?, val infractionType: InfractionType?) class MissionFishActionEntity( override val id: Int?, override val missionId: Int, - override val vesselId: Int?, - override val vesselName: String?, - override val internalReferenceNumber: String?, - override val externalReferenceNumber: String?, - override val ircs: String?, - override val flagState: CountryCode, - override val districtCode: String?, - override val faoAreas: List, + override val vesselId: Int? = null, + override val vesselName: String? = null, + override val internalReferenceNumber: String? = null, + override val externalReferenceNumber: String? = null, + override val ircs: String? = null, + override val flagState: CountryCode? = null, + override val districtCode: String? = null, + override val faoAreas: List? = null, override val fishActionType: MissionActionType, - override val actionDatetimeUtc: Instant, - override val actionEndDatetimeUtc: Instant?, - override val emitsVms: ControlCheck?, - override val emitsAis: ControlCheck?, - override val flightGoals: List, - override val logbookMatchesActivity: ControlCheck?, - override val licencesMatchActivity: ControlCheck?, - override val speciesWeightControlled: Boolean?, - override val speciesSizeControlled: Boolean?, - override val separateStowageOfPreservedSpecies: ControlCheck?, - override val logbookInfractions: List, - override val licencesAndLogbookObservations: String?, - override val gearInfractions: List, - override val speciesInfractions: List, - override val speciesObservations: String?, - override val seizureAndDiversion: Boolean?, - override val otherInfractions: List, - override val numberOfVesselsFlownOver: Int?, - override val unitWithoutOmegaGauge: Boolean?, - override val controlQualityComments: String?, - override val feedbackSheetRequired: Boolean?, - override val userTrigram: String, - override val segments: List, - override val facade: String?, - override val longitude: Double?, - override val latitude: Double?, - override val portLocode: String?, - override var portName: String?, - override val vesselTargeted: ControlCheck?, - override val seizureAndDiversionComments: String?, - override val otherComments: String?, - override val gearOnboard: List, - override val speciesOnboard: List, - override val isFromPoseidon: Boolean, - override var controlUnits: List, - override val isDeleted: Boolean, - override val hasSomeGearsSeized: Boolean, - override val hasSomeSpeciesSeized: Boolean, - override val completedBy: String?, - override val completion: Completion, - override val isAdministrativeControl: Boolean?, - override val isComplianceWithWaterRegulationsControl: Boolean?, - override val isSafetyEquipmentAndStandardsComplianceControl: Boolean?, - override val isSeafarersControl: Boolean?, - override var observationsByUnit: String?, - override var speciesQuantitySeized: Int?, + override val actionDatetimeUtc: Instant? = null, + override val actionEndDatetimeUtc: Instant? = null, + override val emitsVms: ControlCheck? = null, + override val emitsAis: ControlCheck? = null, + override val flightGoals: List? = listOf(), + override val logbookMatchesActivity: ControlCheck? = null, + override val licencesMatchActivity: ControlCheck? = null, + override val speciesWeightControlled: Boolean? = null, + override val speciesSizeControlled: Boolean? = null, + override val separateStowageOfPreservedSpecies: ControlCheck? = null, + override val logbookInfractions: List? = listOf(), + override val licencesAndLogbookObservations: String? = null, + override val gearInfractions: List? = listOf(), + override val speciesInfractions: List? = listOf(), + override val speciesObservations: String? = null, + override val seizureAndDiversion: Boolean? = null, + override val otherInfractions: List? = listOf(), + override val numberOfVesselsFlownOver: Int? = null, + override val unitWithoutOmegaGauge: Boolean? = null, + override val controlQualityComments: String? = null, + override val feedbackSheetRequired: Boolean? = null, + override val userTrigram: String? = null, + override val segments: List? = listOf(), + override val facade: String? = null, + override val longitude: Double? = null, + override val latitude: Double? = null, + override val portLocode: String? = null, + override var portName: String? = null, + override val vesselTargeted: ControlCheck? = null, + override val seizureAndDiversionComments: String? = null, + override val otherComments: String? = null, + override val gearOnboard: List? = listOf(), + override val speciesOnboard: List? = listOf(), + override val isFromPoseidon: Boolean? = null, + override var controlUnits: List? = listOf(), + override val isDeleted: Boolean? = null, + override val hasSomeGearsSeized: Boolean? = null, + override val hasSomeSpeciesSeized: Boolean? = null, + override val completedBy: String? = null, + override val completion: Completion? = null, + override val isAdministrativeControl: Boolean? = null, + override val isComplianceWithWaterRegulationsControl: Boolean? = null, + override val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null, + override val isSeafarersControl: Boolean? = null, + override var observationsByUnit: String? = null, + override var speciesQuantitySeized: Int? = null, ) : MissionActionEntity( missionId = missionId, actionType = ActionType.CONTROL, @@ -89,11 +89,11 @@ class MissionFishActionEntity( override fun computeSummaryTags() { val navInfractions = this.getControlInfractions() val fishInfractions: List = listOf( - this.gearInfractions.map { FishInfraction(it.natinf, it.infractionType) }, - this.logbookInfractions.map { FishInfraction(it.natinf, it.infractionType) }, - this.speciesInfractions.map { FishInfraction(it.natinf, it.infractionType) }, - this.otherInfractions.map { FishInfraction(it.natinf, it.infractionType) } - ).flatten() + this.gearInfractions?.map { FishInfraction(it.natinf, it.infractionType) }, + this.logbookInfractions?.map { FishInfraction(it.natinf, it.infractionType) }, + this.speciesInfractions?.map { FishInfraction(it.natinf, it.infractionType) }, + this.otherInfractions?.map { FishInfraction(it.natinf, it.infractionType) } + ).filterNotNull().flatten() val fishWithReport = fishInfractions.count { it.infractionType == InfractionType.WITH_RECORD } val navWithReport = navInfractions.count { it.infractionType == InfractionTypeEnum.WITH_REPORT } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/GetEnvActionById.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/GetEnvActionById.kt index 8f745bfe..b82c6a22 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/GetEnvActionById.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/GetEnvActionById.kt @@ -1,11 +1,16 @@ 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.envActions.ControlPlansEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionControlPlanEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity import fr.gouv.dgampa.rapportnav.domain.repositories.mission.IEnvMissionRepository import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.GetStatusForAction +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.MapEnvActionControlPlans import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.GetControlByActionId2 +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.GetInfractionsByActionId +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.action.FormattedEnvActionControlPlan import org.slf4j.LoggerFactory @UseCase @@ -13,6 +18,8 @@ class GetEnvActionById( private val monitorEnvApiRepo: IEnvMissionRepository, getStatusForAction: GetStatusForAction, getControlByActionId: GetControlByActionId2, + private val mapControlPlans: MapEnvActionControlPlans, + private val getInfractionsByActionId: GetInfractionsByActionId, ): GetMissionAction(getStatusForAction, getControlByActionId) { private val logger = LoggerFactory.getLogger(GetFishActionListByMissionId::class.java) @@ -24,7 +31,10 @@ class GetEnvActionById( return try { val envAction = getEnvAction(missionId = missionId, actionId = actionId) ?: return null val entity = MissionEnvActionEntity.fromEnvAction(missionId, envAction) + entity.status = this.getStatus(entity) entity.computeControls(controls = this.getControls(entity)) + entity.formattedControlPlans = getFormattedControlPlanList(entity.controlPlans) + entity.navInfractions = getInfractionsByActionId.execute(entity.id.toString()) entity.computeCompleteness() entity } catch (e: Exception) { @@ -33,6 +43,11 @@ class GetEnvActionById( } } + private fun getFormattedControlPlanList(controlPlans: List?): List? { + val filteredControlPlans: ControlPlansEntity? = mapControlPlans.execute(controlPlans) + return FormattedEnvActionControlPlan.fromControlPlansEntity(filteredControlPlans) + } + private fun getEnvAction(missionId: Int, actionId: String): EnvActionEntity? { return monitorEnvApiRepo.findMissionById(missionId = missionId)?.envActions?.find { it.id.toString() == actionId } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateEnvAction.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateEnvAction.kt new file mode 100644 index 00000000..27ccf8d9 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateEnvAction.kt @@ -0,0 +1,44 @@ +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.v2.MissionEnvActionEntity +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.PatchEnvAction +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfractionEnvTarget +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.action.ActionEnvInput +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionEnvActionDataInput +import org.slf4j.LoggerFactory + +@UseCase +class UpdateEnvAction( + private val patchEnvAction: PatchEnvAction, + private val processMissionActionControl: ProcessMissionActionControl, + private val processMissionActionInfractionEnvTarget: ProcessMissionActionInfractionEnvTarget +) { + + private val logger = LoggerFactory.getLogger(UpdateEnvAction::class.java) + fun execute(input: MissionActionInput): MissionEnvActionEntity? { + val action = MissionEnvActionDataInput.toMissionEnvActionEntity(input) + return try { + patchEnvAction.execute( + ActionEnvInput( + actionId = input.id, + missionId = action.missionId, + startDateTimeUtc = action.startDateTimeUtc, + endDateTimeUtc = action.endDateTimeUtc, + observationsByUnit = action.observationsByUnit + ) + ) + val controls = processMissionActionControl.execute(action) + val infractions = + processMissionActionInfractionEnvTarget.execute(action.getActionId(), input.env?.infractions) + action.navInfractions = infractions + action.computeControls(controls) + action + } catch (e: Exception) { + logger.error("UpdateEnvAction failed update Action", e) + return null + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateFishAction.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateFishAction.kt new file mode 100644 index 00000000..c823b208 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateFishAction.kt @@ -0,0 +1,43 @@ +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.v2.MissionFishActionEntity +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.PatchFishAction +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfraction +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.action.ActionFishInput +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionFishActionDataInput +import org.slf4j.LoggerFactory + +@UseCase +class UpdateFishAction( + private val patchFishAction: PatchFishAction, + private val processMissionActionControl: ProcessMissionActionControl, + private val processMissionActionInfraction: ProcessMissionActionInfraction +) { + private val logger = LoggerFactory.getLogger(UpdateFishAction::class.java) + + fun execute(input: MissionActionInput): MissionFishActionEntity? { + val action = MissionFishActionDataInput.toMissionFishActionEntity(input) + return try { + patchFishAction.execute( + ActionFishInput( + actionId = action.id.toString(), + missionId = action.missionId, + startDateTimeUtc = action.startDateTimeUtc, + endDateTimeUtc = action.endDateTimeUtc, + observationsByUnit = action.observationsByUnit + ) + ) + val controls = processMissionActionControl.execute(action) + val infractions = processMissionActionInfraction.execute(action.getActionId(), controls) + controls.processInfractions(infractions) + action.computeControls(controls) + action + } catch (e: Exception) { + logger.error("UpdateFishAction failed update Action", e) + return null + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateNavAction.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateNavAction.kt new file mode 100644 index 00000000..d3112c51 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateNavAction.kt @@ -0,0 +1,34 @@ +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.v2.MissionNavActionEntity +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.action.INavMissionActionRepository +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfraction +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionNavActionDataInput +import org.slf4j.LoggerFactory + +@UseCase +class UpdateNavAction( + private val missionActionRepository: INavMissionActionRepository, + private val processMissionActionControl: ProcessMissionActionControl, + private val processMissionActionInfraction: ProcessMissionActionInfraction +) { + private val logger = LoggerFactory.getLogger(UpdateNavAction::class.java) + + fun execute(input: MissionActionInput): MissionNavActionEntity? { + val action = MissionNavActionDataInput.toMissionNavActionEntity(input) + return try { + missionActionRepository.save(action) + val controls = processMissionActionControl.execute(action) + val infractions = processMissionActionInfraction.execute(action.getActionId(), controls) + controls.processInfractions(infractions) + action.computeControls(controls) + action + } catch (e: Exception) { + logger.error("UpdateNavAction failed update Action", e) + return null + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControl.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControl.kt new file mode 100644 index 00000000..b9131473 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControl.kt @@ -0,0 +1,98 @@ +package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2 + +import fr.gouv.dgampa.rapportnav.config.UseCase +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.* +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionActionEntity +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlAdministrativeRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlGensDeMerRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlNavigationRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlSecurityRepository +import java.util.* + +@UseCase +class ProcessMissionActionControl( + private val controlSecurityRepo: IControlSecurityRepository, + private val controlNavigationRepo: IControlNavigationRepository, + private val controlGensDeMerRepo: IControlGensDeMerRepository, + private val controlAdministrativeRepo: IControlAdministrativeRepository +) { + + fun execute(action: MissionActionEntity): ActionControlEntity { + val controlSecurity = processControlSecurity(action.getActionId(), control = action.controlSecurity) + val controlGensDeMer = processControlGensDeMer(action.getActionId(), control = action.controlGensDeMer) + val controlNavigation = processControlNavigation(action.getActionId(), control = action.controlNavigation) + val controlAdministrative = + processControlAdministrative(action.getActionId(), control = action.controlAdministrative) + return ActionControlEntity( + controlSecurity = controlSecurity, + controlGensDeMer = controlGensDeMer, + controlNavigation = controlNavigation, + controlAdministrative = controlAdministrative + ) + } + + private inline fun processControl( + actionId: String, + control: T?, + findByActionId: (String) -> T?, + saveControl: (T) -> T + ): UUID? { + val existingControl = findByActionId(actionId) + if (control != null && !control.equals(existingControl)) { + return saveControl(control).id + } + return existingControl?.id + } + + + private fun processControlSecurity(actionId: String, control: ControlSecurityEntity?): ControlSecurityEntity? { + val id = processControl( + actionId = actionId, + control = control, + saveControl = { controlSecurityRepo.save(it).toControlSecurityEntity() }, + findByActionId = { controlSecurityRepo.findByActionControlId(it)?.toControlSecurityEntity() }, + ) + if (id != null && control != null) control.id = id + return control + } + + private fun processControlGensDeMer(actionId: String, control: ControlGensDeMerEntity?): ControlGensDeMerEntity? { + val id = processControl( + actionId = actionId, + control = control, + saveControl = { controlGensDeMerRepo.save(it).toControlGensDeMerEntity() }, + findByActionId = { controlGensDeMerRepo.findByActionControlId(it)?.toControlGensDeMerEntity() }, + ) + if (id != null && control != null) control.id = id + return control + } + + private fun processControlNavigation( + actionId: String, + control: ControlNavigationEntity? + ): ControlNavigationEntity? { + val id = processControl( + actionId = actionId, + control = control, + saveControl = { controlNavigationRepo.save(it).toControlNavigationEntity() }, + findByActionId = { controlNavigationRepo.findByActionControlId(it)?.toControlNavigationEntity() }, + ) + if (id != null && control != null) control.id = id + return control + } + + private fun processControlAdministrative( + actionId: String, + control: ControlAdministrativeEntity? + ): ControlAdministrativeEntity? { + val id = processControl( + actionId = actionId, + control = control, + saveControl = { controlAdministrativeRepo.save(it).toControlAdministrativeEntity() }, + findByActionId = { controlAdministrativeRepo.findByActionControlId(it).toControlAdministrativeEntity() }, + ) + if (id != null && control != null) control.id = id + return control + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfraction.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfraction.kt new file mode 100644 index 00000000..4188049d --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfraction.kt @@ -0,0 +1,38 @@ +package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2 + +import fr.gouv.dgampa.rapportnav.config.UseCase +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionRepository + +@UseCase +class ProcessMissionActionInfraction( + private val infractionRepo: IInfractionRepository, +) { + + fun execute(actionId: String, control: ActionControlEntity): List? { + control.computeInfractionControlId() + val toSaveInfractions = control.getControlInfractions() + val infractionIds = toSaveInfractions.map { it.id } + val controlIds = toSaveInfractions.map { it.controlId } + + val databaseInfractions = infractionRepo + .findAllByActionId(actionId) + .map { it.toInfractionEntity() } + .filter { controlIds.contains(it.controlId) } + + val toDeleteInfractions = databaseInfractions.filter { !infractionIds.contains(it.id) } + + delete(toDeleteInfractions) + return save(toSaveInfractions) //TODO: is not equals save + } + + fun save(infractions: List?): List? { + return infractions?.map { infractionRepo.save(it).toInfractionEntity() } + } + + fun delete(infractions: List?) { + infractions?.forEach { infractionRepo.deleteById(it.id) } + } + +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfractionEnvTarget.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfractionEnvTarget.kt new file mode 100644 index 00000000..05a0a36a --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfractionEnvTarget.kt @@ -0,0 +1,58 @@ +package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2 + +import fr.gouv.dgampa.rapportnav.config.UseCase +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEnvTargetEntity +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionEnvTargetRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionRepository +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.Infraction +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.InfractionsByVessel +import java.util.* + +@UseCase +class ProcessMissionActionInfractionEnvTarget( + private val infractionRepo: IInfractionRepository, + private val infractionEnvTargetRepo: IInfractionEnvTargetRepository, +) { + + fun execute(actionId: String, infractionByVessels: List?): List? { + val infractions = + infractionByVessels?.flatMap { it.infractions }?.filter { it.controlId != null || it.controlType != null } + val infractionIds = infractions?.map { it.id } ?: listOf() + + val databaseInfractions = infractionRepo + .findAllByActionId(actionId) + .map { it.toInfractionEntity() } + + val toDeleteInfractions = databaseInfractions.filter { !infractionIds.contains(it.id.toString()) } + + delete(toDeleteInfractions) + return save(infractions) //TODO: is not equals save + } + + fun save(infractions: List?): List? { + // check target / create or Update target + // create infractionEntity -- > save target + //save infraction + return infractions?.map { + // todo check if it has changed + val target = it.target + val newTarget = InfractionEnvTargetEntity( + id = UUID.fromString(target?.id), + missionId = it.missionId, + actionId = it.actionId, + infractionId = UUID.fromString(it.id), + vesselIdentifier = target?.vesselIdentifier, + vesselSize = target?.vesselSize, + vesselType = target?.vesselType, + identityControlledPerson = target?.identityControlledPerson!! + ) + infractionEnvTargetRepo.save(infractionTarget = newTarget, infraction = it.toInfractionEntity()) + infractionRepo.save(it.toInfractionEntity()).toInfractionEntity() + } + } + + fun delete(infractions: List?) { + infractions?.forEach { infractionRepo.deleteById(it.id) } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/BaseMissionNavActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/BaseMissionNavActionDataInput.kt new file mode 100644 index 00000000..f0239a05 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/BaseMissionNavActionDataInput.kt @@ -0,0 +1,39 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselSizeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlMethod +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusReason +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusType + +interface BaseMissionNavActionDataInput { + val latitude: Double? + val longitude: Double? + val detectedPollution: Boolean? + val pollutionObservedByAuthorizedAgent: Boolean? + val diversionCarriedOut: Boolean? + val isSimpleBrewingOperationDone: Boolean? + val isAntiPolDeviceDeployed: Boolean? + val controlMethod: ControlMethod? + val vesselIdentifier: String? + val vesselType: VesselTypeEnum? + val vesselSize: VesselSizeEnum? + val identityControlledPerson: String? + val nbOfInterceptedVessels: Int? + val nbOfInterceptedMigrants: Int? + val nbOfSuspectedSmugglers: Int? + val isVesselRescue: Boolean? + val isPersonRescue: Boolean? + val isVesselNoticed: Boolean? + val isVesselTowed: Boolean? + val isInSRRorFollowedByCROSSMRCC: Boolean? + val numberPersonsRescued: Int? + val numberOfDeaths: Int? + val operationFollowsDEFREP: Boolean? + val locationDescription: String? + val isMigrationRescue: Boolean? + val nbOfVesselsTrackedWithoutIntervention: Int? + val nbAssistedVesselsReturningToShore: Int? + val reason: ActionStatusReason? + val status: ActionStatusType? +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt new file mode 100644 index 00000000..cf8d1a8d --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt @@ -0,0 +1,17 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlAdministrativeEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlGensDeMerEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavigationEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlSecurityEntity +import java.time.Instant + +open class MissionActionDataInput( + open val startDateTimeUtc: Instant, + open val endDateTimeUtc: Instant? = null, + open val observation: String? = null, + open val controlSecurity: ControlSecurityEntity? = null, + open val controlGensDeMer: ControlGensDeMerEntity? = null, + open val controlNavigation: ControlNavigationEntity? = null, + open val controlAdministrative: ControlAdministrativeEntity? = null, +) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionInput.kt new file mode 100644 index 00000000..73e5189d --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionInput.kt @@ -0,0 +1,15 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType + +data class MissionActionInput( + val id: String, + val missionId: Int, + val actionType: ActionType, + val source: MissionSourceEnum, + val env: MissionEnvActionDataInput? = null, + val nav: MissionNavActionDataInput? = null, + val fish: MissionFishActionDataInput? = null +){ +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt new file mode 100644 index 00000000..1f89e851 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt @@ -0,0 +1,48 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.ActionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.* +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.InfractionsByVessel +import java.time.Instant +import java.util.* + +class MissionEnvActionDataInput( + override val startDateTimeUtc: Instant, + override val endDateTimeUtc: Instant? = null, + val observationsByUnit: String? = null, + override val controlSecurity: ControlSecurityEntity? = null, + override val controlGensDeMer: ControlGensDeMerEntity? = null, + override val controlNavigation: ControlNavigationEntity? = null, + override val controlAdministrative: ControlAdministrativeEntity? = null, + val infractions: List? = null +) : MissionActionDataInput( + startDateTimeUtc = startDateTimeUtc, + endDateTimeUtc = endDateTimeUtc, + controlSecurity = controlSecurity, + controlGensDeMer = controlGensDeMer, + controlNavigation = controlNavigation, + controlAdministrative = controlAdministrative +) { + companion object { + fun toMissionEnvActionEntity(input: MissionActionInput): MissionEnvActionEntity { + val data = input.env + val action = MissionEnvActionEntity( + id = UUID.fromString(input.id), + missionId = input.missionId, + endDateTimeUtc = data?.endDateTimeUtc, + startDateTimeUtc = data?.startDateTimeUtc, + observationsByUnit = data?.observationsByUnit, + envActionType = ActionTypeEnum.valueOf(input.actionType.toString()) + ) + + action.controlSecurity = data?.controlSecurity + action.controlGensDeMer = data?.controlGensDeMer + action.controlNavigation = data?.controlNavigation + action.controlAdministrative = data?.controlAdministrative + return action + } + } + + +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt new file mode 100644 index 00000000..d2d26f22 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt @@ -0,0 +1,48 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.MissionActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlAdministrativeEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlGensDeMerEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavigationEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlSecurityEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionFishActionEntity +import java.time.Instant + +class MissionFishActionDataInput( + override val startDateTimeUtc: Instant, + override val endDateTimeUtc: Instant? = null, + val observationsByUnit: String? = null, + override val controlSecurity: ControlSecurityEntity? = null, + override val controlGensDeMer: ControlGensDeMerEntity? = null, + override val controlNavigation: ControlNavigationEntity? = null, + override val controlAdministrative: ControlAdministrativeEntity? = null, +) : MissionActionDataInput( + startDateTimeUtc = startDateTimeUtc, + endDateTimeUtc = endDateTimeUtc, + controlSecurity = controlSecurity, + controlGensDeMer = controlGensDeMer, + controlNavigation = controlNavigation, + controlAdministrative = controlAdministrative +){ + + companion object { + fun toMissionFishActionEntity(input: MissionActionInput): MissionFishActionEntity { + val data = input.fish + val action = MissionFishActionEntity( + id = Integer.parseInt(input.id), + missionId = input.missionId, + fishActionType = MissionActionType.AIR_CONTROL, + observationsByUnit = data?.observationsByUnit, + actionDatetimeUtc = data?.startDateTimeUtc, + actionEndDatetimeUtc = data?.endDateTimeUtc + ) + + action.controlSecurity = data?.controlSecurity + action.controlGensDeMer = data?.controlGensDeMer + action.controlNavigation = data?.controlNavigation + action.controlAdministrative = data?.controlAdministrative + return action + } + + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt new file mode 100644 index 00000000..e4e1ac9d --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt @@ -0,0 +1,106 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselSizeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.* +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusReason +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity +import java.time.Instant +import java.util.* + +class MissionNavActionDataInput( + override val latitude: Double?, + override val longitude: Double?, + override val detectedPollution: Boolean?, + override val pollutionObservedByAuthorizedAgent: Boolean?, + override val diversionCarriedOut: Boolean?, + override val isSimpleBrewingOperationDone: Boolean?, + override val isAntiPolDeviceDeployed: Boolean?, + override val controlMethod: ControlMethod?, + override val vesselIdentifier: String?, + override val vesselType: VesselTypeEnum?, + override val vesselSize: VesselSizeEnum?, + override val identityControlledPerson: String?, + override val nbOfInterceptedVessels: Int?, + override val nbOfInterceptedMigrants: Int?, + override val nbOfSuspectedSmugglers: Int?, + override val isVesselRescue: Boolean?, + override val isPersonRescue: Boolean?, + override val isVesselNoticed: Boolean?, + override val isVesselTowed: Boolean?, + override val isInSRRorFollowedByCROSSMRCC: Boolean?, + override val numberPersonsRescued: Int?, + override val numberOfDeaths: Int?, + override val operationFollowsDEFREP: Boolean?, + override val locationDescription: String?, + override val isMigrationRescue: Boolean?, + override val nbOfVesselsTrackedWithoutIntervention: Int?, + override val nbAssistedVesselsReturningToShore: Int?, + override val reason: ActionStatusReason?, + override val startDateTimeUtc: Instant, + override val endDateTimeUtc: Instant? = null, + override val observation: String? = null, + override val status: ActionStatusType? = null, + override val controlSecurity: ControlSecurityEntity? = null, + override val controlGensDeMer: ControlGensDeMerEntity? = null, + override val controlNavigation: ControlNavigationEntity? = null, + override val controlAdministrative: ControlAdministrativeEntity? = null, +) : MissionActionDataInput( + startDateTimeUtc = startDateTimeUtc, + endDateTimeUtc = endDateTimeUtc, + observation = observation, + controlSecurity = controlSecurity, + controlGensDeMer = controlGensDeMer, + controlNavigation = controlNavigation, + controlAdministrative = controlAdministrative +), BaseMissionNavActionDataInput { + companion object { + fun toMissionNavActionEntity(input: MissionActionInput): MissionNavActionEntity { + val data = input.nav + val action = MissionNavActionEntity( + id = UUID.fromString(input.id), + missionId = input.missionId, + actionType = input.actionType, + startDateTimeUtc = data?.startDateTimeUtc, + endDateTimeUtc = data?.endDateTimeUtc, + observations = data?.observation, + latitude = data?.latitude, + longitude = data?.longitude, + detectedPollution = data?.detectedPollution, + pollutionObservedByAuthorizedAgent = data?.pollutionObservedByAuthorizedAgent, + diversionCarriedOut = data?.diversionCarriedOut, + isSimpleBrewingOperationDone = data?.isSimpleBrewingOperationDone, + isAntiPolDeviceDeployed = data?.isAntiPolDeviceDeployed, + controlMethod = data?.controlMethod, + vesselIdentifier = data?.vesselIdentifier, + vesselType = data?.vesselType, + vesselSize = data?.vesselSize, + identityControlledPerson = data?.identityControlledPerson, + nbOfInterceptedVessels = data?.nbOfInterceptedVessels, + nbOfInterceptedMigrants = data?.nbOfInterceptedMigrants, + nbOfSuspectedSmugglers = data?.nbOfSuspectedSmugglers, + isVesselRescue = data?.isVesselRescue, + isPersonRescue = data?.isPersonRescue, + isVesselNoticed = data?.isVesselNoticed, + isVesselTowed = data?.isVesselTowed, + isInSRRorFollowedByCROSSMRCC = data?.isInSRRorFollowedByCROSSMRCC, + numberPersonsRescued = data?.numberPersonsRescued, + numberOfDeaths = data?.numberOfDeaths, + operationFollowsDEFREP = data?.operationFollowsDEFREP, + locationDescription = data?.locationDescription, + isMigrationRescue = data?.isMigrationRescue, + nbOfVesselsTrackedWithoutIntervention = data?.nbOfVesselsTrackedWithoutIntervention, + nbAssistedVesselsReturningToShore = data?.nbAssistedVesselsReturningToShore, + status = data?.status, + reason = data?.reason + ) + action.controlSecurity = data?.controlSecurity + action.controlGensDeMer = data?.controlGensDeMer + action.controlNavigation = data?.controlNavigation + action.controlAdministrative = data?.controlAdministrative + + return action + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/BaseMissionFishActionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/BaseMissionFishActionDataOutput.kt index ed89f01c..14075170 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/BaseMissionFishActionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/BaseMissionFishActionDataOutput.kt @@ -8,8 +8,8 @@ interface BaseMissionFishActionDataOutput { val internalReferenceNumber: String? val externalReferenceNumber: String? val districtCode: String? - val faoAreas: List - val fishActionType: MissionActionType + val faoAreas: List? + val fishActionType: MissionActionType? val emitsVms: ControlCheck? val emitsAis: ControlCheck? val logbookMatchesActivity: ControlCheck? @@ -17,18 +17,18 @@ interface BaseMissionFishActionDataOutput { val speciesWeightControlled: Boolean? val speciesSizeControlled: Boolean? val separateStowageOfPreservedSpecies: ControlCheck? - val logbookInfractions: List + val logbookInfractions: List? val licencesAndLogbookObservations: String? - val gearInfractions: List - val speciesInfractions: List + val gearInfractions: List? + val speciesInfractions: List? val speciesObservations: String? val seizureAndDiversion: Boolean? - val otherInfractions: List + val otherInfractions: List? val numberOfVesselsFlownOver: Int? val unitWithoutOmegaGauge: Boolean? val controlQualityComments: String? val feedbackSheetRequired: Boolean? - val userTrigram: String + val userTrigram: String? val segments: List val facade: String? val longitude: Double? @@ -38,14 +38,14 @@ interface BaseMissionFishActionDataOutput { val vesselTargeted: ControlCheck? val seizureAndDiversionComments: String? val otherComments: String? - val gearOnboard: List - val speciesOnboard: List - val isFromPoseidon: Boolean - val isDeleted: Boolean - val hasSomeGearsSeized: Boolean - val hasSomeSpeciesSeized: Boolean + val gearOnboard: List? + val speciesOnboard: List? + val isFromPoseidon: Boolean? + val isDeleted: Boolean? + val hasSomeGearsSeized: Boolean? + val hasSomeSpeciesSeized: Boolean? val completedBy: String? - val completion: Completion + val completion: Completion? val isAdministrativeControl: Boolean? val isComplianceWithWaterRegulationsControl: Boolean? val isSafetyEquipmentAndStandardsComplianceControl: Boolean? diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionActionOutput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionActionOutput.kt index 04e2b175..55f4497b 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionActionOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionActionOutput.kt @@ -24,7 +24,8 @@ open class MissionActionOutput( open val data: MissionActionDataOutput ) { companion object { - fun fromMissionActionEntity(action: MissionActionEntity): MissionActionOutput? { + fun fromMissionActionEntity(action: MissionActionEntity?): MissionActionOutput? { + if(action == null) return null return when (action) { is MissionNavActionEntity -> MissionNavActionOutput.fromMissionActionEntity(action) is MissionEnvActionEntity -> MissionEnvActionOutput.fromMissionActionEntity(action) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionFishActionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionFishActionDataOutput.kt index 6ab15373..4d56d227 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionFishActionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionFishActionDataOutput.kt @@ -8,7 +8,7 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlSecu import java.time.Instant class MissionFishActionDataOutput( - override val startDateTimeUtc: Instant, + override val startDateTimeUtc: Instant? = null, override val endDateTimeUtc: Instant? = null, override val vesselId: Int? = null, override val vesselName: String? = null, @@ -35,7 +35,7 @@ class MissionFishActionDataOutput( override val unitWithoutOmegaGauge: Boolean? = null, override val controlQualityComments: String? = null, override val feedbackSheetRequired: Boolean? = null, - override val userTrigram: String, + override val userTrigram: String? = null, override val segments: List = listOf(), override val facade: String? = null, override val longitude: Double? = null, @@ -48,12 +48,12 @@ class MissionFishActionDataOutput( override val otherComments: String? = null, override val gearOnboard: List = listOf(), override val speciesOnboard: List = listOf(), - override val isFromPoseidon: Boolean, - override val isDeleted: Boolean, - override val hasSomeGearsSeized: Boolean, - override val hasSomeSpeciesSeized: Boolean, + override val isFromPoseidon: Boolean? = null, + override val isDeleted: Boolean? = null, + override val hasSomeGearsSeized: Boolean? = null, + override val hasSomeSpeciesSeized: Boolean? = null, override val completedBy: String? = null, - override val completion: Completion, + override val completion: Completion? = null, override val isAdministrativeControl: Boolean? = null, override val isComplianceWithWaterRegulationsControl: Boolean? = null, override val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null, diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionFishActionOutput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionFishActionOutput.kt index c927cc63..d53e0d76 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionFishActionOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/model/v2/MissionFishActionOutput.kt @@ -52,7 +52,7 @@ class MissionFishActionOutput( internalReferenceNumber = fishAction.internalReferenceNumber, externalReferenceNumber = fishAction.externalReferenceNumber, districtCode = fishAction.districtCode, - faoAreas = fishAction.faoAreas, + faoAreas = fishAction.faoAreas?: listOf(), emitsVms = fishAction.emitsVms, emitsAis = fishAction.emitsAis, logbookMatchesActivity = fishAction.logbookMatchesActivity, @@ -60,19 +60,19 @@ class MissionFishActionOutput( speciesWeightControlled = fishAction.speciesWeightControlled, speciesSizeControlled = fishAction.speciesSizeControlled, separateStowageOfPreservedSpecies = fishAction.separateStowageOfPreservedSpecies, - logbookInfractions = fishAction.logbookInfractions, + logbookInfractions = fishAction.logbookInfractions?: listOf(), licencesAndLogbookObservations = fishAction.licencesAndLogbookObservations, - gearInfractions = fishAction.gearInfractions, - speciesInfractions = fishAction.speciesInfractions, + gearInfractions = fishAction.gearInfractions?: listOf(), + speciesInfractions = fishAction.speciesInfractions?: listOf(), speciesObservations = fishAction.speciesObservations, seizureAndDiversion = fishAction.seizureAndDiversion, - otherInfractions = fishAction.otherInfractions, + otherInfractions = fishAction.otherInfractions?: listOf(), numberOfVesselsFlownOver = fishAction.numberOfVesselsFlownOver, unitWithoutOmegaGauge = fishAction.unitWithoutOmegaGauge, controlQualityComments = fishAction.controlQualityComments, feedbackSheetRequired = fishAction.feedbackSheetRequired, userTrigram = fishAction.userTrigram, - segments = fishAction.segments, + segments = fishAction.segments?: listOf(), facade = fishAction.facade, longitude = fishAction.longitude, latitude = fishAction.latitude, @@ -81,8 +81,8 @@ class MissionFishActionOutput( vesselTargeted = fishAction.vesselTargeted, seizureAndDiversionComments = fishAction.seizureAndDiversionComments, otherComments = fishAction.otherComments, - gearOnboard = fishAction.gearOnboard, - speciesOnboard = fishAction.speciesOnboard, + gearOnboard = fishAction.gearOnboard?: listOf(), + speciesOnboard = fishAction.speciesOnboard?: listOf(), isFromPoseidon = fishAction.isFromPoseidon, isDeleted = fishAction.isDeleted, hasSomeGearsSeized = fishAction.hasSomeGearsSeized, diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/MissionActionController.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionActionController.kt similarity index 83% rename from backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/MissionActionController.kt rename to backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionActionController.kt index 9bf904a2..efed61bc 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/MissionActionController.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionActionController.kt @@ -36,11 +36,15 @@ class MissionActionController( @Argument actionId: String, @Argument missionId: Int, ): MissionActionOutput? { + val envActions = getEnvActionByMissionId.execute(missionId = missionId) + val navActions = getNavActionByMissionId.execute(missionId = missionId) + val fishActions = getFIshListActionByMissionId.execute(missionId = missionId) + /* val navAction = getNavActionById.execute(actionId = UUID.fromString(actionId)) if (navAction != null) return MissionActionOutput.fromMissionActionEntity(navAction) val fishAction = getFishActionById.execute(missionId = missionId, actionId = actionId) if (fishAction != null) return MissionActionOutput.fromMissionActionEntity(fishAction) - val envAction = getEnvActionById.execute(missionId = missionId, actionId = actionId) ?: return null - return MissionActionOutput.fromMissionActionEntity(envAction) + val envAction = getEnvActionById.execute(missionId = missionId, actionId = actionId) ?: return null*/ + return MissionActionOutput.fromMissionActionEntity((envActions + navActions + fishActions).first { it.getActionId() == actionId }) } } diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlAdministrativeEntityTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlAdministrativeEntityTest.kt index 8c07b842..1fab9e95 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlAdministrativeEntityTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlAdministrativeEntityTest.kt @@ -113,4 +113,34 @@ class ControlAdministrativeEntityTest { // Assert assertTrue(result) } + + @Test + fun `should check if equals or not equals `() { + val id = UUID.randomUUID() + val entity1 = ControlAdministrativeEntity( + id = id, + missionId = 1, + actionControlId = "action-5", + amountOfControls = 15, + unitShouldConfirm = true, + unitHasConfirmed = null, + compliantSecurityDocuments = ControlResult.YES, + compliantOperatingPermit = ControlResult.NOT_CONCERNED, + upToDateNavigationPermit = ControlResult.NOT_CONCERNED, + ) + + val entity2 = ControlAdministrativeEntity( + id = id, + missionId = 1, + actionControlId = "action-5", + amountOfControls = 15, + unitShouldConfirm = true, + unitHasConfirmed = null, + compliantSecurityDocuments = ControlResult.YES, + compliantOperatingPermit = ControlResult.NOT_CONTROLLED, + upToDateNavigationPermit = ControlResult.NOT_CONCERNED, + ) + // Assert + assertFalse(entity1.equals(entity2)) + } } diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlGensDeMerEntityTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlGensDeMerEntityTest.kt index 2789c13e..94977805 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlGensDeMerEntityTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlGensDeMerEntityTest.kt @@ -1,5 +1,6 @@ package fr.gouv.gmampa.rapportnav.domain.entities.mission.nav.control +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlAdministrativeEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlGensDeMerEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlResult import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity @@ -113,4 +114,35 @@ class ControlGensDeMerEntityTest { // Assert assertTrue(result) } + + @Test + fun `should check if equals or not equals `() { + val id = UUID.randomUUID() + val entity1 = ControlGensDeMerEntity( + id = id, + missionId = 1, + actionControlId = "action-5", + amountOfControls = 15, + unitShouldConfirm = true, + unitHasConfirmed = null, + staffOutnumbered = ControlResult.YES, + upToDateMedicalCheck = ControlResult.NOT_CONCERNED, + knowledgeOfFrenchLawAndLanguage = ControlResult.NOT_CONCERNED + ) + + val entity2 = ControlGensDeMerEntity( + id = id, + missionId = 1, + actionControlId = "action-5", + amountOfControls = 15, + unitShouldConfirm = true, + unitHasConfirmed = null, + staffOutnumbered = ControlResult.YES, + upToDateMedicalCheck = ControlResult.NOT_CONTROLLED, + knowledgeOfFrenchLawAndLanguage = ControlResult.NOT_CONCERNED + ) + + // Assert + assertFalse(entity1.equals(entity2)) + } } diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlNavigationEntityTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlNavigationEntityTest.kt index 718f493d..c335c504 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlNavigationEntityTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlNavigationEntityTest.kt @@ -1,6 +1,8 @@ package fr.gouv.gmampa.rapportnav.domain.entities.mission.nav.control +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlGensDeMerEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavigationEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlResult import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity import org.junit.jupiter.api.Assertions.assertFalse import org.junit.jupiter.api.Assertions.assertTrue @@ -92,4 +94,29 @@ class ControlNavigationEntityTest { // Assert assertTrue(result) } + + @Test + fun `should check if equals or not equals `() { + val id = UUID.randomUUID() + val entity1 = ControlNavigationEntity( + id = id, + missionId = 1, + actionControlId = "action-5", + amountOfControls = 15, + unitShouldConfirm = true, + unitHasConfirmed = null + ) + + val entity2 = ControlNavigationEntity( + id = id, + missionId = 1, + actionControlId = "action-5", + amountOfControls = 12, + unitShouldConfirm = true, + unitHasConfirmed = null + ) + + // Assert + assertFalse(entity1.equals(entity2)) + } } diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlSecurityEntityTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlSecurityEntityTest.kt index 2a006efc..0fe4c916 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlSecurityEntityTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/nav/control/ControlSecurityEntityTest.kt @@ -1,5 +1,6 @@ package fr.gouv.gmampa.rapportnav.domain.entities.mission.nav.control +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavigationEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlSecurityEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity import org.junit.jupiter.api.Assertions.assertFalse @@ -92,4 +93,29 @@ class ControlSecurityEntityTest { // Assert assertTrue(result) } + + @Test + fun `should check if equals or not equals `() { + val id = UUID.randomUUID() + val entity1 = ControlSecurityEntity( + id = id, + missionId = 1, + actionControlId = "action-5", + amountOfControls = 15, + unitShouldConfirm = true, + unitHasConfirmed = null + ) + + val entity2 = ControlSecurityEntity( + id = id, + missionId = 1, + actionControlId = "action-5", + amountOfControls = 12, + unitShouldConfirm = true, + unitHasConfirmed = null + ) + + // Assert + assertFalse(entity1.equals(entity2)) + } } diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetEnvActionByIdTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetEnvActionByIdTest.kt index c74322c1..0340190d 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetEnvActionByIdTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetEnvActionByIdTest.kt @@ -5,8 +5,10 @@ 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.GetStatusForAction +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.MapEnvActionControlPlans import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.GetEnvActionById import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.GetControlByActionId2 +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.GetInfractionsByActionId import fr.gouv.gmampa.rapportnav.mocks.mission.action.ControlMock import fr.gouv.gmampa.rapportnav.mocks.mission.action.EnvActionControlMock import org.assertj.core.api.Assertions.assertThat @@ -36,6 +38,12 @@ class GetEnvActionByIdTest { @MockBean private lateinit var getStatusForAction: GetStatusForAction + @MockBean + private lateinit var mapControlPlans: MapEnvActionControlPlans + + @MockBean + private lateinit var getInfractionsByActionId: GetInfractionsByActionId + @Test fun `test execute get Env action by id`() { val missionId = 761 @@ -63,7 +71,9 @@ class GetEnvActionByIdTest { getEnvActionById = GetEnvActionById( monitorEnvApiRepo = monitorEnvApiRepo, getStatusForAction = getStatusForAction, - getControlByActionId = getControlByActionId + mapControlPlans = mapControlPlans, + getControlByActionId = getControlByActionId, + getInfractionsByActionId = getInfractionsByActionId, ) val missionEnvAction = getEnvActionById.execute(missionId = missionId, actionId = actionId.toString()) diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionControlTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionControlTest.kt new file mode 100644 index 00000000..ed536dab --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionControlTest.kt @@ -0,0 +1,96 @@ +package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.action + +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.repositories.mission.control.IControlAdministrativeRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlGensDeMerRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlNavigationRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlSecurityRepository +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl +import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.ControlAdministrativeModel +import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.ControlGensDeMerModel +import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.ControlNavigationModel +import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.ControlSecurityModel +import fr.gouv.gmampa.rapportnav.mocks.mission.action.ControlMock +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.mockito.Mockito.`when` +import org.mockito.kotlin.anyOrNull +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.test.context.ContextConfiguration +import java.util.* + +@SpringBootTest(classes = [ProcessMissionActionControl::class]) +@ContextConfiguration(classes = [ProcessMissionActionControl::class]) +class ProcessMissionActionControlTest { + + @MockBean + private lateinit var processMissionActionControl: ProcessMissionActionControl + + @MockBean + private lateinit var controlSecurityRepo: IControlSecurityRepository + + @MockBean + private lateinit var controlNavigationRepo: IControlNavigationRepository + + @MockBean + private lateinit var controlGensDeMerRepo: IControlGensDeMerRepository + + @MockBean + private lateinit var controlAdministrativeRepo: IControlAdministrativeRepository + + @Test + fun `Should process all controls when execute, `() { + val action = getMissionAction() + val controls = ControlMock.createAllControl(actionId = action.id.toString()) + action.controlSecurity = controls.controlSecurity + action.controlNavigation = controls.controlNavigation + action.controlAdministrative = controls.controlAdministrative + + val controlSecurityModel = ControlSecurityModel.fromControlSecurityEntity(controls.controlSecurity!!) + val controlNavigationModel = ControlNavigationModel.fromControlNavigationEntity(controls.controlNavigation!!) + + val controlGensDeMerModel = ControlGensDeMerModel.fromControlGensDeMerEntity(controls.controlGensDeMer!!) + val controlAdministrationModel = + ControlAdministrativeModel.fromControlAdministrativeEntity(controls.controlAdministrative!!) + + controlAdministrationModel.hasBeenDone = true + `when`(controlSecurityRepo.findByActionControlId(action.id.toString())).thenReturn(null) + `when`(controlGensDeMerRepo.findByActionControlId(action.id.toString())).thenReturn(controlGensDeMerModel) + `when`(controlNavigationRepo.findByActionControlId(action.id.toString())).thenReturn(controlNavigationModel) + `when`(controlAdministrativeRepo.findByActionControlId(action.id.toString())).thenReturn( + controlAdministrationModel + ) + + `when`(controlSecurityRepo.save(anyOrNull())).thenReturn(controlSecurityModel) + `when`(controlGensDeMerRepo.save(anyOrNull())).thenReturn(controlGensDeMerModel) + `when`(controlNavigationRepo.save(anyOrNull())).thenReturn(controlNavigationModel) + `when`(controlAdministrativeRepo.save(anyOrNull())).thenReturn(controlAdministrationModel) + + processMissionActionControl = ProcessMissionActionControl( + controlSecurityRepo = controlSecurityRepo, + controlGensDeMerRepo = controlGensDeMerRepo, + controlNavigationRepo = controlNavigationRepo, + controlAdministrativeRepo = controlAdministrativeRepo + ) + + val actionControl = processMissionActionControl.execute(action) + + assertThat(actionControl).isNotNull + assertThat(actionControl.controlGensDeMer).isNull() + assertThat(actionControl.controlSecurity).isEqualTo(controls.controlSecurity) + assertThat(actionControl.controlNavigation).isEqualTo(controls.controlNavigation) + assertThat(actionControl.controlAdministrative).isEqualTo(controls.controlAdministrative) + } + + + private fun getMissionAction(): MissionNavActionEntity { + return MissionNavActionEntity( + id = UUID.randomUUID(), + missionId = 761, + actionType = ActionType.CONTROL, + ) + } + +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionEnvTargetTest .kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionEnvTargetTest .kt new file mode 100644 index 00000000..47426c0e --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionEnvTargetTest .kt @@ -0,0 +1,165 @@ +package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.action + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.InfractionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionEnvTargetRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionRepository +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfractionEnvTarget +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.Infraction +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.InfractionTarget +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.InfractionsByVessel +import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.infraction.InfractionModel +import fr.gouv.gmampa.rapportnav.mocks.mission.infraction.InfractionEntityMock +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.Mockito.verify +import org.mockito.Mockito.`when` +import org.mockito.kotlin.anyOrNull +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.test.context.ContextConfiguration +import java.util.* + + +@SpringBootTest(classes = [ProcessMissionActionInfractionEnvTarget::class]) +@ContextConfiguration(classes = [ProcessMissionActionInfractionEnvTarget::class]) +class ProcessMissionActionInfractionEnvTargetTest { + + @MockBean + private lateinit var infractionRepo: IInfractionRepository + + @MockBean + private lateinit var infractionEnvTargetRepo: IInfractionEnvTargetRepository + + @Captor + lateinit var deleteCaptor: ArgumentCaptor> + + @Captor + lateinit var saveCaptor: ArgumentCaptor> + + @MockBean + private lateinit var processMissionActionInfractionEnvTarget: ProcessMissionActionInfractionEnvTarget + + @Test + fun `test execute process infractions env target`() { + val actionId = UUID.randomUUID() + val infractions = getInfractions(actionId.toString()) + val byVessels = InfractionsByVessel(infractions = infractions).groupInfractionsByVesselIdentifier(infractions) + + //Infraction entities + val infractionToDelete = InfractionEntityMock.create( + actionId = actionId.toString(), + controlType = ControlType.GENS_DE_MER + ) + val mockSaveInfraction = InfractionEntityMock.create(controlType = ControlType.SECURITY) + + //Mock + val response = listOf(InfractionModel.fromInfractionEntity(infractionToDelete)) + + `when`(infractionRepo.findAllByActionId(actionId.toString())).thenReturn(response) + `when`(infractionRepo.save(anyOrNull())).thenReturn(InfractionModel.fromInfractionEntity(mockSaveInfraction)) + + //When + processMissionActionInfractionEnvTarget = Mockito.spy( + ProcessMissionActionInfractionEnvTarget( + infractionRepo = infractionRepo, + infractionEnvTargetRepo = infractionEnvTargetRepo + ) + ) + val entities = processMissionActionInfractionEnvTarget.execute(actionId.toString(), byVessels) + verify(processMissionActionInfractionEnvTarget).save(saveCaptor.capture()) + verify(processMissionActionInfractionEnvTarget).delete(deleteCaptor.capture()) + + + //Then + assertThat(entities).isNotNull + assertThat(6).isEqualTo(saveCaptor.value.size) + assertThat(1).isEqualTo(deleteCaptor.value.size) + assertThat(infractionToDelete.id).isEqualTo(deleteCaptor.value.get(0).id) + } + + + private fun getInfractions(actionId: String): List { + return listOf( + Infraction( + id = UUID.randomUUID().toString(), + actionId = actionId, + missionId = 145, + controlId = UUID.randomUUID(), + infractionType = InfractionTypeEnum.WITH_REPORT, + target = InfractionTarget( + id = UUID.randomUUID().toString(), + identityControlledPerson = "identityPerson1" + ) + ), + Infraction( + id = UUID.randomUUID().toString(), + actionId = actionId, + controlId = UUID.randomUUID(), + missionId = 145, + controlType = ControlType.SECURITY, + infractionType = InfractionTypeEnum.WITH_REPORT, + target = InfractionTarget( + id = UUID.randomUUID().toString(), + vesselIdentifier = "firstVesselIdentifier", + identityControlledPerson = "identityPerson2" + ) + ), + Infraction( + id = UUID.randomUUID().toString(), + actionId = actionId, + missionId = 145, + controlId = UUID.randomUUID(), + controlType = ControlType.ADMINISTRATIVE, + infractionType = InfractionTypeEnum.WITH_REPORT, + target = InfractionTarget( + id = UUID.randomUUID().toString(), + identityControlledPerson = "identityPerson3" + ) + ), + Infraction( + id = UUID.randomUUID().toString(), + actionId = actionId, + missionId = 145, + controlId = UUID.randomUUID(), + controlType = ControlType.GENS_DE_MER, + infractionType = InfractionTypeEnum.WITH_REPORT, + target = InfractionTarget( + id = UUID.randomUUID().toString(), + vesselIdentifier = "firstVesselIdentifier", + identityControlledPerson = "identityPerson4", + ) + ), + Infraction( + id = UUID.randomUUID().toString(), + actionId = actionId, + missionId = 145, + controlId = UUID.randomUUID(), + controlType = ControlType.NAVIGATION, + infractionType = InfractionTypeEnum.WITH_REPORT, + target = InfractionTarget( + id = UUID.randomUUID().toString(), + vesselIdentifier = "secondVesselIdentifier", + identityControlledPerson = "identityPerson5", + ) + ), + Infraction( + id = UUID.randomUUID().toString(), + actionId = actionId, + missionId = 145, + controlId = UUID.randomUUID(), + controlType = ControlType.SECURITY, + infractionType = InfractionTypeEnum.WITH_REPORT, + target = InfractionTarget( + id = UUID.randomUUID().toString(), + identityControlledPerson = "identityPerson1", + ) + ) + ) + } + +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionTest.kt new file mode 100644 index 00000000..972f541a --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionTest.kt @@ -0,0 +1,130 @@ +package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.action + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionRepository +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfraction +import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.ControlNavigationModel +import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.ControlSecurityModel +import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.infraction.InfractionModel +import fr.gouv.gmampa.rapportnav.mocks.mission.action.ControlMock +import fr.gouv.gmampa.rapportnav.mocks.mission.infraction.InfractionEntityMock +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.mockito.Mockito.verify +import org.mockito.Mockito.`when` +import org.mockito.kotlin.anyOrNull +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.test.context.ContextConfiguration +import java.util.* + + +@SpringBootTest(classes = [ProcessMissionActionInfraction::class]) +@ContextConfiguration(classes = [ProcessMissionActionInfraction::class]) +class ProcessMissionActionInfractionTest { + + @MockBean + private lateinit var infractionRepo: IInfractionRepository + + @Captor + lateinit var deleteCaptor: ArgumentCaptor> + + @Captor + lateinit var saveCaptor: ArgumentCaptor> + + @MockBean + private lateinit var processMissionActionInfraction: ProcessMissionActionInfraction + + @Test + fun `test execute process infractions`() { + val actionId = UUID.randomUUID() + + //Infraction entities + val securityInfraction = getInfractionSecurityEntity(actionId) + val infractionToDelete = getInfractionNavigationEntity(actionId) + val mockSaveInfraction = InfractionEntityMock.create(controlType = ControlType.SECURITY) + + //Control and infraction model + val actionControl = getActionControlEntity(actionId, securityInfraction) + val securityInfractionModel = getInfractionSecurityModel(securityInfraction, actionControl) + val infractionToDeleteModel = getInfractionNavigationModel(infractionToDelete, actionControl) + + //Mock + val response = listOf(infractionToDeleteModel, securityInfractionModel) + `when`(infractionRepo.findAllByActionId(actionId.toString())).thenReturn(response) + `when`(infractionRepo.save(anyOrNull())).thenReturn(InfractionModel.fromInfractionEntity(mockSaveInfraction)) + + //When + processMissionActionInfraction = Mockito.spy(ProcessMissionActionInfraction(infractionRepo)) + val infractions = processMissionActionInfraction.execute(actionId.toString(), actionControl) + verify(processMissionActionInfraction).save(saveCaptor.capture()) + verify(processMissionActionInfraction).delete(deleteCaptor.capture()) + + + //Then + assertThat(infractions).isNotNull + assertThat(5).isEqualTo(saveCaptor.value.size) + assertThat(1).isEqualTo(deleteCaptor.value.size) + assertThat(infractionToDelete.id).isEqualTo(deleteCaptor.value.get(0).id) + } + + private fun getInfractionNavigationEntity(actionId: UUID): InfractionEntity { + val infractionToDelete = + InfractionEntityMock.create(actionId = actionId.toString(), controlType = ControlType.NAVIGATION) + return infractionToDelete + } + + private fun getInfractionSecurityEntity(actionId: UUID): InfractionEntity { + val securityInfraction = + InfractionEntityMock.create(actionId = actionId.toString(), controlType = ControlType.SECURITY) + return securityInfraction + } + + private fun getInfractionSecurityModel( + securityInfraction: InfractionEntity, + actionControl: ActionControlEntity + ): InfractionModel { + val securityInfractionModel = InfractionModel.fromInfractionEntity(securityInfraction) + securityInfractionModel.control = + ControlSecurityModel.fromControlSecurityEntity(actionControl.controlSecurity!!) + return securityInfractionModel + } + + private fun getInfractionNavigationModel( + infractionToDelete: InfractionEntity, + actionControl: ActionControlEntity + ): InfractionModel { + val infractionToDeleteModel = InfractionModel.fromInfractionEntity(infractionToDelete) + infractionToDeleteModel.control = + ControlNavigationModel.fromControlNavigationEntity(actionControl.controlNavigation!!) + return infractionToDeleteModel + } + + private fun getActionControlEntity( + actionId: UUID, + securityInfraction: InfractionEntity + ): ActionControlEntity { + val actionControl = ControlMock.createAllControl(actionId = actionId.toString()) + actionControl.controlGensDeMer?.infractions = listOf( + InfractionEntityMock.create( + actionId = actionId.toString(), + controlType = ControlType.GENS_DE_MER, + controlId = actionControl.controlGensDeMer?.id + + ), + InfractionEntityMock.create( + actionId = actionId.toString(), + controlType = ControlType.GENS_DE_MER, + controlId = actionControl.controlGensDeMer?.id + ) + ) + actionControl.controlSecurity?.infractions = listOf(securityInfraction) + return actionControl + } + +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt new file mode 100644 index 00000000..f4346b67 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt @@ -0,0 +1,68 @@ +package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.action + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.PatchEnvAction +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.UpdateEnvAction +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfractionEnvTarget +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionEnvActionDataInput +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.mockito.Mockito.`when` +import org.mockito.kotlin.anyOrNull +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.test.context.ContextConfiguration +import java.time.Instant +import java.util.* + +@SpringBootTest(classes = [UpdateEnvAction::class]) +@ContextConfiguration(classes = [UpdateEnvAction::class]) +class UpdateEnvActionTest { + + @MockBean + private lateinit var patchEnvAction: PatchEnvAction + + @MockBean + private lateinit var processMissionActionControl: ProcessMissionActionControl + + @MockBean + private lateinit var processMissionActionInfractionEnvTarget: ProcessMissionActionInfractionEnvTarget + + + @Test + fun `test execute update env action`() { + val actionId = UUID.randomUUID().toString() + val input = MissionActionInput( + id = actionId, + missionId = 761, + actionType = ActionType.CONTROL, + source = MissionSourceEnum.RAPPORTNAV, + env = missionEnvActionDataInput(), + ) + + `when`(patchEnvAction.execute(anyOrNull())).thenReturn(null) + `when`(processMissionActionControl.execute(anyOrNull())).thenReturn(ActionControlEntity()) + `when`(processMissionActionInfractionEnvTarget.execute(actionId, listOf())).thenReturn(listOf()) + + val updateNavAction = UpdateEnvAction( + patchEnvAction = patchEnvAction, + processMissionActionControl = processMissionActionControl, + processMissionActionInfractionEnvTarget = processMissionActionInfractionEnvTarget + ) + + val response = updateNavAction.execute(input) + assertThat(response).isNotNull + + } + + private fun missionEnvActionDataInput() = MissionEnvActionDataInput( + observationsByUnit= "MyObservations", + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + infractions = listOf() + ) +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt new file mode 100644 index 00000000..174a264d --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt @@ -0,0 +1,66 @@ +package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.action + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.PatchFishAction +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.UpdateFishAction +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfraction +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionFishActionDataInput +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.mockito.Mockito.`when` +import org.mockito.kotlin.anyOrNull +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.test.context.ContextConfiguration +import java.time.Instant + +@SpringBootTest(classes = [UpdateFishAction::class]) +@ContextConfiguration(classes = [UpdateFishAction::class]) +class UpdateFishActionTest { + + @MockBean + private lateinit var patchFishAction: PatchFishAction + + @MockBean + private lateinit var processMissionActionControl: ProcessMissionActionControl + + @MockBean + private lateinit var processMissionActionInfraction: ProcessMissionActionInfraction + + + @Test + fun `test execute update fish action`() { + val actionId = 54566.toString() + val input = MissionActionInput( + id = actionId, + missionId = 761, + actionType = ActionType.CONTROL, + source = MissionSourceEnum.RAPPORTNAV, + fish = missionFishActionDataInput(), + ) + + `when`(patchFishAction.execute(anyOrNull())).thenReturn(null) + `when`(processMissionActionControl.execute(anyOrNull())).thenReturn(ActionControlEntity()) + `when`(processMissionActionInfraction.execute(actionId, ActionControlEntity())).thenReturn(listOf()) + + val updateNavAction = UpdateFishAction( + patchFishAction = patchFishAction, + processMissionActionControl = processMissionActionControl, + processMissionActionInfraction = processMissionActionInfraction + ) + + val response = updateNavAction.execute(input) + assertThat(response).isNotNull + + } + + private fun missionFishActionDataInput() = MissionFishActionDataInput( + observationsByUnit= "MyObservations", + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00") + ) +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateNavActionTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateNavActionTest.kt new file mode 100644 index 00000000..4e1453a0 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateNavActionTest.kt @@ -0,0 +1,101 @@ +package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.action + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselSizeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlMethod +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusReason +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusType +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.action.INavMissionActionRepository +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.UpdateNavAction +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfraction +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionNavActionDataInput +import fr.gouv.gmampa.rapportnav.mocks.mission.action.MissionActionModelMock +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.mockito.Mockito.`when` +import org.mockito.kotlin.anyOrNull +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.test.context.ContextConfiguration +import java.time.Instant +import java.util.* + +@SpringBootTest(classes = [UpdateNavAction::class]) +@ContextConfiguration(classes = [UpdateNavAction::class]) +class UpdateNavActionTest { + + @MockBean + private lateinit var missionActionRepository: INavMissionActionRepository + + @MockBean + private lateinit var processMissionActionControl: ProcessMissionActionControl + + @MockBean + private lateinit var processMissionActionInfraction: ProcessMissionActionInfraction + + + @Test + fun `test execute update nav action`() { + val actionId = UUID.randomUUID().toString() + val input = MissionActionInput( + id = actionId, + missionId = 761, + actionType = ActionType.CONTROL, + source = MissionSourceEnum.RAPPORTNAV, + nav = missionNavActionDataInput(), + ) + val model = MissionActionModelMock.create() + `when`(missionActionRepository.save(anyOrNull())).thenReturn(model) + `when`(processMissionActionControl.execute(anyOrNull())).thenReturn(ActionControlEntity()) + `when`(processMissionActionInfraction.execute(actionId, ActionControlEntity())).thenReturn(listOf()) + + val updateNavAction = UpdateNavAction( + missionActionRepository = missionActionRepository, + processMissionActionControl = processMissionActionControl, + processMissionActionInfraction = processMissionActionInfraction + ) + + val response = updateNavAction.execute(input) + assertThat(response).isNotNull + + } + + private fun missionNavActionDataInput() = MissionNavActionDataInput( + startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), + endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), + isAntiPolDeviceDeployed = true, + isSimpleBrewingOperationDone = true, + diversionCarriedOut = true, + latitude = 3434.0, + longitude = 4353.0, + detectedPollution = false, + pollutionObservedByAuthorizedAgent = false, + controlMethod = ControlMethod.SEA, + vesselIdentifier = "vesselIdentifier", + vesselType = VesselTypeEnum.FISHING, + vesselSize = VesselSizeEnum.LESS_THAN_12m, + identityControlledPerson = "identityControlledPerson", + nbOfInterceptedVessels = 4, + nbOfInterceptedMigrants = 64, + nbOfSuspectedSmugglers = 67, + isVesselRescue = false, + isPersonRescue = true, + isVesselNoticed = true, + isVesselTowed = true, + isInSRRorFollowedByCROSSMRCC = false, + numberPersonsRescued = 4, + numberOfDeaths = 90, + operationFollowsDEFREP = false, + locationDescription = "locationDescription", + isMigrationRescue = false, + nbOfVesselsTrackedWithoutIntervention = 4, + nbAssistedVesselsReturningToShore = 50, + reason = ActionStatusReason.ADMINISTRATION, + status = ActionStatusType.ANCHORED + ) +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/control/AddOrUpdateControlTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/control/AddOrProcessControlTest.kt similarity index 99% rename from backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/control/AddOrUpdateControlTest.kt rename to backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/control/AddOrProcessControlTest.kt index 4f3cb67b..24aab84e 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/control/AddOrUpdateControlTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/control/AddOrProcessControlTest.kt @@ -26,7 +26,7 @@ import java.util.* @ExtendWith(SpringExtension::class) @SpringBootTest(classes = [AddOrUpdateControl::class]) -class AddOrUpdateControlTest { +class AddOrProcessControlTest { @MockBean private lateinit var controlAdministrativeRepo: IControlAdministrativeRepository diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/ControlMock.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/ControlMock.kt index 700d8c7a..a7306a57 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/ControlMock.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/ControlMock.kt @@ -1,41 +1,49 @@ package fr.gouv.gmampa.rapportnav.mocks.mission.action import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.InfractionTypeEnum -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlAdministrativeEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlGensDeMerEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavigationEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlSecurityEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.* import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity import fr.gouv.gmampa.rapportnav.mocks.mission.infraction.InfractionEntityMock import java.util.* object ControlMock { - fun createAllControl(): ActionControlEntity { + fun createAllControl(actionId: String? = null, missionId: Int? = null): ActionControlEntity { return ActionControlEntity( controlSecurity = ControlSecurityEntity( - id = UUID.randomUUID(), missionId = 761, - actionControlId = "MyActionId", - amountOfControls = 2 + id = UUID.randomUUID(), + missionId = missionId ?: 761, + actionControlId = actionId ?: "MyActionId", + amountOfControls = 2, + hasBeenDone = false ), controlGensDeMer = ControlGensDeMerEntity( id = UUID.randomUUID(), - missionId = 761, - actionControlId = "MyActionId", - amountOfControls = 2 + missionId = missionId ?: 761, + actionControlId = actionId ?: "MyActionId", + amountOfControls = 2, + hasBeenDone = true, + upToDateMedicalCheck = ControlResult.NO, + staffOutnumbered = ControlResult.NOT_CONTROLLED, + knowledgeOfFrenchLawAndLanguage = ControlResult.YES ), controlNavigation = ControlNavigationEntity( id = UUID.randomUUID(), - missionId = 761, - actionControlId = "MyActionId", + missionId = missionId ?: 761, + actionControlId = actionId ?: "MyActionId", amountOfControls = 2, + hasBeenDone = true, infractions = listOf(InfractionEntityMock.create(infractionType = InfractionTypeEnum.WITHOUT_REPORT)) ), controlAdministrative = ControlAdministrativeEntity( id = UUID.randomUUID(), - missionId = 761, - actionControlId = "MyActionId", + missionId = missionId ?: 761, + actionControlId = actionId ?: "MyActionId", amountOfControls = 2, + hasBeenDone = false, + compliantOperatingPermit = ControlResult.YES, + upToDateNavigationPermit = ControlResult.YES, + compliantSecurityDocuments = ControlResult.NOT_CONTROLLED, infractions = listOf(InfractionEntityMock.create(infractionType = InfractionTypeEnum.WITH_REPORT)) ) ) From ec01d6e3260fda6c352759a51f3f67159c4c17e6 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 11 Dec 2024 15:16:45 +0100 Subject: [PATCH 2/9] feat(action): controller mission-action - mission action controller --- .../api/bff/v2/MissionActionController.kt | 52 ++++++++++++++++--- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionActionController.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionActionController.kt index efed61bc..11c750fb 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionActionController.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionActionController.kt @@ -1,10 +1,14 @@ -package fr.gouv.dgampa.rapportnav.infrastructure.api.bff +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.v2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionActionEntity import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.GetMission import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.* +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionActionOutput import org.slf4j.LoggerFactory import org.springframework.graphql.data.method.annotation.Argument +import org.springframework.graphql.data.method.annotation.MutationMapping import org.springframework.graphql.data.method.annotation.QueryMapping import org.springframework.stereotype.Controller import java.util.* @@ -17,7 +21,12 @@ class MissionActionController( private val getFishActionById: GetFishActionById, private val getEnvActionByMissionId: GetEnvActionListByMissionId, private val getNavActionByMissionId: GetNavActionListByMissionId, - private val getFIshListActionByMissionId: GetFishActionListByMissionId + private val getFIshListActionByMissionId: GetFishActionListByMissionId, + private val updateEnvAction: UpdateEnvAction, + private val updateNavAction: UpdateNavAction, + private val updateFishAction: UpdateFishAction + + ) { private val logger = LoggerFactory.getLogger(MissionActionController::class.java) @@ -36,15 +45,42 @@ class MissionActionController( @Argument actionId: String, @Argument missionId: Int, ): MissionActionOutput? { - val envActions = getEnvActionByMissionId.execute(missionId = missionId) - val navActions = getNavActionByMissionId.execute(missionId = missionId) - val fishActions = getFIshListActionByMissionId.execute(missionId = missionId) - /* val navAction = getNavActionById.execute(actionId = UUID.fromString(actionId)) if (navAction != null) return MissionActionOutput.fromMissionActionEntity(navAction) val fishAction = getFishActionById.execute(missionId = missionId, actionId = actionId) if (fishAction != null) return MissionActionOutput.fromMissionActionEntity(fishAction) - val envAction = getEnvActionById.execute(missionId = missionId, actionId = actionId) ?: return null*/ - return MissionActionOutput.fromMissionActionEntity((envActions + navActions + fishActions).first { it.getActionId() == actionId }) + val envAction = getEnvActionById.execute(missionId = missionId, actionId = actionId) ?: return null + return MissionActionOutput.fromMissionActionEntity(envAction) + } + + + @MutationMapping + fun updateMissionAction( + @Argument action: MissionActionInput + ): MissionActionOutput? { + val response = when (action.source) { + MissionSourceEnum.RAPPORTNAV -> updateNavAction(action) + MissionSourceEnum.MONITORENV -> updateEnvAction(action) + MissionSourceEnum.MONITORFISH -> updateFishAction(action) + else -> throw RuntimeException("Unknown mission action source: ${action.source}") + } + return MissionActionOutput.fromMissionActionEntity(response) } + + private fun updateNavAction(action: MissionActionInput): MissionActionEntity? { + val response = updateNavAction.execute(action) + return getNavActionById.execute(actionId = response?.id) + } + + private fun updateEnvAction(action: MissionActionInput): MissionActionEntity? { + val response = updateEnvAction.execute(action) + return getEnvActionById.execute(missionId = response?.missionId, actionId = response?.id.toString()) + } + + private fun updateFishAction(action: MissionActionInput): MissionActionEntity? { + val response = updateFishAction.execute(action) + return getFishActionById.execute(missionId = response?.missionId, actionId = response?.id.toString()) + } + + } From 5a4e61a6ac8bba2b842e1f9d444307f00198d766 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 13 Dec 2024 14:53:25 +0100 Subject: [PATCH 3/9] feat(mission-action): grapql definitions - graphql definitions - input object update regarding observations --- .../bff/adapters/v2/MissionActionDataInput.kt | 2 +- .../adapters/v2/MissionEnvActionDataInput.kt | 4 +- .../adapters/v2/MissionFishActionDataInput.kt | 4 +- .../adapters/v2/MissionNavActionDataInput.kt | 6 +- .../resources/graphql/mission-action.graphqls | 89 +++++++++++++++++++ 5 files changed, 97 insertions(+), 8 deletions(-) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt index cf8d1a8d..25791cbe 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt @@ -9,7 +9,7 @@ import java.time.Instant open class MissionActionDataInput( open val startDateTimeUtc: Instant, open val endDateTimeUtc: Instant? = null, - open val observation: String? = null, + open val observations: String? = null, open val controlSecurity: ControlSecurityEntity? = null, open val controlGensDeMer: ControlGensDeMerEntity? = null, open val controlNavigation: ControlNavigationEntity? = null, diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt index 1f89e851..4f91db78 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt @@ -10,7 +10,7 @@ import java.util.* class MissionEnvActionDataInput( override val startDateTimeUtc: Instant, override val endDateTimeUtc: Instant? = null, - val observationsByUnit: String? = null, + override val observations: String? = null, override val controlSecurity: ControlSecurityEntity? = null, override val controlGensDeMer: ControlGensDeMerEntity? = null, override val controlNavigation: ControlNavigationEntity? = null, @@ -32,7 +32,7 @@ class MissionEnvActionDataInput( missionId = input.missionId, endDateTimeUtc = data?.endDateTimeUtc, startDateTimeUtc = data?.startDateTimeUtc, - observationsByUnit = data?.observationsByUnit, + observationsByUnit = data?.observations, envActionType = ActionTypeEnum.valueOf(input.actionType.toString()) ) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt index d2d26f22..da2a9f99 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt @@ -11,7 +11,7 @@ import java.time.Instant class MissionFishActionDataInput( override val startDateTimeUtc: Instant, override val endDateTimeUtc: Instant? = null, - val observationsByUnit: String? = null, + override val observations: String? = null, override val controlSecurity: ControlSecurityEntity? = null, override val controlGensDeMer: ControlGensDeMerEntity? = null, override val controlNavigation: ControlNavigationEntity? = null, @@ -32,7 +32,7 @@ class MissionFishActionDataInput( id = Integer.parseInt(input.id), missionId = input.missionId, fishActionType = MissionActionType.AIR_CONTROL, - observationsByUnit = data?.observationsByUnit, + observationsByUnit = data?.observations, actionDatetimeUtc = data?.startDateTimeUtc, actionEndDatetimeUtc = data?.endDateTimeUtc ) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt index e4e1ac9d..fd9b84cc 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt @@ -40,7 +40,7 @@ class MissionNavActionDataInput( override val reason: ActionStatusReason?, override val startDateTimeUtc: Instant, override val endDateTimeUtc: Instant? = null, - override val observation: String? = null, + override val observations: String? = null, override val status: ActionStatusType? = null, override val controlSecurity: ControlSecurityEntity? = null, override val controlGensDeMer: ControlGensDeMerEntity? = null, @@ -49,7 +49,7 @@ class MissionNavActionDataInput( ) : MissionActionDataInput( startDateTimeUtc = startDateTimeUtc, endDateTimeUtc = endDateTimeUtc, - observation = observation, + observations = observations, controlSecurity = controlSecurity, controlGensDeMer = controlGensDeMer, controlNavigation = controlNavigation, @@ -64,7 +64,7 @@ class MissionNavActionDataInput( actionType = input.actionType, startDateTimeUtc = data?.startDateTimeUtc, endDateTimeUtc = data?.endDateTimeUtc, - observations = data?.observation, + observations = data?.observations, latitude = data?.latitude, longitude = data?.longitude, detectedPollution = data?.detectedPollution, diff --git a/backend/src/main/resources/graphql/mission-action.graphqls b/backend/src/main/resources/graphql/mission-action.graphqls index 95e5748e..c6bd8d75 100644 --- a/backend/src/main/resources/graphql/mission-action.graphqls +++ b/backend/src/main/resources/graphql/mission-action.graphqls @@ -172,3 +172,92 @@ extend type Query { extend type Query { action(actionId: ID!, missionId: ID!): MissionActionOutput } + +input InfractionTargetInput { + id: String + missionId: ID! + actionId: String! + controlId: String + controlType: String! + infractionType: String + natinfs: [String] + observations: String + vesselIdentifier: String + identityControlledPerson: String! + vesselType: VesselType + vesselSize: VesselSize + vehicleType: VehicleTypeEnum +} + +input MissionEnvActionDataInput { + startDateTimeUtc: Instant + endDateTimeUtc: Instant + observations: String + infractions:[InfractionTargetInput] + controlSecurity: ControlSecurityInput + controlGensDeMer: ControlGensDeMerInput + controlNavigation: ControlNavigationInput + controlAdministrative: ControlAdministrativeInput +} + +input MissionFishActionDataInput { + startDateTimeUtc: Instant + endDateTimeUtc: Instant + observations: String + controlSecurity: ControlSecurityInput + controlGensDeMer: ControlGensDeMerInput + controlNavigation: ControlNavigationInput + controlAdministrative: ControlAdministrativeInput +} + +input MissionNavActionDataInput { + observations: String + startDateTimeUtc: Instant + endDateTimeUtc: Instant + controlSecurity: ControlSecurityInput + controlGensDeMer: ControlGensDeMerInput + controlNavigation: ControlNavigationInput + controlAdministrative: ControlAdministrativeInput + latitude: Float + longitude: Float + detectedPollution: Boolean + pollutionObservedByAuthorizedAgent: Boolean + diversionCarriedOut: Boolean + isSimpleBrewingOperationDone: Boolean + isAntiPolDeviceDeployed: Boolean + controlMethod: ControlMethod + vesselIdentifier: String + vesselType: VesselType + vesselSize: VesselSize + identityControlledPerson: String + nbOfInterceptedVessels: Int + nbOfInterceptedMigrants: Int + nbOfSuspectedSmugglers: Int + isVesselRescue: Boolean + isPersonRescue: Boolean + isVesselNoticed: Boolean + isVesselTowed: Boolean + isInSRRorFollowedByCROSSMRCC: Boolean + numberPersonsRescued: Int + numberOfDeaths: Int + operationFollowsDEFREP: Boolean + locationDescription: String + isMigrationRescue: Boolean + nbOfVesselsTrackedWithoutIntervention: Int + nbAssistedVesselsReturningToShore: Int + reason: ActionStatusReason +} + +input MissionActionInput { + id: String + missionId: Int + actionType: ActionType + source: MissionSourceEnum + env: MissionEnvActionDataInput + nav: MissionNavActionDataInput + fish: MissionFishActionDataInput +} + +extend type Mutation { + updateMissionAction(action: MissionActionInput!): MissionActionOutput +} From 9161374be6344e4d1a8a4a5aaf9310eeacd95478 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 13 Dec 2024 14:58:22 +0100 Subject: [PATCH 4/9] fix(test): update test to match new definitions --- .../domain/use_cases/mission/action/UpdateEnvActionTest.kt | 2 +- .../domain/use_cases/mission/action/UpdateFishActionTest.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt index f4346b67..5c3e8602 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt @@ -60,7 +60,7 @@ class UpdateEnvActionTest { } private fun missionEnvActionDataInput() = MissionEnvActionDataInput( - observationsByUnit= "MyObservations", + observations = "MyObservations", startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"), infractions = listOf() diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt index 174a264d..3a9e5a84 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt @@ -59,7 +59,7 @@ class UpdateFishActionTest { } private fun missionFishActionDataInput() = MissionFishActionDataInput( - observationsByUnit= "MyObservations", + observations = "MyObservations", startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"), endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00") ) From b0bba6deb1a90eec459df3ae1b951690e6efee04 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 22 Dec 2024 16:52:19 +0100 Subject: [PATCH 5/9] feat(graphql): definition input - adding new input definitions for controls and infractions --- .../action/MissionEnvActionDataOutput.kt | 10 +- .../main/resources/graphql/controls2.graphqls | 92 +++++++++++++++++++ .../resources/graphql/infraction2.graphqls | 65 +++++++++++++ .../resources/graphql/mission-action.graphqls | 68 ++++++-------- 4 files changed, 188 insertions(+), 47 deletions(-) create mode 100644 backend/src/main/resources/graphql/controls2.graphqls create mode 100644 backend/src/main/resources/graphql/infraction2.graphqls diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/monitorenv/output/action/MissionEnvActionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/monitorenv/output/action/MissionEnvActionDataOutput.kt index e194a2a2..3156abaf 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/monitorenv/output/action/MissionEnvActionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/monitorenv/output/action/MissionEnvActionDataOutput.kt @@ -6,11 +6,11 @@ import java.time.ZonedDateTime import java.util.* data class MissionEnvActionDataOutput( - open val id: UUID, - open val actionStartDateTimeUtc: ZonedDateTime? = null, - open val actionEndDateTimeUtc: ZonedDateTime? = null, - open val actionType: ActionTypeEnum, - open val observationsByUnit: String? = null, + val id: UUID, + val actionStartDateTimeUtc: ZonedDateTime? = null, + val actionEndDateTimeUtc: ZonedDateTime? = null, + val actionType: ActionTypeEnum, + val observationsByUnit: String? = null, ) { fun toPatchableEnvActionEntity(): PatchedEnvActionEntity { return PatchedEnvActionEntity( diff --git a/backend/src/main/resources/graphql/controls2.graphqls b/backend/src/main/resources/graphql/controls2.graphqls new file mode 100644 index 00000000..6bd52ff3 --- /dev/null +++ b/backend/src/main/resources/graphql/controls2.graphqls @@ -0,0 +1,92 @@ + +type ControlNavigation2 { + id: String! + amountOfControls: Int! + unitShouldConfirm: Boolean + unitHasConfirmed: Boolean + observations: String + infractions: [Infraction2] + hasBeenDone: Boolean +} + +type ControlSecurity2 { + id: String! + amountOfControls: Int! + unitShouldConfirm: Boolean + unitHasConfirmed: Boolean + observations: String + infractions: [Infraction2] + hasBeenDone: Boolean +} + +type ControlAdministrative2 { + id: String! + amountOfControls: Int! + unitShouldConfirm: Boolean + unitHasConfirmed: Boolean + compliantOperatingPermit: ControlResult + upToDateNavigationPermit: ControlResult + compliantSecurityDocuments: ControlResult + observations: String + infractions: [Infraction2] + hasBeenDone: Boolean +} + +type ControlGensDeMer2 { + id: String! + amountOfControls: Int! + unitShouldConfirm: Boolean + unitHasConfirmed: Boolean + staffOutnumbered: ControlResult + upToDateMedicalCheck: ControlResult + knowledgeOfFrenchLawAndLanguage: ControlResult + observations: String + infractions: [Infraction2] + hasBeenDone: Boolean +} + +input ControlNavigationInput2 { + id: String + amountOfControls: Int + unitShouldConfirm: Boolean + unitHasConfirmed: Boolean + observations: String + infractions: [InfractionInput2] + hasBeenDone: Boolean +} + +input ControlSecurityInput2 { + id: String + amountOfControls: Int + unitShouldConfirm: Boolean + unitHasConfirmed: Boolean + observations: String + infractions: [InfractionInput2] + hasBeenDone: Boolean +} + +input ControlAdministrativeInput2 { + id: String + amountOfControls: Int + unitShouldConfirm: Boolean + unitHasConfirmed: Boolean + compliantOperatingPermit: ControlResult + upToDateNavigationPermit: ControlResult + compliantSecurityDocuments: ControlResult + observations: String + infractions: [InfractionInput2] + hasBeenDone: Boolean +} + +input ControlGensDeMerInput2 { + id: String + amountOfControls: Int + unitShouldConfirm: Boolean + unitHasConfirmed: Boolean + staffOutnumbered: ControlResult + upToDateMedicalCheck: ControlResult + knowledgeOfFrenchLawAndLanguage: ControlResult + observations: String + infractions: [InfractionInput2] + hasBeenDone: Boolean +} diff --git a/backend/src/main/resources/graphql/infraction2.graphqls b/backend/src/main/resources/graphql/infraction2.graphqls new file mode 100644 index 00000000..bde8dc96 --- /dev/null +++ b/backend/src/main/resources/graphql/infraction2.graphqls @@ -0,0 +1,65 @@ + +type Infraction2 { + id: String! + controlType: String + infractionType: InfractionType + natinfs: [String] + observations: String + target: InfractionTarget2 +} + +type InfractionTarget2 { + id: String! + vesselIdentifier: String + identityControlledPerson: String + vesselType: VesselType + vesselSize: VesselSize + companyName: String + relevantCourt: String + infractionType: String + formalNotice: String + toProcess: Boolean +} + +# for Env controls, we group by vesselIdentifier +type InfractionByTarget2 { + vesselIdentifier: String + vesselType: VesselType + controlTypesWithInfraction: [ControlType] + targetAddedByUnit: Boolean + infractions: [Infraction2] + identityControlledPerson: String +} + + +input InfractionInput2 { + id: String + controlId: String + controlType: ControlType + infractionType: InfractionType + natinfs: [String] + observations: String + target: InfractionTargetInput2 +} + +input InfractionTargetInput2 { + id: String + vesselIdentifier: String + identityControlledPerson: String + vesselType: VesselType + vesselSize: VesselSize + companyName: String + relevantCourt: String + infractionType: String + formalNotice: String + toProcess: Boolean +} + +input InfractionByTargetInput2 { + vesselIdentifier: String + vesselType: VesselType + controlTypesWithInfraction: [ControlType] + targetAddedByUnit: Boolean + infractions: [InfractionInput2] + identityControlledPerson: String +} diff --git a/backend/src/main/resources/graphql/mission-action.graphqls b/backend/src/main/resources/graphql/mission-action.graphqls index c6bd8d75..4f1e6823 100644 --- a/backend/src/main/resources/graphql/mission-action.graphqls +++ b/backend/src/main/resources/graphql/mission-action.graphqls @@ -29,10 +29,10 @@ type InfractionEnvDataByOutput{ type MissionEnvActionDataOutput { startDateTimeUtc: Instant endDateTimeUtc: Instant - controlSecurity: ControlSecurity - controlGensDeMer: ControlGensDeMer - controlNavigation: ControlNavigation - controlAdministrative: ControlAdministrative + controlSecurity: ControlSecurity2 + controlGensDeMer: ControlGensDeMer2 + controlNavigation: ControlNavigation2 + controlAdministrative: ControlAdministrative2 completedBy: String formattedControlPlans : [FormattedEnvActionControlPlan] geom: String @@ -50,17 +50,17 @@ type MissionEnvActionDataOutput { vehicleType: VehicleTypeEnum coverMissionZone: Boolean controlsToComplete: [ControlType] - infractions:[InfractionByTarget] + infractions:[InfractionByTarget2] availableControlTypesForInfraction: [ControlType] } type MissionFishActionDataOutput { startDateTimeUtc: Instant endDateTimeUtc: Instant - controlSecurity: ControlSecurity - controlGensDeMer: ControlGensDeMer - controlNavigation: ControlNavigation - controlAdministrative: ControlAdministrative + controlSecurity: ControlSecurity2 + controlGensDeMer: ControlGensDeMer2 + controlNavigation: ControlNavigation2 + controlAdministrative: ControlAdministrative2 vesselId: Int vesselName: String internalReferenceNumber: String @@ -114,10 +114,10 @@ type MissionFishActionDataOutput { type MissionNavActionDataOutput { startDateTimeUtc: Instant endDateTimeUtc: Instant - controlSecurity: ControlSecurity - controlGensDeMer: ControlGensDeMer - controlNavigation: ControlNavigation - controlAdministrative: ControlAdministrative + controlSecurity: ControlSecurity2 + controlGensDeMer: ControlGensDeMer2 + controlNavigation: ControlNavigation2 + controlAdministrative: ControlAdministrative2 observations: String latitude: Float longitude: Float @@ -173,51 +173,35 @@ extend type Query { action(actionId: ID!, missionId: ID!): MissionActionOutput } -input InfractionTargetInput { - id: String - missionId: ID! - actionId: String! - controlId: String - controlType: String! - infractionType: String - natinfs: [String] - observations: String - vesselIdentifier: String - identityControlledPerson: String! - vesselType: VesselType - vesselSize: VesselSize - vehicleType: VehicleTypeEnum -} - input MissionEnvActionDataInput { startDateTimeUtc: Instant endDateTimeUtc: Instant observations: String - infractions:[InfractionTargetInput] - controlSecurity: ControlSecurityInput - controlGensDeMer: ControlGensDeMerInput - controlNavigation: ControlNavigationInput - controlAdministrative: ControlAdministrativeInput + infractions:[InfractionByTargetInput2] + controlSecurity: ControlSecurityInput2 + controlGensDeMer: ControlGensDeMerInput2 + controlNavigation: ControlNavigationInput2 + controlAdministrative: ControlAdministrativeInput2 } input MissionFishActionDataInput { startDateTimeUtc: Instant endDateTimeUtc: Instant observations: String - controlSecurity: ControlSecurityInput - controlGensDeMer: ControlGensDeMerInput - controlNavigation: ControlNavigationInput - controlAdministrative: ControlAdministrativeInput + controlSecurity: ControlSecurityInput2 + controlGensDeMer: ControlGensDeMerInput2 + controlNavigation: ControlNavigationInput2 + controlAdministrative: ControlAdministrativeInput2 } input MissionNavActionDataInput { observations: String startDateTimeUtc: Instant endDateTimeUtc: Instant - controlSecurity: ControlSecurityInput - controlGensDeMer: ControlGensDeMerInput - controlNavigation: ControlNavigationInput - controlAdministrative: ControlAdministrativeInput + controlSecurity: ControlSecurityInput2 + controlGensDeMer: ControlGensDeMerInput2 + controlNavigation: ControlNavigationInput2 + controlAdministrative: ControlAdministrativeInput2 latitude: Float longitude: Float detectedPollution: Boolean From eb15807d3949b840069dfbe38f36e93b41e5cc19 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 23 Dec 2024 12:39:49 +0100 Subject: [PATCH 6/9] feat(infra): new input for control and infractions - control input (administrative, gensDeMer, navigation, security) - infractions input - tests --- .../api/bff/adapters/v2/ActionControlInput.kt | 40 ++++++++ .../api/bff/adapters/v2/BaseControlInput.kt | 26 +++++ .../v2/ControlAdministrativeInput2.kt | 34 +++++++ .../bff/adapters/v2/ControlGensDeMerInput2.kt | 35 +++++++ .../adapters/v2/ControlNavigationInput2.kt | 28 ++++++ .../bff/adapters/v2/ControlSecurityInput2.kt | 27 ++++++ .../adapters/v2/InfractionByTargetInput2.kt | 15 +++ .../api/bff/adapters/v2/InfractionInput2.kt | 53 +++++++++++ .../bff/adapters/v2/InfractionTargetInput2.kt | 12 +++ .../bff/adapters/v2/MissionActionDataInput.kt | 32 +++++-- .../adapters/v2/MissionEnvActionDataInput.kt | 25 ++--- .../adapters/v2/MissionFishActionDataInput.kt | 26 ++--- .../adapters/v2/MissionNavActionDataInput.kt | 82 ++++++++-------- .../bff/adapters/v2/ActionControlInputTest.kt | 94 +++++++++++++++++++ .../v2/ControlAdministrativeInput2Test.kt | 40 ++++++++ .../adapters/v2/ControlGensDeMerInput2Test.kt | 40 ++++++++ .../v2/ControlNavigationInput2Test.kt | 33 +++++++ .../adapters/v2/ControlSecurityInput2Test.kt | 33 +++++++ .../bff/adapters/v2/InfractionInput2Test.kt | 80 ++++++++++++++++ 19 files changed, 674 insertions(+), 81 deletions(-) create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ActionControlInput.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/BaseControlInput.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlAdministrativeInput2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlGensDeMerInput2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlNavigationInput2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlSecurityInput2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionByTargetInput2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionInput2.kt create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionTargetInput2.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ActionControlInputTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlAdministrativeInput2Test.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlGensDeMerInput2Test.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlNavigationInput2Test.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlSecurityInput2Test.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/InfractionInput2Test.kt diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ActionControlInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ActionControlInput.kt new file mode 100644 index 00000000..baea785b --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ActionControlInput.kt @@ -0,0 +1,40 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity + + +class ActionControlInput( + var controlAdministrative: ControlAdministrativeInput2? = null, + var controlGensDeMer: ControlGensDeMerInput2? = null, + var controlSecurity: ControlSecurityInput2? = null, + var controlNavigation: ControlNavigationInput2? = null +) { + + fun getAllInfractions(): List { + this.computeInfractionByControlId() + val genDeMerInfractions = controlGensDeMer?.infractions ?: listOf() + val securityInfractions = controlSecurity?.infractions ?: listOf() + val navigationInfractions = controlNavigation?.infractions ?: listOf() + val administrativeInfractions = controlAdministrative?.infractions ?: listOf() + return genDeMerInfractions + securityInfractions + navigationInfractions + administrativeInfractions + } + + fun toActionControlEntity(infractions: List? = null): ActionControlEntity { + val entity = ActionControlEntity( + controlSecurity = controlSecurity?.toEntity(), + controlGensDeMer = controlGensDeMer?.toEntity(), + controlNavigation = controlNavigation?.toEntity(), + controlAdministrative = controlAdministrative?.toEntity(), + ) + if (infractions != null) entity.seInfractions(infractions) + return entity + } + + private fun computeInfractionByControlId() { + controlSecurity?.infractions?.forEach { it.controlId = controlSecurity?.id?.toString() } + controlGensDeMer?.infractions?.forEach { it.controlId = controlGensDeMer?.id?.toString() } + controlNavigation?.infractions?.forEach { it.controlId = controlNavigation?.id?.toString() } + controlAdministrative?.infractions?.forEach { it.controlId = controlAdministrative?.id?.toString() } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/BaseControlInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/BaseControlInput.kt new file mode 100644 index 00000000..7484a64d --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/BaseControlInput.kt @@ -0,0 +1,26 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.BaseControlEntity +import java.util.* + +abstract class BaseControlInput { + open var id: UUID? = null + var missionId: Int? = null + var actionId: String? = null + open val amountOfControls: Int? = null + open val unitShouldConfirm: Boolean? = null + open val unitHasConfirmed: Boolean? = null + open var infractions: List? = null + open val observations: String? = null + open val hasBeenDone: Boolean? = null + + abstract fun toEntity(): BaseControlEntity + + fun setMissionIdAndActionId(missionId: Int, actionId: String) { + this.actionId = actionId + this.missionId = missionId + infractions?.forEach { + it.setMissionIdAndActionId(actionId = actionId, missionId = missionId) + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlAdministrativeInput2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlAdministrativeInput2.kt new file mode 100644 index 00000000..530a7e15 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlAdministrativeInput2.kt @@ -0,0 +1,34 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlAdministrativeEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlResult +import java.util.* + +data class ControlAdministrativeInput2( + override var id: UUID? = null, + override val amountOfControls: Int? = null, + override val unitShouldConfirm: Boolean? = null, + override var unitHasConfirmed: Boolean? = null, + override var infractions: List? = null, + override val observations: String? = null, + override val hasBeenDone: Boolean? = null, + val compliantOperatingPermit: ControlResult?, + val upToDateNavigationPermit: ControlResult?, + val compliantSecurityDocuments: ControlResult?, +) : BaseControlInput() { + override fun toEntity(): ControlAdministrativeEntity { + return ControlAdministrativeEntity( + id = id ?: UUID.randomUUID(), + missionId = missionId!!, + actionControlId = actionId!!, + amountOfControls = amountOfControls ?: 0, + unitShouldConfirm = unitShouldConfirm, + unitHasConfirmed = unitHasConfirmed, + compliantOperatingPermit = compliantOperatingPermit, + upToDateNavigationPermit = upToDateNavigationPermit, + compliantSecurityDocuments = compliantSecurityDocuments, + observations = observations, + hasBeenDone = hasBeenDone + ) + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlGensDeMerInput2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlGensDeMerInput2.kt new file mode 100644 index 00000000..bdc9cd89 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlGensDeMerInput2.kt @@ -0,0 +1,35 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlGensDeMerEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlResult +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity +import java.util.* + +data class ControlGensDeMerInput2( + override var id: UUID? = null, + override val amountOfControls: Int? = null, + override val unitShouldConfirm: Boolean? = null, + override var unitHasConfirmed: Boolean? = null, + override var infractions: List? = null, + override val observations: String? = null, + override val hasBeenDone: Boolean? = null, + val staffOutnumbered: ControlResult?, + val upToDateMedicalCheck: ControlResult?, + val knowledgeOfFrenchLawAndLanguage: ControlResult?, +) : BaseControlInput() { + override fun toEntity(): ControlGensDeMerEntity { + return ControlGensDeMerEntity( + id = id ?: UUID.randomUUID(), + missionId = missionId!!, + actionControlId = actionId!!, + amountOfControls = amountOfControls ?: 0, + unitShouldConfirm = unitShouldConfirm, + unitHasConfirmed = unitHasConfirmed, + staffOutnumbered = staffOutnumbered, + upToDateMedicalCheck = upToDateMedicalCheck, + knowledgeOfFrenchLawAndLanguage = knowledgeOfFrenchLawAndLanguage, + observations = observations, + hasBeenDone = hasBeenDone + ) + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlNavigationInput2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlNavigationInput2.kt new file mode 100644 index 00000000..073d55a6 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlNavigationInput2.kt @@ -0,0 +1,28 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavigationEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity +import java.util.* + +data class ControlNavigationInput2( + override var id: UUID? = null, + override val amountOfControls: Int? = null, + override val unitShouldConfirm: Boolean? = null, + override var unitHasConfirmed: Boolean? = null, + override var infractions: List? = null, + override val observations: String? = null, + override val hasBeenDone: Boolean? = null, +) : BaseControlInput() { + override fun toEntity(): ControlNavigationEntity { + return ControlNavigationEntity( + id = id ?: UUID.randomUUID(), + missionId = missionId!!, + actionControlId = actionId!!, + amountOfControls = amountOfControls ?: 0, + unitShouldConfirm = unitShouldConfirm, + unitHasConfirmed = unitHasConfirmed, + observations = observations, + hasBeenDone = hasBeenDone + ) + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlSecurityInput2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlSecurityInput2.kt new file mode 100644 index 00000000..a6135ced --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlSecurityInput2.kt @@ -0,0 +1,27 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlSecurityEntity +import java.util.* + +data class ControlSecurityInput2( + override var id: UUID? = null, + override val amountOfControls: Int? = null, + override val unitShouldConfirm: Boolean? = null, + override var unitHasConfirmed: Boolean? = null, + override var infractions: List? = null, + override val observations: String? = null, + override val hasBeenDone: Boolean? = null, +) : BaseControlInput() { + override fun toEntity(): ControlSecurityEntity { + return ControlSecurityEntity( + id = id ?: UUID.randomUUID(), + missionId = missionId!!, + actionControlId = actionId!!, + amountOfControls = amountOfControls ?: 0, + unitShouldConfirm = unitShouldConfirm, + unitHasConfirmed = unitHasConfirmed, + observations = observations, + hasBeenDone = hasBeenDone + ) + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionByTargetInput2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionByTargetInput2.kt new file mode 100644 index 00000000..e3d78d08 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionByTargetInput2.kt @@ -0,0 +1,15 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType + +data class InfractionByTargetInput2( + val vesselIdentifier: String? = null, + val vesselType: VesselTypeEnum? = null, + val controlTypesWithInfraction: List? = listOf(), + val targetAddedByUnit: Boolean? = null, + val infractions: List = listOf(), + val identityControlledPerson: String? = null +) { + +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionInput2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionInput2.kt new file mode 100644 index 00000000..b5b02112 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionInput2.kt @@ -0,0 +1,53 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.InfractionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselSizeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEnvTargetEntity +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.Infraction +import java.util.* + +data class InfractionInput2( + var id: String? = null, + var missionId: Int? = null, + var actionId: String? = null, + var controlId: String? = null, + var controlType: String? = null, + var infractionType: InfractionTypeEnum? = null, + var natinfs: List? = null, + var observations: String? = null, + var target: InfractionTargetInput2? = null +) { + fun setMissionIdAndActionId(missionId: Int, actionId: String) { + this.actionId = actionId + this.missionId = missionId + } + + fun toInfractionEntity(): InfractionEntity { + return Infraction( + id = id ?: UUID.randomUUID().toString(), + missionId = missionId!!, + actionId = actionId!!, + controlId = controlId?.let { UUID.fromString(controlId) }, + controlType = controlType?.let { ControlType.valueOf(it) }, + natinfs = natinfs, + infractionType = infractionType, + observations = observations, + ).toInfractionEntity() + } + + fun toInfractionEnvTargetEntity(): InfractionEnvTargetEntity { + return InfractionEnvTargetEntity( + actionId = actionId!!, + missionId = missionId!!, + id = target?.id?.let { UUID.fromString(it) } ?: UUID.randomUUID(), + infractionId = id?.let { UUID.fromString(it) } ?: UUID.randomUUID(), + vesselIdentifier = target?.vesselIdentifier, + vesselSize = target?.vesselSize?.let { VesselSizeEnum.valueOf(it) }, + vesselType = target?.vesselType?.let { VesselTypeEnum.valueOf(it) }, + identityControlledPerson = target?.identityControlledPerson!! + ) + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionTargetInput2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionTargetInput2.kt new file mode 100644 index 00000000..6a673177 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/InfractionTargetInput2.kt @@ -0,0 +1,12 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VehicleTypeEnum + +data class InfractionTargetInput2 ( + val id: String? = null, + val vesselIdentifier: String? = null, + val vesselType: String? = null, + val vesselSize: String? = null, + val identityControlledPerson: String, + val vehicleType: VehicleTypeEnum? = null, +) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt index 25791cbe..f158edcc 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt @@ -1,17 +1,31 @@ package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlAdministrativeEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlGensDeMerEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavigationEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlSecurityEntity import java.time.Instant open class MissionActionDataInput( open val startDateTimeUtc: Instant, open val endDateTimeUtc: Instant? = null, open val observations: String? = null, - open val controlSecurity: ControlSecurityEntity? = null, - open val controlGensDeMer: ControlGensDeMerEntity? = null, - open val controlNavigation: ControlNavigationEntity? = null, - open val controlAdministrative: ControlAdministrativeEntity? = null, -) + open val controlSecurity: ControlSecurityInput2? = null, + open val controlGensDeMer: ControlGensDeMerInput2? = null, + open val controlNavigation: ControlNavigationInput2? = null, + open val controlAdministrative: ControlAdministrativeInput2? = null +){ + + fun getControls(missionId: Int, actionId: String): ActionControlInput{ + this.computeMissionIdActionId(missionId, actionId) + return ActionControlInput( + controlSecurity = controlSecurity, + controlGensDeMer = controlGensDeMer, + controlNavigation = controlNavigation, + controlAdministrative = controlAdministrative + ) + } + + private fun computeMissionIdActionId(missionId: Int, actionId: String) { + this.controlSecurity?.setMissionIdAndActionId(missionId = missionId, actionId = actionId) + this.controlGensDeMer?.setMissionIdAndActionId(missionId = missionId, actionId = actionId) + this.controlNavigation?.setMissionIdAndActionId(missionId = missionId, actionId = actionId) + this.controlAdministrative?.setMissionIdAndActionId(missionId = missionId, actionId = actionId) + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt index 4f91db78..e12c2634 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt @@ -1,9 +1,7 @@ package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.ActionTypeEnum -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.* import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity -import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.InfractionsByVessel import java.time.Instant import java.util.* @@ -11,11 +9,11 @@ class MissionEnvActionDataInput( override val startDateTimeUtc: Instant, override val endDateTimeUtc: Instant? = null, override val observations: String? = null, - override val controlSecurity: ControlSecurityEntity? = null, - override val controlGensDeMer: ControlGensDeMerEntity? = null, - override val controlNavigation: ControlNavigationEntity? = null, - override val controlAdministrative: ControlAdministrativeEntity? = null, - val infractions: List? = null + override val controlSecurity: ControlSecurityInput2? = null, + override val controlGensDeMer: ControlGensDeMerInput2? = null, + override val controlNavigation: ControlNavigationInput2? = null, + override val controlAdministrative: ControlAdministrativeInput2? = null, + val infractions: List? = null ) : MissionActionDataInput( startDateTimeUtc = startDateTimeUtc, endDateTimeUtc = endDateTimeUtc, @@ -24,6 +22,14 @@ class MissionEnvActionDataInput( controlNavigation = controlNavigation, controlAdministrative = controlAdministrative ) { + + fun getInfractions(missionId: Int, actionId: String): List? { + val infractions = infractions?.flatMap { it.infractions } + //?.filter { it.controlId != null || it.controlType != null } + infractions?.forEach { it.setMissionIdAndActionId(missionId, actionId) } + return infractions + } + companion object { fun toMissionEnvActionEntity(input: MissionActionInput): MissionEnvActionEntity { val data = input.env @@ -35,11 +41,6 @@ class MissionEnvActionDataInput( observationsByUnit = data?.observations, envActionType = ActionTypeEnum.valueOf(input.actionType.toString()) ) - - action.controlSecurity = data?.controlSecurity - action.controlGensDeMer = data?.controlGensDeMer - action.controlNavigation = data?.controlNavigation - action.controlAdministrative = data?.controlAdministrative return action } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt index da2a9f99..42396d69 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt @@ -1,10 +1,6 @@ package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.MissionActionType -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlAdministrativeEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlGensDeMerEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavigationEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlSecurityEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionFishActionEntity import java.time.Instant @@ -12,10 +8,10 @@ class MissionFishActionDataInput( override val startDateTimeUtc: Instant, override val endDateTimeUtc: Instant? = null, override val observations: String? = null, - override val controlSecurity: ControlSecurityEntity? = null, - override val controlGensDeMer: ControlGensDeMerEntity? = null, - override val controlNavigation: ControlNavigationEntity? = null, - override val controlAdministrative: ControlAdministrativeEntity? = null, + override val controlSecurity: ControlSecurityInput2? = null, + override val controlGensDeMer: ControlGensDeMerInput2? = null, + override val controlNavigation: ControlNavigationInput2? = null, + override val controlAdministrative: ControlAdministrativeInput2? = null, ) : MissionActionDataInput( startDateTimeUtc = startDateTimeUtc, endDateTimeUtc = endDateTimeUtc, @@ -27,20 +23,16 @@ class MissionFishActionDataInput( companion object { fun toMissionFishActionEntity(input: MissionActionInput): MissionFishActionEntity { - val data = input.fish + val data = input.fish as MissionFishActionDataInput + val action = MissionFishActionEntity( id = Integer.parseInt(input.id), missionId = input.missionId, fishActionType = MissionActionType.AIR_CONTROL, - observationsByUnit = data?.observations, - actionDatetimeUtc = data?.startDateTimeUtc, - actionEndDatetimeUtc = data?.endDateTimeUtc + observationsByUnit = data.observations, + actionDatetimeUtc = data.startDateTimeUtc, + actionEndDatetimeUtc = data.endDateTimeUtc ) - - action.controlSecurity = data?.controlSecurity - action.controlGensDeMer = data?.controlGensDeMer - action.controlNavigation = data?.controlNavigation - action.controlAdministrative = data?.controlAdministrative return action } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt index fd9b84cc..ac9e2cf1 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt @@ -42,10 +42,10 @@ class MissionNavActionDataInput( override val endDateTimeUtc: Instant? = null, override val observations: String? = null, override val status: ActionStatusType? = null, - override val controlSecurity: ControlSecurityEntity? = null, - override val controlGensDeMer: ControlGensDeMerEntity? = null, - override val controlNavigation: ControlNavigationEntity? = null, - override val controlAdministrative: ControlAdministrativeEntity? = null, + override val controlSecurity: ControlSecurityInput2? = null, + override val controlGensDeMer: ControlGensDeMerInput2? = null, + override val controlNavigation: ControlNavigationInput2? = null, + override val controlAdministrative: ControlAdministrativeInput2? = null, ) : MissionActionDataInput( startDateTimeUtc = startDateTimeUtc, endDateTimeUtc = endDateTimeUtc, @@ -57,50 +57,46 @@ class MissionNavActionDataInput( ), BaseMissionNavActionDataInput { companion object { fun toMissionNavActionEntity(input: MissionActionInput): MissionNavActionEntity { - val data = input.nav + val data = input.nav as MissionNavActionDataInput + val action = MissionNavActionEntity( id = UUID.fromString(input.id), missionId = input.missionId, actionType = input.actionType, - startDateTimeUtc = data?.startDateTimeUtc, - endDateTimeUtc = data?.endDateTimeUtc, - observations = data?.observations, - latitude = data?.latitude, - longitude = data?.longitude, - detectedPollution = data?.detectedPollution, - pollutionObservedByAuthorizedAgent = data?.pollutionObservedByAuthorizedAgent, - diversionCarriedOut = data?.diversionCarriedOut, - isSimpleBrewingOperationDone = data?.isSimpleBrewingOperationDone, - isAntiPolDeviceDeployed = data?.isAntiPolDeviceDeployed, - controlMethod = data?.controlMethod, - vesselIdentifier = data?.vesselIdentifier, - vesselType = data?.vesselType, - vesselSize = data?.vesselSize, - identityControlledPerson = data?.identityControlledPerson, - nbOfInterceptedVessels = data?.nbOfInterceptedVessels, - nbOfInterceptedMigrants = data?.nbOfInterceptedMigrants, - nbOfSuspectedSmugglers = data?.nbOfSuspectedSmugglers, - isVesselRescue = data?.isVesselRescue, - isPersonRescue = data?.isPersonRescue, - isVesselNoticed = data?.isVesselNoticed, - isVesselTowed = data?.isVesselTowed, - isInSRRorFollowedByCROSSMRCC = data?.isInSRRorFollowedByCROSSMRCC, - numberPersonsRescued = data?.numberPersonsRescued, - numberOfDeaths = data?.numberOfDeaths, - operationFollowsDEFREP = data?.operationFollowsDEFREP, - locationDescription = data?.locationDescription, - isMigrationRescue = data?.isMigrationRescue, - nbOfVesselsTrackedWithoutIntervention = data?.nbOfVesselsTrackedWithoutIntervention, - nbAssistedVesselsReturningToShore = data?.nbAssistedVesselsReturningToShore, - status = data?.status, - reason = data?.reason + startDateTimeUtc = data.startDateTimeUtc, + endDateTimeUtc = data.endDateTimeUtc, + observations = data.observations, + latitude = data.latitude, + longitude = data.longitude, + detectedPollution = data.detectedPollution, + pollutionObservedByAuthorizedAgent = data.pollutionObservedByAuthorizedAgent, + diversionCarriedOut = data.diversionCarriedOut, + isSimpleBrewingOperationDone = data.isSimpleBrewingOperationDone, + isAntiPolDeviceDeployed = data.isAntiPolDeviceDeployed, + controlMethod = data.controlMethod, + vesselIdentifier = data.vesselIdentifier, + vesselType = data.vesselType, + vesselSize = data.vesselSize, + identityControlledPerson = data.identityControlledPerson, + nbOfInterceptedVessels = data.nbOfInterceptedVessels, + nbOfInterceptedMigrants = data.nbOfInterceptedMigrants, + nbOfSuspectedSmugglers = data.nbOfSuspectedSmugglers, + isVesselRescue = data.isVesselRescue, + isPersonRescue = data.isPersonRescue, + isVesselNoticed = data.isVesselNoticed, + isVesselTowed = data.isVesselTowed, + isInSRRorFollowedByCROSSMRCC = data.isInSRRorFollowedByCROSSMRCC, + numberPersonsRescued = data.numberPersonsRescued, + numberOfDeaths = data.numberOfDeaths, + operationFollowsDEFREP = data.operationFollowsDEFREP, + locationDescription = data.locationDescription, + isMigrationRescue = data.isMigrationRescue, + nbOfVesselsTrackedWithoutIntervention = data.nbOfVesselsTrackedWithoutIntervention, + nbAssistedVesselsReturningToShore = data.nbAssistedVesselsReturningToShore, + status = data.status, + reason = data.reason ) - action.controlSecurity = data?.controlSecurity - action.controlGensDeMer = data?.controlGensDeMer - action.controlNavigation = data?.controlNavigation - action.controlAdministrative = data?.controlAdministrative - - return action + return action } } } diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ActionControlInputTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ActionControlInputTest.kt new file mode 100644 index 00000000..b365a256 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ActionControlInputTest.kt @@ -0,0 +1,94 @@ +package fr.gouv.gmampa.rapportnav.infrastructure.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlResult +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.* +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.test.context.junit.jupiter.SpringExtension + +@ExtendWith(SpringExtension::class) +class ActionControlInputTest { + @Test + fun `execute should return list of all infractions`() { + val action = getActionInput() + val infractions = action.getAllInfractions() + assertThat(infractions.size).isEqualTo(5) + } + + @Test + fun `execute should return Action control entity`() { + val action = getActionInput() + val entity = action.toActionControlEntity() + assertThat(entity).isNotNull() + assertThat(entity.controlSecurity?.id).isNotNull() + assertThat(entity.controlGensDeMer?.id).isNotNull() + assertThat(entity.controlNavigation?.id).isNotNull() + assertThat(entity.controlAdministrative?.id).isNotNull() + } + + private fun getActionInput(): ActionControlInput { + val controlAdministrative = ControlAdministrativeInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf( + InfractionInput2(controlType = ControlType.ADMINISTRATIVE.toString()) + ), + hasBeenDone = true, + compliantOperatingPermit = ControlResult.YES, + upToDateNavigationPermit = ControlResult.NO, + compliantSecurityDocuments = ControlResult.NOT_CONTROLLED, + ) + controlAdministrative.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + + val controlGensDeMer = ControlGensDeMerInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf( + InfractionInput2(controlType = ControlType.GENS_DE_MER.toString()) + ), + hasBeenDone = true, + knowledgeOfFrenchLawAndLanguage = ControlResult.YES, + staffOutnumbered = ControlResult.NO, + upToDateMedicalCheck = ControlResult.NOT_CONTROLLED + ) + controlGensDeMer.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + + + val controlNavigation = ControlNavigationInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf( + InfractionInput2(controlType = ControlType.NAVIGATION.toString()) + ), + hasBeenDone = true + ) + controlNavigation.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + + val controlSecurity = ControlSecurityInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf( + InfractionInput2(controlType = ControlType.SECURITY.toString()), + InfractionInput2(controlType = ControlType.SECURITY.toString()) + ), + hasBeenDone = true + ) + controlSecurity.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + return ActionControlInput( + controlSecurity = controlSecurity, + controlGensDeMer = controlGensDeMer, + controlNavigation = controlNavigation, + controlAdministrative = controlAdministrative + ) + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlAdministrativeInput2Test.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlAdministrativeInput2Test.kt new file mode 100644 index 00000000..febb706c --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlAdministrativeInput2Test.kt @@ -0,0 +1,40 @@ +package fr.gouv.gmampa.rapportnav.infrastructure.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlResult +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.ControlAdministrativeInput2 +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.test.context.junit.jupiter.SpringExtension + +@ExtendWith(SpringExtension::class) +class ControlAdministrativeInput2Test { + @Test + fun `execute should convert into entity`() { + val input = ControlAdministrativeInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf(), + hasBeenDone = true, + compliantOperatingPermit = ControlResult.YES, + upToDateNavigationPermit = ControlResult.NO, + compliantSecurityDocuments = ControlResult.NOT_CONTROLLED, + ) + input.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + val entity = input.toEntity() + + assertThat(entity).isNotNull() + assertThat(entity.id).isNotNull() + assertThat(entity.missionId).isEqualTo(761) + assertThat(entity.infractions).isEqualTo(null) + assertThat(entity.actionControlId).isEqualTo("my action id") + assertThat(entity.unitShouldConfirm).isEqualTo(false) + assertThat(entity.unitHasConfirmed).isEqualTo(true) + assertThat(entity.hasBeenDone).isEqualTo(true) + assertThat(entity.compliantOperatingPermit).isEqualTo(ControlResult.YES) + assertThat(entity.upToDateNavigationPermit).isEqualTo(ControlResult.NO) + assertThat(entity.compliantSecurityDocuments).isEqualTo(ControlResult.NOT_CONTROLLED) + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlGensDeMerInput2Test.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlGensDeMerInput2Test.kt new file mode 100644 index 00000000..6aba9e6e --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlGensDeMerInput2Test.kt @@ -0,0 +1,40 @@ +package fr.gouv.gmampa.rapportnav.infrastructure.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlResult +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.ControlGensDeMerInput2 +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.test.context.junit.jupiter.SpringExtension + +@ExtendWith(SpringExtension::class) +class ControlGensDeMerInput2Test { + @Test + fun `execute should convert into entity`() { + val input = ControlGensDeMerInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf(), + hasBeenDone = true, + knowledgeOfFrenchLawAndLanguage = ControlResult.YES, + staffOutnumbered = ControlResult.NO, + upToDateMedicalCheck = ControlResult.NOT_CONTROLLED + ) + input.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + val entity = input.toEntity() + + assertThat(entity).isNotNull() + assertThat(entity.id).isNotNull() + assertThat(entity.missionId).isEqualTo(761) + assertThat(entity.infractions).isEqualTo(null) + assertThat(entity.actionControlId).isEqualTo("my action id") + assertThat(entity.unitShouldConfirm).isEqualTo(false) + assertThat(entity.unitHasConfirmed).isEqualTo(true) + assertThat(entity.hasBeenDone).isEqualTo(true) + assertThat(entity.knowledgeOfFrenchLawAndLanguage).isEqualTo(ControlResult.YES) + assertThat(entity.staffOutnumbered).isEqualTo(ControlResult.NO) + assertThat(entity.upToDateMedicalCheck).isEqualTo(ControlResult.NOT_CONTROLLED) + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlNavigationInput2Test.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlNavigationInput2Test.kt new file mode 100644 index 00000000..ca30c31a --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlNavigationInput2Test.kt @@ -0,0 +1,33 @@ +package fr.gouv.gmampa.rapportnav.infrastructure.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.ControlNavigationInput2 +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.test.context.junit.jupiter.SpringExtension + +@ExtendWith(SpringExtension::class) +class ControlNavigationInput2Test { + @Test + fun `execute should convert into entity`() { + val input = ControlNavigationInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf(), + hasBeenDone = true + ) + input.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + val entity = input.toEntity() + + assertThat(entity).isNotNull() + assertThat(entity.id).isNotNull() + assertThat(entity.missionId).isEqualTo(761) + assertThat(entity.infractions).isEqualTo(null) + assertThat(entity.actionControlId).isEqualTo("my action id") + assertThat(entity.unitShouldConfirm).isEqualTo(false) + assertThat(entity.unitHasConfirmed).isEqualTo(true) + assertThat(entity.hasBeenDone).isEqualTo(true) + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlSecurityInput2Test.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlSecurityInput2Test.kt new file mode 100644 index 00000000..50f76098 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ControlSecurityInput2Test.kt @@ -0,0 +1,33 @@ +package fr.gouv.gmampa.rapportnav.infrastructure.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.ControlSecurityInput2 +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.test.context.junit.jupiter.SpringExtension + +@ExtendWith(SpringExtension::class) +class ControlSecurityInput2Test { + @Test + fun `execute should convert into entity`() { + val input = ControlSecurityInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf(), + hasBeenDone = true + ) + input.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + val entity = input.toEntity() + + assertThat(entity).isNotNull() + assertThat(entity.id).isNotNull() + assertThat(entity.missionId).isEqualTo(761) + assertThat(entity.infractions).isEqualTo(null) + assertThat(entity.actionControlId).isEqualTo("my action id") + assertThat(entity.unitShouldConfirm).isEqualTo(false) + assertThat(entity.unitHasConfirmed).isEqualTo(true) + assertThat(entity.hasBeenDone).isEqualTo(true) + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/InfractionInput2Test.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/InfractionInput2Test.kt new file mode 100644 index 00000000..cc617f54 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/InfractionInput2Test.kt @@ -0,0 +1,80 @@ +package fr.gouv.gmampa.rapportnav.infrastructure.bff.adapters.v2 + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.InfractionTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VehicleTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselSizeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselTypeEnum +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.InfractionInput2 +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.InfractionTargetInput2 +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.test.context.junit.jupiter.SpringExtension +import java.util.* + + +@ExtendWith(SpringExtension::class) +class InfractionInput2Test { + + @Test + fun `execute should convert into entity`() { + val actionId = UUID.randomUUID().toString() + val controlId = UUID.randomUUID().toString() + + val input = InfractionInput2( + missionId = 761, + controlId = controlId, + controlType = ControlType.SECURITY.toString(), + infractionType = InfractionTypeEnum.WITH_REPORT, + natinfs = listOf(), + observations = "My observations", + target = null + ) + input.setMissionIdAndActionId(missionId = 761, actionId = actionId) + val entity = input.toInfractionEntity() + + assertThat(entity).isNotNull() + assertThat(entity.id).isNotNull() + assertThat(entity.missionId).isEqualTo(761) + assertThat(entity.infractionType).isEqualTo(InfractionTypeEnum.WITH_REPORT) + assertThat(entity.controlType).isEqualTo(ControlType.SECURITY) + assertThat(entity.actionId).isEqualTo(actionId) + assertThat(entity.observations).isEqualTo("My observations") + assertThat(entity.target).isEqualTo(null) + } + + + @Test + fun `execute should convert into target entity`() { + val actionId = UUID.randomUUID().toString() + val controlId = UUID.randomUUID().toString() + val target = InfractionTargetInput2( + vesselIdentifier = "My vessel identifier", + vesselType = VesselTypeEnum.MOTOR.toString(), + vesselSize = VesselSizeEnum.LESS_THAN_12m.toString(), + identityControlledPerson = "identityControlledPerson", + vehicleType = VehicleTypeEnum.VEHICLE_AIR, + ) + + val input = InfractionInput2( + missionId = 761, + controlId = controlId, + controlType = ControlType.SECURITY.toString(), + infractionType = InfractionTypeEnum.WITH_REPORT, + natinfs = listOf(), + observations = "My observations", + target = target + ) + input.setMissionIdAndActionId(missionId = 761, actionId = actionId) + val entity = input.toInfractionEnvTargetEntity() + + assertThat(entity).isNotNull() + assertThat(entity.id).isNotNull() + assertThat(entity.missionId).isEqualTo(761) + assertThat(entity.vesselType.toString()).isEqualTo(target.vesselType) + assertThat(entity.vesselSize.toString()).isEqualTo(target.vesselSize) + assertThat(entity.vesselIdentifier).isEqualTo(target.vesselIdentifier) + assertThat(entity.identityControlledPerson).isEqualTo(target.identityControlledPerson) + } +} From d70c419547446025a6ec5a21166ec8af5b53e138 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 23 Dec 2024 18:02:01 +0100 Subject: [PATCH 7/9] feat(use_case): update use case to match new input - Update compute control use case - update compute infraction use case - update compte infraction target use_case - create compute control for infraction target - Update tests --- .../nav/control/v2/ActionControlEntity.kt | 17 +- .../nav/infraction/InfractionEntity.kt | 30 +++- .../infraction/InfractionEnvTargetEntity.kt | 28 +++- .../mission/v2/MissionNavActionEntity.kt | 2 +- .../mission/action/v2/UpdateEnvAction.kt | 28 +++- .../mission/action/v2/UpdateFishAction.kt | 15 +- .../mission/action/v2/UpdateNavAction.kt | 16 +- .../control/v2/ProcessMissionActionControl.kt | 76 +++++---- .../ProcessMissionActionControlEnvTarget.kt | 156 ++++++++++++++++++ .../v2/ProcessMissionActionInfraction.kt | 18 +- ...ProcessMissionActionInfractionEnvTarget.kt | 28 +--- .../v2/ControlAdministrativeInput2.kt | 6 +- .../adapters/v2/ControlNavigationInput2.kt | 1 - .../api/bff/v2/MissionActionController.kt | 13 +- .../mission/action/v2/MissionActionModel.kt | 14 +- .../mission/action/GetNavActionByIdTest.kt | 2 +- .../action/GetNavActionListByMissionIdTest.kt | 2 +- .../action/ProcessMissionActionControlTest.kt | 23 ++- ...ssMissionActionInfractionEnvTargetTest .kt | 57 +++---- .../ProcessMissionActionInfractionTest.kt | 68 +++++--- .../mission/action/UpdateEnvActionTest.kt | 8 +- .../mission/action/UpdateFishActionTest.kt | 5 +- .../mission/action/UpdateNavActionTest.kt | 6 +- .../bff/adapters/v2/ActionControlInputTest.kt | 71 +------- .../action/JPAMissionActionRepositoryTest.kt | 6 +- .../mocks/mission/action/ControlInputMock.kt | 58 +++++++ .../mission/action/MissionActionModelMock.kt | 2 +- 27 files changed, 506 insertions(+), 250 deletions(-) create mode 100644 backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControlEnvTarget.kt create mode 100644 backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/ControlInputMock.kt diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/v2/ActionControlEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/v2/ActionControlEntity.kt index 5ef92dca..ea4ac7e1 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/v2/ActionControlEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/control/v2/ActionControlEntity.kt @@ -13,22 +13,7 @@ data class ActionControlEntity( var controlNavigation: ControlNavigationEntity? = null ) { - fun computeInfractionControlId() { - controlSecurity?.infractions?.forEach { it.controlId = controlSecurity?.id } - controlGensDeMer?.infractions?.forEach { it.controlId = controlGensDeMer?.id } - controlNavigation?.infractions?.forEach { it.controlId = controlNavigation?.id } - controlAdministrative?.infractions?.forEach { it.controlId = controlAdministrative?.id } - } - - fun getControlInfractions(): List { - val genDeMerInfractions = controlGensDeMer?.infractions ?: listOf() - val securityInfractions = controlSecurity?.infractions ?: listOf() - val navigationInfractions = controlNavigation?.infractions ?: listOf() - val administrativeInfractions = controlAdministrative?.infractions ?: listOf() - return genDeMerInfractions + securityInfractions + navigationInfractions + administrativeInfractions - } - - fun processInfractions(infractions: List?) { + fun seInfractions(infractions: List?) { controlSecurity?.infractions = infractions?.filter { it.controlId == controlSecurity?.id } controlGensDeMer?.infractions = infractions?.filter { it.controlId == controlGensDeMer?.id } controlNavigation?.infractions = infractions?.filter { it.controlId == controlNavigation?.id } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/infraction/InfractionEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/infraction/InfractionEntity.kt index a8459931..d2ea09c8 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/infraction/InfractionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/infraction/InfractionEntity.kt @@ -14,4 +14,32 @@ data class InfractionEntity( var observations: String? = null, var natinfs: List? = null, var target: InfractionEnvTargetEntity? = null -) +) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as InfractionEntity + return id == other.id + && missionId == other.missionId + && actionId == other.actionId + && controlId == other.controlId + && controlType == other.controlType + && observations == other.observations + && Objects.equals(target, other.target) + && Objects.equals(natinfs, other.natinfs) + } + + override fun hashCode(): Int { + var result = id.hashCode() + result = 31 * result + missionId + result = 31 * result + actionId.hashCode() + result = 31 * result + (controlId?.hashCode() ?: 0) + result = 31 * result + (controlType?.hashCode() ?: 0) + result = 31 * result + (infractionType?.hashCode() ?: 0) + result = 31 * result + (observations?.hashCode() ?: 0) + result = 31 * result + (natinfs?.hashCode() ?: 0) + result = 31 * result + (target?.hashCode() ?: 0) + return result + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/infraction/InfractionEnvTargetEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/infraction/InfractionEnvTargetEntity.kt index f0e7c986..92b49231 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/infraction/InfractionEnvTargetEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/infraction/InfractionEnvTargetEntity.kt @@ -13,5 +13,31 @@ data class InfractionEnvTargetEntity( var vesselType: VesselTypeEnum? = null, var vesselSize: VesselSizeEnum? = null, val vesselIdentifier: String? = null, +) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false -) + other as InfractionEnvTargetEntity + return id == other.id + && missionId == other.missionId + && actionId == other.actionId + && infractionId == other.infractionId + && identityControlledPerson == other.identityControlledPerson + && vesselType == other.vesselType + && vesselSize == other.vesselSize + && vesselIdentifier == other.vesselIdentifier + } + + override fun hashCode(): Int { + var result = id.hashCode() + result = 31 * result + missionId + result = 31 * result + actionId.hashCode() + result = 31 * result + infractionId.hashCode() + result = 31 * result + identityControlledPerson.hashCode() + result = 31 * result + (vesselType?.hashCode() ?: 0) + result = 31 * result + (vesselSize?.hashCode() ?: 0) + result = 31 * result + (vesselIdentifier?.hashCode() ?: 0) + return result + } +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/MissionNavActionEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/MissionNavActionEntity.kt index baecb11d..6d3ee659 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/MissionNavActionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/MissionNavActionEntity.kt @@ -155,7 +155,7 @@ class MissionNavActionEntity( return MissionNavActionEntity( id = model.id, missionId = model.missionId, - actionType = model.actionType.let { ActionType.valueOf(it) }, + actionType = model.actionType, //model.actionType.let { ActionType.valueOf(it) }, startDateTimeUtc = model.startDateTimeUtc, endDateTimeUtc = model.endDateTimeUtc, observations = model.observations, diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateEnvAction.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateEnvAction.kt index 27ccf8d9..7cbe18ae 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateEnvAction.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateEnvAction.kt @@ -4,6 +4,7 @@ import fr.gouv.dgampa.rapportnav.config.UseCase import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionEnvActionEntity import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.PatchEnvAction import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControlEnvTarget import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfractionEnvTarget import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.action.ActionEnvInput import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput @@ -14,12 +15,14 @@ import org.slf4j.LoggerFactory class UpdateEnvAction( private val patchEnvAction: PatchEnvAction, private val processMissionActionControl: ProcessMissionActionControl, + private val processMissionActionControlEnvTarget: ProcessMissionActionControlEnvTarget, private val processMissionActionInfractionEnvTarget: ProcessMissionActionInfractionEnvTarget ) { private val logger = LoggerFactory.getLogger(UpdateEnvAction::class.java) fun execute(input: MissionActionInput): MissionEnvActionEntity? { val action = MissionEnvActionDataInput.toMissionEnvActionEntity(input) + val controlInputs = input.env?.getControls(actionId = input.id, missionId = input.missionId) return try { patchEnvAction.execute( ActionEnvInput( @@ -30,11 +33,28 @@ class UpdateEnvAction( observationsByUnit = action.observationsByUnit ) ) - val controls = processMissionActionControl.execute(action) - val infractions = - processMissionActionInfractionEnvTarget.execute(action.getActionId(), input.env?.infractions) + val controls = processMissionActionControl.execute( + controls = controlInputs, + actionId = action.getActionId() + ) + + val infractionInput = input.env?.getInfractions( + missionId = input.missionId, + actionId = action.getActionId() + ) + + infractionInput?.forEach { + val controlId = processMissionActionControlEnvTarget.execute(infraction = it, controls = controls) + it.controlId = controlId + } + + val infractions = processMissionActionInfractionEnvTarget.execute( + actionId = action.getActionId(), + infractions = infractionInput + ) + action.navInfractions = infractions - action.computeControls(controls) + action.computeControls(controls.toActionControlEntity()) action } catch (e: Exception) { logger.error("UpdateEnvAction failed update Action", e) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateFishAction.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateFishAction.kt index c823b208..ea86c1e6 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateFishAction.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateFishAction.kt @@ -20,6 +20,7 @@ class UpdateFishAction( fun execute(input: MissionActionInput): MissionFishActionEntity? { val action = MissionFishActionDataInput.toMissionFishActionEntity(input) + val controlInputs = input.fish?.getControls(actionId = input.id, missionId = input.missionId) return try { patchFishAction.execute( ActionFishInput( @@ -30,10 +31,16 @@ class UpdateFishAction( observationsByUnit = action.observationsByUnit ) ) - val controls = processMissionActionControl.execute(action) - val infractions = processMissionActionInfraction.execute(action.getActionId(), controls) - controls.processInfractions(infractions) - action.computeControls(controls) + val controls = processMissionActionControl.execute( + controls = controlInputs, + actionId = action.getActionId() + ) + val infractions = processMissionActionInfraction.execute( + actionId = action.getActionId(), + infractions = controls.getAllInfractions() + ) + action.computeControls(controls.toActionControlEntity(infractions)) + action.computeCompleteness() action } catch (e: Exception) { logger.error("UpdateFishAction failed update Action", e) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateNavAction.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateNavAction.kt index d3112c51..856e5d43 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateNavAction.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateNavAction.kt @@ -19,12 +19,20 @@ class UpdateNavAction( fun execute(input: MissionActionInput): MissionNavActionEntity? { val action = MissionNavActionDataInput.toMissionNavActionEntity(input) + val controlInputs = input.nav?.getControls(actionId = input.id, missionId = input.missionId) return try { missionActionRepository.save(action) - val controls = processMissionActionControl.execute(action) - val infractions = processMissionActionInfraction.execute(action.getActionId(), controls) - controls.processInfractions(infractions) - action.computeControls(controls) + val controls = processMissionActionControl.execute( + controls = controlInputs, + actionId = action.getActionId() + ) + + val infractions = processMissionActionInfraction.execute( + actionId = action.getActionId(), + infractions = controls.getAllInfractions() + ) + action.computeControls(controls.toActionControlEntity(infractions)) + action.computeCompleteness() action } catch (e: Exception) { logger.error("UpdateNavAction failed update Action", e) diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControl.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControl.kt index b9131473..9994c18d 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControl.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControl.kt @@ -1,14 +1,12 @@ package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2 import fr.gouv.dgampa.rapportnav.config.UseCase -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.* -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionActionEntity +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.BaseControlEntity import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlAdministrativeRepository import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlGensDeMerRepository import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlNavigationRepository import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlSecurityRepository -import java.util.* +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.* @UseCase class ProcessMissionActionControl( @@ -18,13 +16,14 @@ class ProcessMissionActionControl( private val controlAdministrativeRepo: IControlAdministrativeRepository ) { - fun execute(action: MissionActionEntity): ActionControlEntity { - val controlSecurity = processControlSecurity(action.getActionId(), control = action.controlSecurity) - val controlGensDeMer = processControlGensDeMer(action.getActionId(), control = action.controlGensDeMer) - val controlNavigation = processControlNavigation(action.getActionId(), control = action.controlNavigation) + fun execute(actionId: String, controls: ActionControlInput?): ActionControlInput { + val controlSecurity = processControlSecurity(actionId = actionId, control = controls?.controlSecurity) + val controlGensDeMer = processControlGensDeMer(actionId = actionId, control = controls?.controlGensDeMer) + val controlNavigation = processControlNavigation(actionId = actionId, control = controls?.controlNavigation) val controlAdministrative = - processControlAdministrative(action.getActionId(), control = action.controlAdministrative) - return ActionControlEntity( + processControlAdministrative(actionId = actionId, control = controls?.controlAdministrative) + + return ActionControlInput( controlSecurity = controlSecurity, controlGensDeMer = controlGensDeMer, controlNavigation = controlNavigation, @@ -32,67 +31,72 @@ class ProcessMissionActionControl( ) } - private inline fun processControl( + private inline fun processControl( actionId: String, - control: T?, - findByActionId: (String) -> T?, + control: M?, + findControlByActionId: (String) -> T?, saveControl: (T) -> T - ): UUID? { - val existingControl = findByActionId(actionId) - if (control != null && !control.equals(existingControl)) { - return saveControl(control).id + ): T? { + if (control?.id != null) { + val existingControl = findControlByActionId(actionId) + if (control.toEntity().equals(existingControl)) return existingControl } - return existingControl?.id + if (control == null) return null + System.out.println("[processMissionAction] SAVE: $actionId") + return saveControl(control.toEntity() as T) } - private fun processControlSecurity(actionId: String, control: ControlSecurityEntity?): ControlSecurityEntity? { - val id = processControl( + private fun processControlSecurity(actionId: String, control: ControlSecurityInput2?): ControlSecurityInput2? { + val response = processControl( actionId = actionId, control = control, saveControl = { controlSecurityRepo.save(it).toControlSecurityEntity() }, - findByActionId = { controlSecurityRepo.findByActionControlId(it)?.toControlSecurityEntity() }, + findControlByActionId = { controlSecurityRepo.findByActionControlId(it).toControlSecurityEntity() }, ) - if (id != null && control != null) control.id = id + if (response?.id != null) control?.id = response.id return control } - private fun processControlGensDeMer(actionId: String, control: ControlGensDeMerEntity?): ControlGensDeMerEntity? { - val id = processControl( + private fun processControlGensDeMer(actionId: String, control: ControlGensDeMerInput2?): ControlGensDeMerInput2? { + val response = processControl( actionId = actionId, control = control, saveControl = { controlGensDeMerRepo.save(it).toControlGensDeMerEntity() }, - findByActionId = { controlGensDeMerRepo.findByActionControlId(it)?.toControlGensDeMerEntity() }, + findControlByActionId = { controlGensDeMerRepo.findByActionControlId(it).toControlGensDeMerEntity() }, ) - if (id != null && control != null) control.id = id + if (response?.id != null) control?.id = response.id return control } private fun processControlNavigation( actionId: String, - control: ControlNavigationEntity? - ): ControlNavigationEntity? { - val id = processControl( + control: ControlNavigationInput2? + ): ControlNavigationInput2? { + val response = processControl( actionId = actionId, control = control, saveControl = { controlNavigationRepo.save(it).toControlNavigationEntity() }, - findByActionId = { controlNavigationRepo.findByActionControlId(it)?.toControlNavigationEntity() }, + findControlByActionId = { controlNavigationRepo.findByActionControlId(it).toControlNavigationEntity() }, ) - if (id != null && control != null) control.id = id + if (response?.id != null) control?.id = response.id return control } private fun processControlAdministrative( actionId: String, - control: ControlAdministrativeEntity? - ): ControlAdministrativeEntity? { - val id = processControl( + control: ControlAdministrativeInput2? + ): ControlAdministrativeInput2? { + val response = processControl( actionId = actionId, control = control, saveControl = { controlAdministrativeRepo.save(it).toControlAdministrativeEntity() }, - findByActionId = { controlAdministrativeRepo.findByActionControlId(it).toControlAdministrativeEntity() }, + findControlByActionId = { + controlAdministrativeRepo.findByActionControlId(it).toControlAdministrativeEntity() + }, ) - if (id != null && control != null) control.id = id + if (response?.id != null) control?.id = response.id return control } + } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControlEnvTarget.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControlEnvTarget.kt new file mode 100644 index 00000000..f9590131 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControlEnvTarget.kt @@ -0,0 +1,156 @@ +package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2 + +import fr.gouv.dgampa.rapportnav.config.UseCase +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.* +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlAdministrativeRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlGensDeMerRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlNavigationRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlSecurityRepository +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.ActionControlInput +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.InfractionInput2 +import java.util.* + +@UseCase +class ProcessMissionActionControlEnvTarget( + private val controlSecurityRepo: IControlSecurityRepository, + private val controlNavigationRepo: IControlNavigationRepository, + private val controlGensDeMerRepo: IControlGensDeMerRepository, + private val controlAdministrativeRepo: IControlAdministrativeRepository +) { + + fun execute(infraction: InfractionInput2, controls: ActionControlInput): String? { + val controlType = infraction.controlType?.let { ControlType.valueOf(it) } + val id = when (controlType) { + ControlType.SECURITY -> controls.controlSecurity?.id + ?: processControlSecurity( + actionId = infraction.actionId!!, + missionId = infraction.missionId!! + ).id + + ControlType.GENS_DE_MER -> controls.controlGensDeMer?.id ?: processControlGensDeMer( + actionId = infraction.actionId!!, + missionId = infraction.missionId!! + ).id + + ControlType.NAVIGATION -> controls.controlNavigation?.id ?: processControlNavigation( + actionId = infraction.actionId!!, + missionId = infraction.missionId!! + ).id + + ControlType.ADMINISTRATIVE -> controls.controlAdministrative?.id ?: processControlAdministrative( + actionId = infraction.actionId!!, + missionId = infraction.missionId!! + ).id + + null -> null + } + return id?.toString() + } + + private inline fun processControl( + missionId: Int, + actionId: String, + saveControl: (T) -> T, + findControlByActionId: (String) -> T?, + createControl: (UUID, String, Int) -> T, + ): T { + val existingControl = findControlByActionId(actionId) + if (existingControl?.id != null) return existingControl + val control = createControl(UUID.randomUUID(), actionId, missionId) + return saveControl(control) + } + + + private fun processControlSecurity(actionId: String, missionId: Int): ControlSecurityEntity { + return processControl( + actionId = actionId, + missionId = missionId, + createControl = { id: UUID, s: String, i: Int -> + ControlSecurityEntity( + id = id, + missionId = i, + actionControlId = s, + amountOfControls = 1 + ) + }, + saveControl = { controlSecurityRepo.save(it).toControlSecurityEntity() }, + findControlByActionId = { + if (controlSecurityRepo.existsByActionControlId(it)) { + controlSecurityRepo.findByActionControlId(it).toControlSecurityEntity() + } else { + null + } + }, + ) + } + + private fun processControlGensDeMer(actionId: String, missionId: Int): ControlGensDeMerEntity { + return processControl( + actionId = actionId, + missionId = missionId, + createControl = { id: UUID, s: String, i: Int -> + ControlGensDeMerEntity( + id = id, + missionId = i, + actionControlId = s, + amountOfControls = 1 + ) + }, + saveControl = { controlGensDeMerRepo.save(it).toControlGensDeMerEntity() }, + findControlByActionId = { + if (controlGensDeMerRepo.existsByActionControlId(it)) { + controlGensDeMerRepo.findByActionControlId(it).toControlGensDeMerEntity() + } else { + null + } + }, + ) + } + + private fun processControlNavigation(actionId: String, missionId: Int): ControlNavigationEntity { + return processControl( + actionId = actionId, + missionId = missionId, + createControl = { id: UUID, s: String, i: Int -> + ControlNavigationEntity( + id = id, + missionId = i, + actionControlId = s, + amountOfControls = 1 + ) + }, + saveControl = { controlNavigationRepo.save(it).toControlNavigationEntity() }, + findControlByActionId = { + if (controlNavigationRepo.existsByActionControlId(it)) { + controlNavigationRepo.findByActionControlId(it).toControlNavigationEntity() + } else { + null + } + }, + ) + } + + private fun processControlAdministrative(actionId: String, missionId: Int): ControlAdministrativeEntity { + return processControl( + actionId = actionId, + missionId = missionId, + createControl = { id: UUID, s: String, i: Int -> + ControlAdministrativeEntity( + id = id, + missionId = i, + actionControlId = s, + amountOfControls = 1 + ) + }, + saveControl = { controlAdministrativeRepo.save(it).toControlAdministrativeEntity() }, + findControlByActionId = { + if (controlAdministrativeRepo.existsByActionControlId(it)) { + controlAdministrativeRepo.findByActionControlId(it).toControlAdministrativeEntity() + } else { + null + } + }, + ) + } + +} diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfraction.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfraction.kt index 4188049d..c91d9c37 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfraction.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfraction.kt @@ -1,30 +1,28 @@ package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2 import fr.gouv.dgampa.rapportnav.config.UseCase -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionRepository +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.InfractionInput2 @UseCase class ProcessMissionActionInfraction( - private val infractionRepo: IInfractionRepository, + private val infractionRepo: IInfractionRepository ) { - fun execute(actionId: String, control: ActionControlEntity): List? { - control.computeInfractionControlId() - val toSaveInfractions = control.getControlInfractions() - val infractionIds = toSaveInfractions.map { it.id } - val controlIds = toSaveInfractions.map { it.controlId } + fun execute(actionId: String, infractions: List): List? { + val infractionIds = infractions.map { it.id } val databaseInfractions = infractionRepo .findAllByActionId(actionId) .map { it.toInfractionEntity() } - .filter { controlIds.contains(it.controlId) } + .filter { it.controlId != null } - val toDeleteInfractions = databaseInfractions.filter { !infractionIds.contains(it.id) } + val toDeleteInfractions = databaseInfractions.filter { !infractionIds.contains(it.id.toString()) } + val toSaveInfractions = infractions.map { it.toInfractionEntity() }.filter { !databaseInfractions.contains(it) } delete(toDeleteInfractions) - return save(toSaveInfractions) //TODO: is not equals save + return save(toSaveInfractions) } fun save(infractions: List?): List? { diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfractionEnvTarget.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfractionEnvTarget.kt index 05a0a36a..d17174a0 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfractionEnvTarget.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfractionEnvTarget.kt @@ -2,12 +2,9 @@ package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2 import fr.gouv.dgampa.rapportnav.config.UseCase import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEnvTargetEntity import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionEnvTargetRepository import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionRepository -import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.Infraction -import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.InfractionsByVessel -import java.util.* +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.InfractionInput2 @UseCase class ProcessMissionActionInfractionEnvTarget( @@ -15,9 +12,7 @@ class ProcessMissionActionInfractionEnvTarget( private val infractionEnvTargetRepo: IInfractionEnvTargetRepository, ) { - fun execute(actionId: String, infractionByVessels: List?): List? { - val infractions = - infractionByVessels?.flatMap { it.infractions }?.filter { it.controlId != null || it.controlType != null } + fun execute(actionId: String, infractions: List?): List? { val infractionIds = infractions?.map { it.id } ?: listOf() val databaseInfractions = infractionRepo @@ -30,25 +25,16 @@ class ProcessMissionActionInfractionEnvTarget( return save(infractions) //TODO: is not equals save } - fun save(infractions: List?): List? { + fun save(infractions: List?): List? { // check target / create or Update target // create infractionEntity -- > save target //save infraction return infractions?.map { // todo check if it has changed - val target = it.target - val newTarget = InfractionEnvTargetEntity( - id = UUID.fromString(target?.id), - missionId = it.missionId, - actionId = it.actionId, - infractionId = UUID.fromString(it.id), - vesselIdentifier = target?.vesselIdentifier, - vesselSize = target?.vesselSize, - vesselType = target?.vesselType, - identityControlledPerson = target?.identityControlledPerson!! - ) - infractionEnvTargetRepo.save(infractionTarget = newTarget, infraction = it.toInfractionEntity()) - infractionRepo.save(it.toInfractionEntity()).toInfractionEntity() + val newTarget = it.toInfractionEnvTargetEntity() + val entity = it.toInfractionEntity() + entity.target = newTarget + infractionRepo.save(entity).toInfractionEntity() } } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlAdministrativeInput2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlAdministrativeInput2.kt index 530a7e15..ad02ea33 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlAdministrativeInput2.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlAdministrativeInput2.kt @@ -12,9 +12,9 @@ data class ControlAdministrativeInput2( override var infractions: List? = null, override val observations: String? = null, override val hasBeenDone: Boolean? = null, - val compliantOperatingPermit: ControlResult?, - val upToDateNavigationPermit: ControlResult?, - val compliantSecurityDocuments: ControlResult?, + val compliantOperatingPermit: ControlResult? = null, + val upToDateNavigationPermit: ControlResult? = null, + val compliantSecurityDocuments: ControlResult? = null, ) : BaseControlInput() { override fun toEntity(): ControlAdministrativeEntity { return ControlAdministrativeEntity( diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlNavigationInput2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlNavigationInput2.kt index 073d55a6..4468f10b 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlNavigationInput2.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlNavigationInput2.kt @@ -1,7 +1,6 @@ package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavigationEntity -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity import java.util.* data class ControlNavigationInput2( diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionActionController.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionActionController.kt index 11c750fb..955517e6 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionActionController.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/v2/MissionActionController.kt @@ -45,6 +45,7 @@ class MissionActionController( @Argument actionId: String, @Argument missionId: Int, ): MissionActionOutput? { + val navAction = getNavActionById.execute(actionId = UUID.fromString(actionId)) if (navAction != null) return MissionActionOutput.fromMissionActionEntity(navAction) val fishAction = getFishActionById.execute(missionId = missionId, actionId = actionId) @@ -58,28 +59,26 @@ class MissionActionController( fun updateMissionAction( @Argument action: MissionActionInput ): MissionActionOutput? { - val response = when (action.source) { + val response = when (action.source) { MissionSourceEnum.RAPPORTNAV -> updateNavAction(action) MissionSourceEnum.MONITORENV -> updateEnvAction(action) MissionSourceEnum.MONITORFISH -> updateFishAction(action) else -> throw RuntimeException("Unknown mission action source: ${action.source}") } + this.logger.info(action.id) return MissionActionOutput.fromMissionActionEntity(response) } private fun updateNavAction(action: MissionActionInput): MissionActionEntity? { - val response = updateNavAction.execute(action) - return getNavActionById.execute(actionId = response?.id) + return updateNavAction.execute(action) } private fun updateEnvAction(action: MissionActionInput): MissionActionEntity? { - val response = updateEnvAction.execute(action) - return getEnvActionById.execute(missionId = response?.missionId, actionId = response?.id.toString()) + return updateEnvAction.execute(action) } private fun updateFishAction(action: MissionActionInput): MissionActionEntity? { - val response = updateFishAction.execute(action) - return getFishActionById.execute(missionId = response?.missionId, actionId = response?.id.toString()) + return updateFishAction.execute(action) } diff --git a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/model/mission/action/v2/MissionActionModel.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/model/mission/action/v2/MissionActionModel.kt index 36a7af34..07309961 100644 --- a/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/model/mission/action/v2/MissionActionModel.kt +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/database/model/mission/action/v2/MissionActionModel.kt @@ -1,10 +1,10 @@ package fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.action.v2 +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity -import jakarta.persistence.Column -import jakarta.persistence.Entity -import jakarta.persistence.Id -import jakarta.persistence.Table +import jakarta.persistence.* +import org.hibernate.annotations.JdbcType +import org.hibernate.dialect.PostgreSQLEnumJdbcType import java.time.Instant import java.util.* @@ -18,8 +18,10 @@ data class MissionActionModel( @Column(name = "mission_id", nullable = false) var missionId: Int, + @Enumerated(EnumType.STRING) @Column(name = "action_type", nullable = false) - var actionType: String, + @JdbcType(PostgreSQLEnumJdbcType::class) + var actionType: ActionType, @Column(name = "is_complete_for_stats", nullable = true) var isCompleteForStats: Boolean? = null, @@ -124,7 +126,7 @@ data class MissionActionModel( fun fromMissionActionEntity(action: MissionNavActionEntity) = MissionActionModel( id = action.id, missionId = action.missionId, - actionType = action.actionType.toString(), + actionType = action.actionType, isCompleteForStats = action.isCompleteForStats, startDateTimeUtc = action.startDateTimeUtc?: Instant.now(), endDateTimeUtc = action.endDateTimeUtc, diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetNavActionByIdTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetNavActionByIdTest.kt index 73af9d15..7cf4f05f 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetNavActionByIdTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetNavActionByIdTest.kt @@ -47,7 +47,7 @@ class GetNavActionByIdTest { isAntiPolDeviceDeployed = true, isSimpleBrewingOperationDone = true, diversionCarriedOut = true, - actionType = ActionType.CONTROL.toString(), + actionType = ActionType.CONTROL, ) val mockControl = ControlMock.createAllControl() diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetNavActionListByMissionIdTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetNavActionListByMissionIdTest.kt index cc5ce081..a8560582 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetNavActionListByMissionIdTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetNavActionListByMissionIdTest.kt @@ -48,7 +48,7 @@ class GetNavActionListByMissionIdTest { isAntiPolDeviceDeployed = true, isSimpleBrewingOperationDone = true, diversionCarriedOut = true, - actionType = ActionType.CONTROL.toString(), + actionType = ActionType.CONTROL, ) val mockControl = ControlMock.createAllControl() diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionControlTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionControlTest.kt index ed536dab..2732eb14 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionControlTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionControlTest.kt @@ -11,7 +11,7 @@ import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.C import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.ControlGensDeMerModel import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.ControlNavigationModel import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.ControlSecurityModel -import fr.gouv.gmampa.rapportnav.mocks.mission.action.ControlMock +import fr.gouv.gmampa.rapportnav.mocks.mission.action.ControlInputMock import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.mockito.Mockito.`when` @@ -43,7 +43,15 @@ class ProcessMissionActionControlTest { @Test fun `Should process all controls when execute, `() { val action = getMissionAction() - val controls = ControlMock.createAllControl(actionId = action.id.toString()) + val input = ControlInputMock.createAllControl() + + input.controlGensDeMer?.setMissionIdAndActionId(actionId = action.id.toString(), missionId = action.missionId) + input.controlSecurity?.setMissionIdAndActionId(actionId = action.id.toString(), missionId = action.missionId) + input.controlNavigation?.setMissionIdAndActionId(actionId = action.id.toString(), missionId = action.missionId) + input.controlAdministrative?.setMissionIdAndActionId(actionId = action.id.toString(), missionId = action.missionId) + + val controls = input.toActionControlEntity() + action.controlSecurity = controls.controlSecurity action.controlNavigation = controls.controlNavigation action.controlAdministrative = controls.controlAdministrative @@ -56,7 +64,7 @@ class ProcessMissionActionControlTest { ControlAdministrativeModel.fromControlAdministrativeEntity(controls.controlAdministrative!!) controlAdministrationModel.hasBeenDone = true - `when`(controlSecurityRepo.findByActionControlId(action.id.toString())).thenReturn(null) + `when`(controlSecurityRepo.findByActionControlId(action.id.toString())).thenReturn(controlSecurityModel) `when`(controlGensDeMerRepo.findByActionControlId(action.id.toString())).thenReturn(controlGensDeMerModel) `when`(controlNavigationRepo.findByActionControlId(action.id.toString())).thenReturn(controlNavigationModel) `when`(controlAdministrativeRepo.findByActionControlId(action.id.toString())).thenReturn( @@ -75,13 +83,14 @@ class ProcessMissionActionControlTest { controlAdministrativeRepo = controlAdministrativeRepo ) - val actionControl = processMissionActionControl.execute(action) + input.controlGensDeMer = null + val actionControl = processMissionActionControl.execute(actionId = action.id.toString(), controls = input) assertThat(actionControl).isNotNull assertThat(actionControl.controlGensDeMer).isNull() - assertThat(actionControl.controlSecurity).isEqualTo(controls.controlSecurity) - assertThat(actionControl.controlNavigation).isEqualTo(controls.controlNavigation) - assertThat(actionControl.controlAdministrative).isEqualTo(controls.controlAdministrative) + assertThat(actionControl.controlSecurity).isEqualTo(input.controlSecurity) + assertThat(actionControl.controlNavigation).isEqualTo(input.controlNavigation) + assertThat(actionControl.controlAdministrative).isEqualTo(input.controlAdministrative) } diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionEnvTargetTest .kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionEnvTargetTest .kt index 47426c0e..658118b2 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionEnvTargetTest .kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionEnvTargetTest .kt @@ -6,6 +6,8 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.Infracti import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionEnvTargetRepository import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionRepository import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfractionEnvTarget +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.InfractionInput2 +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.InfractionTargetInput2 import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.Infraction import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.InfractionTarget import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.infraction.InfractionsByVessel @@ -39,7 +41,7 @@ class ProcessMissionActionInfractionEnvTargetTest { lateinit var deleteCaptor: ArgumentCaptor> @Captor - lateinit var saveCaptor: ArgumentCaptor> + lateinit var saveCaptor: ArgumentCaptor> @MockBean private lateinit var processMissionActionInfractionEnvTarget: ProcessMissionActionInfractionEnvTarget @@ -48,7 +50,6 @@ class ProcessMissionActionInfractionEnvTargetTest { fun `test execute process infractions env target`() { val actionId = UUID.randomUUID() val infractions = getInfractions(actionId.toString()) - val byVessels = InfractionsByVessel(infractions = infractions).groupInfractionsByVesselIdentifier(infractions) //Infraction entities val infractionToDelete = InfractionEntityMock.create( @@ -70,7 +71,7 @@ class ProcessMissionActionInfractionEnvTargetTest { infractionEnvTargetRepo = infractionEnvTargetRepo ) ) - val entities = processMissionActionInfractionEnvTarget.execute(actionId.toString(), byVessels) + val entities = processMissionActionInfractionEnvTarget.execute(actionId.toString(), infractions) verify(processMissionActionInfractionEnvTarget).save(saveCaptor.capture()) verify(processMissionActionInfractionEnvTarget).delete(deleteCaptor.capture()) @@ -79,82 +80,82 @@ class ProcessMissionActionInfractionEnvTargetTest { assertThat(entities).isNotNull assertThat(6).isEqualTo(saveCaptor.value.size) assertThat(1).isEqualTo(deleteCaptor.value.size) - assertThat(infractionToDelete.id).isEqualTo(deleteCaptor.value.get(0).id) + assertThat(infractionToDelete.id).isEqualTo(deleteCaptor.value[0].id) } - private fun getInfractions(actionId: String): List { + private fun getInfractions(actionId: String): List { return listOf( - Infraction( + InfractionInput2( id = UUID.randomUUID().toString(), actionId = actionId, missionId = 145, - controlId = UUID.randomUUID(), + controlId = UUID.randomUUID().toString(), infractionType = InfractionTypeEnum.WITH_REPORT, - target = InfractionTarget( + target = InfractionTargetInput2( id = UUID.randomUUID().toString(), identityControlledPerson = "identityPerson1" ) ), - Infraction( + InfractionInput2( id = UUID.randomUUID().toString(), actionId = actionId, - controlId = UUID.randomUUID(), + controlId = UUID.randomUUID().toString(), missionId = 145, - controlType = ControlType.SECURITY, + controlType = ControlType.SECURITY.toString(), infractionType = InfractionTypeEnum.WITH_REPORT, - target = InfractionTarget( + target = InfractionTargetInput2( id = UUID.randomUUID().toString(), vesselIdentifier = "firstVesselIdentifier", identityControlledPerson = "identityPerson2" ) ), - Infraction( + InfractionInput2( id = UUID.randomUUID().toString(), actionId = actionId, missionId = 145, - controlId = UUID.randomUUID(), - controlType = ControlType.ADMINISTRATIVE, + controlId = UUID.randomUUID().toString(), + controlType = ControlType.ADMINISTRATIVE.toString(), infractionType = InfractionTypeEnum.WITH_REPORT, - target = InfractionTarget( + target = InfractionTargetInput2( id = UUID.randomUUID().toString(), identityControlledPerson = "identityPerson3" ) ), - Infraction( + InfractionInput2( id = UUID.randomUUID().toString(), actionId = actionId, missionId = 145, - controlId = UUID.randomUUID(), - controlType = ControlType.GENS_DE_MER, + controlId = UUID.randomUUID().toString(), + controlType = ControlType.GENS_DE_MER.toString(), infractionType = InfractionTypeEnum.WITH_REPORT, - target = InfractionTarget( + target = InfractionTargetInput2( id = UUID.randomUUID().toString(), vesselIdentifier = "firstVesselIdentifier", identityControlledPerson = "identityPerson4", ) ), - Infraction( + InfractionInput2( id = UUID.randomUUID().toString(), actionId = actionId, missionId = 145, - controlId = UUID.randomUUID(), - controlType = ControlType.NAVIGATION, + controlId = UUID.randomUUID().toString(), + controlType = ControlType.NAVIGATION.toString(), infractionType = InfractionTypeEnum.WITH_REPORT, - target = InfractionTarget( + target = InfractionTargetInput2( id = UUID.randomUUID().toString(), vesselIdentifier = "secondVesselIdentifier", identityControlledPerson = "identityPerson5", ) ), - Infraction( + InfractionInput2( id = UUID.randomUUID().toString(), actionId = actionId, missionId = 145, - controlId = UUID.randomUUID(), - controlType = ControlType.SECURITY, + controlId = UUID.randomUUID().toString(), + controlType = ControlType.SECURITY.toString(), infractionType = InfractionTypeEnum.WITH_REPORT, - target = InfractionTarget( + target = InfractionTargetInput2( id = UUID.randomUUID().toString(), identityControlledPerson = "identityPerson1", ) diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionTest.kt index 972f541a..b43f219a 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionTest.kt @@ -1,14 +1,15 @@ package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.action import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionRepository import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfraction +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.ActionControlInput +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.InfractionInput2 import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.ControlNavigationModel import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.control.ControlSecurityModel import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.infraction.InfractionModel -import fr.gouv.gmampa.rapportnav.mocks.mission.action.ControlMock +import fr.gouv.gmampa.rapportnav.mocks.mission.action.ControlInputMock import fr.gouv.gmampa.rapportnav.mocks.mission.infraction.InfractionEntityMock import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -47,7 +48,12 @@ class ProcessMissionActionInfractionTest { //Infraction entities val securityInfraction = getInfractionSecurityEntity(actionId) val infractionToDelete = getInfractionNavigationEntity(actionId) - val mockSaveInfraction = InfractionEntityMock.create(controlType = ControlType.SECURITY) + val mockSaveInfraction = + InfractionEntityMock.create( + controlType = ControlType.SECURITY, + missionId = 761, + actionId = actionId.toString() + ) //Control and infraction model val actionControl = getActionControlEntity(actionId, securityInfraction) @@ -61,7 +67,7 @@ class ProcessMissionActionInfractionTest { //When processMissionActionInfraction = Mockito.spy(ProcessMissionActionInfraction(infractionRepo)) - val infractions = processMissionActionInfraction.execute(actionId.toString(), actionControl) + val infractions = processMissionActionInfraction.execute(actionId.toString(), actionControl.getAllInfractions()) verify(processMissionActionInfraction).save(saveCaptor.capture()) verify(processMissionActionInfraction).delete(deleteCaptor.capture()) @@ -69,58 +75,72 @@ class ProcessMissionActionInfractionTest { //Then assertThat(infractions).isNotNull assertThat(5).isEqualTo(saveCaptor.value.size) - assertThat(1).isEqualTo(deleteCaptor.value.size) + assertThat(2).isEqualTo(deleteCaptor.value.size) assertThat(infractionToDelete.id).isEqualTo(deleteCaptor.value.get(0).id) } private fun getInfractionNavigationEntity(actionId: UUID): InfractionEntity { val infractionToDelete = - InfractionEntityMock.create(actionId = actionId.toString(), controlType = ControlType.NAVIGATION) + InfractionEntityMock.create( + actionId = actionId.toString(), + controlType = ControlType.NAVIGATION, + missionId = 761 + ) return infractionToDelete } - private fun getInfractionSecurityEntity(actionId: UUID): InfractionEntity { + private fun getInfractionSecurityEntity(actionId: UUID): InfractionInput2 { val securityInfraction = - InfractionEntityMock.create(actionId = actionId.toString(), controlType = ControlType.SECURITY) + InfractionInput2( + actionId = actionId.toString(), + controlType = ControlType.SECURITY.toString(), + missionId = 761 + ) return securityInfraction } private fun getInfractionSecurityModel( - securityInfraction: InfractionEntity, - actionControl: ActionControlEntity + securityInfraction: InfractionInput2, + actionControl: ActionControlInput ): InfractionModel { - val securityInfractionModel = InfractionModel.fromInfractionEntity(securityInfraction) + val securityInfractionModel = InfractionModel.fromInfractionEntity(securityInfraction.toInfractionEntity()) securityInfractionModel.control = - ControlSecurityModel.fromControlSecurityEntity(actionControl.controlSecurity!!) + ControlSecurityModel.fromControlSecurityEntity(actionControl.controlSecurity!!.toEntity()) return securityInfractionModel } private fun getInfractionNavigationModel( infractionToDelete: InfractionEntity, - actionControl: ActionControlEntity + actionControl: ActionControlInput ): InfractionModel { val infractionToDeleteModel = InfractionModel.fromInfractionEntity(infractionToDelete) infractionToDeleteModel.control = - ControlNavigationModel.fromControlNavigationEntity(actionControl.controlNavigation!!) + ControlNavigationModel.fromControlNavigationEntity(actionControl.controlNavigation!!.toEntity()) return infractionToDeleteModel } private fun getActionControlEntity( actionId: UUID, - securityInfraction: InfractionEntity - ): ActionControlEntity { - val actionControl = ControlMock.createAllControl(actionId = actionId.toString()) + securityInfraction: InfractionInput2 + ): ActionControlInput { + val controlId = UUID.randomUUID() + val actionControl = ControlInputMock.createAllControl() + actionControl.controlGensDeMer?.setMissionIdAndActionId(actionId = actionId.toString(), missionId = 761) + actionControl.controlSecurity?.setMissionIdAndActionId(actionId = actionId.toString(), missionId = 761) + actionControl.controlNavigation?.setMissionIdAndActionId(actionId = actionId.toString(), missionId = 761) + actionControl.controlAdministrative?.setMissionIdAndActionId(actionId = actionId.toString(), missionId = 761) actionControl.controlGensDeMer?.infractions = listOf( - InfractionEntityMock.create( + InfractionInput2( actionId = actionId.toString(), - controlType = ControlType.GENS_DE_MER, - controlId = actionControl.controlGensDeMer?.id - + controlType = ControlType.GENS_DE_MER.toString(), + controlId = controlId.toString(), + missionId = 761 ), - InfractionEntityMock.create( + InfractionInput2( actionId = actionId.toString(), - controlType = ControlType.GENS_DE_MER, - controlId = actionControl.controlGensDeMer?.id + controlType = ControlType.GENS_DE_MER.toString(), + controlId = controlId.toString(), + missionId = 761 ) ) actionControl.controlSecurity?.infractions = listOf(securityInfraction) diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt index 5c3e8602..42a9961d 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt @@ -2,11 +2,12 @@ package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.action import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.PatchEnvAction import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.UpdateEnvAction import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl +import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControlEnvTarget import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfractionEnvTarget +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.ActionControlInput import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionEnvActionDataInput import org.assertj.core.api.Assertions.assertThat @@ -29,6 +30,8 @@ class UpdateEnvActionTest { @MockBean private lateinit var processMissionActionControl: ProcessMissionActionControl + @MockBean lateinit var processMissionActionControlEnvTarget : ProcessMissionActionControlEnvTarget + @MockBean private lateinit var processMissionActionInfractionEnvTarget: ProcessMissionActionInfractionEnvTarget @@ -45,12 +48,13 @@ class UpdateEnvActionTest { ) `when`(patchEnvAction.execute(anyOrNull())).thenReturn(null) - `when`(processMissionActionControl.execute(anyOrNull())).thenReturn(ActionControlEntity()) + `when`(processMissionActionControl.execute(anyOrNull(), anyOrNull())).thenReturn(ActionControlInput()) `when`(processMissionActionInfractionEnvTarget.execute(actionId, listOf())).thenReturn(listOf()) val updateNavAction = UpdateEnvAction( patchEnvAction = patchEnvAction, processMissionActionControl = processMissionActionControl, + processMissionActionControlEnvTarget = processMissionActionControlEnvTarget, processMissionActionInfractionEnvTarget = processMissionActionInfractionEnvTarget ) diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt index 3a9e5a84..3ce1c47f 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt @@ -7,6 +7,7 @@ import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.PatchFishAction import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.UpdateFishAction import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfraction +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.ActionControlInput import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionFishActionDataInput import org.assertj.core.api.Assertions.assertThat @@ -44,8 +45,8 @@ class UpdateFishActionTest { ) `when`(patchFishAction.execute(anyOrNull())).thenReturn(null) - `when`(processMissionActionControl.execute(anyOrNull())).thenReturn(ActionControlEntity()) - `when`(processMissionActionInfraction.execute(actionId, ActionControlEntity())).thenReturn(listOf()) + `when`(processMissionActionControl.execute(anyOrNull(), anyOrNull())).thenReturn(ActionControlInput()) + `when`(processMissionActionInfraction.execute(actionId, listOf())).thenReturn(listOf()) val updateNavAction = UpdateFishAction( patchFishAction = patchFishAction, diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateNavActionTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateNavActionTest.kt index 4e1453a0..4b0af2fa 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateNavActionTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateNavActionTest.kt @@ -5,13 +5,13 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselSi import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselTypeEnum import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlMethod -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.v2.ActionControlEntity import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusReason import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusType import fr.gouv.dgampa.rapportnav.domain.repositories.mission.action.INavMissionActionRepository import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.UpdateNavAction import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfraction +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.ActionControlInput import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionNavActionDataInput import fr.gouv.gmampa.rapportnav.mocks.mission.action.MissionActionModelMock @@ -51,8 +51,8 @@ class UpdateNavActionTest { ) val model = MissionActionModelMock.create() `when`(missionActionRepository.save(anyOrNull())).thenReturn(model) - `when`(processMissionActionControl.execute(anyOrNull())).thenReturn(ActionControlEntity()) - `when`(processMissionActionInfraction.execute(actionId, ActionControlEntity())).thenReturn(listOf()) + `when`(processMissionActionControl.execute(anyOrNull(), anyOrNull())).thenReturn(ActionControlInput()) + `when`(processMissionActionInfraction.execute(actionId, listOf())).thenReturn(listOf()) val updateNavAction = UpdateNavAction( missionActionRepository = missionActionRepository, diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ActionControlInputTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ActionControlInputTest.kt index b365a256..1f8b1637 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ActionControlInputTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ActionControlInputTest.kt @@ -1,8 +1,7 @@ package fr.gouv.gmampa.rapportnav.infrastructure.bff.adapters.v2 -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlResult -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.* +import fr.gouv.gmampa.rapportnav.mocks.mission.action.ControlInputMock import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -13,6 +12,7 @@ class ActionControlInputTest { @Test fun `execute should return list of all infractions`() { val action = getActionInput() + action.controlSecurity?.setMissionIdAndActionId(missionId = 761, actionId = "my action id") val infractions = action.getAllInfractions() assertThat(infractions.size).isEqualTo(5) } @@ -29,66 +29,11 @@ class ActionControlInputTest { } private fun getActionInput(): ActionControlInput { - val controlAdministrative = ControlAdministrativeInput2( - observations = "My beautiful observation", - amountOfControls = 2, - unitShouldConfirm = false, - unitHasConfirmed = true, - infractions = listOf( - InfractionInput2(controlType = ControlType.ADMINISTRATIVE.toString()) - ), - hasBeenDone = true, - compliantOperatingPermit = ControlResult.YES, - upToDateNavigationPermit = ControlResult.NO, - compliantSecurityDocuments = ControlResult.NOT_CONTROLLED, - ) - controlAdministrative.setMissionIdAndActionId(missionId = 761, actionId = "my action id") - - val controlGensDeMer = ControlGensDeMerInput2( - observations = "My beautiful observation", - amountOfControls = 2, - unitShouldConfirm = false, - unitHasConfirmed = true, - infractions = listOf( - InfractionInput2(controlType = ControlType.GENS_DE_MER.toString()) - ), - hasBeenDone = true, - knowledgeOfFrenchLawAndLanguage = ControlResult.YES, - staffOutnumbered = ControlResult.NO, - upToDateMedicalCheck = ControlResult.NOT_CONTROLLED - ) - controlGensDeMer.setMissionIdAndActionId(missionId = 761, actionId = "my action id") - - - val controlNavigation = ControlNavigationInput2( - observations = "My beautiful observation", - amountOfControls = 2, - unitShouldConfirm = false, - unitHasConfirmed = true, - infractions = listOf( - InfractionInput2(controlType = ControlType.NAVIGATION.toString()) - ), - hasBeenDone = true - ) - controlNavigation.setMissionIdAndActionId(missionId = 761, actionId = "my action id") - - val controlSecurity = ControlSecurityInput2( - observations = "My beautiful observation", - amountOfControls = 2, - unitShouldConfirm = false, - unitHasConfirmed = true, - infractions = listOf( - InfractionInput2(controlType = ControlType.SECURITY.toString()), - InfractionInput2(controlType = ControlType.SECURITY.toString()) - ), - hasBeenDone = true - ) - controlSecurity.setMissionIdAndActionId(missionId = 761, actionId = "my action id") - return ActionControlInput( - controlSecurity = controlSecurity, - controlGensDeMer = controlGensDeMer, - controlNavigation = controlNavigation, - controlAdministrative = controlAdministrative - ) + val action = ControlInputMock.createAllControl() + action.controlAdministrative?.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + action.controlGensDeMer?.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + action.controlNavigation?.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + action.controlSecurity?.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + return action } } diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/repositories/mission/crew/action/JPAMissionActionRepositoryTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/repositories/mission/crew/action/JPAMissionActionRepositoryTest.kt index cf2fea89..0ba7955f 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/repositories/mission/crew/action/JPAMissionActionRepositoryTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/repositories/mission/crew/action/JPAMissionActionRepositoryTest.kt @@ -27,19 +27,19 @@ class JPAMissionActionRepositoryTest { MissionActionModel( id = id1, missionId = 761, - actionType = ActionType.CONTROL.toString(), + actionType = ActionType.CONTROL, startDateTimeUtc = Instant.parse("2024-04-17T07:00:00Z"), ), MissionActionModel( id = UUID.randomUUID(), missionId = 761, - actionType = ActionType.ILLEGAL_IMMIGRATION.toString(), + actionType = ActionType.ILLEGAL_IMMIGRATION, startDateTimeUtc = Instant.parse("2024-04-17T07:00:00Z"), ), MissionActionModel( id = id2, missionId = 761, - actionType = ActionType.SURVEILLANCE.toString(), + actionType = ActionType.SURVEILLANCE, startDateTimeUtc = Instant.parse("2024-04-17T07:00:00Z"), ) ); diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/ControlInputMock.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/ControlInputMock.kt new file mode 100644 index 00000000..f721319e --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/ControlInputMock.kt @@ -0,0 +1,58 @@ +package fr.gouv.gmampa.rapportnav.mocks.mission.action + +import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.* +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.* + +object ControlInputMock { + fun createAllControl(actionId: String? = null, missionId: Int? = null): ActionControlInput { + return ActionControlInput( + controlSecurity = ControlSecurityInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf( + InfractionInput2(controlType = ControlType.SECURITY.toString()), + InfractionInput2(controlType = ControlType.SECURITY.toString()) + ), + hasBeenDone = true + ), + controlGensDeMer = ControlGensDeMerInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf( + InfractionInput2(controlType = ControlType.GENS_DE_MER.toString()) + ), + hasBeenDone = true, + knowledgeOfFrenchLawAndLanguage = ControlResult.YES, + staffOutnumbered = ControlResult.NO, + upToDateMedicalCheck = ControlResult.NOT_CONTROLLED + ), + controlNavigation = ControlNavigationInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf( + InfractionInput2(controlType = ControlType.NAVIGATION.toString()) + ), + hasBeenDone = true + ), + controlAdministrative = ControlAdministrativeInput2( + observations = "My beautiful observation", + amountOfControls = 2, + unitShouldConfirm = false, + unitHasConfirmed = true, + infractions = listOf( + InfractionInput2(controlType = ControlType.ADMINISTRATIVE.toString()) + ), + hasBeenDone = true, + compliantOperatingPermit = ControlResult.YES, + upToDateNavigationPermit = ControlResult.NO, + compliantSecurityDocuments = ControlResult.NOT_CONTROLLED, + ) + ) + } +} diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/MissionActionModelMock.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/MissionActionModelMock.kt index 0e4ced28..382314ee 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/MissionActionModelMock.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/MissionActionModelMock.kt @@ -21,7 +21,7 @@ object MissionActionModelMock { isAntiPolDeviceDeployed = true, isSimpleBrewingOperationDone = true, diversionCarriedOut = true, - actionType = ActionType.CONTROL.toString(), + actionType = ActionType.CONTROL, latitude = 3434.0, longitude = 4353.0, detectedPollution = false, From 172ce6509a4c061cabde7a25d21d20956f82d0d0 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 24 Dec 2024 10:55:11 +0100 Subject: [PATCH 8/9] fix(build): fix test --- .../database/model/mission/action/MissionActionModelTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/model/mission/action/MissionActionModelTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/model/mission/action/MissionActionModelTest.kt index 765ef5f8..fad5e23e 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/model/mission/action/MissionActionModelTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/model/mission/action/MissionActionModelTest.kt @@ -70,7 +70,7 @@ class MissionActionModelTest { assertThat(model.isAntiPolDeviceDeployed).isEqualTo(entity.isAntiPolDeviceDeployed) assertThat(model.isSimpleBrewingOperationDone).isEqualTo(entity.isSimpleBrewingOperationDone) assertThat(model.diversionCarriedOut).isEqualTo(entity.diversionCarriedOut) - assertThat(model.actionType).isEqualTo(entity.actionType.toString()) + assertThat(model.actionType).isEqualTo(entity.actionType) assertThat(model.latitude).isEqualTo(entity.latitude) assertThat(model.longitude).isEqualTo(entity.longitude) assertThat(model.detectedPollution).isEqualTo(entity.detectedPollution) From 7855cffa6f1eae6ebd6c567763735c4951548ab1 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 24 Dec 2024 11:11:58 +0100 Subject: [PATCH 9/9] fix(build): fix test --- .../domain/entities/mission/MissionNavActionEntityTest.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/MissionNavActionEntityTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/MissionNavActionEntityTest.kt index 93a951b5..913329d6 100644 --- a/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/MissionNavActionEntityTest.kt +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/entities/mission/MissionNavActionEntityTest.kt @@ -3,7 +3,6 @@ package fr.gouv.gmampa.rapportnav.domain.entities.mission import fr.gouv.dgampa.rapportnav.domain.entities.mission.CompletenessForStatsStatusEnum import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum -import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.status.ActionStatusType import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.action.v2.MissionActionModel import fr.gouv.gmampa.rapportnav.mocks.mission.action.ControlMock @@ -30,7 +29,7 @@ class MissionNavActionEntityTest { assertThat(entity.isAntiPolDeviceDeployed).isEqualTo(model.isAntiPolDeviceDeployed) assertThat(entity.isSimpleBrewingOperationDone).isEqualTo(model.isSimpleBrewingOperationDone) assertThat(entity.diversionCarriedOut).isEqualTo(model.diversionCarriedOut) - assertThat(entity.actionType.toString()).isEqualTo(model.actionType) + assertThat(entity.actionType).isEqualTo(model.actionType) assertThat(entity.latitude).isEqualTo(model.latitude) assertThat(entity.longitude).isEqualTo(model.longitude) assertThat(entity.detectedPollution).isEqualTo(model.detectedPollution)