Skip to content

Commit

Permalink
Tech - Nettoyage de types ts, kotlin et postgres (#4056)
Browse files Browse the repository at this point in the history
## Linked issues

- Resolve #4057
- Validation des types frontend avec `zod`
- Migrations des types Vessel dans le namespace Vessel
- Migration d'APIs vers RTK pour finaliser l'utilisation de `undefined`
au lieu de `null`

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
louptheron authored Feb 5, 2025
2 parents 93de2f5 + 0418079 commit 0770123
Show file tree
Hide file tree
Showing 218 changed files with 2,461 additions and 2,152 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ jobs:
uses: actions/checkout@v4

- name: Download image
uses: ishworkh/docker-image-artifact-download@v1
uses: ishworkh/container-image-artifact-download@v2.0.0
with:
image: monitorfish-app:${{ env.VERSION }}

Expand Down Expand Up @@ -307,7 +307,7 @@ jobs:
fetch-depth: 100

- name: Download image
uses: ishworkh/docker-image-artifact-download@v1
uses: ishworkh/container-image-artifact-download@v2.0.0
with:
image: monitorfish-app:${{ env.VERSION }}

Expand Down Expand Up @@ -353,7 +353,7 @@ jobs:
uses: actions/checkout@v4

- name: Download image
uses: ishworkh/docker-image-artifact-download@v1
uses: ishworkh/container-image-artifact-download@v2.0.0
with:
image: monitorfish-app:${{ env.VERSION }}

Expand Down
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,19 +34,19 @@ 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 segments: List<String>? = listOf(),
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,
val segmentHighestPriority: String? = null,
val lastControlDatetime: ZonedDateTime? = null,
val postControlComments: String? = null,
val numberControlsLastFiveYears: Short? = null,
val numberControlsLastThreeYears: Short? = null,
val numberInfractionsLastFiveYears: Short? = null,
val numberGearSeizuresLastFiveYears: Short? = null,
val numberSpeciesSeizuresLastFiveYears: Short? = null,
val numberVesselSeizuresLastFiveYears: Short? = null,
val numberControlsLastFiveYears: Short = 0,
val numberControlsLastThreeYears: Short = 0,
val numberInfractionsLastFiveYears: Short = 0,
val numberGearSeizuresLastFiveYears: Short = 0,
val numberSpeciesSeizuresLastFiveYears: Short = 0,
val numberVesselSeizuresLastFiveYears: Short = 0,
)
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 @@ -2,6 +2,8 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.vessel

import fr.gouv.cnsp.monitorfish.config.UseCase
import fr.gouv.cnsp.monitorfish.domain.entities.risk_factor.VesselRiskFactor
import fr.gouv.cnsp.monitorfish.domain.exceptions.BackendUsageErrorCode
import fr.gouv.cnsp.monitorfish.domain.exceptions.BackendUsageException
import fr.gouv.cnsp.monitorfish.domain.repositories.RiskFactorRepository
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand All @@ -13,11 +15,12 @@ class GetVesselRiskFactor(
private val logger: Logger = LoggerFactory.getLogger(GetVesselRiskFactor::class.java)

fun execute(internalReferenceNumber: String): VesselRiskFactor {
val riskFactor = riskFactorRepository.findByInternalReferenceNumber(internalReferenceNumber)

requireNotNull(riskFactor) {
"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 @@ -54,7 +54,7 @@ class VesselController(

@GetMapping("/find")
@Operation(summary = "Get vessel information and positions")
fun getVessel(
fun getVesselAndPositions(
@Parameter(description = "Vessel internal id")
@RequestParam(name = "vesselId")
vesselId: Int?,
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 @@ -4,43 +4,42 @@ import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookMessage
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookOperationType
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.messages.Acknowledgment
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.messages.LogbookMessageValue
import fr.gouv.cnsp.monitorfish.infrastructure.api.outputs.interfaces.BaseLogbookMessageDataOutput
import java.time.ZonedDateTime

data class LogbookMessageDataOutput(
val reportId: String? = null,
val operationNumber: String?,
val tripNumber: String? = null,
val referencedReportId: String? = null,
var isCorrected: Boolean? = false,
val operationType: LogbookOperationType,
val operationDateTime: ZonedDateTime? = null,
val activityDateTime: ZonedDateTime? = null,
val reportDateTime: ZonedDateTime? = null,
val integrationDateTime: ZonedDateTime? = null,
val internalReferenceNumber: String? = null,
val externalReferenceNumber: String? = null,
val ircs: String? = null,
val vesselName: String? = null,
/** ISO Alpha-3 country code. **/
val flagState: String? = null,
val imo: String? = null,
val messageType: String? = null,
var acknowledgment: Acknowledgment? = null,
var deleted: Boolean? = false,
val message: LogbookMessageValue? = null,
var rawMessage: String? = null,
val isSentByFailoverSoftware: Boolean,
) {
override val reportId: String?,
override val operationNumber: String?,
override val tripNumber: String?,
override val referencedReportId: String?,
override val isCorrectedByNewerMessage: Boolean,
override val operationType: LogbookOperationType,
override val operationDateTime: ZonedDateTime?,
override val activityDateTime: ZonedDateTime?,
override val reportDateTime: ZonedDateTime?,
override val integrationDateTime: ZonedDateTime,
override val internalReferenceNumber: String?,
override val externalReferenceNumber: String?,
override val ircs: String?,
override val vesselName: String?,
override val flagState: String?,
override val imo: String?,
override val messageType: String?,
override val acknowledgment: Acknowledgment?,
override val isDeleted: Boolean,
override val message: LogbookMessageValue?,
override val isSentByFailoverSoftware: Boolean,
) : BaseLogbookMessageDataOutput {
companion object {
fun fromLogbookMessage(logbookMessage: LogbookMessage) =
LogbookMessageDataOutput(
internalReferenceNumber = logbookMessage.internalReferenceNumber,
referencedReportId = logbookMessage.referencedReportId,
externalReferenceNumber = logbookMessage.externalReferenceNumber,
ircs = logbookMessage.ircs,
isCorrected = logbookMessage.isCorrectedByNewerMessage,
isCorrectedByNewerMessage = logbookMessage.isCorrectedByNewerMessage,
acknowledgment = logbookMessage.acknowledgment,
deleted = logbookMessage.isDeleted,
isDeleted = logbookMessage.isDeleted,
operationDateTime = logbookMessage.operationDateTime,
activityDateTime = logbookMessage.activityDateTime,
reportDateTime = logbookMessage.reportDateTime,
Expand All @@ -54,7 +53,6 @@ data class LogbookMessageDataOutput(
imo = logbookMessage.imo,
messageType = logbookMessage.messageType,
message = logbookMessage.message,
rawMessage = null,
isSentByFailoverSoftware = logbookMessage.isSentByFailoverSoftware,
)
}
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 @@ -32,21 +32,21 @@ data class LastPositionDataOutput(
val registryPortName: String? = null,
val district: String? = null,
val districtCode: String? = null,
val gearOnboard: List<GearLastPositionDataOutput>? = null,
val segments: List<String>? = listOf(),
val speciesOnboard: List<SpeciesLastPositionDataOutput>? = null,
val totalWeightOnboard: Double? = null,
val gearOnboard: List<GearLastPositionDataOutput>,
val segments: List<String>,
val speciesOnboard: List<SpeciesLastPositionDataOutput>,
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 alerts: List<String>? = listOf(),
val isAtPort: Boolean,
val alerts: List<String>,
val beaconMalfunctionId: Int? = null,
val reportings: List<String> = listOf(),
) {
Expand Down Expand Up @@ -77,14 +77,16 @@ data class LastPositionDataOutput(
registryPortName = position.registryPortName,
district = position.district,
districtCode = position.districtCode,
gearOnboard = position.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) },
segments = position.segments,
gearOnboard =
position.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) }
?: listOf(),
segments = position.segments ?: listOf(),
speciesOnboard =
position.speciesOnboard?.map {
SpeciesLastPositionDataOutput.fromSpeciesLastPosition(
it,
)
},
} ?: listOf(),
totalWeightOnboard = position.totalWeightOnboard,
lastControlDateTime = position.lastControlDateTime,
lastControlInfraction = position.lastControlInfraction,
Expand All @@ -96,7 +98,7 @@ data class LastPositionDataOutput(
riskFactor = position.riskFactor,
underCharter = position.underCharter,
isAtPort = position.isAtPort,
alerts = position.alerts,
alerts = position.alerts ?: listOf(),
beaconMalfunctionId = position.beaconMalfunctionId,
reportings = position.reportings,
)
Expand Down
Loading

0 comments on commit 0770123

Please sign in to comment.