Skip to content

Commit b598126

Browse files
committed
Finalize not nullable types
1 parent bbf7384 commit b598126

35 files changed

+206
-135
lines changed

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/last_position/LastPosition.kt

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package fr.gouv.cnsp.monitorfish.domain.entities.last_position
22

33
import com.neovisionaries.i18n.CountryCode
44
import fr.gouv.cnsp.monitorfish.domain.entities.position.PositionType
5+
import fr.gouv.cnsp.monitorfish.domain.entities.risk_factor.defaultDetectabilityRiskFactor
6+
import fr.gouv.cnsp.monitorfish.domain.entities.risk_factor.defaultImpactRiskFactor
7+
import fr.gouv.cnsp.monitorfish.domain.entities.risk_factor.defaultProbabilityRiskFactor
8+
import fr.gouv.cnsp.monitorfish.domain.entities.risk_factor.defaultRiskFactor
59
import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselIdentifier
610
import java.time.Duration
711
import java.time.ZonedDateTime
@@ -41,17 +45,17 @@ data class LastPosition(
4145
val gearOnboard: List<Gear>? = listOf(),
4246
val segments: List<String>? = listOf(),
4347
val speciesOnboard: List<Species>? = listOf(),
44-
val totalWeightOnboard: Double? = null,
48+
val totalWeightOnboard: Double = 0.0,
4549
val lastControlDateTime: ZonedDateTime? = null,
4650
val lastControlInfraction: Boolean? = null,
4751
val postControlComment: String? = null,
4852
val vesselIdentifier: VesselIdentifier,
49-
val impactRiskFactor: Double? = null,
50-
val probabilityRiskFactor: Double? = null,
51-
val detectabilityRiskFactor: Double? = null,
52-
val riskFactor: Double? = null,
53+
val impactRiskFactor: Double = defaultImpactRiskFactor,
54+
val probabilityRiskFactor: Double = defaultProbabilityRiskFactor,
55+
val detectabilityRiskFactor: Double = defaultDetectabilityRiskFactor,
56+
val riskFactor: Double = defaultRiskFactor,
5357
val underCharter: Boolean? = null,
54-
val isAtPort: Boolean? = null,
58+
val isAtPort: Boolean = false,
5559
val alerts: List<String>? = listOf(),
5660
val beaconMalfunctionId: Int? = null,
5761
val reportings: List<String> = listOf(),

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data class LogbookMessage(
2626
// Reception date of the report by the data center
2727
val integrationDateTime: ZonedDateTime,
2828
var rawMessage: String? = null,
29-
val transmissionFormat: LogbookTransmissionFormat?,
29+
val transmissionFormat: LogbookTransmissionFormat,
3030
val software: String? = null,
3131
var acknowledgment: Acknowledgment? = null,
3232
var isCorrectedByNewerMessage: Boolean = false,
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.gouv.cnsp.monitorfish.domain.entities.logbook
22

33
enum class LogbookTransmissionFormat {
4+
MANUAL,
45
ERS,
56
FLUX,
67
}

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/risk_factor/VesselRiskFactor.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ data class VesselRiskFactor(
3434
/** CFR (Community Fleet Register Number). */
3535
val internalReferenceNumber: String? = null,
3636
val vesselId: Int? = null,
37-
val gearOnboard: List<Gear>? = listOf(),
38-
val speciesOnboard: List<Species>? = listOf(),
39-
val totalWeightOnboard: Double? = null,
37+
val gearOnboard: List<Gear> = listOf(),
38+
val speciesOnboard: List<Species> = listOf(),
39+
val totalWeightOnboard: Double = 0.0,
4040
val segments: List<String> = listOf(),
4141
val probableSegments: List<String>? = listOf(),
4242
val segmentHighestImpact: String? = null,

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/vessel/Vessel.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ data class Vessel(
3232
val vesselType: String? = null,
3333
val sailingCategory: String? = null,
3434
val sailingType: String? = null,
35-
val declaredFishingGears: List<String>? = null,
35+
val declaredFishingGears: List<String> = listOf(),
3636
val pinger: Boolean? = null,
3737
val navigationLicenceExpirationDate: Date? = null,
3838
val navigationLicenceExtensionDate: Date? = null,

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ERSMapper.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.springframework.stereotype.Component
1010

1111
@Component
1212
object ERSMapper {
13-
private const val JSONB_NULL_STRING = "null"
13+
const val JSONB_NULL_STRING = "null"
1414

1515
fun getERSMessageValueFromJSON(
1616
mapper: ObjectMapper,

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotification.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class CreateOrUpdateManualPriorNotification(
122122
reportDateTime = sentAt,
123123
integrationDateTime = ZonedDateTime.now(),
124124
rawMessage = null,
125-
transmissionFormat = null,
125+
transmissionFormat = LogbookTransmissionFormat.MANUAL,
126126
software = null,
127127
acknowledgment = null,
128128
isCorrectedByNewerMessage = false,

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/GetVesselReportings.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ class GetVesselReportings(
7878
logger.info("TIME_RECORD - 'archivedYearsToReportings' took $archivedYearsToReportingsTimeTaken")
7979

8080
val twelveMonthsAgo = ZonedDateTime.now().minusMonths(12)
81-
val lastTwelveMonthsReportings = reportings.filter { reporting ->
82-
reporting.validationDate?.isAfter(twelveMonthsAgo)
83-
?: reporting.creationDate.isAfter(twelveMonthsAgo)
84-
}
81+
val lastTwelveMonthsReportings =
82+
reportings.filter { reporting ->
83+
reporting.validationDate?.isAfter(twelveMonthsAgo)
84+
?: reporting.creationDate.isAfter(twelveMonthsAgo)
85+
}
8586

8687
val (infractionSuspicionsSummary, infractionSuspicionsSummaryTimeTaken) =
8788
measureTimedValue {

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselRiskFactor.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ class GetVesselRiskFactor(
1515
private val logger: Logger = LoggerFactory.getLogger(GetVesselRiskFactor::class.java)
1616

1717
fun execute(internalReferenceNumber: String): VesselRiskFactor {
18-
val riskFactor = riskFactorRepository.findByInternalReferenceNumber(internalReferenceNumber)
19-
?: throw BackendUsageException(
20-
BackendUsageErrorCode.NOT_FOUND_BUT_OK,
21-
message = "No risk factor found for vessel $internalReferenceNumber",
22-
)
18+
val riskFactor =
19+
riskFactorRepository.findByInternalReferenceNumber(internalReferenceNumber)
20+
?: throw BackendUsageException(
21+
BackendUsageErrorCode.NOT_FOUND_BUT_OK,
22+
message = "No risk factor found for vessel $internalReferenceNumber",
23+
)
2324

2425
return riskFactor
2526
}

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LastPositionDataOutput.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ data class LastPositionDataOutput(
3737
val gearOnboard: List<GearLastPositionDataOutput>? = null,
3838
val segments: List<String>? = listOf(),
3939
val speciesOnboard: List<SpeciesLastPositionDataOutput>? = null,
40-
val totalWeightOnboard: Double? = null,
40+
val totalWeightOnboard: Double,
4141
val lastControlDateTime: ZonedDateTime? = null,
4242
val lastControlInfraction: Boolean? = null,
4343
val vesselIdentifier: VesselIdentifier,
4444
val underCharter: Boolean? = null,
45-
val isAtPort: Boolean? = null,
45+
val isAtPort: Boolean,
4646
val beaconMalfunctionId: Int? = null,
4747
) {
4848
companion object {

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LogbookMessageDataOutput.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ data class LogbookMessageDataOutput(
1717
override val operationDateTime: ZonedDateTime?,
1818
override val activityDateTime: ZonedDateTime?,
1919
override val reportDateTime: ZonedDateTime?,
20-
override val integrationDateTime: ZonedDateTime?,
20+
override val integrationDateTime: ZonedDateTime,
2121
override val internalReferenceNumber: String?,
2222
override val externalReferenceNumber: String?,
2323
override val ircs: String?,
@@ -29,7 +29,7 @@ data class LogbookMessageDataOutput(
2929
override val isDeleted: Boolean,
3030
override val message: LogbookMessageValue?,
3131
override val isSentByFailoverSoftware: Boolean,
32-
): BaseLogbookMessageDataOutput {
32+
) : BaseLogbookMessageDataOutput {
3333
companion object {
3434
fun fromLogbookMessage(logbookMessage: LogbookMessage) =
3535
LogbookMessageDataOutput(

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VesselDataOutput.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ data class VesselDataOutput(
2525
val vesselType: String? = null,
2626
val sailingCategory: String? = null,
2727
val sailingType: String? = null,
28-
val declaredFishingGears: List<String>? = null,
28+
val declaredFishingGears: List<String>,
2929
val pinger: Boolean? = null,
3030
val navigationLicenceExpirationDate: Date? = null,
3131
val navigationLicenceExtensionDate: Date? = null,

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LastPositionDataOutput.kt

+9-8
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ data class LastPositionDataOutput(
3535
val gearOnboard: List<GearLastPositionDataOutput>,
3636
val segments: List<String>,
3737
val speciesOnboard: List<SpeciesLastPositionDataOutput>,
38-
val totalWeightOnboard: Double? = null,
38+
val totalWeightOnboard: Double,
3939
val lastControlDateTime: ZonedDateTime? = null,
4040
val lastControlInfraction: Boolean? = null,
4141
val postControlComment: String? = null,
4242
val vesselIdentifier: VesselIdentifier,
43-
val impactRiskFactor: Double? = null,
44-
val probabilityRiskFactor: Double? = null,
45-
val detectabilityRiskFactor: Double? = null,
46-
val riskFactor: Double? = null,
43+
val impactRiskFactor: Double,
44+
val probabilityRiskFactor: Double,
45+
val detectabilityRiskFactor: Double,
46+
val riskFactor: Double,
4747
val underCharter: Boolean? = null,
48-
val isAtPort: Boolean? = null,
48+
val isAtPort: Boolean,
4949
val alerts: List<String>,
5050
val beaconMalfunctionId: Int? = null,
5151
val reportings: List<String> = listOf(),
@@ -77,8 +77,9 @@ data class LastPositionDataOutput(
7777
registryPortName = position.registryPortName,
7878
district = position.district,
7979
districtCode = position.districtCode,
80-
gearOnboard = position.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) }
81-
?: listOf(),
80+
gearOnboard =
81+
position.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) }
82+
?: listOf(),
8283
segments = position.segments ?: listOf(),
8384
speciesOnboard =
8485
position.speciesOnboard?.map {

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageDataOutput.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ data class LogbookMessageDataOutput(
1515
override val operationDateTime: ZonedDateTime?,
1616
override val activityDateTime: ZonedDateTime?,
1717
override val reportDateTime: ZonedDateTime?,
18-
override val integrationDateTime: ZonedDateTime?,
18+
override val integrationDateTime: ZonedDateTime,
1919
override val internalReferenceNumber: String?,
2020
override val externalReferenceNumber: String?,
2121
override val ircs: String?,
@@ -32,7 +32,7 @@ data class LogbookMessageDataOutput(
3232
val rawMessage: String?,
3333
val tripGears: List<LogbookMessageGearDataOutput>?,
3434
val tripSegments: List<LogbookMessageTripSegmentDataOutput>?,
35-
): BaseLogbookMessageDataOutput {
35+
) : BaseLogbookMessageDataOutput {
3636
companion object {
3737
fun fromLogbookMessage(logbookMessage: LogbookMessage): LogbookMessageDataOutput {
3838
val tripGears =

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/RiskFactorDataOutput.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ data class RiskFactorDataOutput(
2626
companion object {
2727
fun fromVesselRiskFactor(vesselRiskFactor: VesselRiskFactor) =
2828
RiskFactorDataOutput(
29-
gearOnboard = vesselRiskFactor.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) } ?: listOf(),
29+
gearOnboard =
30+
vesselRiskFactor.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) }
31+
?: listOf(),
3032
segments = vesselRiskFactor.segments,
3133
segmentHighestImpact = vesselRiskFactor.segmentHighestImpact,
3234
segmentHighestPriority = vesselRiskFactor.segmentHighestPriority,

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VesselDataOutput.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data class VesselDataOutput(
2626
val vesselType: String? = null,
2727
val sailingCategory: String? = null,
2828
val sailingType: String? = null,
29-
val declaredFishingGears: List<String>? = null,
29+
val declaredFishingGears: List<String>,
3030
val pinger: Boolean? = null,
3131
val navigationLicenceExpirationDate: Date? = null,
3232
val navigationLicenceExtensionDate: Date? = null,

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/interfaces/BaseLogbookMessageDataOutput.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface BaseLogbookMessageDataOutput {
1313
val operationDateTime: ZonedDateTime?
1414
val activityDateTime: ZonedDateTime?
1515
val reportDateTime: ZonedDateTime?
16-
val integrationDateTime: ZonedDateTime?
16+
val integrationDateTime: ZonedDateTime
1717
val internalReferenceNumber: String?
1818
val externalReferenceNumber: String?
1919
val ircs: String?

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LastPositionEntity.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ data class LastPositionEntity(
8282
@Column(name = "species_onboard", columnDefinition = "jsonb")
8383
val speciesOnboard: String? = null,
8484
@Column(name = "total_weight_onboard")
85-
val totalWeightOnboard: Double? = null,
85+
val totalWeightOnboard: Double,
8686
@Column(name = "last_control_datetime_utc")
8787
val lastControlDateTime: ZonedDateTime? = null,
8888
@Column(name = "last_control_infraction")
@@ -93,17 +93,17 @@ data class LastPositionEntity(
9393
@Enumerated(EnumType.STRING)
9494
val vesselIdentifier: VesselIdentifier,
9595
@Column(name = "impact_risk_factor")
96-
val impactRiskFactor: Double? = null,
96+
val impactRiskFactor: Double,
9797
@Column(name = "probability_risk_factor")
98-
val probabilityRiskFactor: Double? = null,
98+
val probabilityRiskFactor: Double,
9999
@Column(name = "detectability_risk_factor")
100-
val detectabilityRiskFactor: Double? = null,
100+
val detectabilityRiskFactor: Double,
101101
@Column(name = "risk_factor")
102-
val riskFactor: Double? = null,
102+
val riskFactor: Double,
103103
@Column(name = "under_charter")
104104
val underCharter: Boolean? = null,
105105
@Column(name = "is_at_port")
106-
val isAtPort: Boolean? = null,
106+
val isAtPort: Boolean,
107107
@Column(name = "alerts", columnDefinition = "varchar(200)[]")
108108
val alerts: List<String>? = listOf(),
109109
@Column(name = "beacon_malfunction_id")

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookReportEntity.kt

+9-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.entities
22

33
import com.fasterxml.jackson.databind.ObjectMapper
44
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.*
5+
import fr.gouv.cnsp.monitorfish.domain.mappers.ERSMapper.JSONB_NULL_STRING
56
import fr.gouv.cnsp.monitorfish.domain.mappers.ERSMapper.getERSMessageValueFromJSON
7+
import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters.deserializeJSONList
68
import io.hypersistence.utils.hibernate.type.json.JsonBinaryType
79
import jakarta.persistence.*
810
import org.hibernate.annotations.JdbcType
@@ -54,23 +56,23 @@ data class LogbookReportEntity(
5456
@Column(name = "log_type")
5557
val messageType: String?,
5658
@Type(JsonBinaryType::class)
57-
@Column(name = "value", nullable = true, columnDefinition = "jsonb")
59+
@Column(name = "value", columnDefinition = "jsonb")
5860
val message: String?,
5961
@Column(name = "integration_datetime_utc")
6062
val integrationDateTime: Instant,
6163
@JdbcType(PostgreSQLEnumJdbcType::class)
6264
@Column(name = "transmission_format", columnDefinition = "logbook_message_transmission_format")
6365
@Enumerated(EnumType.STRING)
64-
val transmissionFormat: LogbookTransmissionFormat?,
66+
val transmissionFormat: LogbookTransmissionFormat,
6567
@Column(name = "software")
6668
val software: String?,
6769
@Column(name = "enriched")
68-
val isEnriched: Boolean = false,
70+
val isEnriched: Boolean,
6971
@Type(JsonBinaryType::class)
70-
@Column(name = "trip_gears", nullable = true, columnDefinition = "jsonb")
72+
@Column(name = "trip_gears", columnDefinition = "jsonb")
7173
val tripGears: String?,
7274
@Type(JsonBinaryType::class)
73-
@Column(name = "trip_segments", nullable = true, columnDefinition = "jsonb")
75+
@Column(name = "trip_segments", columnDefinition = "jsonb")
7476
val tripSegments: String?,
7577
@Column(name = "is_test_message")
7678
val isTestMessage: Boolean = false,
@@ -101,8 +103,8 @@ data class LogbookReportEntity(
101103
messageType = logbookMessage.messageType,
102104
operationCountry = null,
103105
operationType = logbookMessage.operationType,
104-
tripGears = null,
105-
tripSegments = null,
106+
tripGears = JSONB_NULL_STRING,
107+
tripSegments = JSONB_NULL_STRING,
106108
)
107109
}
108110

@@ -137,17 +139,4 @@ data class LogbookReportEntity(
137139
tripSegments = tripSegments,
138140
)
139141
}
140-
141-
private fun <T> deserializeJSONList(
142-
mapper: ObjectMapper,
143-
json: String?,
144-
clazz: Class<T>,
145-
): List<T> =
146-
json?.let {
147-
mapper.readValue(
148-
json,
149-
mapper.typeFactory
150-
.constructCollectionType(MutableList::class.java, clazz),
151-
)
152-
} ?: listOf()
153142
}

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ManualPriorNotificationEntity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ data class ManualPriorNotificationEntity(
103103
operationNumber = null,
104104
operationType = LogbookOperationType.DAT,
105105
reportDateTime = sentAt,
106-
transmissionFormat = null,
106+
transmissionFormat = LogbookTransmissionFormat.MANUAL,
107107
tripGears = tripGears,
108108
tripSegments = tripSegments,
109109
vesselName = vesselName,

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class MissionActionEntity(
232232
} ?: listOf(),
233233
actionType = actionType,
234234
actionDatetimeUtc = actionDatetimeUtc.atZone(ZoneOffset.UTC),
235-
actionEndDatetimeUtc = actionEndDatetimeUtc?.let { it.atZone(ZoneOffset.UTC) },
235+
actionEndDatetimeUtc = actionEndDatetimeUtc?.atZone(ZoneOffset.UTC),
236236
emitsVms = emitsVms,
237237
emitsAis = emitsAis,
238238
logbookMatchesActivity = logbookMatchesActivity,

0 commit comments

Comments
 (0)