Skip to content

Commit

Permalink
Save work on Controls and EnvControls
Browse files Browse the repository at this point in the history
  • Loading branch information
lwih committed Oct 26, 2023
1 parent 23cadfa commit 84144f9
Show file tree
Hide file tree
Showing 38 changed files with 498 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselSizeEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselTypeEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.*
import fr.gouv.dgampa.rapportnav.infrastructure.bff.model.NavActionControl
import fr.gouv.dgampa.rapportnav.infrastructure.bff.model.control.NavActionControl
import java.time.ZonedDateTime
import java.util.*

Expand Down Expand Up @@ -51,10 +51,10 @@ data class ActionControlEntity(
vesselType = vesselType,
vesselSize = vesselSize,
identityControlledPerson = identityControlledPerson,
controlAdministrative = controlAdministrative,
controlGensDeMer = controlGensDeMer,
controlNavigation = controlNavigation,
controlSecurity = controlSecurity,
controlAdministrative = controlAdministrative?.toControlAdministrative(),
controlGensDeMer = controlGensDeMer?.toControlGensDeMer(),
controlNavigation = controlNavigation?.toControlNavigation(),
controlSecurity = controlSecurity?.toControlSecurity(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action

import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.status.ActionStatusReason
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.status.ActionStatusType
import fr.gouv.dgampa.rapportnav.infrastructure.bff.model.NavActionStatus
import fr.gouv.dgampa.rapportnav.infrastructure.bff.model.control.NavActionStatus
import java.time.ZonedDateTime
import java.util.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class GetNavMissionById(

fun execute(missionId: Int): NavMissionEntity {
val controls = navActionControlRepository.findAllByMissionId(missionId=missionId).filter { it.deletedAt == null }.map { it.toNavAction() }
// TODO filter controls that have been deleted
val statuses = navStatusRepository.findAllByMissionId(missionId=missionId).filter { it.deletedAt == null }.map { it.toNavAction() }
val actions = controls + statuses
val mission = NavMissionEntity(id = missionId, actions = actions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlAdm
@UseCase
class AddOrUpdateControlAdministrative(private val repository: IControlAdministrativeRepository) {
fun execute(control: ControlAdministrativeEntity): ControlAdministrativeEntity {
val savedData = this.repository.save(control).toControlAdministrative()
val savedData = this.repository.save(control).toControlAdministrativeEntity()
return savedData
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlGen
@UseCase
class AddOrUpdateControlGensDeMer(private val repository: IControlGensDeMerRepository) {
fun execute(control: ControlGensDeMerEntity): ControlGensDeMerEntity {
val savedData = this.repository.save(control).toControlGensDeMer()
val savedData = this.repository.save(control).toControlGensDeMerEntity()
return savedData
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlNav
@UseCase
class AddOrUpdateControlNavigation(private val controlNavigationRepository: IControlNavigationRepository) {
fun execute(control: ControlNavigationEntity): ControlNavigationEntity {
val savedData = this.controlNavigationRepository.save(control).toControlNavigation()
val savedData = this.controlNavigationRepository.save(control).toControlNavigationEntity()
return savedData
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlSec
@UseCase
class AddOrUpdateControlSecurity(private val repository: IControlSecurityRepository) {
fun execute(control: ControlSecurityEntity): ControlSecurityEntity {
val savedData = this.repository.save(control).toControlSecurity()
val savedData = this.repository.save(control).toControlSecurityEntity()
return savedData
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ class DeleteControl(
if (controlGensDeMerRepository.existsByActionControlId(actionControlId = id)) {
val controlGensDeMer = controlGensDeMerRepository.findByActionControlId(actionControlId = id)
controlGensDeMer.deletedAt = ZonedDateTime.now()
controlGensDeMerRepository.save(controlGensDeMer.toControlGensDeMer())
controlGensDeMerRepository.save(controlGensDeMer.toControlGensDeMerEntity())

}
if (controlAdministrativeRepository.existsByActionControlId(actionControlId = id)) {
val controlAdministrative = controlAdministrativeRepository.findByActionControlId(actionControlId = id)
controlAdministrative.deletedAt = ZonedDateTime.now()
controlAdministrativeRepository.save(controlAdministrative.toControlAdministrative())
controlAdministrativeRepository.save(controlAdministrative.toControlAdministrativeEntity())
}
if (controlNavigationRepository.existsByActionControlId(actionControlId = id)) {
val controlNavigation = controlNavigationRepository.findByActionControlId(actionControlId = id)
controlNavigation.deletedAt = ZonedDateTime.now()
controlNavigationRepository.save(controlNavigation.toControlNavigation())
controlNavigationRepository.save(controlNavigation.toControlNavigationEntity())
}
if (controlSecurityRepository.existsByActionControlId(actionControlId = id)) {
val controlSecurity = controlSecurityRepository.findByActionControlId(actionControlId = id)
controlSecurity.deletedAt = ZonedDateTime.now()
controlSecurityRepository.save(controlSecurity.toControlSecurity())
controlSecurityRepository.save(controlSecurity.toControlSecurityEntity())
}

val controlAction = this.controlRepository.findById(id = id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fr.gouv.dgampa.rapportnav.domain.use_cases.missions.control

import fr.gouv.dgampa.rapportnav.config.UseCase
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlAdministrativeEntity
import fr.gouv.dgampa.rapportnav.domain.repositories.mission.control.IControlAdministrativeRepository
import java.util.*

@UseCase
class GetControlAdministrativeByActionId(private val repository: IControlAdministrativeRepository) {
fun execute(actionControlId: UUID): ControlAdministrativeEntity? {
if (this.repository.existsByActionControlId(actionControlId = actionControlId)) {
return this.repository.findByActionControlId(actionControlId = actionControlId).toControlAdministrativeEntity()
}

return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import fr.gouv.dgampa.rapportnav.domain.use_cases.missions.control.DeleteControl
import fr.gouv.dgampa.rapportnav.domain.use_cases.missions.status.AddOrUpdateStatus
import fr.gouv.dgampa.rapportnav.domain.use_cases.missions.status.DeleteStatus
import fr.gouv.dgampa.rapportnav.domain.use_cases.missions.status.GetStatusForAction
import fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters.ActionControlInput
import fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters.ActionStatusInput
import fr.gouv.dgampa.rapportnav.infrastructure.bff.model.*
import fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters.action.ActionControlInput
import fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters.action.ActionStatusInput
import fr.gouv.dgampa.rapportnav.infrastructure.bff.model.control.*
import org.springframework.graphql.data.method.annotation.Argument
import org.springframework.graphql.data.method.annotation.MutationMapping
import org.springframework.graphql.data.method.annotation.SchemaMapping
Expand Down Expand Up @@ -101,14 +101,14 @@ class ActionController(
return ActionType.OTHER
}

@SchemaMapping(typeName = "EnvActionData", field = "amountOfControlsToComplete")
fun getEnvAmountOfControlsToComplete(action: EnvActionData): Int? {
return listOf(
action.isAdministrativeControl,
action.isComplianceWithWaterRegulationsControl,
action.isSafetyEquipmentAndStandardsComplianceControl,
action.isSeafarersControl
).count { it == true }
}
// @SchemaMapping(typeName = "EnvActionData", field = "amountOfControlsToComplete")
// fun getEnvAmountOfControlsToComplete(action: EnvActionData): Int? {
// return listOf(
// action.isAdministrativeControl,
// action.isComplianceWithWaterRegulationsControl,
// action.isSafetyEquipmentAndStandardsComplianceControl,
// action.isSeafarersControl
// ).count { it == true }
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package fr.gouv.dgampa.rapportnav.infrastructure.bff

import fr.gouv.dgampa.rapportnav.domain.use_cases.missions.control.GetControlAdministrativeByActionId
import fr.gouv.dgampa.rapportnav.infrastructure.bff.model.control.ControlAdministrative
import fr.gouv.dgampa.rapportnav.infrastructure.bff.model.control.EnvActionData
import org.springframework.graphql.data.method.annotation.SchemaMapping
import org.springframework.stereotype.Controller


@Controller
class ActionEnvController(
private val getControlAdministrativeByActionId: GetControlAdministrativeByActionId,
) {

// @MutationMapping
// fun addOrUpdateControl(@Argument controlAction: ActionControlInput): NavActionControl {
// val data = controlAction.toActionControl()
// val aa = addOrUpdateControl.execute(data)
// return aa.toNavActionControl()
// }
//
// @MutationMapping
// fun deleteControl(@Argument id: UUID): Boolean {
// val savedData = deleteControl.execute(id)
// return savedData
// }

@SchemaMapping(typeName = "EnvActionData", field = "controlAdministrative")
fun getControlAdministrative(action: EnvActionData): ControlAdministrative? {
if (action.id == null) {
return null
}
val cc = getControlAdministrativeByActionId.execute(actionControlId = action.id)?.toControlAdministrative()
return cc

}
@SchemaMapping(typeName = "EnvActionData", field = "amountOfControlsToComplete")
fun getEnvAmountOfControlsToComplete(action: EnvActionData): Int? {
return listOf(
action.isAdministrativeControl,
action.isComplianceWithWaterRegulationsControl,
action.isSafetyEquipmentAndStandardsComplianceControl,
action.isSeafarersControl
).count { it == true }
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters

import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.NavMissionEntity
import fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters.action.ActionInput

data class MissionInput(
val id: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters
package fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters.action

import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselSizeEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.VesselTypeEnum
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters
package fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters.action

import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionType
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.NavActionEntity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters
package fr.gouv.dgampa.rapportnav.infrastructure.bff.adapters.action

import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ActionStatusEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.status.ActionStatusReason
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fr.gouv.dgampa.rapportnav.infrastructure.bff.model
import fr.gouv.dgampa.rapportnav.domain.entities.mission.MissionActionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.MissionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum
import fr.gouv.dgampa.rapportnav.infrastructure.bff.model.control.Action
import java.time.ZonedDateTime

data class Mission(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.gouv.dgampa.rapportnav.infrastructure.bff.model
package fr.gouv.dgampa.rapportnav.infrastructure.bff.model.control

import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionControlEntity
Expand Down Expand Up @@ -42,7 +42,6 @@ data class Action(
isComplianceWithWaterRegulationsControl = envAction.isComplianceWithWaterRegulationsControl,
isSafetyEquipmentAndStandardsComplianceControl = envAction.isSafetyEquipmentAndStandardsComplianceControl,
isSeafarersControl = envAction.isSeafarersControl,

)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package fr.gouv.dgampa.rapportnav.infrastructure.bff.model
package fr.gouv.dgampa.rapportnav.infrastructure.bff.model.control

import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.*
import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.ControlUnit
import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.*
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.status.ActionStatusReason
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.status.ActionStatusType
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.*
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlMethod
import org.locationtech.jts.geom.Geometry
import java.time.ZonedDateTime
import java.util.*
Expand All @@ -30,6 +30,10 @@ data class EnvActionData(
val isComplianceWithWaterRegulationsControl: Boolean? = null,
val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null,
val isSeafarersControl: Boolean? = null,
val controlAdministrative: ControlAdministrative? = null,
val controlGensDeMer: ControlGensDeMer? = null,
val controlNavigation: ControlNavigation? = null,
val controlSecurity: ControlSecurity? = null
) : ActionData()

data class FishActionData(
Expand Down Expand Up @@ -79,7 +83,11 @@ data class FishActionData(
val controlUnits: List<ControlUnit>,
val isDeleted: Boolean,
val hasSomeGearsSeized: Boolean,
val hasSomeSpeciesSeized: Boolean
val hasSomeSpeciesSeized: Boolean,
val controlAdministrative: ControlAdministrative? = null,
val controlGensDeMer: ControlGensDeMer? = null,
val controlNavigation: ControlNavigation? = null,
val controlSecurity: ControlSecurity? = null
) : ActionData()


Expand Down Expand Up @@ -107,8 +115,8 @@ data class NavActionControl(
val vesselType: VesselTypeEnum? = null,
val vesselSize: VesselSizeEnum? = null,
val identityControlledPerson: String? = null,
val controlAdministrative: ControlAdministrativeEntity?,
val controlGensDeMer: ControlGensDeMerEntity?,
val controlNavigation: ControlNavigationEntity?,
val controlSecurity: ControlSecurityEntity?
val controlAdministrative: ControlAdministrative?,
val controlGensDeMer: ControlGensDeMer?,
val controlNavigation: ControlNavigation?,
val controlSecurity: ControlSecurity?
) : ActionData()
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ data class ActionControlModel(
observations = observations,
identityControlledPerson = identityControlledPerson,
deletedAt = deletedAt,
controlAdministrative = controlAdministrative?.toControlAdministrative(),
controlGensDeMer = controlGensDeMer?.toControlGensDeMer(),
controlNavigation = controlNavigation?.toControlNavigation(),
controlSecurity = controlSecurity?.toControlSecurity()
controlAdministrative = controlAdministrative?.toControlAdministrativeEntity(),
controlGensDeMer = controlGensDeMer?.toControlGensDeMerEntity(),
controlNavigation = controlNavigation?.toControlNavigationEntity(),
controlSecurity = controlSecurity?.toControlSecurityEntity()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ data class ControlAdministrativeModel(
var actionControl: ActionControlModel? = null

) {
fun toControlAdministrative() = ControlAdministrativeEntity(
fun toControlAdministrativeEntity() = ControlAdministrativeEntity(
id = id,
missionId = missionId,
actionControlId = actionControlId,
Expand All @@ -67,7 +67,7 @@ data class ControlAdministrativeModel(
)

companion object {
fun fromControlAdministrative(control: ControlAdministrativeEntity, actionControl: ActionControlModel): ControlAdministrativeModel {
fun fromControlAdministrativeEntity(control: ControlAdministrativeEntity, actionControl: ActionControlModel): ControlAdministrativeModel {
return ControlAdministrativeModel(
id = control.id,
missionId = control.missionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ data class ControlGensDeMerModel(
@JsonIgnore
var actionControl: ActionControlModel? = null
) {
fun toControlGensDeMer() = ControlGensDeMerEntity(
fun toControlGensDeMerEntity() = ControlGensDeMerEntity(
id = id,
missionId = missionId,
actionControlId = actionControlId,
Expand All @@ -66,7 +66,7 @@ data class ControlGensDeMerModel(
)

companion object {
fun fromControlGensDeMer(control: ControlGensDeMerEntity, actionControl: ActionControlModel) = ControlGensDeMerModel(
fun fromControlGensDeMerEntity(control: ControlGensDeMerEntity, actionControl: ActionControlModel) = ControlGensDeMerModel(
id = control.id,
missionId = control.missionId,
actionControlId = actionControl.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data class ControlNavigationModel(
@JsonIgnore
var actionControl: ActionControlModel? = null
) {
fun toControlNavigation() = ControlNavigationEntity(
fun toControlNavigationEntity() = ControlNavigationEntity(
id = id,
missionId = missionId,
actionControlId = actionControlId,
Expand All @@ -52,7 +52,7 @@ data class ControlNavigationModel(
)

companion object {
fun fromControlNavigation(control: ControlNavigationEntity, actionControl: ActionControlModel) = ControlNavigationModel(
fun fromControlNavigationEntity(control: ControlNavigationEntity, actionControl: ActionControlModel) = ControlNavigationModel(
id = control.id,
missionId = control.missionId,
actionControlId = actionControl.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data class ControlSecurityModel(
@JsonIgnore
var actionControl: ActionControlModel? = null
) {
fun toControlSecurity() = ControlSecurityEntity(
fun toControlSecurityEntity() = ControlSecurityEntity(
id = id,
missionId = missionId,
actionControlId = actionControlId,
Expand All @@ -52,7 +52,7 @@ data class ControlSecurityModel(
)

companion object {
fun fromControlSecurity(control: ControlSecurityEntity, actionControl: ActionControlModel) = ControlSecurityModel(
fun fromControlSecurityEntity(control: ControlSecurityEntity, actionControl: ActionControlModel) = ControlSecurityModel(
id = control.id,
missionId = control.missionId,
actionControlId = actionControl.id,
Expand Down
Loading

0 comments on commit 84144f9

Please sign in to comment.