-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUpdateNavAction.kt
34 lines (31 loc) · 1.66 KB
/
UpdateNavAction.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2
import fr.gouv.dgampa.rapportnav.config.UseCase
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionNavActionEntity
import fr.gouv.dgampa.rapportnav.domain.repositories.mission.action.INavMissionActionRepository
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.ProcessMissionActionControl
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.v2.ProcessMissionActionInfraction
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionActionInput
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.adapters.v2.MissionNavActionDataInput
import org.slf4j.LoggerFactory
@UseCase
class UpdateNavAction(
private val missionActionRepository: INavMissionActionRepository,
private val processMissionActionControl: ProcessMissionActionControl,
private val processMissionActionInfraction: ProcessMissionActionInfraction
) {
private val logger = LoggerFactory.getLogger(UpdateNavAction::class.java)
fun execute(input: MissionActionInput): MissionNavActionEntity? {
val action = MissionNavActionDataInput.toMissionNavActionEntity(input)
return try {
missionActionRepository.save(action)
val controls = processMissionActionControl.execute(action)
val infractions = processMissionActionInfraction.execute(action.getActionId(), controls)
controls.processInfractions(infractions)
action.computeControls(controls)
action
} catch (e: Exception) {
logger.error("UpdateNavAction failed update Action", e)
return null
}
}
}