Skip to content

Commit

Permalink
Merge pull request #438 from MTES-MCT/feat/mission-interservices
Browse files Browse the repository at this point in the history
feat: introduce missions inter-services
  • Loading branch information
lwih authored Dec 30, 2024
2 parents 5abba35 + 4eb6753 commit 2b9ca66
Show file tree
Hide file tree
Showing 90 changed files with 3,909 additions and 1,174 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.10-alpine"
description: "Image de la base de données"
PROJECT_VERSION:
value: "2.3.5"
value: "2.4.0-rc7"
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.3.5"
version = "2.4.0-rc7"
description = "RapportNav"

val kotlinVersion by extra("1.9.24")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,9 @@ data class MissionEntity(
}

companion object {
private fun sortActions(
envActions: List<MissionActionEntity.EnvAction>,
fishActions: List<MissionActionEntity.FishAction>,
navActions: List<MissionActionEntity.NavAction>
): List<MissionActionEntity> {
return (envActions + fishActions + navActions).sortedByDescending { action ->

fun sortActionsAsc(actions: List<MissionActionEntity>): List<MissionActionEntity> {
return (actions).sortedByDescending { action ->
when (action) {
is MissionActionEntity.EnvAction -> {
if (action.envAction?.controlAction !== null) {
Expand All @@ -100,8 +97,23 @@ data class MissionEntity(
}
}
}

fun sortActions(
envActions: List<MissionActionEntity.EnvAction>,
fishActions: List<MissionActionEntity.FishAction>,
navActions: List<MissionActionEntity.NavAction>
): List<MissionActionEntity> {
return sortActionsAsc((envActions + fishActions + navActions))
}

fun sortActions(
actions: List<MissionActionEntity>,
): List<MissionActionEntity> {
return sortActionsAsc(actions)
}
}


private fun calculateMissionStatus(
startDateTimeUtc: Instant,
endDateTimeUtc: Instant? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.export

// if you update this enum, update it too in the API and frontend
enum class ExportModeEnum {
INDIVIDUAL_MISSION, // Export one single mission into one document
COMBINED_MISSIONS_IN_ONE, // Export several missions combined into one mission into one document
MULTIPLE_MISSIONS_ZIPPED // Export several missions into several documents into a zip
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.export

// if you update this enum, update it too in the API and frontend
enum class ExportReportTypeEnum {
ALL, // all at once
AEM, // aka tableaux AEM
PATROL // aka rapport de patrouille
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class FakeActionData {
portName = "La Rochelle",
actionType = MissionActionType.LAND_CONTROL,
actionDatetimeUtc = Instant.parse("2024-01-09T14:00:00Z"),
actionEndDatetimeUtc = Instant.parse("2024-01-09T18:00:00Z"),
flightGoals = listOf(),
logbookInfractions = listOf(),
gearInfractions = listOf(),
Expand Down Expand Up @@ -222,19 +223,21 @@ class FakeActionData {
),
flagState = CountryCode.FR,
isFromPoseidon = false,
observationsByUnit = "gfgfd"

)
)
val missionAction2 = MissionAction(
id = missionId + 2,
missionId = missionId,
completion = Completion.TO_COMPLETE,
completion = Completion.COMPLETED,
vesselId = 5232556,
vesselName = "Le POILLET",
latitude = 48.389999,
longitude = -4.490000,
facade = "Outre-Mer",
actionType = MissionActionType.SEA_CONTROL,
actionDatetimeUtc = Instant.parse("2024-01-09T11:00:00Z"),
actionEndDatetimeUtc = Instant.parse("2024-01-09T16:00:00Z"),
flightGoals = listOf(),
logbookInfractions = listOf(
LogbookInfraction(infractionType = InfractionType.WITHOUT_RECORD, natinf = 2212),
Expand Down Expand Up @@ -277,6 +280,7 @@ class FakeActionData {
isSeafarersControl = true,
flagState = CountryCode.FR,
isFromPoseidon = false,
observationsByUnit = "gfgfd"
)

val missionAction3 = MissionAction(
Expand All @@ -301,6 +305,6 @@ class FakeActionData {
isFromPoseidon = false,
userTrigram = "ACK"
)
return listOf(missionAction1, missionAction2, missionAction3)
return listOf(missionAction1, missionAction3)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +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.aem.AEMTableExport
import fr.gouv.dgampa.rapportnav.domain.entities.mission.MissionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.export.MissionAEMExportEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.export.MissionExportEntity
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.GetMission
import fr.gouv.dgampa.rapportnav.domain.use_cases.utils.FillAEMExcelRow
import fr.gouv.dgampa.rapportnav.infrastructure.utils.Base64Converter
Expand All @@ -27,7 +27,7 @@ class ExportMissionAEM(
) {

private val logger: Logger = LoggerFactory.getLogger(ExportMissionAEM::class.java)
fun execute(missionId: Int): MissionAEMExportEntity? {
fun execute(missionId: Int): MissionExportEntity? {
return try {

val inputStream = javaClass.getResourceAsStream(aemTemplatePath)
Expand All @@ -54,7 +54,7 @@ class ExportMissionAEM(

logger.info("ODS file created and converted to Base64")

return MissionAEMExportEntity(
return MissionExportEntity(
fileName = "Rapport_AEM.ods",
fileContent = base64Content
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ExportMissionRapportPatrouille(
return null
}

// to combine
val generalInfo: MissionGeneralInfoEntity? = getMissionGeneralInfoByMissionId.execute(missionId)
val service = getServiceById.execute(generalInfo?.serviceId)

Expand All @@ -88,6 +89,7 @@ class ExportMissionRapportPatrouille(
durationUnit = DurationUnit.HOURS
)

// to combine
val timeline = formatActionsForTimeline.formatTimeline(mission.actions)

val rescueInfo = getInfoAboutNavAction.execute(
Expand Down Expand Up @@ -131,6 +133,7 @@ class ExportMissionRapportPatrouille(
)
}

// to combine
// Bilan opérationnel
val proFishingSeaSummary = getMissionOperationalSummary.getProFishingSeaSummary(mission)
val proFishingLandSummary = getMissionOperationalSummary.getProFishingLandSummary(mission)
Expand Down Expand Up @@ -179,8 +182,8 @@ class ExportMissionRapportPatrouille(
"\${rescueInfoHours}" to (rescueInfo?.get("durationInHours") ?: ""),
"\${nauticalEventsInfoCount}" to (nauticalEventsInfo?.get("count") ?: ""),
"\${nauticalEventsInfoHours}" to (nauticalEventsInfo?.get("durationInHours") ?: ""),
"\${antiPollutionInfoCount}" to (nauticalEventsInfo?.get("count") ?: ""),
"\${antiPollutionInfoHours}" to (nauticalEventsInfo?.get("durationInHours") ?: ""),
"\${antiPollutionInfoCount}" to (antiPollutionInfo?.get("count") ?: ""),
"\${antiPollutionInfoHours}" to (antiPollutionInfo?.get("durationInHours") ?: ""),
"\${baaemAndVigimerInfoCount}" to (baaemAndVigimerInfo?.get("count") ?: ""),
"\${baaemAndVigimerInfoHours}" to (baaemAndVigimerInfo?.get("durationInHours") ?: ""),
"\${baaemAndVigimerInfoShips}" to "",
Expand Down Expand Up @@ -489,7 +492,7 @@ class ExportMissionRapportPatrouille(
table.setWidth("100%")

// Remove the initial empty row that is automatically created
if (table.rows.size > 0) {
if (table.rows.isNotEmpty()) {
table.removeRow(0)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.export.v2

import fr.gouv.dgampa.rapportnav.config.UseCase
import fr.gouv.dgampa.rapportnav.domain.entities.mission.MissionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.export.MissionExportEntity
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.GetMission
import fr.gouv.dgampa.rapportnav.domain.use_cases.utils.FormatDateTime
import org.slf4j.LoggerFactory

@UseCase
class ExportMissionAEMCombined(
private val formatDateTime: FormatDateTime,
private val exportMissionAEMSingle: ExportMissionAEMSingle,
private val getMissionById: GetMission,
) {

private val logger = LoggerFactory.getLogger(ExportMissionAEMCombined::class.java)


/**
* Returns a merged Rapport de Patrouille
* Taking several missions and combining them into one
*
* @param missionIds a list of Mission Ids
* @return a MissionExportEntity with file name and content
*/
fun execute(missionIds: List<Int>): MissionExportEntity? {

try {

// retrieve missions
var missions = mutableListOf<MissionEntity>()

for (missionId in missionIds) {
val mission = getMissionById.execute(missionId)
if (mission != null) {
missions.add(mission)
}
}

// bundle actions and other stuff
val firstMission = missions.first() // Take all other fields from the first mission
val combinedActions = missions.flatMap { it.actions.orEmpty() } // Aggregate all actions from all missions
val mission =
firstMission.copy(actions = MissionEntity.sortActions(combinedActions)) // Create a new instance with aggregated actions

// create file
val output = exportMissionAEMSingle.createFile(mission = mission)


return MissionExportEntity(
fileName = "tableaux-AEM-combinés_${formatDateTime.formatDate(missions.first().startDateTimeUtc)}.ods",
fileContent = output?.fileContent.orEmpty()
)

} catch (e: Exception) {
logger.error("[AEM] - error while generating report : ${e.message}")
return null
}
}

}
Loading

0 comments on commit 2b9ca66

Please sign in to comment.