-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMissionFishActionEntity.kt
189 lines (179 loc) · 9.62 KB
/
MissionFishActionEntity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package fr.gouv.dgampa.rapportnav.domain.entities.mission.v2
import com.neovisionaries.i18n.CountryCode
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.InfractionTypeEnum
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.ActionType
import fr.gouv.dgampa.rapportnav.domain.utils.EntityCompletenessValidator
import java.time.Instant
data class FishInfraction(val natinf: Int?, val infractionType: InfractionType?)
class MissionFishActionEntity(
override val id: Int?,
override val missionId: Int,
override val vesselId: Int? = null,
override val vesselName: String? = null,
override val internalReferenceNumber: String? = null,
override val externalReferenceNumber: String? = null,
override val ircs: String? = null,
override val flagState: CountryCode? = null,
override val districtCode: String? = null,
override val faoAreas: List<String>? = null,
override val fishActionType: MissionActionType,
override val actionDatetimeUtc: Instant? = null,
override val actionEndDatetimeUtc: Instant? = null,
override val emitsVms: ControlCheck? = null,
override val emitsAis: ControlCheck? = null,
override val flightGoals: List<FlightGoal>? = listOf(),
override val logbookMatchesActivity: ControlCheck? = null,
override val licencesMatchActivity: ControlCheck? = null,
override val speciesWeightControlled: Boolean? = null,
override val speciesSizeControlled: Boolean? = null,
override val separateStowageOfPreservedSpecies: ControlCheck? = null,
override val logbookInfractions: List<LogbookInfraction>? = listOf(),
override val licencesAndLogbookObservations: String? = null,
override val gearInfractions: List<GearInfraction>? = listOf(),
override val speciesInfractions: List<SpeciesInfraction>? = listOf(),
override val speciesObservations: String? = null,
override val seizureAndDiversion: Boolean? = null,
override val otherInfractions: List<OtherInfraction>? = listOf(),
override val numberOfVesselsFlownOver: Int? = null,
override val unitWithoutOmegaGauge: Boolean? = null,
override val controlQualityComments: String? = null,
override val feedbackSheetRequired: Boolean? = null,
override val userTrigram: String? = null,
override val segments: List<FleetSegment>? = listOf(),
override val facade: String? = null,
override val longitude: Double? = null,
override val latitude: Double? = null,
override val portLocode: String? = null,
override var portName: String? = null,
override val vesselTargeted: ControlCheck? = null,
override val seizureAndDiversionComments: String? = null,
override val otherComments: String? = null,
override val gearOnboard: List<GearControl>? = listOf(),
override val speciesOnboard: List<SpeciesControl>? = listOf(),
override val isFromPoseidon: Boolean? = null,
override var controlUnits: List<ControlUnit>? = listOf(),
override val isDeleted: Boolean? = null,
override val hasSomeGearsSeized: Boolean? = null,
override val hasSomeSpeciesSeized: Boolean? = null,
override val completedBy: String? = null,
override val completion: Completion? = null,
override val isAdministrativeControl: Boolean? = null,
override val isComplianceWithWaterRegulationsControl: Boolean? = null,
override val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null,
override val isSeafarersControl: Boolean? = null,
override var observationsByUnit: String? = null,
override var speciesQuantitySeized: Int? = null,
) : MissionActionEntity(
missionId = missionId,
actionType = ActionType.CONTROL,
isCompleteForStats = false,
endDateTimeUtc = actionEndDatetimeUtc,
startDateTimeUtc = actionDatetimeUtc,
source = MissionSourceEnum.MONITORFISH,
isSeafarersControl = isSeafarersControl,
isAdministrativeControl = isAdministrativeControl,
isComplianceWithWaterRegulationsControl = isComplianceWithWaterRegulationsControl,
isSafetyEquipmentAndStandardsComplianceControl = isSafetyEquipmentAndStandardsComplianceControl,
), BaseMissionFishAction {
override fun getActionId(): String {
return id.toString()
}
override fun computeSummaryTags() {
val navInfractions = this.getControlInfractions()
val fishInfractions: List<FishInfraction> = listOf(
this.gearInfractions?.map { FishInfraction(it.natinf, it.infractionType) },
this.logbookInfractions?.map { FishInfraction(it.natinf, it.infractionType) },
this.speciesInfractions?.map { FishInfraction(it.natinf, it.infractionType) },
this.otherInfractions?.map { FishInfraction(it.natinf, it.infractionType) }
).filterNotNull().flatten()
val fishWithReport = fishInfractions.count { it.infractionType == InfractionType.WITH_RECORD }
val navWithReport = navInfractions.count { it.infractionType == InfractionTypeEnum.WITH_REPORT }
val infractionTag = getInfractionTag(fishWithReport + navWithReport)
val navNatinfs = navInfractions.flatMap { it.natinfs ?: emptyList() }
val fishNatinfs = fishInfractions.map { it.natinf.toString() }
val withReportNatinf = (navNatinfs + fishNatinfs).count { true }
val natinfTag = getNatinfTag(withReportNatinf)
this.summaryTags = listOf(infractionTag, natinfTag)
}
override fun computeCompleteness() {
val sourcesOfMissingDataForStats = mutableListOf<MissionSourceEnum>()
val rapportNavComplete = EntityCompletenessValidator.isCompleteForStats(this)
val monitorFishComplete = this.completion === Completion.COMPLETED
if (!rapportNavComplete) {
sourcesOfMissingDataForStats.add(MissionSourceEnum.RAPPORTNAV)
}
if (!monitorFishComplete) {
sourcesOfMissingDataForStats.add(MissionSourceEnum.MONITORFISH)
}
this.isCompleteForStats = rapportNavComplete && monitorFishComplete
this.sourcesOfMissingDataForStats = sourcesOfMissingDataForStats
this.computeSummaryTags()
this.computeControlsToComplete()
this.computeCompletenessForStats()
}
companion object {
fun fromFishAction(action: FishAction) = MissionFishActionEntity(
id = action.id,
missionId = action.missionId,
fishActionType = action.actionType,
actionDatetimeUtc = action.actionDatetimeUtc,
actionEndDatetimeUtc = action.actionEndDatetimeUtc,
vesselId = action.vesselId,
vesselName = action.vesselName,
internalReferenceNumber = action.internalReferenceNumber,
externalReferenceNumber = action.externalReferenceNumber,
ircs = action.ircs,
flagState = action.flagState,
districtCode = action.districtCode,
faoAreas = action.faoAreas,
emitsVms = action.emitsVms,
emitsAis = action.emitsAis,
flightGoals = action.flightGoals,
logbookMatchesActivity = action.logbookMatchesActivity,
licencesMatchActivity = action.licencesMatchActivity,
speciesWeightControlled = action.speciesWeightControlled,
speciesSizeControlled = action.speciesSizeControlled,
separateStowageOfPreservedSpecies = action.separateStowageOfPreservedSpecies,
logbookInfractions = action.logbookInfractions,
licencesAndLogbookObservations = action.licencesAndLogbookObservations,
gearInfractions = action.gearInfractions,
speciesInfractions = action.speciesInfractions,
speciesObservations = action.speciesObservations,
seizureAndDiversion = action.seizureAndDiversion,
otherInfractions = action.otherInfractions,
numberOfVesselsFlownOver = action.numberOfVesselsFlownOver,
unitWithoutOmegaGauge = action.unitWithoutOmegaGauge,
controlQualityComments = action.controlQualityComments,
feedbackSheetRequired = action.feedbackSheetRequired,
userTrigram = action.userTrigram,
segments = action.segments,
facade = action.facade,
longitude = action.longitude,
latitude = action.latitude,
portLocode = action.portLocode,
// This field is only used when fetching missions
portName = action.portName,
vesselTargeted = action.vesselTargeted,
seizureAndDiversionComments = action.seizureAndDiversionComments,
otherComments = action.otherComments,
gearOnboard = action.gearOnboard,
speciesOnboard = action.speciesOnboard,
isFromPoseidon = action.isFromPoseidon,
controlUnits = action.controlUnits,
isDeleted = action.isDeleted,
hasSomeGearsSeized = action.hasSomeGearsSeized,
hasSomeSpeciesSeized = action.hasSomeSpeciesSeized,
completedBy = action.completedBy,
completion = action.completion,
isAdministrativeControl = action.isAdministrativeControl,
isComplianceWithWaterRegulationsControl = action.isComplianceWithWaterRegulationsControl,
isSafetyEquipmentAndStandardsComplianceControl = action.isSafetyEquipmentAndStandardsComplianceControl,
isSeafarersControl = action.isSeafarersControl,
observationsByUnit = action.observationsByUnit,
speciesQuantitySeized = action.speciesQuantitySeized
)
}
}