Skip to content

Commit

Permalink
Merge pull request #166 from MTES-MCT/mission-status-def
Browse files Browse the repository at this point in the history
fix(MissionStatus): rework Mission status definition by not using isC…
  • Loading branch information
lwih authored May 30, 2024
2 parents 397e057 + 944cf1b commit 9fc5244
Show file tree
Hide file tree
Showing 16 changed files with 8 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ data class MissionEntity(
val geom: MultiPolygon? = null,
val startDateTimeUtc: ZonedDateTime,
val endDateTimeUtc: ZonedDateTime? = null,
val isClosed: Boolean,
val isDeleted: Boolean,
val isGeometryComputedFromControls: Boolean,
val missionSource: MissionSourceEnum,
Expand Down Expand Up @@ -55,7 +54,6 @@ data class MissionEntity(
geom = envMission.mission.geom,
startDateTimeUtc = envMission.mission.startDateTimeUtc,
endDateTimeUtc = envMission.mission.endDateTimeUtc,
isClosed = envMission.mission.isClosed,
isDeleted = envMission.mission.isDeleted,
isGeometryComputedFromControls = envMission.mission.isGeometryComputedFromControls,
missionSource = envMission.mission.missionSource,
Expand All @@ -70,7 +68,6 @@ data class MissionEntity(
crew = navMission?.crew,
) {
this.status = this.calculateMissionStatus(
isClosed = envMission.mission.isClosed,
startDateTimeUtc = envMission.mission.startDateTimeUtc,
endDateTimeUtc = envMission.mission.endDateTimeUtc,
)
Expand Down Expand Up @@ -101,13 +98,12 @@ data class MissionEntity(
}

private fun calculateMissionStatus(
isClosed: Boolean,
startDateTimeUtc: ZonedDateTime,
endDateTimeUtc: ZonedDateTime? = null,
): MissionStatusEnum {
val compareDate = ZonedDateTime.now()

if (isClosed) {
if (endDateTimeUtc != null && ZonedDateTime.parse(endDateTimeUtc.toString()).isBefore(compareDate)) {
return MissionStatusEnum.ENDED
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ data class MissionEntity(
val startDateTimeUtc: ZonedDateTime,
val endDateTimeUtc: ZonedDateTime? = null,
var envActions: List<EnvActionEntity>? = listOf(),
val isClosed: Boolean,
val isDeleted: Boolean,
val isGeometryComputedFromControls: Boolean,
val missionSource: MissionSourceEnum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ data class Mission(
val id: Int,
val missionTypes: List<MissionType>,
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 startDateTimeUtc: ZonedDateTime,
val endDateTimeUtc: ZonedDateTime? = null,
val missionSource: MissionSource,
val isClosed: Boolean,
val hasMissionOrder: Boolean? = false,
val isUnderJdp: Boolean? = false,
val controlUnits: List<ControlUnit> = listOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class FakeMissionData(
missionSource = MissionSourceEnum.RAPPORTNAV,
startDateTimeUtc = ZonedDateTime.parse("2024-01-09T09:00:00Z"),
endDateTimeUtc = ZonedDateTime.parse("2024-01-09T15:00:00Z"),
isClosed = false,
isDeleted = false,
isGeometryComputedFromControls = false,
hasMissionOrder = false,
Expand All @@ -130,7 +129,6 @@ class FakeMissionData(
missionSource = MissionSourceEnum.RAPPORTNAV,
startDateTimeUtc = ZonedDateTime.parse("2024-01-09T09:00:00Z"),
endDateTimeUtc = ZonedDateTime.parse("2024-01-09T15:00:00Z"),
isClosed = false,
isDeleted = false,
isGeometryComputedFromControls = false,
hasMissionOrder = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class GetEnvMissions(
observationsCacem = null,
startDateTimeUtc = ZonedDateTime.parse("2022-03-15T04:50:09Z"),
// endDateTimeUtc = ZonedDateTime.parse("2022-03-23T20:29:03Z"),
isClosed = true,
isDeleted = false,
missionSource = MissionSourceEnum.RAPPORTNAV,
hasMissionOrder = false,
Expand All @@ -38,7 +37,6 @@ class GetEnvMissions(
observationsCacem = null,
startDateTimeUtc = ZonedDateTime.parse("2022-02-15T04:50:09Z"),
endDateTimeUtc = ZonedDateTime.parse("2022-02-23T20:29:03Z"),
isClosed = true,
isDeleted = false,
missionSource = MissionSourceEnum.MONITORENV,
hasMissionOrder = false,
Expand All @@ -52,7 +50,6 @@ class GetEnvMissions(
observationsCacem = null,
startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"),
endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"),
isClosed = true,
isDeleted = false,
missionSource = MissionSourceEnum.MONITORFISH,
hasMissionOrder = false,
Expand All @@ -66,7 +63,6 @@ class GetEnvMissions(
observationsCacem = null,
startDateTimeUtc = ZonedDateTime.parse("2024-03-11T07:00:00Z"),
endDateTimeUtc = ZonedDateTime.parse("2024-03-22T18:00:00Z"),
isClosed = true,
isDeleted = false,
missionSource = MissionSourceEnum.MONITORFISH,
hasMissionOrder = false,
Expand All @@ -82,7 +78,6 @@ class GetEnvMissions(
observationsCacem = null,
startDateTimeUtc = ZonedDateTime.parse("2026-04-11T07:00:00Z"),
endDateTimeUtc = ZonedDateTime.parse("2026-03-22T18:00:00Z"),
isClosed = false,
isDeleted = false,
missionSource = MissionSourceEnum.RAPPORTNAV,
hasMissionOrder = false,
Expand All @@ -98,7 +93,6 @@ class GetEnvMissions(
observationsCacem = null,
startDateTimeUtc = ZonedDateTime.parse("2024-04-17T07:00:00Z"),
endDateTimeUtc = ZonedDateTime.parse("2026-03-22T18:00:00Z"),
isClosed = false,
isDeleted = false,
missionSource = MissionSourceEnum.MONITORENV,
hasMissionOrder = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import java.time.ZonedDateTime

data class Mission(
val id: Int,
val isClosed: Boolean,
val missionSource: MissionSourceEnum,
val startDateTimeUtc: ZonedDateTime,
val endDateTimeUtc: ZonedDateTime?,
Expand Down Expand Up @@ -43,7 +42,6 @@ data class Mission(

return Mission(
id = mission.id,
isClosed = mission.isClosed,
missionSource = mission.missionSource,
startDateTimeUtc = mission.startDateTimeUtc,
endDateTimeUtc = mission.endDateTimeUtc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ data class MissionDataOutput @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) co
val endDateTimeUtc: ZonedDateTime? = null,
val envActions: List<EnvActionEntity>? = null,
val missionSource: MissionSourceEnum,
val isClosed: Boolean,
val hasMissionOrder: Boolean,
val isUnderJdp: Boolean,
val isGeometryComputedFromControls: Boolean,
Expand All @@ -44,7 +43,6 @@ data class MissionDataOutput @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) co
endDateTimeUtc = endDateTimeUtc,
envActions = envActions,
missionSource = missionSource,
isClosed = isClosed,
hasMissionOrder = hasMissionOrder,
isUnderJdp = isUnderJdp,
isGeometryComputedFromControls = isGeometryComputedFromControls,
Expand All @@ -70,7 +68,6 @@ data class MissionDataOutput @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) co
endDateTimeUtc = mission.endDateTimeUtc,
envActions = mission.envActions,
missionSource = mission.missionSource,
isClosed = mission.isClosed,
hasMissionOrder = mission.hasMissionOrder,
isUnderJdp = mission.isUnderJdp,
isGeometryComputedFromControls = mission.isGeometryComputedFromControls,
Expand Down
1 change: 0 additions & 1 deletion backend/src/main/resources/graphql/mission.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ input MissionInput {

type Mission {
id: ID!
isClosed: Boolean!
missionSource: String!
startDateTimeUtc: String!
endDateTimeUtc: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ class MissionEntityTests {
@Nested
inner class CalculateMissionStatus {
@Test
fun `should return ENDED when isClosed is true`() {
fun `should return ENDED when the endDate is prior than now`() {
val mission = MissionEntity(
envMission = ExtendedEnvMissionEntity.fromEnvMission(EnvMissionMock.create(isClosed = true)),
envMission = ExtendedEnvMissionEntity.fromEnvMission(
EnvMissionMock.create(
startDateTimeUtc = ZonedDateTime.now().minusDays(14),
endDateTimeUtc = ZonedDateTime.now().minusDays(2)
)
),
fishMissionActions = listOf(FishActionControlMock.create()).map {
ExtendedFishActionEntity.fromMissionAction(
it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ object EnvMissionMock {
geom: MultiPolygon? = null,
startDateTimeUtc: ZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2022, 1, 2, 12, 0), ZoneOffset.UTC),
endDateTimeUtc: ZonedDateTime? = null,
isClosed: Boolean = false,
isDeleted: Boolean = false,
isGeometryComputedFromControls: Boolean = false,
missionSource: MissionSourceEnum = MissionSourceEnum.MONITORENV,
Expand All @@ -43,7 +42,6 @@ object EnvMissionMock {
geom = geom,
startDateTimeUtc = startDateTimeUtc,
endDateTimeUtc = endDateTimeUtc,
isClosed = isClosed,
isDeleted = isDeleted,
isGeometryComputedFromControls = isGeometryComputedFromControls,
missionSource = missionSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ object FishMissionMock {
geom: MultiPolygon? = null,
startDateTimeUtc: ZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2022, 1, 2, 12, 0), ZoneOffset.UTC),
endDateTimeUtc: ZonedDateTime? = null,
isClosed: Boolean = false,
missionSource: MissionSource = MissionSource.MONITORENV,
hasMissionOrder: Boolean = false,
isUnderJdp: Boolean = false,
Expand All @@ -36,7 +35,6 @@ object FishMissionMock {
geom = geom,
startDateTimeUtc = startDateTimeUtc,
endDateTimeUtc = endDateTimeUtc,
isClosed = isClosed,
missionSource = missionSource,
hasMissionOrder = hasMissionOrder,
isUnderJdp = isUnderJdp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ object MissionEntityMock {
geom: MultiPolygon? = null,
startDateTimeUtc: ZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2022, 1, 2, 12, 0), ZoneOffset.UTC),
endDateTimeUtc: ZonedDateTime? = null,
isClosed: Boolean = false,
isDeleted: Boolean = false,
isGeometryComputedFromControls: Boolean = false,
missionSource: MissionSourceEnum = MissionSourceEnum.MONITORENV,
Expand All @@ -43,7 +42,6 @@ object MissionEntityMock {
geom = geom,
startDateTimeUtc = startDateTimeUtc,
endDateTimeUtc = endDateTimeUtc,
isClosed = isClosed,
isDeleted = isDeleted,
isGeometryComputedFromControls = isGeometryComputedFromControls,
missionSource = missionSource,
Expand Down
1 change: 0 additions & 1 deletion frontend/src/pam/missions/missions-list.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const openedMission = {

const closedMission = {
id: 2,
isClosed: true,
startDateTimeUtc: '2022-08-07T12:00:00Z',
status: MissionStatusEnum.CLOSED
} as unknown as Mission
Expand Down
21 changes: 0 additions & 21 deletions frontend/src/types/env-mission-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,12 @@ export type ResourceUnit = {

export type Mission<EnvAction = EnvActionControl | EnvActionSurveillance | EnvActionNote> = {
id: any
closedBy: string
controlUnits: Omit<ControlUnit, 'id'>[]
endDateTimeUtc?: string
envActions: EnvAction[]
facade: SeaFrontEnum
geom?: Record<string, any>[]
hasMissionOrder?: boolean
isClosed: boolean
isUnderJdp?: boolean
missionSource: MissionSourceEnum
missionTypes: MissionTypeEnum[]
Expand Down Expand Up @@ -448,22 +446,3 @@ export type Infraction = NewInfraction & {
formalNotice: FormalNoticeEnum
infractionType: InfractionTypeEnum
}

export const getMissionStatus = (mission: Mission, compareDate = Date.now()): MissionStatusEnum | string => {
const { endDateTimeUtc, isClosed, startDateTimeUtc } = mission
if (isClosed) {
return MissionStatusEnum.CLOSED
}
if (startDateTimeUtc) {
if (parseISO(startDateTimeUtc) && compareAsc(parseISO(startDateTimeUtc), compareDate) >= 0) {
return MissionStatusEnum.UPCOMING
}
if (!!endDateTimeUtc && parseISO(endDateTimeUtc) && compareDesc(parseISO(endDateTimeUtc), compareDate) >= 0) {
return MissionStatusEnum.ENDED
}

return MissionStatusEnum.PENDING
}

return 'ERROR'
}
1 change: 0 additions & 1 deletion frontend/src/types/fish-mission-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export namespace LegacyControlUnit {
export interface FishAction {
actionDatetimeUtc: string
actionType: MissionActionType
closedBy: string | undefined
controlQualityComments: string | undefined
controlUnits: LegacyControlUnit.LegacyControlUnit[]
districtCode: string | undefined
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/types/mission-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ export enum VesselSizeEnum {

export type Mission = {
id: number
closedBy: string
controlUnits: Omit<ControlUnit, 'id'>[]
endDateTimeUtc?: string
facade: SeaFrontEnum
geom?: Record<string, any>[]
hasMissionOrder?: boolean
isClosed: boolean
isUnderJdp?: boolean
missionSource: MissionSourceEnum
missionTypes: MissionTypeEnum[]
Expand Down

0 comments on commit 9fc5244

Please sign in to comment.