From ee65ed63507f015dfc657558440d4235b68d0835 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Tue, 26 Mar 2024 14:52:45 +0100 Subject: [PATCH 1/7] Add compare of cacem actions --- .../components/MissionForm/formikUsecases.ts | 12 +++++++++- .../hooks/useGetMainFormFormikUsecases.ts | 12 ++++++---- .../useGetMissionActionFormikUsecases.ts | 12 ++++++---- .../Mission/useCases/deleteMissionAction.ts | 24 +++++++++++++++---- 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts b/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts index 6514a21d65..ac9d46341e 100644 --- a/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts +++ b/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts @@ -1,6 +1,7 @@ import { faoAreasApi } from '@api/faoAreas' import { getSummedSpeciesOnBoard } from '@features/Logbook/utils' import { missionFormActions } from '@features/Mission/components/MissionForm/slice' +import { EnvMissionAction } from '@features/Mission/envMissionAction.types' import { MissionAction } from '@features/Mission/missionAction.types' import { getLastControlCircleGeometry } from '@features/Mission/useCases/getLastControlCircleGeometry' import { vesselApi } from '@features/Vessel/apis' @@ -143,7 +144,7 @@ const updateSpeciesOnboard = } const updateMissionLocation = - (dispatch, ports: Port.Port[] | undefined) => + (dispatch, ports: Port.Port[] | undefined, envActions: EnvMissionAction.MissionAction[]) => async ( isGeometryComputedFromControls: boolean | undefined, missionAction: MissionActionFormValues | MissionAction.MissionAction | undefined @@ -152,6 +153,15 @@ const updateMissionLocation = return } + const lastEnvActionDate = envActions + .map(action => action.actionStartDateTimeUtc) + .sort((a, b) => a.localeCompare(b))[0] + + if (lastEnvActionDate && lastEnvActionDate > missionAction.actionDatetimeUtc) { + // As a action from Env is newer, we do not update the mission location + return + } + const nextMissionGeometry = await dispatch(getLastControlCircleGeometry(ports, missionAction)) if (!nextMissionGeometry) { return diff --git a/frontend/src/features/Mission/components/MissionForm/hooks/useGetMainFormFormikUsecases.ts b/frontend/src/features/Mission/components/MissionForm/hooks/useGetMainFormFormikUsecases.ts index be02c059e6..b84cb835f3 100644 --- a/frontend/src/features/Mission/components/MissionForm/hooks/useGetMainFormFormikUsecases.ts +++ b/frontend/src/features/Mission/components/MissionForm/hooks/useGetMainFormFormikUsecases.ts @@ -1,7 +1,9 @@ import { useGetPortsQuery } from '@api/port' +import { useGetMissionQuery } from '@features/Mission/monitorenvMissionApi' import { isAirOrSeaControl, isLandControl } from '@features/Mission/useCases/getLastControlCircleGeometry' import { useMainAppDispatch } from '@hooks/useMainAppDispatch' import { useMainAppSelector } from '@hooks/useMainAppSelector' +import { skipToken } from '@reduxjs/toolkit/query' import { sortBy } from 'lodash' import { formikUsecase } from '../formikUsecases' @@ -13,6 +15,7 @@ export function useGetMainFormFormikUsecases() { const draft = useMainAppSelector(state => state.missionForm.draft) const getPortsApiQuery = useGetPortsQuery() + const getMissionApiQuery = useGetMissionQuery(draft?.mainFormValues?.id ?? skipToken) return { /** @@ -50,10 +53,11 @@ export function useGetMainFormFormikUsecases() { return false } - await formikUsecase.updateMissionLocation(dispatch, getPortsApiQuery.data)( - isGeometryComputedFromControls, - lastControl - ) + await formikUsecase.updateMissionLocation( + dispatch, + getPortsApiQuery.data, + getMissionApiQuery.data?.envActions ?? [] + )(isGeometryComputedFromControls, lastControl) return true } diff --git a/frontend/src/features/Mission/components/MissionForm/hooks/useGetMissionActionFormikUsecases.ts b/frontend/src/features/Mission/components/MissionForm/hooks/useGetMissionActionFormikUsecases.ts index f61812bcce..730b5a12f7 100644 --- a/frontend/src/features/Mission/components/MissionForm/hooks/useGetMissionActionFormikUsecases.ts +++ b/frontend/src/features/Mission/components/MissionForm/hooks/useGetMissionActionFormikUsecases.ts @@ -1,8 +1,10 @@ import { useGetPortsQuery } from '@api/port' import { useGetFleetSegmentsQuery } from '@features/FleetSegment/apis' import { MissionAction } from '@features/Mission/missionAction.types' +import { useGetMissionQuery } from '@features/Mission/monitorenvMissionApi' import { useMainAppDispatch } from '@hooks/useMainAppDispatch' import { useMainAppSelector } from '@hooks/useMainAppSelector' +import { skipToken } from '@reduxjs/toolkit/query' import { useFormikContext } from 'formik' import { useMemo } from 'react' @@ -22,6 +24,7 @@ export function useGetMissionActionFormikUsecases() { const getFleetSegmentsApiQuery = useGetFleetSegmentsQuery() const getPortsApiQuery = useGetPortsQuery() + const getMissionApiQuery = useGetMissionQuery(draft?.mainFormValues?.id ?? skipToken) const fleetSegmentsAsOptions: Option[] = useMemo( () => getFleetSegmentsAsOption(getFleetSegmentsApiQuery.data), @@ -89,10 +92,11 @@ export function useGetMissionActionFormikUsecases() { * The mission location is equal to the current action geometry modified. */ const updateMissionLocation = (missionActionValues: MissionActionFormValues) => - formikUsecase.updateMissionLocation(dispatch, getPortsApiQuery.data)( - draft?.mainFormValues.isGeometryComputedFromControls, - missionActionValues - ) + formikUsecase.updateMissionLocation( + dispatch, + getPortsApiQuery.data, + getMissionApiQuery.data?.envActions ?? [] + )(draft?.mainFormValues.isGeometryComputedFromControls, missionActionValues) /** * When updating the mission location from an action, we use the `RTK-Query` cache object to access the `mission` form. diff --git a/frontend/src/features/Mission/useCases/deleteMissionAction.ts b/frontend/src/features/Mission/useCases/deleteMissionAction.ts index c16b13cd86..2850b034f3 100644 --- a/frontend/src/features/Mission/useCases/deleteMissionAction.ts +++ b/frontend/src/features/Mission/useCases/deleteMissionAction.ts @@ -2,6 +2,7 @@ import { missionActionApi } from '@api/missionAction' import { portApi } from '@api/port' import { formikUsecase } from '@features/Mission/components/MissionForm/formikUsecases' import { missionFormActions } from '@features/Mission/components/MissionForm/slice' +import { monitorenvMissionApi } from '@features/Mission/monitorenvMissionApi' import { MissionAction } from '../missionAction.types' @@ -15,7 +16,7 @@ export const deleteMissionAction = isAutoSaveEnabled: boolean, isGeometryComputedFromControls: boolean ): MainAppThunk> => - async dispatch => { + async (dispatch, getState) => { const deletedAction = actionsFormValues.find((_, index) => index === actionIndex) const nextActionsFormValues = actionsFormValues.filter((_, index) => index !== actionIndex) @@ -47,12 +48,25 @@ export const deleteMissionAction = await formikUsecase.initMissionLocation(dispatch)(isGeometryComputedFromControls) } else { const { data: ports } = await dispatch(portApi.endpoints.getPorts.initiate()) + const missionId = getState().missionForm.draft?.mainFormValues?.id + const envActions = await getEnvActions(dispatch, missionId) - await formikUsecase.updateMissionLocation(dispatch, ports)( - isGeometryComputedFromControls, - nextControlActionsWithGeometry[0] - ) + await formikUsecase.updateMissionLocation( + dispatch, + ports, + envActions + )(isGeometryComputedFromControls, nextControlActionsWithGeometry[0]) } return nextActionsFormValues } + +async function getEnvActions(dispatch, missionId: number | undefined) { + if (!missionId) { + return [] + } + + const { data: mission } = await dispatch(monitorenvMissionApi.endpoints.getMission.initiate(missionId)) + + return mission?.envActions ?? [] +} From bc89757d25665194cfd6fd69f609b83d5ee10d0d Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Tue, 26 Mar 2024 16:41:53 +0100 Subject: [PATCH 2/7] Add a proxy of mission API in monitorfish backend --- .../domain/entities/alerts/PendingAlert.kt | 4 +- .../domain/entities/mission/Mission.kt | 4 + .../entities/mission/MissionAndActions.kt | 2 +- .../env_mission_action/EnvMissionAction.kt | 10 ++ .../env_mission_action/MissionActionType.kt | 7 + .../mission_actions/ControlCheck.kt | 2 +- .../mission_actions/ControlOrigin.kt | 2 +- .../mission_actions/Controller.kt | 2 +- .../mission_actions/ControlsSummary.kt | 2 +- .../mission_actions/FleetSegment.kt | 2 +- .../mission_actions/FlightGoal.kt | 2 +- .../mission_actions/GearControl.kt | 2 +- .../mission_actions/GearInfraction.kt | 2 +- .../mission_actions/Infraction.kt | 2 +- .../mission_actions/InfractionCategory.kt | 2 +- .../mission_actions/InfractionType.kt | 2 +- .../mission_actions/LogbookInfraction.kt | 2 +- .../mission_actions/MissionAction.kt | 2 +- .../mission_actions/MissionActionType.kt | 2 +- .../mission_actions/OtherInfraction.kt | 2 +- .../mission_actions/SpeciesControl.kt | 2 +- .../mission_actions/SpeciesInfraction.kt | 2 +- .../mission_actions/actrep/ActivityCode.kt | 6 + .../actrep/JointDeploymentPlan.kt | 2 +- .../mission_actions/actrep/species.kt | 2 +- .../mission_actions/actrep/ActivityCode.kt | 6 - .../domain/entities/reporting/Reporting.kt | 4 +- .../repositories/InfractionRepository.kt | 2 +- .../repositories/MissionActionsRepository.kt | 2 +- .../domain/repositories/MissionRepository.kt | 4 + .../use_cases/infraction/GetAllInfractions.kt | 4 +- .../{missions => mission}/GetAllMissions.kt | 2 +- .../domain/use_cases/mission/GetMission.kt | 31 ++++ .../mission_actions/AddMissionAction.kt | 4 +- .../mission_actions/DeleteMissionAction.kt | 2 +- .../mission_actions/GetActivityReports.kt | 12 +- .../mission_actions/GetMissionAction.kt | 4 +- .../mission_actions/GetMissionActionFacade.kt | 6 +- .../mission_actions/GetMissionActions.kt | 4 +- .../mission_actions/GetVesselControls.kt | 6 +- .../mission_actions/UpdateMissionAction.kt | 4 +- .../mission_actions/dtos/ActivityReport.kt | 6 +- .../mission_actions/dtos/ActivityReports.kt | 2 +- .../api/ControllersExceptionHandler.kt | 23 +-- .../api/bff/MissionActionsController.kt | 3 +- .../api/bff/MissionController.kt | 22 ++- .../api/input/AddMissionActionDataInput.kt | 26 ++-- .../api/outputs/ActivityReportDataOutput.kt | 4 +- .../api/outputs/ActivityReportsDataOutput.kt | 2 +- .../api/outputs/ControlsSummaryDataOutput.kt | 2 +- .../FullMissionWithActionsDataOutput.kt | 57 +++++++ .../api/outputs/GearControlDataOutput.kt | 2 +- .../api/outputs/InfractionDataOutput.kt | 2 +- .../api/outputs/MissionActionDataOutput.kt | 2 +- .../PublicMissionActionsController.kt | 2 +- .../database/entities/InfractionEntity.kt | 8 +- .../database/entities/MissionActionEntity.kt | 146 ++++++++++-------- .../repositories/JpaInfractionRepository.kt | 6 +- .../JpaMissionActionsRepository.kt | 16 +- .../interfaces/DBMissionActionsRepository.kt | 2 +- .../monitorenv/APIMissionRepository.kt | 16 ++ .../input/EnvMissionActionDataResponse.kt | 38 +++++ .../monitorenv/input/MissionDataResponse.kt | 13 ++ .../mission_actions/MissionActionUTests.kt | 2 +- .../actrep/JointDeploymentPlanUTests.kt | 2 +- .../use_cases/GetPendingAlertsUTests.kt | 9 +- .../use_cases/GetVesselReportingsUTests.kt | 14 +- .../GetAllMissionsUTests.kt | 7 +- .../use_cases/mission/GetMissionUTests.kt | 92 +++++++++++ .../{mission_actions => mission}/TestUtils.kt | 25 ++- .../mission_actions/AddMissionActionUTests.kt | 6 +- .../DeleteMissionActionUTests.kt | 6 +- .../GetActivityReportsUTests.kt | 12 +- .../GetMissionActionFacadeUTests.kt | 6 +- .../GetVesselControlsUTests.kt | 10 +- .../UpdateMissionActionUTests.kt | 6 +- .../domain/use_cases/missions/TestUtils.kt | 24 --- .../api/bff/MissionsControllerITests.kt | 6 +- .../PublicMissionActionsControllerITests.kt | 45 +++--- .../api/bff/VesselControllerITests.kt | 8 +- .../public_api/InfractionControllerITests.kt | 14 +- .../PublicMissionActionsControllerITests.kt | 8 +- .../JpaInfractionRepositoryITests.kt | 10 +- .../JpaMissionActionRepositoryITests.kt | 56 ++++--- .../database/repositories/TestUtils.kt | 103 ++++++------ .../monitorenv/APIMissionRepositoryITest.kt | 32 ++++ .../infrastructure/monitorenv/TestUtils.kt | 57 ++++++- .../mission_form/main_form.spec.ts | 6 +- frontend/src/domain/entities/mission/index.ts | 6 +- .../MissionForm/ActionList/index.tsx | 2 +- .../hooks/useGetMainFormFormikUsecases.ts | 2 +- .../useGetMissionActionFormikUsecases.ts | 2 +- .../utils/getMissionFormInitialValues.ts | 4 +- .../components/MissionList/constants.ts | 3 +- .../hooks/useGetFilteredMissionsQuery.ts | 11 +- .../Mission/components/MissionList/index.tsx | 4 +- .../Mission/components/MissionList/utils.tsx | 4 +- .../src/features/Mission/mission.types.ts | 6 +- .../features/Mission/monitorenvMissionApi.ts | 8 - .../features/Mission/monitorfishMissionApi.ts | 15 +- .../Mission/useCases/deleteMissionAction.ts | 4 +- .../features/Mission/useCases/editMission.ts | 7 +- .../Mission/useCases/getMissionWithActions.ts | 25 --- .../saveMissionAndMissionActionsByDiff.ts | 7 +- 104 files changed, 835 insertions(+), 409 deletions(-) create mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt create mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/MissionActionType.kt rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/ControlCheck.kt (61%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/ControlOrigin.kt (71%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/Controller.kt (68%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/ControlsSummary.kt (75%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/FleetSegment.kt (57%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/FlightGoal.kt (69%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/GearControl.kt (79%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/GearInfraction.kt (65%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/Infraction.kt (71%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/InfractionCategory.kt (60%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/InfractionType.kt (66%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/LogbookInfraction.kt (66%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/MissionAction.kt (98%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/MissionActionType.kt (75%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/OtherInfraction.kt (64%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/SpeciesControl.kt (74%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/SpeciesInfraction.kt (65%) create mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/ActivityCode.kt rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/actrep/JointDeploymentPlan.kt (95%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/actrep/species.kt (98%) delete mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/ActivityCode.kt rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{missions => mission}/GetAllMissions.kt (97%) create mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMission.kt rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/AddMissionAction.kt (83%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/DeleteMissionAction.kt (91%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/GetActivityReports.kt (89%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/GetMissionAction.kt (79%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/GetMissionActionFacade.kt (86%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/GetMissionActions.kt (81%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/GetVesselControls.kt (92%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/UpdateMissionAction.kt (84%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/dtos/ActivityReport.kt (61%) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/dtos/ActivityReports.kt (65%) create mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/FullMissionWithActionsDataOutput.kt create mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt rename backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/MissionActionUTests.kt (98%) rename backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/{ => mission}/mission_actions/actrep/JointDeploymentPlanUTests.kt (97%) rename backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{missions => mission}/GetAllMissionsUTests.kt (92%) create mode 100644 backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt rename backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{mission_actions => mission}/TestUtils.kt (50%) rename backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/AddMissionActionUTests.kt (92%) rename backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/DeleteMissionActionUTests.kt (86%) rename backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/GetActivityReportsUTests.kt (96%) rename backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/GetMissionActionFacadeUTests.kt (95%) rename backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/GetVesselControlsUTests.kt (91%) rename backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/{ => mission}/mission_actions/UpdateMissionActionUTests.kt (86%) delete mode 100644 backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/missions/TestUtils.kt delete mode 100644 frontend/src/features/Mission/useCases/getMissionWithActions.ts diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/alerts/PendingAlert.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/alerts/PendingAlert.kt index e50c6dbbb7..41e79284ff 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/alerts/PendingAlert.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/alerts/PendingAlert.kt @@ -2,7 +2,7 @@ package fr.gouv.cnsp.monitorfish.domain.entities.alerts import com.neovisionaries.i18n.CountryCode import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.AlertType -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselIdentifier import java.time.ZonedDateTime @@ -18,7 +18,7 @@ class PendingAlert( val creationDate: ZonedDateTime, val tripNumber: String? = null, val value: AlertType, - var infraction: Infraction? = null, + var infraction: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction? = null, val latitude: Double? = null, val longitude: Double? = null, ) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/Mission.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/Mission.kt index 2fc9d9fc01..1cf38aca9b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/Mission.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/Mission.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.entities.mission +import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.EnvMissionAction import java.time.ZonedDateTime /** @@ -15,6 +16,9 @@ data class Mission( val observationsCnsp: String? = null, val facade: String? = null, val geom: MultiPolygon? = null, + val createdAtUtc: ZonedDateTime? = null, + val updatedAtUtc: ZonedDateTime? = null, + val envActions: List? = listOf(), val startDateTimeUtc: ZonedDateTime, val endDateTimeUtc: ZonedDateTime? = null, val isGeometryComputedFromControls: Boolean, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/MissionAndActions.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/MissionAndActions.kt index 93804e948f..bf7ff315a9 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/MissionAndActions.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/MissionAndActions.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.entities.mission -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction data class MissionAndActions( val mission: Mission, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt new file mode 100644 index 0000000000..6d44a4ee02 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt @@ -0,0 +1,10 @@ +package fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action + +import java.time.ZonedDateTime +import java.util.* + +data class EnvMissionAction( + val id: UUID, + val actionStartDateTimeUtc: ZonedDateTime, + val actionType: MissionActionType, +) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/MissionActionType.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/MissionActionType.kt new file mode 100644 index 0000000000..d4e70cd338 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/MissionActionType.kt @@ -0,0 +1,7 @@ +package fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action + +enum class MissionActionType(val value: String) { + CONTROL("CONTROL"), + NOTE("NOTE"), + SURVEILLANCE("SURVEILLANCE"), +} diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/ControlCheck.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/ControlCheck.kt similarity index 61% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/ControlCheck.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/ControlCheck.kt index e1aca5037c..881156e38f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/ControlCheck.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/ControlCheck.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions enum class ControlCheck(val value: String) { YES("YES"), diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/ControlOrigin.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/ControlOrigin.kt similarity index 71% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/ControlOrigin.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/ControlOrigin.kt index 72f7379a28..3918218ee5 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/ControlOrigin.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/ControlOrigin.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions enum class ControlOrigin(val value: String) { POSEIDON_ENV("POSEIDON_ENV"), diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/Controller.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/Controller.kt similarity index 68% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/Controller.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/Controller.kt index 284da8f55f..7e2de3eff0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/Controller.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/Controller.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions data class Controller( var id: Int, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/ControlsSummary.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/ControlsSummary.kt similarity index 75% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/ControlsSummary.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/ControlsSummary.kt index 52786b0768..341231003d 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/ControlsSummary.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/ControlsSummary.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions data class ControlsSummary( val vesselId: Int, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/FleetSegment.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/FleetSegment.kt similarity index 57% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/FleetSegment.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/FleetSegment.kt index 9d1b0ac357..d4c485a45f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/FleetSegment.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/FleetSegment.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions data class FleetSegment( var segment: String? = null, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/FlightGoal.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/FlightGoal.kt similarity index 69% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/FlightGoal.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/FlightGoal.kt index 947efcaf14..894d8ff48a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/FlightGoal.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/FlightGoal.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions enum class FlightGoal(val value: String) { VMS_AIS_CHECK("VMS_AIS_CHECK"), diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/GearControl.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/GearControl.kt similarity index 79% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/GearControl.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/GearControl.kt index dcbbaa7f57..da6ed80b47 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/GearControl.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/GearControl.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions class GearControl { var gearCode: String? = null diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/GearInfraction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/GearInfraction.kt similarity index 65% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/GearInfraction.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/GearInfraction.kt index 15583641df..3b2c279b2d 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/GearInfraction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/GearInfraction.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions data class GearInfraction( var infractionType: InfractionType? = null, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/Infraction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/Infraction.kt similarity index 71% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/Infraction.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/Infraction.kt index 5eb3056ab5..e6a914a1e1 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/Infraction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/Infraction.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions data class Infraction( var natinfCode: Int, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/InfractionCategory.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/InfractionCategory.kt similarity index 60% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/InfractionCategory.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/InfractionCategory.kt index 83fc97a6bf..5304d037ec 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/InfractionCategory.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/InfractionCategory.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions enum class InfractionCategory(val value: String) { FISHING("Pêche"), diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/InfractionType.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/InfractionType.kt similarity index 66% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/InfractionType.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/InfractionType.kt index 73232c0c73..3dd67aa1ce 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/InfractionType.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/InfractionType.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions enum class InfractionType(val value: String) { WITH_RECORD("WITH_RECORD"), diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/LogbookInfraction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/LogbookInfraction.kt similarity index 66% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/LogbookInfraction.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/LogbookInfraction.kt index 353484ed2c..eef2eed1f1 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/LogbookInfraction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/LogbookInfraction.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions data class LogbookInfraction( var infractionType: InfractionType? = null, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/MissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt similarity index 98% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/MissionAction.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt index 2af38614de..ebb1d23f8a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/MissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit import java.time.ZonedDateTime diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/MissionActionType.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionType.kt similarity index 75% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/MissionActionType.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionType.kt index 7959fce867..fb4b53fc8a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/MissionActionType.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionType.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions enum class MissionActionType(val value: String) { SEA_CONTROL("SEA_CONTROL"), diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/OtherInfraction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/OtherInfraction.kt similarity index 64% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/OtherInfraction.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/OtherInfraction.kt index 3da995d4ce..e6ab9580db 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/OtherInfraction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/OtherInfraction.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions class OtherInfraction { var infractionType: InfractionType? = null diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/SpeciesControl.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/SpeciesControl.kt similarity index 74% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/SpeciesControl.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/SpeciesControl.kt index b4e1abad1d..39eaaf735a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/SpeciesControl.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/SpeciesControl.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions class SpeciesControl { var speciesCode: String? = null diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/SpeciesInfraction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/SpeciesInfraction.kt similarity index 65% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/SpeciesInfraction.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/SpeciesInfraction.kt index b7b2a4f12d..d8bc4ba067 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/SpeciesInfraction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/SpeciesInfraction.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions class SpeciesInfraction { var infractionType: InfractionType? = null diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/ActivityCode.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/ActivityCode.kt new file mode 100644 index 0000000000..c06a09650c --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/ActivityCode.kt @@ -0,0 +1,6 @@ +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep + +enum class ActivityCode { + FIS, + LAN, +} diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/JointDeploymentPlan.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlan.kt similarity index 95% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/JointDeploymentPlan.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlan.kt index 79d96d35f3..17ce37f7dd 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/JointDeploymentPlan.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlan.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep enum class JointDeploymentPlan(private val species: List) { MEDITERRANEAN_AND_EASTERN_ATLANTIC(MEDITERRANEAN_AND_EASTERN_ATLANTIC_SPECIES), diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/species.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/species.kt similarity index 98% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/species.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/species.kt index da71f03651..67308060d8 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/species.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/species.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep typealias FaoZones = List typealias FaoZonesAndSpecy = Pair diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/ActivityCode.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/ActivityCode.kt deleted file mode 100644 index f052131ecf..0000000000 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/ActivityCode.kt +++ /dev/null @@ -1,6 +0,0 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep - -enum class ActivityCode { - FIS, - LAN, -} diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt index e220830741..b499c76abe 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt @@ -1,7 +1,7 @@ package fr.gouv.cnsp.monitorfish.domain.entities.reporting import com.neovisionaries.i18n.CountryCode -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselIdentifier import java.time.ZonedDateTime @@ -20,7 +20,7 @@ data class Reporting( val value: ReportingValue, val isArchived: Boolean, val isDeleted: Boolean, - var infraction: Infraction? = null, + var infraction: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction? = null, var underCharter: Boolean? = null, val latitude: Double? = null, val longitude: Double? = null, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/InfractionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/InfractionRepository.kt index eeed29ae43..9b0fea1009 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/InfractionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/InfractionRepository.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.repositories -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction interface InfractionRepository { fun findInfractionByNatinfCode(natinfCode: Int): Infraction diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionActionsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionActionsRepository.kt index 852b56bbdb..1d70e3fe5b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionActionsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionActionsRepository.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.repositories -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction import java.time.ZonedDateTime interface MissionActionsRepository { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionRepository.kt index 5e9600f836..9b57d17977 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionRepository.kt @@ -2,6 +2,7 @@ package fr.gouv.cnsp.monitorfish.domain.repositories import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit import fr.gouv.cnsp.monitorfish.domain.entities.mission.Mission +import fr.gouv.cnsp.monitorfish.domain.exceptions.CouldNotFindException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import java.time.ZonedDateTime @@ -21,4 +22,7 @@ interface MissionRepository { fun findByIds( ids: List, ): List + + @Throws(CouldNotFindException::class) + fun findById(id: Int): Mission } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/infraction/GetAllInfractions.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/infraction/GetAllInfractions.kt index 9b2fdc9c5b..ec417899ff 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/infraction/GetAllInfractions.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/infraction/GetAllInfractions.kt @@ -1,12 +1,12 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.infraction import fr.gouv.cnsp.monitorfish.config.UseCase -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction import fr.gouv.cnsp.monitorfish.domain.repositories.InfractionRepository @UseCase class GetAllInfractions(private val infractionRepository: InfractionRepository) { - fun execute(): List { + fun execute(): List { return infractionRepository.findAll() } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/missions/GetAllMissions.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissions.kt similarity index 97% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/missions/GetAllMissions.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissions.kt index 35fa8aa4d4..c4abfeb32c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/missions/GetAllMissions.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissions.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.missions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission import fr.gouv.cnsp.monitorfish.config.DatabaseProperties import fr.gouv.cnsp.monitorfish.config.UseCase diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMission.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMission.kt new file mode 100644 index 0000000000..feb8d82a37 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMission.kt @@ -0,0 +1,31 @@ +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission + +import fr.gouv.cnsp.monitorfish.config.UseCase +import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionAndActions +import fr.gouv.cnsp.monitorfish.domain.exceptions.CouldNotFindException +import fr.gouv.cnsp.monitorfish.domain.repositories.MissionRepository +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.GetMissionActions +import kotlinx.coroutines.async +import kotlinx.coroutines.coroutineScope + +@UseCase +class GetMission( + private val missionRepository: MissionRepository, + private val getMissionActions: GetMissionActions, +) { + @Throws(CouldNotFindException::class) + suspend fun execute(missionId: Int): MissionAndActions { + return coroutineScope { + val missionFuture = async { + missionRepository.findById(missionId) + } + + val actions = getMissionActions.execute(missionId) + + return@coroutineScope MissionAndActions( + mission = missionFuture.await(), + actions = actions, + ) + } + } +} diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/AddMissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionAction.kt similarity index 83% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/AddMissionAction.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionAction.kt index 2462493e14..3e1ba33765 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/AddMissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionAction.kt @@ -1,7 +1,7 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import fr.gouv.cnsp.monitorfish.config.UseCase -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository @UseCase diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/DeleteMissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionAction.kt similarity index 91% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/DeleteMissionAction.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionAction.kt index f1613f79b2..fd32f7a478 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/DeleteMissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionAction.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import fr.gouv.cnsp.monitorfish.config.UseCase import fr.gouv.cnsp.monitorfish.domain.exceptions.CouldNotDeleteException diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetActivityReports.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReports.kt similarity index 89% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetActivityReports.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReports.kt index 9e1a112d13..c790987587 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetActivityReports.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReports.kt @@ -1,16 +1,16 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import fr.gouv.cnsp.monitorfish.config.UseCase -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep.ActivityCode -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep.JointDeploymentPlan +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.ActivityCode +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.JointDeploymentPlan import fr.gouv.cnsp.monitorfish.domain.exceptions.CodeNotFoundException import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository import fr.gouv.cnsp.monitorfish.domain.repositories.MissionRepository import fr.gouv.cnsp.monitorfish.domain.repositories.PortRepository import fr.gouv.cnsp.monitorfish.domain.repositories.VesselRepository -import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.dtos.ActivityReport -import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.dtos.ActivityReports +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.dtos.ActivityReport +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.dtos.ActivityReports import org.slf4j.LoggerFactory import java.time.ZonedDateTime diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionAction.kt similarity index 79% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionAction.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionAction.kt index db94068fd4..f12933d8c9 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionAction.kt @@ -1,7 +1,7 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import fr.gouv.cnsp.monitorfish.config.UseCase -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction import fr.gouv.cnsp.monitorfish.domain.exceptions.CouldNotFindException import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionActionFacade.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionFacade.kt similarity index 86% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionActionFacade.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionFacade.kt index d5703e8240..b8c281c98d 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionActionFacade.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionFacade.kt @@ -1,9 +1,9 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import fr.gouv.cnsp.monitorfish.config.UseCase import fr.gouv.cnsp.monitorfish.domain.entities.facade.Facade -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType import fr.gouv.cnsp.monitorfish.domain.repositories.FacadeAreasRepository import fr.gouv.cnsp.monitorfish.domain.repositories.PortRepository import org.locationtech.jts.geom.Coordinate diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionActions.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActions.kt similarity index 81% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionActions.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActions.kt index 3343d30ff0..2e4e05d745 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionActions.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActions.kt @@ -1,7 +1,7 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import fr.gouv.cnsp.monitorfish.config.UseCase -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository import org.slf4j.LoggerFactory diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetVesselControls.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControls.kt similarity index 92% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetVesselControls.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControls.kt index 37f38aaa15..8e0397ccf4 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetVesselControls.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControls.kt @@ -1,8 +1,8 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import fr.gouv.cnsp.monitorfish.config.UseCase -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.ControlsSummary -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlsSummary +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType import fr.gouv.cnsp.monitorfish.domain.exceptions.CodeNotFoundException import fr.gouv.cnsp.monitorfish.domain.repositories.GearRepository import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/UpdateMissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionAction.kt similarity index 84% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/UpdateMissionAction.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionAction.kt index 06a5aaa49b..3aba59d0b8 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/UpdateMissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionAction.kt @@ -1,7 +1,7 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import fr.gouv.cnsp.monitorfish.config.UseCase -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository import org.slf4j.LoggerFactory diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/dtos/ActivityReport.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/dtos/ActivityReport.kt similarity index 61% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/dtos/ActivityReport.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/dtos/ActivityReport.kt index e226931d3b..42aaf98de1 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/dtos/ActivityReport.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/dtos/ActivityReport.kt @@ -1,8 +1,8 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.dtos +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.dtos import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep.ActivityCode +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.ActivityCode import fr.gouv.cnsp.monitorfish.domain.entities.vessel.Vessel data class ActivityReport( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/dtos/ActivityReports.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/dtos/ActivityReports.kt similarity index 65% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/dtos/ActivityReports.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/dtos/ActivityReports.kt index 3430556059..58453f7c07 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/dtos/ActivityReports.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/dtos/ActivityReports.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.dtos +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.dtos data class ActivityReports( val activityReports: List, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/ControllersExceptionHandler.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/ControllersExceptionHandler.kt index 7bd253225d..64fcd613c0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/ControllersExceptionHandler.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/ControllersExceptionHandler.kt @@ -1,10 +1,7 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api import fr.gouv.cnsp.monitorfish.config.SentryConfig -import fr.gouv.cnsp.monitorfish.domain.exceptions.CouldNotUpdateControlObjectiveException -import fr.gouv.cnsp.monitorfish.domain.exceptions.CouldNotUpdateFleetSegmentException -import fr.gouv.cnsp.monitorfish.domain.exceptions.NAFMessageParsingException -import fr.gouv.cnsp.monitorfish.domain.exceptions.NoLogbookFishingTripFound +import fr.gouv.cnsp.monitorfish.domain.exceptions.* import fr.gouv.cnsp.monitorfish.infrastructure.api.outputs.ApiError import fr.gouv.cnsp.monitorfish.infrastructure.api.outputs.MissingParameterApiError import io.sentry.Sentry @@ -43,19 +40,11 @@ class ControllersExceptionHandler(val sentryConfig: SentryConfig) { } @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(CouldNotUpdateControlObjectiveException::class) - fun handleCouldNotUpdateControlObjectiveException(e: Exception): ApiError { - logger.error(e.message, e.cause) - - if (sentryConfig.enabled == true) { - Sentry.captureException(e) - } - - return ApiError(CouldNotUpdateControlObjectiveException(e.message.toString(), e)) - } - - @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(IllegalArgumentException::class) + @ExceptionHandler( + IllegalArgumentException::class, + CouldNotUpdateControlObjectiveException::class, + CouldNotFindException::class, + ) fun handleIllegalArgumentException(e: Exception): ApiError { logger.error(e.message, e.cause) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt index ac651c30fc..6d34c43443 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt @@ -1,6 +1,7 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.bff -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep.JointDeploymentPlan +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.JointDeploymentPlan +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.* import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.* import fr.gouv.cnsp.monitorfish.infrastructure.api.input.AddMissionActionDataInput import fr.gouv.cnsp.monitorfish.infrastructure.api.outputs.ActivityReportsDataOutput diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionController.kt index 6196a1c403..e749bb39b3 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionController.kt @@ -1,11 +1,14 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.bff -import fr.gouv.cnsp.monitorfish.domain.use_cases.missions.GetAllMissions -import fr.gouv.cnsp.monitorfish.domain.use_cases.reporting.* +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.GetAllMissions +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.GetMission +import fr.gouv.cnsp.monitorfish.infrastructure.api.outputs.FullMissionWithActionsDataOutput import fr.gouv.cnsp.monitorfish.infrastructure.api.outputs.MissionWithActionsDataOutput import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter import io.swagger.v3.oas.annotations.tags.Tag +import jakarta.websocket.server.PathParam +import kotlinx.coroutines.runBlocking import org.springframework.format.annotation.DateTimeFormat import org.springframework.web.bind.annotation.* import java.time.ZonedDateTime @@ -15,6 +18,7 @@ import java.time.ZonedDateTime @Tag(name = "Proxy APIs for missions") class MissionController( private val getAllMissions: GetAllMissions, + private val getMission: GetMission, ) { @GetMapping("") @@ -59,4 +63,18 @@ class MissionController( ) return missionsAndActions.map { MissionWithActionsDataOutput.fromMissionAndActions(it) } } + + @GetMapping("/{id}") + @Operation(summary = "Get mission") + fun getMissionController( + @PathParam("Id") + @PathVariable(name = "id") + id: Int, + ): FullMissionWithActionsDataOutput { + return runBlocking { + val missionAndActions = getMission.execute(id) + + return@runBlocking FullMissionWithActionsDataOutput.fromMissionAndActions(missionAndActions) + } + } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt index 49f9429b37..cccdf7d490 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.input -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.* +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import java.time.ZonedDateTime data class AddMissionActionDataInput( @@ -13,19 +13,19 @@ data class AddMissionActionDataInput( var flagState: String? = null, var districtCode: String? = null, var faoAreas: List = listOf(), - var flightGoals: List = listOf(), + var flightGoals: List = listOf(), var actionType: MissionActionType, var actionDatetimeUtc: ZonedDateTime, - var emitsVms: ControlCheck? = null, - var emitsAis: ControlCheck? = null, - var logbookMatchesActivity: ControlCheck? = null, - var licencesMatchActivity: ControlCheck? = null, + var emitsVms: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + var emitsAis: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + var logbookMatchesActivity: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + var licencesMatchActivity: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, var speciesWeightControlled: Boolean? = null, var speciesSizeControlled: Boolean? = null, - var separateStowageOfPreservedSpecies: ControlCheck? = null, - var logbookInfractions: List = listOf(), + var separateStowageOfPreservedSpecies: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + var logbookInfractions: List = listOf(), var licencesAndLogbookObservations: String? = null, - var gearInfractions: List = listOf(), + var gearInfractions: List = listOf(), var speciesInfractions: List = listOf(), var speciesObservations: String? = null, var seizureAndDiversion: Boolean? = null, @@ -34,17 +34,17 @@ data class AddMissionActionDataInput( var unitWithoutOmegaGauge: Boolean? = null, var controlQualityComments: String? = null, var feedbackSheetRequired: Boolean? = null, - var segments: List = listOf(), + var segments: List = listOf(), var facade: String? = null, var longitude: Double? = null, var latitude: Double? = null, var portLocode: String? = null, var seizureAndDiversionComments: String? = null, var otherComments: String? = null, - var gearOnboard: List = listOf(), + var gearOnboard: List = listOf(), var userTrigram: String? = null, var speciesOnboard: List = listOf(), - var vesselTargeted: ControlCheck? = null, + var vesselTargeted: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, var hasSomeGearsSeized: Boolean = false, var hasSomeSpeciesSeized: Boolean = false, var closedBy: String? = null, @@ -54,7 +54,7 @@ data class AddMissionActionDataInput( var isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null, var isSeafarersControl: Boolean? = null, ) { - fun toMissionAction() = MissionAction( + fun toMissionAction() = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( vesselId = vesselId, vesselName = vesselName, internalReferenceNumber = internalReferenceNumber, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportDataOutput.kt index 5b5da896dd..9eeb5c3745 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportDataOutput.kt @@ -1,8 +1,8 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep.ActivityCode -import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.dtos.ActivityReport +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.ActivityCode +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.dtos.ActivityReport data class ActivityReportDataOutput( val action: MissionActionDataOutput, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportsDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportsDataOutput.kt index e4b69195ea..705faa3dce 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportsDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportsDataOutput.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs -import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.dtos.ActivityReports +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.dtos.ActivityReports data class ActivityReportsDataOutput( val activityReports: List, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ControlsSummaryDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ControlsSummaryDataOutput.kt index e546998e3d..3fcba2928c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ControlsSummaryDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ControlsSummaryDataOutput.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.ControlsSummary +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlsSummary data class ControlsSummaryDataOutput( val vesselId: Int, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/FullMissionWithActionsDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/FullMissionWithActionsDataOutput.kt new file mode 100644 index 0000000000..c0d408feae --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/FullMissionWithActionsDataOutput.kt @@ -0,0 +1,57 @@ +package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs + +import fr.gouv.cnsp.monitorfish.domain.entities.mission.* +import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.EnvMissionAction +import java.time.ZonedDateTime + +/** +@see monitorenv/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/missions/MissionEntity.kt +for the full entity structure + */ +data class FullMissionWithActionsDataOutput( + val id: Int, + val missionTypes: List, + val openBy: String? = null, + val closedBy: String? = null, + val observationsCacem: String? = null, + val observationsCnsp: String? = null, + val facade: String? = null, + val geom: MultiPolygon? = null, + val createdAtUtc: ZonedDateTime? = null, + val updatedAtUtc: ZonedDateTime? = null, + val envActions: List? = listOf(), + val startDateTimeUtc: ZonedDateTime, + val endDateTimeUtc: ZonedDateTime? = null, + val isGeometryComputedFromControls: Boolean, + val missionSource: MissionSource, + val isClosed: Boolean, + val hasMissionOrder: Boolean? = false, + val isUnderJdp: Boolean? = false, + val controlUnits: List = listOf(), + val actions: List, +) { + companion object { + fun fromMissionAndActions(missionAndActions: MissionAndActions) = FullMissionWithActionsDataOutput( + id = missionAndActions.mission.id, + missionTypes = missionAndActions.mission.missionTypes, + openBy = missionAndActions.mission.openBy, + closedBy = missionAndActions.mission.closedBy, + observationsCacem = missionAndActions.mission.observationsCacem, + observationsCnsp = missionAndActions.mission.observationsCnsp, + facade = missionAndActions.mission.facade, + geom = missionAndActions.mission.geom, + createdAtUtc = missionAndActions.mission.createdAtUtc, + updatedAtUtc = missionAndActions.mission.updatedAtUtc, + envActions = missionAndActions.mission.envActions, + startDateTimeUtc = missionAndActions.mission.startDateTimeUtc, + endDateTimeUtc = missionAndActions.mission.endDateTimeUtc, + isGeometryComputedFromControls = missionAndActions.mission.isGeometryComputedFromControls, + missionSource = missionAndActions.mission.missionSource, + isClosed = missionAndActions.mission.isClosed, + hasMissionOrder = missionAndActions.mission.hasMissionOrder, + isUnderJdp = missionAndActions.mission.isUnderJdp, + controlUnits = missionAndActions.mission.controlUnits, + actions = missionAndActions.actions.map { MissionActionDataOutput.fromMissionAction(it) }, + ) + } +} diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearControlDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearControlDataOutput.kt index b39d5dea52..dad16220e3 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearControlDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearControlDataOutput.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.GearControl +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearControl data class GearControlDataOutput( var gearCode: String? = null, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/InfractionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/InfractionDataOutput.kt index 99b34a2937..fd91e93294 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/InfractionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/InfractionDataOutput.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction data class InfractionDataOutput( var natinfCode: Int? = null, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt index 8a7aafca5e..762b70a39d 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt @@ -1,7 +1,7 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.* +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import java.time.ZonedDateTime data class MissionActionDataOutput( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsController.kt index 4c60e39df1..c7d98234ba 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsController.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.public_api -import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.GetMissionActions +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.GetMissionActions import fr.gouv.cnsp.monitorfish.infrastructure.api.outputs.MissionActionDataOutput import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt index f387e47c0b..6c2bebe9b2 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt @@ -1,7 +1,7 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.entities -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.InfractionCategory +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory import jakarta.persistence.* @Entity @@ -18,11 +18,11 @@ data class InfractionEntity( var infraction: String? = null, ) { - fun toInfraction() = Infraction( + fun toInfraction() = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction( natinfCode = natinfCode, regulation = regulation, infractionCategory = infractionCategory?.let { category -> - InfractionCategory.values().firstOrNull { + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.values().firstOrNull { it.value == category } }, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt index 55157a9dfe..fda163498b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt @@ -2,7 +2,7 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.entities import com.fasterxml.jackson.databind.ObjectMapper import fr.gouv.cnsp.monitorfish.domain.entities.facade.Facade -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.* +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import io.hypersistence.utils.hibernate.type.array.ListArrayType import io.hypersistence.utils.hibernate.type.json.JsonBinaryType import jakarta.persistence.* @@ -48,23 +48,23 @@ class MissionActionEntity( val actionDatetimeUtc: Instant, @Column(name = "emits_vms") @Enumerated(EnumType.STRING) - val emitsVms: ControlCheck? = null, + val emitsVms: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, @Column(name = "emits_ais") @Enumerated(EnumType.STRING) - val emitsAis: ControlCheck? = null, + val emitsAis: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, @Column(name = "logbook_matches_activity") @Enumerated(EnumType.STRING) - val logbookMatchesActivity: ControlCheck? = null, + val logbookMatchesActivity: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, @Column(name = "licences_match_activity") @Enumerated(EnumType.STRING) - val licencesMatchActivity: ControlCheck? = null, + val licencesMatchActivity: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, @Column(name = "species_weight_controlled") val speciesWeightControlled: Boolean? = null, @Column(name = "species_size_controlled") val speciesSizeControlled: Boolean? = null, @Column(name = "separate_stowage_of_preserved_species") @Enumerated(EnumType.STRING) - val separateStowageOfPreservedSpecies: ControlCheck? = null, + val separateStowageOfPreservedSpecies: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, @Type(JsonBinaryType::class) @Column(name = "logbook_infractions", columnDefinition = "jsonb") val logbookInfractions: String? = null, @@ -108,7 +108,7 @@ class MissionActionEntity( val portLocode: String? = null, @Column(name = "vessel_targeted") @Enumerated(EnumType.STRING) - val vesselTargeted: ControlCheck? = null, + val vesselTargeted: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, @Column(name = "seizure_and_diversion_comments") val seizureAndDiversionComments: String? = null, @Column(name = "other_comments") @@ -138,7 +138,10 @@ class MissionActionEntity( ) { companion object { - fun fromMissionAction(mapper: ObjectMapper, missionAction: MissionAction): MissionActionEntity = + fun fromMissionAction( + mapper: ObjectMapper, + missionAction: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction, + ): MissionActionEntity = MissionActionEntity( id = missionAction.id, missionId = missionAction.missionId, @@ -194,59 +197,80 @@ class MissionActionEntity( ) } - fun toMissionAction(mapper: ObjectMapper) = MissionAction( - id = id, - missionId = missionId, - vesselId = vesselId, - vesselName = vesselName, - internalReferenceNumber = internalReferenceNumber, - externalReferenceNumber = externalReferenceNumber, - ircs = ircs, - flagState = flagState, - districtCode = districtCode, - faoAreas = faoAreas ?: listOf(), - flightGoals = flightGoals?.map { FlightGoal.valueOf(it) } ?: listOf(), - actionType = actionType, - actionDatetimeUtc = actionDatetimeUtc.atZone(ZoneOffset.UTC), - emitsVms = emitsVms, - emitsAis = emitsAis, - logbookMatchesActivity = logbookMatchesActivity, - licencesMatchActivity = licencesMatchActivity, - speciesWeightControlled = speciesWeightControlled, - speciesSizeControlled = speciesSizeControlled, - separateStowageOfPreservedSpecies = separateStowageOfPreservedSpecies, - logbookInfractions = deserializeJSONList(mapper, logbookInfractions, LogbookInfraction::class.java), - licencesAndLogbookObservations = licencesAndLogbookObservations, - gearInfractions = deserializeJSONList(mapper, gearInfractions, GearInfraction::class.java), - speciesInfractions = deserializeJSONList(mapper, speciesInfractions, SpeciesInfraction::class.java), - speciesObservations = speciesObservations, - seizureAndDiversion = seizureAndDiversion, - otherInfractions = deserializeJSONList(mapper, otherInfractions, OtherInfraction::class.java), - numberOfVesselsFlownOver = numberOfVesselsFlownOver, - unitWithoutOmegaGauge = unitWithoutOmegaGauge, - controlQualityComments = controlQualityComments, - feedbackSheetRequired = feedbackSheetRequired, - userTrigram = userTrigram, - segments = deserializeJSONList(mapper, segments, FleetSegment::class.java), - facade = facade?.let { Facade.from(it).toString() }, - longitude = longitude, - latitude = latitude, - portLocode = portLocode, - vesselTargeted = vesselTargeted, - seizureAndDiversionComments = seizureAndDiversionComments, - otherComments = otherComments, - gearOnboard = deserializeJSONList(mapper, gearOnboard, GearControl::class.java), - speciesOnboard = deserializeJSONList(mapper, speciesOnboard, SpeciesControl::class.java), - isDeleted = isDeleted, - hasSomeGearsSeized = hasSomeGearsSeized, - hasSomeSpeciesSeized = hasSomeSpeciesSeized, - closedBy = closedBy, - isFromPoseidon = isFromPoseidon, - isAdministrativeControl = isAdministrativeControl, - isComplianceWithWaterRegulationsControl = isComplianceWithWaterRegulationsControl, - isSafetyEquipmentAndStandardsComplianceControl = isSafetyEquipmentAndStandardsComplianceControl, - isSeafarersControl = isSeafarersControl, - ) + fun toMissionAction(mapper: ObjectMapper) = + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( + id = id, + missionId = missionId, + vesselId = vesselId, + vesselName = vesselName, + internalReferenceNumber = internalReferenceNumber, + externalReferenceNumber = externalReferenceNumber, + ircs = ircs, + flagState = flagState, + districtCode = districtCode, + faoAreas = faoAreas ?: listOf(), + flightGoals = flightGoals?.map { + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FlightGoal.valueOf( + it, + ) + } ?: listOf(), + actionType = actionType, + actionDatetimeUtc = actionDatetimeUtc.atZone(ZoneOffset.UTC), + emitsVms = emitsVms, + emitsAis = emitsAis, + logbookMatchesActivity = logbookMatchesActivity, + licencesMatchActivity = licencesMatchActivity, + speciesWeightControlled = speciesWeightControlled, + speciesSizeControlled = speciesSizeControlled, + separateStowageOfPreservedSpecies = separateStowageOfPreservedSpecies, + logbookInfractions = deserializeJSONList( + mapper, + logbookInfractions, + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.LogbookInfraction::class.java, + ), + licencesAndLogbookObservations = licencesAndLogbookObservations, + gearInfractions = deserializeJSONList( + mapper, + gearInfractions, + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearInfraction::class.java, + ), + speciesInfractions = deserializeJSONList(mapper, speciesInfractions, SpeciesInfraction::class.java), + speciesObservations = speciesObservations, + seizureAndDiversion = seizureAndDiversion, + otherInfractions = deserializeJSONList(mapper, otherInfractions, OtherInfraction::class.java), + numberOfVesselsFlownOver = numberOfVesselsFlownOver, + unitWithoutOmegaGauge = unitWithoutOmegaGauge, + controlQualityComments = controlQualityComments, + feedbackSheetRequired = feedbackSheetRequired, + userTrigram = userTrigram, + segments = deserializeJSONList( + mapper, + segments, + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FleetSegment::class.java, + ), + facade = facade?.let { Facade.from(it).toString() }, + longitude = longitude, + latitude = latitude, + portLocode = portLocode, + vesselTargeted = vesselTargeted, + seizureAndDiversionComments = seizureAndDiversionComments, + otherComments = otherComments, + gearOnboard = deserializeJSONList( + mapper, + gearOnboard, + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearControl::class.java, + ), + speciesOnboard = deserializeJSONList(mapper, speciesOnboard, SpeciesControl::class.java), + isDeleted = isDeleted, + hasSomeGearsSeized = hasSomeGearsSeized, + hasSomeSpeciesSeized = hasSomeSpeciesSeized, + closedBy = closedBy, + isFromPoseidon = isFromPoseidon, + isAdministrativeControl = isAdministrativeControl, + isComplianceWithWaterRegulationsControl = isComplianceWithWaterRegulationsControl, + isSafetyEquipmentAndStandardsComplianceControl = isSafetyEquipmentAndStandardsComplianceControl, + isSeafarersControl = isSeafarersControl, + ) private fun deserializeJSONList(mapper: ObjectMapper, json: String?, clazz: Class): List = json?.let { mapper.readValue( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepository.kt index 90da7d3f88..cb2ab29bd7 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepository.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.repositories -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction import fr.gouv.cnsp.monitorfish.domain.exceptions.NatinfCodeNotFoundException import fr.gouv.cnsp.monitorfish.domain.repositories.InfractionRepository import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.interfaces.DBInfractionRepository @@ -11,14 +11,14 @@ import org.springframework.stereotype.Repository @Repository class JpaInfractionRepository(private val dbInfractionRepository: DBInfractionRepository) : InfractionRepository { @Cacheable(value = ["infractions"]) - override fun findAll(): List { + override fun findAll(): List { return dbInfractionRepository.findAll().map { it.toInfraction() } } @Cacheable(value = ["infraction"]) - override fun findInfractionByNatinfCode(natinfCode: Int): Infraction { + override fun findInfractionByNatinfCode(natinfCode: Int): fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction { return try { dbInfractionRepository.findByNatinfCodeEquals(natinfCode).toInfraction() } catch (e: EmptyResultDataAccessException) { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt index 222e883f60..6cb5878d20 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt @@ -1,8 +1,8 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.repositories import com.fasterxml.jackson.databind.ObjectMapper -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.MissionActionEntity import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.interfaces.DBMissionActionsRepository @@ -18,14 +18,14 @@ class JpaMissionActionsRepository( override fun findVesselMissionActionsAfterDateTime( vesselId: Int, afterDateTime: ZonedDateTime, - ): List { + ): List { return dbMissionActionsRepository.findAllByVesselIdEqualsAndActionDatetimeUtcAfterAndIsDeletedIsFalse( vesselId, afterDateTime.toInstant(), ).map { control -> control.toMissionAction(mapper) } } - override fun findByMissionId(missionId: Int): List { + override fun findByMissionId(missionId: Int): List { return dbMissionActionsRepository.findAllByMissionIdAndIsDeletedIsFalse(missionId).map { action -> action.toMissionAction( mapper, @@ -33,7 +33,7 @@ class JpaMissionActionsRepository( } } - override fun findMissionActionsIn(missionIds: List): List { + override fun findMissionActionsIn(missionIds: List): List { return dbMissionActionsRepository.findAllByMissionIdInAndIsDeletedIsFalse(missionIds).map { action -> action.toMissionAction( mapper, @@ -41,16 +41,16 @@ class JpaMissionActionsRepository( } } - override fun save(missionAction: MissionAction): MissionAction { + override fun save(missionAction: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction): fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction { return dbMissionActionsRepository.save(MissionActionEntity.fromMissionAction(mapper, missionAction)) .toMissionAction(mapper) } - override fun findById(id: Int): MissionAction { + override fun findById(id: Int): fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction { return dbMissionActionsRepository.findById(id).get().toMissionAction(mapper) } - override fun findControlsInDates(beforeDateTime: ZonedDateTime, afterDateTime: ZonedDateTime): List { + override fun findControlsInDates(beforeDateTime: ZonedDateTime, afterDateTime: ZonedDateTime): List { return dbMissionActionsRepository.findAllByActionDatetimeUtcBeforeAndActionDatetimeUtcAfterAndIsDeletedIsFalseAndActionTypeIn( beforeDateTime.toInstant(), afterDateTime.toInstant(), diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBMissionActionsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBMissionActionsRepository.kt index f7baa6fc6d..2d6a9aafb0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBMissionActionsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBMissionActionsRepository.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.interfaces -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.MissionActionEntity import org.springframework.data.repository.CrudRepository import java.time.Instant diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepository.kt index 5e5c2e6c7c..1e91c28717 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepository.kt @@ -4,6 +4,7 @@ import fr.gouv.cnsp.monitorfish.config.ApiClient import fr.gouv.cnsp.monitorfish.config.MonitorenvProperties import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit import fr.gouv.cnsp.monitorfish.domain.entities.mission.Mission +import fr.gouv.cnsp.monitorfish.domain.exceptions.CouldNotFindException import fr.gouv.cnsp.monitorfish.domain.repositories.MissionRepository import fr.gouv.cnsp.monitorfish.infrastructure.monitorenv.input.MissionDataResponse import io.ktor.client.call.* @@ -122,4 +123,19 @@ class APIMissionRepository( } } } + + override fun findById(id: Int): Mission { + val missionUrl = "${monitorenvProperties.url}/api/v1/missions/$id" + + logger.info("Fetching mission at URL: $missionUrl") + return runBlocking { + try { + val mission = apiClient.httpClient.get(missionUrl).body() + + return@runBlocking mission.toFullMission() + } catch (e: Exception) { + throw CouldNotFindException("Could not fetch missions at $missionUrl", e) + } + } + } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt new file mode 100644 index 0000000000..f22ee2092d --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt @@ -0,0 +1,38 @@ +package fr.gouv.cnsp.monitorfish.infrastructure.monitorenv.input + +import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.EnvMissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.MissionActionType +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import java.time.ZonedDateTime +import java.util.* + +@Serializable +data class EnvMissionActionDataResponse( + @Serializable(with = UUIDSerializer::class) + val id: UUID, + val actionStartDateTimeUtc: String, + val actionType: MissionActionType, +) { + fun toEnvMissionAction() = EnvMissionAction( + id = id, + actionStartDateTimeUtc = ZonedDateTime.parse(actionStartDateTimeUtc), + actionType = actionType, + ) +} + +object UUIDSerializer : KSerializer { + override val descriptor = PrimitiveSerialDescriptor("UUID", PrimitiveKind.STRING) + + override fun deserialize(decoder: Decoder): UUID { + return UUID.fromString(decoder.decodeString()) + } + + override fun serialize(encoder: Encoder, value: UUID) { + encoder.encodeString(value.toString()) + } +} diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/MissionDataResponse.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/MissionDataResponse.kt index 2763cbb905..b4c81fd37f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/MissionDataResponse.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/MissionDataResponse.kt @@ -19,6 +19,9 @@ data class MissionDataResponse( val observationsCnsp: String? = null, val facade: String? = null, val geom: MultiPolygon? = null, + val createdAtUtc: String? = null, + val updatedAtUtc: String? = null, + val envActions: List? = listOf(), val startDateTimeUtc: String, val endDateTimeUtc: String? = null, val isGeometryComputedFromControls: Boolean, @@ -45,4 +48,14 @@ data class MissionDataResponse( hasMissionOrder = hasMissionOrder, isUnderJdp = isUnderJdp, ) + + fun toFullMission(): Mission { + val mission = toMission().copy( + createdAtUtc = createdAtUtc?.let { ZonedDateTime.parse(createdAtUtc) }, + updatedAtUtc = updatedAtUtc?.let { ZonedDateTime.parse(updatedAtUtc) }, + envActions = envActions?.map { it.toEnvMissionAction() }, + ) + + return mission + } } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/MissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt similarity index 98% rename from backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/MissionActionUTests.kt rename to backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt index db8606dfa0..f662e2ec39 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/MissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/JointDeploymentPlanUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlanUTests.kt similarity index 97% rename from backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/JointDeploymentPlanUTests.kt rename to backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlanUTests.kt index d2c7cd8fef..cc4e11540a 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission_actions/actrep/JointDeploymentPlanUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlanUTests.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep +package fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetPendingAlertsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetPendingAlertsUTests.kt index a864ef28cd..2f65ab51c3 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetPendingAlertsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetPendingAlertsUTests.kt @@ -6,8 +6,8 @@ import com.nhaarman.mockitokotlin2.eq import fr.gouv.cnsp.monitorfish.domain.entities.alerts.PendingAlert import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.AlertTypeMapping import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.ThreeMilesTrawlingAlert -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.InfractionCategory +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselIdentifier import fr.gouv.cnsp.monitorfish.domain.repositories.InfractionRepository import fr.gouv.cnsp.monitorfish.domain.repositories.PendingAlertRepository @@ -45,7 +45,10 @@ class GetPendingAlertsUTests { value = ThreeMilesTrawlingAlert(), ) given(infractionRepository.findInfractionByNatinfCode(eq(7059))).willReturn( - Infraction(natinfCode = 7059, infractionCategory = InfractionCategory.FISHING), + Infraction( + natinfCode = 7059, + infractionCategory = InfractionCategory.FISHING, + ), ) given(pendingAlertRepository.findAlertsOfTypes(any())).willReturn(listOf(pendingAlert)) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselReportingsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselReportingsUTests.kt index 32ac6414b5..bbdd37580e 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselReportingsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselReportingsUTests.kt @@ -2,8 +2,8 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.eq -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.InfractionCategory +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselIdentifier import fr.gouv.cnsp.monitorfish.domain.repositories.InfractionRepository import fr.gouv.cnsp.monitorfish.domain.repositories.ReportingRepository @@ -33,7 +33,10 @@ class GetVesselReportingsUTests { fun `execute Should return the reporting of a specified vessel When vessel id is null`() { // Given given(infractionRepository.findInfractionByNatinfCode(eq(7059))).willReturn( - Infraction(natinfCode = 7059, infractionCategory = InfractionCategory.FISHING), + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction( + natinfCode = 7059, + infractionCategory = InfractionCategory.FISHING, + ), ) given(reportingRepository.findCurrentAndArchivedByVesselIdentifierEquals(any(), any(), any())).willReturn( TestUtils.getDummyReportings(), @@ -67,7 +70,10 @@ class GetVesselReportingsUTests { fun `execute Should return the reporting of a specified vessel When vessel id is not null`() { // Given given(infractionRepository.findInfractionByNatinfCode(eq(7059))).willReturn( - Infraction(natinfCode = 7059, infractionCategory = InfractionCategory.FISHING), + Infraction( + natinfCode = 7059, + infractionCategory = InfractionCategory.FISHING, + ), ) given(reportingRepository.findCurrentAndArchivedByVesselIdEquals(eq(123456), any())).willReturn( TestUtils.getDummyReportings(), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/missions/GetAllMissionsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissionsUTests.kt similarity index 92% rename from backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/missions/GetAllMissionsUTests.kt rename to backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissionsUTests.kt index df951e627f..9ccf088cd1 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/missions/GetAllMissionsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissionsUTests.kt @@ -1,17 +1,16 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.missions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission import com.nhaarman.mockitokotlin2.* import fr.gouv.cnsp.monitorfish.config.DatabaseProperties import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository import fr.gouv.cnsp.monitorfish.domain.repositories.MissionRepository -import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.TestUtils.getDummyMissionActions -import fr.gouv.cnsp.monitorfish.domain.use_cases.missions.TestUtils.getDummyMissions +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.TestUtils.getDummyMissionActions +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.TestUtils.getDummyMissions import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.test.context.junit.jupiter.SpringExtension -import java.util.* @ExtendWith(SpringExtension::class) class GetAllMissionsUTests { diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt new file mode 100644 index 0000000000..6d2dd34589 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt @@ -0,0 +1,92 @@ +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission + +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.given +import com.nhaarman.mockitokotlin2.willThrow +import fr.gouv.cnsp.monitorfish.domain.entities.mission.Mission +import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionSource +import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.EnvMissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.exceptions.CouldNotFindException +import fr.gouv.cnsp.monitorfish.domain.repositories.MissionRepository +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.TestUtils.getDummyMissionActions +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.GetMissionActions +import kotlinx.coroutines.runBlocking +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.catchThrowable +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.test.context.junit.jupiter.SpringExtension +import java.time.ZonedDateTime +import java.util.* + +@ExtendWith(SpringExtension::class) +class GetMissionUTests { + + @MockBean + private lateinit var getMissionActions: GetMissionActions + + @MockBean + private lateinit var missionRepository: MissionRepository + + @Test + fun `execute Should get a mission with associated actions`() { + // Given + given(missionRepository.findById(any())).willReturn( + Mission( + id = 123, + controlUnits = listOf(), + missionTypes = listOf(MissionType.SEA), + startDateTimeUtc = ZonedDateTime.now(), + isGeometryComputedFromControls = false, + missionSource = MissionSource.MONITORFISH, + isClosed = false, + envActions = listOf( + EnvMissionAction( + id = UUID.randomUUID(), + actionStartDateTimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.CONTROL, + ), + ), + ), + ) + given(getMissionActions.execute(any())).willReturn(getDummyMissionActions(listOf(123, 456))) + + // When + val missionsAndActions = runBlocking { + return@runBlocking GetMission( + missionRepository, + getMissionActions, + ).execute(123) + } + + // Then + assertThat(missionsAndActions.mission.envActions).hasSize(1) + assertThat(missionsAndActions.actions).hasSize(2) + } + + @Test + fun `execute Should throw When a mission could not be fetched`() { + // Given + given(missionRepository.findById(any())).willThrow(CouldNotFindException("API ERROR")) + given(getMissionActions.execute(any())).willReturn(getDummyMissionActions(listOf(123, 456))) + + // When + val throwable = catchThrowable { + runBlocking { + GetMission( + missionRepository, + getMissionActions, + ).execute(123) + } + } + + // Then + assertThat(throwable).isNotNull() + assertThat(throwable.message).isEqualTo( + "API ERROR", + ) + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/TestUtils.kt similarity index 50% rename from backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/TestUtils.kt rename to backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/TestUtils.kt index ccf301dc2e..3253f0710c 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/TestUtils.kt @@ -1,10 +1,29 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.Mission +import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionSource +import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType import java.time.ZonedDateTime object TestUtils { + fun getDummyMissions(number: Int): List { + val ids = (1..number).toList() + + return ids.map { + return@map Mission( + id = it, + controlUnits = listOf(), + missionTypes = listOf(MissionType.SEA), + startDateTimeUtc = ZonedDateTime.now(), + isGeometryComputedFromControls = false, + missionSource = MissionSource.MONITORFISH, + isClosed = false, + ) + } + } + fun getDummyMissionActions(missionIds: List): List { return missionIds.map { missionId -> // Generate the number of mission actions corresponding to the id of the mission diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/AddMissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionActionUTests.kt similarity index 92% rename from backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/AddMissionActionUTests.kt rename to backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionActionUTests.kt index 060fd7e018..aebf933f02 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/AddMissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionActionUTests.kt @@ -1,12 +1,12 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import com.nhaarman.mockitokotlin2.anyOrNull import com.nhaarman.mockitokotlin2.argumentCaptor import com.nhaarman.mockitokotlin2.given import com.nhaarman.mockitokotlin2.verify import fr.gouv.cnsp.monitorfish.domain.entities.facade.Facade -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/DeleteMissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionActionUTests.kt similarity index 86% rename from backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/DeleteMissionActionUTests.kt rename to backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionActionUTests.kt index 53974a4358..35e99f449a 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/DeleteMissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionActionUTests.kt @@ -1,8 +1,8 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import com.nhaarman.mockitokotlin2.* -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetActivityReportsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt similarity index 96% rename from backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetActivityReportsUTests.kt rename to backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt index a47bc20227..ebf32c9e87 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetActivityReportsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt @@ -1,4 +1,4 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import com.neovisionaries.i18n.CountryCode import com.nhaarman.mockitokotlin2.any @@ -7,11 +7,11 @@ import com.nhaarman.mockitokotlin2.given import fr.gouv.cnsp.monitorfish.domain.entities.mission.Mission import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionSource import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionType -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.SpeciesControl -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep.ActivityCode -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep.JointDeploymentPlan +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.SpeciesControl +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.ActivityCode +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.JointDeploymentPlan import fr.gouv.cnsp.monitorfish.domain.entities.port.Port import fr.gouv.cnsp.monitorfish.domain.entities.vessel.Vessel import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionActionFacadeUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionFacadeUTests.kt similarity index 95% rename from backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionActionFacadeUTests.kt rename to backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionFacadeUTests.kt index f8c7d5e7cd..85546776d9 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetMissionActionFacadeUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionFacadeUTests.kt @@ -1,11 +1,11 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.given import fr.gouv.cnsp.monitorfish.domain.entities.facade.Facade import fr.gouv.cnsp.monitorfish.domain.entities.facade.FacadeArea -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType import fr.gouv.cnsp.monitorfish.domain.entities.port.Port import fr.gouv.cnsp.monitorfish.domain.repositories.FacadeAreasRepository import fr.gouv.cnsp.monitorfish.domain.repositories.PortRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetVesselControlsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControlsUTests.kt similarity index 91% rename from backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetVesselControlsUTests.kt rename to backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControlsUTests.kt index 90648bd356..f82d1e97cc 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/GetVesselControlsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControlsUTests.kt @@ -1,12 +1,12 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.eq import fr.gouv.cnsp.monitorfish.domain.entities.gear.Gear -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.GearControl -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.SpeciesInfraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearControl +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.SpeciesInfraction import fr.gouv.cnsp.monitorfish.domain.entities.port.Port import fr.gouv.cnsp.monitorfish.domain.repositories.GearRepository import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/UpdateMissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt similarity index 86% rename from backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/UpdateMissionActionUTests.kt rename to backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt index 3fe31e1850..478df3e0ae 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission_actions/UpdateMissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt @@ -1,7 +1,7 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions +package fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType import fr.gouv.cnsp.monitorfish.domain.repositories.MissionActionsRepository import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/missions/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/missions/TestUtils.kt deleted file mode 100644 index 79f24dcc87..0000000000 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/missions/TestUtils.kt +++ /dev/null @@ -1,24 +0,0 @@ -package fr.gouv.cnsp.monitorfish.domain.use_cases.missions - -import fr.gouv.cnsp.monitorfish.domain.entities.mission.Mission -import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionSource -import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionType -import java.time.ZonedDateTime - -object TestUtils { - fun getDummyMissions(number: Int): List { - val ids = (1..number).toList() - - return ids.map { - return@map Mission( - id = it, - controlUnits = listOf(), - missionTypes = listOf(MissionType.SEA), - startDateTimeUtc = ZonedDateTime.now(), - isGeometryComputedFromControls = false, - missionSource = MissionSource.MONITORFISH, - isClosed = false, - ) - } - } -} diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt index b32bbdf66a..559e67619c 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt @@ -6,8 +6,8 @@ import fr.gouv.cnsp.monitorfish.config.OIDCProperties import fr.gouv.cnsp.monitorfish.config.SecurityConfig import fr.gouv.cnsp.monitorfish.config.SentryConfig import fr.gouv.cnsp.monitorfish.domain.entities.mission.* -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.* -import fr.gouv.cnsp.monitorfish.domain.use_cases.missions.GetAllMissions +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.GetAllMissions import kotlinx.coroutines.runBlocking import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test @@ -59,7 +59,7 @@ class MissionsControllerITests { startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), ), actions = listOf( - MissionAction( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( id = 3, vesselId = 1, missionId = 123, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt index 90335b1c11..c2ecca7c56 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt @@ -7,13 +7,14 @@ import fr.gouv.cnsp.monitorfish.config.OIDCProperties import fr.gouv.cnsp.monitorfish.config.SecurityConfig import fr.gouv.cnsp.monitorfish.config.SentryConfig import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.* -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep.ActivityCode -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep.JointDeploymentPlan +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.ActivityCode +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.JointDeploymentPlan import fr.gouv.cnsp.monitorfish.domain.entities.vessel.Vessel +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.* +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.dtos.ActivityReport +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.dtos.ActivityReports import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.* -import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.dtos.ActivityReport -import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.dtos.ActivityReports import fr.gouv.cnsp.monitorfish.infrastructure.api.input.AddMissionActionDataInput import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.TestUtils import kotlinx.coroutines.runBlocking @@ -70,13 +71,13 @@ class PublicMissionActionsControllerITests { fun `Should get all controls for a vessel`() { // Given givenSuspended { this.getVesselControls.execute(any(), any()) }.willReturn( - ControlsSummary( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlsSummary( 1, 3, 4, 5, listOf( - MissionAction( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( 1, 1, 1, @@ -110,7 +111,7 @@ class PublicMissionActionsControllerITests { // Given givenSuspended { this.getMissionActions.execute(any()) }.willReturn( listOf( - MissionAction( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( 123, 1, 1, @@ -154,21 +155,25 @@ class PublicMissionActionsControllerITests { vesselId = 2, actionType = MissionActionType.SEA_CONTROL, logbookInfractions = listOf( - LogbookInfraction( - InfractionType.WITH_RECORD, + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.LogbookInfraction( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, 27689, "Poids à bord MNZ supérieur de 50% au poids déclaré", ), ), faoAreas = listOf("25.6.9", "25.7.9"), segments = listOf( - FleetSegment( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FleetSegment( segment = "WWSS10", segmentName = "World Wide Segment", ), ), gearInfractions = listOf( - GearInfraction(InfractionType.WITH_RECORD, 27689, "Maille trop petite"), + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearInfraction( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + 27689, + "Maille trop petite", + ), ), hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, @@ -198,7 +203,7 @@ class PublicMissionActionsControllerITests { ), ) - argumentCaptor().apply { + argumentCaptor().apply { verify(addMissionAction).execute(capture()) Assertions.assertThat(allValues[0].actionDatetimeUtc.toString()).isEqualTo("2023-04-27T16:05Z") @@ -212,7 +217,7 @@ class PublicMissionActionsControllerITests { val newMission = TestUtils.getDummyMissionAction(dateTime) given(updateMissionAction.execute(any(), any())).willReturn(newMission) - val gearControl = GearControl() + val gearControl = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearControl() gearControl.declaredMesh = 60.0 gearControl.hasUncontrolledMesh = true gearControl.gearCode = "OTB" @@ -228,21 +233,25 @@ class PublicMissionActionsControllerITests { vesselId = 2, actionType = MissionActionType.SEA_CONTROL, logbookInfractions = listOf( - LogbookInfraction( - InfractionType.WITH_RECORD, + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.LogbookInfraction( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, 27689, "Poids à bord MNZ supérieur de 50% au poids déclaré", ), ), faoAreas = listOf("25.6.9", "25.7.9"), segments = listOf( - FleetSegment( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FleetSegment( segment = "WWSS10", segmentName = "World Wide Segment", ), ), gearInfractions = listOf( - GearInfraction(InfractionType.WITH_RECORD, 27689, "Maille trop petite"), + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearInfraction( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + 27689, + "Maille trop petite", + ), ), gearOnboard = listOf(gearControl), hasSomeGearsSeized = false, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt index 93972e3b0e..80c53a000f 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt @@ -14,8 +14,8 @@ import fr.gouv.cnsp.monitorfish.domain.entities.last_position.Gear import fr.gouv.cnsp.monitorfish.domain.entities.last_position.LastPosition import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookMessagesAndAlerts import fr.gouv.cnsp.monitorfish.domain.entities.logbook.Voyage -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.InfractionCategory +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory import fr.gouv.cnsp.monitorfish.domain.entities.position.Position import fr.gouv.cnsp.monitorfish.domain.entities.position.PositionType import fr.gouv.cnsp.monitorfish.domain.entities.reporting.CurrentAndArchivedReportings @@ -549,9 +549,9 @@ class VesselControllerITests { value = ThreeMilesTrawlingAlert() as ReportingValue, isArchived = false, isDeleted = false, - infraction = Infraction( + infraction = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction( natinfCode = 7059, - infractionCategory = InfractionCategory.FISHING, + infractionCategory = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.FISHING, ), ), null, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt index 34d7dbe09c..2548f8b12e 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt @@ -3,8 +3,8 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.public_api import fr.gouv.cnsp.monitorfish.config.OIDCProperties import fr.gouv.cnsp.monitorfish.config.SecurityConfig import fr.gouv.cnsp.monitorfish.config.SentryConfig -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.Infraction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.InfractionCategory +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory import fr.gouv.cnsp.monitorfish.domain.use_cases.infraction.GetAllInfractions import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test @@ -33,8 +33,14 @@ class InfractionControllerITests { // Given given(this.getAllInfractions.execute()).willReturn( listOf( - Infraction(natinfCode = 7059, infractionCategory = InfractionCategory.FISHING), - Infraction(natinfCode = 7065, infractionCategory = InfractionCategory.FISHING), + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction( + natinfCode = 7059, + infractionCategory = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.FISHING, + ), + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction( + natinfCode = 7065, + infractionCategory = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.FISHING, + ), ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt index 0fbbb01a6c..981c00356d 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt @@ -4,9 +4,9 @@ import com.nhaarman.mockitokotlin2.any import fr.gouv.cnsp.monitorfish.config.OIDCProperties import fr.gouv.cnsp.monitorfish.config.SecurityConfig import fr.gouv.cnsp.monitorfish.config.SentryConfig -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType -import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.GetMissionActions +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.GetMissionActions import kotlinx.coroutines.runBlocking import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test @@ -39,7 +39,7 @@ class PublicMissionActionsControllerITests { // Given givenSuspended { this.getMissionActions.execute(any()) }.willReturn( listOf( - MissionAction( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( 123, 1, 1, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt index d71bbd3eeb..62649c37da 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.repositories -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.InfractionCategory +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable import org.junit.jupiter.api.Test @@ -20,7 +20,9 @@ class JpaInfractionRepositoryITests : AbstractDBTests() { // Then assertThat(infraction.infraction).isEqualTo("Taille de maille non réglementaire") - assertThat(infraction.infractionCategory).isEqualTo(InfractionCategory.FISHING) + assertThat(infraction.infractionCategory).isEqualTo( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.FISHING, + ) assertThat(infraction.natinfCode).isEqualTo(23581) assertThat(infraction.regulation).isEqualTo("Arreté du 12/01/3021") } @@ -48,6 +50,8 @@ class JpaInfractionRepositoryITests : AbstractDBTests() { assertThat(infractions.first().natinfCode).isEqualTo(23581) assertThat(infractions.first().regulation).isEqualTo("Arreté du 12/01/3021") assertThat(infractions.first().infraction).isEqualTo("Taille de maille non réglementaire") - assertThat(infractions.first().infractionCategory).isEqualTo(InfractionCategory.FISHING) + assertThat(infractions.first().infractionCategory).isEqualTo( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.FISHING, + ) } } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt index 74eedc7504..36a3322588 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt @@ -1,9 +1,9 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.repositories -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.ControlCheck -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.InfractionType -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.TestUtils.getDummyMissionAction import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable @@ -48,17 +48,27 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { assertThat(controls).hasSize(2) val firstControl = controls.first() - assertThat(firstControl.emitsVms).isEqualTo(ControlCheck.YES) - assertThat(firstControl.emitsAis).isEqualTo(ControlCheck.NOT_APPLICABLE) - assertThat(firstControl.logbookMatchesActivity).isEqualTo(ControlCheck.NO) + assertThat(firstControl.emitsVms).isEqualTo( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.YES, + ) + assertThat(firstControl.emitsAis).isEqualTo( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NOT_APPLICABLE, + ) + assertThat(firstControl.logbookMatchesActivity).isEqualTo( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NO, + ) assertThat(firstControl.speciesWeightControlled).isTrue assertThat(firstControl.speciesSizeControlled).isTrue - assertThat(firstControl.separateStowageOfPreservedSpecies).isEqualTo(ControlCheck.YES) + assertThat(firstControl.separateStowageOfPreservedSpecies).isEqualTo( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.YES, + ) assertThat(firstControl.faoAreas).hasSize(2) assertThat(firstControl.faoAreas.first()).isEqualTo("27.7.d") assertThat(firstControl.faoAreas.last()).isEqualTo("27.7.e") assertThat(firstControl.logbookInfractions).hasSize(1) - assertThat(firstControl.logbookInfractions.first().infractionType).isEqualTo(InfractionType.WITH_RECORD) + assertThat(firstControl.logbookInfractions.first().infractionType).isEqualTo( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + ) assertThat(firstControl.logbookInfractions.first().natinf).isEqualTo(27689) assertThat(firstControl.logbookInfractions.first().comments).contains( "Poids à bord MNZ supérieur de 50% au poids déclaré", @@ -67,17 +77,23 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { "C'est pas très très bien réglo toute cette poissecalle non déclarée", ) assertThat(firstControl.gearInfractions).hasSize(2) - assertThat(firstControl.gearInfractions.first().infractionType).isEqualTo(InfractionType.WITH_RECORD) + assertThat(firstControl.gearInfractions.first().infractionType).isEqualTo( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + ) assertThat(firstControl.gearInfractions.first().natinf).isEqualTo(23581) assertThat(firstControl.gearInfractions.first().comments).isEqualTo("Maille trop petite") assertThat(firstControl.speciesInfractions).hasSize(1) - assertThat(firstControl.speciesInfractions.first().infractionType).isEqualTo(InfractionType.WITHOUT_RECORD) + assertThat(firstControl.speciesInfractions.first().infractionType).isEqualTo( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITHOUT_RECORD, + ) assertThat(firstControl.speciesInfractions.first().natinf).isEqualTo(28346) assertThat(firstControl.speciesInfractions.first().comments).isEqualTo("Sous taille de 8cm") assertThat(firstControl.speciesObservations).isEqualTo("Saisie de l'ensemble des captures à bord") assertThat(firstControl.seizureAndDiversion).isTrue assertThat(firstControl.otherInfractions).hasSize(2) - assertThat(firstControl.otherInfractions.first().infractionType).isEqualTo(InfractionType.WITH_RECORD) + assertThat(firstControl.otherInfractions.first().infractionType).isEqualTo( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + ) assertThat(firstControl.otherInfractions.first().natinf).isEqualTo(23588) assertThat(firstControl.otherInfractions.first().comments).isEqualTo( "Chalutage répété dans les 3 milles sur Piste VMS - confirmé de visu", @@ -94,7 +110,9 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { assertThat(firstControl.longitude).isEqualTo(-0.52) assertThat(firstControl.latitude).isEqualTo(47.44) assertThat(firstControl.portLocode).isNull() - assertThat(firstControl.vesselTargeted).isEqualTo(ControlCheck.NO) + assertThat(firstControl.vesselTargeted).isEqualTo( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NO, + ) assertThat(firstControl.seizureAndDiversion).isTrue assertThat(firstControl.seizureAndDiversionComments).isEqualTo("Saisie de la pêche") assertThat(firstControl.otherComments).isEqualTo("Commentaires post contrôle") @@ -189,14 +207,14 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { val existingAction = jpaMissionActionsRepository.findById(expectedId) assertThat(existingAction.internalReferenceNumber).isNull() - val actionToUpdate = MissionAction( + val actionToUpdate = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( actionDatetimeUtc = ZonedDateTime.now(), actionType = MissionActionType.SEA_CONTROL, controlQualityComments = null, controlUnits = listOf(), districtCode = null, emitsAis = null, - emitsVms = ControlCheck.NOT_APPLICABLE, + emitsVms = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NOT_APPLICABLE, externalReferenceNumber = "DONTSINK", facade = "Sud Océan Indien", faoAreas = listOf(), @@ -210,9 +228,9 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { ircs = "CALLME", latitude = 49.44, licencesAndLogbookObservations = null, - licencesMatchActivity = ControlCheck.NOT_APPLICABLE, + licencesMatchActivity = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NOT_APPLICABLE, logbookInfractions = listOf(), - logbookMatchesActivity = ControlCheck.NOT_APPLICABLE, + logbookMatchesActivity = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NOT_APPLICABLE, longitude = -0.56, missionId = 34, numberOfVesselsFlownOver = null, @@ -223,7 +241,7 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { segments = listOf(), seizureAndDiversion = false, seizureAndDiversionComments = null, - separateStowageOfPreservedSpecies = ControlCheck.NO, + separateStowageOfPreservedSpecies = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NO, speciesInfractions = listOf(), speciesObservations = null, speciesOnboard = listOf(), @@ -233,7 +251,7 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { userTrigram = "JKL", vesselId = 1, vesselName = "PHENOMENE", - vesselTargeted = ControlCheck.YES, + vesselTargeted = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.YES, isDeleted = false, hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt index 3b12e815a5..c9d73b2853 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt @@ -1,52 +1,65 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.repositories -import fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.* +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import java.time.ZonedDateTime object TestUtils { - fun getDummyMissionAction(dateTime: ZonedDateTime, id: Int? = null) = MissionAction( - id = id, - actionDatetimeUtc = dateTime, - missionId = 2, - vesselId = 2, - internalReferenceNumber = "FR0564654", - externalReferenceNumber = "FDEY874", - ircs = "FDZFEE", - flagState = "FR", - actionType = MissionActionType.SEA_CONTROL, - flightGoals = listOf(FlightGoal.CLOSED_AREA, FlightGoal.UNAUTHORIZED_FISHING), - emitsVms = ControlCheck.YES, - emitsAis = ControlCheck.NOT_APPLICABLE, - logbookMatchesActivity = ControlCheck.NO, - speciesWeightControlled = true, - speciesSizeControlled = true, - separateStowageOfPreservedSpecies = ControlCheck.YES, - logbookInfractions = listOf( - LogbookInfraction( - InfractionType.WITH_RECORD, - 27689, - "Poids à bord MNZ supérieur de 50% au poids déclaré", + fun getDummyMissionAction(dateTime: ZonedDateTime, id: Int? = null) = + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( + id = id, + actionDatetimeUtc = dateTime, + missionId = 2, + vesselId = 2, + internalReferenceNumber = "FR0564654", + externalReferenceNumber = "FDEY874", + ircs = "FDZFEE", + flagState = "FR", + actionType = MissionActionType.SEA_CONTROL, + flightGoals = listOf( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FlightGoal.CLOSED_AREA, + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FlightGoal.UNAUTHORIZED_FISHING, ), - ), - faoAreas = listOf("25.6.9", "25.7.9"), - segments = listOf( - FleetSegment(segment = "WWSS10", segmentName = "World Wide Segment"), - ), - gearInfractions = listOf(GearInfraction(InfractionType.WITH_RECORD, 27689, "Maille trop petite")), - controlQualityComments = "Ciblage CNSP respecté", - feedbackSheetRequired = true, - userTrigram = "DEF", - facade = "NAMO", - longitude = -6.56, - latitude = 45.12, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - closedBy = "XYZ", - isFromPoseidon = true, - isAdministrativeControl = true, - isComplianceWithWaterRegulationsControl = true, - isSafetyEquipmentAndStandardsComplianceControl = true, - isSeafarersControl = true, - ) + emitsVms = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.YES, + emitsAis = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NOT_APPLICABLE, + logbookMatchesActivity = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NO, + speciesWeightControlled = true, + speciesSizeControlled = true, + separateStowageOfPreservedSpecies = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.YES, + logbookInfractions = listOf( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.LogbookInfraction( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + 27689, + "Poids à bord MNZ supérieur de 50% au poids déclaré", + ), + ), + faoAreas = listOf("25.6.9", "25.7.9"), + segments = listOf( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FleetSegment( + segment = "WWSS10", + segmentName = "World Wide Segment", + ), + ), + gearInfractions = listOf( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearInfraction( + fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + 27689, + "Maille trop petite", + ), + ), + controlQualityComments = "Ciblage CNSP respecté", + feedbackSheetRequired = true, + userTrigram = "DEF", + facade = "NAMO", + longitude = -6.56, + latitude = 45.12, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + closedBy = "XYZ", + isFromPoseidon = true, + isAdministrativeControl = true, + isComplianceWithWaterRegulationsControl = true, + isSafetyEquipmentAndStandardsComplianceControl = true, + isSeafarersControl = true, + ) } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt index 4e7b25f927..287929d02c 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt @@ -3,6 +3,8 @@ package fr.gouv.cnsp.monitorfish.infrastructure.monitorenv import fr.gouv.cnsp.monitorfish.config.ApiClient import fr.gouv.cnsp.monitorfish.config.MonitorenvProperties import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.MissionActionType +import fr.gouv.cnsp.monitorfish.infrastructure.monitorenv.TestUtils.Companion.getDummyMission import fr.gouv.cnsp.monitorfish.infrastructure.monitorenv.TestUtils.Companion.getDummyMissions import io.ktor.client.engine.mock.* import io.ktor.http.* @@ -286,4 +288,34 @@ class APIMissionRepositoryITest { ) } } + + @Test + fun `findById Should return a mission`() { + runBlocking { + // Given + val mockEngine = MockEngine { _ -> + respond( + content = ByteReadChannel(getDummyMission()), + status = HttpStatusCode.OK, + headers = headersOf(HttpHeaders.ContentType, "application/json"), + ) + } + val apiClient = ApiClient(mockEngine) + val monitorenvProperties = MonitorenvProperties() + monitorenvProperties.url = "http://test" + + // When + val mission = APIMissionRepository(monitorenvProperties, apiClient) + .findById(123) + + // Then + assertThat(mission.createdAtUtc.toString()).isEqualTo("2023-04-20T09:57Z") + assertThat(mission.envActions).hasSize(2) + assertThat(mission.envActions?.first()?.actionType).isEqualTo(MissionActionType.CONTROL) + assertThat(mockEngine.requestHistory.first().url.toString()) + .isEqualTo( + "http://test/api/v1/missions/123", + ) + } + } } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt index 53236a6cee..4c395be8a6 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt @@ -2,6 +2,47 @@ package fr.gouv.cnsp.monitorfish.infrastructure.monitorenv class TestUtils { companion object { + fun getDummyMission(): String { + return """ + { + "id":263, + "missionTypes":["SEA"], + "controlUnits":[{"id":10197, + "administration":"Marine Nationale", + "isArchived":false, + "name":"BE Jaguar", + "resources":[], + "contact":null}], + "openBy":null, + "closedBy":null, + "observationsCacem":null, + "observationsCnsp":null, + "facade":"NAMO", + "geom":{"type":"MultiPolygon","coordinates":[[[[-3.50814078, 48.92061516],[-3.48954745,48.84160728],[-3.40230182,48.80959241],[-3.28073004,48.85384285],[-3.25212491,48.90557567],[-3.50814078,48.92061516]]]]}, + "createdAtUtc":"2023-04-20T09:57:00Z", + "updatedAtUtc":"2023-04-20T09:57:00Z", + "startDateTimeUtc":"2023-04-20T09:57:00Z", + "startDateTimeUtc":"2023-04-20T09:57:00Z", + "endDateTimeUtc":"2023-04-21T10:57:59Z", + "envActions":[ + { + "id": "123", + "actionStartDateTimeUtc": "2023-04-21T10:57:59Z", + "actionType": "CONTROL" + }, + { + "id": "124", + "actionStartDateTimeUtc": "2023-04-21T10:57:59Z", + "actionType": "NOTE" + } + ], + "isGeometryComputedFromControls":false, + "missionSource":"MONITORFISH", + "isClosed":false + } + """.trimIndent() + } + fun getDummyMissions(): String { return """ [{ @@ -19,9 +60,23 @@ class TestUtils { "observationsCnsp":null, "facade":"NAMO", "geom":{"type":"MultiPolygon","coordinates":[[[[-3.50814078, 48.92061516],[-3.48954745,48.84160728],[-3.40230182,48.80959241],[-3.28073004,48.85384285],[-3.25212491,48.90557567],[-3.50814078,48.92061516]]]]}, + "createdAtUtc":"2023-04-20T09:57:00Z", + "updatedAtUtc":"2023-04-20T09:57:00Z", + "startDateTimeUtc":"2023-04-20T09:57:00Z", "startDateTimeUtc":"2023-04-20T09:57:00Z", "endDateTimeUtc":"2023-04-21T10:57:59Z", - "envActions":[], + "envActions":[ + { + "id": 123, + "actionStartDateTimeUtc": "2023-04-21T10:57:59Z", + "actionType": "CONTROL", + }, + { + "id": 124, + "actionStartDateTimeUtc": "2023-04-21T10:57:59Z", + "actionType": "NOTE", + } + ], "isGeometryComputedFromControls":false, "missionSource":"MONITORFISH", "isClosed":false diff --git a/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts b/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts index 8bded33b7e..6ea7185d1b 100644 --- a/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts +++ b/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts @@ -40,7 +40,7 @@ context('Side Window > Mission Form > Main Form', () => { }, statusCode: 201 }).as('createMission') - cy.intercept('GET', '/api/v1/missions/1', { + cy.intercept('GET', '/bff/v1/missions/1', { body: { envActions: [], id: 1 @@ -99,7 +99,7 @@ context('Side Window > Mission Form > Main Form', () => { }, () => { openSideWindowNewMission() - cy.intercept('GET', '/api/v1/missions/1', { + cy.intercept('GET', '/bff/v1/missions/1', { body: { envActions: [], id: 1 @@ -172,7 +172,7 @@ context('Side Window > Mission Form > Main Form', () => { it('Should send the expected data to the API when creating a new mission', () => { openSideWindowNewMission() - cy.intercept('GET', '/api/v1/missions/1', { + cy.intercept('GET', '/bff/v1/missions/1', { body: { envActions: [], id: 1 diff --git a/frontend/src/domain/entities/mission/index.ts b/frontend/src/domain/entities/mission/index.ts index 4e6ff68317..1e49e4eaa3 100644 --- a/frontend/src/domain/entities/mission/index.ts +++ b/frontend/src/domain/entities/mission/index.ts @@ -19,7 +19,6 @@ import { MonitorFishLayer } from '../layers/types' import { OpenLayersGeometryType } from '../map/constants' import type { MissionActionFormValues, MissionMainFormValues } from '@features/Mission/components/MissionForm/types' -import type { MissionWithActions } from '@features/Mission/mission.types' import type { MultiPolygon } from 'ol/geom' import MissionStatus = Mission.MissionStatus @@ -31,7 +30,10 @@ export function getMissionFeaturePointId(id: number) { return `${MonitorFishLayer.MISSION_PIN_POINT}:${id}` } -export const getMissionFeaturePoint = ({ actions, ...mission }: MissionWithActions): Feature | undefined => { +export const getMissionFeaturePoint = ({ + actions, + ...mission +}: Mission.MissionWithActions): Feature | undefined => { const geoJSON = new GeoJSON() if (!mission.geom?.coordinates.length) { diff --git a/frontend/src/features/Mission/components/MissionForm/ActionList/index.tsx b/frontend/src/features/Mission/components/MissionForm/ActionList/index.tsx index 75519751da..9a12bd96f5 100644 --- a/frontend/src/features/Mission/components/MissionForm/ActionList/index.tsx +++ b/frontend/src/features/Mission/components/MissionForm/ActionList/index.tsx @@ -3,7 +3,7 @@ import { EnvActionCard } from '@features/Mission/components/MissionForm/ActionLi import { EnvMissionAction } from '@features/Mission/envMissionAction.types' import { Mission } from '@features/Mission/mission.types' import { MissionAction } from '@features/Mission/missionAction.types' -import { useGetMissionQuery } from '@features/Mission/monitorenvMissionApi' +import { useGetMissionQuery } from '@features/Mission/monitorfishMissionApi' import { Dropdown, Icon } from '@mtes-mct/monitor-ui' import { skipToken } from '@reduxjs/toolkit/dist/query' import { useMemo } from 'react' diff --git a/frontend/src/features/Mission/components/MissionForm/hooks/useGetMainFormFormikUsecases.ts b/frontend/src/features/Mission/components/MissionForm/hooks/useGetMainFormFormikUsecases.ts index b84cb835f3..c511f86897 100644 --- a/frontend/src/features/Mission/components/MissionForm/hooks/useGetMainFormFormikUsecases.ts +++ b/frontend/src/features/Mission/components/MissionForm/hooks/useGetMainFormFormikUsecases.ts @@ -1,5 +1,5 @@ import { useGetPortsQuery } from '@api/port' -import { useGetMissionQuery } from '@features/Mission/monitorenvMissionApi' +import { useGetMissionQuery } from '@features/Mission/monitorfishMissionApi' import { isAirOrSeaControl, isLandControl } from '@features/Mission/useCases/getLastControlCircleGeometry' import { useMainAppDispatch } from '@hooks/useMainAppDispatch' import { useMainAppSelector } from '@hooks/useMainAppSelector' diff --git a/frontend/src/features/Mission/components/MissionForm/hooks/useGetMissionActionFormikUsecases.ts b/frontend/src/features/Mission/components/MissionForm/hooks/useGetMissionActionFormikUsecases.ts index 730b5a12f7..f33870f7fc 100644 --- a/frontend/src/features/Mission/components/MissionForm/hooks/useGetMissionActionFormikUsecases.ts +++ b/frontend/src/features/Mission/components/MissionForm/hooks/useGetMissionActionFormikUsecases.ts @@ -1,7 +1,7 @@ import { useGetPortsQuery } from '@api/port' import { useGetFleetSegmentsQuery } from '@features/FleetSegment/apis' import { MissionAction } from '@features/Mission/missionAction.types' -import { useGetMissionQuery } from '@features/Mission/monitorenvMissionApi' +import { useGetMissionQuery } from '@features/Mission/monitorfishMissionApi' import { useMainAppDispatch } from '@hooks/useMainAppDispatch' import { useMainAppSelector } from '@hooks/useMainAppSelector' import { skipToken } from '@reduxjs/toolkit/query' diff --git a/frontend/src/features/Mission/components/MissionForm/utils/getMissionFormInitialValues.ts b/frontend/src/features/Mission/components/MissionForm/utils/getMissionFormInitialValues.ts index cbbfddd136..7f1be86c35 100644 --- a/frontend/src/features/Mission/components/MissionForm/utils/getMissionFormInitialValues.ts +++ b/frontend/src/features/Mission/components/MissionForm/utils/getMissionFormInitialValues.ts @@ -1,10 +1,10 @@ -import { type MissionWithActions } from '@features/Mission/mission.types' +import { Mission } from '@features/Mission/mission.types' import { validateMissionForms } from './validateMissionForms' import type { MissionActionFormValues, MissionMainFormValues } from '../types' -export function getMissionDraftFromMissionWithActions(missionWithActions: MissionWithActions): { +export function getMissionDraftFromMissionWithActions(missionWithActions: Mission.MissionWithActions): { actionsFormValues: MissionActionFormValues[] mainFormValues: MissionMainFormValues } { diff --git a/frontend/src/features/Mission/components/MissionList/constants.ts b/frontend/src/features/Mission/components/MissionList/constants.ts index 3fa14525f5..d8f1deb154 100644 --- a/frontend/src/features/Mission/components/MissionList/constants.ts +++ b/frontend/src/features/Mission/components/MissionList/constants.ts @@ -8,7 +8,6 @@ import { UNKNOWN_VESSEL } from '../../../../domain/entities/vessel/vessel' import { Mission } from '../../mission.types' import { MissionAction } from '../../missionAction.types' -import type { MissionWithActions } from '../../mission.types' import type { TableOptions } from '@hooks/useTable/types' import type { Option } from '@mtes-mct/monitor-ui' @@ -40,7 +39,7 @@ const MISSION_ACTION_CONTROL_TYPES = [ MissionAction.MissionActionType.SEA_CONTROL ] -export const MISSION_LIST_TABLE_OPTIONS: TableOptions = { +export const MISSION_LIST_TABLE_OPTIONS: TableOptions = { columns: [ { fixedWidth: 136, diff --git a/frontend/src/features/Mission/components/MissionList/hooks/useGetFilteredMissionsQuery.ts b/frontend/src/features/Mission/components/MissionList/hooks/useGetFilteredMissionsQuery.ts index e737f0d4c5..432751a4e8 100644 --- a/frontend/src/features/Mission/components/MissionList/hooks/useGetFilteredMissionsQuery.ts +++ b/frontend/src/features/Mission/components/MissionList/hooks/useGetFilteredMissionsQuery.ts @@ -1,3 +1,4 @@ +import { Mission } from '@features/Mission/mission.types' import { customDayjs } from '@mtes-mct/monitor-ui' import { useMemo } from 'react' @@ -9,15 +10,13 @@ import { useMainAppSelector } from '../../../../../hooks/useMainAppSelector' import { useGetMissionsQuery } from '../../../monitorfishMissionApi' import { MissionDateRangeFilter, MissionFilterType } from '../types' -import type { MissionWithActions } from '../../../mission.types' - const TWO_MINUTES = 2 * 60 * 1000 export const useGetFilteredMissionsQuery = (): { isError: boolean isLoading: boolean - missions: MissionWithActions[] - missionsSeaFrontFiltered: MissionWithActions[] + missions: Mission.MissionWithActions[] + missionsSeaFrontFiltered: Mission.MissionWithActions[] } => { const listFilterValues = useMainAppSelector(state => state.missionList.listFilterValues) const listSeaFront = useMainAppSelector(state => state.missionList.listSeaFront) @@ -85,7 +84,7 @@ export const useGetFilteredMissionsQuery = (): { { pollingInterval: TWO_MINUTES } ) - const missions: MissionWithActions[] = useMemo(() => { + const missions: Mission.MissionWithActions[] = useMemo(() => { if (!data) { return [] } @@ -98,7 +97,7 @@ export const useGetFilteredMissionsQuery = (): { ) }, [data, listFilterValues]) - const missionsSeaFrontFiltered: MissionWithActions[] = useMemo(() => { + const missionsSeaFrontFiltered: Mission.MissionWithActions[] = useMemo(() => { if (!missions) { return [] } diff --git a/frontend/src/features/Mission/components/MissionList/index.tsx b/frontend/src/features/Mission/components/MissionList/index.tsx index 09e1e14608..6080add731 100644 --- a/frontend/src/features/Mission/components/MissionList/index.tsx +++ b/frontend/src/features/Mission/components/MissionList/index.tsx @@ -17,11 +17,11 @@ import { EmptyCardTable } from '../../../../ui/card-table/EmptyCardTable' import { NoRsuiteOverrideWrapper } from '../../../../ui/NoRsuiteOverrideWrapper' import { ExportActivityReportsDialog } from '../../../ActivityReport/components/ExportActivityReportsDialog' import { SubMenu } from '../../../SideWindow/SubMenu' +import { Mission } from '../../mission.types' import { addMission } from '../../useCases/addMission' import { editMission } from '../../useCases/editMission' import type { GeoJSON as GeoJSONType } from '../../../../domain/types/GeoJSON' -import type { Mission, MissionWithActions } from '../../mission.types' export function MissionList() { const listSeaFront = useMainAppSelector(store => store.missionList.listSeaFront) @@ -35,7 +35,7 @@ export function MissionList() { const { isError, isLoading, missions, missionsSeaFrontFiltered } = useGetFilteredMissionsQuery() - const { renderTableHead, tableData } = useTable( + const { renderTableHead, tableData } = useTable( missionsSeaFrontFiltered, MISSION_LIST_TABLE_OPTIONS, [], diff --git a/frontend/src/features/Mission/components/MissionList/utils.tsx b/frontend/src/features/Mission/components/MissionList/utils.tsx index 2b36a12eb5..29416609ed 100644 --- a/frontend/src/features/Mission/components/MissionList/utils.tsx +++ b/frontend/src/features/Mission/components/MissionList/utils.tsx @@ -4,7 +4,7 @@ import { uniq } from 'lodash/fp' import styled from 'styled-components' import { getMissionColor } from '../../layers/MissionLayer/styles' -import { Mission, type MissionWithActions } from '../../mission.types' +import { Mission } from '../../mission.types' import type { LegacyControlUnit } from '../../../../domain/types/legacyControlUnit' @@ -21,7 +21,7 @@ export function getControlUnitsNamesFromAdministrations( return uniqueSortedNames } -export function hasSomeOngoingActions(mission: MissionWithActions): boolean { +export function hasSomeOngoingActions(mission: Mission.MissionWithActions): boolean { return !mission.isClosed && mission.actions.filter(({ closedBy }) => !closedBy).length > 0 } diff --git a/frontend/src/features/Mission/mission.types.ts b/frontend/src/features/Mission/mission.types.ts index 7ae0dc8436..8474b5807c 100644 --- a/frontend/src/features/Mission/mission.types.ts +++ b/frontend/src/features/Mission/mission.types.ts @@ -127,8 +127,8 @@ export namespace Mission { numberOfInfractionsWithRecords: number vesselName: string | undefined } -} -export interface MissionWithActions extends Mission.Mission { - actions: MissionAction.MissionAction[] + export interface MissionWithActions extends Mission { + actions: MissionAction.MissionAction[] + } } diff --git a/frontend/src/features/Mission/monitorenvMissionApi.ts b/frontend/src/features/Mission/monitorenvMissionApi.ts index 06843b610b..3132147823 100644 --- a/frontend/src/features/Mission/monitorenvMissionApi.ts +++ b/frontend/src/features/Mission/monitorenvMissionApi.ts @@ -7,7 +7,6 @@ import { ControlUnit } from '@mtes-mct/monitor-ui' const CREATE_MISSION_ERROR_MESSAGE = "Nous n'avons pas pu créer la mission." const DELETE_MISSION_ERROR_MESSAGE = "Nous n'avons pas pu supprimer la mission." -const GET_MISSION_ERROR_MESSAGE = "Nous n'avons pas pu récupérer la mission." const GET_ENGAGED_CONTROL_UNITS_ERROR_MESSAGE = "Nous n'avons pas pu récupérer les unités en mission." const UPDATE_MISSION_ERROR_MESSAGE = "Nous n'avons pas pu mettre à jour la mission." const CAN_DELETE_MISSION_ERROR_MESSAGE = "Nous n'avons pas pu vérifier si cette mission est supprimable." @@ -53,12 +52,6 @@ export const monitorenvMissionApi = monitorenvApi.injectEndpoints({ transformErrorResponse: response => new FrontendApiError(GET_ENGAGED_CONTROL_UNITS_ERROR_MESSAGE, response) }), - getMission: builder.query({ - keepUnusedDataFor: 0, - query: id => `/v1/missions/${id}`, - transformErrorResponse: response => new FrontendApiError(GET_MISSION_ERROR_MESSAGE, response) - }), - updateMission: builder.mutation({ query: mission => ({ body: mission, @@ -74,6 +67,5 @@ export const { useCreateMissionMutation, useDeleteMissionMutation, useGetEngagedControlUnitsQuery, - useGetMissionQuery, useUpdateMissionMutation } = monitorenvMissionApi diff --git a/frontend/src/features/Mission/monitorfishMissionApi.ts b/frontend/src/features/Mission/monitorfishMissionApi.ts index e7e4e6111d..b8fce28925 100644 --- a/frontend/src/features/Mission/monitorfishMissionApi.ts +++ b/frontend/src/features/Mission/monitorfishMissionApi.ts @@ -1,6 +1,9 @@ +import { FrontendApiError } from '@libs/FrontendApiError' + +import { Mission } from './mission.types' import { monitorfishApi } from '../../api/api' -import type { MissionWithActions } from './mission.types' +const GET_MISSION_ERROR_MESSAGE = "Nous n'avons pas pu récupérer la mission." type GetMissionsFilter = { missionSource?: string @@ -31,7 +34,13 @@ enum MonitorenvStatusMapping { export const monitorfishMissionApi = monitorfishApi.injectEndpoints({ endpoints: builder => ({ - getMissions: builder.query({ + getMission: builder.query({ + keepUnusedDataFor: 0, + query: id => `/missions/${id}`, + transformErrorResponse: response => new FrontendApiError(GET_MISSION_ERROR_MESSAGE, response) + }), + + getMissions: builder.query({ providesTags: [{ type: 'Missions' }], query: (filter: GetMissionsFilter) => [ @@ -49,4 +58,4 @@ export const monitorfishMissionApi = monitorfishApi.injectEndpoints({ }) }) -export const { useGetMissionsQuery } = monitorfishMissionApi +export const { useGetMissionQuery, useGetMissionsQuery } = monitorfishMissionApi diff --git a/frontend/src/features/Mission/useCases/deleteMissionAction.ts b/frontend/src/features/Mission/useCases/deleteMissionAction.ts index 2850b034f3..bbb958be4d 100644 --- a/frontend/src/features/Mission/useCases/deleteMissionAction.ts +++ b/frontend/src/features/Mission/useCases/deleteMissionAction.ts @@ -2,7 +2,7 @@ import { missionActionApi } from '@api/missionAction' import { portApi } from '@api/port' import { formikUsecase } from '@features/Mission/components/MissionForm/formikUsecases' import { missionFormActions } from '@features/Mission/components/MissionForm/slice' -import { monitorenvMissionApi } from '@features/Mission/monitorenvMissionApi' +import { monitorfishMissionApi } from '@features/Mission/monitorfishMissionApi' import { MissionAction } from '../missionAction.types' @@ -66,7 +66,7 @@ async function getEnvActions(dispatch, missionId: number | undefined) { return [] } - const { data: mission } = await dispatch(monitorenvMissionApi.endpoints.getMission.initiate(missionId)) + const { data: mission } = await dispatch(monitorfishMissionApi.endpoints.getMission.initiate(missionId)) return mission?.envActions ?? [] } diff --git a/frontend/src/features/Mission/useCases/editMission.ts b/frontend/src/features/Mission/useCases/editMission.ts index 2f6d7ad7fd..0b02f909df 100644 --- a/frontend/src/features/Mission/useCases/editMission.ts +++ b/frontend/src/features/Mission/useCases/editMission.ts @@ -1,10 +1,11 @@ +import { RTK_FORCE_REFETCH_QUERY_OPTIONS } from '@api/constants' +import { monitorfishMissionApi } from '@features/Mission/monitorfishMissionApi' import { DisplayedErrorKey } from '@libs/DisplayedError/constants' import { SideWindowMenuKey, SideWindowStatus } from 'domain/entities/sideWindow/constants' import { displayedErrorActions } from 'domain/shared_slices/DisplayedError' import { sideWindowActions } from 'domain/shared_slices/SideWindow' import { displayOrLogError } from 'domain/use_cases/error/displayOrLogError' -import { getMissionWithActions } from './getMissionWithActions' import { FrontendApiError } from '../../../libs/FrontendApiError' import { handleThunkError } from '../../../utils/handleThunkError' import { askForSideWindowDraftCancellationConfirmation } from '../../SideWindow/useCases/askForSideWindowDraftCancellationConfirmation' @@ -42,7 +43,9 @@ const editMissionWithoutConfirmation = try { dispatch(missionFormActions.reset()) - const missionWithActions = await dispatch(getMissionWithActions(id)) + const missionWithActions = await dispatch( + monitorfishMissionApi.endpoints.getMission.initiate(id, RTK_FORCE_REFETCH_QUERY_OPTIONS) + ).unwrap() const nextDraft = getMissionDraftFromMissionWithActions(missionWithActions) dispatch(missionFormActions.initializeDraft(nextDraft)) diff --git a/frontend/src/features/Mission/useCases/getMissionWithActions.ts b/frontend/src/features/Mission/useCases/getMissionWithActions.ts deleted file mode 100644 index 219d36c445..0000000000 --- a/frontend/src/features/Mission/useCases/getMissionWithActions.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { RTK_FORCE_REFETCH_QUERY_OPTIONS } from '@api/constants' -import { missionActionApi } from '@api/missionAction' - -import { monitorenvMissionApi } from '../monitorenvMissionApi' - -import type { MissionWithActions } from '@features/Mission/mission.types' -import type { MainAppThunk } from '@store' - -export const getMissionWithActions = - (id: number): MainAppThunk> => - async dispatch => { - const mission = await dispatch( - monitorenvMissionApi.endpoints.getMission.initiate(id, RTK_FORCE_REFETCH_QUERY_OPTIONS) - ).unwrap() - const actions = await dispatch( - missionActionApi.endpoints.getMissionActions.initiate(id, RTK_FORCE_REFETCH_QUERY_OPTIONS) - ).unwrap() - - const missionWithActions: MissionWithActions = { - ...mission, - actions - } - - return missionWithActions - } diff --git a/frontend/src/features/Mission/useCases/saveMissionAndMissionActionsByDiff.ts b/frontend/src/features/Mission/useCases/saveMissionAndMissionActionsByDiff.ts index f89f22dc70..e1d17622fd 100644 --- a/frontend/src/features/Mission/useCases/saveMissionAndMissionActionsByDiff.ts +++ b/frontend/src/features/Mission/useCases/saveMissionAndMissionActionsByDiff.ts @@ -1,7 +1,8 @@ +import { RTK_FORCE_REFETCH_QUERY_OPTIONS } from '@api/constants' import { missionActionApi } from '@api/missionAction' import { missionFormActions } from '@features/Mission/components/MissionForm/slice' import { getMissionActionsDataFromMissionActionsFormValues } from '@features/Mission/components/MissionForm/utils' -import { getMissionWithActions } from '@features/Mission/useCases/getMissionWithActions' +import { monitorfishMissionApi } from '@features/Mission/monitorfishMissionApi' import { saveMission } from '@features/Mission/useCases/saveMission' import { logSoftError } from '@mtes-mct/monitor-ui' import { assertNotNullish } from '@utils/assertNotNullish' @@ -21,7 +22,9 @@ export const saveMissionAndMissionActionsByDiff = assertNotNullish(savedMission.id) - const currentMissionWithActions = await dispatch(getMissionWithActions(savedMission.id)) + const currentMissionWithActions = await dispatch( + monitorfishMissionApi.endpoints.getMission.initiate(savedMission.id, RTK_FORCE_REFETCH_QUERY_OPTIONS) + ).unwrap() const { deletedMissionActionIds, updatedMissionActionDatas } = getMissionActionsDataFromMissionActionsFormValues( savedMission.id, actionsFormValues, From 2b6ca1b8d4faef2a83912e70b84e93b08d1bd6ed Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Tue, 26 Mar 2024 18:18:21 +0100 Subject: [PATCH 3/7] Fix few tests --- .../domain/entities/alerts/PendingAlert.kt | 2 +- .../domain/entities/reporting/Reporting.kt | 2 +- .../mission_actions/DeleteMissionAction.kt | 4 +- .../api/bff/MissionActionsController.kt | 1 - .../use_cases/mission/GetMissionUTests.kt | 4 +- .../api/bff/MissionsControllerITests.kt | 56 ++++++++++++++++++- .../PublicMissionActionsControllerITests.kt | 4 +- .../infrastructure/api/bff/Utils.kt | 6 ++ .../PublicMissionActionsControllerITests.kt | 2 +- .../infrastructure/monitorenv/TestUtils.kt | 15 +++-- 10 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/Utils.kt diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/alerts/PendingAlert.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/alerts/PendingAlert.kt index 41e79284ff..e21294931e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/alerts/PendingAlert.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/alerts/PendingAlert.kt @@ -18,7 +18,7 @@ class PendingAlert( val creationDate: ZonedDateTime, val tripNumber: String? = null, val value: AlertType, - var infraction: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction? = null, + var infraction: Infraction? = null, val latitude: Double? = null, val longitude: Double? = null, ) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt index b499c76abe..bf4c96a49b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt @@ -20,7 +20,7 @@ data class Reporting( val value: ReportingValue, val isArchived: Boolean, val isDeleted: Boolean, - var infraction: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction? = null, + var infraction: Infraction? = null, var underCharter: Boolean? = null, val latitude: Double? = null, val longitude: Double? = null, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionAction.kt index fd32f7a478..b0ce47c778 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionAction.kt @@ -10,9 +10,9 @@ class DeleteMissionAction(private val missionActionsRepository: MissionActionsRe fun execute(actionId: Int) { try { val targetedAction = missionActionsRepository.findById(actionId) - val sofDeletedAction = targetedAction.copy(isDeleted = true) + val softDeletedAction = targetedAction.copy(isDeleted = true) - missionActionsRepository.save(sofDeletedAction) + missionActionsRepository.save(softDeletedAction) } catch (e: Throwable) { throw CouldNotDeleteException("Could not find mission action with id: ${e.message}", e) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt index 6d34c43443..f9f0f5ee08 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt @@ -2,7 +2,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.bff import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.JointDeploymentPlan import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.* -import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.* import fr.gouv.cnsp.monitorfish.infrastructure.api.input.AddMissionActionDataInput import fr.gouv.cnsp.monitorfish.infrastructure.api.outputs.ActivityReportsDataOutput import fr.gouv.cnsp.monitorfish.infrastructure.api.outputs.ControlsSummaryDataOutput diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt index 6d2dd34589..deefe93186 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt @@ -52,7 +52,7 @@ class GetMissionUTests { ), ), ) - given(getMissionActions.execute(any())).willReturn(getDummyMissionActions(listOf(123, 456))) + given(getMissionActions.execute(any())).willReturn(getDummyMissionActions(listOf(1, 2))) // When val missionsAndActions = runBlocking { @@ -64,7 +64,7 @@ class GetMissionUTests { // Then assertThat(missionsAndActions.mission.envActions).hasSize(1) - assertThat(missionsAndActions.actions).hasSize(2) + assertThat(missionsAndActions.actions).hasSize(3) } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt index 559e67619c..bcf1d83666 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt @@ -1,5 +1,6 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.bff +import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.anyOrNull import com.nhaarman.mockitokotlin2.given import fr.gouv.cnsp.monitorfish.config.OIDCProperties @@ -8,6 +9,7 @@ import fr.gouv.cnsp.monitorfish.config.SentryConfig import fr.gouv.cnsp.monitorfish.domain.entities.mission.* import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.GetAllMissions +import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.GetMission import kotlinx.coroutines.runBlocking import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test @@ -33,6 +35,9 @@ class MissionsControllerITests { @MockBean private lateinit var getAllMission: GetAllMissions + @MockBean + private lateinit var getMission: GetMission + @Test fun `Should get all missions`() { // Given @@ -59,7 +64,7 @@ class MissionsControllerITests { startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), ), actions = listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( + MissionAction( id = 3, vesselId = 1, missionId = 123, @@ -111,4 +116,53 @@ class MissionsControllerITests { ) } } + + @Test + fun `Should get a mission`() { + // Given + givenSuspended { + getMission.execute(any()) + }.willReturn( + MissionAndActions( + mission = Mission( + 123, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isClosed = false, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + actions = listOf( + MissionAction( + id = 3, + vesselId = 1, + missionId = 123, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + ), + ), + ), + ) + + // When + api.perform( + get("/bff/v1/missions/123"), + ) + // Then + .andExpect(status().isOk) + .andExpect(jsonPath("$.isGeometryComputedFromControls", equalTo(false))) + .andExpect(jsonPath("$.actions.length()", equalTo(1))) + + runBlocking { + Mockito.verify(getMission).execute( + 123, + ) + } + } } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt index c2ecca7c56..3aceebc58f 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt @@ -7,14 +7,14 @@ import fr.gouv.cnsp.monitorfish.config.OIDCProperties import fr.gouv.cnsp.monitorfish.config.SecurityConfig import fr.gouv.cnsp.monitorfish.config.SentryConfig import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit -import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.ActivityCode import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.JointDeploymentPlan import fr.gouv.cnsp.monitorfish.domain.entities.vessel.Vessel import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.* import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.dtos.ActivityReport import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.mission_actions.dtos.ActivityReports -import fr.gouv.cnsp.monitorfish.domain.use_cases.mission_actions.* import fr.gouv.cnsp.monitorfish.infrastructure.api.input.AddMissionActionDataInput import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.TestUtils import kotlinx.coroutines.runBlocking diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/Utils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/Utils.kt new file mode 100644 index 0000000000..e5d7b8d9c7 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/Utils.kt @@ -0,0 +1,6 @@ +package fr.gouv.cnsp.monitorfish.infrastructure.api.bff + +import kotlinx.coroutines.runBlocking +import org.mockito.BDDMockito + +fun givenSuspended(block: suspend () -> T) = BDDMockito.given(runBlocking { block() })!! diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt index 981c00356d..a9fe719970 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt @@ -39,7 +39,7 @@ class PublicMissionActionsControllerITests { // Given givenSuspended { this.getMissionActions.execute(any()) }.willReturn( listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( + MissionAction( 123, 1, 1, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt index 4c395be8a6..621fa059a8 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt @@ -26,12 +26,12 @@ class TestUtils { "endDateTimeUtc":"2023-04-21T10:57:59Z", "envActions":[ { - "id": "123", + "id": "88713755-3966-4ca4-ae18-10cab6249485", "actionStartDateTimeUtc": "2023-04-21T10:57:59Z", "actionType": "CONTROL" }, { - "id": "124", + "id": "69713755-3966-4ca4-ae18-10cab6249485", "actionStartDateTimeUtc": "2023-04-21T10:57:59Z", "actionType": "NOTE" } @@ -65,16 +65,15 @@ class TestUtils { "startDateTimeUtc":"2023-04-20T09:57:00Z", "startDateTimeUtc":"2023-04-20T09:57:00Z", "endDateTimeUtc":"2023-04-21T10:57:59Z", - "envActions":[ - { - "id": 123, + "envActions":[{ + "id": "88713755-3966-4ca4-ae18-10cab6249485", "actionStartDateTimeUtc": "2023-04-21T10:57:59Z", - "actionType": "CONTROL", + "actionType": "CONTROL" }, { - "id": 124, + "id": "65713755-3966-4ca4-ae18-10cab6249485", "actionStartDateTimeUtc": "2023-04-21T10:57:59Z", - "actionType": "NOTE", + "actionType": "NOTE" } ], "isGeometryComputedFromControls":false, From 727bace3875cb521ec93ec4c1a861d7fb1474244 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Tue, 26 Mar 2024 18:30:20 +0100 Subject: [PATCH 4/7] Remove full package names --- .../env_mission_action/EnvMissionAction.kt | 2 +- ...nActionType.kt => EnvMissionActionType.kt} | 2 +- .../api/input/AddMissionActionDataInput.kt | 24 +++++++------- .../database/entities/InfractionEntity.kt | 4 +-- .../database/entities/MissionActionEntity.kt | 24 +++++++------- .../repositories/JpaInfractionRepository.kt | 4 +-- .../JpaMissionActionsRepository.kt | 12 +++---- .../input/EnvMissionActionDataResponse.kt | 4 +-- .../use_cases/mission/GetMissionUTests.kt | 5 ++- .../PublicMissionActionsControllerITests.kt | 31 +++++++++---------- .../api/bff/VesselControllerITests.kt | 4 +-- .../public_api/InfractionControllerITests.kt | 8 ++--- .../JpaInfractionRepositoryITests.kt | 4 +-- .../JpaMissionActionRepositoryITests.kt | 30 +++++++++--------- .../database/repositories/TestUtils.kt | 24 +++++++------- .../monitorenv/APIMissionRepositoryITest.kt | 4 +-- 16 files changed, 92 insertions(+), 94 deletions(-) rename backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/{MissionActionType.kt => EnvMissionActionType.kt} (74%) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt index 6d44a4ee02..9d40978fca 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt @@ -6,5 +6,5 @@ import java.util.* data class EnvMissionAction( val id: UUID, val actionStartDateTimeUtc: ZonedDateTime, - val actionType: MissionActionType, + val actionType: EnvMissionActionType, ) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/MissionActionType.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionActionType.kt similarity index 74% rename from backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/MissionActionType.kt rename to backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionActionType.kt index d4e70cd338..b54f23627f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/MissionActionType.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionActionType.kt @@ -1,6 +1,6 @@ package fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action -enum class MissionActionType(val value: String) { +enum class EnvMissionActionType(val value: String) { CONTROL("CONTROL"), NOTE("NOTE"), SURVEILLANCE("SURVEILLANCE"), diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt index cccdf7d490..eec2b2a994 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt @@ -13,19 +13,19 @@ data class AddMissionActionDataInput( var flagState: String? = null, var districtCode: String? = null, var faoAreas: List = listOf(), - var flightGoals: List = listOf(), + var flightGoals: List = listOf(), var actionType: MissionActionType, var actionDatetimeUtc: ZonedDateTime, - var emitsVms: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, - var emitsAis: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, - var logbookMatchesActivity: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, - var licencesMatchActivity: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + var emitsVms: ControlCheck? = null, + var emitsAis: ControlCheck? = null, + var logbookMatchesActivity: ControlCheck? = null, + var licencesMatchActivity: ControlCheck? = null, var speciesWeightControlled: Boolean? = null, var speciesSizeControlled: Boolean? = null, - var separateStowageOfPreservedSpecies: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, - var logbookInfractions: List = listOf(), + var separateStowageOfPreservedSpecies: ControlCheck? = null, + var logbookInfractions: List = listOf(), var licencesAndLogbookObservations: String? = null, - var gearInfractions: List = listOf(), + var gearInfractions: List = listOf(), var speciesInfractions: List = listOf(), var speciesObservations: String? = null, var seizureAndDiversion: Boolean? = null, @@ -34,17 +34,17 @@ data class AddMissionActionDataInput( var unitWithoutOmegaGauge: Boolean? = null, var controlQualityComments: String? = null, var feedbackSheetRequired: Boolean? = null, - var segments: List = listOf(), + var segments: List = listOf(), var facade: String? = null, var longitude: Double? = null, var latitude: Double? = null, var portLocode: String? = null, var seizureAndDiversionComments: String? = null, var otherComments: String? = null, - var gearOnboard: List = listOf(), + var gearOnboard: List = listOf(), var userTrigram: String? = null, var speciesOnboard: List = listOf(), - var vesselTargeted: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + var vesselTargeted: ControlCheck? = null, var hasSomeGearsSeized: Boolean = false, var hasSomeSpeciesSeized: Boolean = false, var closedBy: String? = null, @@ -54,7 +54,7 @@ data class AddMissionActionDataInput( var isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null, var isSeafarersControl: Boolean? = null, ) { - fun toMissionAction() = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( + fun toMissionAction() = MissionAction( vesselId = vesselId, vesselName = vesselName, internalReferenceNumber = internalReferenceNumber, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt index 6c2bebe9b2..c844776a74 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt @@ -18,11 +18,11 @@ data class InfractionEntity( var infraction: String? = null, ) { - fun toInfraction() = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction( + fun toInfraction() = Infraction( natinfCode = natinfCode, regulation = regulation, infractionCategory = infractionCategory?.let { category -> - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.values().firstOrNull { + InfractionCategory.entries.firstOrNull { it.value == category } }, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt index fda163498b..771a0dfc15 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt @@ -48,23 +48,23 @@ class MissionActionEntity( val actionDatetimeUtc: Instant, @Column(name = "emits_vms") @Enumerated(EnumType.STRING) - val emitsVms: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + val emitsVms: ControlCheck? = null, @Column(name = "emits_ais") @Enumerated(EnumType.STRING) - val emitsAis: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + val emitsAis: ControlCheck? = null, @Column(name = "logbook_matches_activity") @Enumerated(EnumType.STRING) - val logbookMatchesActivity: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + val logbookMatchesActivity: ControlCheck? = null, @Column(name = "licences_match_activity") @Enumerated(EnumType.STRING) - val licencesMatchActivity: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + val licencesMatchActivity: ControlCheck? = null, @Column(name = "species_weight_controlled") val speciesWeightControlled: Boolean? = null, @Column(name = "species_size_controlled") val speciesSizeControlled: Boolean? = null, @Column(name = "separate_stowage_of_preserved_species") @Enumerated(EnumType.STRING) - val separateStowageOfPreservedSpecies: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + val separateStowageOfPreservedSpecies: ControlCheck? = null, @Type(JsonBinaryType::class) @Column(name = "logbook_infractions", columnDefinition = "jsonb") val logbookInfractions: String? = null, @@ -108,7 +108,7 @@ class MissionActionEntity( val portLocode: String? = null, @Column(name = "vessel_targeted") @Enumerated(EnumType.STRING) - val vesselTargeted: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck? = null, + val vesselTargeted: ControlCheck? = null, @Column(name = "seizure_and_diversion_comments") val seizureAndDiversionComments: String? = null, @Column(name = "other_comments") @@ -140,7 +140,7 @@ class MissionActionEntity( companion object { fun fromMissionAction( mapper: ObjectMapper, - missionAction: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction, + missionAction: MissionAction, ): MissionActionEntity = MissionActionEntity( id = missionAction.id, @@ -198,7 +198,7 @@ class MissionActionEntity( } fun toMissionAction(mapper: ObjectMapper) = - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( + MissionAction( id = id, missionId = missionId, vesselId = vesselId, @@ -226,13 +226,13 @@ class MissionActionEntity( logbookInfractions = deserializeJSONList( mapper, logbookInfractions, - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.LogbookInfraction::class.java, + LogbookInfraction::class.java, ), licencesAndLogbookObservations = licencesAndLogbookObservations, gearInfractions = deserializeJSONList( mapper, gearInfractions, - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearInfraction::class.java, + GearInfraction::class.java, ), speciesInfractions = deserializeJSONList(mapper, speciesInfractions, SpeciesInfraction::class.java), speciesObservations = speciesObservations, @@ -246,7 +246,7 @@ class MissionActionEntity( segments = deserializeJSONList( mapper, segments, - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FleetSegment::class.java, + FleetSegment::class.java, ), facade = facade?.let { Facade.from(it).toString() }, longitude = longitude, @@ -258,7 +258,7 @@ class MissionActionEntity( gearOnboard = deserializeJSONList( mapper, gearOnboard, - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearControl::class.java, + GearControl::class.java, ), speciesOnboard = deserializeJSONList(mapper, speciesOnboard, SpeciesControl::class.java), isDeleted = isDeleted, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepository.kt index cb2ab29bd7..345293a9b0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepository.kt @@ -11,14 +11,14 @@ import org.springframework.stereotype.Repository @Repository class JpaInfractionRepository(private val dbInfractionRepository: DBInfractionRepository) : InfractionRepository { @Cacheable(value = ["infractions"]) - override fun findAll(): List { + override fun findAll(): List { return dbInfractionRepository.findAll().map { it.toInfraction() } } @Cacheable(value = ["infraction"]) - override fun findInfractionByNatinfCode(natinfCode: Int): fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction { + override fun findInfractionByNatinfCode(natinfCode: Int): Infraction { return try { dbInfractionRepository.findByNatinfCodeEquals(natinfCode).toInfraction() } catch (e: EmptyResultDataAccessException) { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt index 6cb5878d20..50c6ae9bcc 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt @@ -18,14 +18,14 @@ class JpaMissionActionsRepository( override fun findVesselMissionActionsAfterDateTime( vesselId: Int, afterDateTime: ZonedDateTime, - ): List { + ): List { return dbMissionActionsRepository.findAllByVesselIdEqualsAndActionDatetimeUtcAfterAndIsDeletedIsFalse( vesselId, afterDateTime.toInstant(), ).map { control -> control.toMissionAction(mapper) } } - override fun findByMissionId(missionId: Int): List { + override fun findByMissionId(missionId: Int): List { return dbMissionActionsRepository.findAllByMissionIdAndIsDeletedIsFalse(missionId).map { action -> action.toMissionAction( mapper, @@ -33,7 +33,7 @@ class JpaMissionActionsRepository( } } - override fun findMissionActionsIn(missionIds: List): List { + override fun findMissionActionsIn(missionIds: List): List { return dbMissionActionsRepository.findAllByMissionIdInAndIsDeletedIsFalse(missionIds).map { action -> action.toMissionAction( mapper, @@ -41,16 +41,16 @@ class JpaMissionActionsRepository( } } - override fun save(missionAction: fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction): fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction { + override fun save(missionAction: MissionAction): MissionAction { return dbMissionActionsRepository.save(MissionActionEntity.fromMissionAction(mapper, missionAction)) .toMissionAction(mapper) } - override fun findById(id: Int): fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction { + override fun findById(id: Int): MissionAction { return dbMissionActionsRepository.findById(id).get().toMissionAction(mapper) } - override fun findControlsInDates(beforeDateTime: ZonedDateTime, afterDateTime: ZonedDateTime): List { + override fun findControlsInDates(beforeDateTime: ZonedDateTime, afterDateTime: ZonedDateTime): List { return dbMissionActionsRepository.findAllByActionDatetimeUtcBeforeAndActionDatetimeUtcAfterAndIsDeletedIsFalseAndActionTypeIn( beforeDateTime.toInstant(), afterDateTime.toInstant(), diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt index f22ee2092d..44c9e3c62e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt @@ -1,7 +1,7 @@ package fr.gouv.cnsp.monitorfish.infrastructure.monitorenv.input import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.EnvMissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.EnvMissionActionType import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind @@ -16,7 +16,7 @@ data class EnvMissionActionDataResponse( @Serializable(with = UUIDSerializer::class) val id: UUID, val actionStartDateTimeUtc: String, - val actionType: MissionActionType, + val actionType: EnvMissionActionType, ) { fun toEnvMissionAction() = EnvMissionAction( id = id, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt index deefe93186..25e891b0de 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt @@ -2,12 +2,11 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.mission import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.given -import com.nhaarman.mockitokotlin2.willThrow import fr.gouv.cnsp.monitorfish.domain.entities.mission.Mission import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionSource import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionType import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.EnvMissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.EnvMissionActionType import fr.gouv.cnsp.monitorfish.domain.exceptions.CouldNotFindException import fr.gouv.cnsp.monitorfish.domain.repositories.MissionRepository import fr.gouv.cnsp.monitorfish.domain.use_cases.mission.TestUtils.getDummyMissionActions @@ -47,7 +46,7 @@ class GetMissionUTests { EnvMissionAction( id = UUID.randomUUID(), actionStartDateTimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.CONTROL, + actionType = EnvMissionActionType.CONTROL, ), ), ), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt index 3aceebc58f..32e2610ad2 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt @@ -7,8 +7,7 @@ import fr.gouv.cnsp.monitorfish.config.OIDCProperties import fr.gouv.cnsp.monitorfish.config.SecurityConfig import fr.gouv.cnsp.monitorfish.config.SentryConfig import fr.gouv.cnsp.monitorfish.domain.entities.mission.ControlUnit -import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction -import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.* import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.ActivityCode import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.actrep.JointDeploymentPlan import fr.gouv.cnsp.monitorfish.domain.entities.vessel.Vessel @@ -77,7 +76,7 @@ class PublicMissionActionsControllerITests { 4, 5, listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( + MissionAction( 1, 1, 1, @@ -111,7 +110,7 @@ class PublicMissionActionsControllerITests { // Given givenSuspended { this.getMissionActions.execute(any()) }.willReturn( listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( + MissionAction( 123, 1, 1, @@ -155,22 +154,22 @@ class PublicMissionActionsControllerITests { vesselId = 2, actionType = MissionActionType.SEA_CONTROL, logbookInfractions = listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.LogbookInfraction( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + LogbookInfraction( + InfractionType.WITH_RECORD, 27689, "Poids à bord MNZ supérieur de 50% au poids déclaré", ), ), faoAreas = listOf("25.6.9", "25.7.9"), segments = listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FleetSegment( + FleetSegment( segment = "WWSS10", segmentName = "World Wide Segment", ), ), gearInfractions = listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearInfraction( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + GearInfraction( + InfractionType.WITH_RECORD, 27689, "Maille trop petite", ), @@ -203,7 +202,7 @@ class PublicMissionActionsControllerITests { ), ) - argumentCaptor().apply { + argumentCaptor().apply { verify(addMissionAction).execute(capture()) Assertions.assertThat(allValues[0].actionDatetimeUtc.toString()).isEqualTo("2023-04-27T16:05Z") @@ -217,7 +216,7 @@ class PublicMissionActionsControllerITests { val newMission = TestUtils.getDummyMissionAction(dateTime) given(updateMissionAction.execute(any(), any())).willReturn(newMission) - val gearControl = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearControl() + val gearControl = GearControl() gearControl.declaredMesh = 60.0 gearControl.hasUncontrolledMesh = true gearControl.gearCode = "OTB" @@ -233,22 +232,22 @@ class PublicMissionActionsControllerITests { vesselId = 2, actionType = MissionActionType.SEA_CONTROL, logbookInfractions = listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.LogbookInfraction( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + LogbookInfraction( + InfractionType.WITH_RECORD, 27689, "Poids à bord MNZ supérieur de 50% au poids déclaré", ), ), faoAreas = listOf("25.6.9", "25.7.9"), segments = listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FleetSegment( + FleetSegment( segment = "WWSS10", segmentName = "World Wide Segment", ), ), gearInfractions = listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearInfraction( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + GearInfraction( + InfractionType.WITH_RECORD, 27689, "Maille trop petite", ), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt index 80c53a000f..3918f68039 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt @@ -549,9 +549,9 @@ class VesselControllerITests { value = ThreeMilesTrawlingAlert() as ReportingValue, isArchived = false, isDeleted = false, - infraction = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction( + infraction = Infraction( natinfCode = 7059, - infractionCategory = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.FISHING, + infractionCategory = InfractionCategory.FISHING, ), ), null, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt index 2548f8b12e..50b8603367 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt @@ -33,13 +33,13 @@ class InfractionControllerITests { // Given given(this.getAllInfractions.execute()).willReturn( listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction( + Infraction( natinfCode = 7059, - infractionCategory = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.FISHING, + infractionCategory = InfractionCategory.FISHING, ), - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infraction( + Infraction( natinfCode = 7065, - infractionCategory = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.FISHING, + infractionCategory = InfractionCategory.FISHING, ), ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt index 62649c37da..05c45df805 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt @@ -21,7 +21,7 @@ class JpaInfractionRepositoryITests : AbstractDBTests() { // Then assertThat(infraction.infraction).isEqualTo("Taille de maille non réglementaire") assertThat(infraction.infractionCategory).isEqualTo( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.FISHING, + InfractionCategory.FISHING, ) assertThat(infraction.natinfCode).isEqualTo(23581) assertThat(infraction.regulation).isEqualTo("Arreté du 12/01/3021") @@ -51,7 +51,7 @@ class JpaInfractionRepositoryITests : AbstractDBTests() { assertThat(infractions.first().regulation).isEqualTo("Arreté du 12/01/3021") assertThat(infractions.first().infraction).isEqualTo("Taille de maille non réglementaire") assertThat(infractions.first().infractionCategory).isEqualTo( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionCategory.FISHING, + InfractionCategory.FISHING, ) } } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt index 36a3322588..c00c59a777 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt @@ -49,25 +49,25 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { val firstControl = controls.first() assertThat(firstControl.emitsVms).isEqualTo( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.YES, + ControlCheck.YES, ) assertThat(firstControl.emitsAis).isEqualTo( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NOT_APPLICABLE, + ControlCheck.NOT_APPLICABLE, ) assertThat(firstControl.logbookMatchesActivity).isEqualTo( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NO, + ControlCheck.NO, ) assertThat(firstControl.speciesWeightControlled).isTrue assertThat(firstControl.speciesSizeControlled).isTrue assertThat(firstControl.separateStowageOfPreservedSpecies).isEqualTo( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.YES, + ControlCheck.YES, ) assertThat(firstControl.faoAreas).hasSize(2) assertThat(firstControl.faoAreas.first()).isEqualTo("27.7.d") assertThat(firstControl.faoAreas.last()).isEqualTo("27.7.e") assertThat(firstControl.logbookInfractions).hasSize(1) assertThat(firstControl.logbookInfractions.first().infractionType).isEqualTo( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + InfractionType.WITH_RECORD, ) assertThat(firstControl.logbookInfractions.first().natinf).isEqualTo(27689) assertThat(firstControl.logbookInfractions.first().comments).contains( @@ -78,13 +78,13 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { ) assertThat(firstControl.gearInfractions).hasSize(2) assertThat(firstControl.gearInfractions.first().infractionType).isEqualTo( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + InfractionType.WITH_RECORD, ) assertThat(firstControl.gearInfractions.first().natinf).isEqualTo(23581) assertThat(firstControl.gearInfractions.first().comments).isEqualTo("Maille trop petite") assertThat(firstControl.speciesInfractions).hasSize(1) assertThat(firstControl.speciesInfractions.first().infractionType).isEqualTo( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITHOUT_RECORD, + InfractionType.WITHOUT_RECORD, ) assertThat(firstControl.speciesInfractions.first().natinf).isEqualTo(28346) assertThat(firstControl.speciesInfractions.first().comments).isEqualTo("Sous taille de 8cm") @@ -92,7 +92,7 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { assertThat(firstControl.seizureAndDiversion).isTrue assertThat(firstControl.otherInfractions).hasSize(2) assertThat(firstControl.otherInfractions.first().infractionType).isEqualTo( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + InfractionType.WITH_RECORD, ) assertThat(firstControl.otherInfractions.first().natinf).isEqualTo(23588) assertThat(firstControl.otherInfractions.first().comments).isEqualTo( @@ -111,7 +111,7 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { assertThat(firstControl.latitude).isEqualTo(47.44) assertThat(firstControl.portLocode).isNull() assertThat(firstControl.vesselTargeted).isEqualTo( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NO, + ControlCheck.NO, ) assertThat(firstControl.seizureAndDiversion).isTrue assertThat(firstControl.seizureAndDiversionComments).isEqualTo("Saisie de la pêche") @@ -207,14 +207,14 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { val existingAction = jpaMissionActionsRepository.findById(expectedId) assertThat(existingAction.internalReferenceNumber).isNull() - val actionToUpdate = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( + val actionToUpdate = MissionAction( actionDatetimeUtc = ZonedDateTime.now(), actionType = MissionActionType.SEA_CONTROL, controlQualityComments = null, controlUnits = listOf(), districtCode = null, emitsAis = null, - emitsVms = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NOT_APPLICABLE, + emitsVms = ControlCheck.NOT_APPLICABLE, externalReferenceNumber = "DONTSINK", facade = "Sud Océan Indien", faoAreas = listOf(), @@ -228,9 +228,9 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { ircs = "CALLME", latitude = 49.44, licencesAndLogbookObservations = null, - licencesMatchActivity = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NOT_APPLICABLE, + licencesMatchActivity = ControlCheck.NOT_APPLICABLE, logbookInfractions = listOf(), - logbookMatchesActivity = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NOT_APPLICABLE, + logbookMatchesActivity = ControlCheck.NOT_APPLICABLE, longitude = -0.56, missionId = 34, numberOfVesselsFlownOver = null, @@ -241,7 +241,7 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { segments = listOf(), seizureAndDiversion = false, seizureAndDiversionComments = null, - separateStowageOfPreservedSpecies = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NO, + separateStowageOfPreservedSpecies = ControlCheck.NO, speciesInfractions = listOf(), speciesObservations = null, speciesOnboard = listOf(), @@ -251,7 +251,7 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { userTrigram = "JKL", vesselId = 1, vesselName = "PHENOMENE", - vesselTargeted = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.YES, + vesselTargeted = ControlCheck.YES, isDeleted = false, hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt index c9d73b2853..bf4fe1ec62 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt @@ -5,7 +5,7 @@ import java.time.ZonedDateTime object TestUtils { fun getDummyMissionAction(dateTime: ZonedDateTime, id: Int? = null) = - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.MissionAction( + MissionAction( id = id, actionDatetimeUtc = dateTime, missionId = 2, @@ -16,32 +16,32 @@ object TestUtils { flagState = "FR", actionType = MissionActionType.SEA_CONTROL, flightGoals = listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FlightGoal.CLOSED_AREA, - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FlightGoal.UNAUTHORIZED_FISHING, + FlightGoal.CLOSED_AREA, + FlightGoal.UNAUTHORIZED_FISHING, ), - emitsVms = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.YES, - emitsAis = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NOT_APPLICABLE, - logbookMatchesActivity = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.NO, + emitsVms = ControlCheck.YES, + emitsAis = ControlCheck.NOT_APPLICABLE, + logbookMatchesActivity = ControlCheck.NO, speciesWeightControlled = true, speciesSizeControlled = true, - separateStowageOfPreservedSpecies = fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlCheck.YES, + separateStowageOfPreservedSpecies = ControlCheck.YES, logbookInfractions = listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.LogbookInfraction( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + LogbookInfraction( + InfractionType.WITH_RECORD, 27689, "Poids à bord MNZ supérieur de 50% au poids déclaré", ), ), faoAreas = listOf("25.6.9", "25.7.9"), segments = listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FleetSegment( + FleetSegment( segment = "WWSS10", segmentName = "World Wide Segment", ), ), gearInfractions = listOf( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.GearInfraction( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.InfractionType.WITH_RECORD, + GearInfraction( + InfractionType.WITH_RECORD, 27689, "Maille trop petite", ), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt index 287929d02c..b99cde2d2d 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt @@ -3,7 +3,7 @@ package fr.gouv.cnsp.monitorfish.infrastructure.monitorenv import fr.gouv.cnsp.monitorfish.config.ApiClient import fr.gouv.cnsp.monitorfish.config.MonitorenvProperties import fr.gouv.cnsp.monitorfish.domain.entities.mission.MissionType -import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.MissionActionType +import fr.gouv.cnsp.monitorfish.domain.entities.mission.env_mission_action.EnvMissionActionType import fr.gouv.cnsp.monitorfish.infrastructure.monitorenv.TestUtils.Companion.getDummyMission import fr.gouv.cnsp.monitorfish.infrastructure.monitorenv.TestUtils.Companion.getDummyMissions import io.ktor.client.engine.mock.* @@ -311,7 +311,7 @@ class APIMissionRepositoryITest { // Then assertThat(mission.createdAtUtc.toString()).isEqualTo("2023-04-20T09:57Z") assertThat(mission.envActions).hasSize(2) - assertThat(mission.envActions?.first()?.actionType).isEqualTo(MissionActionType.CONTROL) + assertThat(mission.envActions?.first()?.actionType).isEqualTo(EnvMissionActionType.CONTROL) assertThat(mockEngine.requestHistory.first().url.toString()) .isEqualTo( "http://test/api/v1/missions/123", From 94a6111a48f7c41354d14fd98d99ea0d2c21ebc9 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Tue, 26 Mar 2024 19:07:01 +0100 Subject: [PATCH 5/7] Add cypress test of newer mission action from cacem --- .../mission_form/sea_control_edition.spec.ts | 30 +++++++++++++++++++ .../MainForm/FormikLocationPicker.tsx | 14 +++++---- .../components/MissionForm/formikUsecases.ts | 7 ++++- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/frontend/cypress/e2e/side_window/mission_form/sea_control_edition.spec.ts b/frontend/cypress/e2e/side_window/mission_form/sea_control_edition.spec.ts index 109547801a..ccd81e8be1 100644 --- a/frontend/cypress/e2e/side_window/mission_form/sea_control_edition.spec.ts +++ b/frontend/cypress/e2e/side_window/mission_form/sea_control_edition.spec.ts @@ -1,6 +1,8 @@ import { editSideWindowMission } from './utils' +import { SeaFrontGroup } from '../../../../src/domain/entities/seaFront/constants' import { customDayjs } from '../../utils/customDayjs' import { getUtcDateInMultipleFormats } from '../../utils/getUtcDateInMultipleFormats' +import { editSideWindowMissionListMissionWithId } from '../mission_list/utils' context('Side Window > Mission Form > Sea Control Edition', () => { beforeEach(() => { @@ -263,4 +265,32 @@ context('Side Window > Mission Form > Sea Control Edition', () => { .should('eq', 201) } ) + + it('Should not update the mission zone When a CACEM control is newer', () => { + editSideWindowMissionListMissionWithId(34, SeaFrontGroup.MEMN) + + cy.intercept('POST', '/api/v1/missions/34', { + body: { + id: 1 + }, + statusCode: 201 + }).as('updateMission34') + cy.intercept('PUT', '/bff/v1/mission_actions/9', { + body: { + id: 1 + }, + statusCode: 200 + }) + + cy.get('*[data-cy="action-list-item"]').eq(2).click() + cy.wait(500) + + cy.get('input[placeholder="Rechercher un navire..."]').clear().type('phe') + cy.contains('mark', 'PHE').click() + + cy.get('[aria-label="Supprimer cette zone"]').click() + + cy.wait(250) + cy.get('.Toastify__toast--success').should('not.exist') + }) }) diff --git a/frontend/src/features/Mission/components/MissionForm/MainForm/FormikLocationPicker.tsx b/frontend/src/features/Mission/components/MissionForm/MainForm/FormikLocationPicker.tsx index 1a27b0103d..20fe63bf90 100644 --- a/frontend/src/features/Mission/components/MissionForm/MainForm/FormikLocationPicker.tsx +++ b/frontend/src/features/Mission/components/MissionForm/MainForm/FormikLocationPicker.tsx @@ -117,13 +117,15 @@ export function FormikLocationPicker() { setFieldValue('geom', geometryComputedFromControls) - window.document.dispatchEvent( - new NotificationEvent( - 'Une zone de mission a été modifiée à partir des contrôles de la mission', - 'success', - true + if (geometryComputedFromControls.coordinates?.length) { + window.document.dispatchEvent( + new NotificationEvent( + 'Une zone de mission a été modifiée à partir des contrôles de la mission', + 'success', + true + ) ) - ) + } dispatch(missionFormActions.unsetGeometryComputedFromControls()) }, diff --git a/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts b/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts index ac9d46341e..5f97b853f2 100644 --- a/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts +++ b/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts @@ -154,8 +154,13 @@ const updateMissionLocation = } const lastEnvActionDate = envActions + .filter( + action => + action.actionType === EnvMissionAction.MissionActionType.CONTROL || + action.actionType === EnvMissionAction.MissionActionType.SURVEILLANCE + ) .map(action => action.actionStartDateTimeUtc) - .sort((a, b) => a.localeCompare(b))[0] + .sort((a, b) => b.localeCompare(a))[0] if (lastEnvActionDate && lastEnvActionDate > missionAction.actionDatetimeUtc) { // As a action from Env is newer, we do not update the mission location From ce6cb3af17f1f554ec722107e475eaa93d338a8b Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Wed, 27 Mar 2024 08:40:33 +0100 Subject: [PATCH 6/7] Make cacem action date as nullable --- .../entities/mission/env_mission_action/EnvMissionAction.kt | 2 +- .../monitorenv/input/EnvMissionActionDataResponse.kt | 4 ++-- .../cypress/e2e/side_window/mission_form/main_form.spec.ts | 6 +++--- .../Mission/components/MissionForm/ActionList/index.tsx | 4 ++++ .../Mission/components/MissionForm/formikUsecases.ts | 1 + frontend/src/features/Mission/envMissionAction.types.ts | 4 ++-- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt index 9d40978fca..ac97bc018c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/env_mission_action/EnvMissionAction.kt @@ -5,6 +5,6 @@ import java.util.* data class EnvMissionAction( val id: UUID, - val actionStartDateTimeUtc: ZonedDateTime, + val actionStartDateTimeUtc: ZonedDateTime? = null, val actionType: EnvMissionActionType, ) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt index 44c9e3c62e..47852ccf7d 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt @@ -15,12 +15,12 @@ import java.util.* data class EnvMissionActionDataResponse( @Serializable(with = UUIDSerializer::class) val id: UUID, - val actionStartDateTimeUtc: String, + val actionStartDateTimeUtc: String? = null, val actionType: EnvMissionActionType, ) { fun toEnvMissionAction() = EnvMissionAction( id = id, - actionStartDateTimeUtc = ZonedDateTime.parse(actionStartDateTimeUtc), + actionStartDateTimeUtc = actionStartDateTimeUtc?.let { ZonedDateTime.parse(it) }, actionType = actionType, ) } diff --git a/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts b/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts index 6ea7185d1b..dfb9afb296 100644 --- a/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts +++ b/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts @@ -562,7 +562,7 @@ context('Side Window > Mission Form > Main Form', () => { cy.intercept( { method: 'GET', - path: '/api/v1/missions/6', + path: '/bff/v1/missions/6', times: 1 }, { statusCode: 400 } @@ -570,7 +570,7 @@ context('Side Window > Mission Form > Main Form', () => { cy.intercept( { method: 'GET', - path: '/api/v1/missions/6', + path: '/bff/v1/missions/6', times: 1 }, { statusCode: 400 } @@ -578,7 +578,7 @@ context('Side Window > Mission Form > Main Form', () => { cy.intercept( { method: 'GET', - path: '/api/v1/missions/6', + path: '/bff/v1/missions/6', times: 1 }, { statusCode: 400 } diff --git a/frontend/src/features/Mission/components/MissionForm/ActionList/index.tsx b/frontend/src/features/Mission/components/MissionForm/ActionList/index.tsx index 9a12bd96f5..40aa85c5a2 100644 --- a/frontend/src/features/Mission/components/MissionForm/ActionList/index.tsx +++ b/frontend/src/features/Mission/components/MissionForm/ActionList/index.tsx @@ -62,6 +62,10 @@ export function ActionList({ const dateA = actionA.actionDatetimeUtc const dateB = actionB.actionDatetimeUtc + if (!dateA || !dateB) { + return 1 + } + if (dateA < dateB) { return 1 } diff --git a/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts b/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts index 5f97b853f2..4d42a64df8 100644 --- a/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts +++ b/frontend/src/features/Mission/components/MissionForm/formikUsecases.ts @@ -160,6 +160,7 @@ const updateMissionLocation = action.actionType === EnvMissionAction.MissionActionType.SURVEILLANCE ) .map(action => action.actionStartDateTimeUtc) + .filter((actionStartDateTimeUtc): actionStartDateTimeUtc is string => actionStartDateTimeUtc !== null) .sort((a, b) => b.localeCompare(a))[0] if (lastEnvActionDate && lastEnvActionDate > missionAction.actionDatetimeUtc) { diff --git a/frontend/src/features/Mission/envMissionAction.types.ts b/frontend/src/features/Mission/envMissionAction.types.ts index 0b8fb79062..0e10d8ef30 100644 --- a/frontend/src/features/Mission/envMissionAction.types.ts +++ b/frontend/src/features/Mission/envMissionAction.types.ts @@ -2,7 +2,7 @@ import { Mission } from '@features/Mission/mission.types' export namespace EnvMissionAction { export interface MissionAction { - actionStartDateTimeUtc: string + actionStartDateTimeUtc?: string actionType: MissionActionType id: number } @@ -23,7 +23,7 @@ export namespace EnvMissionAction { } export type MissionActionForTimeline = MissionAction & { - actionDatetimeUtc?: string + actionDatetimeUtc?: string | undefined index?: number source: Mission.MissionSource } From 838cee464e3e0ff3ea0402453a93ee80907706d0 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Wed, 27 Mar 2024 13:59:29 +0100 Subject: [PATCH 7/7] Remove package names --- .../domain/use_cases/infraction/GetAllInfractions.kt | 2 +- .../infrastructure/database/entities/MissionActionEntity.kt | 2 +- .../api/bff/PublicMissionActionsControllerITests.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/infraction/GetAllInfractions.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/infraction/GetAllInfractions.kt index ec417899ff..d90d4e78b2 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/infraction/GetAllInfractions.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/infraction/GetAllInfractions.kt @@ -6,7 +6,7 @@ import fr.gouv.cnsp.monitorfish.domain.repositories.InfractionRepository @UseCase class GetAllInfractions(private val infractionRepository: InfractionRepository) { - fun execute(): List { + fun execute(): List { return infractionRepository.findAll() } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt index 771a0dfc15..7ca65db8e6 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt @@ -210,7 +210,7 @@ class MissionActionEntity( districtCode = districtCode, faoAreas = faoAreas ?: listOf(), flightGoals = flightGoals?.map { - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.FlightGoal.valueOf( + FlightGoal.valueOf( it, ) } ?: listOf(), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt index 32e2610ad2..2c86a1ff2d 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PublicMissionActionsControllerITests.kt @@ -70,7 +70,7 @@ class PublicMissionActionsControllerITests { fun `Should get all controls for a vessel`() { // Given givenSuspended { this.getVesselControls.execute(any(), any()) }.willReturn( - fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.ControlsSummary( + ControlsSummary( 1, 3, 4,