-
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.
Merge pull request #68 from MTES-MCT/fixes
Allow editing target for Env infractions on targets reported by the u…
- Loading branch information
Showing
44 changed files
with
2,337 additions
and
2,178 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
...gampa/rapportnav/domain/repositories/mission/infraction/IInfractionEnvTargetRepository.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,11 @@ | ||
package fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction | ||
|
||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity | ||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEnvTargetEntity | ||
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.infraction.InfractionEnvTargetModel | ||
|
||
interface IInfractionEnvTargetRepository { | ||
fun save(infractionTarget: InfractionEnvTargetEntity, infraction: InfractionEntity): InfractionEnvTargetModel | ||
|
||
fun findByActionIdAndVesselIdentifier(actionId: String, vesselIdentifier: String): List<InfractionEnvTargetModel> | ||
} |
16 changes: 16 additions & 0 deletions
16
...v/dgampa/rapportnav/domain/use_cases/mission/infraction/AddOrUpdateInfractionEnvTarget.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,16 @@ | ||
package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction | ||
|
||
import fr.gouv.dgampa.rapportnav.config.UseCase | ||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity | ||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEnvTargetEntity | ||
import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionEnvTargetRepository | ||
|
||
@UseCase | ||
class AddOrUpdateInfractionEnvTarget( | ||
private val repo: IInfractionEnvTargetRepository, | ||
) { | ||
fun execute(infractionTarget: InfractionEnvTargetEntity, infraction: InfractionEntity): InfractionEnvTargetEntity { | ||
val savedData = repo.save(infractionTarget, infraction).toInfractionEnvTargetEntity() | ||
return savedData | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
...ouv/dgampa/rapportnav/domain/use_cases/mission/infraction/IsControlledAllowedForTarget.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,20 @@ | ||
package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.infraction | ||
|
||
import fr.gouv.dgampa.rapportnav.config.UseCase | ||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlType | ||
import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionEnvTargetRepository | ||
|
||
@UseCase | ||
class IsControlledAllowedForTarget( | ||
private val repo: IInfractionEnvTargetRepository, | ||
private val getInfractionById: GetInfractionById, | ||
) { | ||
fun execute(actionId: String, vesselIdentifier: String, controlType: ControlType): Boolean { | ||
val targets = repo.findByActionIdAndVesselIdentifier(actionId = actionId, vesselIdentifier = vesselIdentifier) | ||
val controlledAllowed = targets.map { | ||
val infraction = it.infraction?.toInfractionEntity() | ||
return controlType != infraction?.controlType | ||
} | ||
return controlledAllowed.all { true } | ||
} | ||
} |
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
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
9 changes: 9 additions & 0 deletions
9
...e/database/repositories/interfaces/mission/infraction/IDBInfractionEnvTargetRepository.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,9 @@ | ||
package fr.gouv.dgampa.rapportnav.infrastructure.database.repositories.interfaces.mission.infraction | ||
|
||
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.infraction.InfractionEnvTargetModel | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import java.util.* | ||
|
||
interface IDBInfractionEnvTargetRepository : JpaRepository<InfractionEnvTargetModel, UUID> { | ||
fun findByActionIdAndVesselIdentifier(actionId: String, vesselIdentifier: String): List<InfractionEnvTargetModel> | ||
} |
44 changes: 44 additions & 0 deletions
44
...frastructure/database/repositories/mission/infraction/JPAInfractionEnvTargetRepository.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,44 @@ | ||
package fr.gouv.dgampa.rapportnav.infrastructure.database.repositories.mission.infraction | ||
|
||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity | ||
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEnvTargetEntity | ||
import fr.gouv.dgampa.rapportnav.domain.repositories.mission.infraction.IInfractionEnvTargetRepository | ||
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.infraction.InfractionEnvTargetModel | ||
import fr.gouv.dgampa.rapportnav.infrastructure.database.repositories.interfaces.mission.infraction.IDBInfractionEnvTargetRepository | ||
import org.springframework.dao.InvalidDataAccessApiUsageException | ||
import org.springframework.stereotype.Repository | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
|
||
@Repository | ||
class JPAInfractionEnvTargetRepository( | ||
private val dbRepo: IDBInfractionEnvTargetRepository, | ||
) : IInfractionEnvTargetRepository { | ||
|
||
@Transactional | ||
override fun save( | ||
infractionTarget: InfractionEnvTargetEntity, | ||
infraction: InfractionEntity | ||
): InfractionEnvTargetModel { | ||
return try { | ||
val model = InfractionEnvTargetModel.fromInfractionEnvTargetEntity(infractionTarget, infraction) | ||
dbRepo.save(model) | ||
} catch (e: InvalidDataAccessApiUsageException) { | ||
throw Exception("Error saving or updating Infraction Env Target", e) | ||
} | ||
} | ||
|
||
override fun findByActionIdAndVesselIdentifier( | ||
actionId: String, | ||
vesselIdentifier: String | ||
): List<InfractionEnvTargetModel> { | ||
return try { | ||
val models = dbRepo.findByActionIdAndVesselIdentifier(actionId, vesselIdentifier) | ||
models | ||
} catch (e: InvalidDataAccessApiUsageException) { | ||
throw Exception("Error findByActionIdAndVesselIdentifier Infraction Env Target", e) | ||
} | ||
} | ||
|
||
|
||
} |
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.