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 58b01535e..a30f480c8 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 325c14dc4..6e28cf4db 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 9ae67692f..5d026243f 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 4a62ff7ba..ba4cdb79a 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 37405bdc7..b22a28d0b 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 7b8aa35a8..ea4ac7e17 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,11 @@ data class ActionControlEntity( var controlSecurity: ControlSecurityEntity? = null, var controlNavigation: ControlNavigationEntity? = null ) { + + 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 } + controlAdministrative?.infractions = infractions?.filter { it.controlId == controlAdministrative?.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 a8459931f..d2ea09c83 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 f0e7c9862..92b49231a 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/BaseMissionFishAction.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/BaseMissionFishAction.kt index 6c4059b6a..3a7d5baae 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 e659e9986..8eead379f 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/entities/mission/v2/MissionNavActionEntity.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/v2/MissionNavActionEntity.kt index baecb11d7..6d3ee659f 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/GetEnvActionById.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/GetEnvActionById.kt index 8f745bfef..b82c6a223 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 000000000..7cbe18aef --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateEnvAction.kt @@ -0,0 +1,64 @@ +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.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 +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 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( + actionId = input.id, + missionId = action.missionId, + startDateTimeUtc = action.startDateTimeUtc, + endDateTimeUtc = action.endDateTimeUtc, + observationsByUnit = action.observationsByUnit + ) + ) + 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.toActionControlEntity()) + 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 000000000..ea86c1e66 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateFishAction.kt @@ -0,0 +1,50 @@ +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) + val controlInputs = input.fish?.getControls(actionId = input.id, missionId = input.missionId) + 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( + 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) + 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 000000000..856e5d435 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/action/v2/UpdateNavAction.kt @@ -0,0 +1,42 @@ +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) + val controlInputs = input.nav?.getControls(actionId = input.id, missionId = input.missionId) + return try { + missionActionRepository.save(action) + 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) + 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 000000000..9994c18dc --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/control/v2/ProcessMissionActionControl.kt @@ -0,0 +1,102 @@ +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.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 fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.* + +@UseCase +class ProcessMissionActionControl( + private val controlSecurityRepo: IControlSecurityRepository, + private val controlNavigationRepo: IControlNavigationRepository, + private val controlGensDeMerRepo: IControlGensDeMerRepository, + private val controlAdministrativeRepo: IControlAdministrativeRepository +) { + + 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(actionId = actionId, control = controls?.controlAdministrative) + + return ActionControlInput( + controlSecurity = controlSecurity, + controlGensDeMer = controlGensDeMer, + controlNavigation = controlNavigation, + controlAdministrative = controlAdministrative + ) + } + + private inline fun processControl( + actionId: String, + control: M?, + findControlByActionId: (String) -> T?, + saveControl: (T) -> T + ): T? { + if (control?.id != null) { + val existingControl = findControlByActionId(actionId) + if (control.toEntity().equals(existingControl)) return existingControl + } + if (control == null) return null + System.out.println("[processMissionAction] SAVE: $actionId") + return saveControl(control.toEntity() as T) + } + + + private fun processControlSecurity(actionId: String, control: ControlSecurityInput2?): ControlSecurityInput2? { + val response = processControl( + actionId = actionId, + control = control, + saveControl = { controlSecurityRepo.save(it).toControlSecurityEntity() }, + findControlByActionId = { controlSecurityRepo.findByActionControlId(it).toControlSecurityEntity() }, + ) + if (response?.id != null) control?.id = response.id + return control + } + + private fun processControlGensDeMer(actionId: String, control: ControlGensDeMerInput2?): ControlGensDeMerInput2? { + val response = processControl( + actionId = actionId, + control = control, + saveControl = { controlGensDeMerRepo.save(it).toControlGensDeMerEntity() }, + findControlByActionId = { controlGensDeMerRepo.findByActionControlId(it).toControlGensDeMerEntity() }, + ) + if (response?.id != null) control?.id = response.id + return control + } + + private fun processControlNavigation( + actionId: String, + control: ControlNavigationInput2? + ): ControlNavigationInput2? { + val response = processControl( + actionId = actionId, + control = control, + saveControl = { controlNavigationRepo.save(it).toControlNavigationEntity() }, + findControlByActionId = { controlNavigationRepo.findByActionControlId(it).toControlNavigationEntity() }, + ) + if (response?.id != null) control?.id = response.id + return control + } + + private fun processControlAdministrative( + actionId: String, + control: ControlAdministrativeInput2? + ): ControlAdministrativeInput2? { + val response = processControl( + actionId = actionId, + control = control, + saveControl = { controlAdministrativeRepo.save(it).toControlAdministrativeEntity() }, + findControlByActionId = { + controlAdministrativeRepo.findByActionControlId(it).toControlAdministrativeEntity() + }, + ) + 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 000000000..f95901316 --- /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 new file mode 100644 index 000000000..c91d9c37b --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfraction.kt @@ -0,0 +1,36 @@ +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.repositories.mission.infraction.IInfractionRepository +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.InfractionInput2 + +@UseCase +class ProcessMissionActionInfraction( + private val infractionRepo: IInfractionRepository +) { + + fun execute(actionId: String, infractions: List): List? { + val infractionIds = infractions.map { it.id } + + val databaseInfractions = infractionRepo + .findAllByActionId(actionId) + .map { it.toInfractionEntity() } + .filter { it.controlId != null } + + val toDeleteInfractions = databaseInfractions.filter { !infractionIds.contains(it.id.toString()) } + val toSaveInfractions = infractions.map { it.toInfractionEntity() }.filter { !databaseInfractions.contains(it) } + + delete(toDeleteInfractions) + return save(toSaveInfractions) + } + + 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 000000000..d17174a0f --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/infraction/v2/ProcessMissionActionInfractionEnvTarget.kt @@ -0,0 +1,44 @@ +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.repositories.mission.infraction.IInfractionEnvTargetRepository +import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionRepository +import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.InfractionInput2 + +@UseCase +class ProcessMissionActionInfractionEnvTarget( + private val infractionRepo: IInfractionRepository, + private val infractionEnvTargetRepo: IInfractionEnvTargetRepository, +) { + + fun execute(actionId: String, infractions: List?): List? { + 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 newTarget = it.toInfractionEnvTargetEntity() + val entity = it.toInfractionEntity() + entity.target = newTarget + infractionRepo.save(entity).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/ActionControlInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ActionControlInput.kt new file mode 100644 index 000000000..baea785b8 --- /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 000000000..7484a64de --- /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/BaseMissionNavActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/BaseMissionNavActionDataInput.kt new file mode 100644 index 000000000..f0239a054 --- /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/ControlAdministrativeInput2.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlAdministrativeInput2.kt new file mode 100644 index 000000000..ad02ea338 --- /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? = null, + val upToDateNavigationPermit: ControlResult? = null, + val compliantSecurityDocuments: ControlResult? = null, +) : 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 000000000..bdc9cd893 --- /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 000000000..4468f10be --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/ControlNavigationInput2.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.ControlNavigationEntity +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 000000000..a6135ced8 --- /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 000000000..e3d78d088 --- /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 000000000..b5b021125 --- /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 000000000..6a673177d --- /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 new file mode 100644 index 000000000..f158edccd --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionDataInput.kt @@ -0,0 +1,31 @@ +package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2 + +import java.time.Instant + +open class MissionActionDataInput( + open val startDateTimeUtc: Instant, + open val endDateTimeUtc: Instant? = null, + open val observations: String? = 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/MissionActionInput.kt b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionActionInput.kt new file mode 100644 index 000000000..73e5189d2 --- /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 000000000..e12c2634f --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionEnvActionDataInput.kt @@ -0,0 +1,49 @@ +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.v2.MissionEnvActionEntity +import java.time.Instant +import java.util.* + +class MissionEnvActionDataInput( + override val startDateTimeUtc: Instant, + override val endDateTimeUtc: Instant? = null, + override val observations: String? = 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, + controlSecurity = controlSecurity, + controlGensDeMer = controlGensDeMer, + 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 + val action = MissionEnvActionEntity( + id = UUID.fromString(input.id), + missionId = input.missionId, + endDateTimeUtc = data?.endDateTimeUtc, + startDateTimeUtc = data?.startDateTimeUtc, + observationsByUnit = data?.observations, + envActionType = ActionTypeEnum.valueOf(input.actionType.toString()) + ) + 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 000000000..42396d69a --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionFishActionDataInput.kt @@ -0,0 +1,40 @@ +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.v2.MissionFishActionEntity +import java.time.Instant + +class MissionFishActionDataInput( + override val startDateTimeUtc: Instant, + override val endDateTimeUtc: Instant? = null, + override val observations: String? = 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, + controlSecurity = controlSecurity, + controlGensDeMer = controlGensDeMer, + controlNavigation = controlNavigation, + controlAdministrative = controlAdministrative +){ + + companion object { + fun toMissionFishActionEntity(input: MissionActionInput): MissionFishActionEntity { + 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 + ) + 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 000000000..ac9e2cf1a --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/dgampa/rapportnav/infrastructure/api/bff/adapters/v2/MissionNavActionDataInput.kt @@ -0,0 +1,102 @@ +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 observations: String? = null, + override val status: ActionStatusType? = 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, + observations = observations, + controlSecurity = controlSecurity, + controlGensDeMer = controlGensDeMer, + controlNavigation = controlNavigation, + controlAdministrative = controlAdministrative +), BaseMissionNavActionDataInput { + companion object { + fun toMissionNavActionEntity(input: MissionActionInput): MissionNavActionEntity { + 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 + ) + 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 ed89f01c3..14075170f 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 04e2b1750..55f4497b7 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 6ab153738..4d56d227e 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 c927cc63e..d53e0d768 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 59% 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 9bf904a2d..955517e62 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 @@ -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,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) @@ -43,4 +53,33 @@ class MissionActionController( 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}") + } + this.logger.info(action.id) + return MissionActionOutput.fromMissionActionEntity(response) + } + + private fun updateNavAction(action: MissionActionInput): MissionActionEntity? { + return updateNavAction.execute(action) + } + + private fun updateEnvAction(action: MissionActionInput): MissionActionEntity? { + return updateEnvAction.execute(action) + } + + private fun updateFishAction(action: MissionActionInput): MissionActionEntity? { + 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 36a7af346..073099616 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/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 e194a2a20..3156abaf8 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 000000000..6bd52ff34 --- /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 000000000..bde8dc966 --- /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 95e5748e2..4f1e68232 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 @@ -172,3 +172,76 @@ extend type Query { extend type Query { action(actionId: ID!, missionId: ID!): MissionActionOutput } + +input MissionEnvActionDataInput { + startDateTimeUtc: Instant + endDateTimeUtc: Instant + observations: String + infractions:[InfractionByTargetInput2] + controlSecurity: ControlSecurityInput2 + controlGensDeMer: ControlGensDeMerInput2 + controlNavigation: ControlNavigationInput2 + controlAdministrative: ControlAdministrativeInput2 +} + +input MissionFishActionDataInput { + startDateTimeUtc: Instant + endDateTimeUtc: Instant + observations: String + controlSecurity: ControlSecurityInput2 + controlGensDeMer: ControlGensDeMerInput2 + controlNavigation: ControlNavigationInput2 + controlAdministrative: ControlAdministrativeInput2 +} + +input MissionNavActionDataInput { + observations: String + startDateTimeUtc: Instant + endDateTimeUtc: Instant + controlSecurity: ControlSecurityInput2 + controlGensDeMer: ControlGensDeMerInput2 + controlNavigation: ControlNavigationInput2 + controlAdministrative: ControlAdministrativeInput2 + 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 +} 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 93a951b51..913329d69 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) 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 8c07b8420..1fab9e95b 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 2789c13e9..949778056 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 718f493d3..c335c504a 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 2a006efce..0fe4c9168 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 c74322c13..0340190d2 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/GetNavActionByIdTest.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/GetNavActionByIdTest.kt index 73af9d151..7cf4f05f7 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 cc5ce0815..a85605821 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 new file mode 100644 index 000000000..2732eb146 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionControlTest.kt @@ -0,0 +1,105 @@ +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.ControlInputMock +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 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 + + 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(controlSecurityModel) + `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 + ) + + input.controlGensDeMer = null + val actionControl = processMissionActionControl.execute(actionId = action.id.toString(), controls = input) + + assertThat(actionControl).isNotNull + assertThat(actionControl.controlGensDeMer).isNull() + assertThat(actionControl.controlSecurity).isEqualTo(input.controlSecurity) + assertThat(actionControl.controlNavigation).isEqualTo(input.controlNavigation) + assertThat(actionControl.controlAdministrative).isEqualTo(input.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 000000000..658118b2a --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionEnvTargetTest .kt @@ -0,0 +1,166 @@ +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.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 +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()) + + //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(), infractions) + 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[0].id) + } + + + private fun getInfractions(actionId: String): List { + return listOf( + InfractionInput2( + id = UUID.randomUUID().toString(), + actionId = actionId, + missionId = 145, + controlId = UUID.randomUUID().toString(), + infractionType = InfractionTypeEnum.WITH_REPORT, + target = InfractionTargetInput2( + id = UUID.randomUUID().toString(), + identityControlledPerson = "identityPerson1" + ) + ), + InfractionInput2( + id = UUID.randomUUID().toString(), + actionId = actionId, + controlId = UUID.randomUUID().toString(), + missionId = 145, + controlType = ControlType.SECURITY.toString(), + infractionType = InfractionTypeEnum.WITH_REPORT, + target = InfractionTargetInput2( + id = UUID.randomUUID().toString(), + vesselIdentifier = "firstVesselIdentifier", + identityControlledPerson = "identityPerson2" + ) + ), + InfractionInput2( + id = UUID.randomUUID().toString(), + actionId = actionId, + missionId = 145, + controlId = UUID.randomUUID().toString(), + controlType = ControlType.ADMINISTRATIVE.toString(), + infractionType = InfractionTypeEnum.WITH_REPORT, + target = InfractionTargetInput2( + id = UUID.randomUUID().toString(), + identityControlledPerson = "identityPerson3" + ) + ), + InfractionInput2( + id = UUID.randomUUID().toString(), + actionId = actionId, + missionId = 145, + controlId = UUID.randomUUID().toString(), + controlType = ControlType.GENS_DE_MER.toString(), + infractionType = InfractionTypeEnum.WITH_REPORT, + target = InfractionTargetInput2( + id = UUID.randomUUID().toString(), + vesselIdentifier = "firstVesselIdentifier", + identityControlledPerson = "identityPerson4", + ) + ), + InfractionInput2( + id = UUID.randomUUID().toString(), + actionId = actionId, + missionId = 145, + controlId = UUID.randomUUID().toString(), + controlType = ControlType.NAVIGATION.toString(), + infractionType = InfractionTypeEnum.WITH_REPORT, + target = InfractionTargetInput2( + id = UUID.randomUUID().toString(), + vesselIdentifier = "secondVesselIdentifier", + identityControlledPerson = "identityPerson5", + ) + ), + InfractionInput2( + id = UUID.randomUUID().toString(), + actionId = actionId, + missionId = 145, + controlId = UUID.randomUUID().toString(), + controlType = ControlType.SECURITY.toString(), + infractionType = InfractionTypeEnum.WITH_REPORT, + 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 new file mode 100644 index 000000000..b43f219af --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/ProcessMissionActionInfractionTest.kt @@ -0,0 +1,150 @@ +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.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.ControlInputMock +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, + missionId = 761, + actionId = actionId.toString() + ) + + //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.getAllInfractions()) + verify(processMissionActionInfraction).save(saveCaptor.capture()) + verify(processMissionActionInfraction).delete(deleteCaptor.capture()) + + + //Then + assertThat(infractions).isNotNull + assertThat(5).isEqualTo(saveCaptor.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, + missionId = 761 + ) + return infractionToDelete + } + + private fun getInfractionSecurityEntity(actionId: UUID): InfractionInput2 { + val securityInfraction = + InfractionInput2( + actionId = actionId.toString(), + controlType = ControlType.SECURITY.toString(), + missionId = 761 + ) + return securityInfraction + } + + private fun getInfractionSecurityModel( + securityInfraction: InfractionInput2, + actionControl: ActionControlInput + ): InfractionModel { + val securityInfractionModel = InfractionModel.fromInfractionEntity(securityInfraction.toInfractionEntity()) + securityInfractionModel.control = + ControlSecurityModel.fromControlSecurityEntity(actionControl.controlSecurity!!.toEntity()) + return securityInfractionModel + } + + private fun getInfractionNavigationModel( + infractionToDelete: InfractionEntity, + actionControl: ActionControlInput + ): InfractionModel { + val infractionToDeleteModel = InfractionModel.fromInfractionEntity(infractionToDelete) + infractionToDeleteModel.control = + ControlNavigationModel.fromControlNavigationEntity(actionControl.controlNavigation!!.toEntity()) + return infractionToDeleteModel + } + + private fun getActionControlEntity( + actionId: UUID, + 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( + InfractionInput2( + actionId = actionId.toString(), + controlType = ControlType.GENS_DE_MER.toString(), + controlId = controlId.toString(), + missionId = 761 + ), + InfractionInput2( + actionId = actionId.toString(), + controlType = ControlType.GENS_DE_MER.toString(), + controlId = controlId.toString(), + missionId = 761 + ) + ) + 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 000000000..42a9961df --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateEnvActionTest.kt @@ -0,0 +1,72 @@ +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.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 +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 lateinit var processMissionActionControlEnvTarget : ProcessMissionActionControlEnvTarget + + @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(), anyOrNull())).thenReturn(ActionControlInput()) + `when`(processMissionActionInfractionEnvTarget.execute(actionId, listOf())).thenReturn(listOf()) + + val updateNavAction = UpdateEnvAction( + patchEnvAction = patchEnvAction, + processMissionActionControl = processMissionActionControl, + processMissionActionControlEnvTarget = processMissionActionControlEnvTarget, + processMissionActionInfractionEnvTarget = processMissionActionInfractionEnvTarget + ) + + val response = updateNavAction.execute(input) + assertThat(response).isNotNull + + } + + private fun missionEnvActionDataInput() = MissionEnvActionDataInput( + 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 new file mode 100644 index 000000000..3ce1c47f9 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/domain/use_cases/mission/action/UpdateFishActionTest.kt @@ -0,0 +1,67 @@ +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.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 +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(), anyOrNull())).thenReturn(ActionControlInput()) + `when`(processMissionActionInfraction.execute(actionId, listOf())).thenReturn(listOf()) + + val updateNavAction = UpdateFishAction( + patchFishAction = patchFishAction, + processMissionActionControl = processMissionActionControl, + processMissionActionInfraction = processMissionActionInfraction + ) + + val response = updateNavAction.execute(input) + assertThat(response).isNotNull + + } + + private fun missionFishActionDataInput() = MissionFishActionDataInput( + observations = "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 000000000..4b0af2fa8 --- /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.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 +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(), anyOrNull())).thenReturn(ActionControlInput()) + `when`(processMissionActionInfraction.execute(actionId, listOf())).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 4f3cb67b4..24aab84e7 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/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 000000000..1f8b16370 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/bff/adapters/v2/ActionControlInputTest.kt @@ -0,0 +1,39 @@ +package fr.gouv.gmampa.rapportnav.infrastructure.bff.adapters.v2 + +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 +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() + action.controlSecurity?.setMissionIdAndActionId(missionId = 761, actionId = "my action id") + 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 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/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 000000000..febb706c2 --- /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 000000000..6aba9e6e8 --- /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 000000000..ca30c31ab --- /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 000000000..50f760987 --- /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 000000000..cc617f546 --- /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) + } +} 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 765ef5f83..fad5e23e5 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) 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 cf2fea89f..0ba7955f6 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 000000000..f721319e8 --- /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/ControlMock.kt b/backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/mocks/mission/action/ControlMock.kt index 700d8c7ac..a7306a576 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)) ) ) 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 0e4ced28f..382314ee9 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,