Skip to content

Commit

Permalink
refacto: updating mission
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeperrault committed Jan 13, 2025
1 parent 28507bc commit 973b319
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.gouv.cacem.monitorenv.domain.use_cases.missions

import fr.gouv.cacem.monitorenv.config.UseCase
import fr.gouv.cacem.monitorenv.domain.entities.mission.*
import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity
import fr.gouv.cacem.monitorenv.domain.repositories.IFacadeAreasRepository
import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository
import fr.gouv.cacem.monitorenv.domain.repositories.IPostgisFunctionRepository
Expand Down Expand Up @@ -51,12 +51,6 @@ class CreateOrUpdateMission(
UpdateMissionEvent(savedMission.mission),
)

/**
* TODO When doing an update, the `createdAtUtc` field is returned as null.
* To fix this, we return the stored `createdAtUtc`
*/
return savedMission.mission.copy(
createdAtUtc = savedMission.mission.createdAtUtc ?: storedMission?.createdAtUtc,
)
return savedMission.mission
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ data class CreateOrUpdateMissionDataInput(
val isGeometryComputedFromControls: Boolean,
val createdAtUtc: ZonedDateTime?,
val updatedAtUtc: ZonedDateTime?,

) {
) {
fun toMissionEntity(): MissionEntity {
val hasMissionOrder = this.hasMissionOrder == true
val isUnderJdp = this.isUnderJdp == true
Expand Down Expand Up @@ -63,7 +62,7 @@ data class CreateOrUpdateMissionDataInput(
return this.envActions
?.filter {
it.actionType == ActionTypeEnum.SURVEILLANCE ||
it.actionType == ActionTypeEnum.CONTROL
it.actionType == ActionTypeEnum.CONTROL
}
?.map { Pair(it.id, it.reportingIds.get()) }
?: listOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.hibernate.Hibernate
import org.hibernate.annotations.Fetch
import org.hibernate.annotations.FetchMode
import org.hibernate.annotations.JdbcType
import org.hibernate.annotations.UpdateTimestamp
import org.hibernate.dialect.PostgreSQLEnumJdbcType
import org.locationtech.jts.geom.MultiPolygon
import org.n52.jackson.datatype.jts.GeometryDeserializer
Expand Down Expand Up @@ -233,7 +234,7 @@ class MissionModel(
@Column(name = "observations_cnsp") val observationsCnsp: String? = null,
@Column(name = "open_by") val openBy: String? = null,
@Column(name = "start_datetime_utc") val startDateTimeUtc: Instant,
@Column(name = "updated_at_utc") var updatedAtUtc: Instant?,
@Column(name = "updated_at_utc") @UpdateTimestamp var updatedAtUtc: Instant?,
) {
fun toMissionEntity(objectMapper: ObjectMapper): MissionEntity {
val mappedControlUnits =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.boot.test.system.CapturedOutput
import org.springframework.boot.test.system.OutputCaptureExtension
import org.mockito.Mock
import org.mockito.Mockito.mock
import org.springframework.boot.test.system.CapturedOutput
import org.springframework.boot.test.system.OutputCaptureExtension
import org.springframework.test.context.junit.jupiter.SpringExtension

@ExtendWith(SpringExtension::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CanDeleteMissionUTests {
CanDeleteMission(
missionRepository = missionRepository,
monitorFishMissionActionsRepository =
monitorFishMissionActionsRepository,
monitorFishMissionActionsRepository,
rapportNavMissionActionsRepository = rapportNavMissionActionsRepository,
)
.execute(missionId, MissionSourceEnum.MONITORFISH)
Expand All @@ -75,13 +75,14 @@ class CanDeleteMissionUTests {
given(missionRepository.findById(missionId))
.willReturn(
aMissionEntity(
envActions = listOf(
anEnvAction(
mapper = ObjectMapper(),
id = UUID.randomUUID()
)
)
)
envActions =
listOf(
anEnvAction(
mapper = ObjectMapper(),
id = UUID.randomUUID(),
),
),
),
)
given(rapportNavMissionActionsRepository.findRapportNavMissionActionsById(missionId))
.willReturn(
Expand All @@ -95,7 +96,7 @@ class CanDeleteMissionUTests {
CanDeleteMission(
missionRepository = missionRepository,
monitorFishMissionActionsRepository =
monitorFishMissionActionsRepository,
monitorFishMissionActionsRepository,
rapportNavMissionActionsRepository = rapportNavMissionActionsRepository,
)
.execute(missionId, MissionSourceEnum.MONITORFISH)
Expand All @@ -111,13 +112,14 @@ class CanDeleteMissionUTests {
given(missionRepository.findById(missionId))
.willReturn(
aMissionEntity(
envActions = listOf(
anEnvAction(
mapper = ObjectMapper(),
id = UUID.randomUUID()
)
)
)
envActions =
listOf(
anEnvAction(
mapper = ObjectMapper(),
id = UUID.randomUUID(),
),
),
),
)
given(rapportNavMissionActionsRepository.findRapportNavMissionActionsById(missionId))
.willReturn(
Expand All @@ -131,7 +133,7 @@ class CanDeleteMissionUTests {
CanDeleteMission(
missionRepository = missionRepository,
monitorFishMissionActionsRepository =
monitorFishMissionActionsRepository,
monitorFishMissionActionsRepository,
rapportNavMissionActionsRepository = rapportNavMissionActionsRepository,
)
.execute(missionId, MissionSourceEnum.MONITORFISH)
Expand Down Expand Up @@ -163,7 +165,7 @@ class CanDeleteMissionUTests {
CanDeleteMission(
missionRepository = missionRepository,
monitorFishMissionActionsRepository =
monitorFishMissionActionsRepository,
monitorFishMissionActionsRepository,
rapportNavMissionActionsRepository = rapportNavMissionActionsRepository,
)
.execute(missionId, MissionSourceEnum.MONITORENV)
Expand Down Expand Up @@ -208,7 +210,7 @@ class CanDeleteMissionUTests {
CanDeleteMission(
missionRepository = missionRepository,
monitorFishMissionActionsRepository =
monitorFishMissionActionsRepository,
monitorFishMissionActionsRepository,
rapportNavMissionActionsRepository = rapportNavMissionActionsRepository,
)
.execute(missionId, MissionSourceEnum.MONITORENV)
Expand Down Expand Up @@ -263,7 +265,7 @@ class CanDeleteMissionUTests {
CanDeleteMission(
missionRepository = missionRepository,
monitorFishMissionActionsRepository =
monitorFishMissionActionsRepository,
monitorFishMissionActionsRepository,
rapportNavMissionActionsRepository = rapportNavMissionActionsRepository,
)
.execute(missionId, MissionSourceEnum.MONITORENV)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,28 +184,28 @@ class CreateOrPatchEnvActionsUTests {
.save(
argThat {
this ==
missionToUpdate.copy(
envActions =
missionToUpdate.envActions?.map {
when (it) {
is EnvActionControlEntity ->
it.copy(
facade = "La Face Ade",
department =
"Quequ'part",
)

is EnvActionSurveillanceEntity ->
it.copy(
facade = "La Face Ade",
department =
"Quequ'part",
)

else -> it
}
},
)
missionToUpdate.copy(
envActions =
missionToUpdate.envActions?.map {
when (it) {
is EnvActionControlEntity ->
it.copy(
facade = "La Face Ade",
department =
"Quequ'part",
)

is EnvActionSurveillanceEntity ->
it.copy(
facade = "La Face Ade",
department =
"Quequ'part",
)

else -> it
}
},
)
},
)
assertThat(createdMission).isEqualTo(expectedUpdatedMission)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ class CreateOrUpdateMissionUTests {
missionRepository.save(
argThat {
this ==
missionToUpdate.copy(
facade = "La Face Ade",
envActions = existingEnvActions,
observationsByUnit = "observations",
)
missionToUpdate.copy(
facade = "La Face Ade",
envActions = existingEnvActions,
observationsByUnit = "observations",
)
},
),
)
Expand All @@ -164,11 +164,11 @@ class CreateOrUpdateMissionUTests {
.save(
argThat {
this ==
missionToUpdate.copy(
facade = "La Face Ade",
envActions = existingEnvActions,
observationsByUnit = "observations",
)
missionToUpdate.copy(
facade = "La Face Ade",
envActions = existingEnvActions,
observationsByUnit = "observations",
)
},
)
assertThat(createdMission).isEqualTo(expectedCreatedMission)
Expand Down Expand Up @@ -200,7 +200,7 @@ class CreateOrUpdateMissionUTests {
MissionEntity(
id = 100,
endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"),
createdAtUtc = null,
createdAtUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"),
updatedAtUtc = ZonedDateTime.now(),
facade = "La Face Ade",
hasMissionOrder = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MissionFixture {
isUnderJdp = false,
isGeometryComputedFromControls = false,
updatedAtUtc = null,
createdAtUtc = null
createdAtUtc = null,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ class MissionsITests {

@MockitoBean
private lateinit var createOrUpdateMissionWithActionsAndAttachedReporting:
CreateOrUpdateMissionWithActionsAndAttachedReporting
CreateOrUpdateMissionWithActionsAndAttachedReporting

@MockitoBean
private lateinit var getFullMissions: GetFullMissions

@MockitoBean
private lateinit var getFullMissionWithFishAndRapportNavActions:
GetFullMissionWithFishAndRapportNavActions
GetFullMissionWithFishAndRapportNavActions

@MockitoBean
private lateinit var deleteMission: DeleteMission
Expand All @@ -90,7 +90,7 @@ class MissionsITests {
.read(
"MULTIPOLYGON (((-4.54877817 48.30555988, -4.54997332 48.30597601, -4.54998501 48.30718823, -4.5487929 48.30677461, -4.54877817 48.30555988)))",
) as
MultiPolygon
MultiPolygon
private val point = WKTReader().read("POINT (-4.54877816747593 48.305559876971)") as Point

@Test
Expand Down Expand Up @@ -244,7 +244,7 @@ class MissionsITests {
LegacyControlUnitResourceEntity(
id = 2,
controlUnitId =
1,
1,
name =
"Ressource 2",
),
Expand Down Expand Up @@ -521,7 +521,7 @@ class MissionsITests {
LegacyControlUnitResourceEntity(
id = 2,
controlUnitId =
1,
1,
name =
"Ressource 2",
),
Expand Down Expand Up @@ -795,7 +795,7 @@ class MissionsITests {
listOf(
Pair(UUID.fromString("bf9f4062-83d3-4a85-b89b-76c0ded6473d"), listOf(1)),
) as
List<EnvActionAttachedToReportingIds>
List<EnvActionAttachedToReportingIds>
given(
createOrUpdateMissionWithActionsAndAttachedReporting.execute(
mission = requestBody.toMissionEntity(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class ReportingsITests {
.read(
"POINT (-61.0 14.0)",
) as
Point,
Point,
),
controlUnit = null,
),
Expand Down Expand Up @@ -276,7 +276,7 @@ class ReportingsITests {
.read(
"POINT (-61.0 14.0)",
) as
Point,
Point,
),
controlUnit = null,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class VigilanceAreasITests {
.read(
"MULTIPOLYGON (((-4.54877817 48.30555988, -4.54997332 48.30597601, -4.54998501 48.30718823, -4.5487929 48.30677461, -4.54877817 48.30555988)))",
) as
MultiPolygon
MultiPolygon
private val point = WKTReader().read("POINT (-4.54877816747593 48.305559876971)") as Point

private val vigilanceArea1 =
Expand Down
Loading

0 comments on commit 973b319

Please sign in to comment.