Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tech] Lint Backend #2695

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package fr.gouv.cnsp.monitorfish.domain.entities.mission_actions.actrep

enum class ActivityCode {
FIS,
LAN
LAN,
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ typealias FaoCodesAndSpecy = Pair<FaoCodes, String>

val MED_FAO_CODES = listOf("37.1", "37.2", "37.3")
val MEDITERRANEAN_AND_EASTERN_ATLANTIC_SPECIES: List<FaoCodesAndSpecy> = generateSpeciesWithFaoCode(
MED_FAO_CODES, listOf(
MED_FAO_CODES,
listOf(
"ANE",
"HOM",
"JAX",
Expand Down Expand Up @@ -53,14 +54,15 @@ val MEDITERRANEAN_AND_EASTERN_ATLANTIC_SPECIES: List<FaoCodesAndSpecy> = generat
"CTB",
"SWA",
"SOL",
"ANN"
)
"ANN",
),
) +
// Eastern Atlantic part
listOf(Pair(listOf("27.7", "27.8", "27.9", "27.10"), "BFT"))
val NS_01_FAO_CODES = listOf("27.4", "27.3.a")
val NORTH_SEA_SPECIES = generateSpeciesWithFaoCode(
NS_01_FAO_CODES, listOf(
NS_01_FAO_CODES,
listOf(
"HOM",
"JAX",
"ALB",
Expand Down Expand Up @@ -99,14 +101,15 @@ val NORTH_SEA_SPECIES = generateSpeciesWithFaoCode(
"BLL",
"SOL",
"NOP",
)
),
)
val WW_01_FAO_CODES = listOf("27.6", "27.7", "27.8", "27.9", "27.10")
val WESTERN_WATERS_SPECIES = listOf(
Pair(listOf("27.6", "27.7", "27.8", "27.9"), "PIL"),
Pair(listOf("27.6", "27.7", "27.8", "27.9"), "ELE"),
) + generateSpeciesWithFaoCode(
WW_01_FAO_CODES, listOf(
WW_01_FAO_CODES,
listOf(
"ANE",
"HOM",
"JAX",
Expand Down Expand Up @@ -139,8 +142,8 @@ val WESTERN_WATERS_SPECIES = listOf(
"SRX",
"BSF",
"BOR",
"SOL"
)
"SOL",
),
)

fun generateSpeciesWithFaoCode(faoCodes: FaoCodes, species: List<String>): List<FaoCodesAndSpecy> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ interface MissionRepository {
seaFronts: List<String>?,
): List<Mission>
fun findByIds(
ids: List<Int>
ids: List<Int>,
): List<Mission>
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GetActivityReports(

fun execute(beforeDateTime: ZonedDateTime, afterDateTime: ZonedDateTime, jdp: JointDeploymentPlan): List<ActivityReport> {
val controls = missionActionsRepository.findControlsInDates(beforeDateTime, afterDateTime)
logger.info("Found ${controls.size} controls between dates [${afterDateTime}, ${beforeDateTime}].")
logger.info("Found ${controls.size} controls between dates [$afterDateTime, $beforeDateTime].")

if (controls.isEmpty()) {
return listOf()
Expand All @@ -48,7 +48,9 @@ class GetActivityReports(
MissionActionType.SEA_CONTROL -> {
val controlMission = missions.firstOrNull { mission -> mission.id == control.missionId }
if (controlMission == null) {
logger.error("Mission id '${control.missionId}' linked to control id '${control.id}' could not be found.")
logger.error(
"Mission id '${control.missionId}' linked to control id '${control.id}' could not be found.",
)
}

// The mission must be under JDP
Expand Down Expand Up @@ -91,7 +93,7 @@ class GetActivityReports(
activityCode = activityCode,
controlUnits = controlMission.controlUnits,
vesselNationalIdentifier = controlledVessel.getNationalIdentifier(),
vessel = controlledVessel
vessel = controlledVessel,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ data class ActivityReport(
val activityCode: ActivityCode,
val vesselNationalIdentifier: String, // The `districtCode` and `internalReferenceNumber` concatenation
val controlUnits: List<ControlUnit>,
val vessel: Vessel
val vessel: Vessel,
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MissionActionsController(
private val updateMissionAction: UpdateMissionAction,
private val deleteMissionAction: DeleteMissionAction,
private val getMissionAction: GetMissionAction,
private val getActivityReports: GetActivityReports
private val getActivityReports: GetActivityReports,
) {

@GetMapping("/controls")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ data class ActivityReportDataOutput(
val activityCode: ActivityCode,
val vesselNationalIdentifier: String, // The `districtCode` and `internalReferenceNumber` concatenation
val controlUnits: List<ControlUnit>,
val vessel: VesselDataOutput
){
val vessel: VesselDataOutput,
) {
companion object {
fun fromActivityReport(activityReport: ActivityReport) = ActivityReportDataOutput(
action = MissionActionDataOutput.fromMissionAction(activityReport.action),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class JpaMissionActionsRepository(
listOf(
MissionActionType.SEA_CONTROL,
MissionActionType.LAND_CONTROL,
)
),
).map { action ->
action.toMissionAction(
mapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface DBMissionActionsRepository : CrudRepository<MissionActionEntity, Int>
fun findAllByActionDatetimeUtcBeforeAndActionDatetimeUtcAfterAndIsDeletedIsFalseAndActionTypeIn(
beforeDateTime: Instant,
afterDateTime: Instant,
actionTypes: List<MissionActionType>
actionTypes: List<MissionActionType>,
): List<MissionActionEntity>
fun findAllByMissionIdAndIsDeletedIsFalse(missionId: Int): List<MissionActionEntity>
fun findAllByMissionIdInAndIsDeletedIsFalse(missionIds: List<Int>): List<MissionActionEntity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,120 +43,126 @@ class GetActivityReportsUTests {

@Test
fun `execute Should return the activity report of a JDP control`() {
// Given
val species = SpeciesControl()
species.speciesCode = "HKE"
// Given
val species = SpeciesControl()
species.speciesCode = "HKE"

val controls = listOf(
MissionAction(
id = 1,
vesselId = 1,
missionId = 1,
actionDatetimeUtc = ZonedDateTime.now(),
portLocode = "AEFAT",
faoAreas = listOf("27.4.b", "27.4.c"),
actionType = MissionActionType.LAND_CONTROL,
gearOnboard = listOf(),
speciesOnboard = listOf(species),
seizureAndDiversion = true,
isDeleted = false,
hasSomeGearsSeized = false,
hasSomeSpeciesSeized = false,
isFromPoseidon = false,
),
MissionAction(
id = 2,
vesselId = 1,
missionId = 2,
actionDatetimeUtc = ZonedDateTime.now(),
actionType = MissionActionType.SEA_CONTROL,
seizureAndDiversion = false,
speciesInfractions = listOf(),
isDeleted = false,
hasSomeGearsSeized = false,
hasSomeSpeciesSeized = false,
isFromPoseidon = false,
),
MissionAction(
id = 3,
vesselId = 2,
missionId = 3,
actionDatetimeUtc = ZonedDateTime.now(),
actionType = MissionActionType.SEA_CONTROL,
seizureAndDiversion = false,
speciesInfractions = listOf(),
isDeleted = false,
hasSomeGearsSeized = false,
hasSomeSpeciesSeized = false,
isFromPoseidon = false,
),
)
given(missionActionsRepository.findControlsInDates(any(), any())).willReturn(controls)
val controls = listOf(
MissionAction(
id = 1,
vesselId = 1,
missionId = 1,
actionDatetimeUtc = ZonedDateTime.now(),
portLocode = "AEFAT",
faoAreas = listOf("27.4.b", "27.4.c"),
actionType = MissionActionType.LAND_CONTROL,
gearOnboard = listOf(),
speciesOnboard = listOf(species),
seizureAndDiversion = true,
isDeleted = false,
hasSomeGearsSeized = false,
hasSomeSpeciesSeized = false,
isFromPoseidon = false,
),
MissionAction(
id = 2,
vesselId = 1,
missionId = 2,
actionDatetimeUtc = ZonedDateTime.now(),
actionType = MissionActionType.SEA_CONTROL,
seizureAndDiversion = false,
speciesInfractions = listOf(),
isDeleted = false,
hasSomeGearsSeized = false,
hasSomeSpeciesSeized = false,
isFromPoseidon = false,
),
MissionAction(
id = 3,
vesselId = 2,
missionId = 3,
actionDatetimeUtc = ZonedDateTime.now(),
actionType = MissionActionType.SEA_CONTROL,
seizureAndDiversion = false,
speciesInfractions = listOf(),
isDeleted = false,
hasSomeGearsSeized = false,
hasSomeSpeciesSeized = false,
isFromPoseidon = false,
),
)
given(missionActionsRepository.findControlsInDates(any(), any())).willReturn(controls)

val vessels = listOf(
Vessel(
id = 1,
internalReferenceNumber = "FR00022680",
vesselName = "MY AWESOME VESSEL",
flagState = CountryCode.FR,
declaredFishingGears = listOf("Trémails"),
vesselType = "Fishing",
districtCode = "AY",
),
Vessel(
id = 2,
internalReferenceNumber = "FR00065455",
vesselName = "MY SECOND AWESOME VESSEL",
flagState = CountryCode.FR,
declaredFishingGears = listOf("Trémails"),
vesselType = "Fishing",
districtCode = "LO",
)
)
given(vesselRepository.findVesselsByIds(eq(listOf(1, 2)))).willReturn(vessels)
val vessels = listOf(
Vessel(
id = 1,
internalReferenceNumber = "FR00022680",
vesselName = "MY AWESOME VESSEL",
flagState = CountryCode.FR,
declaredFishingGears = listOf("Trémails"),
vesselType = "Fishing",
districtCode = "AY",
),
Vessel(
id = 2,
internalReferenceNumber = "FR00065455",
vesselName = "MY SECOND AWESOME VESSEL",
flagState = CountryCode.FR,
declaredFishingGears = listOf("Trémails"),
vesselType = "Fishing",
districtCode = "LO",
),
)
given(vesselRepository.findVesselsByIds(eq(listOf(1, 2)))).willReturn(vessels)

val missions = listOf(Mission(
val missions = listOf(
Mission(
1,
missionTypes = listOf(MissionType.LAND),
missionSource = MissionSource.MONITORFISH,
isClosed = false,
isUnderJdp = false,
startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC),
),
Mission(
2,
missionTypes = listOf(MissionType.SEA),
missionSource = MissionSource.MONITORFISH,
isClosed = false,
isUnderJdp = true,
startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC),
),
Mission(
2,
missionTypes = listOf(MissionType.SEA),
missionSource = MissionSource.MONITORFISH,
isClosed = false,
isUnderJdp = false,
startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC),
)
)
given(missionRepository.findByIds(listOf(1, 2, 3))).willReturn(missions)
given(portRepository.find(eq("AEFAT"))).willReturn(Port("AEFAT", "Al Jazeera Port"))
),
Mission(
2,
missionTypes = listOf(MissionType.SEA),
missionSource = MissionSource.MONITORFISH,
isClosed = false,
isUnderJdp = true,
startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC),
),
Mission(
2,
missionTypes = listOf(MissionType.SEA),
missionSource = MissionSource.MONITORFISH,
isClosed = false,
isUnderJdp = false,
startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC),
),
)
given(missionRepository.findByIds(listOf(1, 2, 3))).willReturn(missions)
given(portRepository.find(eq("AEFAT"))).willReturn(Port("AEFAT", "Al Jazeera Port"))

// When
val activityReports = GetActivityReports(missionActionsRepository, portRepository, vesselRepository, missionRepository).execute(
ZonedDateTime.now(),
ZonedDateTime.now().minusDays(1),
JointDeploymentPlan.NORTH_SEA
)
// When
val activityReports = GetActivityReports(
missionActionsRepository,
portRepository,
vesselRepository,
missionRepository,
).execute(
ZonedDateTime.now(),
ZonedDateTime.now().minusDays(1),
JointDeploymentPlan.NORTH_SEA,
)

// Then
assertThat(activityReports).hasSize(2)
val landReport = activityReports.first()
assertThat(landReport.activityCode).isEqualTo(ActivityCode.LAN)
assertThat(landReport.action.portName).isEqualTo("Al Jazeera Port")
val seaReport = activityReports.last()
assertThat(seaReport.activityCode).isEqualTo(ActivityCode.FIS)
assertThat(landReport.vesselNationalIdentifier).isEqualTo("AYFR00022680")
// Then
assertThat(activityReports).hasSize(2)
val landReport = activityReports.first()
assertThat(landReport.activityCode).isEqualTo(ActivityCode.LAN)
assertThat(landReport.action.portName).isEqualTo("Al Jazeera Port")
val seaReport = activityReports.last()
assertThat(seaReport.activityCode).isEqualTo(ActivityCode.FIS)
assertThat(landReport.vesselNationalIdentifier).isEqualTo("AYFR00022680")
}
}
Loading
Loading