-
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.
[Missions] API publique ne peut pas écrire sur les envActions (#1078)
resolves #879 Pas de changement coté Fish nécessaire. Il n'est cependant plus nécessaire de renvoyer les envActions.
- Loading branch information
Showing
10 changed files
with
348 additions
and
185 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...ain/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActions.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,88 @@ | ||
package fr.gouv.cacem.monitorenv.domain.use_cases.missions | ||
|
||
import fr.gouv.cacem.monitorenv.config.UseCase | ||
import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity | ||
import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.ActionTypeEnum | ||
import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.EnvActionEntity | ||
import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.EnvActionNoteEntity | ||
import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.EnvActionSurveillanceEntity | ||
import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.envActionControl.EnvActionControlEntity | ||
import fr.gouv.cacem.monitorenv.domain.repositories.IDepartmentAreaRepository | ||
import fr.gouv.cacem.monitorenv.domain.repositories.IFacadeAreasRepository | ||
import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository | ||
|
||
@UseCase | ||
class CreateOrUpdateEnvActions( | ||
private val departmentRepository: IDepartmentAreaRepository, | ||
private val facadeRepository: IFacadeAreasRepository, | ||
private val missionRepository: IMissionRepository, | ||
) { | ||
@Throws(IllegalArgumentException::class) | ||
fun execute( | ||
mission: MissionEntity, | ||
envActions: List<EnvActionEntity>?, | ||
): MissionEntity { | ||
val envActionsToSave = | ||
envActions?.map { | ||
when (it.actionType) { | ||
ActionTypeEnum.CONTROL -> { | ||
(it as EnvActionControlEntity).copy( | ||
facade = | ||
(it.geom ?: mission.geom)?.let { geom -> | ||
facadeRepository.findFacadeFromGeometry(geom) | ||
}, | ||
department = | ||
(it.geom ?: mission.geom)?.let { geom -> | ||
departmentRepository.findDepartmentFromGeometry( | ||
geom, | ||
) | ||
}, | ||
) | ||
} | ||
ActionTypeEnum.SURVEILLANCE -> { | ||
val surveillance = it as EnvActionSurveillanceEntity | ||
/* | ||
When coverMissionZone is true, use mission geometry in priority, fall back to action geometry. | ||
When coverMissionZone is not true, prioritize the other way around. | ||
Ideally the fallbacks should not be needed, but if coverMissionZone is true and the mission geom | ||
is null, or if coverMissionZone is false and the action geom is null, then rather that nothing, | ||
better use the geometry that is available, if any. | ||
*/ | ||
val geometry = | ||
if (surveillance.coverMissionZone == true) { | ||
(mission.geom ?: surveillance.geom) | ||
} else { | ||
(surveillance.geom ?: mission.geom) | ||
} | ||
surveillance.copy( | ||
facade = | ||
geometry?.let { geom -> | ||
facadeRepository.findFacadeFromGeometry(geom) | ||
}, | ||
department = | ||
geometry?.let { geom -> | ||
departmentRepository.findDepartmentFromGeometry( | ||
geom, | ||
) | ||
}, | ||
) | ||
} | ||
ActionTypeEnum.NOTE -> { | ||
(it as EnvActionNoteEntity).copy() | ||
} | ||
} | ||
} | ||
|
||
val missionToSave = | ||
mission.copy( | ||
envActions = envActionsToSave, | ||
) | ||
val savedMission = missionRepository.save(missionToSave) | ||
|
||
if (savedMission.mission.id == null) { | ||
throw IllegalArgumentException("Mission id is null") | ||
} | ||
|
||
return savedMission.mission | ||
} | ||
} |
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
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.