Skip to content

Commit

Permalink
Merge branch 'main' into jacoco
Browse files Browse the repository at this point in the history
  • Loading branch information
lwih authored Oct 18, 2024
2 parents 1a09ecf + df6b836 commit 2c4be74
Show file tree
Hide file tree
Showing 25 changed files with 603 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ variables:
value: "postgres:15.8-alpine"
description: "Image de la base de données"
PROJECT_VERSION:
value: "2.2.3"
value: "2.2.6"
description: "Version du projet à déployer"
SERVER_ENV_INT:
value: "int-rapportnav-appli01"
Expand Down
2 changes: 1 addition & 1 deletion backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.lang.System.getenv

group = "fr.gouv.dgampa"
version = "2.2.3"
version = "2.2.6"
description = "RapportNav"

val kotlinVersion by extra("1.9.24")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ data class AEMIllegalFish(

fun getNbrOfInfractionWithPV(fishActions: List<ExtendedFishActionEntity?>): Double {
return fishActions.map { it?.controlAction?.action }.fold(0.0) { acc, c ->
acc.plus(c!!.gearInfractions.filter { g -> g.infractionType == InfractionType.WITH_RECORD }.size)
.plus(c.otherInfractions.filter { o -> o.infractionType == InfractionType.WITH_RECORD }.size)
.plus(c.speciesInfractions.filter { s -> s.infractionType == InfractionType.WITH_RECORD }.size)
.plus(c.logbookInfractions.filter { l -> l.infractionType == InfractionType.WITH_RECORD }.size)
acc.plus(c?.gearInfractions?.filter { g -> g.infractionType == InfractionType.WITH_RECORD }?.size ?: 0)
.plus(
c?.otherInfractions?.filter { o -> o.infractionType == InfractionType.WITH_RECORD }?.size ?: 0
)
.plus(
c?.speciesInfractions?.filter { s -> s.infractionType == InfractionType.WITH_RECORD }?.size ?: 0
)
.plus(
c?.logbookInfractions?.filter { l -> l.infractionType == InfractionType.WITH_RECORD }?.size ?: 0
)
};
}

Expand All @@ -61,7 +67,7 @@ data class AEMIllegalFish(
}

fun getQuantityOfFish(fishActions: List<ExtendedFishActionEntity?>): Double {
return 0.0;
return 0.0; //TODO: hasSomeSpeciesSeized
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ data class AEMMigrationRescue(

companion object {
fun getNbrPersonsRescued(actionRescues: List<ActionRescueEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued!!) }
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued ?: 0) }
}

fun getNbrOfVesselsTrackedWithoutIntervention(actionRescues: List<ActionRescueEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.nbOfVesselsTrackedWithoutIntervention!!) }
return actionRescues.fold(0.0) { acc, actionRescue ->
acc.plus(
actionRescue?.nbOfVesselsTrackedWithoutIntervention ?: 0
)
}
}

fun getAssistedVesselsReturningToShore(actionRescues: List<ActionRescueEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.nbAssistedVesselsReturningToShore!!) }
return actionRescues.fold(0.0) { acc, actionRescue ->
acc.plus(
actionRescue?.nbAssistedVesselsReturningToShore ?: 0
)
}
}

private fun actionRescueEntities(navActions: List<NavActionEntity>): List<ActionRescueEntity?> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class AEMOutOfMigrationRescue(

companion object {
fun getNbrPersonsRescued(actionRescues: List<ActionRescueEntity?>): Double {
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued!!) }
return actionRescues.fold(0.0) { acc, actionRescue -> acc.plus(actionRescue?.numberPersonsRescued ?: 0) }
}

private fun actionRescueEntities(navActions: List<NavActionEntity>): List<ActionRescueEntity?> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,25 @@ import fr.gouv.dgampa.rapportnav.domain.repositories.mission.crew.IMissionCrewRe
class GetAgentsCrewByMissionId(private val agentCrewRepository: IMissionCrewRepository) {

fun execute(missionId: Int, commentDefaultsToString: Boolean? = false): List<MissionCrewEntity> {
val rolePriority = listOf(
"Commandant",
"Second capitaine",
"Second",
"Chef mécanicien",
"Second mécanicien",
"Mécanicien électricien",
"Mécanicien",
"Chef de quart",
"Maître d’équipage",
"Agent pont",
"Agent machine",
"Agent mécanicien",
"Électricien",
"Cuisinier",
)

return agentCrewRepository.findByMissionId(missionId = missionId)
.map { it.toMissionCrewEntity(commentDefaultsToString) }
.sortedBy { it.id }
.sortedBy { rolePriority.indexOf(it.role.title) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class ExportMissionRapportPatrouille(
val leisureSailingSeaSummary = getMissionOperationalSummary.getLeisureSailingSeaSummary(mission)
val leisureSailingLandSummary = getMissionOperationalSummary.getLeisureSailingLandSummary(mission)

val envSummary = getMissionOperationalSummary.getEnvSummary(mission)
val leisureFishingSummary = getMissionOperationalSummary.getLeisureFishingSummary(mission)

val placeholders: Map<String, String?> = mapOf(
"\${service}" to (service?.name ?: ""),
"\${numRapport}" to formatDateTime.formatDate(mission.startDateTimeUtc),
Expand Down Expand Up @@ -187,14 +190,6 @@ class ExportMissionRapportPatrouille(
"\${essence}" to (generalInfo?.consumedFuelInLiters?.toString() ?: ""),

"\${observations}" to (mission.observationsByUnit ?: ""),

// "\${proSailingSeaSummary}" to gson.toJson(proSailingSeaSummary),
// "\${leisureSailingSeaSummary}" to gson.toJson(leisureSailingSeaSummary),
// "\${proFishingLandSummary}" to gson.toJson(proFishingLandSummary),
// "\${proSailingLandSummary}" to gson.toJson(proSailingLandSummary),
// "\${leisureSailingLandSummary}" to gson.toJson(leisureSailingLandSummary),


)

fun castLinkedHashMapToList(map: LinkedHashMap<String, Map<String, Int?>>): List<List<String?>> {
Expand Down Expand Up @@ -331,6 +326,40 @@ class ExportMissionRapportPatrouille(
}


paragraphs = document.paragraphs.toList()
for (paragraph in paragraphs) {
if (paragraph.text.contains("\${envSummary}")) {
val header: List<String?> = listOf(
"Nbre surveillance Env",
"Nbre ctrl Env",
"Nbre de PV Env",
)
val secondRow: List<String?> = envSummary.values.map { value ->
if (value > 0) value.toString() else ""
}
val table: List<List<String?>> = listOf(header, secondRow)
insertOperationalSummaryTableAtParagraph(paragraph, table)
}
}


paragraphs = document.paragraphs.toList()
for (paragraph in paragraphs) {
if (paragraph.text.contains("\${leisureFishingSummary}")) {

val header: List<String?> = listOf(
"Nbre Navires contrôlés",
"Nbre de PV pêche de loisir",
)
val secondRow: List<String?> = leisureFishingSummary.values.map { value ->
if (value > 0) value.toString() else ""
}
val table: List<List<String?>> = listOf(header, secondRow)
insertOperationalSummaryTableAtParagraph(paragraph, table)
}
}



for (table in document.tables) {
replacePlaceholdersInTable(table, placeholders)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,48 @@ class GetMissionOperationalSummary {
return summary.filterKeys { it in keysToKeep }
}

fun getEnvSummary(mission: MissionEntity): Map<String, Int> {
val actions = mission.actions
?.filterIsInstance<MissionActionEntity.EnvAction>()
?: emptyList()
val nbSurveillances = actions.count { it.envAction?.surveillanceAction != null }
val nbControls = actions.count { it.envAction?.controlAction != null }
val nbPv = actions.sumOf { action ->
(action.envAction?.controlAction?.action?.infractions?.count { inf ->
inf.infractionType == InfractionTypeEnum.WITH_REPORT
} ?: 0)
}
val summary = mapOf(
"nbSurveillances" to nbSurveillances,
"nbControls" to nbControls,
"nbPv" to nbPv
)


return summary
}

fun getLeisureFishingSummary(mission: MissionEntity): Map<String, Int> {
// specifically filter for theme Peche de loisir (autre que PAP), it has id 112
val themeId = 112
val actions = mission.actions
?.filterIsInstance<MissionActionEntity.EnvAction>()
?.filter { it.envAction?.controlAction != null }
?.filter { it.envAction?.controlAction?.action?.controlPlans?.any { theme -> theme.themeId == themeId } == true }
?: emptyList()
val nbPv = actions.sumOf { action ->
// Sum infractions of type WITH_REPORT from different control categories
(action.envAction?.controlAction?.action?.infractions?.count { inf ->
inf.infractionType == InfractionTypeEnum.WITH_REPORT
} ?: 0)
}
val summary = mapOf(
"nbControls" to actions.count(),
"nbPv" to nbPv
)
return summary
}

private fun getFishActionSummary(
mission: MissionEntity,
controlMethod: MissionActionType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MissionCrewModel(
var missionId: Int,

@Column(name = "comment", nullable = true)
var comment: String?,
var comment: String? = null,

@ManyToOne
@JoinColumn(name = "agent_role_id")
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ class AEMOutOfMigrationRescueTest {
assertThat(migrationRescue.nbrOfRescuedOperation).isEqualTo(nbrOfRescuedOperation);
}

@Test
fun `Should not thow null pointer exception event if nbrPersonsRescued is null`() {
val action = NavActionEntity(
id = UUID.randomUUID(),
missionId = 761,
actionType = ActionType.ILLEGAL_IMMIGRATION,
startDateTimeUtc = Instant.parse("2019-09-09T00:00:00.000+01:00"),
endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"),
rescueAction = ActionRescueEntity(
missionId = 761,
id = UUID.randomUUID(),
startDateTimeUtc = Instant.parse("2019-09-08T22:00:00.000+01:00"),
endDateTimeUtc = Instant.parse("2019-09-09T01:00:00.000+01:00"),
observations = "",
numberPersonsRescued = null,
numberOfDeaths = 0,
isMigrationRescue = false
)
)
val migrationRescue = AEMOutOfMigrationRescue(navActions = listOf(action));
assertThat(migrationRescue).isNotNull();
assertThat(migrationRescue.nbrPersonsRescued).isEqualTo(0.0);
}

private fun navActionEntities(): List<NavActionEntity> {
val actions = listOf(
NavActionEntity(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package fr.gouv.gmampa.rapportnav.domain.use_cases.mission.crew

import fr.gouv.dgampa.rapportnav.domain.repositories.mission.crew.IMissionCrewRepository
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.crew.GetAgentsCrewByMissionId
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew.AgentModel
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew.AgentRoleModel
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew.MissionCrewModel
import junit.framework.TestCase.assertEquals
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.mock.mockito.MockBean

@SpringBootTest(classes = [GetAgentsCrewByMissionId::class])
class GetAgentsCrewByMissionIdTest {

@Autowired
private lateinit var getAgentsCrewByMissionId: GetAgentsCrewByMissionId

@MockBean
private lateinit var agentCrewRepository: IMissionCrewRepository


@Test
fun `execute should return sorted list of crew members by role priority`() {

val missionId = 1

val johnDoe = AgentModel(
firstName = "John",
lastName = "Doe",
id = 1
)

val janeDoe = AgentModel(
firstName = "Jane",
lastName = "Doe",
id = 2
)

val alfredDeMusset = AgentModel(
firstName = "Alfred",
lastName = "de Musset",
id = 3
)

val guyDeMaupassant = AgentModel(
firstName = "Guy",
lastName = "de Maupassant",
id = 4
)

val chefMecano = AgentRoleModel(
title = "Chef mécanicien",
id = 1
)

val secondCapitaine = AgentRoleModel(
title = "Second capitaine",
id = 2
)

val cuisinier = AgentRoleModel(
title = "Cuisinier",
id = 3
)

val commandant = AgentRoleModel(
title = "Commandant",
id = 4
)

val crewMembers = listOf(
MissionCrewModel(role = chefMecano, agent = janeDoe, missionId = missionId, id = 1),
MissionCrewModel(role = secondCapitaine, agent = johnDoe, missionId = missionId, id = 2),
MissionCrewModel(role = cuisinier, agent = alfredDeMusset, missionId = missionId, id = 3),
MissionCrewModel(role = commandant, agent = guyDeMaupassant, missionId = missionId, id = 4),
)

`when`(agentCrewRepository.findByMissionId(missionId)).thenReturn(crewMembers)

val sortedCrew = getAgentsCrewByMissionId.execute(missionId, commentDefaultsToString = false)

// Assert
val expectedRoles = listOf("Commandant", "Second capitaine", "Chef mécanicien", "Cuisinier")
assertEquals(expectedRoles, sortedCrew.map { it.role.title })
}
}
Loading

0 comments on commit 2c4be74

Please sign in to comment.