-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
430 additions
and
521 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...tlin/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/export/ExportReportTypeEnum.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
6 changes: 0 additions & 6 deletions
6
...in/fr/gouv/dgampa/rapportnav/domain/entities/mission/nav/export/MissionAEMExportEntity.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 0 additions & 94 deletions
94
.../kotlin/fr/gouv/dgampa/rapportnav/domain/use_cases/mission/export/ExportZipMissionsAEM.kt
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
.../fr/gouv/dgampa/rapportnav/domain/use_cases/mission/export/v2/ExportMissionAEMCombined.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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 = combinedActions) // Create a new instance with aggregated actions | ||
|
||
// create file | ||
val output = exportMissionAEMSingle.createFile(mission = mission) | ||
|
||
|
||
return MissionExportEntity( | ||
fileName = "Rapport de patrouille combiné - ${formatDateTime.formatDate(mission.startDateTimeUtc)}.odt", | ||
fileContent = output?.fileContent.orEmpty() | ||
) | ||
|
||
} catch (e: Exception) { | ||
logger.error("[AEM] - error while generating report : ${e.message}") | ||
return null | ||
} | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
...uv/dgampa/rapportnav/domain/use_cases/mission/export/v2/ExportMissionAEMMultipleZipped.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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.CompletenessForStatsStatusEnum | ||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.export.MissionExportEntity | ||
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.GetMission | ||
import org.slf4j.LoggerFactory | ||
import java.io.File | ||
|
||
@UseCase | ||
class ExportMissionAEMMultipleZipped( | ||
private val exportMissionAEMSingle: ExportMissionAEMSingle, | ||
private val getMissionById: GetMission, | ||
private val zipFiles: ZipFiles, | ||
) { | ||
|
||
private val logger = LoggerFactory.getLogger(ExportMissionAEMMultipleZipped::class.java) | ||
|
||
|
||
/** | ||
* Returns a zip with several Rapports de Patrouille | ||
* There will be one file per complete mission | ||
* | ||
* @param missionIds a list of Mission Ids | ||
* @return a MissionExportEntity with file name and content | ||
*/ | ||
fun execute(missionIds: List<Int>): MissionExportEntity? { | ||
try { | ||
val filesToZip = mutableListOf<File>(); | ||
|
||
// retrieve missions | ||
for (missionId in missionIds) { | ||
val mission = getMissionById.execute(missionId) | ||
|
||
// only keep complete missions | ||
if (mission != null && mission.completenessForStats?.status === CompletenessForStatsStatusEnum.COMPLETE) { | ||
val output = exportMissionAEMSingle.createFile(mission = mission) | ||
filesToZip.add(File(output?.fileContent.orEmpty())) | ||
|
||
} | ||
} | ||
|
||
// zip all files together | ||
val output = zipFiles.execute(filesToZip) | ||
|
||
return MissionExportEntity( | ||
fileName = "Rapports de patrouille.odt", | ||
fileContent = output | ||
) | ||
|
||
} catch (e: Exception) { | ||
logger.error("[ExportMissionAEMMultipleZipped] - error building zipped mission export ${e.message}") | ||
return null | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.