Skip to content

Commit

Permalink
fix(events): fixes for surveillance, fish actions, illegal immigratio…
Browse files Browse the repository at this point in the history
…n and visual things
  • Loading branch information
lwih committed Apr 30, 2024
1 parent 9b56cf8 commit b37509e
Show file tree
Hide file tree
Showing 12 changed files with 310 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ data class MissionEntity(
): List<MissionActionEntity> {
return (envActions + fishActions + navActions).sortedByDescending { action ->
when (action) {
is MissionActionEntity.EnvAction -> action.envAction?.controlAction?.action?.actionStartDateTimeUtc
is MissionActionEntity.EnvAction -> {
if (action.envAction?.controlAction !== null) {
action.envAction.controlAction.action?.actionStartDateTimeUtc
} else {
action.envAction?.surveillanceAction?.action?.actionStartDateTimeUtc
}
}

is MissionActionEntity.FishAction -> action.fishAction.controlAction?.action?.actionDatetimeUtc
is MissionActionEntity.NavAction -> action.navAction.startDateTimeUtc
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,50 @@ class GetFishActionsByMissionId(
segments = listOf(FleetSegment("MED01", "Chaluts de fond"))
)

val actions = listOf(missionAction1, missionAction2).map {
var action = ExtendedFishActionEntity.fromMissionAction(it)
action = attachControlsToActionControl.toFishAction(
actionId = it.id?.toString(),
action = action
)
action
val missionAction3 = MissionAction(
id = missionId + 3,
missionId = missionId,
completion = Completion.COMPLETED,
vesselId = 5232556,
vesselName = "Le ROSE",
latitude = 48.389999,
longitude = -4.490000,
actionType = MissionActionType.OBSERVATION,
actionDatetimeUtc = ZonedDateTime.parse("2024-01-09T11:00:00Z"),
isDeleted = false,
isAdministrativeControl = true,
licencesAndLogbookObservations = null,
hasSomeGearsSeized = false,
hasSomeSpeciesSeized = false,
)

val actions = listOf(missionAction1, missionAction2, missionAction3).filter {
listOf(
MissionActionType.SEA_CONTROL,
MissionActionType.LAND_CONTROL
).contains(it.actionType)
}
.map {
var action = ExtendedFishActionEntity.fromMissionAction(it)
action = attachControlsToActionControl.toFishAction(
actionId = it.id?.toString(),
action = action
)
action
}

return actions
}

fun execute(missionId: Int): List<ExtendedFishActionEntity> {
try {
val fishActions = fishActionRepo.findFishActions(missionId = missionId)
val actions = fishActions.map {
val actions = fishActions.filter {
listOf(
MissionActionType.SEA_CONTROL,
MissionActionType.LAND_CONTROL
).contains(it.actionType)
}.map {
var action = ExtendedFishActionEntity.fromMissionAction(it)
action = attachControlsToActionControl.toFishAction(
actionId = it.id?.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ class GroupActionByDate {
fun execute(actions: List<MissionActionEntity>?): Map<LocalDate, List<MissionActionEntity>>? {
return actions?.groupBy { action ->
when (action) {
is MissionActionEntity.EnvAction -> action.envAction?.controlAction?.action?.actionStartDateTimeUtc?.takeIf { true }
?.toLocalDate()
is MissionActionEntity.EnvAction -> {
val controlActionDate =
action.envAction?.controlAction?.action?.actionStartDateTimeUtc?.toLocalDate()
val surveillanceActionDate =
action.envAction?.surveillanceAction?.action?.actionStartDateTimeUtc?.toLocalDate()
controlActionDate ?: surveillanceActionDate
}

is MissionActionEntity.FishAction -> action.fishAction.controlAction?.action?.actionDatetimeUtc?.takeIf { true }
?.toLocalDate()

is MissionActionEntity.NavAction -> action.navAction.startDateTimeUtc.takeIf { true }
?.toLocalDate()

else -> null // Handle other types of actions, if any
is MissionActionEntity.FishAction -> action.fishAction.controlAction?.action?.actionDatetimeUtc?.toLocalDate()
is MissionActionEntity.NavAction -> action.navAction.startDateTimeUtc.toLocalDate()
}
}?.mapNotNull { (date, actions) ->
date?.let { it to actions }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.export
import fr.gouv.dgampa.rapportnav.config.UseCase
import fr.gouv.dgampa.rapportnav.domain.entities.mission.MissionActionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionControlEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionSurveillanceEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.InfractionType
import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.MissionAction
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionControlEntity
Expand Down Expand Up @@ -61,9 +62,18 @@ class FormatActionsForTimeline(
}

private fun formatEnvAction(action: MissionActionEntity.EnvAction): String? {
return action.envAction?.controlAction?.action?.let { envControlAction ->
formatEnvControl(envControlAction)
return if (action.envAction?.controlAction != null) {
action.envAction.controlAction.action?.let { envControlAction ->
formatEnvControl(envControlAction)
}
} else if (action.envAction?.surveillanceAction != null) {
action.envAction.surveillanceAction.action.let { envSurveillanceAction ->
formatEnvSurveillance(envSurveillanceAction)
}
} else {
null
}

}

private fun formatFishAction(action: MissionActionEntity.FishAction): String? {
Expand Down Expand Up @@ -94,6 +104,14 @@ class FormatActionsForTimeline(
}
}

fun formatEnvSurveillance(action: EnvActionSurveillanceEntity?): String? {
return action?.let {
val startTime = formatDateTime.formatTime(action.actionStartDateTimeUtc)
val endTime = formatDateTime.formatTime(action.actionEndDateTimeUtc)
return "$startTime / $endTime - Surveillance Environnement"
}
}

fun formatFishControl(action: MissionAction?): String? {
return action?.let {
val startTime = formatDateTime.formatTime(action.actionDatetimeUtc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ExtendedEnvA
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ExtendedFishActionEntity
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.GroupActionByDate
import fr.gouv.gmampa.rapportnav.mocks.mission.action.EnvActionControlMock
import fr.gouv.gmampa.rapportnav.mocks.mission.action.EnvActionSurveillanceMock
import fr.gouv.gmampa.rapportnav.mocks.mission.action.FishActionControlMock
import fr.gouv.gmampa.rapportnav.mocks.mission.action.NavActionStatusMock
import org.assertj.core.api.Assertions.assertThat
Expand All @@ -31,7 +32,7 @@ class GroupActionByDateTest {
@Test
fun `execute should group actions by day`() {
// Mock mission actions
val action1 = MissionActionEntity.EnvAction(
val actionEnvControl1 = MissionActionEntity.EnvAction(
ExtendedEnvActionEntity.fromEnvActionEntity(
EnvActionControlMock.create(
actionStartDateTimeUtc = ZonedDateTime.of(
Expand All @@ -40,6 +41,15 @@ class GroupActionByDateTest {
)
)
)
val actionEnvSurveillance1 = MissionActionEntity.EnvAction(
ExtendedEnvActionEntity.fromEnvActionEntity(
EnvActionSurveillanceMock.create(
actionStartDateTimeUtc = ZonedDateTime.of(
LocalDateTime.of(2022, 1, 1, 12, 0), ZoneOffset.UTC
)
)
)
)

val action2 = MissionActionEntity.FishAction(
ExtendedFishActionEntity.fromMissionAction(
Expand All @@ -57,13 +67,13 @@ class GroupActionByDateTest {
NavActionStatusMock.createActionStatusEntity().toNavActionEntity()
)

val actions = listOf(action1, action2, action3)
val actions = listOf(actionEnvControl1, actionEnvSurveillance1, action2, action3)

val result = groupActionByDate.execute(actions)

assertThat(result).isNotNull()
assertThat(result!!.size).isEqualTo(2)
assertThat(result[LocalDate.of(2022, 1, 1)]?.size).isEqualTo(2)
assertThat(result[LocalDate.of(2022, 1, 1)]?.size).isEqualTo(3)
assertThat(result[LocalDate.of(2022, 1, 2)]?.size).isEqualTo(1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.export

import fr.gouv.dgampa.rapportnav.domain.entities.mission.MissionActionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionControlEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionSurveillanceEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.ThemeEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.InfractionType
import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.MissionAction
Expand Down Expand Up @@ -35,6 +36,8 @@ class FormatActionsForTimelineTests {

private val envControl =
MissionActionEntity.EnvAction(ExtendedEnvActionEntity.fromEnvActionEntity(EnvActionControlMock.create()))
private val envSurveillance =
MissionActionEntity.EnvAction(ExtendedEnvActionEntity.fromEnvActionEntity(EnvActionSurveillanceMock.create()))
private val fishControl =
MissionActionEntity.FishAction(ExtendedFishActionEntity.fromMissionAction(FishActionControlMock.create()))
private val navControl =
Expand All @@ -47,7 +50,7 @@ class FormatActionsForTimelineTests {
fun setUp() {
// Set up mock behavior for GroupActionByDate
val data: Map<LocalDate, List<MissionActionEntity>> = mapOf(
LocalDate.of(2022, 1, 1) to listOf(envControl, fishControl),
LocalDate.of(2022, 1, 1) to listOf(envControl, fishControl, envSurveillance),
LocalDate.of(2022, 1, 2) to listOf(navControl, navStatus, navFreeNote)
)
Mockito.`when`(groupActionByDate.execute(any())).thenReturn(data)
Expand All @@ -70,6 +73,7 @@ class FormatActionsForTimelineTests {
listOf(
envControl,
fishControl,
envSurveillance,
navControl,
navStatus,
navFreeNote
Expand All @@ -80,6 +84,7 @@ class FormatActionsForTimelineTests {
LocalDate.of(2022, 1, 1) to listOf(
"12:00 / 14:00 - Contrôle Environnement",
"12:00 - Contrôle Pêche - (DD): 52.14,14.30 - Le Pi - LR 314 - Infractions: sans PV - RAS",
"12:00 / 14:00 - Surveillance Environnement",
),
LocalDate.of(2022, 1, 2) to listOf(
"12:00 / 14:00 - Contrôle administratif ",
Expand All @@ -106,6 +111,7 @@ class FormatActionsForTimelineTests {
listOf(
envControl,
fishControl,
envSurveillance,
navControl,
navStatus,
navFreeNote
Expand All @@ -117,6 +123,7 @@ class FormatActionsForTimelineTests {
freeNote = listOf<TimelineActionItem>(
TimelineActionItem(observations = "12:00 / 14:00 - Contrôle Environnement"),
TimelineActionItem(observations = "12:00 - Contrôle Pêche - (DD): 52.14,14.30 - Le Pi - LR 314 - Infractions: sans PV - RAS"),
TimelineActionItem(observations = "12:00 / 14:00 - Surveillance Environnement"),
)
),
TimelineActions(
Expand All @@ -137,6 +144,12 @@ class FormatActionsForTimelineTests {
assertThat(formatActionsForTimeline.formatEnvControl(action)).isEqualTo("12:00 / 14:00 - Contrôle Environnement")
}

@Test
fun `formatEnvSurveillance should return basic formatted string`() {
val action: EnvActionSurveillanceEntity = EnvActionSurveillanceMock.create()
assertThat(formatActionsForTimeline.formatEnvSurveillance(action)).isEqualTo("12:00 / 14:00 - Surveillance Environnement")
}

@Test
fun `formatEnvControl should return formatted string with facade`() {
val action: EnvActionControlEntity = EnvActionControlMock.create(facade = "Golfe de Gascogne")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package fr.gouv.gmampa.rapportnav.mocks.mission.action

import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.ActionCompletionEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionSurveillanceEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.ThemeEntity
import org.locationtech.jts.geom.Geometry
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.util.*

object EnvActionSurveillanceMock {
fun create(
id: UUID = UUID.randomUUID(),
actionStartDateTimeUtc: ZonedDateTime? = ZonedDateTime.of(LocalDateTime.of(2022, 1, 2, 12, 0), ZoneOffset.UTC),
actionEndDateTimeUtc: ZonedDateTime? = ZonedDateTime.of(LocalDateTime.of(2022, 1, 2, 14, 0), ZoneOffset.UTC),
geom: Geometry? = null,
facade: String? = null,
department: String? = null,
themes: List<ThemeEntity>? = null,
observations: String? = null,
completion: ActionCompletionEnum = ActionCompletionEnum.COMPLETED,
completedBy: String? = null,
openBy: String? = null,
coverMissionZone: Boolean? = null,
): EnvActionSurveillanceEntity {
return EnvActionSurveillanceEntity(
id = id,
actionStartDateTimeUtc = actionStartDateTimeUtc,
actionEndDateTimeUtc = actionEndDateTimeUtc,
geom = geom,
facade = facade,
department = department,
themes = themes,
observations = observations,
completion = completion,
openBy = openBy,
completedBy = completedBy,
coverMissionZone = coverMissionZone
// Set other properties to their default values or mocks as needed
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ const ActionIllegalImmigrationForm: React.FC<ActionIllegalImmigrationFormProps>
>
<Stack.Item style={{ flex: 1 }}>
<NumberInput
isRequired={true}
error={
actionData?.nbOfInterceptedVessels === undefined || actionData?.nbOfInterceptedVessels === null
? 'error'
: undefined
}
isErrorMessageHidden={true}
label="Nb de navires/embarcations interceptées"
name="nbOfInterceptedVessels"
role="nbOfInterceptedVessels"
Expand All @@ -174,6 +181,13 @@ const ActionIllegalImmigrationForm: React.FC<ActionIllegalImmigrationFormProps>
</Stack.Item>
<Stack.Item style={{ flex: 1 }}>
<NumberInput
isRequired={true}
error={
actionData?.nbOfInterceptedMigrants === undefined || actionData?.nbOfInterceptedMigrants === null
? 'error'
: undefined
}
isErrorMessageHidden={true}
label="Nb de migrants interceptés"
name="nbOfInterceptedMigrants"
role="nbOfInterceptedMigrants"
Expand All @@ -185,6 +199,13 @@ const ActionIllegalImmigrationForm: React.FC<ActionIllegalImmigrationFormProps>
</Stack.Item>
<Stack.Item style={{ flex: 1 }}>
<NumberInput
isRequired={true}
error={
actionData?.nbOfSuspectedSmugglers === undefined || actionData?.nbOfSuspectedSmugglers === null
? 'error'
: undefined
}
isErrorMessageHidden={true}
label="Nb de passeurs présumés"
name="nbOfSuspectedSmugglers"
role="nbOfSuspectedSmugglers"
Expand Down
Loading

0 comments on commit b37509e

Please sign in to comment.