Skip to content

Commit

Permalink
Add fake missions before user tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lwih committed Jan 2, 2024
1 parent aec6d8b commit 0e17959
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 209 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: "Release"

on:
# push:
# branches: [ "main" ]
push:
branches: [ "main" ]
release:
types: [ published ]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package fr.gouv.dgampa.rapportnav.domain.use_cases.mission

import fr.gouv.dgampa.rapportnav.config.UseCase
import fr.gouv.dgampa.rapportnav.domain.entities.mission.MissionActionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.MissionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionTypeEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.*
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ExtendedEnvActionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.user.User
import org.locationtech.jts.geom.Coordinate
import java.time.ZonedDateTime
import java.util.*

@UseCase
class FakeMissionData(
private val getFishActionsByMissionId: GetFishActionsByMissionId,
) {

fun getEmptyMissionIds(): List<Int> {
return listOf(621, 311, 761)
}

fun getFullMissionIds(): List<Int> {
return listOf(622, 312, 762)
}

fun getEnvActionIds(): List<String> {
return getFullMissionIds().map { missionId ->
"226d84bc-e6c5-4d29-8a5f-7db642f99$missionId"
}
}

fun getFishActionIds(): List<String> {
return getFullMissionIds().map { missionId ->
(missionId + 1).toString()
} + getFullMissionIds().map { missionId ->
(missionId + 2).toString()
}
}

fun envControls(missionId: Int): List<ExtendedEnvActionEntity> {
val envActionControl1 = EnvActionControlEntity(
id = UUID.fromString("226d84bc-e6c5-4d29-8a5f-7db642f99$missionId"),
actionStartDateTimeUtc = ZonedDateTime.parse("2024-01-09T10:00:00Z"),
actionEndDateTimeUtc = null, // Set to null if not provided in your API response
themes = listOf(
ThemeEntity(
theme = "Rejets illicites",
subThemes = listOf("avitaillement", "soutage"),
protectedSpecies = listOf()
)
),
geom = createMockMultiPoint(listOf(Coordinate(-8.52318191, 48.30305604))),
actionNumberOfControls = 2,
actionTargetType = ActionTargetTypeEnum.VEHICLE,
vehicleType = VehicleTypeEnum.VESSEL,
observations = "Observation",
isComplianceWithWaterRegulationsControl = true,
isSafetyEquipmentAndStandardsComplianceControl = true,
isSeafarersControl = false,
isAdministrativeControl = false,
infractions = listOf(
InfractionEntity(
id = "91200795-2823-46b3-8814-a5b3bca29$missionId",
natinf = listOf("4210", "28732"),
registrationNumber = "123ABC57",
companyName = null,
relevantCourt = null,
infractionType = InfractionTypeEnum.WITHOUT_REPORT,
formalNotice = FormalNoticeEnum.NO,
toProcess = false,
controlledPersonIdentity = "M. Bernard",
vesselType = VesselTypeEnum.COMMERCIAL,
vesselSize = VesselSizeEnum.FROM_24_TO_46m
)
)
)
return listOf(ExtendedEnvActionEntity.fromEnvActionEntity(envActionControl1)!!)
}

fun fullMission(missionId: Int): MissionEntity {

val envActions = envControls(missionId).map {
MissionActionEntity.EnvAction(it)
}
val fishActions = getFishActionsByMissionId.getFakeActions(missionId).map {
MissionActionEntity.FishAction(it)
}

return MissionEntity(
id = missionId,
missionTypes = listOf(MissionTypeEnum.SEA),
missionSource = MissionSourceEnum.RAPPORTNAV,
startDateTimeUtc = ZonedDateTime.parse("2024-01-08T08:00:00Z"),
endDateTimeUtc = ZonedDateTime.parse("2024-01-22T20:00:00Z"),
isClosed = false,
isDeleted = false,
isGeometryComputedFromControls = false,
hasMissionOrder = false,
isUnderJdp = false,
openBy = "fake",
actions = fishActions + envActions
)
}

fun emptyMission(missionId: Int): MissionEntity {
return MissionEntity(
id = missionId,
missionTypes = listOf(MissionTypeEnum.SEA),
missionSource = MissionSourceEnum.RAPPORTNAV,
startDateTimeUtc = ZonedDateTime.parse("2024-01-08T08:00:00Z"),
endDateTimeUtc = ZonedDateTime.parse("2024-01-22T20:00:00Z"),
isClosed = false,
isDeleted = false,
isGeometryComputedFromControls = false,
hasMissionOrder = false,
isUnderJdp = false,
openBy = "fake",
actions = listOf(),
)
}

fun getFakeMissionsforUser(user: User?): List<MissionEntity> {
return when (user?.serviceId) {
// bouteillon
7 -> {
return listOf(fullMission(621), emptyMission(622))
}
// Ariane
3 -> {
return listOf(fullMission(311), emptyMission(312))
}
// d'Alba
6 -> {
return listOf(fullMission(761), emptyMission(762))
}
// else
else -> {
return listOf()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import java.net.http.HttpResponse
import java.time.ZonedDateTime
import java.util.*

fun createMockMultiPoint(coordinates: List<Coordinate>): MultiPoint {
val factory = GeometryFactory()
val points = coordinates.map { factory.createPoint(it) }
return factory.createMultiPoint(points.toTypedArray())
}

@UseCase
class GetEnvMissionById(
Expand Down Expand Up @@ -65,12 +70,6 @@ class GetEnvMissionById(
)


fun createMockMultiPoint(coordinates: List<Coordinate>): MultiPoint {
val factory = GeometryFactory()
val points = coordinates.map { factory.createPoint(it) }
return factory.createMultiPoint(points.toTypedArray())
}

val envActionControl1 = EnvActionControlEntity(
id = UUID.fromString("226d84bc-e6c5-4d29-8a5f-7db642f99d16"),
actionStartDateTimeUtc = ZonedDateTime.parse("2023-12-15T10:00:00Z"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,58 +34,58 @@ class GetEnvMissions(
)
return missions
// } catch (e: Exception) {
// logger.error("GetEnvMissions failed loading Missions", e)
//
// val mission1 = EnvMission(
// id = 10,
// missionTypes = listOf(MissionTypeEnum.SEA),
// facade = "Outre-Mer",
// observationsCacem = null,
// startDateTimeUtc = ZonedDateTime.parse("2022-03-15T04:50:09Z"),
// logger.error("GetEnvMissions failed loading Missions", e)

// val mission1 = EnvMission(
// id = 10,
// missionTypes = listOf(MissionTypeEnum.SEA),
// facade = "Outre-Mer",
// observationsCacem = null,
// startDateTimeUtc = ZonedDateTime.parse("2022-03-15T04:50:09Z"),
//// endDateTimeUtc = ZonedDateTime.parse("2022-03-23T20:29:03Z"),
// isClosed = false,
// isDeleted = false,
// missionSource = MissionSourceEnum.RAPPORTNAV,
// hasMissionOrder = false,
// isUnderJdp = false,
// isGeometryComputedFromControls = false,
// )
// val mission2 = EnvMission(
// id = 11,
// missionTypes = listOf(MissionTypeEnum.SEA),
// facade = "Outre-Mer",
// 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,
// isUnderJdp = false,
// isGeometryComputedFromControls = false
// )
// val mission3 = EnvMission(
// id = 12,
// missionTypes = listOf(MissionTypeEnum.SEA),
// facade = "Outre-Mer",
// 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,
// isUnderJdp = false,
// isGeometryComputedFromControls = false
// )
// isClosed = false,
// isDeleted = false,
// missionSource = MissionSourceEnum.RAPPORTNAV,
// hasMissionOrder = false,
// isUnderJdp = false,
// isGeometryComputedFromControls = false,
// )
// val mission2 = EnvMission(
// id = 11,
// missionTypes = listOf(MissionTypeEnum.SEA),
// facade = "Outre-Mer",
// 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,
// isUnderJdp = false,
// isGeometryComputedFromControls = false
// )
// val mission3 = EnvMission(
// id = 12,
// missionTypes = listOf(MissionTypeEnum.SEA),
// facade = "Outre-Mer",
// 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,
// isUnderJdp = false,
// isGeometryComputedFromControls = false
// )
//
// val envMissions = listOf(mission1, mission2, mission3)
// val envMissions = listOf(mission1, mission2, mission3)
//
// val missions = envMissions.map { MissionEntity(envMission = ExtendedEnvMissionEntity.fromEnvMission(it)) }
// val missions = envMissions.map { MissionEntity(envMission = ExtendedEnvMissionEntity.fromEnvMission(it)) }
//
// logger.info("Found ${missions.size} missions ")
// logger.info("Found ${missions.size} missions ")
//
// return missions
// return missions
// }


Expand Down
Loading

0 comments on commit 0e17959

Please sign in to comment.