Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.crew

import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew.MissionCrewAbsenceModel
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew.MissionCrewModel
import java.time.Instant
import java.time.LocalDate


data class MissionCrewAbsenceEntity(
val id: Int? = null,
val startDate: LocalDate? = null,
val endDate: LocalDate? = null,
val isAbsentFullMission: Boolean? = null,
val reason: String? = null,
) {

fun toMissionCrewAbsenceModel(crew: MissionCrewModel): MissionCrewAbsenceModel {
return MissionCrewAbsenceModel(
id = id,
startDate = startDate,
endDate = endDate,
isAbsentFullMission = isAbsentFullMission,
reason = reason,
missionCrew = crew
)
}

companion object {
fun fromMissionCrewAbsenceModel(model: MissionCrewAbsenceModel): MissionCrewAbsenceEntity {
return MissionCrewAbsenceEntity(
id = model.id,
startDate = model.startDate,
endDate = model.endDate,
isAbsentFullMission = model.isAbsentFullMission,
reason = model.reason,
)
}
}
}

Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.crew

import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew.MissionCrewModel
import java.time.Instant
import java.util.*

import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew.MissionCrewModel

data class MissionCrewEntity(
val id: Int? = null,
val agent: AgentEntity,
val agent: AgentEntity? = null,
val comment: String? = null,
val role: AgentRoleEntity? = null,
val missionId: Int? = null,
val missionIdUUID: UUID? = null,
val createdAt: Instant? = null,
val updatedAt: Instant? = null,
var fullName: String? = null,
val absences: List<MissionCrewAbsenceEntity>? = null
){

fun toMissionCrewModel(commentDefaultsToString: Boolean? = false): MissionCrewModel {
return MissionCrewModel(
var model = MissionCrewModel(
id = id,
missionId = missionId,
agent = agent.toAgentModel(),
agent = agent?.toAgentModel(),
role = role?.toAgentRoleModel(),
comment = if (comment == null && commentDefaultsToString == true) "" else comment,
missionIdUUID = missionIdUUID,
fullName = fullName,
)
model.absences = absences?.map { it.toMissionCrewAbsenceModel(model) }?.toMutableList() ?: mutableListOf()
return model
}

companion object {
Expand All @@ -34,11 +35,14 @@ data class MissionCrewEntity(
missionId = crew.missionId,
comment = crew.comment,
missionIdUUID = crew.missionIdUUID,
agent = crew.agent.let { AgentEntity.fromAgentModel(it) },
agent = crew.agent?.let { AgentEntity.fromAgentModel(it) },
role = crew.role?.let { AgentRoleEntity.fromAgentRoleModel(it) },
createdAt = crew.createdAt,
updatedAt = crew.updatedAt
absences = crew.absences.map { MissionCrewAbsenceEntity.fromMissionCrewAbsenceModel(it) },
fullName = crew.fullName,
)
}
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ class ExportMissionRapportPatrouille(

val crew: List<List<String?>> = listOf(
listOf("Fonction", "Nom", "Observation (formation, repos, mission, stage...)")
) + agentsCrew.map {
) + agentsCrew.map { row ->
val displayName = row.agent?.let { "${it.firstName} ${it.lastName}" }
?: row.fullName // fallback when agent == null

listOf(
it.role?.title,
"${it.agent.firstName} ${it.agent.lastName}",
it.comment.takeIf { comment -> !comment.isNullOrEmpty() } ?: "Présent"
row.role?.title,
displayName,
row.comment.takeIf { !it.isNullOrEmpty() } ?: "Présent"
)
}


// to combine
// Bilan opérationnel
val proFishingSeaSummary = getMissionOperationalSummary.getProFishingSeaSummary(mission)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,18 @@ class ExportMissionPatrolSingle(

val crew: List<List<String?>> = listOf(
listOf("Fonction", "Nom", "Observation (formation, repos, mission, stage...)")
) + agentsCrew.map {
) + agentsCrew.map { row ->
val displayName = row.agent?.let { "${it.firstName} ${it.lastName}" }
?: row.fullName // fallback when agent == null

listOf(
it.role?.title,
"${it.agent.firstName} ${it.agent.lastName}",
it.comment.takeIf { comment -> !comment.isNullOrEmpty() } ?: "Présent"
row.role?.title,
displayName,
row.comment.takeIf { !it.isNullOrEmpty() } ?: "Présent"
)
}


// Bilan opérationnel
val proFishingSeaSummary = getMissionOperationalSummary.getProFishingSeaSummary(mission)
val proFishingLandSummary = getMissionOperationalSummary.getProFishingLandSummary(mission)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,19 @@ class ExportMissionPatrolSingle2(

val crew: List<List<String?>> = listOf(
listOf("Fonction", "Nom", "Observation (formation, repos, mission, stage...)")
) + missionCrew.orEmpty().map {
) + missionCrew.orEmpty().map { row ->
val displayName = row.agent?.let { "${it.firstName} ${it.lastName}" }
?: row.fullName // fallback when agent == null

listOf(
it.role?.title,
"${it.agent.firstName} ${it.agent.lastName}",
it.comment.takeIf { comment -> !comment.isNullOrEmpty() } ?: "Présent"
row.role?.title,
displayName,
row.comment.takeIf { !it.isNullOrEmpty() } ?: "Présent"
)
}



// Bilan opérationnel
val operationalSummary = patrolData?.operationalSummary
val proFishingSeaSummary = operationalSummary?.proFishingSeaSummary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,45 @@ package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.crew

import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.crew.MissionCrewEntity
import java.util.UUID
import kotlin.collections.map
import kotlin.collections.orEmpty

data class MissionCrew(
val id: Int? = null,
val agent: Agent,
val agent: Agent? = null,
val missionId: Int? = null,
val comment: String? = null,
val role: AgentRole? = null,
val missionIdUUID: UUID? = null
val missionIdUUID: UUID? = null,
val absences: List<MissionCrewAbsence>? = null,
var fullName: String? = null,
) {

companion object {
fun fromMissionCrewEntity(crew: MissionCrewEntity): MissionCrew {
return MissionCrew(
id = crew.id,
missionId = crew.missionId,
agent = Agent.fromAgentEntity(crew.agent),
agent = crew.agent?.let { Agent.fromAgentEntity(it) },
role = crew.role?.let { AgentRole.fromAgentRoleEntity(it) },
comment = crew.comment,
missionIdUUID = crew.missionIdUUID
missionIdUUID = crew.missionIdUUID,
absences = crew.absences.orEmpty().map { MissionCrewAbsence.fromMissionCrewAbsenceEntity(it) },
fullName = crew.fullName,
)
}
}

fun toMissionCrewEntity(missionIdUUID: UUID?= null, missionId: Int? = null): MissionCrewEntity {
return MissionCrewEntity(
id = if (id == 0 || id == null) null else id,
agent = agent.toAgentEntity(),
missionIdUUID = missionIdUUID,
agent = agent?.toAgentEntity(),
missionId = missionId,
comment = comment,
role = role?.toAgentRoleEntity(),
missionIdUUID = missionIdUUID
absences = absences.orEmpty().map { it.toMissionCrewAbsenceEntity() },
fullName = fullName,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.crew

import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.crew.MissionCrewAbsenceEntity
import java.time.LocalDate

data class MissionCrewAbsence(
val id: Int? = null,
val startDate: LocalDate? = null,
val endDate: LocalDate? = null,
val isAbsentFullMission: Boolean? = null,
val reason: String? = null,
) {

companion object {
fun fromMissionCrewAbsenceEntity(crew: MissionCrewAbsenceEntity): MissionCrewAbsence {
return MissionCrewAbsence(
id = crew.id,
startDate = crew.startDate,
endDate = crew.endDate,
isAbsentFullMission = crew.isAbsentFullMission,
reason = crew.reason,
)
}
}

fun toMissionCrewAbsenceEntity(): MissionCrewAbsenceEntity {
return MissionCrewAbsenceEntity(
id = if (id == 0 || id == null) null else id,
startDate = startDate,
endDate = endDate,
isAbsentFullMission = isAbsentFullMission,
reason = reason,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew

import com.fasterxml.jackson.annotation.JsonIgnore
import jakarta.persistence.*
import org.springframework.data.annotation.CreatedBy
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedBy
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.Instant
import java.time.LocalDate

@Entity
@EntityListeners(AuditingEntityListener::class)
@Table(name = "mission_crew_absence")
class MissionCrewAbsenceModel(

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
var id: Int? = null,

@Column(name = "start_date", nullable = true)
var startDate: LocalDate? = null,

@Column(name = "end_date", nullable = true)
var endDate: LocalDate? = null,

@Column(name = "is_absent_full_mission", nullable = true)
var isAbsentFullMission: Boolean? = null,

@Column(name = "reason", nullable = true)
var reason: String? = null,

@CreatedDate
@Column(name = "created_at", updatable = false)
var createdAt: Instant? = null,

@LastModifiedDate
@Column(name = "updated_at")
var updatedAt: Instant? = null,

@CreatedBy
@Column(name = "created_by", updatable = false)
var createdBy: Int? = null,

@LastModifiedBy
@Column(name = "updated_by")
var updatedBy: Int? = null,
//
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "mission_crew_id", referencedColumnName = "id", nullable = true)
@JsonIgnore
var missionCrew: MissionCrewModel? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@ class MissionCrewModel(
var id: Int?,

@ManyToOne
@JoinColumn(name = "agent_id")
var agent: AgentModel,
@JoinColumn(name = "agent_id", nullable = true)
var agent: AgentModel? = null,

@Column(name = "full_name", nullable = true)
var fullName: String? = null,

@Column(name = "mission_id", nullable = true)
var missionId: Int? = null,

@Column(name = "mission_id_uuid", nullable = true)
var missionIdUUID: UUID? = null,

@Column(name = "comment", nullable = true)
var comment: String? = null,

@ManyToOne
@JoinColumn(name = "agent_role_id", nullable = true)
var role: AgentRoleModel?,

@Column(name = "mission_id_uuid", nullable = true)
var missionIdUUID: UUID? = null,

@CreatedDate
@Column(name = "created_at", nullable = true, updatable = false)
var createdAt: Instant? = null,
Expand All @@ -49,5 +52,13 @@ class MissionCrewModel(

@LastModifiedBy
@Column(name = "updated_by")
var updatedBy: Int? = null
var updatedBy: Int? = null,

@OneToMany(
mappedBy = "missionCrew",
cascade = [CascadeType.ALL],
orphanRemoval = true
)
var absences: MutableList<MissionCrewAbsenceModel> = mutableListOf()

)
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ class JPAMissionCrewRepository(
override fun save(crew: MissionCrewEntity): MissionCrewModel {
return try {
val crewModel = crew.toMissionCrewModel()
val agent = dbAgentRepository.findById(crew.agent.id!!).orElseThrow()
crewModel.agent = agent

if (crew.agent != null) {
val agent = dbAgentRepository.findById(crew.agent.id!!).orElseThrow()
crewModel.agent = agent
// TODO ask christian
// crewModel.fullName = listOf(crew.agent.firstName, crew.agent.lastName).joinToString(separator = " ")
}


if (crew.role !== null) {
val role = dbAgentRoleRepository.findById(crew.role.id!!).orElseThrow()
Expand Down
Loading
Loading