Skip to content

Commit

Permalink
Finalize not nullable types
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Feb 4, 2025
1 parent bbf7384 commit b598126
Show file tree
Hide file tree
Showing 35 changed files with 206 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package fr.gouv.cnsp.monitorfish.domain.entities.last_position

import com.neovisionaries.i18n.CountryCode
import fr.gouv.cnsp.monitorfish.domain.entities.position.PositionType
import fr.gouv.cnsp.monitorfish.domain.entities.risk_factor.defaultDetectabilityRiskFactor
import fr.gouv.cnsp.monitorfish.domain.entities.risk_factor.defaultImpactRiskFactor
import fr.gouv.cnsp.monitorfish.domain.entities.risk_factor.defaultProbabilityRiskFactor
import fr.gouv.cnsp.monitorfish.domain.entities.risk_factor.defaultRiskFactor
import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselIdentifier
import java.time.Duration
import java.time.ZonedDateTime
Expand Down Expand Up @@ -41,17 +45,17 @@ data class LastPosition(
val gearOnboard: List<Gear>? = listOf(),
val segments: List<String>? = listOf(),
val speciesOnboard: List<Species>? = listOf(),
val totalWeightOnboard: Double? = null,
val totalWeightOnboard: Double = 0.0,
val lastControlDateTime: ZonedDateTime? = null,
val lastControlInfraction: Boolean? = null,
val postControlComment: String? = null,
val vesselIdentifier: VesselIdentifier,
val impactRiskFactor: Double? = null,
val probabilityRiskFactor: Double? = null,
val detectabilityRiskFactor: Double? = null,
val riskFactor: Double? = null,
val impactRiskFactor: Double = defaultImpactRiskFactor,
val probabilityRiskFactor: Double = defaultProbabilityRiskFactor,
val detectabilityRiskFactor: Double = defaultDetectabilityRiskFactor,
val riskFactor: Double = defaultRiskFactor,
val underCharter: Boolean? = null,
val isAtPort: Boolean? = null,
val isAtPort: Boolean = false,
val alerts: List<String>? = listOf(),
val beaconMalfunctionId: Int? = null,
val reportings: List<String> = listOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data class LogbookMessage(
// Reception date of the report by the data center
val integrationDateTime: ZonedDateTime,
var rawMessage: String? = null,
val transmissionFormat: LogbookTransmissionFormat?,
val transmissionFormat: LogbookTransmissionFormat,
val software: String? = null,
var acknowledgment: Acknowledgment? = null,
var isCorrectedByNewerMessage: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.gouv.cnsp.monitorfish.domain.entities.logbook

enum class LogbookTransmissionFormat {
MANUAL,
ERS,
FLUX,
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ data class VesselRiskFactor(
/** CFR (Community Fleet Register Number). */
val internalReferenceNumber: String? = null,
val vesselId: Int? = null,
val gearOnboard: List<Gear>? = listOf(),
val speciesOnboard: List<Species>? = listOf(),
val totalWeightOnboard: Double? = null,
val gearOnboard: List<Gear> = listOf(),
val speciesOnboard: List<Species> = listOf(),
val totalWeightOnboard: Double = 0.0,
val segments: List<String> = listOf(),
val probableSegments: List<String>? = listOf(),
val segmentHighestImpact: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ data class Vessel(
val vesselType: String? = null,
val sailingCategory: String? = null,
val sailingType: String? = null,
val declaredFishingGears: List<String>? = null,
val declaredFishingGears: List<String> = listOf(),
val pinger: Boolean? = null,
val navigationLicenceExpirationDate: Date? = null,
val navigationLicenceExtensionDate: Date? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.springframework.stereotype.Component

@Component
object ERSMapper {
private const val JSONB_NULL_STRING = "null"
const val JSONB_NULL_STRING = "null"

fun getERSMessageValueFromJSON(
mapper: ObjectMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class CreateOrUpdateManualPriorNotification(
reportDateTime = sentAt,
integrationDateTime = ZonedDateTime.now(),
rawMessage = null,
transmissionFormat = null,
transmissionFormat = LogbookTransmissionFormat.MANUAL,
software = null,
acknowledgment = null,
isCorrectedByNewerMessage = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ class GetVesselReportings(
logger.info("TIME_RECORD - 'archivedYearsToReportings' took $archivedYearsToReportingsTimeTaken")

val twelveMonthsAgo = ZonedDateTime.now().minusMonths(12)
val lastTwelveMonthsReportings = reportings.filter { reporting ->
reporting.validationDate?.isAfter(twelveMonthsAgo)
?: reporting.creationDate.isAfter(twelveMonthsAgo)
}
val lastTwelveMonthsReportings =
reportings.filter { reporting ->
reporting.validationDate?.isAfter(twelveMonthsAgo)
?: reporting.creationDate.isAfter(twelveMonthsAgo)
}

val (infractionSuspicionsSummary, infractionSuspicionsSummaryTimeTaken) =
measureTimedValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ class GetVesselRiskFactor(
private val logger: Logger = LoggerFactory.getLogger(GetVesselRiskFactor::class.java)

fun execute(internalReferenceNumber: String): VesselRiskFactor {
val riskFactor = riskFactorRepository.findByInternalReferenceNumber(internalReferenceNumber)
?: throw BackendUsageException(
BackendUsageErrorCode.NOT_FOUND_BUT_OK,
message = "No risk factor found for vessel $internalReferenceNumber",
)
val riskFactor =
riskFactorRepository.findByInternalReferenceNumber(internalReferenceNumber)
?: throw BackendUsageException(
BackendUsageErrorCode.NOT_FOUND_BUT_OK,
message = "No risk factor found for vessel $internalReferenceNumber",
)

return riskFactor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ data class LastPositionDataOutput(
val gearOnboard: List<GearLastPositionDataOutput>? = null,
val segments: List<String>? = listOf(),
val speciesOnboard: List<SpeciesLastPositionDataOutput>? = null,
val totalWeightOnboard: Double? = null,
val totalWeightOnboard: Double,
val lastControlDateTime: ZonedDateTime? = null,
val lastControlInfraction: Boolean? = null,
val vesselIdentifier: VesselIdentifier,
val underCharter: Boolean? = null,
val isAtPort: Boolean? = null,
val isAtPort: Boolean,
val beaconMalfunctionId: Int? = null,
) {
companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data class LogbookMessageDataOutput(
override val operationDateTime: ZonedDateTime?,
override val activityDateTime: ZonedDateTime?,
override val reportDateTime: ZonedDateTime?,
override val integrationDateTime: ZonedDateTime?,
override val integrationDateTime: ZonedDateTime,
override val internalReferenceNumber: String?,
override val externalReferenceNumber: String?,
override val ircs: String?,
Expand All @@ -29,7 +29,7 @@ data class LogbookMessageDataOutput(
override val isDeleted: Boolean,
override val message: LogbookMessageValue?,
override val isSentByFailoverSoftware: Boolean,
): BaseLogbookMessageDataOutput {
) : BaseLogbookMessageDataOutput {
companion object {
fun fromLogbookMessage(logbookMessage: LogbookMessage) =
LogbookMessageDataOutput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data class VesselDataOutput(
val vesselType: String? = null,
val sailingCategory: String? = null,
val sailingType: String? = null,
val declaredFishingGears: List<String>? = null,
val declaredFishingGears: List<String>,
val pinger: Boolean? = null,
val navigationLicenceExpirationDate: Date? = null,
val navigationLicenceExtensionDate: Date? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ data class LastPositionDataOutput(
val gearOnboard: List<GearLastPositionDataOutput>,
val segments: List<String>,
val speciesOnboard: List<SpeciesLastPositionDataOutput>,
val totalWeightOnboard: Double? = null,
val totalWeightOnboard: Double,
val lastControlDateTime: ZonedDateTime? = null,
val lastControlInfraction: Boolean? = null,
val postControlComment: String? = null,
val vesselIdentifier: VesselIdentifier,
val impactRiskFactor: Double? = null,
val probabilityRiskFactor: Double? = null,
val detectabilityRiskFactor: Double? = null,
val riskFactor: Double? = null,
val impactRiskFactor: Double,
val probabilityRiskFactor: Double,
val detectabilityRiskFactor: Double,
val riskFactor: Double,
val underCharter: Boolean? = null,
val isAtPort: Boolean? = null,
val isAtPort: Boolean,
val alerts: List<String>,
val beaconMalfunctionId: Int? = null,
val reportings: List<String> = listOf(),
Expand Down Expand Up @@ -77,8 +77,9 @@ data class LastPositionDataOutput(
registryPortName = position.registryPortName,
district = position.district,
districtCode = position.districtCode,
gearOnboard = position.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) }
?: listOf(),
gearOnboard =
position.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) }
?: listOf(),
segments = position.segments ?: listOf(),
speciesOnboard =
position.speciesOnboard?.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class LogbookMessageDataOutput(
override val operationDateTime: ZonedDateTime?,
override val activityDateTime: ZonedDateTime?,
override val reportDateTime: ZonedDateTime?,
override val integrationDateTime: ZonedDateTime?,
override val integrationDateTime: ZonedDateTime,
override val internalReferenceNumber: String?,
override val externalReferenceNumber: String?,
override val ircs: String?,
Expand All @@ -32,7 +32,7 @@ data class LogbookMessageDataOutput(
val rawMessage: String?,
val tripGears: List<LogbookMessageGearDataOutput>?,
val tripSegments: List<LogbookMessageTripSegmentDataOutput>?,
): BaseLogbookMessageDataOutput {
) : BaseLogbookMessageDataOutput {
companion object {
fun fromLogbookMessage(logbookMessage: LogbookMessage): LogbookMessageDataOutput {
val tripGears =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ data class RiskFactorDataOutput(
companion object {
fun fromVesselRiskFactor(vesselRiskFactor: VesselRiskFactor) =
RiskFactorDataOutput(
gearOnboard = vesselRiskFactor.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) } ?: listOf(),
gearOnboard =
vesselRiskFactor.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) }
?: listOf(),
segments = vesselRiskFactor.segments,
segmentHighestImpact = vesselRiskFactor.segmentHighestImpact,
segmentHighestPriority = vesselRiskFactor.segmentHighestPriority,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data class VesselDataOutput(
val vesselType: String? = null,
val sailingCategory: String? = null,
val sailingType: String? = null,
val declaredFishingGears: List<String>? = null,
val declaredFishingGears: List<String>,
val pinger: Boolean? = null,
val navigationLicenceExpirationDate: Date? = null,
val navigationLicenceExtensionDate: Date? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface BaseLogbookMessageDataOutput {
val operationDateTime: ZonedDateTime?
val activityDateTime: ZonedDateTime?
val reportDateTime: ZonedDateTime?
val integrationDateTime: ZonedDateTime?
val integrationDateTime: ZonedDateTime
val internalReferenceNumber: String?
val externalReferenceNumber: String?
val ircs: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ data class LastPositionEntity(
@Column(name = "species_onboard", columnDefinition = "jsonb")
val speciesOnboard: String? = null,
@Column(name = "total_weight_onboard")
val totalWeightOnboard: Double? = null,
val totalWeightOnboard: Double,
@Column(name = "last_control_datetime_utc")
val lastControlDateTime: ZonedDateTime? = null,
@Column(name = "last_control_infraction")
Expand All @@ -93,17 +93,17 @@ data class LastPositionEntity(
@Enumerated(EnumType.STRING)
val vesselIdentifier: VesselIdentifier,
@Column(name = "impact_risk_factor")
val impactRiskFactor: Double? = null,
val impactRiskFactor: Double,
@Column(name = "probability_risk_factor")
val probabilityRiskFactor: Double? = null,
val probabilityRiskFactor: Double,
@Column(name = "detectability_risk_factor")
val detectabilityRiskFactor: Double? = null,
val detectabilityRiskFactor: Double,
@Column(name = "risk_factor")
val riskFactor: Double? = null,
val riskFactor: Double,
@Column(name = "under_charter")
val underCharter: Boolean? = null,
@Column(name = "is_at_port")
val isAtPort: Boolean? = null,
val isAtPort: Boolean,
@Column(name = "alerts", columnDefinition = "varchar(200)[]")
val alerts: List<String>? = listOf(),
@Column(name = "beacon_malfunction_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package fr.gouv.cnsp.monitorfish.infrastructure.database.entities

import com.fasterxml.jackson.databind.ObjectMapper
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.*
import fr.gouv.cnsp.monitorfish.domain.mappers.ERSMapper.JSONB_NULL_STRING
import fr.gouv.cnsp.monitorfish.domain.mappers.ERSMapper.getERSMessageValueFromJSON
import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters.deserializeJSONList
import io.hypersistence.utils.hibernate.type.json.JsonBinaryType
import jakarta.persistence.*
import org.hibernate.annotations.JdbcType
Expand Down Expand Up @@ -54,23 +56,23 @@ data class LogbookReportEntity(
@Column(name = "log_type")
val messageType: String?,
@Type(JsonBinaryType::class)
@Column(name = "value", nullable = true, columnDefinition = "jsonb")
@Column(name = "value", columnDefinition = "jsonb")
val message: String?,
@Column(name = "integration_datetime_utc")
val integrationDateTime: Instant,
@JdbcType(PostgreSQLEnumJdbcType::class)
@Column(name = "transmission_format", columnDefinition = "logbook_message_transmission_format")
@Enumerated(EnumType.STRING)
val transmissionFormat: LogbookTransmissionFormat?,
val transmissionFormat: LogbookTransmissionFormat,
@Column(name = "software")
val software: String?,
@Column(name = "enriched")
val isEnriched: Boolean = false,
val isEnriched: Boolean,
@Type(JsonBinaryType::class)
@Column(name = "trip_gears", nullable = true, columnDefinition = "jsonb")
@Column(name = "trip_gears", columnDefinition = "jsonb")
val tripGears: String?,
@Type(JsonBinaryType::class)
@Column(name = "trip_segments", nullable = true, columnDefinition = "jsonb")
@Column(name = "trip_segments", columnDefinition = "jsonb")
val tripSegments: String?,
@Column(name = "is_test_message")
val isTestMessage: Boolean = false,
Expand Down Expand Up @@ -101,8 +103,8 @@ data class LogbookReportEntity(
messageType = logbookMessage.messageType,
operationCountry = null,
operationType = logbookMessage.operationType,
tripGears = null,
tripSegments = null,
tripGears = JSONB_NULL_STRING,
tripSegments = JSONB_NULL_STRING,
)
}

Expand Down Expand Up @@ -137,17 +139,4 @@ data class LogbookReportEntity(
tripSegments = tripSegments,
)
}

private fun <T> deserializeJSONList(
mapper: ObjectMapper,
json: String?,
clazz: Class<T>,
): List<T> =
json?.let {
mapper.readValue(
json,
mapper.typeFactory
.constructCollectionType(MutableList::class.java, clazz),
)
} ?: listOf()
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ data class ManualPriorNotificationEntity(
operationNumber = null,
operationType = LogbookOperationType.DAT,
reportDateTime = sentAt,
transmissionFormat = null,
transmissionFormat = LogbookTransmissionFormat.MANUAL,
tripGears = tripGears,
tripSegments = tripSegments,
vesselName = vesselName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class MissionActionEntity(
} ?: listOf(),
actionType = actionType,
actionDatetimeUtc = actionDatetimeUtc.atZone(ZoneOffset.UTC),
actionEndDatetimeUtc = actionEndDatetimeUtc?.let { it.atZone(ZoneOffset.UTC) },
actionEndDatetimeUtc = actionEndDatetimeUtc?.atZone(ZoneOffset.UTC),
emitsVms = emitsVms,
emitsAis = emitsAis,
logbookMatchesActivity = logbookMatchesActivity,
Expand Down
Loading

0 comments on commit b598126

Please sign in to comment.