Skip to content

Commit

Permalink
Merge pull request #495 from MTES-MCT/fix/action-env-fish
Browse files Browse the repository at this point in the history
fix(action): fix env fish action over uuid
  • Loading branch information
aleckvincent authored Jan 13, 2025
2 parents 172a822 + 452b626 commit 2de46c5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.GetStatusForAct
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.MapEnvActionControlPlans
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.GetControlByActionId2
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction.GetInfractionsByActionId
import fr.gouv.dgampa.rapportnav.domain.utils.isValidUUID
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.action.FormattedEnvActionControlPlan
import org.slf4j.LoggerFactory

Expand All @@ -28,6 +29,7 @@ class GetEnvActionById(
logger.error("GetEnvActionById received a null missionId")
throw IllegalArgumentException("GetEnvActionById should not receive null missionId")
}
if (!isValidUUID(actionId)) return null
return try {
val envAction = getEnvAction(missionId = missionId, actionId = actionId) ?: return null
val entity = MissionEnvActionEntity.fromEnvAction(missionId, envAction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionFishActionEnt
import fr.gouv.dgampa.rapportnav.domain.repositories.mission.IFishActionRepository
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.GetStatusForAction
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.control.v2.GetControlByActionId2
import fr.gouv.dgampa.rapportnav.domain.utils.isValidUUID
import org.slf4j.LoggerFactory
import org.springframework.cache.annotation.Cacheable
import java.util.*

@UseCase
class GetFishActionById(
Expand All @@ -23,6 +25,7 @@ class GetFishActionById(
logger.error("GetFishActionById received a null missionId or actionId null")
throw IllegalArgumentException("GetFishActionById should not receive null missionId or actionId null")
}
if (!isInteger(actionId)) return null
return try {
val fishAction = getFishAction(missionId = missionId, actionId = actionId) ?: return null
val entity = MissionFishActionEntity.fromFishAction(fishAction)
Expand All @@ -40,4 +43,7 @@ class GetFishActionById(
it.id == Integer.valueOf(actionId)
}
}

private fun isInteger(actionId: String?): Boolean =
actionId?.let { runCatching { Integer.valueOf(actionId) }.isSuccess } == true
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GetFishActionListByMissionId(
}

private fun getFishActionList(missionId: Int): List<MissionAction> {
return fishActionRepo.findFishActions(missionId = missionId).filter {
return fishActionRepo.findFishActions(missionId = missionId).orEmpty().filter {
listOf(
MissionActionType.SEA_CONTROL,
MissionActionType.LAND_CONTROL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ class GetNavActionById(
private val logger = LoggerFactory.getLogger(GetNavActionById::class.java)

fun execute(actionId: String?): MissionNavActionEntity? {
if (!isValidUUID(actionId)) {
logger.error("GetNavActionById received an actionId that is not a valid UUID: $actionId, returning null...")
return null
}
if (!isValidUUID(actionId)) return null
return try {
val model = missionActionRepository.findById(UUID.fromString(actionId)).orElse(null) ?: return null
val entity = MissionNavActionEntity.fromMissionActionModel(model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GetNavActionListByMissionId(
}

private fun getNavActionList(missionId: Int): List<MissionActionModel> {
return navMissionActionRepository.findByMissionId(missionId = missionId)
return navMissionActionRepository.findByMissionId(missionId = missionId).orEmpty()
}

private fun processActions(actions: List<MissionActionModel>): List<MissionNavActionEntity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class MissionActionRestController(
@GetMapping("")
@Operation(summary = "Get the list of actions on a mission Id")
fun getActions(@PathVariable(name = "missionId") missionId: Int): List<MissionAction?> {
val envActions = getEnvActionByMissionId.execute(missionId = missionId)
val navActions = getNavActionByMissionId.execute(missionId = missionId)
val fishActions = getFIshListActionByMissionId.execute(missionId = missionId)
val envActions = getEnvActionByMissionId.execute(missionId = missionId).orEmpty()
val navActions = getNavActionByMissionId.execute(missionId = missionId).orEmpty()
val fishActions = getFIshListActionByMissionId.execute(missionId = missionId).orEmpty()
return (envActions + navActions + fishActions)
.sortedByDescending { action -> action.startDateTimeUtc }
.map { action -> MissionAction.fromMissionActionEntity(action) }
Expand Down Expand Up @@ -78,7 +78,7 @@ class MissionActionRestController(

@DeleteMapping("{actionId}")
@Operation(summary = "Delete a mission action")
fun deleteAction(@PathVariable(name = "actionId") actionId: String): Unit {
fun deleteAction(@PathVariable(name = "actionId") actionId: String, @PathVariable missionId: String): Unit {
deleteNavAction.execute(UUID.fromString(actionId))
}
}

0 comments on commit 2de46c5

Please sign in to comment.