diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 4c483bde72..be685b7d67 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -97,18 +97,19 @@ springBoot { buildInfo { properties { - additional = mapOf( - "commit.hash" to "COMMIT_TO_CHANGE", - ) + additional = + mapOf( + "commit.hash" to "COMMIT_TO_CHANGE", + ) } } } -tasks.withType() { +tasks.withType { options.encoding = "UTF-8" } -tasks.withType() { +tasks.withType { options.encoding = "UTF-8" } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/Utils.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/Utils.kt index 5536d95e7e..c1ea97ddc1 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/Utils.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/Utils.kt @@ -7,7 +7,10 @@ class Utils { * * If both strings are null or empty, they are considered equivalent. */ - fun areStringsEqual(leftString: String?, rightString: String?): Boolean { + fun areStringsEqual( + leftString: String?, + rightString: String?, + ): Boolean { val normalizedLeftString = leftString?.trim().takeUnless { it.isNullOrEmpty() || it == " " } val normalizedRightString = rightString?.trim().takeUnless { it.isNullOrEmpty() || it == " " } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/ApiClient.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/ApiClient.kt index ac67a26db0..61e3d17a65 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/ApiClient.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/ApiClient.kt @@ -10,15 +10,16 @@ import org.springframework.context.annotation.Configuration @Configuration class ApiClient(engine: HttpClientEngine = Java.create()) { - val httpClient = HttpClient(engine) { - install(ContentNegotiation) { - json( - Json { - prettyPrint = true - isLenient = true - ignoreUnknownKeys = true - }, - ) + val httpClient = + HttpClient(engine) { + install(ContentNegotiation) { + json( + Json { + prettyPrint = true + isLenient = true + ignoreUnknownKeys = true + }, + ) + } } - } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/SecurityConfig.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/SecurityConfig.kt index 63d0a17197..8e5195f057 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/SecurityConfig.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/SecurityConfig.kt @@ -82,11 +82,12 @@ class SecurityConfig( @Bean fun corsConfigurationSource(): CorsConfigurationSource { - val configuration = CorsConfiguration().apply { - allowedOrigins = listOf("*") - allowedMethods = listOf("HEAD", "GET", "POST", "PUT", "DELETE", "OPTIONS") - allowedHeaders = listOf("Authorization", "Cache-Control", "Content-Type") - } + val configuration = + CorsConfiguration().apply { + allowedOrigins = listOf("*") + allowedMethods = listOf("HEAD", "GET", "POST", "PUT", "DELETE", "OPTIONS") + allowedHeaders = listOf("Authorization", "Cache-Control", "Content-Type") + } val source = UrlBasedCorsConfigurationSource() source.registerCorsConfiguration("/**", configuration) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/SwaggerConfig.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/SwaggerConfig.kt index 0dce7a8f9f..d4694498f4 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/SwaggerConfig.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/config/SwaggerConfig.kt @@ -10,7 +10,6 @@ import org.springframework.context.annotation.Configuration @Configuration class SwaggerConfig { - @Autowired private val hostProperties: HostProperties? = null diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/beacon_malfunctions/VesselBeaconMalfunctionsResume.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/beacon_malfunctions/VesselBeaconMalfunctionsResume.kt index 4d1bbc4d8b..8defd92b8f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/beacon_malfunctions/VesselBeaconMalfunctionsResume.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/beacon_malfunctions/VesselBeaconMalfunctionsResume.kt @@ -14,21 +14,25 @@ data class VesselBeaconMalfunctionsResume( ): VesselBeaconMalfunctionsResume { val oneYearBefore = ZonedDateTime.now().minusYears(1) - val lastBeaconMalfunction = beaconMalfunctionsWithDetails - .maxByOrNull { it.beaconMalfunction.malfunctionStartDateTime } + val lastBeaconMalfunction = + beaconMalfunctionsWithDetails + .maxByOrNull { it.beaconMalfunction.malfunctionStartDateTime } - val lastYearBeaconMalfunctionsWithDetails = beaconMalfunctionsWithDetails.filter { - it.beaconMalfunction.malfunctionStartDateTime > oneYearBefore - } + val lastYearBeaconMalfunctionsWithDetails = + beaconMalfunctionsWithDetails.filter { + it.beaconMalfunction.malfunctionStartDateTime > oneYearBefore + } - val numberOfBeaconsAtSea = getNumberOfBeaconsMalfunctionsAt( - VesselStatus.AT_SEA, - lastYearBeaconMalfunctionsWithDetails, - ) - val numberOfBeaconsAtPort = getNumberOfBeaconsMalfunctionsAt( - VesselStatus.AT_PORT, - lastYearBeaconMalfunctionsWithDetails, - ) + val numberOfBeaconsAtSea = + getNumberOfBeaconsMalfunctionsAt( + VesselStatus.AT_SEA, + lastYearBeaconMalfunctionsWithDetails, + ) + val numberOfBeaconsAtPort = + getNumberOfBeaconsMalfunctionsAt( + VesselStatus.AT_PORT, + lastYearBeaconMalfunctionsWithDetails, + ) return VesselBeaconMalfunctionsResume( numberOfBeaconsAtSea = numberOfBeaconsAtSea, @@ -48,8 +52,9 @@ data class VesselBeaconMalfunctionsResume( } private fun getFirstVesselStatus(beaconMalfunctionsWithDetails: BeaconMalfunctionWithDetails): VesselStatus { - val beaconMalfunctionVesselStatusActions = beaconMalfunctionsWithDetails.actions - .filter { action -> action.propertyName == BeaconMalfunctionActionPropertyName.VESSEL_STATUS } + val beaconMalfunctionVesselStatusActions = + beaconMalfunctionsWithDetails.actions + .filter { action -> action.propertyName == BeaconMalfunctionActionPropertyName.VESSEL_STATUS } return when (beaconMalfunctionVesselStatusActions.isEmpty()) { true -> beaconMalfunctionsWithDetails.beaconMalfunction.vesselStatus @@ -62,9 +67,10 @@ data class VesselBeaconMalfunctionsResume( } private fun getLastVesselStatus(beaconMalfunction: BeaconMalfunctionWithDetails?): VesselStatus? { - val lastVesselStatus = beaconMalfunction?.actions?.filter { action -> - action.propertyName == BeaconMalfunctionActionPropertyName.VESSEL_STATUS - }?.maxByOrNull { action -> action.dateTime }?.nextValue + val lastVesselStatus = + beaconMalfunction?.actions?.filter { action -> + action.propertyName == BeaconMalfunctionActionPropertyName.VESSEL_STATUS + }?.maxByOrNull { action -> action.dateTime }?.nextValue return lastVesselStatus?.let { VesselStatus.valueOf(lastVesselStatus) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/facade/SeafrontGroup.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/facade/SeafrontGroup.kt index 424ed7d239..8df90366ec 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/facade/SeafrontGroup.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/facade/SeafrontGroup.kt @@ -12,16 +12,17 @@ enum class SeafrontGroup { ; companion object { - private val groupToSeafronts = mapOf( - ALL to Seafront.entries, - MED to listOf(Seafront.CORSE, Seafront.MED), - MEMN to listOf(Seafront.MEMN), - NAMO to listOf(Seafront.NAMO), - OUTREMEROA to listOf(Seafront.GUADELOUPE, Seafront.GUYANE, Seafront.MARTINIQUE), - OUTREMEROI to listOf(Seafront.MAYOTTE, Seafront.SUD_OCEAN_INDIEN), - SA to listOf(Seafront.SA), - NONE to emptyList(), - ) + private val groupToSeafronts = + mapOf( + ALL to Seafront.entries, + MED to listOf(Seafront.CORSE, Seafront.MED), + MEMN to listOf(Seafront.MEMN), + NAMO to listOf(Seafront.NAMO), + OUTREMEROA to listOf(Seafront.GUADELOUPE, Seafront.GUYANE, Seafront.MARTINIQUE), + OUTREMEROI to listOf(Seafront.MAYOTTE, Seafront.SUD_OCEAN_INDIEN), + SA to listOf(Seafront.SA), + NONE to emptyList(), + ) fun fromSeafront(seafront: Seafront?): SeafrontGroup { return seafront?.let { groupToSeafronts.entries.first { it.key != ALL && it.value.contains(seafront) }.key } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/last_position/LastPosition.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/last_position/LastPosition.kt index 5944221467..e5ab6bb5c9 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/last_position/LastPosition.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/last_position/LastPosition.kt @@ -8,8 +8,7 @@ import java.time.ZonedDateTime data class LastPosition( val id: Int? = null, - - /* Vessel identification properties */ + // Vessel identification properties val vesselId: Int? = null, // Unique code composed by the contracting party/cooperating non-contracting party expressed as 3-alpha // country code followed by the vessel registration number as recorded in the national fleet register @@ -23,7 +22,6 @@ data class LastPosition( val vesselName: String? = null, val flagState: CountryCode, val positionType: PositionType, - val latitude: Double? = null, val longitude: Double? = null, val estimatedCurrentLatitude: Double? = null, @@ -32,7 +30,6 @@ data class LastPosition( val course: Double? = null, val dateTime: ZonedDateTime, val tripNumber: String? = null, - val emissionPeriod: Duration? = null, val lastLogbookMessageDateTime: ZonedDateTime? = null, val departureDateTime: ZonedDateTime? = null, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt index 54cfcd75d8..0b53345978 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt @@ -27,7 +27,6 @@ data class LogbookMessage( var rawMessage: String? = null, val transmissionFormat: LogbookTransmissionFormat?, val software: String? = null, - var acknowledgment: Acknowledgment? = null, var isCorrectedByNewerMessage: Boolean = false, var isDeleted: Boolean = false, @@ -51,24 +50,26 @@ data class LogbookMessage( val isCurrentAcknowledgementSuccessful = currentAcknowledgement?.isSuccess ?: false val isNewAcknowledgementSuccessful = newAcknowledgement.returnStatus == RETReturnErrorCode.SUCCESS.number - val shouldUpdate = when { - // If there is no currently calculated acknowledgement yet, create it - currentAcknowledgement?.dateTime == null || currentAcknowledgement.isSuccess == null -> true - // Else, if the new acknowledgement message is successful while the currently calculated one is not, replace it - isNewAcknowledgementSuccessful && currentAcknowledgement.isSuccess != true -> true - // Else, if the new failure acknowledgement message is more recent - // than the currently calculated one (also a failure in this case), replace it - !isNewAcknowledgementSuccessful && - newLogbookMessageAcknowledgement.reportDateTime != null && - newLogbookMessageAcknowledgement.reportDateTime > currentAcknowledgement.dateTime -> true - - else -> false - } - if (shouldUpdate) { - this.acknowledgment = newAcknowledgement.also { - it.isSuccess = isCurrentAcknowledgementSuccessful || isNewAcknowledgementSuccessful - it.dateTime = newLogbookMessageAcknowledgement.reportDateTime + val shouldUpdate = + when { + // If there is no currently calculated acknowledgement yet, create it + currentAcknowledgement?.dateTime == null || currentAcknowledgement.isSuccess == null -> true + // Else, if the new acknowledgement message is successful while the currently calculated one is not, replace it + isNewAcknowledgementSuccessful && currentAcknowledgement.isSuccess != true -> true + // Else, if the new failure acknowledgement message is more recent + // than the currently calculated one (also a failure in this case), replace it + !isNewAcknowledgementSuccessful && + newLogbookMessageAcknowledgement.reportDateTime != null && + newLogbookMessageAcknowledgement.reportDateTime > currentAcknowledgement.dateTime -> true + + else -> false } + if (shouldUpdate) { + this.acknowledgment = + newAcknowledgement.also { + it.isSuccess = isCurrentAcknowledgementSuccessful || isNewAcknowledgementSuccessful + it.dateTime = newLogbookMessageAcknowledgement.reportDateTime + } } } @@ -180,7 +181,7 @@ data class LogbookMessage( it.messageType == messageType && ( (reportId.isNullOrEmpty() && it.referencedReportId == reportId) || (referencedReportId.isNullOrEmpty() && it.referencedReportId == referencedReportId) - ) + ) } } @@ -197,18 +198,23 @@ data class LogbookMessage( } private fun setIsCorrectedByNewerMessage(relatedMessages: List) { - isCorrectedByNewerMessage = relatedMessages.any { - operationType == LogbookOperationType.COR && - it.reportDateTime != null && - it.reportDateTime > reportDateTime - } + isCorrectedByNewerMessage = + relatedMessages.any { + operationType == LogbookOperationType.COR && + it.reportDateTime != null && + it.reportDateTime > reportDateTime + } } - private fun setNamesFromCodes(message: COE, allSpecies: List) { + private fun setNamesFromCodes( + message: COE, + allSpecies: List, + ) { message.targetSpeciesOnEntry?.let { targetSpeciesOnEntry -> - message.targetSpeciesNameOnEntry = EffortTargetSpeciesGroup.entries.find { - it.name == targetSpeciesOnEntry - }?.value + message.targetSpeciesNameOnEntry = + EffortTargetSpeciesGroup.entries.find { + it.name == targetSpeciesOnEntry + }?.value if (message.targetSpeciesNameOnEntry == null) { message.targetSpeciesNameOnEntry = allSpecies.find { it.code == targetSpeciesOnEntry }?.name @@ -216,11 +222,15 @@ data class LogbookMessage( } } - private fun setNamesFromCodes(message: COX, allSpecies: List) { + private fun setNamesFromCodes( + message: COX, + allSpecies: List, + ) { message.targetSpeciesOnExit?.let { targetSpeciesOnExit -> - message.targetSpeciesNameOnExit = EffortTargetSpeciesGroup.entries.find { - it.name == targetSpeciesOnExit - }?.value + message.targetSpeciesNameOnExit = + EffortTargetSpeciesGroup.entries.find { + it.name == targetSpeciesOnExit + }?.value if (message.targetSpeciesNameOnExit == null) { message.targetSpeciesNameOnExit = allSpecies.find { it.code == targetSpeciesOnExit }?.name @@ -228,11 +238,15 @@ data class LogbookMessage( } } - private fun setNamesFromCodes(message: CRO, allSpecies: List) { + private fun setNamesFromCodes( + message: CRO, + allSpecies: List, + ) { message.targetSpeciesOnExit?.let { targetSpeciesOnExit -> - message.targetSpeciesNameOnExit = EffortTargetSpeciesGroup.entries.find { - it.name == targetSpeciesOnExit - }?.value + message.targetSpeciesNameOnExit = + EffortTargetSpeciesGroup.entries.find { + it.name == targetSpeciesOnExit + }?.value if (message.targetSpeciesNameOnExit == null) { message.targetSpeciesNameOnExit = allSpecies.find { it.code == targetSpeciesOnExit }?.name @@ -240,9 +254,10 @@ data class LogbookMessage( } message.targetSpeciesOnEntry?.let { targetSpeciesOnEntry -> - message.targetSpeciesNameOnEntry = EffortTargetSpeciesGroup.entries.find { - it.name == targetSpeciesOnEntry - }?.value + message.targetSpeciesNameOnEntry = + EffortTargetSpeciesGroup.entries.find { + it.name == targetSpeciesOnEntry + }?.value if (message.targetSpeciesNameOnEntry == null) { message.targetSpeciesNameOnEntry = allSpecies.find { it.code == targetSpeciesOnEntry }?.name @@ -268,7 +283,10 @@ data class LogbookMessage( } } - private fun setNamesFromCodes(message: CPS, allSpecies: List) { + private fun setNamesFromCodes( + message: CPS, + allSpecies: List, + ) { message.catches.forEach { catch -> addSpeciesName(catch, catch.species, allSpecies) } @@ -297,7 +315,10 @@ data class LogbookMessage( } } - private fun setNamesFromCodes(message: DIS, allSpecies: List) { + private fun setNamesFromCodes( + message: DIS, + allSpecies: List, + ) { message.catches.forEach { catch -> catch.species?.let { species -> addSpeciesName(catch, species, allSpecies) @@ -305,7 +326,11 @@ data class LogbookMessage( } } - private fun setNamesFromCodes(message: LAN, allPorts: List, allSpecies: List) { + private fun setNamesFromCodes( + message: LAN, + allPorts: List, + allSpecies: List, + ) { message.port?.let { portLocode -> message.portName = allPorts.find { it.locode == portLocode }?.name } @@ -317,7 +342,11 @@ data class LogbookMessage( } } - private fun setNamesFromCodes(message: PNO, allPorts: List, allSpecies: List) { + private fun setNamesFromCodes( + message: PNO, + allPorts: List, + allSpecies: List, + ) { message.port?.let { arrivalPortLocode -> message.portName = allPorts.find { it.locode == arrivalPortLocode }?.name } @@ -345,11 +374,19 @@ data class LogbookMessage( } } - private fun addSpeciesName(catch: LogbookFishingCatch, species: String, allSpecies: List) { + private fun addSpeciesName( + catch: LogbookFishingCatch, + species: String, + allSpecies: List, + ) { catch.speciesName = allSpecies.find { it.code == species }?.name } - private fun addSpeciesName(catch: ProtectedSpeciesCatch, species: String, allSpecies: List) { + private fun addSpeciesName( + catch: ProtectedSpeciesCatch, + species: String, + allSpecies: List, + ) { catch.speciesName = allSpecies.find { it.code == species }?.name } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessageAndValue.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessageAndValue.kt index eedf55e31b..aa5ccd4774 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessageAndValue.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessageAndValue.kt @@ -9,11 +9,12 @@ class LogbookMessageAndValue( private val clazz: Class, ) { val value: T - get() = if (clazz.isInstance(logbookMessage.message)) { - clazz.cast(logbookMessage.message) - } else { - throw EntityConversionException( - "Logbook message is not of type $clazz (reportId: ${logbookMessage.reportId}).", - ) - } + get() = + if (clazz.isInstance(logbookMessage.message)) { + clazz.cast(logbookMessage.message) + } else { + throw EntityConversionException( + "Logbook message is not of type $clazz (reportId: ${logbookMessage.reportId}).", + ) + } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookSoftware.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookSoftware.kt index 81fa2dac84..92e89f7fa6 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookSoftware.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookSoftware.kt @@ -35,9 +35,10 @@ enum class LogbookSoftware(val software: String) { } fun isVisioCaptureInRealTime(software: String?): Boolean { - val isVisioCapture = software?.let { - it.startsWith("FT") || it.startsWith("JT") - } + val isVisioCapture = + software?.let { + it.startsWith("FT") || it.startsWith("JT") + } return isVisioCapture ?: false } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt index 2f7da19f0e..ff47d870f1 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionAction.kt @@ -73,11 +73,12 @@ data class MissionAction( var observationsByUnit: String? = null, ) { fun verify() { - val controlTypes = listOf( - MissionActionType.AIR_CONTROL, - MissionActionType.LAND_CONTROL, - MissionActionType.SEA_CONTROL, - ) + val controlTypes = + listOf( + MissionActionType.AIR_CONTROL, + MissionActionType.LAND_CONTROL, + MissionActionType.SEA_CONTROL, + ) if (controlTypes.any { it == this.actionType }) { require(this.vesselId != null) { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/Constants.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/Constants.kt index 73119d4839..68b865fcd1 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/Constants.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/Constants.kt @@ -18,193 +18,201 @@ typealias FaoZonesAndSpecy = Pair */ val EASTERN_ATLANTIC_SPECY = Pair(EASTERN_ATLANTIC_OPERATIONAL_ZONES, "BFT") -val MEDITERRANEAN_AND_EASTERN_ATLANTIC_SPECIES: List = generateSpeciesWithFaoCode( - MEDITERRANEAN_OPERATIONAL_ZONES, +val MEDITERRANEAN_AND_EASTERN_ATLANTIC_SPECIES: List = + generateSpeciesWithFaoCode( + MEDITERRANEAN_OPERATIONAL_ZONES, + listOf( + "ANE", + "HOM", + "JAX", + "HMM", + "JAA", + "SWO", + "ALB", + "MAC", + "MAZ", + "PIL", + "BFT", + "ELE", + "BSS", + "WRF", + "SIA", + "COL", + "DOX", + "DPS", + "ARA", + "SBR", + "SBG", + "ARS", + "LBS", + "VLO", + "LOX", + "NEP", + "SSB", + "GPX", + "HKE", + "SBA", + "PAC", + "RPG", + "VEN", + "PTS", + "CLH", + "MUX", + "MUM", + "MUR", + "MUT", + "SHR", + "CTB", + "SWA", + "SOL", + "ANN", + ), + ) + + // Eastern Atlantic part for BFT + listOf(EASTERN_ATLANTIC_SPECY) + +val NORTH_SEA_SPECIES: List = + generateSpeciesWithFaoCode( + NORTH_SEA_OPERATIONAL_ZONES, + listOf( + "HOM", + "JAX", + "ALB", + "ARU", + "ARY", + "HER", + "SAN", + "MAC", + "WHB", + "SPR", + "BET", + "ELE", + "ANF", + "MNZ", + "USK", + "COD", + "LEZ", + "PRA", + "SBR", + "HAD", + "GHL", + "GRV", + "NEP", + "POL", + "POK", + "LEM", + "BLI", + "LIN", + "WHG", + "HKE", + "PLE", + "WIT", + "SRX", + "BSF", + "SCF", + "BLL", + "SOL", + "NOP", + ), + ) + +val WESTERN_WATERS_SPECIES: List = listOf( - "ANE", - "HOM", - "JAX", - "HMM", - "JAA", - "SWO", - "ALB", - "MAC", - "MAZ", - "PIL", - "BFT", - "ELE", - "BSS", - "WRF", - "SIA", - "COL", - "DOX", - "DPS", - "ARA", - "SBR", - "SBG", - "ARS", - "LBS", - "VLO", - "LOX", - "NEP", - "SSB", - "GPX", - "HKE", - "SBA", - "PAC", - "RPG", - "VEN", - "PTS", - "CLH", - "MUX", - "MUM", - "MUR", - "MUT", - "SHR", - "CTB", - "SWA", - "SOL", - "ANN", - ), -) + - // Eastern Atlantic part for BFT - listOf(EASTERN_ATLANTIC_SPECY) + Pair(listOf("27.6", "27.7", "27.8", "27.9"), "PIL"), + Pair(listOf("27.6", "27.7", "27.8", "27.9"), "ELE"), + ) + + generateSpeciesWithFaoCode( + listOf("27.6", "27.7", "27.8", "27.9", "27.10"), + listOf( + "ANE", + "HOM", + "JAX", + "ALB", + "ARU", + "ARY", + "HER", + "MAC", + "WHB", + "SPR", + "OTH", + "BET", + "ANF", + "MNZ", + "USK", + "COD", + "LEZ", + "SBR", + "HAD", + "GHL", + "GRV", + "NEP", + "POL", + "POK", + "BLI", + "LIN", + "WHG", + "HKE", + "PLE", + "SRX", + "BSF", + "BOR", + "SOL", + ), + ) -val NORTH_SEA_SPECIES: List = generateSpeciesWithFaoCode( - NORTH_SEA_OPERATIONAL_ZONES, +val EU_THIRD_COUNTRIES = listOf(CountryCode.GB) + +/** + * See species detailed in p.26 ("CARTES DES ESPÈCES SOUMISES A QUOTAS") + * https://extranet.legipeche.metier.developpement-durable.gouv.fr/fichier/pdf/guide_cnsp_cle79d8b7.pdf?arg=24331&cle=2b455fff3506433f7e33f33562508a576908b941&file=pdf%2Fguide_cnsp_cle79d8b7.pdf + */ +val EU_QUOTAS_SPECIES = listOf( - "HOM", - "JAX", - "ALB", - "ARU", - "ARY", - "HER", - "SAN", - "MAC", - "WHB", - "SPR", - "BET", - "ELE", + "DGS", + "ANE", "ANF", - "MNZ", + "ALF", "USK", "COD", "LEZ", - "PRA", + "JAX", "SBR", "HAD", + "SWO", + "LEZ", "GHL", - "GRV", - "NEP", - "POL", - "POK", - "LEM", - "BLI", - "LIN", - "WHG", - "HKE", - "PLE", - "WIT", - "SRX", - "BSF", - "SCF", - "BLL", - "SOL", - "NOP", - ), -) - -val WESTERN_WATERS_SPECIES: List = listOf( - Pair(listOf("27.6", "27.7", "27.8", "27.9"), "PIL"), - Pair(listOf("27.6", "27.7", "27.8", "27.9"), "ELE"), -) + generateSpeciesWithFaoCode( - listOf("27.6", "27.7", "27.8", "27.9", "27.10"), - listOf( - "ANE", - "HOM", - "JAX", "ALB", "ARU", - "ARY", + "RNG", "HER", - "MAC", - "WHB", - "SPR", - "OTH", - "BET", - "ANF", - "MNZ", - "USK", - "COD", - "LEZ", - "SBR", - "HAD", - "GHL", - "GRV", "NEP", "POL", "POK", + "LEM", + "WIT", "BLI", "LIN", + "MAC", "WHG", - "HKE", + "WHB", + "BSH", + "BSH", "PLE", "SRX", + "RJU", + "RJE", "BSF", - "BOR", + "SPR", "SOL", - ), -) - -val EU_THIRD_COUNTRIES = listOf(CountryCode.GB) - -/** - * See species detailed in p.26 ("CARTES DES ESPÈCES SOUMISES A QUOTAS") - * https://extranet.legipeche.metier.developpement-durable.gouv.fr/fichier/pdf/guide_cnsp_cle79d8b7.pdf?arg=24331&cle=2b455fff3506433f7e33f33562508a576908b941&file=pdf%2Fguide_cnsp_cle79d8b7.pdf - */ -val EU_QUOTAS_SPECIES = listOf( - "DGS", - "ANE", - "ANF", - "ALF", - "USK", - "COD", - "LEZ", - "JAX", - "SBR", - "HAD", - "SWO", - "LEZ", - "GHL", - "ALB", - "ARU", - "RNG", - "HER", - "NEP", - "POL", - "POK", - "LEM", - "WIT", - "BLI", - "LIN", - "MAC", - "WHG", - "WHB", - "BSH", - "BSH", - "PLE", - "SRX", - "RJU", - "RJE", - "BSF", - "SPR", - "SOL", - "BET", - "BFT", - "TUR", - "BLL", -) + "BET", + "BFT", + "TUR", + "BLL", + ) -fun generateSpeciesWithFaoCode(faoZones: FaoZones, species: List): List { +fun generateSpeciesWithFaoCode( + faoZones: FaoZones, + species: List, +): List { return species.map { Pair(faoZones, it) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlan.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlan.kt index 3598bc3bd4..f911be9dc4 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlan.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlan.kt @@ -63,41 +63,43 @@ enum class JointDeploymentPlan( return false } - val hasSpeciesInJdp = this.species.any { (jdpFaoZones, jdpSpecy) -> - val isSpecyFoundInJdpSpecies = speciesOnboardCodes.contains(jdpSpecy) - - val isFaoZoneFoundInJdpFaoZones = jdpFaoZones - .any { jdpFaoCode -> - // The JDP FAO zone is included in at least one trip FAO code - tripFaoCodes.any { tripFaoCode -> tripFaoCode.contains(jdpFaoCode) } - } - - return@any isSpecyFoundInJdpSpecies && isFaoZoneFoundInJdpFaoZones - } + val hasSpeciesInJdp = + this.species.any { (jdpFaoZones, jdpSpecy) -> + val isSpecyFoundInJdpSpecies = speciesOnboardCodes.contains(jdpSpecy) + + val isFaoZoneFoundInJdpFaoZones = + jdpFaoZones + .any { jdpFaoCode -> + // The JDP FAO zone is included in at least one trip FAO code + tripFaoCodes.any { tripFaoCode -> tripFaoCode.contains(jdpFaoCode) } + } + + return@any isSpecyFoundInJdpSpecies && isFaoZoneFoundInJdpFaoZones + } - val hasSpeciesInEUQuotas = if (isThirdCountryVessel) { - EU_QUOTAS_SPECIES.any { quotaSpecy -> speciesOnboardCodes.contains(quotaSpecy) } - } else { - false - } + val hasSpeciesInEUQuotas = + if (isThirdCountryVessel) { + EU_QUOTAS_SPECIES.any { quotaSpecy -> speciesOnboardCodes.contains(quotaSpecy) } + } else { + false + } return hasSpeciesInJdp || hasSpeciesInEUQuotas } - fun getFirstFaoAreaIncludedInJdp( - control: MissionAction, - ): FaoArea? { + fun getFirstFaoAreaIncludedInJdp(control: MissionAction): FaoArea? { val jdpFaoAreas = this.getOperationalZones() if (control.actionType == MissionActionType.SEA_CONTROL && !isAttributedJdp(control)) { return null } - val firstFaoAreaIncludedInJdp = control.faoAreas - .map { FaoArea(it) } - .firstOrNull { controlFaoArea -> - jdpFaoAreas.any { controlFaoArea.hasFaoCodeIncludedIn(it) } - } + val firstFaoAreaIncludedInJdp = + control.faoAreas + .map { FaoArea(it) } + .firstOrNull { controlFaoArea -> + jdpFaoAreas.any { controlFaoArea.hasFaoCodeIncludedIn(it) } + } return firstFaoAreaIncludedInJdp } @@ -108,42 +110,40 @@ enum class JointDeploymentPlan( * `JointDeploymentPlan.entries.firstOrNull` is the arbitrary rule to attach a control to only one JDP. * see: https://github.com/MTES-MCT/monitorfish/issues/3157#issuecomment-2093036583 */ - fun isAttributedJdp( - control: MissionAction, - ) = JointDeploymentPlan.entries - .firstOrNull { jdpEntry -> + fun isAttributedJdp(control: MissionAction) = + JointDeploymentPlan.entries + .firstOrNull { jdpEntry -> + /** + * There is an overlap between the `MEDITERRANEAN_AND_EASTERN_ATLANTIC` and the WESTERN_WATERS JDPs. + * We add a filter by species to avoid counting all controls done in + * `EASTERN_ATLANTIC_OPERATIONAL_ZONES without targeted species in catches. + */ + if (jdpEntry == MEDITERRANEAN_AND_EASTERN_ATLANTIC) { + return@firstOrNull isMedJdpAttributed(control) + } + + return@firstOrNull jdpEntry.getOperationalZones().any { jdpFaoArea -> + control.faoAreas.any { controlFaoArea -> + FaoArea(controlFaoArea).hasFaoCodeIncludedIn(jdpFaoArea) + } + } + } == this + + private fun isMedJdpAttributed(control: MissionAction) = + MEDITERRANEAN_AND_EASTERN_ATLANTIC.getOperationalZones().any { jdpFaoArea -> /** - * There is an overlap between the `MEDITERRANEAN_AND_EASTERN_ATLANTIC` and the WESTERN_WATERS JDPs. - * We add a filter by species to avoid counting all controls done in - * `EASTERN_ATLANTIC_OPERATIONAL_ZONES without targeted species in catches. + * Filter by FAO zone AND `EASTERN_ATLANTIC_SPECY` + * if the fao zone is included in the `EASTERN_ATLANTIC_OPERATIONAL_ZONES` */ - if (jdpEntry == MEDITERRANEAN_AND_EASTERN_ATLANTIC) { - return@firstOrNull isMedJdpAttributed(control) - } - - return@firstOrNull jdpEntry.getOperationalZones().any { jdpFaoArea -> - control.faoAreas.any { controlFaoArea -> - FaoArea(controlFaoArea).hasFaoCodeIncludedIn(jdpFaoArea) + if (EASTERN_ATLANTIC_OPERATIONAL_ZONES.contains(jdpFaoArea)) { + return@any control.faoAreas.any { controlFaoArea -> + FaoArea(controlFaoArea).hasFaoCodeIncludedIn(jdpFaoArea) && + control.speciesOnboard.map { it.speciesCode }.contains(EASTERN_ATLANTIC_SPECY.second) } } - } == this - - private fun isMedJdpAttributed( - control: MissionAction, - ) = MEDITERRANEAN_AND_EASTERN_ATLANTIC.getOperationalZones().any { jdpFaoArea -> - /** - * Filter by FAO zone AND `EASTERN_ATLANTIC_SPECY` - * if the fao zone is included in the `EASTERN_ATLANTIC_OPERATIONAL_ZONES` - */ - if (EASTERN_ATLANTIC_OPERATIONAL_ZONES.contains(jdpFaoArea)) { + return@any control.faoAreas.any { controlFaoArea -> - FaoArea(controlFaoArea).hasFaoCodeIncludedIn(jdpFaoArea) && - control.speciesOnboard.map { it.speciesCode }.contains(EASTERN_ATLANTIC_SPECY.second) + FaoArea(controlFaoArea).hasFaoCodeIncludedIn(jdpFaoArea) } } - - return@any control.faoAreas.any { controlFaoArea -> - FaoArea(controlFaoArea).hasFaoCodeIncludedIn(jdpFaoArea) - } - } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/position/Position.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/position/Position.kt index 05214806a1..325d527c99 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/position/Position.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/position/Position.kt @@ -5,8 +5,7 @@ import java.time.ZonedDateTime data class Position( val id: Int? = null, - - /* Vessel identification properties */ + // Vessel identification properties // Unique code composed by the contracting party/cooperating non-contracting party expressed as 3-alpha // country code followed by the vessel registration number as recorded in the national fleet register val internalReferenceNumber: String? = null, @@ -22,7 +21,6 @@ data class Position( val isManual: Boolean? = null, val isFishing: Boolean? = null, val isAtPort: Boolean? = null, - val latitude: Double, val longitude: Double, val speed: Double?, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/prior_notification/PdfDocument.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/prior_notification/PdfDocument.kt index 42316508c4..09ad7bd01a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/prior_notification/PdfDocument.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/prior_notification/PdfDocument.kt @@ -20,7 +20,9 @@ data class PdfDocument( if (pdfDocument != null) { if (other.pdfDocument == null) return false if (!pdfDocument.contentEquals(other.pdfDocument)) return false - } else if (other.pdfDocument != null) return false + } else if (other.pdfDocument != null) { + return false + } return true } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/prior_notification/PriorNotification.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/prior_notification/PriorNotification.kt index 1db9392c3e..08202fa073 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/prior_notification/PriorNotification.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/prior_notification/PriorNotification.kt @@ -41,36 +41,37 @@ data class PriorNotification( /** * See /adrs/0006-prior-notification-states-specifications.md for more details. */ - get() = run { - val pnoValue = logbookMessageAndValue.value - - val isInVerificationScope = pnoValue.isInVerificationScope - val isVerified = pnoValue.isVerified - val isSent = pnoValue.isSent - val isBeingSent = pnoValue.isBeingSent - - return when { - isInVerificationScope == null || isVerified == null || isSent == null || isBeingSent == null -> null - !isInVerificationScope && !isVerified && !isSent && !isBeingSent -> PriorNotificationState.OUT_OF_VERIFICATION_SCOPE - !isInVerificationScope && !isVerified && !isSent && isBeingSent -> PriorNotificationState.PENDING_AUTO_SEND - !isInVerificationScope && !isVerified && isSent && !isBeingSent -> PriorNotificationState.AUTO_SEND_DONE - !isInVerificationScope && isVerified && !isSent && !isBeingSent -> PriorNotificationState.FAILED_SEND - !isInVerificationScope && isVerified && !isSent && isBeingSent -> PriorNotificationState.PENDING_SEND - !isInVerificationScope && isVerified && isSent && !isBeingSent -> PriorNotificationState.VERIFIED_AND_SENT - isInVerificationScope && !isVerified && !isSent && !isBeingSent -> PriorNotificationState.PENDING_VERIFICATION - isInVerificationScope && isVerified && !isSent && !isBeingSent -> PriorNotificationState.FAILED_SEND - isInVerificationScope && isVerified && !isSent && isBeingSent -> PriorNotificationState.PENDING_SEND - isInVerificationScope && isVerified && isSent && !isBeingSent -> PriorNotificationState.VERIFIED_AND_SENT - else -> { - logger.error( - "Impossible PriorNotification state: `reportId = $reportId`, isInVerificationScope = $isInVerificationScope`, `isVerified = $isVerified`, `isSent = $isSent`, `isBeingSent = $isBeingSent`.", - BackendInternalErrorCode.UNPROCESSABLE_RESOURCE_DATA, - ) - - null + get() = + run { + val pnoValue = logbookMessageAndValue.value + + val isInVerificationScope = pnoValue.isInVerificationScope + val isVerified = pnoValue.isVerified + val isSent = pnoValue.isSent + val isBeingSent = pnoValue.isBeingSent + + return when { + isInVerificationScope == null || isVerified == null || isSent == null || isBeingSent == null -> null + !isInVerificationScope && !isVerified && !isSent && !isBeingSent -> PriorNotificationState.OUT_OF_VERIFICATION_SCOPE + !isInVerificationScope && !isVerified && !isSent && isBeingSent -> PriorNotificationState.PENDING_AUTO_SEND + !isInVerificationScope && !isVerified && isSent && !isBeingSent -> PriorNotificationState.AUTO_SEND_DONE + !isInVerificationScope && isVerified && !isSent && !isBeingSent -> PriorNotificationState.FAILED_SEND + !isInVerificationScope && isVerified && !isSent && isBeingSent -> PriorNotificationState.PENDING_SEND + !isInVerificationScope && isVerified && isSent && !isBeingSent -> PriorNotificationState.VERIFIED_AND_SENT + isInVerificationScope && !isVerified && !isSent && !isBeingSent -> PriorNotificationState.PENDING_VERIFICATION + isInVerificationScope && isVerified && !isSent && !isBeingSent -> PriorNotificationState.FAILED_SEND + isInVerificationScope && isVerified && !isSent && isBeingSent -> PriorNotificationState.PENDING_SEND + isInVerificationScope && isVerified && isSent && !isBeingSent -> PriorNotificationState.VERIFIED_AND_SENT + else -> { + logger.error( + "Impossible PriorNotification state: `reportId = $reportId`, isInVerificationScope = $isInVerificationScope`, `isVerified = $isVerified`, `isSent = $isSent`, `isBeingSent = $isBeingSent`.", + BackendInternalErrorCode.UNPROCESSABLE_RESOURCE_DATA, + ) + + null + } } } - } fun enrich( allRiskFactors: List, @@ -80,21 +81,23 @@ data class PriorNotification( val logbookMessage = logbookMessageAndValue.logbookMessage val pnoValue = logbookMessageAndValue.value - port = pnoValue.port?.let { portLocode -> - allPorts.find { it.locode == portLocode } - } + port = + pnoValue.port?.let { portLocode -> + allPorts.find { it.locode == portLocode } + } seafront = port?.facade?.let { Seafront.from(it) } - lastControlDateTime = if (isManuallyCreated) { - logbookMessage.vesselId?.let { vesselId -> - allRiskFactors.find { it.vesselId == vesselId }?.lastControlDatetime - } - } else { - logbookMessage.internalReferenceNumber?.let { vesselInternalReferenceNumber -> - allRiskFactors.find { it.internalReferenceNumber == vesselInternalReferenceNumber }?.lastControlDatetime + lastControlDateTime = + if (isManuallyCreated) { + logbookMessage.vesselId?.let { vesselId -> + allRiskFactors.find { it.vesselId == vesselId }?.lastControlDatetime + } + } else { + logbookMessage.internalReferenceNumber?.let { vesselInternalReferenceNumber -> + allRiskFactors.find { it.internalReferenceNumber == vesselInternalReferenceNumber }?.lastControlDatetime + } } - } } fun enrichLogbookMessage( @@ -104,23 +107,26 @@ data class PriorNotification( logbookRawMessageRepository: LogbookRawMessageRepository, ) { val logbookMessage = logbookMessageAndValue.logbookMessage - val logbookMessageWithRawMessage = logbookMessage.operationNumber?.let { operationNumber -> - logbookMessage.copy( - rawMessage = try { - logbookRawMessageRepository.findRawMessage(operationNumber) - } catch (e: NoERSMessagesFound) { - logger.warn(e.message) - - null - }, - ) - } ?: logbookMessage + val logbookMessageWithRawMessage = + logbookMessage.operationNumber?.let { operationNumber -> + logbookMessage.copy( + rawMessage = + try { + logbookRawMessageRepository.findRawMessage(operationNumber) + } catch (e: NoERSMessagesFound) { + logger.warn(e.message) + + null + }, + ) + } ?: logbookMessage logbookMessageWithRawMessage.enrichGearPortAndSpecyNames(allGears, allPorts, allSpecies) - logbookMessageAndValue = LogbookMessageAndValue( - logbookMessageWithRawMessage, - PNO::class.java, - ) + logbookMessageAndValue = + LogbookMessageAndValue( + logbookMessageWithRawMessage, + PNO::class.java, + ) } fun enrichReportingCount(reportingRepository: ReportingRepository) { @@ -140,20 +146,22 @@ data class PriorNotification( } fun markAsAcknowledged() { - logbookMessageAndValue = LogbookMessageAndValue( - logbookMessageAndValue.logbookMessage.copy(acknowledgment = Acknowledgment(isSuccess = true)), - PNO::class.java, - ) + logbookMessageAndValue = + LogbookMessageAndValue( + logbookMessageAndValue.logbookMessage.copy(acknowledgment = Acknowledgment(isSuccess = true)), + PNO::class.java, + ) } companion object { private val logger = LoggerFactory.getLogger(PriorNotification::class.java) fun fromLogbookMessage(logbookMessage: LogbookMessage): PriorNotification { - val logbookMessageAndValue = LogbookMessageAndValue( - logbookMessage = logbookMessage, - clazz = PNO::class.java, - ) + val logbookMessageAndValue = + LogbookMessageAndValue( + logbookMessage = logbookMessage, + clazz = PNO::class.java, + ) return PriorNotification( reportId = logbookMessage.reportId, @@ -163,7 +171,6 @@ data class PriorNotification( logbookMessageAndValue = logbookMessageAndValue, sentAt = logbookMessageAndValue.logbookMessage.reportDateTime, updatedAt = logbookMessage.operationDateTime, - // These props need to be calculated in the use case port = null, reportingCount = null, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/InfractionSuspicion.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/InfractionSuspicion.kt index 6c36ae9cae..314e3fd95b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/InfractionSuspicion.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/InfractionSuspicion.kt @@ -13,15 +13,15 @@ data class InfractionSuspicion( val seaFront: String? = null, val dml: String? = null, ) : InfractionSuspicionOrObservationType( - reportingActor = reportingActor, - controlUnitId = controlUnitId, - authorTrigram = authorTrigram, - authorContact = authorContact, - title = title, - description = description, - natinfCode = natinfCode, - type = ReportingTypeMapping.INFRACTION_SUSPICION, -) { + reportingActor = reportingActor, + controlUnitId = controlUnitId, + authorTrigram = authorTrigram, + authorContact = authorContact, + title = title, + description = description, + natinfCode = natinfCode, + type = ReportingTypeMapping.INFRACTION_SUSPICION, + ) { companion object { fun fromUpdatedReporting( updatedInfractionSuspicionOrObservation: UpdatedInfractionSuspicionOrObservation, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/InfractionSuspicionOrObservationType.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/InfractionSuspicionOrObservationType.kt index d4f4405e69..93437cb19e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/InfractionSuspicionOrObservationType.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/InfractionSuspicionOrObservationType.kt @@ -13,19 +13,24 @@ abstract class InfractionSuspicionOrObservationType( open val description: String? = null, override val natinfCode: Int? = null, ) : ReportingValue(natinfCode) { - fun checkReportingActorAndFieldsRequirements() = when (reportingActor) { - ReportingActor.UNIT -> require(controlUnitId != null) { - "An unit must be set" + fun checkReportingActorAndFieldsRequirements() = + when (reportingActor) { + ReportingActor.UNIT -> + require(controlUnitId != null) { + "An unit must be set" + } + ReportingActor.DML -> + require(!authorContact.isNullOrEmpty()) { + "An author contact must be set" + } + ReportingActor.DIRM -> + require(!authorContact.isNullOrEmpty()) { + "An author contact must be set" + } + ReportingActor.OTHER -> + require(!authorContact.isNullOrEmpty()) { + "An author contact must be set" + } + else -> {} } - ReportingActor.DML -> require(!authorContact.isNullOrEmpty()) { - "An author contact must be set" - } - ReportingActor.DIRM -> require(!authorContact.isNullOrEmpty()) { - "An author contact must be set" - } - ReportingActor.OTHER -> require(!authorContact.isNullOrEmpty()) { - "An author contact must be set" - } - else -> {} - } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Observation.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Observation.kt index 1c9204f513..1301ae16af 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Observation.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Observation.kt @@ -10,22 +10,23 @@ class Observation( override val title: String, override val description: String? = null, ) : InfractionSuspicionOrObservationType( - reportingActor = reportingActor, - natinfCode = null, - title = title, - type = ReportingTypeMapping.OBSERVATION, - authorTrigram = authorTrigram, -) { + reportingActor = reportingActor, + natinfCode = null, + title = title, + type = ReportingTypeMapping.OBSERVATION, + authorTrigram = authorTrigram, + ) { companion object { fun fromUpdatedReporting( updatedInfractionSuspicionOrObservation: UpdatedInfractionSuspicionOrObservation, - ): Observation = Observation( - reportingActor = updatedInfractionSuspicionOrObservation.reportingActor, - controlUnitId = updatedInfractionSuspicionOrObservation.controlUnitId, - authorTrigram = updatedInfractionSuspicionOrObservation.authorTrigram, - authorContact = updatedInfractionSuspicionOrObservation.authorContact, - title = updatedInfractionSuspicionOrObservation.title, - description = updatedInfractionSuspicionOrObservation.description, - ) + ): Observation = + Observation( + reportingActor = updatedInfractionSuspicionOrObservation.reportingActor, + controlUnitId = updatedInfractionSuspicionOrObservation.controlUnitId, + authorTrigram = updatedInfractionSuspicionOrObservation.authorTrigram, + authorContact = updatedInfractionSuspicionOrObservation.authorContact, + title = updatedInfractionSuspicionOrObservation.title, + description = updatedInfractionSuspicionOrObservation.description, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt index e962dab0dc..f9441edcb8 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/reporting/Reporting.kt @@ -22,7 +22,6 @@ data class Reporting( val isDeleted: Boolean, val latitude: Double? = null, val longitude: Double? = null, - // Enriched in the use-case val infraction: Infraction? = null, // Enriched in the use-case diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/helpers/GeoHelpers.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/helpers/GeoHelpers.kt index 7a321322e3..a1110dd8cd 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/helpers/GeoHelpers.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/helpers/GeoHelpers.kt @@ -7,7 +7,11 @@ enum class Direction(val direction: String) { W("W"), } -fun degreeMinuteToDecimal(direction: String, degree: Int, minute: Int): Double { +fun degreeMinuteToDecimal( + direction: String, + degree: Int, + minute: Int, +): Double { val maxDegree = 180 val maxMinute = 59 val secondsInMinute = 60 diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/NAFMessageMapper.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/NAFMessageMapper.kt index 5e9722d13f..49bfd81969 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/NAFMessageMapper.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/NAFMessageMapper.kt @@ -15,7 +15,6 @@ import java.time.format.DateTimeFormatter import kotlin.properties.Delegates class NAFMessageMapper(private val naf: String) { - private val logger: Logger = LoggerFactory.getLogger(NAFMessageMapper::class.java) private lateinit var dateTime: ZonedDateTime @@ -53,14 +52,15 @@ class NAFMessageMapper(private val naf: String) { try { when (it) { - NAFCode.TYPE_OF_MESSAGE -> when (value) { - positionMessageType -> this.isManual = false - manualMessageType -> { - this.isManual = true - logger.info("Receiving new manual position") + NAFCode.TYPE_OF_MESSAGE -> + when (value) { + positionMessageType -> this.isManual = false + manualMessageType -> { + this.isManual = true + logger.info("Receiving new manual position") + } + else -> throw NAFMessageParsingException("Unhandled message type \"$value\"", naf) } - else -> throw NAFMessageParsingException("Unhandled message type \"$value\"", naf) - } NAFCode.INTERNAL_REFERENCE_NUMBER -> this.internalReferenceNumber = value NAFCode.RADIO_CALL_SIGN -> this.ircs = value NAFCode.VESSEL_NAME -> this.vesselName = value diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/PatchEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/PatchEntity.kt index 9010f00d6d..7c4066836c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/PatchEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/PatchEntity.kt @@ -9,7 +9,6 @@ import kotlin.reflect.full.memberProperties @UseCase class PatchEntity { - /** * Patches the target entity with values from the source entity. * @@ -21,7 +20,10 @@ class PatchEntity { * @param target The target entity to be patched. * @param source The source entity providing the patch values. */ - fun execute(target: T, source: S): T { + fun execute( + target: T, + source: S, + ): T { val sourceProperties = source::class.memberProperties val targetProperties = target::class.memberProperties @@ -31,11 +33,12 @@ class PatchEntity { if (targetProp != null && targetProp is KMutableProperty<*>) { val sourceValue = sourceProp.getter.call(source) val existingValue = targetProp.getter.call(target) - val finalValue = if (sourceValue is Optional<*>) { - getValueFromOptional(existingValue, sourceValue) - } else { - sourceValue ?: existingValue - } + val finalValue = + if (sourceValue is Optional<*>) { + getValueFromOptional(existingValue, sourceValue) + } else { + sourceValue ?: existingValue + } targetProp.setter.call(target, finalValue) } @@ -44,7 +47,10 @@ class PatchEntity { return target } - private fun getValueFromOptional(existingValue: Any?, optional: Optional<*>?): Any? { + private fun getValueFromOptional( + existingValue: Any?, + optional: Optional<*>?, + ): Any? { return when { optional == null -> existingValue optional.isPresent -> optional.get() diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ReportingMapper.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ReportingMapper.kt index 8fb5c2c13a..18b04f1711 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ReportingMapper.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ReportingMapper.kt @@ -13,7 +13,11 @@ import org.springframework.stereotype.Component object ReportingMapper { private const val jsonbNullString = "null" - fun getReportingValueFromJSON(mapper: ObjectMapper, message: String?, reportingType: ReportingType): ReportingValue { + fun getReportingValueFromJSON( + mapper: ObjectMapper, + message: String?, + reportingType: ReportingType, + ): ReportingValue { return try { if (!message.isNullOrEmpty() && message != jsonbNullString) { when (reportingType) { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionActionsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionActionsRepository.kt index 31aa62d3c8..c34db98a49 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionActionsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionActionsRepository.kt @@ -4,5 +4,6 @@ import fr.gouv.cnsp.monitorfish.domain.entities.beacon_malfunctions.BeaconMalfun interface BeaconMalfunctionActionsRepository { fun findAllByBeaconMalfunctionId(beaconMalfunctionId: Int): List + fun save(beaconMalfunctionAction: BeaconMalfunctionAction) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionCommentsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionCommentsRepository.kt index 6618d35549..4e6da1723e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionCommentsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionCommentsRepository.kt @@ -4,5 +4,6 @@ import fr.gouv.cnsp.monitorfish.domain.entities.beacon_malfunctions.BeaconMalfun interface BeaconMalfunctionCommentsRepository { fun findAllByBeaconMalfunctionId(beaconMalfunctionId: Int): List + fun save(beaconMalfunctionComment: BeaconMalfunctionComment) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionsRepository.kt index 23628d8f8f..c72ef5841a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconMalfunctionsRepository.kt @@ -5,10 +5,18 @@ import java.time.ZonedDateTime interface BeaconMalfunctionsRepository { fun findAll(): List - fun findAllByVesselId(vesselId: Int, afterDateTime: ZonedDateTime): List + + fun findAllByVesselId( + vesselId: Int, + afterDateTime: ZonedDateTime, + ): List + fun findAllExceptArchived(): List + fun findLastSixtyArchived(): List + fun find(beaconMalfunctionId: Int): BeaconMalfunction + fun update( id: Int, vesselStatus: VesselStatus?, @@ -16,6 +24,7 @@ interface BeaconMalfunctionsRepository { endOfBeaconMalfunctionReason: EndOfBeaconMalfunctionReason?, updateDateTime: ZonedDateTime, ) + fun requestNotification( id: Int, notificationType: BeaconMalfunctionNotificationType, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconRepository.kt index 35502f8a87..668a3cba5d 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/BeaconRepository.kt @@ -4,6 +4,8 @@ import fr.gouv.cnsp.monitorfish.domain.entities.beacon_malfunctions.Beacon interface BeaconRepository { fun search(searched: String): List + fun findBeaconByVesselId(vesselId: Int): Beacon? + fun findActivatedBeaconNumbers(): List } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/ControlObjectivesRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/ControlObjectivesRepository.kt index 85aebdf29a..be3b496fbe 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/ControlObjectivesRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/ControlObjectivesRepository.kt @@ -4,7 +4,9 @@ import fr.gouv.cnsp.monitorfish.domain.entities.control_objective.ControlObjecti interface ControlObjectivesRepository { fun findAllByYear(year: Int): List + fun findYearEntries(): List + fun update( id: Int, targetNumberOfControlsAtSea: Int?, @@ -13,6 +15,11 @@ interface ControlObjectivesRepository { ) fun delete(id: Int) + fun add(controlObjective: ControlObjective): Int - fun addYear(currentYear: Int, nextYear: Int) + + fun addYear( + currentYear: Int, + nextYear: Int, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/FleetSegmentRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/FleetSegmentRepository.kt index 065fe90f84..a8807bda5d 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/FleetSegmentRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/FleetSegmentRepository.kt @@ -6,11 +6,26 @@ import fr.gouv.cnsp.monitorfish.domain.use_cases.dtos.CreateOrUpdateFleetSegment interface FleetSegmentRepository { // For test purpose fun findAll(): List + fun findAllByYear(year: Int): List - fun update(segment: String, fields: CreateOrUpdateFleetSegmentFields, year: Int): FleetSegment - fun delete(segment: String, year: Int): List + fun update( + segment: String, + fields: CreateOrUpdateFleetSegmentFields, + year: Int, + ): FleetSegment + + fun delete( + segment: String, + year: Int, + ): List + fun create(segment: FleetSegment): FleetSegment + fun findYearEntries(): List - fun addYear(currentYear: Int, nextYear: Int) + + fun addYear( + currentYear: Int, + nextYear: Int, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/InfractionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/InfractionRepository.kt index 9b0fea1009..df7eed18c2 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/InfractionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/InfractionRepository.kt @@ -4,5 +4,6 @@ import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Infracti interface InfractionRepository { fun findInfractionByNatinfCode(natinfCode: Int): Infraction + fun findAll(): List } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/LastPositionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/LastPositionRepository.kt index 9f7453d456..63bb8d2fa0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/LastPositionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/LastPositionRepository.kt @@ -7,9 +7,13 @@ import java.time.ZonedDateTime interface LastPositionRepository { fun findAll(): List + fun findAllInLastMonthOrWithBeaconMalfunction(): List + fun findAllWithBeaconMalfunctionBeforeLast48Hours(): List + fun findLastPositionDate(): ZonedDateTime + fun removeAlertToLastPositionByVesselIdentifierEquals( alertType: AlertTypeMapping, vesselIdentifier: VesselIdentifier, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/LogbookReportRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/LogbookReportRepository.kt index 82f4671eac..179cb07aae 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/LogbookReportRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/LogbookReportRepository.kt @@ -46,7 +46,10 @@ interface LogbookReportRepository { // Only used in tests fun findById(id: Long): LogbookMessage - fun findAcknowledgedPriorNotificationByReportId(reportId: String, operationDate: ZonedDateTime): PriorNotification? + fun findAcknowledgedPriorNotificationByReportId( + reportId: String, + operationDate: ZonedDateTime, + ): PriorNotification? fun findLastMessageDate(): ZonedDateTime @@ -69,7 +72,6 @@ interface LogbookReportRepository { fun updatePriorNotificationState( reportId: String, operationDate: ZonedDateTime, - isBeingSent: Boolean, isSent: Boolean, isVerified: Boolean, @@ -80,12 +82,14 @@ interface LogbookReportRepository { fun updatePriorNotificationAuthorTrigramAndNote( reportId: String, operationDate: ZonedDateTime, - authorTrigram: String?, note: String?, ) - fun invalidate(reportId: String, operationDate: ZonedDateTime) + fun invalidate( + reportId: String, + operationDate: ZonedDateTime, + ) // For test purpose fun deleteAll() diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/ManualPriorNotificationRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/ManualPriorNotificationRepository.kt index 757e46e561..b3ac964864 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/ManualPriorNotificationRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/ManualPriorNotificationRepository.kt @@ -10,7 +10,12 @@ interface ManualPriorNotificationRepository { fun save(newOrNextPriorNotification: PriorNotification): PriorNotification - fun updateState(reportId: String, isBeingSent: Boolean, isSent: Boolean, isVerified: Boolean) + fun updateState( + reportId: String, + isBeingSent: Boolean, + isSent: Boolean, + isVerified: Boolean, + ) fun invalidate(reportId: String) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MetricsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MetricsRepository.kt index 710b940545..27a0050610 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MetricsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MetricsRepository.kt @@ -1,5 +1,8 @@ package fr.gouv.cnsp.monitorfish.domain.repositories interface MetricsRepository { - fun sendMissingCodeWarning(codeType: String, code: String) + fun sendMissingCodeWarning( + codeType: String, + code: String, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionActionsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionActionsRepository.kt index ccc4688f7b..6bbea45cea 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionActionsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionActionsRepository.kt @@ -5,9 +5,20 @@ import java.time.ZonedDateTime interface MissionActionsRepository { fun findById(id: Int): MissionAction + fun findByMissionId(missionId: Int): List - fun findVesselMissionActionsAfterDateTime(vesselId: Int, afterDateTime: ZonedDateTime): List - fun findSeaAndLandControlBetweenDates(beforeDateTime: ZonedDateTime, afterDateTime: ZonedDateTime): List + + fun findVesselMissionActionsAfterDateTime( + vesselId: Int, + afterDateTime: ZonedDateTime, + ): List + + fun findSeaAndLandControlBetweenDates( + beforeDateTime: ZonedDateTime, + afterDateTime: ZonedDateTime, + ): List + fun findMissionActionsIn(missionIds: List): List + fun save(missionAction: MissionAction): MissionAction } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionRepository.kt index 9b57d17977..2091a88d64 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/MissionRepository.kt @@ -8,7 +8,11 @@ import kotlinx.coroutines.Deferred import java.time.ZonedDateTime interface MissionRepository { - fun findControlUnitsOfMission(scope: CoroutineScope, missionId: Int): Deferred> + fun findControlUnitsOfMission( + scope: CoroutineScope, + missionId: Int, + ): Deferred> + fun findAllMissions( pageNumber: Int?, pageSize: Int?, @@ -19,9 +23,8 @@ interface MissionRepository { missionStatuses: List?, seaFronts: List?, ): List - fun findByIds( - ids: List, - ): List + + fun findByIds(ids: List): List @Throws(CouldNotFindException::class) fun findById(id: Int): Mission diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PNOAndLANAlertRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PNOAndLANAlertRepository.kt index 3ea5227d80..a48269fd6a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PNOAndLANAlertRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PNOAndLANAlertRepository.kt @@ -5,6 +5,7 @@ import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.AlertTypeMapping interface PNOAndLANAlertRepository { fun save(alert: PNOAndLANAlert) + fun findAlertsOfTypes( types: List, internalReferenceNumber: String, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PendingAlertRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PendingAlertRepository.kt index 1981a5daaf..f2ccfd9069 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PendingAlertRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PendingAlertRepository.kt @@ -5,7 +5,10 @@ import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.AlertTypeMapping interface PendingAlertRepository { fun save(alert: PendingAlert) + fun delete(id: Int) + fun findAlertsOfTypes(types: List): List + fun find(id: Int): PendingAlert } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PnoSegmentSubscriptionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PnoSegmentSubscriptionRepository.kt index d064c17c4d..32b0f522d6 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PnoSegmentSubscriptionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PnoSegmentSubscriptionRepository.kt @@ -1,5 +1,8 @@ package fr.gouv.cnsp.monitorfish.domain.repositories interface PnoSegmentSubscriptionRepository { - fun has(portLocode: String, segmentCodes: List): Boolean + fun has( + portLocode: String, + segmentCodes: List, + ): Boolean } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PortRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PortRepository.kt index d003db362e..6c29466542 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PortRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PortRepository.kt @@ -5,6 +5,7 @@ import fr.gouv.cnsp.monitorfish.domain.exceptions.CodeNotFoundException interface PortRepository { fun findAll(): List + fun findAllActive(): List @Throws(CodeNotFoundException::class) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PositionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PositionRepository.kt index 788143a804..fb8d8bc6cc 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PositionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PositionRepository.kt @@ -5,7 +5,9 @@ import java.time.ZonedDateTime interface PositionRepository { fun findAll(): List + fun findAllByMmsi(mmsi: String): List + fun findVesselLastPositionsByIrcs( ircs: String, from: ZonedDateTime, @@ -33,5 +35,6 @@ interface PositionRepository { ): List fun save(position: Position) + fun findLastPositionDate(): ZonedDateTime } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PriorNotificationPdfDocumentRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PriorNotificationPdfDocumentRepository.kt index 307ff1656c..38e83fd19b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PriorNotificationPdfDocumentRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/PriorNotificationPdfDocumentRepository.kt @@ -4,5 +4,6 @@ import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PdfDocument interface PriorNotificationPdfDocumentRepository { fun findByReportId(reportId: String): PdfDocument + fun deleteByReportId(reportId: String) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/SilencedAlertRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/SilencedAlertRepository.kt index f49c26dc76..154cd6fcaa 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/SilencedAlertRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/SilencedAlertRepository.kt @@ -10,8 +10,10 @@ interface SilencedAlertRepository { silencedBeforeDate: ZonedDateTime, isValidated: Boolean, ): SilencedAlert + fun save(silencedAlert: SilencedAlert): SilencedAlert fun findAllCurrentSilencedAlerts(): List + fun delete(id: Int) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/UserAuthorizationRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/UserAuthorizationRepository.kt index a2567e93e3..c67522f5f7 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/UserAuthorizationRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/UserAuthorizationRepository.kt @@ -4,6 +4,8 @@ import fr.gouv.cnsp.monitorfish.domain.entities.authorization.UserAuthorization interface UserAuthorizationRepository { fun findByHashedEmail(hashedEmail: String): UserAuthorization + fun save(user: UserAuthorization) + fun delete(hashedEmail: String) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/VesselRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/VesselRepository.kt index 57aebfb817..bba1e2b506 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/VesselRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/repositories/VesselRepository.kt @@ -22,5 +22,8 @@ interface VesselRepository { fun search(searched: String): List - fun findUnderCharterForVessel(vesselIdentifier: VesselIdentifier, value: String): Boolean + fun findUnderCharterForVessel( + vesselIdentifier: VesselIdentifier, + value: String, + ): Boolean } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/alert/SilenceAlert.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/alert/SilenceAlert.kt index 362843fe47..8211c63fa8 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/alert/SilenceAlert.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/alert/SilenceAlert.kt @@ -42,16 +42,19 @@ class SilenceAlert( } private fun getSilencedAlertWithNatinf(silencedAlert: SilencedAlert): SilencedAlert { - val nextValueWithNatinf: AlertType = when (silencedAlert.value.type) { - AlertTypeMapping.THREE_MILES_TRAWLING_ALERT -> ThreeMilesTrawlingAlert() - AlertTypeMapping.FRENCH_EEZ_FISHING_ALERT -> FrenchEEZFishingAlert() - AlertTypeMapping.TWELVE_MILES_FISHING_ALERT -> TwelveMilesFishingAlert() - AlertTypeMapping.MISSING_FAR_ALERT -> MissingFARAlert() - AlertTypeMapping.MISSING_FAR_48_HOURS_ALERT -> MissingFAR48HoursAlert() - else -> { - throw IllegalArgumentException("The alert type '${silencedAlert.value.type}' could not be silenced.") + val nextValueWithNatinf: AlertType = + when (silencedAlert.value.type) { + AlertTypeMapping.THREE_MILES_TRAWLING_ALERT -> ThreeMilesTrawlingAlert() + AlertTypeMapping.FRENCH_EEZ_FISHING_ALERT -> FrenchEEZFishingAlert() + AlertTypeMapping.TWELVE_MILES_FISHING_ALERT -> TwelveMilesFishingAlert() + AlertTypeMapping.MISSING_FAR_ALERT -> MissingFARAlert() + AlertTypeMapping.MISSING_FAR_48_HOURS_ALERT -> MissingFAR48HoursAlert() + else -> { + throw IllegalArgumentException( + "The alert type '${silencedAlert.value.type}' could not be silenced.", + ) + } } - } return silencedAlert.copy(value = nextValueWithNatinf) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/alert/SilencePendingAlert.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/alert/SilencePendingAlert.kt index da16ef5995..132fa053e0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/alert/SilencePendingAlert.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/alert/SilencePendingAlert.kt @@ -30,26 +30,28 @@ class SilencePendingAlert( } } - val before = when (silenceAlertPeriod) { - SilenceAlertPeriod.THIS_OCCURRENCE -> ZonedDateTime.now() - SilenceAlertPeriod.ONE_HOUR -> ZonedDateTime.now().plusHours(1) - SilenceAlertPeriod.TWO_HOURS -> ZonedDateTime.now().plusHours(2) - SilenceAlertPeriod.SIX_HOURS -> ZonedDateTime.now().plusHours(6) - SilenceAlertPeriod.TWELVE_HOURS -> ZonedDateTime.now().plusHours(12) - SilenceAlertPeriod.ONE_DAY -> ZonedDateTime.now().plusDays(1) - SilenceAlertPeriod.ONE_WEEK -> ZonedDateTime.now().plusWeeks(1) - SilenceAlertPeriod.ONE_MONTH -> ZonedDateTime.now().plusMonths(1) - SilenceAlertPeriod.ONE_YEAR -> ZonedDateTime.now().plusYears(1) - SilenceAlertPeriod.CUSTOM -> beforeDateTime!! - } + val before = + when (silenceAlertPeriod) { + SilenceAlertPeriod.THIS_OCCURRENCE -> ZonedDateTime.now() + SilenceAlertPeriod.ONE_HOUR -> ZonedDateTime.now().plusHours(1) + SilenceAlertPeriod.TWO_HOURS -> ZonedDateTime.now().plusHours(2) + SilenceAlertPeriod.SIX_HOURS -> ZonedDateTime.now().plusHours(6) + SilenceAlertPeriod.TWELVE_HOURS -> ZonedDateTime.now().plusHours(12) + SilenceAlertPeriod.ONE_DAY -> ZonedDateTime.now().plusDays(1) + SilenceAlertPeriod.ONE_WEEK -> ZonedDateTime.now().plusWeeks(1) + SilenceAlertPeriod.ONE_MONTH -> ZonedDateTime.now().plusMonths(1) + SilenceAlertPeriod.ONE_YEAR -> ZonedDateTime.now().plusYears(1) + SilenceAlertPeriod.CUSTOM -> beforeDateTime!! + } val silencedAlert = pendingAlertRepository.find(alertId) - val savedSilencedAlert = silencedAlertRepository.save( - alert = silencedAlert, - silencedBeforeDate = before, - isValidated = false, - ) + val savedSilencedAlert = + silencedAlertRepository.save( + alert = silencedAlert, + silencedBeforeDate = before, + isValidated = false, + ) pendingAlertRepository.delete(alertId) updateLastPositionBeforePipelineUpdate(silencedAlert) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/GetIsAuthorizedUser.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/GetIsAuthorizedUser.kt index cd84c32bc4..d3d27b04fa 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/GetIsAuthorizedUser.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/GetIsAuthorizedUser.kt @@ -11,7 +11,10 @@ class GetIsAuthorizedUser( ) { private val logger = LoggerFactory.getLogger(GetIsAuthorizedUser::class.java) - fun execute(email: String, isSuperUserPath: Boolean): Boolean { + fun execute( + email: String, + isSuperUserPath: Boolean, + ): Boolean { /** * If the path is not super-user protected, authorize any logged user */ @@ -21,15 +24,16 @@ class GetIsAuthorizedUser( val hashedEmail = hash(email) - val userAuthorization = try { - userAuthorizationRepository.findByHashedEmail(hashedEmail) - } catch (e: Throwable) { - /** - * If the user is not found in the `UserAuthorizationRepository` and the path - * is super-user protected, reject - */ - return false - } + val userAuthorization = + try { + userAuthorizationRepository.findByHashedEmail(hashedEmail) + } catch (e: Throwable) { + /** + * If the user is not found in the `UserAuthorizationRepository` and the path + * is super-user protected, reject + */ + return false + } return userAuthorization.isSuperUser } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/SaveUser.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/SaveUser.kt index 5056b21091..d12784f662 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/SaveUser.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/SaveUser.kt @@ -9,11 +9,15 @@ import fr.gouv.cnsp.monitorfish.domain.repositories.UserAuthorizationRepository class SaveUser( private val userAuthorizationRepository: UserAuthorizationRepository, ) { - fun execute(email: String, isSuperUser: Boolean) { - val user = UserAuthorization( - hashedEmail = hash(email), - isSuperUser = isSuperUser, - ) + fun execute( + email: String, + isSuperUser: Boolean, + ) { + val user = + UserAuthorization( + hashedEmail = hash(email), + isSuperUser = isSuperUser, + ) userAuthorizationRepository.save(user) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetBeaconMalfunction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetBeaconMalfunction.kt index 4321f78ccb..3d1fe929ef 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetBeaconMalfunction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetBeaconMalfunction.kt @@ -19,19 +19,23 @@ class GetBeaconMalfunction( fun execute(beaconMalfunctionId: Int): BeaconMalfunctionResumeAndDetails { val lastPositions = lastPositionRepository.findAll() val beaconMalfunction = beaconMalfunctionsRepository.find(beaconMalfunctionId) - val beaconMalfunctionComments = beaconMalfunctionCommentsRepository.findAllByBeaconMalfunctionId( - beaconMalfunctionId, - ) - val beaconMalfunctionActions = beaconMalfunctionActionsRepository.findAllByBeaconMalfunctionId( - beaconMalfunctionId, - ) - val beaconMalfunctionNotifications = beaconMalfunctionNotificationsRepository.findAllByBeaconMalfunctionId( - beaconMalfunctionId, - ) + val beaconMalfunctionComments = + beaconMalfunctionCommentsRepository.findAllByBeaconMalfunctionId( + beaconMalfunctionId, + ) + val beaconMalfunctionActions = + beaconMalfunctionActionsRepository.findAllByBeaconMalfunctionId( + beaconMalfunctionId, + ) + val beaconMalfunctionNotifications = + beaconMalfunctionNotificationsRepository.findAllByBeaconMalfunctionId( + beaconMalfunctionId, + ) - val riskFactor = lastPositions.find( - BeaconMalfunction.getVesselFromBeaconMalfunction(beaconMalfunction), - )?.riskFactor + val riskFactor = + lastPositions.find( + BeaconMalfunction.getVesselFromBeaconMalfunction(beaconMalfunction), + )?.riskFactor beaconMalfunction.riskFactor = riskFactor if (riskFactor == null) { @@ -41,32 +45,42 @@ class GetBeaconMalfunction( } val oneYearBefore = ZonedDateTime.now().minusYears(1) - val vesselBeaconMalfunctions = beaconMalfunctionsRepository.findAllByVesselId( - beaconMalfunction.vesselId, - oneYearBefore, - ) + val vesselBeaconMalfunctions = + beaconMalfunctionsRepository.findAllByVesselId( + beaconMalfunction.vesselId, + oneYearBefore, + ) - val beaconMalfunctionsWithDetails = vesselBeaconMalfunctions.map { vesselBeaconMalfunction -> - val comments = beaconMalfunctionCommentsRepository.findAllByBeaconMalfunctionId(vesselBeaconMalfunction.id) - val actions = beaconMalfunctionActionsRepository.findAllByBeaconMalfunctionId(vesselBeaconMalfunction.id) + val beaconMalfunctionsWithDetails = + vesselBeaconMalfunctions.map { vesselBeaconMalfunction -> + val comments = + beaconMalfunctionCommentsRepository.findAllByBeaconMalfunctionId( + vesselBeaconMalfunction.id, + ) + val actions = + beaconMalfunctionActionsRepository.findAllByBeaconMalfunctionId( + vesselBeaconMalfunction.id, + ) - BeaconMalfunctionWithDetails(vesselBeaconMalfunction, comments, actions) - } + BeaconMalfunctionWithDetails(vesselBeaconMalfunction, comments, actions) + } - val vesselBeaconMalfunctionsResume = VesselBeaconMalfunctionsResume.fromBeaconMalfunctions( - beaconMalfunctionsWithDetails, - ) + val vesselBeaconMalfunctionsResume = + VesselBeaconMalfunctionsResume.fromBeaconMalfunctions( + beaconMalfunctionsWithDetails, + ) - val notifications = beaconMalfunctionNotifications - .groupBy { it.toGroupByKeys() } - .map { - BeaconMalfunctionNotifications( - dateTimeUtc = it.key.dateTimeUtc, - beaconMalfunctionId = it.key.beaconMalfunctionId, - notificationType = it.key.notificationType, - notifications = it.value, - ) - } + val notifications = + beaconMalfunctionNotifications + .groupBy { it.toGroupByKeys() } + .map { + BeaconMalfunctionNotifications( + dateTimeUtc = it.key.dateTimeUtc, + beaconMalfunctionId = it.key.beaconMalfunctionId, + notificationType = it.key.notificationType, + notifications = it.value, + ) + } return BeaconMalfunctionResumeAndDetails( beaconMalfunction = beaconMalfunction, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/SaveBeaconMalfunctionComment.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/SaveBeaconMalfunctionComment.kt index d14df07fa9..31ad5319b3 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/SaveBeaconMalfunctionComment.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/SaveBeaconMalfunctionComment.kt @@ -18,12 +18,13 @@ class SaveBeaconMalfunctionComment( comment: String, userType: BeaconMalfunctionCommentUserType, ): BeaconMalfunctionResumeAndDetails { - val beaconMalfunctionComment = BeaconMalfunctionComment( - beaconMalfunctionId = beaconMalfunctionId, - comment = comment, - userType = userType, - dateTime = ZonedDateTime.now(), - ) + val beaconMalfunctionComment = + BeaconMalfunctionComment( + beaconMalfunctionId = beaconMalfunctionId, + comment = comment, + userType = userType, + dateTime = ZonedDateTime.now(), + ) beaconMalfunctionCommentsRepository.save(beaconMalfunctionComment) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/UpdateBeaconMalfunction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/UpdateBeaconMalfunction.kt index 4e629f19a8..0ccd8eaca4 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/UpdateBeaconMalfunction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/UpdateBeaconMalfunction.kt @@ -34,32 +34,36 @@ class UpdateBeaconMalfunction( beaconMalfunctionsRepository.update(id, vesselStatus, stage, endOfBeaconMalfunctionReason, updateDateTime) - var propertyName: BeaconMalfunctionActionPropertyName? = vesselStatus?.let { - BeaconMalfunctionActionPropertyName.VESSEL_STATUS - } + var propertyName: BeaconMalfunctionActionPropertyName? = + vesselStatus?.let { + BeaconMalfunctionActionPropertyName.VESSEL_STATUS + } propertyName = stage?.let { BeaconMalfunctionActionPropertyName.STAGE } ?: propertyName require(propertyName != null) { "The property to update could not be identified" } - val previousValue = when (propertyName) { - BeaconMalfunctionActionPropertyName.STAGE -> previousBeaconMalfunction.stage.name - BeaconMalfunctionActionPropertyName.VESSEL_STATUS -> previousBeaconMalfunction.vesselStatus.name - } + val previousValue = + when (propertyName) { + BeaconMalfunctionActionPropertyName.STAGE -> previousBeaconMalfunction.stage.name + BeaconMalfunctionActionPropertyName.VESSEL_STATUS -> previousBeaconMalfunction.vesselStatus.name + } - val nextValue = when (propertyName) { - BeaconMalfunctionActionPropertyName.STAGE -> stage!!.name - BeaconMalfunctionActionPropertyName.VESSEL_STATUS -> vesselStatus!!.name - } + val nextValue = + when (propertyName) { + BeaconMalfunctionActionPropertyName.STAGE -> stage!!.name + BeaconMalfunctionActionPropertyName.VESSEL_STATUS -> vesselStatus!!.name + } - val beaconMalfunctionAction = BeaconMalfunctionAction( - beaconMalfunctionId = id, - propertyName = propertyName, - previousValue = previousValue, - nextValue = nextValue, - dateTime = updateDateTime, - ) + val beaconMalfunctionAction = + BeaconMalfunctionAction( + beaconMalfunctionId = id, + propertyName = propertyName, + previousValue = previousValue, + nextValue = nextValue, + dateTime = updateDateTime, + ) beaconMalfunctionActionsRepository.save(beaconMalfunctionAction) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/control_objective/AddControlObjective.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/control_objective/AddControlObjective.kt index ef35ee825d..7e1a1df075 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/control_objective/AddControlObjective.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/control_objective/AddControlObjective.kt @@ -6,7 +6,11 @@ import fr.gouv.cnsp.monitorfish.domain.repositories.ControlObjectivesRepository @UseCase class AddControlObjective(private val controlObjectivesRepository: ControlObjectivesRepository) { - fun execute(segment: String, facade: String, year: Int): Int { + fun execute( + segment: String, + facade: String, + year: Int, + ): Int { return controlObjectivesRepository.add( ControlObjective( segment = segment, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeFaoAreasFromCoordinates.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeFaoAreasFromCoordinates.kt index 7ba1eff630..8c253eb128 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeFaoAreasFromCoordinates.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeFaoAreasFromCoordinates.kt @@ -9,7 +9,10 @@ import org.locationtech.jts.geom.GeometryFactory @UseCase class ComputeFaoAreasFromCoordinates(private val faoAreaRepository: FaoAreaRepository) { - fun execute(longitude: Double, latitude: Double): List { + fun execute( + longitude: Double, + latitude: Double, + ): List { val point = GeometryFactory().createPoint(Coordinate(longitude, latitude)) val allFaoAreas = faoAreaRepository.findByIncluding(point) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeVesselFaoAreas.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeVesselFaoAreas.kt index 513d1d5c62..a9aca0359f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeVesselFaoAreas.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeVesselFaoAreas.kt @@ -38,11 +38,12 @@ class ComputeVesselFaoAreas( if (internalReferenceNumber != null) { // Get faoZones from speciesOnboard in risk factors table (updated by the pipeline) val vesselRiskFactor = riskFactorRepository.findByInternalReferenceNumber(internalReferenceNumber) - val faoAreas = vesselRiskFactor?.let { - it.speciesOnboard?.let { species -> - species.mapNotNull { specy -> specy.faoZone } - } - } ?: listOf() + val faoAreas = + vesselRiskFactor?.let { + it.speciesOnboard?.let { species -> + species.mapNotNull { specy -> specy.faoZone } + } + } ?: listOf() if (faoAreas.isNotEmpty()) { val faoAreasObjects = faoAreas.map { FaoArea(faoCode = it) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/ComputeFleetSegments.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/ComputeFleetSegments.kt index 570364d0b0..0769643560 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/ComputeFleetSegments.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/ComputeFleetSegments.kt @@ -26,19 +26,22 @@ class ComputeFleetSegments( val currentYear = ZonedDateTime.now(clock).year val fleetSegments = fleetSegmentRepository.findAllByYear(currentYear) - val computedSegments = fleetSegments.filter { fleetSegment -> - val isContainingGearFromList = - fleetSegment.gears.isEmpty() || fleetSegment.gears.any { gearCodes.contains(it) } - val isContainingSpecyFromList = - (fleetSegment.targetSpecies.isEmpty() && fleetSegment.bycatchSpecies.isEmpty()) || - fleetSegment.targetSpecies.any { specyCodes.contains(it) } || - fleetSegment.bycatchSpecies.any { specyCodes.contains(it) } - val isContainingFaoAreaFromList = fleetSegment.faoAreas.isEmpty() || fleetSegment.faoAreas.any { faoArea -> - faoAreas.map { FaoArea(it) }.any { it.hasFaoCodeIncludedIn(faoArea) } - } + val computedSegments = + fleetSegments.filter { fleetSegment -> + val isContainingGearFromList = + fleetSegment.gears.isEmpty() || fleetSegment.gears.any { gearCodes.contains(it) } + val isContainingSpecyFromList = + (fleetSegment.targetSpecies.isEmpty() && fleetSegment.bycatchSpecies.isEmpty()) || + fleetSegment.targetSpecies.any { specyCodes.contains(it) } || + fleetSegment.bycatchSpecies.any { specyCodes.contains(it) } + val isContainingFaoAreaFromList = + fleetSegment.faoAreas.isEmpty() || + fleetSegment.faoAreas.any { faoArea -> + faoAreas.map { FaoArea(it) }.any { it.hasFaoCodeIncludedIn(faoArea) } + } - return@filter isContainingGearFromList && isContainingSpecyFromList && isContainingFaoAreaFromList - } + return@filter isContainingGearFromList && isContainingSpecyFromList && isContainingFaoAreaFromList + } return computedSegments } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/CreateFleetSegment.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/CreateFleetSegment.kt index f2a3bbdaaa..631550cb4e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/CreateFleetSegment.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/CreateFleetSegment.kt @@ -16,19 +16,20 @@ class CreateFleetSegment(private val fleetSegmentRepository: FleetSegmentReposit "Year must be provided" } - val newSegment = fields.let { - FleetSegment( - segment = it.segment!!, - segmentName = it.segmentName ?: "", - dirm = listOf(), - gears = it.gears ?: listOf(), - faoAreas = it.faoAreas ?: listOf(), - targetSpecies = it.targetSpecies ?: listOf(), - bycatchSpecies = it.bycatchSpecies ?: listOf(), - impactRiskFactor = it.impactRiskFactor ?: 0.0, - year = it.year!!, - ) - } + val newSegment = + fields.let { + FleetSegment( + segment = it.segment!!, + segmentName = it.segmentName ?: "", + dirm = listOf(), + gears = it.gears ?: listOf(), + faoAreas = it.faoAreas ?: listOf(), + targetSpecies = it.targetSpecies ?: listOf(), + bycatchSpecies = it.bycatchSpecies ?: listOf(), + impactRiskFactor = it.impactRiskFactor ?: 0.0, + year = it.year!!, + ) + } return fleetSegmentRepository.create(newSegment) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/DeleteFleetSegment.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/DeleteFleetSegment.kt index 3ce8743285..7c56344fde 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/DeleteFleetSegment.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/DeleteFleetSegment.kt @@ -8,7 +8,10 @@ import fr.gouv.cnsp.monitorfish.domain.repositories.FleetSegmentRepository @UseCase class DeleteFleetSegment(private val fleetSegmentRepository: FleetSegmentRepository) { @Throws(CouldNotDeleteException::class, IllegalArgumentException::class) - fun execute(segment: String, year: Int): List { + fun execute( + segment: String, + year: Int, + ): List { return fleetSegmentRepository.delete(segment, year) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UpdateFleetSegment.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UpdateFleetSegment.kt index 3a7c86a989..d63f221723 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UpdateFleetSegment.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UpdateFleetSegment.kt @@ -9,7 +9,11 @@ import fr.gouv.cnsp.monitorfish.domain.use_cases.dtos.CreateOrUpdateFleetSegment @UseCase class UpdateFleetSegment(private val fleetSegmentRepository: FleetSegmentRepository) { @Throws(CouldNotUpdateFleetSegmentException::class, IllegalArgumentException::class) - fun execute(segment: String, fields: CreateOrUpdateFleetSegmentFields, year: Int): FleetSegment { + fun execute( + segment: String, + fields: CreateOrUpdateFleetSegmentFields, + year: Int, + ): FleetSegment { require( fields.segment != null || fields.bycatchSpecies != null || diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/Utils.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/Utils.kt index daaa1acc60..f3520fafd9 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/Utils.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/Utils.kt @@ -19,11 +19,12 @@ fun removeRedundantFaoArea(faoAreas: List): List { return distinctFAOAreas .filter { currentFaoArea -> // If there is no faoCode, we do not keep this faoArea - val anotherFaoAreaContainingCurrent = distinctFAOAreas - // We remove the currentFaoArea from the list - .filter { it !== currentFaoArea } - // We check if another faoArea starts with the currentFaoArea - .any { it.faoCode.startsWith(currentFaoArea.faoCode) } + val anotherFaoAreaContainingCurrent = + distinctFAOAreas + // We remove the currentFaoArea from the list + .filter { it !== currentFaoArea } + // We check if another faoArea starts with the currentFaoArea + .any { it.faoCode.startsWith(currentFaoArea.faoCode) } // If another faoArea contains the currentFaoArea, then we remove the currentFaoArea if (anotherFaoAreaContainingCurrent) { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/gear/GetAllGears.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/gear/GetAllGears.kt index 4c21bff88b..df38ddd44c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/gear/GetAllGears.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/gear/GetAllGears.kt @@ -13,18 +13,20 @@ class GetAllGears( private val GearCodeGroupRepository: GearCodeGroupRepository, ) { private val logger = LoggerFactory.getLogger(GetAllGears::class.java) + fun execute(): List { val allGears = gearRepository.findAll() - val allGearsWithGroup = allGears - .map { - try { - val gearCodeGroup = GearCodeGroupRepository.find(it.code) - it.groupId = gearCodeGroup.groupId - } catch (e: CodeNotFoundException) { - logger.warn(e.message) + val allGearsWithGroup = + allGears + .map { + try { + val gearCodeGroup = GearCodeGroupRepository.find(it.code) + it.groupId = gearCodeGroup.groupId + } catch (e: CodeNotFoundException) { + logger.warn(e.message) + } + it } - it - } return allGearsWithGroup } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissions.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissions.kt index c4abfeb32c..0b76cd812c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissions.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissions.kt @@ -30,30 +30,33 @@ class GetAllMissions( missionStatuses: List?, seaFronts: List?, ): List { - val missions = missionRepository.findAllMissions( - pageNumber, - pageSize, - startedAfterDateTime, - startedBeforeDateTime, - missionSources, - missionTypes, - missionStatuses, - seaFronts, - ) + val missions = + missionRepository.findAllMissions( + pageNumber, + pageSize, + startedAfterDateTime, + startedBeforeDateTime, + missionSources, + missionTypes, + missionStatuses, + seaFronts, + ) - val allMissionsActions = missions - .chunked(databaseProperties.missionsActionsChunkSize) - .map { chunkedMissions -> - val ids = chunkedMissions.map { it.id } - return@map missionActionsRepository.findMissionActionsIn(ids) - } - .flatten() + val allMissionsActions = + missions + .chunked(databaseProperties.missionsActionsChunkSize) + .map { chunkedMissions -> + val ids = chunkedMissions.map { it.id } + return@map missionActionsRepository.findMissionActionsIn(ids) + } + .flatten() logger.info("Got ${allMissionsActions.size} mission actions associated to fetched missions.") return missions.map { mission -> - val missionActions = allMissionsActions - .filter { it.missionId == mission.id } - .sortedByDescending { it.actionDatetimeUtc } + val missionActions = + allMissionsActions + .filter { it.missionId == mission.id } + .sortedByDescending { it.actionDatetimeUtc } return@map MissionAndActions(mission, missionActions) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMission.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMission.kt index feb8d82a37..c664883914 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMission.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMission.kt @@ -16,9 +16,10 @@ class GetMission( @Throws(CouldNotFindException::class) suspend fun execute(missionId: Int): MissionAndActions { return coroutineScope { - val missionFuture = async { - missionRepository.findById(missionId) - } + val missionFuture = + async { + missionRepository.findById(missionId) + } val actions = getMissionActions.execute(missionId) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReports.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReports.kt index 7ea7a9a435..d35548647c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReports.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReports.kt @@ -23,7 +23,11 @@ class GetActivityReports( ) { private val logger = LoggerFactory.getLogger(GetActivityReports::class.java) - fun execute(beforeDateTime: ZonedDateTime, afterDateTime: ZonedDateTime, jdp: JointDeploymentPlan): ActivityReports { + fun execute( + beforeDateTime: ZonedDateTime, + afterDateTime: ZonedDateTime, + jdp: JointDeploymentPlan, + ): ActivityReports { val controls = missionActionsRepository.findSeaAndLandControlBetweenDates(beforeDateTime, afterDateTime) logger.info("Found ${controls.size} controls between dates [$afterDateTime, $beforeDateTime].") @@ -41,87 +45,97 @@ class GetActivityReports( val missions = missionRepository.findByIds(missionIds) logger.info("Found ${missions.size} missions.") - val filteredControls = controls.filter { control -> - when (control.actionType) { - MissionActionType.LAND_CONTROL -> { - return@filter jdp.isLandControlApplicable(control) - } - - MissionActionType.SEA_CONTROL -> { - val controlMission = missions.firstOrNull { mission -> mission.id == control.missionId } - val isUnderJdp = controlMission?.isUnderJdp == true - if (controlMission == null) { - logger.error( - "Mission id '${control.missionId}' linked to SEA control id '${control.id}' could not be found. Is this mission deleted ?", - ) + val filteredControls = + controls.filter { control -> + when (control.actionType) { + MissionActionType.LAND_CONTROL -> { + return@filter jdp.isLandControlApplicable(control) } - if (control.faoAreas.isNotEmpty()) { - return@filter isUnderJdp && jdp.isAttributedJdp(control) + MissionActionType.SEA_CONTROL -> { + val controlMission = missions.firstOrNull { mission -> mission.id == control.missionId } + val isUnderJdp = controlMission?.isUnderJdp == true + if (controlMission == null) { + logger.error( + "Mission id '${control.missionId}' linked to SEA control id '${control.id}' could not be found. Is this mission deleted ?", + ) + } + + if (control.faoAreas.isNotEmpty()) { + return@filter isUnderJdp && jdp.isAttributedJdp(control) + } + + // The mission must be under JDP + return@filter isUnderJdp } - // The mission must be under JDP - return@filter isUnderJdp + else -> throw IllegalArgumentException("Bad control type: ${control.actionType}") } - - else -> throw IllegalArgumentException("Bad control type: ${control.actionType}") + }.filter { control -> + val controlMission = missions.firstOrNull { mission -> mission.id == control.missionId } + // All AECP reports are excluded from the response + // see: https://github.com/MTES-MCT/monitorfish/issues/3194 + return@filter !( + controlMission?.controlUnits?.any { + controlUnit -> + controlUnit.administration == "AECP" + } ?: false + ) } - }.filter { control -> - val controlMission = missions.firstOrNull { mission -> mission.id == control.missionId } - // All AECP reports are excluded from the response - // see: https://github.com/MTES-MCT/monitorfish/issues/3194 - return@filter !(controlMission?.controlUnits?.any { controlUnit -> controlUnit.administration == "AECP" } ?: false) - } logger.info("Found ${filteredControls.size} controls to report.") - val activityReports = filteredControls.map { control -> - val activityCode = when (control.actionType) { - MissionActionType.LAND_CONTROL -> ActivityCode.LAN - MissionActionType.SEA_CONTROL -> ActivityCode.FIS - else -> throw IllegalArgumentException("Bad control type: ${control.actionType}") - } + val activityReports = + filteredControls.map { control -> + val activityCode = + when (control.actionType) { + MissionActionType.LAND_CONTROL -> ActivityCode.LAN + MissionActionType.SEA_CONTROL -> ActivityCode.FIS + else -> throw IllegalArgumentException("Bad control type: ${control.actionType}") + } - val controlledVessel = try { - vessels.first { vessel -> vessel.id == control.vesselId } - } catch (e: NoSuchElementException) { - logger.error("The vessel id ${control.vesselId} could not be found.", e) + val controlledVessel = + try { + vessels.first { vessel -> vessel.id == control.vesselId } + } catch (e: NoSuchElementException) { + logger.error("The vessel id ${control.vesselId} could not be found.", e) - return@map null - } - val controlMission = try { - missions.first { mission -> mission.id == control.missionId } - } catch (e: NoSuchElementException) { - logger.error( - "Mission id '${control.missionId}' linked to ${control.actionType} control id '${control.id}' could not be found. Is this mission deleted ?", - e, - ) + return@map null + } + val controlMission = + try { + missions.first { mission -> mission.id == control.missionId } + } catch (e: NoSuchElementException) { + logger.error( + "Mission id '${control.missionId}' linked to ${control.actionType} control id '${control.id}' could not be found. Is this mission deleted ?", + e, + ) - return@map null - } + return@map null + } - control.portLocode?.let { port -> - try { - control.portName = portRepository.findByLocode(port).name - } catch (e: CodeNotFoundException) { - logger.warn(e.message) + control.portLocode?.let { port -> + try { + control.portName = portRepository.findByLocode(port).name + } catch (e: CodeNotFoundException) { + logger.warn(e.message) + } } - } - val faoArea = jdp.getFirstFaoAreaIncludedInJdp(control) - - ActivityReport( - action = control, - activityCode = activityCode, - controlUnits = controlMission.controlUnits, - faoArea = faoArea?.faoCode, - /** - * The fleet segment is set as null, as we need to integrate the EFCA segments referential - * see: https://github.com/MTES-MCT/monitorfish/issues/3157#issuecomment-2093036583 - */ - segment = null, - vesselNationalIdentifier = controlledVessel.getNationalIdentifier(), - vessel = controlledVessel, - ) - }.filterNotNull() + val faoArea = jdp.getFirstFaoAreaIncludedInJdp(control) + + ActivityReport( + action = control, + activityCode = activityCode, + controlUnits = controlMission.controlUnits, + faoArea = faoArea?.faoCode, + /** + * The fleet segment is set as null, as we need to integrate the EFCA segments referential + * see: https://github.com/MTES-MCT/monitorfish/issues/3157#issuecomment-2093036583 + */ + segment = null, + vesselNationalIdentifier = controlledVessel.getNationalIdentifier(), + vessel = controlledVessel, + ) + }.filterNotNull() return ActivityReports( activityReports = activityReports, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActions.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActions.kt index 2e4e05d745..90bf102c81 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActions.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActions.kt @@ -13,8 +13,9 @@ class GetMissionActions( fun execute(missionId: Int): List { logger.debug("Searching undeleted actions for mission $missionId") - val actions = missionActionsRepository.findByMissionId(missionId) - .sortedByDescending { it.actionDatetimeUtc } + val actions = + missionActionsRepository.findByMissionId(missionId) + .sortedByDescending { it.actionDatetimeUtc } logger.debug("Found ${actions.size} undeleted actions for mission $missionId") return actions diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControls.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControls.kt index 1de4e1f9cc..3668760adf 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControls.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControls.kt @@ -21,62 +21,72 @@ class GetVesselControls( ) { private val logger = LoggerFactory.getLogger(GetVesselControls::class.java) - suspend fun execute(vesselId: Int, afterDateTime: ZonedDateTime): ControlsSummary = coroutineScope { - logger.debug("Searching controls for vessel {} after {}", vesselId, afterDateTime) - val controls = missionActionsRepository.findVesselMissionActionsAfterDateTime(vesselId, afterDateTime) - .filter { - it.actionType in setOf( - MissionActionType.SEA_CONTROL, - MissionActionType.AIR_CONTROL, - MissionActionType.LAND_CONTROL, - ) - } - logger.debug("Found ${controls.size} controls for vessel $vesselId") + suspend fun execute( + vesselId: Int, + afterDateTime: ZonedDateTime, + ): ControlsSummary = + coroutineScope { + logger.debug("Searching controls for vessel {} after {}", vesselId, afterDateTime) + val controls = + missionActionsRepository.findVesselMissionActionsAfterDateTime(vesselId, afterDateTime) + .filter { + it.actionType in + setOf( + MissionActionType.SEA_CONTROL, + MissionActionType.AIR_CONTROL, + MissionActionType.LAND_CONTROL, + ) + } + logger.debug("Found ${controls.size} controls for vessel $vesselId") - val controlsWithCodeValues = controls.map { action -> - val controlUnits = missionRepository.findControlUnitsOfMission(this, action.missionId) + val controlsWithCodeValues = + controls.map { action -> + val controlUnits = missionRepository.findControlUnitsOfMission(this, action.missionId) - Pair(action, controlUnits) - }.map { (control, controlUnits) -> - control.controlUnits = controlUnits.await() + Pair(action, controlUnits) + }.map { (control, controlUnits) -> + control.controlUnits = controlUnits.await() - control.portLocode?.let { port -> - try { - control.portName = portRepository.findByLocode(port).name - } catch (e: CodeNotFoundException) { - logger.warn(e.message) - } - } + control.portLocode?.let { port -> + try { + control.portName = portRepository.findByLocode(port).name + } catch (e: CodeNotFoundException) { + logger.warn(e.message) + } + } - control.gearOnboard.forEach { gearControl -> - gearControl.gearCode?.let { gear -> - try { - gearControl.gearName = gearRepository.findByCode(gear).name - } catch (e: CodeNotFoundException) { - logger.warn(e.message) + control.gearOnboard.forEach { gearControl -> + gearControl.gearCode?.let { gear -> + try { + gearControl.gearName = gearRepository.findByCode(gear).name + } catch (e: CodeNotFoundException) { + logger.warn(e.message) + } + } } - } - } - control - } + control + } - val numberOfDiversions = controlsWithCodeValues - .filter { it.seizureAndDiversion == true } - .size - val numberOfControlsWithSomeGearsSeized = controlsWithCodeValues - .filter { it.hasSomeGearsSeized == true } - .size - val numberOfControlsWithSomeSpeciesSeized = controlsWithCodeValues - .filter { it.hasSomeSpeciesSeized == true } - .size + val numberOfDiversions = + controlsWithCodeValues + .filter { it.seizureAndDiversion == true } + .size + val numberOfControlsWithSomeGearsSeized = + controlsWithCodeValues + .filter { it.hasSomeGearsSeized == true } + .size + val numberOfControlsWithSomeSpeciesSeized = + controlsWithCodeValues + .filter { it.hasSomeSpeciesSeized == true } + .size - ControlsSummary( - vesselId = vesselId, - numberOfDiversions = numberOfDiversions, - numberOfControlsWithSomeGearsSeized = numberOfControlsWithSomeGearsSeized, - numberOfControlsWithSomeSpeciesSeized = numberOfControlsWithSomeSpeciesSeized, - controls = controlsWithCodeValues, - ) - } + ControlsSummary( + vesselId = vesselId, + numberOfDiversions = numberOfDiversions, + numberOfControlsWithSomeGearsSeized = numberOfControlsWithSomeGearsSeized, + numberOfControlsWithSomeSpeciesSeized = numberOfControlsWithSomeSpeciesSeized, + controls = controlsWithCodeValues, + ) + } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/PatchMissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/PatchMissionAction.kt index d759070d10..116b8f9088 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/PatchMissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/PatchMissionAction.kt @@ -13,8 +13,10 @@ class PatchMissionAction( private val missionActionsRepository: MissionActionsRepository, private val patchMissionAction: PatchEntity, ) { - - fun execute(id: Int, patchableEnvActionEntity: PatchableMissionAction): MissionAction { + fun execute( + id: Int, + patchableEnvActionEntity: PatchableMissionAction, + ): MissionAction { return try { val previousMissionAction = missionActionsRepository.findById(id) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionAction.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionAction.kt index 3aba59d0b8..bd8194ebaf 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionAction.kt @@ -12,17 +12,21 @@ class UpdateMissionAction( ) { private val logger = LoggerFactory.getLogger(UpdateMissionAction::class.java) - fun execute(actionId: Int, action: MissionAction): MissionAction { + fun execute( + actionId: Int, + action: MissionAction, + ): MissionAction { logger.info("Updating mission action $actionId") action.verify() // We store the `storedValue` of the enum and not the enum uppercase value val facade = getMissionActionFacade.execute(action)?.toString() - val actionWithId = action.copy( - id = actionId, - facade = facade, - ) + val actionWithId = + action.copy( + id = actionId, + facade = facade, + ) return missionActionsRepository.save(actionWithId) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeManualPriorNotification.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeManualPriorNotification.kt index ffe143961b..a8dfa2a208 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeManualPriorNotification.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeManualPriorNotification.kt @@ -16,7 +16,6 @@ class ComputeManualPriorNotification( private val pnoSegmentSubscriptionRepository: PnoSegmentSubscriptionRepository, private val pnoVesselSubscriptionRepository: PnoVesselSubscriptionRepository, private val vesselRepository: VesselRepository, - private val computeFleetSegments: ComputeFleetSegments, private val computePnoTypes: ComputePnoTypes, private val computeRiskFactor: ComputeRiskFactor, @@ -32,8 +31,9 @@ class ComputeManualPriorNotification( val vessel = vesselRepository.findVesselById(vesselId) val faoAreas = globalFaoArea?.let { listOf(globalFaoArea) } ?: fishingCatches.mapNotNull { it.faoZone } - val fishingCatchesWithFaoArea = globalFaoArea?.let { fishingCatches.map { it.copy(faoZone = globalFaoArea) } } - ?: fishingCatches + val fishingCatchesWithFaoArea = + globalFaoArea?.let { fishingCatches.map { it.copy(faoZone = globalFaoArea) } } + ?: fishingCatches val specyCodes = fishingCatches.mapNotNull { it.species } val vesselCfr = vessel?.internalReferenceNumber val vesselFlagCountryCode = vessel?.flagState @@ -42,11 +42,13 @@ class ComputeManualPriorNotification( val types = computePnoTypes.execute(fishingCatchesWithFaoArea, tripGearCodes, vesselFlagCountryCode) val vesselRiskFactor = computeRiskFactor.execute(portLocode, tripSegments, vesselCfr) - val isInVerificationScope = ManualPriorNotificationComputedValues - .isInVerificationScope(vesselFlagCountryCode, vesselRiskFactor) - val isPartOfControlUnitSubscriptions = pnoPortSubscriptionRepository.has(portLocode) || - pnoVesselSubscriptionRepository.has(vesselId) || - pnoSegmentSubscriptionRepository.has(portLocode, tripSegments.map { it.segment }) + val isInVerificationScope = + ManualPriorNotificationComputedValues + .isInVerificationScope(vesselFlagCountryCode, vesselRiskFactor) + val isPartOfControlUnitSubscriptions = + pnoPortSubscriptionRepository.has(portLocode) || + pnoVesselSubscriptionRepository.has(vesselId) || + pnoSegmentSubscriptionRepository.has(portLocode, tripSegments.map { it.segment }) val nextState = PriorNotification.getNextState(isInVerificationScope, isPartOfControlUnitSubscriptions) return ManualPriorNotificationComputedValues( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputePnoTypes.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputePnoTypes.kt index 768ac0c7cc..a0b2ab0be4 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputePnoTypes.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputePnoTypes.kt @@ -27,57 +27,70 @@ class ComputePnoTypes( val allPnoTypes = pnoTypeRepository.findAll() val allPnoTypeRules = allPnoTypes.map { pnoType -> pnoType.pnoTypeRules.map { it to pnoType } }.flatten() - val catchToPnoTypeRules = catchToLand.map { pnoCatch -> - val pnoTypeRules = allPnoTypeRules - .map { it.first } - .filter { rule -> ruleAppliesToCatch(rule, pnoCatch, pnoGears = gearCodes) } - - return@map pnoCatch to pnoTypeRules - } - - val filteredPnoTypeRules = allPnoTypeRules.filter { (rule) -> - val allCatchesOfRule = catchToPnoTypeRules - .filter { (_, pnoTypeRules) -> pnoTypeRules.any { pnoTypeRuleOfCatch -> pnoTypeRuleOfCatch.id == rule.id } } - .map { (pnoCatch, _) -> pnoCatch } - - val hasEmptyGears = rule.gears.isEmpty() - val hasEmptyFlagStates = rule.flagStates.isEmpty() - val hasEmptyRequiredCatches = rule.species.isEmpty() && rule.faoAreas.isEmpty() && rule.cgpmAreas.isEmpty() - - val numberOfEmptyRules = listOf(hasEmptyGears, hasEmptyFlagStates, hasEmptyRequiredCatches).count { it } - - val containsGear = rule.gears.any { gearCodes.contains(it) } - val containsFlagState = rule.flagStates.contains(flagState) - - val totalCatchesWeight = allCatchesOfRule.mapNotNull { it.weight }.sum() - val hasCatchesAndMinimumQuantity = - allCatchesOfRule.isNotEmpty() && totalCatchesWeight >= rule.minimumQuantityKg - - return@filter when (numberOfEmptyRules) { - 0 -> containsGear && containsFlagState && hasCatchesAndMinimumQuantity - - 1 -> when { - !hasEmptyGears && !hasEmptyFlagStates -> containsGear && containsFlagState - !hasEmptyGears && !hasEmptyRequiredCatches -> containsGear && hasCatchesAndMinimumQuantity - !hasEmptyFlagStates && !hasEmptyRequiredCatches -> containsFlagState && hasCatchesAndMinimumQuantity - else -> false - } + val catchToPnoTypeRules = + catchToLand.map { pnoCatch -> + val pnoTypeRules = + allPnoTypeRules + .map { it.first } + .filter { rule -> ruleAppliesToCatch(rule, pnoCatch, pnoGears = gearCodes) } + + return@map pnoCatch to pnoTypeRules + } - 2 -> when { - hasEmptyGears && hasEmptyFlagStates -> hasCatchesAndMinimumQuantity - hasEmptyGears && hasEmptyRequiredCatches -> containsFlagState - hasEmptyFlagStates && hasEmptyRequiredCatches -> containsGear - else -> false + val filteredPnoTypeRules = + allPnoTypeRules.filter { (rule) -> + val allCatchesOfRule = + catchToPnoTypeRules + .filter { + (_, pnoTypeRules) -> + pnoTypeRules.any { pnoTypeRuleOfCatch -> pnoTypeRuleOfCatch.id == rule.id } + } + .map { (pnoCatch, _) -> pnoCatch } + + val hasEmptyGears = rule.gears.isEmpty() + val hasEmptyFlagStates = rule.flagStates.isEmpty() + val hasEmptyRequiredCatches = rule.species.isEmpty() && rule.faoAreas.isEmpty() && rule.cgpmAreas.isEmpty() + + val numberOfEmptyRules = listOf(hasEmptyGears, hasEmptyFlagStates, hasEmptyRequiredCatches).count { it } + + val containsGear = rule.gears.any { gearCodes.contains(it) } + val containsFlagState = rule.flagStates.contains(flagState) + + val totalCatchesWeight = allCatchesOfRule.mapNotNull { it.weight }.sum() + val hasCatchesAndMinimumQuantity = + allCatchesOfRule.isNotEmpty() && totalCatchesWeight >= rule.minimumQuantityKg + + return@filter when (numberOfEmptyRules) { + 0 -> containsGear && containsFlagState && hasCatchesAndMinimumQuantity + + 1 -> + when { + !hasEmptyGears && !hasEmptyFlagStates -> containsGear && containsFlagState + !hasEmptyGears && !hasEmptyRequiredCatches -> containsGear && hasCatchesAndMinimumQuantity + !hasEmptyFlagStates && !hasEmptyRequiredCatches -> containsFlagState && hasCatchesAndMinimumQuantity + else -> false + } + + 2 -> + when { + hasEmptyGears && hasEmptyFlagStates -> hasCatchesAndMinimumQuantity + hasEmptyGears && hasEmptyRequiredCatches -> containsFlagState + hasEmptyFlagStates && hasEmptyRequiredCatches -> containsGear + else -> false + } + + else -> true } - - else -> true } - } return filteredPnoTypeRules.map { (_, type) -> type }.distinctBy { it.id } } - fun ruleAppliesToCatch(rule: PnoTypeRule, pnoCatch: LogbookFishingCatch, pnoGears: List): Boolean { + fun ruleAppliesToCatch( + rule: PnoTypeRule, + pnoCatch: LogbookFishingCatch, + pnoGears: List, + ): Boolean { val containsSpecies = rule.species.isEmpty() || rule.species.contains(pnoCatch.species) val containsGear = rule.gears.isEmpty() || rule.gears.any { pnoGears.contains(it) } val containsFaoAreas = rule.faoAreas.isEmpty() || rule.faoAreas.any { pnoCatch.faoZone?.startsWith(it) == true } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeRiskFactor.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeRiskFactor.kt index dc4aa5556f..6dac6b4a33 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeRiskFactor.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeRiskFactor.kt @@ -37,19 +37,21 @@ class ComputeRiskFactor( fleetSegments.maxByOrNull { it.impactRiskFactor }?.impactRiskFactor ?: defaultImpactRiskFactor val probabilityRiskFactor = storedRiskFactor?.probabilityRiskFactor ?: defaultProbabilityRiskFactor val controlRateRiskFactor = storedRiskFactor?.controlRateRiskFactor ?: defaultControlRateRiskFactor - val highestControlPriorityLevel = controlObjectivesRepository.findAllByYear(currentYear) - .filter { controlObjective -> - !facade.isNullOrEmpty() && - controlObjective.facade == facade && - fleetSegments.map { it.segment }.contains(controlObjective.segment) - } - .maxByOrNull { it.controlPriorityLevel } - ?.controlPriorityLevel ?: defaultControlPriorityLevel + val highestControlPriorityLevel = + controlObjectivesRepository.findAllByYear(currentYear) + .filter { controlObjective -> + !facade.isNullOrEmpty() && + controlObjective.facade == facade && + fleetSegments.map { it.segment }.contains(controlObjective.segment) + } + .maxByOrNull { it.controlPriorityLevel } + ?.controlPriorityLevel ?: defaultControlPriorityLevel - val computedRiskFactor = highestImpactRiskFactor.pow(impactRiskFactorCoefficient) * - probabilityRiskFactor.pow(probabilityRiskFactorCoefficient) * - controlRateRiskFactor.pow(controlRateRiskFactorCoefficient) * - highestControlPriorityLevel.pow(controlPriorityLevelCoefficient) + val computedRiskFactor = + highestImpactRiskFactor.pow(impactRiskFactorCoefficient) * + probabilityRiskFactor.pow(probabilityRiskFactorCoefficient) * + controlRateRiskFactor.pow(controlRateRiskFactorCoefficient) * + highestControlPriorityLevel.pow(controlPriorityLevelCoefficient) return computedRiskFactor } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotification.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotification.kt index e218ca175f..3ed84c0f06 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotification.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotification.kt @@ -22,7 +22,6 @@ class CreateOrUpdateManualPriorNotification( private val portRepository: PortRepository, private val priorNotificationPdfDocumentRepository: PriorNotificationPdfDocumentRepository, private val vesselRepository: VesselRepository, - private val computeManualPriorNotification: ComputeManualPriorNotification, private val getPriorNotification: GetPriorNotification, ) { @@ -30,7 +29,6 @@ class CreateOrUpdateManualPriorNotification( fun execute( reportId: String?, - authorTrigram: String, didNotFishAfterZeroNotice: Boolean, expectedArrivalDate: ZonedDateTime, @@ -53,90 +51,95 @@ class CreateOrUpdateManualPriorNotification( ): PriorNotification { // /!\ Backend computed vessel risk factor is only used as a real time Frontend indicator. // The Backend should NEVER update `risk_factors` DB table, only the pipeline is allowed to update it. - val computedValues = computeManualPriorNotification.execute( - fishingCatches, - globalFaoArea, - portLocode, - tripGearCodes, - vesselId, - ) - - val isPartOfControlUnitSubscriptions = pnoPortSubscriptionRepository.has(portLocode) || - pnoVesselSubscriptionRepository.has(vesselId) || - pnoSegmentSubscriptionRepository.has(portLocode, computedValues.tripSegments.map { it.segment }) - - val fishingCatchesWithFaoArea = globalFaoArea?.let { fishingCatches.map { it.copy(faoZone = globalFaoArea) } } - ?: fishingCatches + val computedValues = + computeManualPriorNotification.execute( + fishingCatches, + globalFaoArea, + portLocode, + tripGearCodes, + vesselId, + ) + + val isPartOfControlUnitSubscriptions = + pnoPortSubscriptionRepository.has(portLocode) || + pnoVesselSubscriptionRepository.has(vesselId) || + pnoSegmentSubscriptionRepository.has(portLocode, computedValues.tripSegments.map { it.segment }) + + val fishingCatchesWithFaoArea = + globalFaoArea?.let { fishingCatches.map { it.copy(faoZone = globalFaoArea) } } + ?: fishingCatches val tripGears = getTripGears(tripGearCodes) val tripSegments = computedValues.tripSegments.map { it.toLogbookTripSegment() } val vessel = vesselRepository.findVesselById(vesselId) val priorNotificationTypes = computedValues.types.map { it.toPriorNotificationType() } - val message = getMessage( - authorTrigram = authorTrigram, - expectedArrivalDate = expectedArrivalDate, - expectedLandingDate = expectedLandingDate, - // At the moment, manual prior notifications only have a single global FAO area field in Frontend, - // so we transform that single FAO area into an FAO area per fishing catch. - fishingCatches = fishingCatchesWithFaoArea, - hasPortEntranceAuthorization = hasPortEntranceAuthorization, - hasPortLandingAuthorization = hasPortLandingAuthorization, - note = note, - pnoTypes = priorNotificationTypes, - portLocode = portLocode, - purpose = purpose, - computedVesselFlagCountryCode = vessel?.flagState, - computedVesselRiskFactor = computedValues.vesselRiskFactor, - isPartOfControlUnitSubscriptions = isPartOfControlUnitSubscriptions, - ) - - val pnoLogbookMessage = LogbookMessage( - id = null, - reportId = reportId, - operationNumber = null, - tripNumber = null, - referencedReportId = null, - operationDateTime = ZonedDateTime.now(), - internalReferenceNumber = vessel?.internalReferenceNumber, - externalReferenceNumber = vessel?.externalReferenceNumber, - ircs = vessel?.ircs, - vesselName = vessel?.vesselName, - vesselId = vesselId, - flagState = vessel?.flagState?.alpha3, - imo = vessel?.imo, - reportDateTime = sentAt, - integrationDateTime = ZonedDateTime.now(), - rawMessage = null, - transmissionFormat = null, - software = null, - acknowledgment = null, - isCorrectedByNewerMessage = false, - isDeleted = false, - isEnriched = true, - isSentByFailoverSoftware = false, - message = message, - messageType = LogbookMessageTypeMapping.PNO.name, - operationType = LogbookOperationType.DAT, - tripGears = tripGears, - tripSegments = tripSegments, - ) + val message = + getMessage( + authorTrigram = authorTrigram, + expectedArrivalDate = expectedArrivalDate, + expectedLandingDate = expectedLandingDate, + // At the moment, manual prior notifications only have a single global FAO area field in Frontend, + // so we transform that single FAO area into an FAO area per fishing catch. + fishingCatches = fishingCatchesWithFaoArea, + hasPortEntranceAuthorization = hasPortEntranceAuthorization, + hasPortLandingAuthorization = hasPortLandingAuthorization, + note = note, + pnoTypes = priorNotificationTypes, + portLocode = portLocode, + purpose = purpose, + computedVesselFlagCountryCode = vessel?.flagState, + computedVesselRiskFactor = computedValues.vesselRiskFactor, + isPartOfControlUnitSubscriptions = isPartOfControlUnitSubscriptions, + ) + + val pnoLogbookMessage = + LogbookMessage( + id = null, + reportId = reportId, + operationNumber = null, + tripNumber = null, + referencedReportId = null, + operationDateTime = ZonedDateTime.now(), + internalReferenceNumber = vessel?.internalReferenceNumber, + externalReferenceNumber = vessel?.externalReferenceNumber, + ircs = vessel?.ircs, + vesselName = vessel?.vesselName, + vesselId = vesselId, + flagState = vessel?.flagState?.alpha3, + imo = vessel?.imo, + reportDateTime = sentAt, + integrationDateTime = ZonedDateTime.now(), + rawMessage = null, + transmissionFormat = null, + software = null, + acknowledgment = null, + isCorrectedByNewerMessage = false, + isDeleted = false, + isEnriched = true, + isSentByFailoverSoftware = false, + message = message, + messageType = LogbookMessageTypeMapping.PNO.name, + operationType = LogbookOperationType.DAT, + tripGears = tripGears, + tripSegments = tripSegments, + ) val logbookMessageAndValue = LogbookMessageAndValue(pnoLogbookMessage, PNO::class.java) - val newOrNextPriorNotification = PriorNotification( - reportId = reportId, - didNotFishAfterZeroNotice = didNotFishAfterZeroNotice, - isManuallyCreated = true, - logbookMessageAndValue = logbookMessageAndValue, - sentAt = sentAt, - - // All these props are useless for the save operation. - createdAt = null, - port = null, - reportingCount = null, - seafront = null, - vessel = null, - lastControlDateTime = null, - updatedAt = null, - ) + val newOrNextPriorNotification = + PriorNotification( + reportId = reportId, + didNotFishAfterZeroNotice = didNotFishAfterZeroNotice, + isManuallyCreated = true, + logbookMessageAndValue = logbookMessageAndValue, + sentAt = sentAt, + // All these props are useless for the save operation. + createdAt = null, + port = null, + reportingCount = null, + seafront = null, + vessel = null, + lastControlDateTime = null, + updatedAt = null, + ) // Any update must trigger a new PDF generation, so we delete the existing PDF document // which is re-generated by the Pipeline each time a PDF is deleted @@ -150,11 +153,12 @@ class CreateOrUpdateManualPriorNotification( val createdOrUpdatedIncompletePriorNotification = manualPriorNotificationRepository.save(newOrNextPriorNotification) - val createdOrUpdatedPriorNotification = getPriorNotification.execute( - createdOrUpdatedIncompletePriorNotification.reportId!!, - createdOrUpdatedIncompletePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, - true, - ) + val createdOrUpdatedPriorNotification = + getPriorNotification.execute( + createdOrUpdatedIncompletePriorNotification.reportId!!, + createdOrUpdatedIncompletePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, + true, + ) return createdOrUpdatedPriorNotification } @@ -176,8 +180,9 @@ class CreateOrUpdateManualPriorNotification( ): PNO { val allPorts = portRepository.findAll() - val isInVerificationScope = ManualPriorNotificationComputedValues - .isInVerificationScope(computedVesselFlagCountryCode, computedVesselRiskFactor) + val isInVerificationScope = + ManualPriorNotificationComputedValues + .isInVerificationScope(computedVesselFlagCountryCode, computedVesselRiskFactor) // If the prior notification is not in verification scope, // we pass `isBeingSent` as `true` in order to ask the workflow to send it. val isBeingSent = !isInVerificationScope && isPartOfControlUnitSubscriptions diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetNumberToVerify.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetNumberToVerify.kt index 5e01d2ac04..eb7ae42d54 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetNumberToVerify.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetNumberToVerify.kt @@ -23,22 +23,25 @@ class GetNumberToVerify( val manualPriorNotifications = manualPriorNotificationRepository.findAllToVerify() val incompletePriorNotifications = automaticPriorNotifications + manualPriorNotifications - val undeletedPriorNotifications = incompletePriorNotifications - .filter { !it.logbookMessageAndValue.logbookMessage.isDeleted } + val undeletedPriorNotifications = + incompletePriorNotifications + .filter { !it.logbookMessageAndValue.logbookMessage.isDeleted } - val priorNotifications = undeletedPriorNotifications - .map { priorNotification -> - priorNotification.enrich(allRiskFactors, allPorts, priorNotification.isManuallyCreated) + val priorNotifications = + undeletedPriorNotifications + .map { priorNotification -> + priorNotification.enrich(allRiskFactors, allPorts, priorNotification.isManuallyCreated) - priorNotification - } + priorNotification + } return PriorNotificationStats( - perSeafrontGroupCount = SeafrontGroup.entries.associateWith { seafrontGroupEntry -> - priorNotifications.count { priorNotification -> - seafrontGroupEntry.hasSeafront(priorNotification.seafront) - } - }, + perSeafrontGroupCount = + SeafrontGroup.entries.associateWith { seafrontGroupEntry -> + priorNotifications.count { priorNotification -> + seafrontGroupEntry.hasSeafront(priorNotification.seafront) + } + }, ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotification.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotification.kt index 1577a276e7..5c57439071 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotification.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotification.kt @@ -20,18 +20,23 @@ class GetPriorNotification( private val speciesRepository: SpeciesRepository, private val vesselRepository: VesselRepository, ) { - fun execute(reportId: String, operationDate: ZonedDateTime, isManuallyCreated: Boolean): PriorNotification { + fun execute( + reportId: String, + operationDate: ZonedDateTime, + isManuallyCreated: Boolean, + ): PriorNotification { val allGears = gearRepository.findAll() val allPorts = portRepository.findAll() val allRiskFactors = riskFactorRepository.findAll() val allSpecies = speciesRepository.findAll() - val priorNotification = if (isManuallyCreated) { - manualPriorNotificationRepository.findByReportId(reportId) - } else { - logbookReportRepository.findAcknowledgedPriorNotificationByReportId(reportId, operationDate) - } - ?: throw BackendUsageException(BackendUsageErrorCode.NOT_FOUND) + val priorNotification = + if (isManuallyCreated) { + manualPriorNotificationRepository.findByReportId(reportId) + } else { + logbookReportRepository.findAcknowledgedPriorNotificationByReportId(reportId, operationDate) + } + ?: throw BackendUsageException(BackendUsageErrorCode.NOT_FOUND) priorNotification.enrich(allRiskFactors, allPorts, isManuallyCreated) priorNotification.enrichLogbookMessage( @@ -46,24 +51,25 @@ class GetPriorNotification( return priorNotificationWithVessel } - private fun getPriorNotificationWithVessel( - priorNotification: PriorNotification, - ): PriorNotification { - val vessel = when (priorNotification.isManuallyCreated) { - true -> if (priorNotification.logbookMessageAndValue.logbookMessage.vesselId != null) { - vesselRepository.findVesselById(priorNotification.logbookMessageAndValue.logbookMessage.vesselId!!) - } else { - null - } + private fun getPriorNotificationWithVessel(priorNotification: PriorNotification): PriorNotification { + val vessel = + when (priorNotification.isManuallyCreated) { + true -> + if (priorNotification.logbookMessageAndValue.logbookMessage.vesselId != null) { + vesselRepository.findVesselById(priorNotification.logbookMessageAndValue.logbookMessage.vesselId!!) + } else { + null + } - false -> if (priorNotification.logbookMessageAndValue.logbookMessage.internalReferenceNumber != null) { - vesselRepository.findFirstByInternalReferenceNumber( - priorNotification.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } else { - null - } - } ?: UNKNOWN_VESSEL + false -> + if (priorNotification.logbookMessageAndValue.logbookMessage.internalReferenceNumber != null) { + vesselRepository.findFirstByInternalReferenceNumber( + priorNotification.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } else { + null + } + } ?: UNKNOWN_VESSEL return priorNotification.copy(vessel = vessel) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationPdfDocument.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationPdfDocument.kt index e8c0850037..54d4bd1c41 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationPdfDocument.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationPdfDocument.kt @@ -9,7 +9,10 @@ import fr.gouv.cnsp.monitorfish.domain.repositories.PriorNotificationPdfDocument class GetPriorNotificationPdfDocument( private val priorNotificationPdfDocumentRepository: PriorNotificationPdfDocumentRepository, ) { - fun execute(reportId: String, isVerifyingExistence: Boolean): PdfDocument? { + fun execute( + reportId: String, + isVerifyingExistence: Boolean, + ): PdfDocument? { return try { priorNotificationPdfDocumentRepository.findByReportId(reportId) } catch (e: BackendUsageException) { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt index 83a0d0d346..2a4f304fae 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt @@ -42,114 +42,126 @@ class GetPriorNotifications( val allRiskFactors = riskFactorRepository.findAll() val allSpecies = speciesRepository.findAll() - val (automaticPriorNotifications, findAllPriorNotificationsTimeTaken) = measureTimedValue { - logbookReportRepository.findAllAcknowledgedPriorNotifications(filter) - } + val (automaticPriorNotifications, findAllPriorNotificationsTimeTaken) = + measureTimedValue { + logbookReportRepository.findAllAcknowledgedPriorNotifications(filter) + } logger.info( "TIME_RECORD - 'logbookReportRepository.findAllPriorNotifications()' took $findAllPriorNotificationsTimeTaken.", ) - val (manualPriorNotifications, manualPriorNotificationRepositoryFindAllTimeTaken) = measureTimedValue { - manualPriorNotificationRepository.findAll(filter) - } + val (manualPriorNotifications, manualPriorNotificationRepositoryFindAllTimeTaken) = + measureTimedValue { + manualPriorNotificationRepository.findAll(filter) + } logger.info( "TIME_RECORD - 'manualPriorNotificationRepository.findAll()' took $manualPriorNotificationRepositoryFindAllTimeTaken.", ) val incompletePriorNotifications = automaticPriorNotifications + manualPriorNotifications - val (priorNotifications, enrichedPriorNotificationsTimeTaken) = measureTimedValue { - incompletePriorNotifications - .map { priorNotification -> - priorNotification.enrich(allRiskFactors, allPorts, priorNotification.isManuallyCreated) - priorNotification.logbookMessageAndValue.logbookMessage - .enrichGearPortAndSpecyNames(allGears, allPorts, allSpecies) + val (priorNotifications, enrichedPriorNotificationsTimeTaken) = + measureTimedValue { + incompletePriorNotifications + .map { priorNotification -> + priorNotification.enrich(allRiskFactors, allPorts, priorNotification.isManuallyCreated) + priorNotification.logbookMessageAndValue.logbookMessage + .enrichGearPortAndSpecyNames(allGears, allPorts, allSpecies) - priorNotification - } - } + priorNotification + } + } logger.info("TIME_RECORD - 'priorNotifications' took $enrichedPriorNotificationsTimeTaken.") - val (sortedAndFilteredPriorNotifications, sortedAndFilteredPriorNotificationsTimeTaken) = measureTimedValue { - when (sortDirection) { - Sort.Direction.ASC -> priorNotifications.sortedWith( - compareBy( - { getSortKey(it, sortColumn) }, - { it.logbookMessageAndValue.logbookMessage.id }, // Tie-breaker - ), - ) - - Sort.Direction.DESC -> priorNotifications.sortedWith( - // Only solution found to fix typing issues - compareByDescending { getSortKey(it, sortColumn) } - .thenByDescending { it.logbookMessageAndValue.logbookMessage.id }, // Tie-breaker - ) - }.filter { seafrontGroup.hasSeafront(it.seafront) && (states.isNullOrEmpty() || states.contains(it.state)) } - } + val (sortedAndFilteredPriorNotifications, sortedAndFilteredPriorNotificationsTimeTaken) = + measureTimedValue { + when (sortDirection) { + Sort.Direction.ASC -> + priorNotifications.sortedWith( + compareBy( + { getSortKey(it, sortColumn) }, + { it.logbookMessageAndValue.logbookMessage.id }, // Tie-breaker + ), + ) + + Sort.Direction.DESC -> + priorNotifications.sortedWith( + // Only solution found to fix typing issues + compareByDescending { getSortKey(it, sortColumn) } + .thenByDescending { it.logbookMessageAndValue.logbookMessage.id }, // Tie-breaker + ) + }.filter { seafrontGroup.hasSeafront(it.seafront) && (states.isNullOrEmpty() || states.contains(it.state)) } + } logger.info( "TIME_RECORD - 'sortedAndFilteredPriorNotifications' took $sortedAndFilteredPriorNotificationsTimeTaken.", ) - val (extraData, extraDataTimeTaken) = measureTimedValue { - PriorNotificationStats( - perSeafrontGroupCount = SeafrontGroup.entries.associateWith { seafrontGroupEntry -> - priorNotifications.count { priorNotification -> - seafrontGroupEntry.hasSeafront(priorNotification.seafront) - } - }, - ) - } + val (extraData, extraDataTimeTaken) = + measureTimedValue { + PriorNotificationStats( + perSeafrontGroupCount = + SeafrontGroup.entries.associateWith { seafrontGroupEntry -> + priorNotifications.count { priorNotification -> + seafrontGroupEntry.hasSeafront(priorNotification.seafront) + } + }, + ) + } logger.info("TIME_RECORD - 'extraData' took $extraDataTimeTaken.") - val (paginatedList, paginatedListTimeTaken) = measureTimedValue { - PaginatedList.new( - sortedAndFilteredPriorNotifications, - pageNumber, - pageSize, - extraData, - ) - } + val (paginatedList, paginatedListTimeTaken) = + measureTimedValue { + PaginatedList.new( + sortedAndFilteredPriorNotifications, + pageNumber, + pageSize, + extraData, + ) + } logger.info("TIME_RECORD - 'paginatedList' took $paginatedListTimeTaken.") val paginatedListWithVessels = paginatedList.copy(data = getPriorNotificationsWithVessel(paginatedList.data)) // Enrich the reporting count for each prior notification after pagination to limit the number of queries - val (enrichedPaginatedList, enrichedPaginatedListTimeTaken) = measureTimedValue { - paginatedListWithVessels.apply { - data.forEach { - it.enrichReportingCount(reportingRepository) + val (enrichedPaginatedList, enrichedPaginatedListTimeTaken) = + measureTimedValue { + paginatedListWithVessels.apply { + data.forEach { + it.enrichReportingCount(reportingRepository) + } } } - } logger.info("TIME_RECORD - 'enrichedPaginatedList' took $enrichedPaginatedListTimeTaken.") return enrichedPaginatedList } - private fun getPriorNotificationsWithVessel( - priorNotifications: List, - ): List { - val vesselsIds = priorNotifications - .filter { it.isManuallyCreated } - .mapNotNull { it.logbookMessageAndValue.logbookMessage.vesselId } - val internalReferenceNumbers = priorNotifications - .filter { !it.isManuallyCreated } - .mapNotNull { it.logbookMessageAndValue.logbookMessage.internalReferenceNumber } - val vessels = vesselRepository.findVesselsByIds(vesselsIds) + - vesselRepository.findVesselsByInternalReferenceNumbers(internalReferenceNumbers) + private fun getPriorNotificationsWithVessel(priorNotifications: List): List { + val vesselsIds = + priorNotifications + .filter { it.isManuallyCreated } + .mapNotNull { it.logbookMessageAndValue.logbookMessage.vesselId } + val internalReferenceNumbers = + priorNotifications + .filter { !it.isManuallyCreated } + .mapNotNull { it.logbookMessageAndValue.logbookMessage.internalReferenceNumber } + val vessels = + vesselRepository.findVesselsByIds(vesselsIds) + + vesselRepository.findVesselsByInternalReferenceNumbers(internalReferenceNumbers) return priorNotifications.map { val isManuallyCreated = it.isManuallyCreated val vesselId = it.logbookMessageAndValue.logbookMessage.vesselId val internalReferenceNumber = it.logbookMessageAndValue.logbookMessage.internalReferenceNumber - val vessel = vessels.find { searchedVessel -> - return@find if (isManuallyCreated) { - searchedVessel.id == vesselId - } else { - searchedVessel.internalReferenceNumber == internalReferenceNumber - } - } ?: UNKNOWN_VESSEL + val vessel = + vessels.find { searchedVessel -> + return@find if (isManuallyCreated) { + searchedVessel.id == vesselId + } else { + searchedVessel.internalReferenceNumber == internalReferenceNumber + } + } ?: UNKNOWN_VESSEL return@map it.copy(vessel = vessel) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/InvalidatePriorNotification.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/InvalidatePriorNotification.kt index b96c6586dc..ae14b50d78 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/InvalidatePriorNotification.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/InvalidatePriorNotification.kt @@ -12,7 +12,11 @@ class InvalidatePriorNotification( private val manualPriorNotificationRepository: ManualPriorNotificationRepository, private val getPriorNotification: GetPriorNotification, ) { - fun execute(reportId: String, operationDate: ZonedDateTime, isManuallyCreated: Boolean): PriorNotification { + fun execute( + reportId: String, + operationDate: ZonedDateTime, + isManuallyCreated: Boolean, + ): PriorNotification { if (isManuallyCreated) { manualPriorNotificationRepository.invalidate(reportId) } else { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotification.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotification.kt index 3a3d896bdc..e100823bc1 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotification.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotification.kt @@ -12,7 +12,11 @@ class VerifyAndSendPriorNotification( private val manualPriorNotificationRepository: ManualPriorNotificationRepository, private val getPriorNotification: GetPriorNotification, ) { - fun execute(reportId: String, operationDate: ZonedDateTime, isManuallyCreated: Boolean): PriorNotification { + fun execute( + reportId: String, + operationDate: ZonedDateTime, + isManuallyCreated: Boolean, + ): PriorNotification { if (isManuallyCreated) { manualPriorNotificationRepository .updateState(reportId, isBeingSent = true, isSent = false, isVerified = true) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/AddReporting.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/AddReporting.kt index 2aab5054ce..0c3a84d12a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/AddReporting.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/AddReporting.kt @@ -33,16 +33,18 @@ class AddReporting( newReporting.value as InfractionSuspicionOrObservationType newReporting.value.checkReportingActorAndFieldsRequirements() - val nextReporting = if (newReporting.type === ReportingType.INFRACTION_SUSPICION) { - newReporting.value as InfractionSuspicion - val nextInfractionSuspicion = getInfractionSuspicionWithDMLAndSeaFront.execute( - newReporting.value, - newReporting.vesselId, - ) - newReporting.copy(value = nextInfractionSuspicion) - } else { - newReporting - } + val nextReporting = + if (newReporting.type === ReportingType.INFRACTION_SUSPICION) { + newReporting.value as InfractionSuspicion + val nextInfractionSuspicion = + getInfractionSuspicionWithDMLAndSeaFront.execute( + newReporting.value, + newReporting.vesselId, + ) + newReporting.copy(value = nextInfractionSuspicion) + } else { + newReporting + } val savedReporting = reportingRepository.save(nextReporting) val controlUnitId = (savedReporting.value as InfractionSuspicionOrObservationType).controlUnitId diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/GetAllCurrentReportings.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/GetAllCurrentReportings.kt index b78ee57a4f..83b43b6a53 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/GetAllCurrentReportings.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/GetAllCurrentReportings.kt @@ -32,49 +32,51 @@ class GetAllCurrentReportings( val currentReportings = reportingRepository.findAll(filter) val controlUnits = getAllControlUnits.execute() - val currentReportingsWithCharterInfo = currentReportings.map { reporting -> - val underCharter = try { - when (reporting.vesselIdentifier) { - VesselIdentifier.INTERNAL_REFERENCE_NUMBER -> { - requireNotNull(reporting.internalReferenceNumber) { - "The fields 'internalReferenceNumber' must be not null when the vessel identifier is INTERNAL_REFERENCE_NUMBER." - } - vesselRepository.findUnderCharterForVessel( - reporting.vesselIdentifier, - reporting.internalReferenceNumber, - ) - } + val currentReportingsWithCharterInfo = + currentReportings.map { reporting -> + val underCharter = + try { + when (reporting.vesselIdentifier) { + VesselIdentifier.INTERNAL_REFERENCE_NUMBER -> { + requireNotNull(reporting.internalReferenceNumber) { + "The fields 'internalReferenceNumber' must be not null when the vessel identifier is INTERNAL_REFERENCE_NUMBER." + } + vesselRepository.findUnderCharterForVessel( + reporting.vesselIdentifier, + reporting.internalReferenceNumber, + ) + } - VesselIdentifier.IRCS -> { - requireNotNull(reporting.ircs) { - "The fields 'ircs' must be not null when the vessel identifier is IRCS." - } - vesselRepository.findUnderCharterForVessel(reporting.vesselIdentifier, reporting.ircs) - } + VesselIdentifier.IRCS -> { + requireNotNull(reporting.ircs) { + "The fields 'ircs' must be not null when the vessel identifier is IRCS." + } + vesselRepository.findUnderCharterForVessel(reporting.vesselIdentifier, reporting.ircs) + } + + VesselIdentifier.EXTERNAL_REFERENCE_NUMBER -> { + requireNotNull(reporting.externalReferenceNumber) { + "The fields 'externalReferenceNumber' must be not null when the vessel identifier is EXTERNAL_REFERENCE_NUMBER." + } + vesselRepository.findUnderCharterForVessel( + reporting.vesselIdentifier, + reporting.externalReferenceNumber, + ) + } - VesselIdentifier.EXTERNAL_REFERENCE_NUMBER -> { - requireNotNull(reporting.externalReferenceNumber) { - "The fields 'externalReferenceNumber' must be not null when the vessel identifier is EXTERNAL_REFERENCE_NUMBER." + else -> null } - vesselRepository.findUnderCharterForVessel( - reporting.vesselIdentifier, - reporting.externalReferenceNumber, + } catch (e: Throwable) { + logger.debug( + "Last position not found for vessel \"${reporting.internalReferenceNumber}/${reporting.ircs}/${reporting.externalReferenceNumber}\" " + + "and vessel identifier \"${reporting.vesselIdentifier}\": ${e.message}", ) + null } - else -> null - } - } catch (e: Throwable) { - logger.debug( - "Last position not found for vessel \"${reporting.internalReferenceNumber}/${reporting.ircs}/${reporting.externalReferenceNumber}\" " + - "and vessel identifier \"${reporting.vesselIdentifier}\": ${e.message}", - ) - null + reporting.copy(underCharter = underCharter) } - reporting.copy(underCharter = underCharter) - } - return currentReportingsWithCharterInfo.map { reporting -> if (reporting.type == ReportingType.ALERT) { return@map Pair(reporting, null) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/UpdateReporting.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/UpdateReporting.kt index 4d416515bf..4e01be94da 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/UpdateReporting.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/UpdateReporting.kt @@ -16,7 +16,10 @@ class UpdateReporting( ) { private val logger: Logger = LoggerFactory.getLogger(UpdateReporting::class.java) - fun execute(reportingId: Int, updatedInfractionSuspicionOrObservation: UpdatedInfractionSuspicionOrObservation): Pair { + fun execute( + reportingId: Int, + updatedInfractionSuspicionOrObservation: UpdatedInfractionSuspicionOrObservation, + ): Pair { val currentReporting = reportingRepository.findById(reportingId) val controlUnits = getAllControlUnits.execute() logger.info("Updating reporting id $reportingId for vessel id ${currentReporting.vesselId}") @@ -29,9 +32,10 @@ class UpdateReporting( ReportingType.OBSERVATION -> { currentReporting.value as InfractionSuspicionOrObservationType - val nextObservation = Observation.fromUpdatedReporting( - updatedInfractionSuspicionOrObservation, - ) + val nextObservation = + Observation.fromUpdatedReporting( + updatedInfractionSuspicionOrObservation, + ) nextObservation.checkReportingActorAndFieldsRequirements() val updatedReporting = reportingRepository.update(reportingId, nextObservation) @@ -42,11 +46,12 @@ class UpdateReporting( ReportingType.INFRACTION_SUSPICION -> { currentReporting.value as InfractionSuspicionOrObservationType - val nextInfractionSuspicion = InfractionSuspicion.fromUpdatedReporting( - updatedInfractionSuspicionOrObservation, - ).let { - getInfractionSuspicionWithDMLAndSeaFront.execute(it, currentReporting.vesselId) - } + val nextInfractionSuspicion = + InfractionSuspicion.fromUpdatedReporting( + updatedInfractionSuspicionOrObservation, + ).let { + getInfractionSuspicionWithDMLAndSeaFront.execute(it, currentReporting.vesselId) + } nextInfractionSuspicion.checkReportingActorAndFieldsRequirements() val updatedReporting = reportingRepository.update(reportingId, nextInfractionSuspicion) @@ -60,7 +65,10 @@ class UpdateReporting( } } - fun getControlUnit(reporting: Reporting, controlUnits: List): ControlUnit? { + fun getControlUnit( + reporting: Reporting, + controlUnits: List, + ): ControlUnit? { val controlUnitId = (reporting.value as InfractionSuspicionOrObservationType).controlUnitId return controlUnits.find { it.id == controlUnitId } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetLogbookMessages.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetLogbookMessages.kt index 1f0b05dc60..31b6685431 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetLogbookMessages.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetLogbookMessages.kt @@ -28,26 +28,27 @@ class GetLogbookMessages( val allPorts = portRepository.findAll() val allSpecies = speciesRepository.findAll() - val messages = logbookReportRepository - .findAllMessagesByTripNumberBetweenDates( - internalReferenceNumber, - afterDepartureDate, - beforeDepartureDate, - tripNumber, - ) - .sortedBy { it.reportDateTime } - .map { logbookMessage -> - logbookMessage.operationNumber?.let { operationNumber -> - try { - val rawMessage = logbookRawMessageRepository.findRawMessage(operationNumber) - logbookMessage.rawMessage = rawMessage - } catch (e: NoERSMessagesFound) { - logger.warn(e.message) + val messages = + logbookReportRepository + .findAllMessagesByTripNumberBetweenDates( + internalReferenceNumber, + afterDepartureDate, + beforeDepartureDate, + tripNumber, + ) + .sortedBy { it.reportDateTime } + .map { logbookMessage -> + logbookMessage.operationNumber?.let { operationNumber -> + try { + val rawMessage = logbookRawMessageRepository.findRawMessage(operationNumber) + logbookMessage.rawMessage = rawMessage + } catch (e: NoERSMessagesFound) { + logger.warn(e.message) + } } - } - logbookMessage - } + logbookMessage + } messages.forEach { it.enrich(messages, allGears, allPorts, allSpecies) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVessel.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVessel.kt index 4edfd915f0..614d671ae9 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVessel.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVessel.kt @@ -60,11 +60,12 @@ class GetVessel( val vessel = vesselFuture.await() val beacon = vessel?.id?.let { vesselId -> beaconRepository.findBeaconByVesselId(vesselId) } - val logbookSoftware = vessel?.internalReferenceNumber?.let { - logbookReportRepository.findLastReportSoftware( - it, - ) - } + val logbookSoftware = + vessel?.internalReferenceNumber?.let { + logbookReportRepository.findLastReportSoftware( + it, + ) + } val hasVisioCaptures = logbookSoftware?.let { LogbookSoftware.isVisioCaptureInRealTime(logbookSoftware) } ?: false Pair( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselBeaconMalfunctions.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselBeaconMalfunctions.kt index 93bf857052..0df44e6f12 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselBeaconMalfunctions.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselBeaconMalfunctions.kt @@ -18,26 +18,30 @@ class GetVesselBeaconMalfunctions( private val beaconMalfunctionActionsRepository: BeaconMalfunctionActionsRepository, ) { private val logger = LoggerFactory.getLogger(GetVesselBeaconMalfunctions::class.java) + fun execute( vesselId: Int, afterDateTime: ZonedDateTime, ): VesselBeaconMalfunctionsResumeAndHistory { val beaconMalfunctions = beaconMalfunctionsRepository.findAllByVesselId(vesselId, afterDateTime) - val beaconMalfunctionsWithDetails = beaconMalfunctions.map { - val comments = beaconMalfunctionCommentsRepository.findAllByBeaconMalfunctionId(it.id) - val actions = beaconMalfunctionActionsRepository.findAllByBeaconMalfunctionId(it.id) + val beaconMalfunctionsWithDetails = + beaconMalfunctions.map { + val comments = beaconMalfunctionCommentsRepository.findAllByBeaconMalfunctionId(it.id) + val actions = beaconMalfunctionActionsRepository.findAllByBeaconMalfunctionId(it.id) - BeaconMalfunctionWithDetails(it, comments, actions) - } + BeaconMalfunctionWithDetails(it, comments, actions) + } val resume = VesselBeaconMalfunctionsResume.fromBeaconMalfunctions(beaconMalfunctionsWithDetails) - val currentBeaconMalfunction = beaconMalfunctionsWithDetails.find { - it.beaconMalfunction.stage != Stage.ARCHIVED - } - val history = beaconMalfunctionsWithDetails.filter { - it.beaconMalfunction.id != currentBeaconMalfunction?.beaconMalfunction?.id - } + val currentBeaconMalfunction = + beaconMalfunctionsWithDetails.find { + it.beaconMalfunction.stage != Stage.ARCHIVED + } + val history = + beaconMalfunctionsWithDetails.filter { + it.beaconMalfunction.id != currentBeaconMalfunction?.beaconMalfunction?.id + } return VesselBeaconMalfunctionsResumeAndHistory( resume = resume, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselPositions.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselPositions.kt index 6c23397edd..4e3069a3c0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselPositions.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselPositions.kt @@ -42,47 +42,50 @@ class GetVesselPositions( } } - val from = when (trackDepth) { - VesselTrackDepth.TWELVE_HOURS -> ZonedDateTime.now().minusHours(12) - VesselTrackDepth.LAST_DEPARTURE -> { - try { - // We subtract 4h to this date to ensure the track starts at the port - // (the departure message may be sent after the departure) - logbookReportRepository.findFirstAcknowledgedDateOfTripBeforeDateTime( - internalReferenceNumber, - ZonedDateTime.now(), - ) - .minusHours(4) - } catch (e: NoLogbookFishingTripFound) { - logger.warn(e.message) - isTrackDepthModified = true - ZonedDateTime.now().minusDays(1) + val from = + when (trackDepth) { + VesselTrackDepth.TWELVE_HOURS -> ZonedDateTime.now().minusHours(12) + VesselTrackDepth.LAST_DEPARTURE -> { + try { + // We subtract 4h to this date to ensure the track starts at the port + // (the departure message may be sent after the departure) + logbookReportRepository.findFirstAcknowledgedDateOfTripBeforeDateTime( + internalReferenceNumber, + ZonedDateTime.now(), + ) + .minusHours(4) + } catch (e: NoLogbookFishingTripFound) { + logger.warn(e.message) + isTrackDepthModified = true + ZonedDateTime.now().minusDays(1) + } } + VesselTrackDepth.ONE_DAY -> ZonedDateTime.now().minusDays(1) + VesselTrackDepth.TWO_DAYS -> ZonedDateTime.now().minusDays(2) + VesselTrackDepth.THREE_DAYS -> ZonedDateTime.now().minusDays(3) + VesselTrackDepth.ONE_WEEK -> ZonedDateTime.now().minusWeeks(1) + VesselTrackDepth.TWO_WEEK -> ZonedDateTime.now().minusWeeks(2) + VesselTrackDepth.THREE_WEEK -> ZonedDateTime.now().minusWeeks(3) + VesselTrackDepth.ONE_MONTH -> ZonedDateTime.now().minusMonths(1) + VesselTrackDepth.CUSTOM -> fromDateTime } - VesselTrackDepth.ONE_DAY -> ZonedDateTime.now().minusDays(1) - VesselTrackDepth.TWO_DAYS -> ZonedDateTime.now().minusDays(2) - VesselTrackDepth.THREE_DAYS -> ZonedDateTime.now().minusDays(3) - VesselTrackDepth.ONE_WEEK -> ZonedDateTime.now().minusWeeks(1) - VesselTrackDepth.TWO_WEEK -> ZonedDateTime.now().minusWeeks(2) - VesselTrackDepth.THREE_WEEK -> ZonedDateTime.now().minusWeeks(3) - VesselTrackDepth.ONE_MONTH -> ZonedDateTime.now().minusMonths(1) - VesselTrackDepth.CUSTOM -> fromDateTime - } - val to = when (trackDepth) { - VesselTrackDepth.CUSTOM -> toDateTime - else -> ZonedDateTime.now() - } + val to = + when (trackDepth) { + VesselTrackDepth.CUSTOM -> toDateTime + else -> ZonedDateTime.now() + } return coroutineScope { - val positionsFuture = findPositionsAsync( - vesselIdentifier, - internalReferenceNumber, - from, - to, - ircs, - externalReferenceNumber, - ) + val positionsFuture = + findPositionsAsync( + vesselIdentifier, + internalReferenceNumber, + from, + to, + ircs, + externalReferenceNumber, + ) Pair( isTrackDepthModified, @@ -100,35 +103,39 @@ class GetVesselPositions( externalReferenceNumber: String, ): Deferred> { return when (vesselIdentifier) { - VesselIdentifier.INTERNAL_REFERENCE_NUMBER -> async { - positionRepository.findVesselLastPositionsByInternalReferenceNumber( - internalReferenceNumber, - from!!, - to!!, - ) - .sortedBy { it.dateTime } - } - VesselIdentifier.IRCS -> async { - positionRepository.findVesselLastPositionsByIrcs(ircs, from!!, to!!) - .sortedBy { it.dateTime } - } - VesselIdentifier.EXTERNAL_REFERENCE_NUMBER -> async { - positionRepository.findVesselLastPositionsByExternalReferenceNumber( - externalReferenceNumber, - from!!, - to!!, - ) - .sortedBy { it.dateTime } - } - else -> async { - positionRepository.findVesselLastPositionsWithoutSpecifiedIdentifier( - internalReferenceNumber = internalReferenceNumber, - externalReferenceNumber = externalReferenceNumber, - ircs = ircs, - from = from!!, - to = to!!, - ).sortedBy { it.dateTime } - } + VesselIdentifier.INTERNAL_REFERENCE_NUMBER -> + async { + positionRepository.findVesselLastPositionsByInternalReferenceNumber( + internalReferenceNumber, + from!!, + to!!, + ) + .sortedBy { it.dateTime } + } + VesselIdentifier.IRCS -> + async { + positionRepository.findVesselLastPositionsByIrcs(ircs, from!!, to!!) + .sortedBy { it.dateTime } + } + VesselIdentifier.EXTERNAL_REFERENCE_NUMBER -> + async { + positionRepository.findVesselLastPositionsByExternalReferenceNumber( + externalReferenceNumber, + from!!, + to!!, + ) + .sortedBy { it.dateTime } + } + else -> + async { + positionRepository.findVesselLastPositionsWithoutSpecifiedIdentifier( + internalReferenceNumber = internalReferenceNumber, + externalReferenceNumber = externalReferenceNumber, + ircs = ircs, + from = from!!, + to = to!!, + ).sortedBy { it.dateTime } + } } } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselReportings.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselReportings.kt index ca97a6a50c..a856d8bc48 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselReportings.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselReportings.kt @@ -31,33 +31,37 @@ class GetVesselReportings( ): CurrentAndArchivedReportings { val controlUnits = getAllControlUnits.execute() - val reportings = findReportings( - vesselId, - vesselIdentifier, - internalReferenceNumber, - fromDate, - ircs, - externalReferenceNumber, - ) - - val current = getReportingsAndOccurrences(reportings.filter { !it.isArchived }) - .sortedWith(compareByDescending { it.reporting.validationDate ?: it.reporting.creationDate }) - .map { reportingAndOccurrences -> - enrichWithInfractionAndControlUnit(reportingAndOccurrences, controlUnits) - } - - val yearsRange = fromDate.year..ZonedDateTime.now().year - val archivedYearsToReportings = yearsRange.associateWith { year -> - val reportingsOfYear = reportings - .filter { it.isArchived } - .filter { filterByYear(it, year) } + val reportings = + findReportings( + vesselId, + vesselIdentifier, + internalReferenceNumber, + fromDate, + ircs, + externalReferenceNumber, + ) - getReportingsAndOccurrences(reportingsOfYear) + val current = + getReportingsAndOccurrences(reportings.filter { !it.isArchived }) .sortedWith(compareByDescending { it.reporting.validationDate ?: it.reporting.creationDate }) .map { reportingAndOccurrences -> enrichWithInfractionAndControlUnit(reportingAndOccurrences, controlUnits) } - } + + val yearsRange = fromDate.year..ZonedDateTime.now().year + val archivedYearsToReportings = + yearsRange.associateWith { year -> + val reportingsOfYear = + reportings + .filter { it.isArchived } + .filter { filterByYear(it, year) } + + getReportingsAndOccurrences(reportingsOfYear) + .sortedWith(compareByDescending { it.reporting.validationDate ?: it.reporting.creationDate }) + .map { reportingAndOccurrences -> + enrichWithInfractionAndControlUnit(reportingAndOccurrences, controlUnits) + } + } return CurrentAndArchivedReportings(current, archivedYearsToReportings) } @@ -77,21 +81,24 @@ class GetVesselReportings( reportingAndOccurrences: ReportingAndOccurrences, controlUnits: List, ): ReportingAndOccurrences { - val updatedInfraction = reportingAndOccurrences.reporting.value.natinfCode?.let { natinfCode -> - try { - infractionRepository.findInfractionByNatinfCode(natinfCode) - } catch (e: NatinfCodeNotFoundException) { - logger.warn(e.message) - null + val updatedInfraction = + reportingAndOccurrences.reporting.value.natinfCode?.let { natinfCode -> + try { + infractionRepository.findInfractionByNatinfCode(natinfCode) + } catch (e: NatinfCodeNotFoundException) { + logger.warn(e.message) + null + } } - } - val updatedReporting = reportingAndOccurrences.reporting.copy( - infraction = updatedInfraction ?: reportingAndOccurrences.reporting.infraction, - ) - val updatedReportingAndOccurrences = reportingAndOccurrences.copy( - reporting = updatedReporting, - ) + val updatedReporting = + reportingAndOccurrences.reporting.copy( + infraction = updatedInfraction ?: reportingAndOccurrences.reporting.infraction, + ) + val updatedReportingAndOccurrences = + reportingAndOccurrences.copy( + reporting = updatedReporting, + ) if (updatedReporting.type == ReportingType.ALERT) { return updatedReportingAndOccurrences @@ -104,45 +111,49 @@ class GetVesselReportings( } private fun getReportingsAndOccurrences(reportings: List): List { - val reportingsWithoutAlerts: List = reportings - .filter { it.type != ReportingType.ALERT } - .map { reporting -> - ReportingAndOccurrences( - otherOccurrencesOfSameAlert = emptyList(), - reporting = reporting, - controlUnit = null, - ) - } - - val alertTypeToAlertsOccurrences: Map> = reportings - .filter { it.type == ReportingType.ALERT } - .groupBy { (it.value as AlertType).type } - .withDefault { emptyList() } - - val alertTypeToLastAlertAndOccurrences: List = alertTypeToAlertsOccurrences - .flatMap { (_, alerts) -> - if (alerts.isEmpty()) { - return@flatMap listOf() + val reportingsWithoutAlerts: List = + reportings + .filter { it.type != ReportingType.ALERT } + .map { reporting -> + ReportingAndOccurrences( + otherOccurrencesOfSameAlert = emptyList(), + reporting = reporting, + controlUnit = null, + ) } - val lastAlert = alerts.maxByOrNull { - checkNotNull(it.validationDate) { - "An alert must have a validation date: alert ${it.id} has no validation date ($it)." + val alertTypeToAlertsOccurrences: Map> = + reportings + .filter { it.type == ReportingType.ALERT } + .groupBy { (it.value as AlertType).type } + .withDefault { emptyList() } + + val alertTypeToLastAlertAndOccurrences: List = + alertTypeToAlertsOccurrences + .flatMap { (_, alerts) -> + if (alerts.isEmpty()) { + return@flatMap listOf() } - it.validationDate + val lastAlert = + alerts.maxByOrNull { + checkNotNull(it.validationDate) { + "An alert must have a validation date: alert ${it.id} has no validation date ($it)." + } + + it.validationDate + } + checkNotNull(lastAlert) { "Last alert cannot be null" } + val otherOccurrencesOfSameAlert = alerts.filter { it.id != lastAlert.id } + + return@flatMap listOf( + ReportingAndOccurrences( + otherOccurrencesOfSameAlert = otherOccurrencesOfSameAlert, + reporting = lastAlert, + controlUnit = null, + ), + ) } - checkNotNull(lastAlert) { "Last alert cannot be null" } - val otherOccurrencesOfSameAlert = alerts.filter { it.id != lastAlert.id } - - return@flatMap listOf( - ReportingAndOccurrences( - otherOccurrencesOfSameAlert = otherOccurrencesOfSameAlert, - reporting = lastAlert, - controlUnit = null, - ), - ) - } return (reportingsWithoutAlerts + alertTypeToLastAlertAndOccurrences) } @@ -177,12 +188,13 @@ class GetVesselReportings( fromDate, ) - else -> reportingRepository.findCurrentAndArchivedWithoutVesselIdentifier( - internalReferenceNumber, - externalReferenceNumber, - ircs, - fromDate, - ) + else -> + reportingRepository.findCurrentAndArchivedWithoutVesselIdentifier( + internalReferenceNumber, + externalReferenceNumber, + ircs, + fromDate, + ) } } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselVoyage.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselVoyage.kt index 643a2bf4de..9837a18e8b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselVoyage.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetVesselVoyage.kt @@ -19,59 +19,73 @@ class GetVesselVoyage( ) { private val logger = LoggerFactory.getLogger(GetVesselVoyage::class.java) - fun execute(internalReferenceNumber: String, voyageRequest: VoyageRequest, tripNumber: String?): Voyage { - val trip = try { - when (voyageRequest) { - VoyageRequest.LAST -> logbookReportRepository.findLastTripBeforeDateTime( - internalReferenceNumber, - /** - * This 4-hour buffer prevents incorrect message datetime to be filtered. - * Sometimes, vessel inboard computers might have offset datetime. - */ - ZonedDateTime.now().plusHours(4), - ) - VoyageRequest.PREVIOUS -> { - require(tripNumber != null) { - "Current trip number parameter must be not null" + fun execute( + internalReferenceNumber: String, + voyageRequest: VoyageRequest, + tripNumber: String?, + ): Voyage { + val trip = + try { + when (voyageRequest) { + VoyageRequest.LAST -> + logbookReportRepository.findLastTripBeforeDateTime( + internalReferenceNumber, + /** + * This 4-hour buffer prevents incorrect message datetime to be filtered. + * Sometimes, vessel inboard computers might have offset datetime. + */ + ZonedDateTime.now().plusHours(4), + ) + VoyageRequest.PREVIOUS -> { + require(tripNumber != null) { + "Current trip number parameter must be not null" + } + + logbookReportRepository.findTripBeforeTripNumber(internalReferenceNumber, tripNumber) } + VoyageRequest.NEXT -> { + require(tripNumber != null) { + "Current trip number parameter must be not null" + } - logbookReportRepository.findTripBeforeTripNumber(internalReferenceNumber, tripNumber) - } - VoyageRequest.NEXT -> { - require(tripNumber != null) { - "Current trip number parameter must be not null" + logbookReportRepository.findTripAfterTripNumber(internalReferenceNumber, tripNumber) } - logbookReportRepository.findTripAfterTripNumber(internalReferenceNumber, tripNumber) - } + VoyageRequest.EQUALS -> { + require(tripNumber != null) { + "trip number parameter must be not null" + } - VoyageRequest.EQUALS -> { - require(tripNumber != null) { - "trip number parameter must be not null" + logbookReportRepository.findFirstAndLastOperationsDatesOfTrip( + internalReferenceNumber, + tripNumber, + ) } - - logbookReportRepository.findFirstAndLastOperationsDatesOfTrip(internalReferenceNumber, tripNumber) } + } catch (e: IllegalArgumentException) { + throw NoLogbookFishingTripFound( + "Could not fetch voyage for request \"${voyageRequest}\": ${e.message}", + e, + ) } - } catch (e: IllegalArgumentException) { - throw NoLogbookFishingTripFound("Could not fetch voyage for request \"${voyageRequest}\": ${e.message}", e) - } val isLastVoyage = getIsLastVoyage(tripNumber, voyageRequest, internalReferenceNumber, trip.tripNumber) val isFirstVoyage = getIsFirstVoyage(internalReferenceNumber, trip.tripNumber) - val alerts = PNOAndLANAlertRepository.findAlertsOfTypes( - listOf(AlertTypeMapping.PNO_LAN_WEIGHT_TOLERANCE_ALERT), - internalReferenceNumber, - trip.tripNumber, - ) - - val logbookMessages = getLogbookMessages.execute( - internalReferenceNumber, - trip.startDate, - trip.endDate, - trip.tripNumber, - ) + val alerts = + PNOAndLANAlertRepository.findAlertsOfTypes( + listOf(AlertTypeMapping.PNO_LAN_WEIGHT_TOLERANCE_ALERT), + internalReferenceNumber, + trip.tripNumber, + ) + + val logbookMessages = + getLogbookMessages.execute( + internalReferenceNumber, + trip.startDate, + trip.endDate, + trip.tripNumber, + ) return Voyage( isLastVoyage, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/SearchVessels.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/SearchVessels.kt index 9d087eaaac..fef0f45aa0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/SearchVessels.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/SearchVessels.kt @@ -11,25 +11,27 @@ class SearchVessels( private val beaconRepository: BeaconRepository, ) { fun execute(searched: String): List { - val vessels = vesselRepository.search(searched).filter { - !( - it.internalReferenceNumber.isNullOrEmpty() && - it.externalReferenceNumber.isNullOrEmpty() && - it.ircs.isNullOrEmpty() && - it.mmsi.isNullOrEmpty() + val vessels = + vesselRepository.search(searched).filter { + !( + it.internalReferenceNumber.isNullOrEmpty() && + it.externalReferenceNumber.isNullOrEmpty() && + it.ircs.isNullOrEmpty() && + it.mmsi.isNullOrEmpty() ) - }.map { VesselAndBeacon(vessel = it) } + }.map { VesselAndBeacon(vessel = it) } val beacons = beaconRepository.search(searched) val beaconsVesselId = beacons.mapNotNull { it.vesselId } - val vesselsFromBeacons = vesselRepository - .findVesselsByIds(beaconsVesselId) - .map { vessel -> - val beacon = beacons.find { beacon -> beacon.vesselId == vessel.id } + val vesselsFromBeacons = + vesselRepository + .findVesselsByIds(beaconsVesselId) + .map { vessel -> + val beacon = beacons.find { beacon -> beacon.vesselId == vessel.id } - return@map VesselAndBeacon(vessel, beacon) - } + return@map VesselAndBeacon(vessel, beacon) + } return (vesselsFromBeacons + vessels) .distinctBy { it.vessel.id } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/ControllersExceptionHandler.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/ControllersExceptionHandler.kt index 2bf175aa85..e3698633d6 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/ControllersExceptionHandler.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/ControllersExceptionHandler.kt @@ -23,9 +23,7 @@ class ControllersExceptionHandler(val sentryConfig: SentryConfig) { @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(BackendInternalException::class) - fun handleBackendInternalException( - e: BackendInternalException, - ): BackendInternalErrorDataOutput { + fun handleBackendInternalException(e: BackendInternalException): BackendInternalErrorDataOutput { return BackendInternalErrorDataOutput(code = e.code, message = e.message) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/BeaconMalfunctionController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/BeaconMalfunctionController.kt index 468a91da51..71fc122a02 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/BeaconMalfunctionController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/BeaconMalfunctionController.kt @@ -23,7 +23,6 @@ class BeaconMalfunctionController( private val saveBeaconMalfunctionComment: SaveBeaconMalfunctionComment, private val requestNotification: RequestNotification, ) { - @GetMapping(value = [""]) @Operation(summary = "Get all beacon malfunctions") fun getAllBeaconMalfunctions(): List { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ControlObjectiveAdminController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ControlObjectiveAdminController.kt index f184eb93b3..66b0d50476 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ControlObjectiveAdminController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ControlObjectiveAdminController.kt @@ -21,7 +21,6 @@ class ControlObjectiveAdminController( private val deleteControlObjective: DeleteControlObjective, private val addControlObjective: AddControlObjective, ) { - @GetMapping("/{year}") @Operation(summary = "Get control objectives of a given year") fun getControlObjectivesOfYear( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/DataReferentialController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/DataReferentialController.kt index 71d4a8ef67..6d258b092b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/DataReferentialController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/DataReferentialController.kt @@ -17,7 +17,6 @@ class DataReferentialController( private val getAllGears: GetAllGears, private val getAllSpeciesAndSpeciesGroups: GetAllSpeciesAndSpeciesGroups, ) { - @GetMapping("/v1/gears") @Operation(summary = "Get FAO fishing gear codes") fun getGears(): List { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FaoAreaController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FaoAreaController.kt index c98080313f..f324142d65 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FaoAreaController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FaoAreaController.kt @@ -17,7 +17,6 @@ class FaoAreaController( private val getFAOAreas: GetFaoAreas, private val computeVesselFAOAreas: ComputeVesselFaoAreas, ) { - @GetMapping("/v1/fao_areas") @Operation(summary = "Get FAO areas") fun getFAOAreas(): List { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentAdminController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentAdminController.kt index bfb19da1f1..56fa549f37 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentAdminController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentAdminController.kt @@ -20,7 +20,6 @@ class FleetSegmentAdminController( private val getFleetSegmentYearEntries: GetFleetSegmentYearEntries, private val addFleetSegmentYear: AddFleetSegmentYear, ) { - @PutMapping(value = [""], consumes = ["application/json"]) @Operation(summary = "Update a fleet segment") fun updateFleetSegment( @@ -33,11 +32,12 @@ class FleetSegmentAdminController( @RequestBody createOrUpdateFleetSegmentData: CreateOrUpdateFleetSegmentDataInput, ): FleetSegmentDataOutput { - val updatedFleetSegment = updateFleetSegment.execute( - segment = segment, - fields = createOrUpdateFleetSegmentData.toCreateOrUpdateFleetSegmentFields(), - year = year, - ) + val updatedFleetSegment = + updateFleetSegment.execute( + segment = segment, + fields = createOrUpdateFleetSegmentData.toCreateOrUpdateFleetSegmentFields(), + year = year, + ) return FleetSegmentDataOutput.fromFleetSegment(updatedFleetSegment) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentController.kt index 3a5d37b2f8..0606eccdfa 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentController.kt @@ -16,7 +16,6 @@ class FleetSegmentController( private val getAllFleetSegmentsByYearByYear: GetAllFleetSegmentsByYear, private val computeFleetSegments: ComputeFleetSegments, ) { - @GetMapping("/{year}") @Operation(summary = "Get fleet segments") fun getFleetSegments( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ForeignFMCsController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ForeignFMCsController.kt index 0f2c3793ac..e27610041d 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ForeignFMCsController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ForeignFMCsController.kt @@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RestController @RequestMapping("/bff/v1/foreign_fmcs") @Tag(name = "APIs for foreign FMCs") class ForeignFMCsController(private val getAllForeignFMCs: GetAllForeignFMCs) { - @GetMapping("") @Operation(summary = "Get all foreign FMCs") fun getAllForeignFMCs(): List { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt index f9f0f5ee08..868ce696ae 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsController.kt @@ -28,7 +28,6 @@ class MissionActionsController( private val getMissionAction: GetMissionAction, private val getActivityReports: GetActivityReports, ) { - @GetMapping("/controls") @Operation(summary = "Get vessel's controls") fun getVesselControls( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionController.kt index 76578f0648..10baf6eeee 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionController.kt @@ -19,7 +19,6 @@ class MissionController( private val getAllMissions: GetAllMissions, private val getMission: GetMission, ) { - @GetMapping("") @Operation(summary = "Get all missions") fun getAllMissionsController( @@ -50,16 +49,17 @@ class MissionController( @RequestParam(name = "seaFronts", required = false) seaFronts: List?, ): List { - val missionsAndActions = getAllMissions.execute( - startedAfterDateTime = startedAfterDateTime, - startedBeforeDateTime = startedBeforeDateTime, - missionSources = missionSources, - missionStatuses = missionStatuses, - missionTypes = missionTypes, - seaFronts = seaFronts, - pageNumber = pageNumber, - pageSize = pageSize, - ) + val missionsAndActions = + getAllMissions.execute( + startedAfterDateTime = startedAfterDateTime, + startedBeforeDateTime = startedBeforeDateTime, + missionSources = missionSources, + missionStatuses = missionStatuses, + missionTypes = missionTypes, + seaFronts = seaFronts, + pageNumber = pageNumber, + pageSize = pageSize, + ) return missionsAndActions.map { MissionWithActionsDataOutput.fromMissionAndActions(it) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PendingAlertController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PendingAlertController.kt index d157c8243a..f8d587450f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PendingAlertController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PendingAlertController.kt @@ -23,7 +23,6 @@ class PendingAlertController( private val silenceAlert: SilenceAlert, private val objectMapper: ObjectMapper, ) { - @GetMapping("") @Operation(summary = "Get pending operational alerts") fun getOperationalAlerts(): List { @@ -51,11 +50,12 @@ class PendingAlertController( @RequestBody silenceOperationalAlertData: SilenceOperationalAlertDataInput, ): SilencedAlertDataOutput { - val silencedAlert = silencePendingAlert.execute( - id, - silenceOperationalAlertData.silencedAlertPeriod, - silenceOperationalAlertData.beforeDateTime, - ) + val silencedAlert = + silencePendingAlert.execute( + id, + silenceOperationalAlertData.silencedAlertPeriod, + silenceOperationalAlertData.beforeDateTime, + ) return SilencedAlertDataOutput.fromSilencedAlert(silencedAlert) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PortController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PortController.kt index ba8dc34b78..4ca1cc09bd 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PortController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PortController.kt @@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RestController @RequestMapping("/bff/v1/ports") @Tag(name = "APIs for Ports") class PortController(private val getActivePorts: GetActivePorts) { - @GetMapping("") @Operation(summary = "Get all active ports") fun getActivePorts(): List { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PriorNotificationController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PriorNotificationController.kt index 18936ff995..913a88f0f7 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PriorNotificationController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PriorNotificationController.kt @@ -81,14 +81,12 @@ class PriorNotificationController( @Parameter(description = "Vessels that will arrive before the given date.") @RequestParam(name = "willArriveBefore") willArriveBefore: String, - @Parameter(description = "Seafront group.") @RequestParam(name = "seafrontGroup") seafrontGroup: SeafrontGroup, @Parameter(description = "States.") @RequestParam(name = "states") states: List? = null, - @Parameter(description = "Sort column.") @RequestParam(name = "sortColumn") sortColumn: PriorNotificationsSortColumn, @@ -102,28 +100,40 @@ class PriorNotificationController( @RequestParam(name = "pageNumber") pageNumber: Int, ): PaginatedListDataOutput { - val priorNotificationsFilter = PriorNotificationsFilter( - flagStates = flagStates, - hasOneOrMoreReportings = hasOneOrMoreReportings, - isLessThanTwelveMetersVessel = isLessThanTwelveMetersVessel, - lastControlledAfter = lastControlledAfter, - lastControlledBefore = lastControlledBefore, - portLocodes = portLocodes, - priorNotificationTypes = priorNotificationTypes, - searchQuery = searchQuery, - specyCodes = specyCodes, - tripGearCodes = tripGearCodes, - tripSegmentCodes = tripSegmentCodes, - willArriveAfter = willArriveAfter, - willArriveBefore = willArriveBefore, - ) + val priorNotificationsFilter = + PriorNotificationsFilter( + flagStates = flagStates, + hasOneOrMoreReportings = hasOneOrMoreReportings, + isLessThanTwelveMetersVessel = isLessThanTwelveMetersVessel, + lastControlledAfter = lastControlledAfter, + lastControlledBefore = lastControlledBefore, + portLocodes = portLocodes, + priorNotificationTypes = priorNotificationTypes, + searchQuery = searchQuery, + specyCodes = specyCodes, + tripGearCodes = tripGearCodes, + tripSegmentCodes = tripSegmentCodes, + willArriveAfter = willArriveAfter, + willArriveBefore = willArriveBefore, + ) - val paginatedPriorNotifications = getPriorNotifications - .execute(priorNotificationsFilter, seafrontGroup, states, sortColumn, sortDirection, pageNumber, pageSize) - val priorNotificationListItemDataOutputs = paginatedPriorNotifications.data - .mapNotNull { PriorNotificationListItemDataOutput.fromPriorNotification(it) } - val extraDataOutput = PriorNotificationsExtraDataOutput - .fromPriorNotificationStats(paginatedPriorNotifications.extraData) + val paginatedPriorNotifications = + getPriorNotifications + .execute( + priorNotificationsFilter, + seafrontGroup, + states, + sortColumn, + sortDirection, + pageNumber, + pageSize, + ) + val priorNotificationListItemDataOutputs = + paginatedPriorNotifications.data + .mapNotNull { PriorNotificationListItemDataOutput.fromPriorNotification(it) } + val extraDataOutput = + PriorNotificationsExtraDataOutput + .fromPriorNotificationStats(paginatedPriorNotifications.extraData) return PaginatedListDataOutput( priorNotificationListItemDataOutputs, @@ -147,12 +157,13 @@ class PriorNotificationController( @RequestBody logbookPriorNotificationFormDataInput: LogbookPriorNotificationFormDataInput, ): LogbookPriorNotificationFormDataOutput { - val updatedPriorNotification = updateLogbookPriorNotification.execute( - reportId = reportId, - operationDate = operationDate, - authorTrigram = logbookPriorNotificationFormDataInput.authorTrigram, - note = logbookPriorNotificationFormDataInput.note, - ) + val updatedPriorNotification = + updateLogbookPriorNotification.execute( + reportId = reportId, + operationDate = operationDate, + authorTrigram = logbookPriorNotificationFormDataInput.authorTrigram, + note = logbookPriorNotificationFormDataInput.note, + ) return LogbookPriorNotificationFormDataOutput.fromPriorNotification(updatedPriorNotification) } @@ -167,13 +178,14 @@ class PriorNotificationController( ): ManualPriorNotificationComputedValuesDataOutput { val fishingCatches = manualPriorNotificationComputeDataInput.fishingCatches.map { it.toLogbookFishingCatch() } - val manualPriorNotificationComputedValues = computeManualPriorNotification.execute( - fishingCatches = fishingCatches, - globalFaoArea = manualPriorNotificationComputeDataInput.globalFaoArea, - portLocode = manualPriorNotificationComputeDataInput.portLocode, - tripGearCodes = manualPriorNotificationComputeDataInput.tripGearCodes, - vesselId = manualPriorNotificationComputeDataInput.vesselId, - ) + val manualPriorNotificationComputedValues = + computeManualPriorNotification.execute( + fishingCatches = fishingCatches, + globalFaoArea = manualPriorNotificationComputeDataInput.globalFaoArea, + portLocode = manualPriorNotificationComputeDataInput.portLocode, + tripGearCodes = manualPriorNotificationComputeDataInput.tripGearCodes, + vesselId = manualPriorNotificationComputeDataInput.vesselId, + ) return ManualPriorNotificationComputedValuesDataOutput .fromManualPriorNotificationComputedValues(manualPriorNotificationComputedValues) @@ -185,23 +197,24 @@ class PriorNotificationController( @RequestBody manualPriorNotificationFormDataInput: ManualPriorNotificationFormDataInput, ): ManualPriorNotificationFormDataOutput { - val createdPriorNotification = createOrUpdateManualPriorNotification.execute( - hasPortEntranceAuthorization = manualPriorNotificationFormDataInput.hasPortEntranceAuthorization, - hasPortLandingAuthorization = manualPriorNotificationFormDataInput.hasPortLandingAuthorization, - authorTrigram = manualPriorNotificationFormDataInput.authorTrigram, - didNotFishAfterZeroNotice = manualPriorNotificationFormDataInput.didNotFishAfterZeroNotice, - expectedArrivalDate = manualPriorNotificationFormDataInput.expectedArrivalDate, - expectedLandingDate = manualPriorNotificationFormDataInput.expectedLandingDate, - globalFaoArea = manualPriorNotificationFormDataInput.globalFaoArea, - fishingCatches = manualPriorNotificationFormDataInput.fishingCatches.map { it.toLogbookFishingCatch() }, - note = manualPriorNotificationFormDataInput.note, - portLocode = manualPriorNotificationFormDataInput.portLocode, - reportId = null, - sentAt = manualPriorNotificationFormDataInput.sentAt, - purpose = manualPriorNotificationFormDataInput.purpose, - tripGearCodes = manualPriorNotificationFormDataInput.tripGearCodes, - vesselId = manualPriorNotificationFormDataInput.vesselId, - ) + val createdPriorNotification = + createOrUpdateManualPriorNotification.execute( + hasPortEntranceAuthorization = manualPriorNotificationFormDataInput.hasPortEntranceAuthorization, + hasPortLandingAuthorization = manualPriorNotificationFormDataInput.hasPortLandingAuthorization, + authorTrigram = manualPriorNotificationFormDataInput.authorTrigram, + didNotFishAfterZeroNotice = manualPriorNotificationFormDataInput.didNotFishAfterZeroNotice, + expectedArrivalDate = manualPriorNotificationFormDataInput.expectedArrivalDate, + expectedLandingDate = manualPriorNotificationFormDataInput.expectedLandingDate, + globalFaoArea = manualPriorNotificationFormDataInput.globalFaoArea, + fishingCatches = manualPriorNotificationFormDataInput.fishingCatches.map { it.toLogbookFishingCatch() }, + note = manualPriorNotificationFormDataInput.note, + portLocode = manualPriorNotificationFormDataInput.portLocode, + reportId = null, + sentAt = manualPriorNotificationFormDataInput.sentAt, + purpose = manualPriorNotificationFormDataInput.purpose, + tripGearCodes = manualPriorNotificationFormDataInput.tripGearCodes, + vesselId = manualPriorNotificationFormDataInput.vesselId, + ) return ManualPriorNotificationFormDataOutput.fromPriorNotification(createdPriorNotification) } @@ -215,23 +228,24 @@ class PriorNotificationController( @RequestBody manualPriorNotificationFormDataInput: ManualPriorNotificationFormDataInput, ): ManualPriorNotificationFormDataOutput { - val updatedPriorNotification = createOrUpdateManualPriorNotification.execute( - hasPortEntranceAuthorization = manualPriorNotificationFormDataInput.hasPortEntranceAuthorization, - hasPortLandingAuthorization = manualPriorNotificationFormDataInput.hasPortLandingAuthorization, - authorTrigram = manualPriorNotificationFormDataInput.authorTrigram, - didNotFishAfterZeroNotice = manualPriorNotificationFormDataInput.didNotFishAfterZeroNotice, - expectedArrivalDate = manualPriorNotificationFormDataInput.expectedArrivalDate, - expectedLandingDate = manualPriorNotificationFormDataInput.expectedLandingDate, - globalFaoArea = manualPriorNotificationFormDataInput.globalFaoArea, - fishingCatches = manualPriorNotificationFormDataInput.fishingCatches.map { it.toLogbookFishingCatch() }, - note = manualPriorNotificationFormDataInput.note, - portLocode = manualPriorNotificationFormDataInput.portLocode, - reportId = reportId, - sentAt = manualPriorNotificationFormDataInput.sentAt, - purpose = manualPriorNotificationFormDataInput.purpose, - tripGearCodes = manualPriorNotificationFormDataInput.tripGearCodes, - vesselId = manualPriorNotificationFormDataInput.vesselId, - ) + val updatedPriorNotification = + createOrUpdateManualPriorNotification.execute( + hasPortEntranceAuthorization = manualPriorNotificationFormDataInput.hasPortEntranceAuthorization, + hasPortLandingAuthorization = manualPriorNotificationFormDataInput.hasPortLandingAuthorization, + authorTrigram = manualPriorNotificationFormDataInput.authorTrigram, + didNotFishAfterZeroNotice = manualPriorNotificationFormDataInput.didNotFishAfterZeroNotice, + expectedArrivalDate = manualPriorNotificationFormDataInput.expectedArrivalDate, + expectedLandingDate = manualPriorNotificationFormDataInput.expectedLandingDate, + globalFaoArea = manualPriorNotificationFormDataInput.globalFaoArea, + fishingCatches = manualPriorNotificationFormDataInput.fishingCatches.map { it.toLogbookFishingCatch() }, + note = manualPriorNotificationFormDataInput.note, + portLocode = manualPriorNotificationFormDataInput.portLocode, + reportId = reportId, + sentAt = manualPriorNotificationFormDataInput.sentAt, + purpose = manualPriorNotificationFormDataInput.purpose, + tripGearCodes = manualPriorNotificationFormDataInput.tripGearCodes, + vesselId = manualPriorNotificationFormDataInput.vesselId, + ) return ManualPriorNotificationFormDataOutput.fromPriorNotification(updatedPriorNotification) } @@ -274,14 +288,16 @@ class PriorNotificationController( @PathVariable(name = "reportId") reportId: String, ): ResponseEntity { - val pdfDocument = getPriorNotificationPdfDocument.execute(reportId = reportId, isVerifyingExistence = false) - ?: return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null) + val pdfDocument = + getPriorNotificationPdfDocument.execute(reportId = reportId, isVerifyingExistence = false) + ?: return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null) val fileName = "preavis_debarquement_${pdfDocument.generationDatetimeUtc.format(ISO_DATE_TIME)}.pdf" - val headers = HttpHeaders().apply { - contentType = MediaType.APPLICATION_PDF - setContentDispositionFormData("attachment", fileName) - } + val headers = + HttpHeaders().apply { + contentType = MediaType.APPLICATION_PDF + setContentDispositionFormData("attachment", fileName) + } headers.add("x-generation-date", pdfDocument.generationDatetimeUtc.format(ISO_DATE_TIME)) return ResponseEntity(pdfDocument.pdfDocument, headers, HttpStatus.OK) @@ -332,11 +348,12 @@ class PriorNotificationController( @RequestParam(name = "isManuallyCreated") isManuallyCreated: Boolean, ): PriorNotificationDataOutput { - val updatedPriorNotification = invalidatePriorNotification.execute( - reportId = reportId, - operationDate = operationDate, - isManuallyCreated = isManuallyCreated, - ) + val updatedPriorNotification = + invalidatePriorNotification.execute( + reportId = reportId, + operationDate = operationDate, + isManuallyCreated = isManuallyCreated, + ) return PriorNotificationDataOutput.fromPriorNotification(updatedPriorNotification) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ReportingController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ReportingController.kt index fe92da66a7..26f3e2ea2e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ReportingController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ReportingController.kt @@ -22,7 +22,6 @@ class ReportingController( private val getAllCurrentReportings: GetAllCurrentReportings, private val addReporting: AddReporting, ) { - @PostMapping(value = [""], consumes = ["application/json"]) @Operation(summary = "Create a reporting") @ResponseStatus(HttpStatus.CREATED) @@ -62,17 +61,20 @@ class ReportingController( @RequestBody updateReportingInput: UpdateReportingDataInput, ): ReportingDataOutput { - val (updatedReporting, controlUnit) = updateReporting.execute( - reportingId, - updateReportingInput.toUpdatedReportingValues(), - ) + val (updatedReporting, controlUnit) = + updateReporting.execute( + reportingId, + updateReportingInput.toUpdatedReportingValues(), + ) return ReportingDataOutput.fromReporting(updatedReporting, controlUnit) } @PutMapping(value = ["/archive"]) @Operation(summary = "Archive multiple reportings") - fun archiveReportings(@RequestBody ids: List) { + fun archiveReportings( + @RequestBody ids: List, + ) { archiveReportings.execute(ids) } @@ -88,7 +90,9 @@ class ReportingController( @PutMapping(value = ["/delete"]) @Operation(summary = "Delete multiple reportings") - fun deleteReporting(@RequestBody ids: List) { + fun deleteReporting( + @RequestBody ids: List, + ) { deleteReportings.execute(ids) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselController.kt index 9875186bde..69c3fea69d 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselController.kt @@ -84,16 +84,17 @@ class VesselController( beforeDateTime: ZonedDateTime?, ): ResponseEntity { return runBlocking { - val (vesselTrackHasBeenModified, vesselWithData) = getVessel.execute( - vesselId, - internalReferenceNumber, - externalReferenceNumber, - IRCS, - trackDepth, - vesselIdentifier, - afterDateTime, - beforeDateTime, - ) + val (vesselTrackHasBeenModified, vesselWithData) = + getVessel.execute( + vesselId, + internalReferenceNumber, + externalReferenceNumber, + IRCS, + trackDepth, + vesselIdentifier, + afterDateTime, + beforeDateTime, + ) val returnCode = if (vesselTrackHasBeenModified) HttpStatus.ACCEPTED else HttpStatus.OK @@ -112,10 +113,11 @@ class VesselController( @DateTimeFormat(pattern = zoneDateTimePattern) afterDateTime: ZonedDateTime, ): BeaconMalfunctionsResumeAndHistoryDataOutput { - val beaconMalfunctionsWithDetails = getVesselBeaconMalfunctions.execute( - vesselId, - afterDateTime, - ) + val beaconMalfunctionsWithDetails = + getVesselBeaconMalfunctions.execute( + vesselId, + afterDateTime, + ) return BeaconMalfunctionsResumeAndHistoryDataOutput.fromBeaconMalfunctionsResumeAndHistory( beaconMalfunctionsWithDetails, @@ -150,21 +152,23 @@ class VesselController( beforeDateTime: ZonedDateTime?, ): ResponseEntity> { return runBlocking { - val (vesselTrackHasBeenModified, positions) = getVesselPositions.execute( - internalReferenceNumber, - externalReferenceNumber, - IRCS, - trackDepth, - vesselIdentifier, - afterDateTime, - beforeDateTime, - ) + val (vesselTrackHasBeenModified, positions) = + getVesselPositions.execute( + internalReferenceNumber, + externalReferenceNumber, + IRCS, + trackDepth, + vesselIdentifier, + afterDateTime, + beforeDateTime, + ) val returnCode = if (vesselTrackHasBeenModified) HttpStatus.ACCEPTED else HttpStatus.OK - val positionsDataOutput = positions.await().map { - PositionDataOutput.fromPosition(it) - } + val positionsDataOutput = + positions.await().map { + PositionDataOutput.fromPosition(it) + } return@runBlocking ResponseEntity.status(returnCode).body(positionsDataOutput) } @@ -197,14 +201,15 @@ class VesselController( @DateTimeFormat(pattern = zoneDateTimePattern) fromDate: ZonedDateTime, ): CurrentAndArchivedReportingDataOutput { - val currentAndArchivedReportings = getVesselReportings.execute( - vesselId, - internalReferenceNumber, - externalReferenceNumber, - IRCS, - vesselIdentifier, - fromDate, - ) + val currentAndArchivedReportings = + getVesselReportings.execute( + vesselId, + internalReferenceNumber, + externalReferenceNumber, + IRCS, + vesselIdentifier, + fromDate, + ) return CurrentAndArchivedReportingDataOutput.fromCurrentAndArchivedReporting(currentAndArchivedReportings) } @@ -214,7 +219,7 @@ class VesselController( fun searchVessel( @Parameter( description = - "Vessel internal reference number (CFR), external marker, IRCS, MMSI, name or beacon number", + "Vessel internal reference number (CFR), external marker, IRCS, MMSI, name or beacon number", required = true, ) @RequestParam(name = "searched") @@ -233,7 +238,7 @@ class VesselController( internalReferenceNumber: String, @Parameter( description = - "Voyage request (LAST, PREVIOUS or NEXT) with respect to date", + "Voyage request (LAST, PREVIOUS or NEXT) with respect to date", required = true, ) @RequestParam(name = "voyageRequest") diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt index 885eb0b902..b25dbba45a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/AddMissionActionDataInput.kt @@ -58,58 +58,59 @@ data class AddMissionActionDataInput( var isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null, var isSeafarersControl: Boolean? = null, ) { - fun toMissionAction() = MissionAction( - vesselId = vesselId, - vesselName = vesselName, - internalReferenceNumber = internalReferenceNumber, - externalReferenceNumber = externalReferenceNumber, - ircs = ircs, - flagState = flagState ?: CountryCode.UNDEFINED, - districtCode = districtCode, - faoAreas = faoAreas, - flightGoals = flightGoals, - missionId = missionId, - actionType = actionType, - actionDatetimeUtc = actionDatetimeUtc, - emitsVms = emitsVms, - emitsAis = emitsAis, - logbookMatchesActivity = logbookMatchesActivity, - licencesMatchActivity = licencesMatchActivity, - speciesWeightControlled = speciesWeightControlled, - speciesSizeControlled = speciesSizeControlled, - separateStowageOfPreservedSpecies = separateStowageOfPreservedSpecies, - logbookInfractions = logbookInfractions, - licencesAndLogbookObservations = licencesAndLogbookObservations, - gearInfractions = gearInfractions, - speciesInfractions = speciesInfractions, - speciesObservations = speciesObservations, - seizureAndDiversion = seizureAndDiversion, - otherInfractions = otherInfractions, - numberOfVesselsFlownOver = numberOfVesselsFlownOver, - unitWithoutOmegaGauge = unitWithoutOmegaGauge, - controlQualityComments = controlQualityComments, - feedbackSheetRequired = feedbackSheetRequired, - segments = segments, - facade = facade, - longitude = longitude, - latitude = latitude, - portLocode = portLocode, - seizureAndDiversionComments = seizureAndDiversionComments, - otherComments = otherComments, - gearOnboard = gearOnboard, - speciesOnboard = speciesOnboard, - userTrigram = userTrigram, - vesselTargeted = vesselTargeted, - isDeleted = false, - hasSomeGearsSeized = hasSomeGearsSeized, - hasSomeSpeciesSeized = hasSomeSpeciesSeized, - speciesQuantitySeized = speciesQuantitySeized, - completedBy = completedBy, - completion = completion, - isFromPoseidon = isFromPoseidon ?: false, - isAdministrativeControl = isAdministrativeControl, - isComplianceWithWaterRegulationsControl = isComplianceWithWaterRegulationsControl, - isSafetyEquipmentAndStandardsComplianceControl = isSafetyEquipmentAndStandardsComplianceControl, - isSeafarersControl = isSeafarersControl, - ) + fun toMissionAction() = + MissionAction( + vesselId = vesselId, + vesselName = vesselName, + internalReferenceNumber = internalReferenceNumber, + externalReferenceNumber = externalReferenceNumber, + ircs = ircs, + flagState = flagState ?: CountryCode.UNDEFINED, + districtCode = districtCode, + faoAreas = faoAreas, + flightGoals = flightGoals, + missionId = missionId, + actionType = actionType, + actionDatetimeUtc = actionDatetimeUtc, + emitsVms = emitsVms, + emitsAis = emitsAis, + logbookMatchesActivity = logbookMatchesActivity, + licencesMatchActivity = licencesMatchActivity, + speciesWeightControlled = speciesWeightControlled, + speciesSizeControlled = speciesSizeControlled, + separateStowageOfPreservedSpecies = separateStowageOfPreservedSpecies, + logbookInfractions = logbookInfractions, + licencesAndLogbookObservations = licencesAndLogbookObservations, + gearInfractions = gearInfractions, + speciesInfractions = speciesInfractions, + speciesObservations = speciesObservations, + seizureAndDiversion = seizureAndDiversion, + otherInfractions = otherInfractions, + numberOfVesselsFlownOver = numberOfVesselsFlownOver, + unitWithoutOmegaGauge = unitWithoutOmegaGauge, + controlQualityComments = controlQualityComments, + feedbackSheetRequired = feedbackSheetRequired, + segments = segments, + facade = facade, + longitude = longitude, + latitude = latitude, + portLocode = portLocode, + seizureAndDiversionComments = seizureAndDiversionComments, + otherComments = otherComments, + gearOnboard = gearOnboard, + speciesOnboard = speciesOnboard, + userTrigram = userTrigram, + vesselTargeted = vesselTargeted, + isDeleted = false, + hasSomeGearsSeized = hasSomeGearsSeized, + hasSomeSpeciesSeized = hasSomeSpeciesSeized, + speciesQuantitySeized = speciesQuantitySeized, + completedBy = completedBy, + completion = completion, + isFromPoseidon = isFromPoseidon ?: false, + isAdministrativeControl = isAdministrativeControl, + isComplianceWithWaterRegulationsControl = isComplianceWithWaterRegulationsControl, + isSafetyEquipmentAndStandardsComplianceControl = isSafetyEquipmentAndStandardsComplianceControl, + isSeafarersControl = isSeafarersControl, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/CreateOrUpdateFleetSegmentDataInput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/CreateOrUpdateFleetSegmentDataInput.kt index b170329925..b9a4454854 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/CreateOrUpdateFleetSegmentDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/CreateOrUpdateFleetSegmentDataInput.kt @@ -12,14 +12,15 @@ data class CreateOrUpdateFleetSegmentDataInput( var impactRiskFactor: Double? = null, var year: Int? = null, ) { - fun toCreateOrUpdateFleetSegmentFields() = CreateOrUpdateFleetSegmentFields( - segment = this.segment, - segmentName = this.segmentName, - gears = this.gears, - faoAreas = this.faoAreas, - targetSpecies = this.targetSpecies, - bycatchSpecies = this.bycatchSpecies, - impactRiskFactor = this.impactRiskFactor, - year = this.year, - ) + fun toCreateOrUpdateFleetSegmentFields() = + CreateOrUpdateFleetSegmentFields( + segment = this.segment, + segmentName = this.segmentName, + gears = this.gears, + faoAreas = this.faoAreas, + targetSpecies = this.targetSpecies, + bycatchSpecies = this.bycatchSpecies, + impactRiskFactor = this.impactRiskFactor, + year = this.year, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/CreateReportingDataInput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/CreateReportingDataInput.kt index 3b6b12ad8d..3e37579219 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/CreateReportingDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/CreateReportingDataInput.kt @@ -20,19 +20,20 @@ class CreateReportingDataInput( val validationDate: ZonedDateTime? = null, val value: InfractionSuspicionOrObservationType, ) { - fun toReporting() = Reporting( - type = this.type, - vesselId = this.vesselId, - vesselName = this.vesselName, - internalReferenceNumber = this.internalReferenceNumber, - externalReferenceNumber = this.externalReferenceNumber, - ircs = this.ircs, - vesselIdentifier = this.vesselIdentifier, - flagState = this.flagState, - creationDate = this.creationDate, - validationDate = this.validationDate, - isDeleted = false, - isArchived = false, - value = this.value, - ) + fun toReporting() = + Reporting( + type = this.type, + vesselId = this.vesselId, + vesselName = this.vesselName, + internalReferenceNumber = this.internalReferenceNumber, + externalReferenceNumber = this.externalReferenceNumber, + ircs = this.ircs, + vesselIdentifier = this.vesselIdentifier, + flagState = this.flagState, + creationDate = this.creationDate, + validationDate = this.validationDate, + isDeleted = false, + isArchived = false, + value = this.value, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/SilencedAlertDataInput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/SilencedAlertDataInput.kt index f030549e3d..c5e0a6c99b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/SilencedAlertDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/SilencedAlertDataInput.kt @@ -18,15 +18,16 @@ class SilencedAlertDataInput( val silencedBeforeDate: ZonedDateTime, val value: String, ) { - fun toSilencedAlert(objectMapper: ObjectMapper) = SilencedAlert( - vesselId = this.vesselId, - vesselName = this.vesselName, - internalReferenceNumber = this.internalReferenceNumber, - externalReferenceNumber = this.externalReferenceNumber, - ircs = this.ircs, - vesselIdentifier = this.vesselIdentifier, - flagState = this.flagState, - silencedBeforeDate = this.silencedBeforeDate, - value = objectMapper.readValue(value, AlertType::class.java), - ) + fun toSilencedAlert(objectMapper: ObjectMapper) = + SilencedAlert( + vesselId = this.vesselId, + vesselName = this.vesselName, + internalReferenceNumber = this.internalReferenceNumber, + externalReferenceNumber = this.externalReferenceNumber, + ircs = this.ircs, + vesselIdentifier = this.vesselIdentifier, + flagState = this.flagState, + silencedBeforeDate = this.silencedBeforeDate, + value = objectMapper.readValue(value, AlertType::class.java), + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/UpdateReportingDataInput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/UpdateReportingDataInput.kt index 1375304b41..a7aacd7bdb 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/UpdateReportingDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/UpdateReportingDataInput.kt @@ -14,14 +14,15 @@ class UpdateReportingDataInput( val description: String? = null, val natinfCode: Int? = null, ) { - fun toUpdatedReportingValues() = UpdatedInfractionSuspicionOrObservation( - reportingActor = this.reportingActor, - type = this.type, - controlUnitId = this.controlUnitId, - authorTrigram = this.authorTrigram, - authorContact = this.authorContact, - title = this.title, - description = this.description, - natinfCode = this.natinfCode, - ) + fun toUpdatedReportingValues() = + UpdatedInfractionSuspicionOrObservation( + reportingActor = this.reportingActor, + type = this.type, + controlUnitId = this.controlUnitId, + authorTrigram = this.authorTrigram, + authorContact = this.authorContact, + title = this.title, + description = this.description, + natinfCode = this.natinfCode, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/VesselLightController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/VesselLightController.kt index 288d562f6a..ef4b9e93dd 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/VesselLightController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/VesselLightController.kt @@ -30,7 +30,6 @@ class VesselLightController( private val getVessel: GetVessel, private val getVesselVoyage: GetVesselVoyage, ) { - companion object { const val zoneDateTimePattern = "yyyy-MM-dd'T'HH:mm:ss.000X" } @@ -78,16 +77,17 @@ class VesselLightController( beforeDateTime: ZonedDateTime?, ): ResponseEntity { return runBlocking { - val (vesselTrackHasBeenModified, vesselWithData) = getVessel.execute( - vesselId, - internalReferenceNumber, - externalReferenceNumber, - IRCS, - trackDepth, - vesselIdentifier, - afterDateTime, - beforeDateTime, - ) + val (vesselTrackHasBeenModified, vesselWithData) = + getVessel.execute( + vesselId, + internalReferenceNumber, + externalReferenceNumber, + IRCS, + trackDepth, + vesselIdentifier, + afterDateTime, + beforeDateTime, + ) val returnCode = if (vesselTrackHasBeenModified) HttpStatus.ACCEPTED else HttpStatus.OK @@ -103,7 +103,7 @@ class VesselLightController( internalReferenceNumber: String, @Parameter( description = - "Voyage request (LAST, PREVIOUS or NEXT) with respect to date", + "Voyage request (LAST, PREVIOUS or NEXT) with respect to date", required = true, ) @RequestParam(name = "voyageRequest") diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LastPositionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LastPositionDataOutput.kt index 5063921a79..5a526a272f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LastPositionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LastPositionDataOutput.kt @@ -74,11 +74,12 @@ data class LastPositionDataOutput( districtCode = position.districtCode, gearOnboard = position.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) }, segments = position.segments, - speciesOnboard = position.speciesOnboard?.map { - SpeciesLastPositionDataOutput.fromSpeciesLastPosition( - it, - ) - }, + speciesOnboard = + position.speciesOnboard?.map { + SpeciesLastPositionDataOutput.fromSpeciesLastPosition( + it, + ) + }, totalWeightOnboard = position.totalWeightOnboard, lastControlDateTime = position.lastControlDateTime, lastControlInfraction = position.lastControlInfraction, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LogbookMessageDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LogbookMessageDataOutput.kt index f30ff76d63..16d97dc1eb 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LogbookMessageDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LogbookMessageDataOutput.kt @@ -31,28 +31,29 @@ data class LogbookMessageDataOutput( val isSentByFailoverSoftware: Boolean, ) { companion object { - fun fromLogbookMessage(logbookMessage: LogbookMessage) = LogbookMessageDataOutput( - internalReferenceNumber = logbookMessage.internalReferenceNumber, - referencedReportId = logbookMessage.referencedReportId, - externalReferenceNumber = logbookMessage.externalReferenceNumber, - ircs = logbookMessage.ircs, - isCorrected = logbookMessage.isCorrectedByNewerMessage, - acknowledgment = logbookMessage.acknowledgment, - deleted = logbookMessage.isDeleted, - operationDateTime = logbookMessage.operationDateTime, - reportDateTime = logbookMessage.reportDateTime, - integrationDateTime = logbookMessage.integrationDateTime, - vesselName = logbookMessage.vesselName, - operationType = logbookMessage.operationType, - reportId = logbookMessage.reportId, - operationNumber = logbookMessage.operationNumber, - tripNumber = logbookMessage.tripNumber, - flagState = logbookMessage.flagState, - imo = logbookMessage.imo, - messageType = logbookMessage.messageType, - message = logbookMessage.message, - rawMessage = null, - isSentByFailoverSoftware = logbookMessage.isSentByFailoverSoftware, - ) + fun fromLogbookMessage(logbookMessage: LogbookMessage) = + LogbookMessageDataOutput( + internalReferenceNumber = logbookMessage.internalReferenceNumber, + referencedReportId = logbookMessage.referencedReportId, + externalReferenceNumber = logbookMessage.externalReferenceNumber, + ircs = logbookMessage.ircs, + isCorrected = logbookMessage.isCorrectedByNewerMessage, + acknowledgment = logbookMessage.acknowledgment, + deleted = logbookMessage.isDeleted, + operationDateTime = logbookMessage.operationDateTime, + reportDateTime = logbookMessage.reportDateTime, + integrationDateTime = logbookMessage.integrationDateTime, + vesselName = logbookMessage.vesselName, + operationType = logbookMessage.operationType, + reportId = logbookMessage.reportId, + operationNumber = logbookMessage.operationNumber, + tripNumber = logbookMessage.tripNumber, + flagState = logbookMessage.flagState, + imo = logbookMessage.imo, + messageType = logbookMessage.messageType, + message = logbookMessage.message, + rawMessage = null, + isSentByFailoverSoftware = logbookMessage.isSentByFailoverSoftware, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LogbookMessagesAndAlertsDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LogbookMessagesAndAlertsDataOutput.kt index 786a382314..4a3b86115b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LogbookMessagesAndAlertsDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/LogbookMessagesAndAlertsDataOutput.kt @@ -8,11 +8,10 @@ data class LogbookMessagesAndAlertsDataOutput( val alerts: List, ) { companion object { - fun fromLogbookMessagesAndAlerts( - logbookMessagesAndAlerts: LogbookMessagesAndAlerts, - ) = LogbookMessagesAndAlertsDataOutput( - logbookMessagesAndAlerts.logbookMessages.map { LogbookMessageDataOutput.fromLogbookMessage(it) }, - logbookMessagesAndAlerts.alerts, - ) + fun fromLogbookMessagesAndAlerts(logbookMessagesAndAlerts: LogbookMessagesAndAlerts) = + LogbookMessagesAndAlertsDataOutput( + logbookMessagesAndAlerts.logbookMessages.map { LogbookMessageDataOutput.fromLogbookMessage(it) }, + logbookMessagesAndAlerts.alerts, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VesselAndPositionsDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VesselAndPositionsDataOutput.kt index d2f680769b..e0d711c5f0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VesselAndPositionsDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VesselAndPositionsDataOutput.kt @@ -10,13 +10,15 @@ data class VesselAndPositionsDataOutput( companion object { fun fromVesselWithData(vesselInformation: VesselInformation): VesselAndPositionsDataOutput { return VesselAndPositionsDataOutput( - vessel = VesselDataOutput.fromVessel( - vesselInformation.vessel, - vesselInformation.beacon, - ), - positions = vesselInformation.positions.map { - PositionDataOutput.fromPosition(it) - }, + vessel = + VesselDataOutput.fromVessel( + vesselInformation.vessel, + vesselInformation.beacon, + ), + positions = + vesselInformation.positions.map { + PositionDataOutput.fromPosition(it) + }, ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VesselDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VesselDataOutput.kt index 0a016ced95..604742175f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VesselDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VesselDataOutput.kt @@ -43,7 +43,10 @@ data class VesselDataOutput( val hasVisioCaptures: Boolean? = null, ) { companion object { - fun fromVessel(vessel: Vessel?, beacon: Beacon?): VesselDataOutput? { + fun fromVessel( + vessel: Vessel?, + beacon: Beacon?, + ): VesselDataOutput? { if (vessel == null) { return null } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VoyageDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VoyageDataOutput.kt index f64cf57674..2975587325 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VoyageDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/outputs/VoyageDataOutput.kt @@ -19,8 +19,9 @@ data class VoyageDataOutput( startDate = voyage.startDate, endDate = voyage.endDate, tripNumber = voyage.tripNumber, - logbookMessagesAndAlerts = LogbookMessagesAndAlertsDataOutput - .fromLogbookMessagesAndAlerts(voyage.logbookMessagesAndAlerts), + logbookMessagesAndAlerts = + LogbookMessagesAndAlertsDataOutput + .fromLogbookMessagesAndAlerts(voyage.logbookMessagesAndAlerts), ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/CorrelationInterceptor.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/CorrelationInterceptor.kt index 3bd3277639..e82be7cb68 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/CorrelationInterceptor.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/CorrelationInterceptor.kt @@ -15,7 +15,11 @@ class CorrelationInterceptor : HandlerInterceptor { private const val CORRELATION_ID_LOG_VAR_NAME = "correlationId" } - override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean { + override fun preHandle( + request: HttpServletRequest, + response: HttpServletResponse, + handler: Any, + ): Boolean { val correlationId = getCorrelationIdFromHeader(request) MDC.put(CORRELATION_ID_LOG_VAR_NAME, correlationId) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LogGETRequests.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LogGETRequests.kt index 62b580217d..f1de805b8f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LogGETRequests.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LogGETRequests.kt @@ -10,7 +10,11 @@ import org.springframework.web.servlet.HandlerInterceptor class LogGETRequests(val mapper: ObjectMapper) : HandlerInterceptor { private val logger = LoggerFactory.getLogger(LogGETRequests::class.java) - override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean { + override fun preHandle( + request: HttpServletRequest, + response: HttpServletResponse, + handler: Any, + ): Boolean { if (request.method == GET.name()) { val requestLog = LoggingFormatter.formatRequest(mapper, request) requestLog?.let { logger.info(it) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LogResponseWithBody.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LogResponseWithBody.kt index bda5c1ffcb..f9f569b3ca 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LogResponseWithBody.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LogResponseWithBody.kt @@ -18,7 +18,10 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice class LogResponseWithBody(val mapper: ObjectMapper) : ResponseBodyAdvice { private val logger = LoggerFactory.getLogger(LogGETRequests::class.java) - override fun supports(returnType: MethodParameter, converterType: Class>): Boolean { + override fun supports( + returnType: MethodParameter, + converterType: Class>, + ): Boolean { return true } @@ -31,12 +34,13 @@ class LogResponseWithBody(val mapper: ObjectMapper) : ResponseBodyAdvice { response: ServerHttpResponse, ): Any? { if (request.method == PUT || request.method == POST) { - val requestLog = LoggingFormatter.formatResponse( - mapper, - (request as ServletServerHttpRequest).servletRequest, - (response as ServletServerHttpResponse).servletResponse, - body, - ) + val requestLog = + LoggingFormatter.formatResponse( + mapper, + (request as ServletServerHttpRequest).servletRequest, + (response as ServletServerHttpResponse).servletResponse, + body, + ) logger.info(requestLog) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LoggingFormatter.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LoggingFormatter.kt index 89bd6a516b..94a5f19822 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LoggingFormatter.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/log/LoggingFormatter.kt @@ -7,7 +7,11 @@ import java.util.* class LoggingFormatter { companion object { - fun formatRequest(mapper: ObjectMapper, httpServletRequest: HttpServletRequest?, body: Any? = null): String? { + fun formatRequest( + mapper: ObjectMapper, + httpServletRequest: HttpServletRequest?, + body: Any? = null, + ): String? { if (httpServletRequest == null) { return null } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportDataOutput.kt index 64b4842291..64c9e3c369 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportDataOutput.kt @@ -14,14 +14,15 @@ data class ActivityReportDataOutput( val vessel: VesselDataOutput, ) { companion object { - fun fromActivityReport(activityReport: ActivityReport) = ActivityReportDataOutput( - action = MissionActionDataOutput.fromMissionAction(activityReport.action), - activityCode = activityReport.activityCode, - faoArea = activityReport.faoArea, - segment = activityReport.segment, - vesselNationalIdentifier = activityReport.vesselNationalIdentifier, - controlUnits = activityReport.controlUnits, - vessel = VesselDataOutput.fromVessel(activityReport.vessel), - ) + fun fromActivityReport(activityReport: ActivityReport) = + ActivityReportDataOutput( + action = MissionActionDataOutput.fromMissionAction(activityReport.action), + activityCode = activityReport.activityCode, + faoArea = activityReport.faoArea, + segment = activityReport.segment, + vesselNationalIdentifier = activityReport.vesselNationalIdentifier, + controlUnits = activityReport.controlUnits, + vessel = VesselDataOutput.fromVessel(activityReport.vessel), + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportsDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportsDataOutput.kt index 705faa3dce..2245ca8b38 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportsDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ActivityReportsDataOutput.kt @@ -7,9 +7,15 @@ data class ActivityReportsDataOutput( val jdpSpecies: List, ) { companion object { - fun fromActivityReports(activityReports: ActivityReports) = ActivityReportsDataOutput( - activityReports = activityReports.activityReports.map { ActivityReportDataOutput.fromActivityReport(it) }, - jdpSpecies = activityReports.jdpSpecies, - ) + fun fromActivityReports(activityReports: ActivityReports) = + ActivityReportsDataOutput( + activityReports = + activityReports.activityReports.map { + ActivityReportDataOutput.fromActivityReport( + it, + ) + }, + jdpSpecies = activityReports.jdpSpecies, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/AlertDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/AlertDataOutput.kt index c444b74497..e3acca96f8 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/AlertDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/AlertDataOutput.kt @@ -10,11 +10,12 @@ class AlertDataOutput( val natinfCode: Int? = null, ) : ReportingValueDataOutput() { companion object { - fun fromAlertType(alertType: AlertType) = AlertDataOutput( - type = alertType.type, - seaFront = alertType.seaFront, - dml = alertType.dml, - natinfCode = alertType.natinfCode, - ) + fun fromAlertType(alertType: AlertType) = + AlertDataOutput( + type = alertType.type, + seaFront = alertType.seaFront, + dml = alertType.dml, + natinfCode = alertType.natinfCode, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionNotificationDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionNotificationDataOutput.kt index 97b1e1e578..d6a2ddf88a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionNotificationDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionNotificationDataOutput.kt @@ -17,7 +17,6 @@ data class BeaconMalfunctionNotificationDataOutput( val success: Boolean?, val errorMessage: String?, ) { - companion object { fun fromBeaconMalfunctionNotification( beaconMalfunctionNotification: BeaconMalfunctionNotification, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionNotificationsDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionNotificationsDataOutput.kt index 8d32327844..f6177191f9 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionNotificationsDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionNotificationsDataOutput.kt @@ -18,8 +18,9 @@ data class BeaconMalfunctionNotificationsDataOutput( beaconMalfunctionId = beaconMalfunctionNotifications.beaconMalfunctionId, dateTime = beaconMalfunctionNotifications.dateTimeUtc, notificationType = beaconMalfunctionNotifications.notificationType, - notifications = beaconMalfunctionNotifications.notifications - .map { BeaconMalfunctionNotificationDataOutput.fromBeaconMalfunctionNotification(it) }, + notifications = + beaconMalfunctionNotifications.notifications + .map { BeaconMalfunctionNotificationDataOutput.fromBeaconMalfunctionNotification(it) }, ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionResumeAndDetailsDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionResumeAndDetailsDataOutput.kt index 3da78d2878..66cc3511db 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionResumeAndDetailsDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionResumeAndDetailsDataOutput.kt @@ -14,29 +14,34 @@ data class BeaconMalfunctionResumeAndDetailsDataOutput( beaconMalfunctionResumeAndDetails: BeaconMalfunctionResumeAndDetails, ): BeaconMalfunctionResumeAndDetailsDataOutput { return BeaconMalfunctionResumeAndDetailsDataOutput( - beaconMalfunction = BeaconMalfunctionDataOutput.fromBeaconMalfunction( - beaconMalfunctionResumeAndDetails.beaconMalfunction, - ), - resume = beaconMalfunctionResumeAndDetails.resume?.let { - VesselBeaconMalfunctionResumeDataOutput.fromVesselBeaconMalfunctionResume( - beaconMalfunctionResumeAndDetails.resume, - ) - }, - comments = beaconMalfunctionResumeAndDetails.comments.map { - BeaconMalfunctionCommentDataOutput.fromBeaconMalfunctionComment( - it, - ) - }, - actions = beaconMalfunctionResumeAndDetails.actions.map { - BeaconMalfunctionActionDataOutput.fromBeaconMalfunctionAction( - it, - ) - }, - notifications = beaconMalfunctionResumeAndDetails.notifications.map { - BeaconMalfunctionNotificationsDataOutput.fromBeaconMalfunctionNotifications( - it, - ) - }, + beaconMalfunction = + BeaconMalfunctionDataOutput.fromBeaconMalfunction( + beaconMalfunctionResumeAndDetails.beaconMalfunction, + ), + resume = + beaconMalfunctionResumeAndDetails.resume?.let { + VesselBeaconMalfunctionResumeDataOutput.fromVesselBeaconMalfunctionResume( + beaconMalfunctionResumeAndDetails.resume, + ) + }, + comments = + beaconMalfunctionResumeAndDetails.comments.map { + BeaconMalfunctionCommentDataOutput.fromBeaconMalfunctionComment( + it, + ) + }, + actions = + beaconMalfunctionResumeAndDetails.actions.map { + BeaconMalfunctionActionDataOutput.fromBeaconMalfunctionAction( + it, + ) + }, + notifications = + beaconMalfunctionResumeAndDetails.notifications.map { + BeaconMalfunctionNotificationsDataOutput.fromBeaconMalfunctionNotifications( + it, + ) + }, ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionWithDetailsDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionWithDetailsDataOutput.kt index 3beb0df78b..2deeed4740 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionWithDetailsDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionWithDetailsDataOutput.kt @@ -12,19 +12,22 @@ data class BeaconMalfunctionWithDetailsDataOutput( beaconMalfunctionWithDetails: BeaconMalfunctionWithDetails, ): BeaconMalfunctionWithDetailsDataOutput { return BeaconMalfunctionWithDetailsDataOutput( - beaconMalfunction = BeaconMalfunctionDataOutput.fromBeaconMalfunction( - beaconMalfunctionWithDetails.beaconMalfunction, - ), - comments = beaconMalfunctionWithDetails.comments.map { - BeaconMalfunctionCommentDataOutput.fromBeaconMalfunctionComment( - it, - ) - }, - actions = beaconMalfunctionWithDetails.actions.map { - BeaconMalfunctionActionDataOutput.fromBeaconMalfunctionAction( - it, - ) - }, + beaconMalfunction = + BeaconMalfunctionDataOutput.fromBeaconMalfunction( + beaconMalfunctionWithDetails.beaconMalfunction, + ), + comments = + beaconMalfunctionWithDetails.comments.map { + BeaconMalfunctionCommentDataOutput.fromBeaconMalfunctionComment( + it, + ) + }, + actions = + beaconMalfunctionWithDetails.actions.map { + BeaconMalfunctionActionDataOutput.fromBeaconMalfunctionAction( + it, + ) + }, ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionsResumeAndHistoryDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionsResumeAndHistoryDataOutput.kt index 496bede2dd..b4957015dc 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionsResumeAndHistoryDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/BeaconMalfunctionsResumeAndHistoryDataOutput.kt @@ -11,19 +11,22 @@ data class BeaconMalfunctionsResumeAndHistoryDataOutput( fun fromBeaconMalfunctionsResumeAndHistory( vesselBeaconMalfunctionsResumeAndHistory: VesselBeaconMalfunctionsResumeAndHistory, ) = BeaconMalfunctionsResumeAndHistoryDataOutput( - resume = VesselBeaconMalfunctionResumeDataOutput.fromVesselBeaconMalfunctionResume( - vesselBeaconMalfunctionsResumeAndHistory.resume, - ), - current = vesselBeaconMalfunctionsResumeAndHistory.current?.let { - BeaconMalfunctionWithDetailsDataOutput.fromBeaconMalfunctionWithDetails( - vesselBeaconMalfunctionsResumeAndHistory.current, - ) - }, - history = vesselBeaconMalfunctionsResumeAndHistory.history.map { - BeaconMalfunctionWithDetailsDataOutput.fromBeaconMalfunctionWithDetails( - it, - ) - }, + resume = + VesselBeaconMalfunctionResumeDataOutput.fromVesselBeaconMalfunctionResume( + vesselBeaconMalfunctionsResumeAndHistory.resume, + ), + current = + vesselBeaconMalfunctionsResumeAndHistory.current?.let { + BeaconMalfunctionWithDetailsDataOutput.fromBeaconMalfunctionWithDetails( + vesselBeaconMalfunctionsResumeAndHistory.current, + ) + }, + history = + vesselBeaconMalfunctionsResumeAndHistory.history.map { + BeaconMalfunctionWithDetailsDataOutput.fromBeaconMalfunctionWithDetails( + it, + ) + }, ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ControlsSummaryDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ControlsSummaryDataOutput.kt index 3fcba2928c..0ab3441091 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ControlsSummaryDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ControlsSummaryDataOutput.kt @@ -10,12 +10,13 @@ data class ControlsSummaryDataOutput( val controls: List, ) { companion object { - fun fromControlsSummary(controlsSummary: ControlsSummary) = ControlsSummaryDataOutput( - vesselId = controlsSummary.vesselId, - numberOfDiversions = controlsSummary.numberOfDiversions, - numberOfControlsWithSomeGearsSeized = controlsSummary.numberOfControlsWithSomeGearsSeized, - numberOfControlsWithSomeSpeciesSeized = controlsSummary.numberOfControlsWithSomeSpeciesSeized, - controls = controlsSummary.controls.map { MissionActionDataOutput.fromMissionAction(it) }, - ) + fun fromControlsSummary(controlsSummary: ControlsSummary) = + ControlsSummaryDataOutput( + vesselId = controlsSummary.vesselId, + numberOfDiversions = controlsSummary.numberOfDiversions, + numberOfControlsWithSomeGearsSeized = controlsSummary.numberOfControlsWithSomeGearsSeized, + numberOfControlsWithSomeSpeciesSeized = controlsSummary.numberOfControlsWithSomeSpeciesSeized, + controls = controlsSummary.controls.map { MissionActionDataOutput.fromMissionAction(it) }, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/CurrentAndArchivedReportingDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/CurrentAndArchivedReportingDataOutput.kt index d713abca3d..d0e5d0b6bd 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/CurrentAndArchivedReportingDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/CurrentAndArchivedReportingDataOutput.kt @@ -8,17 +8,18 @@ class CurrentAndArchivedReportingDataOutput( val archived: Map>, ) { companion object { - fun fromCurrentAndArchivedReporting( - currentAndArchivedReportings: CurrentAndArchivedReportings, - ) = CurrentAndArchivedReportingDataOutput( - current = currentAndArchivedReportings.current.map { - ReportingAndOccurrencesDataOutput.fromReportingAndOccurrences(it) - }, - archived = currentAndArchivedReportings.archived.mapValues { (_, reportingAndOccurrences) -> - reportingAndOccurrences.map { - ReportingAndOccurrencesDataOutput.fromReportingAndOccurrences(it) - } - }, - ) + fun fromCurrentAndArchivedReporting(currentAndArchivedReportings: CurrentAndArchivedReportings) = + CurrentAndArchivedReportingDataOutput( + current = + currentAndArchivedReportings.current.map { + ReportingAndOccurrencesDataOutput.fromReportingAndOccurrences(it) + }, + archived = + currentAndArchivedReportings.archived.mapValues { (_, reportingAndOccurrences) -> + reportingAndOccurrences.map { + ReportingAndOccurrencesDataOutput.fromReportingAndOccurrences(it) + } + }, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/EnvMissionActionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/EnvMissionActionDataOutput.kt index f7c82b0159..f9f661e77a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/EnvMissionActionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/EnvMissionActionDataOutput.kt @@ -12,11 +12,12 @@ data class EnvMissionActionDataOutput( val observations: String? = null, ) { companion object { - fun fromEnvMissionAction(envMissionAction: EnvMissionAction) = EnvMissionActionDataOutput( - id = envMissionAction.id, - actionStartDateTimeUtc = envMissionAction.actionStartDateTimeUtc, - actionType = envMissionAction.actionType, - observations = envMissionAction.observations, - ) + fun fromEnvMissionAction(envMissionAction: EnvMissionAction) = + EnvMissionActionDataOutput( + id = envMissionAction.id, + actionStartDateTimeUtc = envMissionAction.actionStartDateTimeUtc, + actionType = envMissionAction.actionType, + observations = envMissionAction.observations, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ForeignFMCDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ForeignFMCDataOutput.kt index aff0ed57bb..beb73aadb4 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ForeignFMCDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ForeignFMCDataOutput.kt @@ -8,10 +8,11 @@ data class ForeignFMCDataOutput( var emailAddresses: List? = null, ) { companion object { - fun fromForeignFMC(foreignFMC: ForeignFMC) = ForeignFMCDataOutput( - countryCodeIso3 = foreignFMC.countryCodeIso3, - countryName = foreignFMC.countryName, - emailAddresses = foreignFMC.emailAddresses, - ) + fun fromForeignFMC(foreignFMC: ForeignFMC) = + ForeignFMCDataOutput( + countryCodeIso3 = foreignFMC.countryCodeIso3, + countryName = foreignFMC.countryName, + emailAddresses = foreignFMC.emailAddresses, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearControlDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearControlDataOutput.kt index dad16220e3..9cc6d89062 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearControlDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearControlDataOutput.kt @@ -11,13 +11,14 @@ data class GearControlDataOutput( var gearWasControlled: Boolean? = null, ) { companion object { - fun fromGearControl(gearControl: GearControl) = GearControlDataOutput( - gearCode = gearControl.gearCode, - gearName = gearControl.gearName, - declaredMesh = gearControl.declaredMesh, - controlledMesh = gearControl.controlledMesh, - hasUncontrolledMesh = gearControl.hasUncontrolledMesh, - gearWasControlled = gearControl.gearWasControlled, - ) + fun fromGearControl(gearControl: GearControl) = + GearControlDataOutput( + gearCode = gearControl.gearCode, + gearName = gearControl.gearName, + declaredMesh = gearControl.declaredMesh, + controlledMesh = gearControl.controlledMesh, + hasUncontrolledMesh = gearControl.hasUncontrolledMesh, + gearWasControlled = gearControl.gearWasControlled, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearLastPositionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearLastPositionDataOutput.kt index 60338b4bee..5f7fc2db66 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearLastPositionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/GearLastPositionDataOutput.kt @@ -8,10 +8,11 @@ data class GearLastPositionDataOutput( var mesh: Double? = null, ) { companion object { - fun fromGearLastPosition(gear: Gear) = GearLastPositionDataOutput( - gear = gear.gear, - dimensions = gear.dimensions, - mesh = gear.mesh, - ) + fun fromGearLastPosition(gear: Gear) = + GearLastPositionDataOutput( + gear = gear.gear, + dimensions = gear.dimensions, + mesh = gear.mesh, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/HealthDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/HealthDataOutput.kt index 91575bd741..c8a2b6f211 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/HealthDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/HealthDataOutput.kt @@ -10,11 +10,12 @@ data class HealthDataOutput( val suddenDropOfPositionsReceived: Boolean, ) { companion object { - fun fromHealth(health: Health) = HealthDataOutput( - dateLastPositionUpdatedByPrefect = health.dateLastPositionUpdatedByPrefect, - dateLastPositionReceivedByAPI = health.dateLastPositionReceivedByAPI, - dateLogbookMessageReceived = health.dateLogbookMessageReceived, - suddenDropOfPositionsReceived = health.suddenDropOfPositionsReceived, - ) + fun fromHealth(health: Health) = + HealthDataOutput( + dateLastPositionUpdatedByPrefect = health.dateLastPositionUpdatedByPrefect, + dateLastPositionReceivedByAPI = health.dateLastPositionReceivedByAPI, + dateLogbookMessageReceived = health.dateLogbookMessageReceived, + suddenDropOfPositionsReceived = health.suddenDropOfPositionsReceived, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/InfractionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/InfractionDataOutput.kt index fd91e93294..3c5217c5f9 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/InfractionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/InfractionDataOutput.kt @@ -9,11 +9,12 @@ data class InfractionDataOutput( var infraction: String? = null, ) { companion object { - fun fromInfraction(infraction: Infraction) = InfractionDataOutput( - natinfCode = infraction.natinfCode, - regulation = infraction.regulation, - infractionCategory = infraction.infractionCategory.toString(), - infraction = infraction.infraction, - ) + fun fromInfraction(infraction: Infraction) = + InfractionDataOutput( + natinfCode = infraction.natinfCode, + regulation = infraction.regulation, + infractionCategory = infraction.infractionCategory.toString(), + infraction = infraction.infraction, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LastPositionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LastPositionDataOutput.kt index 46cb9e3682..52e56145fa 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LastPositionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LastPositionDataOutput.kt @@ -79,11 +79,12 @@ data class LastPositionDataOutput( districtCode = position.districtCode, gearOnboard = position.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) }, segments = position.segments, - speciesOnboard = position.speciesOnboard?.map { - SpeciesLastPositionDataOutput.fromSpeciesLastPosition( - it, - ) - }, + speciesOnboard = + position.speciesOnboard?.map { + SpeciesLastPositionDataOutput.fromSpeciesLastPosition( + it, + ) + }, totalWeightOnboard = position.totalWeightOnboard, lastControlDateTime = position.lastControlDateTime, lastControlInfraction = position.lastControlInfraction, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageDataOutput.kt index 32f8e0ce0a..009a5c6d38 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessageDataOutput.kt @@ -21,7 +21,6 @@ data class LogbookMessageDataOutput( val flagState: String?, val imo: String?, val rawMessage: String?, - val acknowledgment: Acknowledgment?, val isCorrectedByNewerMessage: Boolean, val isDeleted: Boolean, @@ -34,12 +33,14 @@ data class LogbookMessageDataOutput( ) { companion object { fun fromLogbookMessage(logbookMessage: LogbookMessage): LogbookMessageDataOutput { - val tripGears = logbookMessage.tripGears?.mapNotNull { - LogbookMessageGearDataOutput.fromGear(it) - } - val tripSegments = logbookMessage.tripSegments?.map { - LogbookMessageTripSegmentDataOutput.fromLogbookTripSegment(it) - } + val tripGears = + logbookMessage.tripGears?.mapNotNull { + LogbookMessageGearDataOutput.fromGear(it) + } + val tripSegments = + logbookMessage.tripSegments?.map { + LogbookMessageTripSegmentDataOutput.fromLogbookTripSegment(it) + } return LogbookMessageDataOutput( internalReferenceNumber = logbookMessage.internalReferenceNumber, @@ -56,7 +57,6 @@ data class LogbookMessageDataOutput( flagState = logbookMessage.flagState, imo = logbookMessage.imo, rawMessage = logbookMessage.rawMessage, - acknowledgment = logbookMessage.acknowledgment, isCorrectedByNewerMessage = logbookMessage.isCorrectedByNewerMessage, isDeleted = logbookMessage.isDeleted, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessagesAndAlertsDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessagesAndAlertsDataOutput.kt index 3bcb499824..ed83a7e1a7 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessagesAndAlertsDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/LogbookMessagesAndAlertsDataOutput.kt @@ -8,11 +8,10 @@ data class LogbookMessagesAndAlertsDataOutput( val alerts: List, ) { companion object { - fun fromLogbookMessagesAndAlerts( - logbookMessagesAndAlerts: LogbookMessagesAndAlerts, - ) = LogbookMessagesAndAlertsDataOutput( - logbookMessagesAndAlerts.logbookMessages.map { LogbookMessageDataOutput.fromLogbookMessage(it) }, - logbookMessagesAndAlerts.alerts, - ) + fun fromLogbookMessagesAndAlerts(logbookMessagesAndAlerts: LogbookMessagesAndAlerts) = + LogbookMessagesAndAlertsDataOutput( + logbookMessagesAndAlerts.logbookMessages.map { LogbookMessageDataOutput.fromLogbookMessage(it) }, + logbookMessagesAndAlerts.alerts, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationComputedValuesDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationComputedValuesDataOutput.kt index 1846a8a2d4..dba3e7229b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationComputedValuesDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationComputedValuesDataOutput.kt @@ -18,10 +18,12 @@ data class ManualPriorNotificationComputedValuesDataOutput( fun fromManualPriorNotificationComputedValues( manualPriorNotificationComputedValues: ManualPriorNotificationComputedValues, ): ManualPriorNotificationComputedValuesDataOutput { - val tripSegmentDataOutputs = manualPriorNotificationComputedValues.tripSegments - .map { LogbookMessageTripSegmentDataOutput.fromFleetSegment(it) } - val priorNotificationTypeDataOutputs = manualPriorNotificationComputedValues.types - .map { PriorNotificationTypeDataOutput.fromPnoType(it) } + val tripSegmentDataOutputs = + manualPriorNotificationComputedValues.tripSegments + .map { LogbookMessageTripSegmentDataOutput.fromFleetSegment(it) } + val priorNotificationTypeDataOutputs = + manualPriorNotificationComputedValues.types + .map { PriorNotificationTypeDataOutput.fromPnoType(it) } return ManualPriorNotificationComputedValuesDataOutput( nextState = manualPriorNotificationComputedValues.nextState, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationDraftDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationDraftDataOutput.kt index 6aa50bd359..48d362f06d 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationDraftDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationDraftDataOutput.kt @@ -29,15 +29,18 @@ data class ManualPriorNotificationDraftDataOutput( val logbookMessage = priorNotification.logbookMessageAndValue.logbookMessage val pnoValue = priorNotification.logbookMessageAndValue.value - val expectedArrivalDate = pnoValue.predictedArrivalDatetimeUtc - ?.let { CustomZonedDateTime.fromZonedDateTime(it).toString() } - val expectedLandingDate = pnoValue.predictedLandingDatetimeUtc - ?.let { CustomZonedDateTime.fromZonedDateTime(it).toString() } - val tripGearCodes = logbookMessage.tripGears - ?.let { tripGears -> - tripGears - .map { tripGear -> requireNotNull(tripGear.gear) { "`it.gear` is null." } } - } ?: emptyList() + val expectedArrivalDate = + pnoValue.predictedArrivalDatetimeUtc + ?.let { CustomZonedDateTime.fromZonedDateTime(it).toString() } + val expectedLandingDate = + pnoValue.predictedLandingDatetimeUtc + ?.let { CustomZonedDateTime.fromZonedDateTime(it).toString() } + val tripGearCodes = + logbookMessage.tripGears + ?.let { tripGears -> + tripGears + .map { tripGear -> requireNotNull(tripGear.gear) { "`it.gear` is null." } } + } ?: emptyList() val hasPortEntranceAuthorization = pnoValue.hasPortEntranceAuthorization ?: true val hasPortLandingAuthorization = pnoValue.hasPortLandingAuthorization ?: true @@ -47,14 +50,16 @@ data class ManualPriorNotificationDraftDataOutput( // while in Backend, we always have an FAO area field per fishing catch. // So we need to check if all fishing catches have the same FAO area to know which case we are in. val hasGlobalFaoArea = pnoValue.catchOnboard.mapNotNull { it.faoZone }.distinct().size == 1 - val globalFaoArea = if (hasGlobalFaoArea) { - pnoValue.catchOnboard.first().faoZone - } else { - null - } - val fishingCatchDataOutputs = pnoValue.catchOnboard.map { - ManualPriorNotificationFishingCatchDataOutput.fromLogbookFishingCatch(it, !hasGlobalFaoArea) - } + val globalFaoArea = + if (hasGlobalFaoArea) { + pnoValue.catchOnboard.first().faoZone + } else { + null + } + val fishingCatchDataOutputs = + pnoValue.catchOnboard.map { + ManualPriorNotificationFishingCatchDataOutput.fromLogbookFishingCatch(it, !hasGlobalFaoArea) + } return ManualPriorNotificationDraftDataOutput( authorTrigram = pnoValue.authorTrigram, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationFishingCatchDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationFishingCatchDataOutput.kt index 18a45afb10..b9f85831d9 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationFishingCatchDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationFishingCatchDataOutput.kt @@ -15,15 +15,18 @@ data class ManualPriorNotificationFishingCatchDataOutput( withFaoArea: Boolean, ): ManualPriorNotificationFishingCatchDataOutput { val faoArea = if (withFaoArea) logbookFishingCatch.faoZone else null - val specyCode = requireNotNull(logbookFishingCatch.species) { - "`logbookFishingCatch.species` is null." - } - val specyName = requireNotNull(logbookFishingCatch.speciesName) { - "`logbookFishingCatch.speciesName` is null." - } - val weight = requireNotNull(logbookFishingCatch.weight) { - "`logbookFishingCatch.weight` is null." - } + val specyCode = + requireNotNull(logbookFishingCatch.species) { + "`logbookFishingCatch.species` is null." + } + val specyName = + requireNotNull(logbookFishingCatch.speciesName) { + "`logbookFishingCatch.speciesName` is null." + } + val weight = + requireNotNull(logbookFishingCatch.weight) { + "`logbookFishingCatch.weight` is null." + } return ManualPriorNotificationFishingCatchDataOutput( faoArea, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationFormDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationFormDataOutput.kt index b716760485..fb5718aae5 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationFormDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ManualPriorNotificationFormDataOutput.kt @@ -29,33 +29,40 @@ data class ManualPriorNotificationFormDataOutput( val logbookMessage = priorNotification.logbookMessageAndValue.logbookMessage val pnoValue = priorNotification.logbookMessageAndValue.value - val authorTrigram = requireNotNull(pnoValue.authorTrigram) { - "`pnoValue.authorTrigram` is null." - } - val expectedArrivalDate = CustomZonedDateTime.fromZonedDateTime( - requireNotNull(pnoValue.predictedArrivalDatetimeUtc) { - "`message.predictedArrivalDatetimeUtc` is null." - }, - ).toString() - val expectedLandingDate = CustomZonedDateTime.fromZonedDateTime( - requireNotNull(pnoValue.predictedLandingDatetimeUtc) { - "`message.predictedLandingDatetimeUtc` is null." - }, - ).toString() + val authorTrigram = + requireNotNull(pnoValue.authorTrigram) { + "`pnoValue.authorTrigram` is null." + } + val expectedArrivalDate = + CustomZonedDateTime.fromZonedDateTime( + requireNotNull(pnoValue.predictedArrivalDatetimeUtc) { + "`message.predictedArrivalDatetimeUtc` is null." + }, + ).toString() + val expectedLandingDate = + CustomZonedDateTime.fromZonedDateTime( + requireNotNull(pnoValue.predictedLandingDatetimeUtc) { + "`message.predictedLandingDatetimeUtc` is null." + }, + ).toString() val portLocode = requireNotNull(pnoValue.port) { "`pnoValue.port` is null." } val purpose = requireNotNull(pnoValue.purpose) { "`pnoValue.purpose` is null." } val reportId = requireNotNull(priorNotification.reportId) { "`priorNotification.reportId` is null." } val sentAt = requireNotNull(priorNotification.sentAt) { "`priorNotification.sentAt` is null." } - val tripGearCodes = requireNotNull(logbookMessage.tripGears) { - "`logbookMessage.tripGears` is null." - }.map { requireNotNull(it.gear) { "`it.gear` is null." } } + val tripGearCodes = + requireNotNull(logbookMessage.tripGears) { + "`logbookMessage.tripGears` is null." + }.map { requireNotNull(it.gear) { "`it.gear` is null." } } val updatedAt = - requireNotNull(priorNotification.updatedAt) { "`priorNotification.updatedAt` is null." }.withZoneSameInstant( + requireNotNull( + priorNotification.updatedAt, + ) { "`priorNotification.updatedAt` is null." }.withZoneSameInstant( ZoneOffset.UTC, ).toString() - val vesselId = requireNotNull(priorNotification.vessel) { - "`priorNotification.vessel` is null." - }.id + val vesselId = + requireNotNull(priorNotification.vessel) { + "`priorNotification.vessel` is null." + }.id val hasPortEntranceAuthorization = pnoValue.hasPortEntranceAuthorization ?: true val hasPortLandingAuthorization = pnoValue.hasPortLandingAuthorization ?: true @@ -65,14 +72,16 @@ data class ManualPriorNotificationFormDataOutput( // while in Backend, we always have an FAO area field per fishing catch. // So we need to check if all fishing catches have the same FAO area to know which case we are in. val hasGlobalFaoArea = pnoValue.catchOnboard.mapNotNull { it.faoZone }.distinct().size == 1 - val globalFaoArea = if (hasGlobalFaoArea) { - pnoValue.catchOnboard.first().faoZone - } else { - null - } - val fishingCatchDataOutputs = pnoValue.catchOnboard.map { - ManualPriorNotificationFishingCatchDataOutput.fromLogbookFishingCatch(it, !hasGlobalFaoArea) - } + val globalFaoArea = + if (hasGlobalFaoArea) { + pnoValue.catchOnboard.first().faoZone + } else { + null + } + val fishingCatchDataOutputs = + pnoValue.catchOnboard.map { + ManualPriorNotificationFishingCatchDataOutput.fromLogbookFishingCatch(it, !hasGlobalFaoArea) + } return ManualPriorNotificationFormDataOutput( reportId = reportId, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt index 176f165e61..b99a16dfa9 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionActionDataOutput.kt @@ -65,63 +65,64 @@ data class MissionActionDataOutput( val observationsByUnit: String? = null, ) { companion object { - fun fromMissionAction(missionAction: MissionAction) = MissionActionDataOutput( - id = missionAction.id, - vesselId = missionAction.vesselId, - vesselName = missionAction.vesselName, - internalReferenceNumber = missionAction.internalReferenceNumber, - externalReferenceNumber = missionAction.externalReferenceNumber, - ircs = missionAction.ircs, - flagState = missionAction.flagState, - districtCode = missionAction.districtCode, - faoAreas = missionAction.faoAreas, - flightGoals = missionAction.flightGoals, - missionId = missionAction.missionId, - actionType = missionAction.actionType, - actionDatetimeUtc = missionAction.actionDatetimeUtc, - actionEndDatetimeUtc = missionAction.actionEndDatetimeUtc, - emitsVms = missionAction.emitsVms, - emitsAis = missionAction.emitsAis, - logbookMatchesActivity = missionAction.logbookMatchesActivity, - licencesMatchActivity = missionAction.licencesMatchActivity, - speciesWeightControlled = missionAction.speciesWeightControlled, - speciesSizeControlled = missionAction.speciesSizeControlled, - separateStowageOfPreservedSpecies = missionAction.separateStowageOfPreservedSpecies, - logbookInfractions = missionAction.logbookInfractions, - licencesAndLogbookObservations = missionAction.licencesAndLogbookObservations, - gearInfractions = missionAction.gearInfractions, - speciesInfractions = missionAction.speciesInfractions, - speciesObservations = missionAction.speciesObservations, - seizureAndDiversion = missionAction.seizureAndDiversion, - otherInfractions = missionAction.otherInfractions, - numberOfVesselsFlownOver = missionAction.numberOfVesselsFlownOver, - unitWithoutOmegaGauge = missionAction.unitWithoutOmegaGauge, - controlQualityComments = missionAction.controlQualityComments, - feedbackSheetRequired = missionAction.feedbackSheetRequired, - segments = missionAction.segments, - facade = missionAction.facade, - longitude = missionAction.longitude, - latitude = missionAction.latitude, - portLocode = missionAction.portLocode, - portName = missionAction.portName, - seizureAndDiversionComments = missionAction.seizureAndDiversionComments, - otherComments = missionAction.otherComments, - gearOnboard = missionAction.gearOnboard, - speciesOnboard = missionAction.speciesOnboard, - controlUnits = missionAction.controlUnits, - userTrigram = missionAction.userTrigram, - vesselTargeted = missionAction.vesselTargeted, - hasSomeGearsSeized = missionAction.hasSomeGearsSeized, - hasSomeSpeciesSeized = missionAction.hasSomeSpeciesSeized, - speciesQuantitySeized = missionAction.speciesQuantitySeized, - completedBy = missionAction.completedBy, - completion = missionAction.completion, - isFromPoseidon = missionAction.isFromPoseidon, - isAdministrativeControl = missionAction.isAdministrativeControl, - isComplianceWithWaterRegulationsControl = missionAction.isComplianceWithWaterRegulationsControl, - isSafetyEquipmentAndStandardsComplianceControl = missionAction.isSafetyEquipmentAndStandardsComplianceControl, - isSeafarersControl = missionAction.isSeafarersControl, - observationsByUnit = missionAction.observationsByUnit, - ) + fun fromMissionAction(missionAction: MissionAction) = + MissionActionDataOutput( + id = missionAction.id, + vesselId = missionAction.vesselId, + vesselName = missionAction.vesselName, + internalReferenceNumber = missionAction.internalReferenceNumber, + externalReferenceNumber = missionAction.externalReferenceNumber, + ircs = missionAction.ircs, + flagState = missionAction.flagState, + districtCode = missionAction.districtCode, + faoAreas = missionAction.faoAreas, + flightGoals = missionAction.flightGoals, + missionId = missionAction.missionId, + actionType = missionAction.actionType, + actionDatetimeUtc = missionAction.actionDatetimeUtc, + actionEndDatetimeUtc = missionAction.actionEndDatetimeUtc, + emitsVms = missionAction.emitsVms, + emitsAis = missionAction.emitsAis, + logbookMatchesActivity = missionAction.logbookMatchesActivity, + licencesMatchActivity = missionAction.licencesMatchActivity, + speciesWeightControlled = missionAction.speciesWeightControlled, + speciesSizeControlled = missionAction.speciesSizeControlled, + separateStowageOfPreservedSpecies = missionAction.separateStowageOfPreservedSpecies, + logbookInfractions = missionAction.logbookInfractions, + licencesAndLogbookObservations = missionAction.licencesAndLogbookObservations, + gearInfractions = missionAction.gearInfractions, + speciesInfractions = missionAction.speciesInfractions, + speciesObservations = missionAction.speciesObservations, + seizureAndDiversion = missionAction.seizureAndDiversion, + otherInfractions = missionAction.otherInfractions, + numberOfVesselsFlownOver = missionAction.numberOfVesselsFlownOver, + unitWithoutOmegaGauge = missionAction.unitWithoutOmegaGauge, + controlQualityComments = missionAction.controlQualityComments, + feedbackSheetRequired = missionAction.feedbackSheetRequired, + segments = missionAction.segments, + facade = missionAction.facade, + longitude = missionAction.longitude, + latitude = missionAction.latitude, + portLocode = missionAction.portLocode, + portName = missionAction.portName, + seizureAndDiversionComments = missionAction.seizureAndDiversionComments, + otherComments = missionAction.otherComments, + gearOnboard = missionAction.gearOnboard, + speciesOnboard = missionAction.speciesOnboard, + controlUnits = missionAction.controlUnits, + userTrigram = missionAction.userTrigram, + vesselTargeted = missionAction.vesselTargeted, + hasSomeGearsSeized = missionAction.hasSomeGearsSeized, + hasSomeSpeciesSeized = missionAction.hasSomeSpeciesSeized, + speciesQuantitySeized = missionAction.speciesQuantitySeized, + completedBy = missionAction.completedBy, + completion = missionAction.completion, + isFromPoseidon = missionAction.isFromPoseidon, + isAdministrativeControl = missionAction.isAdministrativeControl, + isComplianceWithWaterRegulationsControl = missionAction.isComplianceWithWaterRegulationsControl, + isSafetyEquipmentAndStandardsComplianceControl = missionAction.isSafetyEquipmentAndStandardsComplianceControl, + isSeafarersControl = missionAction.isSeafarersControl, + observationsByUnit = missionAction.observationsByUnit, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionWithActionsDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionWithActionsDataOutput.kt index f5ce3bf568..d80a020641 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionWithActionsDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/MissionWithActionsDataOutput.kt @@ -29,27 +29,29 @@ data class MissionWithActionsDataOutput( val actions: List, ) { companion object { - fun fromMissionAndActions(missionAndActions: MissionAndActions) = MissionWithActionsDataOutput( - id = missionAndActions.mission.id, - missionTypes = missionAndActions.mission.missionTypes, - openBy = missionAndActions.mission.openBy, - completedBy = missionAndActions.mission.completedBy, - observationsCacem = missionAndActions.mission.observationsCacem, - observationsCnsp = missionAndActions.mission.observationsCnsp, - facade = missionAndActions.mission.facade, - geom = missionAndActions.mission.geom, - createdAtUtc = missionAndActions.mission.createdAtUtc, - updatedAtUtc = missionAndActions.mission.updatedAtUtc, - envActions = missionAndActions.mission.envActions - ?.map { EnvMissionActionDataOutput.fromEnvMissionAction(it) } ?: listOf(), - startDateTimeUtc = missionAndActions.mission.startDateTimeUtc, - endDateTimeUtc = missionAndActions.mission.endDateTimeUtc, - isGeometryComputedFromControls = missionAndActions.mission.isGeometryComputedFromControls, - missionSource = missionAndActions.mission.missionSource, - hasMissionOrder = missionAndActions.mission.hasMissionOrder, - isUnderJdp = missionAndActions.mission.isUnderJdp, - controlUnits = missionAndActions.mission.controlUnits, - actions = missionAndActions.actions.map { MissionActionDataOutput.fromMissionAction(it) }, - ) + fun fromMissionAndActions(missionAndActions: MissionAndActions) = + MissionWithActionsDataOutput( + id = missionAndActions.mission.id, + missionTypes = missionAndActions.mission.missionTypes, + openBy = missionAndActions.mission.openBy, + completedBy = missionAndActions.mission.completedBy, + observationsCacem = missionAndActions.mission.observationsCacem, + observationsCnsp = missionAndActions.mission.observationsCnsp, + facade = missionAndActions.mission.facade, + geom = missionAndActions.mission.geom, + createdAtUtc = missionAndActions.mission.createdAtUtc, + updatedAtUtc = missionAndActions.mission.updatedAtUtc, + envActions = + missionAndActions.mission.envActions + ?.map { EnvMissionActionDataOutput.fromEnvMissionAction(it) } ?: listOf(), + startDateTimeUtc = missionAndActions.mission.startDateTimeUtc, + endDateTimeUtc = missionAndActions.mission.endDateTimeUtc, + isGeometryComputedFromControls = missionAndActions.mission.isGeometryComputedFromControls, + missionSource = missionAndActions.mission.missionSource, + hasMissionOrder = missionAndActions.mission.hasMissionOrder, + isUnderJdp = missionAndActions.mission.isUnderJdp, + controlUnits = missionAndActions.mission.controlUnits, + actions = missionAndActions.actions.map { MissionActionDataOutput.fromMissionAction(it) }, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ObservationDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ObservationDataOutput.kt index b561438c49..e8e6049fb7 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ObservationDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ObservationDataOutput.kt @@ -14,7 +14,10 @@ class ObservationDataOutput( val description: String? = null, ) : ReportingValueDataOutput() { companion object { - fun fromObservation(observation: Observation, controlUnit: ControlUnit? = null): ObservationDataOutput { + fun fromObservation( + observation: Observation, + controlUnit: ControlUnit? = null, + ): ObservationDataOutput { return ObservationDataOutput( reportingActor = observation.reportingActor, controlUnitId = observation.controlUnitId, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PendingAlertDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PendingAlertDataOutput.kt index 5de3d82e7e..eb9a64c8b0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PendingAlertDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PendingAlertDataOutput.kt @@ -21,19 +21,20 @@ data class PendingAlertDataOutput( var infraction: InfractionDataOutput? = null, ) { companion object { - fun fromPendingAlert(pendingAlert: PendingAlert) = PendingAlertDataOutput( - id = pendingAlert.id, - vesselId = pendingAlert.vesselId, - vesselName = pendingAlert.vesselName, - internalReferenceNumber = pendingAlert.internalReferenceNumber, - externalReferenceNumber = pendingAlert.externalReferenceNumber, - ircs = pendingAlert.ircs, - vesselIdentifier = pendingAlert.vesselIdentifier, - flagState = pendingAlert.flagState, - creationDate = pendingAlert.creationDate, - tripNumber = pendingAlert.tripNumber, - value = pendingAlert.value, - infraction = pendingAlert.infraction?.let { InfractionDataOutput.fromInfraction(it) }, - ) + fun fromPendingAlert(pendingAlert: PendingAlert) = + PendingAlertDataOutput( + id = pendingAlert.id, + vesselId = pendingAlert.vesselId, + vesselName = pendingAlert.vesselName, + internalReferenceNumber = pendingAlert.internalReferenceNumber, + externalReferenceNumber = pendingAlert.externalReferenceNumber, + ircs = pendingAlert.ircs, + vesselIdentifier = pendingAlert.vesselIdentifier, + flagState = pendingAlert.flagState, + creationDate = pendingAlert.creationDate, + tripNumber = pendingAlert.tripNumber, + value = pendingAlert.value, + infraction = pendingAlert.infraction?.let { InfractionDataOutput.fromInfraction(it) }, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt index e9a167c4ee..a0f28d93b2 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationDataOutput.kt @@ -22,32 +22,38 @@ class PriorNotificationDataOutput( ) { companion object { fun fromPriorNotification(priorNotification: PriorNotification): PriorNotificationDataOutput { - val reportId = requireNotNull(priorNotification.reportId) { - "`reportId` is null." - } + val reportId = + requireNotNull(priorNotification.reportId) { + "`reportId` is null." + } - val asLogbookForm = if (!priorNotification.isManuallyCreated) { - LogbookPriorNotificationFormDataOutput.fromPriorNotification(priorNotification) - } else { - null - } - val asManualDraft = if (!priorNotification.isManuallyCreated) { - ManualPriorNotificationDraftDataOutput.fromPriorNotification(priorNotification) - } else { - null - } - val asManualForm = if (priorNotification.isManuallyCreated) { - ManualPriorNotificationFormDataOutput.fromPriorNotification(priorNotification) - } else { - null - } + val asLogbookForm = + if (!priorNotification.isManuallyCreated) { + LogbookPriorNotificationFormDataOutput.fromPriorNotification(priorNotification) + } else { + null + } + val asManualDraft = + if (!priorNotification.isManuallyCreated) { + ManualPriorNotificationDraftDataOutput.fromPriorNotification(priorNotification) + } else { + null + } + val asManualForm = + if (priorNotification.isManuallyCreated) { + ManualPriorNotificationFormDataOutput.fromPriorNotification(priorNotification) + } else { + null + } - val isLessThanTwelveMetersVessel = requireNotNull(priorNotification.vessel) { - "`priorNotification.vessel` is null." - }.isLessThanTwelveMetersVessel() - val isVesselUnderCharter = requireNotNull(priorNotification.vessel) { - "`priorNotification.vessel` is null." - }.underCharter + val isLessThanTwelveMetersVessel = + requireNotNull(priorNotification.vessel) { + "`priorNotification.vessel` is null." + }.isLessThanTwelveMetersVessel() + val isVesselUnderCharter = + requireNotNull(priorNotification.vessel) { + "`priorNotification.vessel` is null." + }.underCharter val logbookMessage = priorNotification.logbookMessageAndValue.logbookMessage val logbookMessageDataOutput = LogbookMessageDataOutput.fromLogbookMessage(logbookMessage) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationListItemDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationListItemDataOutput.kt index f6c2a6debe..d5c429a45a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationListItemDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/PriorNotificationListItemDataOutput.kt @@ -60,14 +60,17 @@ data class PriorNotificationListItemDataOutput( val message = priorNotification.logbookMessageAndValue.value val acknowledgment = logbookMessage.acknowledgment?.let { AcknowledgmentDataOutput.fromAcknowledgment(it) } - val onBoardCatches = message.catchOnboard - .map { LogbookMessageFishingCatchDataOutput.fromLogbookFishingCatch(it) } - val tripGears = logbookMessage.tripGears?.mapNotNull { - LogbookMessageGearDataOutput.fromGear(it) - } ?: emptyList() - val tripSegments = logbookMessage.tripSegments?.map { - LogbookMessageTripSegmentDataOutput.fromLogbookTripSegment(it) - } ?: emptyList() + val onBoardCatches = + message.catchOnboard + .map { LogbookMessageFishingCatchDataOutput.fromLogbookFishingCatch(it) } + val tripGears = + logbookMessage.tripGears?.mapNotNull { + LogbookMessageGearDataOutput.fromGear(it) + } ?: emptyList() + val tripSegments = + logbookMessage.tripSegments?.map { + LogbookMessageTripSegmentDataOutput.fromLogbookTripSegment(it) + } ?: emptyList() val types = message.pnoTypes.map { PriorNotificationTypeDataOutput.fromPriorNotificationType(it) } val vessel = requireNotNull(priorNotification.vessel) { "`vessel` is null." } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ReportingAndOccurrencesDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ReportingAndOccurrencesDataOutput.kt index 849a6dc02d..2f4723de9c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ReportingAndOccurrencesDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ReportingAndOccurrencesDataOutput.kt @@ -7,15 +7,19 @@ data class ReportingAndOccurrencesDataOutput( val reporting: ReportingDataOutput, ) { companion object { - fun fromReportingAndOccurrences(reportingAndOccurrences: ReportingAndOccurrences): ReportingAndOccurrencesDataOutput { + fun fromReportingAndOccurrences( + reportingAndOccurrences: ReportingAndOccurrences, + ): ReportingAndOccurrencesDataOutput { return ReportingAndOccurrencesDataOutput( - otherOccurrencesOfSameAlert = reportingAndOccurrences.otherOccurrencesOfSameAlert.map { reporting -> - ReportingDataOutput.fromReporting(reporting, reportingAndOccurrences.controlUnit) - }, - reporting = ReportingDataOutput.fromReporting( - reportingAndOccurrences.reporting, - reportingAndOccurrences.controlUnit, - ), + otherOccurrencesOfSameAlert = + reportingAndOccurrences.otherOccurrencesOfSameAlert.map { reporting -> + ReportingDataOutput.fromReporting(reporting, reportingAndOccurrences.controlUnit) + }, + reporting = + ReportingDataOutput.fromReporting( + reportingAndOccurrences.reporting, + reportingAndOccurrences.controlUnit, + ), ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ReportingDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ReportingDataOutput.kt index 1b235f7544..61563581e3 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ReportingDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/ReportingDataOutput.kt @@ -29,17 +29,22 @@ class ReportingDataOutput( val underCharter: Boolean? = null, ) { companion object { - fun fromReporting(reporting: Reporting, controlUnit: ControlUnit?): ReportingDataOutput { - val value = when (reporting.value) { - is InfractionSuspicion -> InfractionSuspicionDataOutput.fromInfractionSuspicion( - reporting.value, - controlUnit, - ) + fun fromReporting( + reporting: Reporting, + controlUnit: ControlUnit?, + ): ReportingDataOutput { + val value = + when (reporting.value) { + is InfractionSuspicion -> + InfractionSuspicionDataOutput.fromInfractionSuspicion( + reporting.value, + controlUnit, + ) - is Observation -> ObservationDataOutput.fromObservation(reporting.value, controlUnit) - is AlertType -> AlertDataOutput.fromAlertType(reporting.value) - else -> throw IllegalArgumentException("Should not happen.") - } + is Observation -> ObservationDataOutput.fromObservation(reporting.value, controlUnit) + is AlertType -> AlertDataOutput.fromAlertType(reporting.value) + else -> throw IllegalArgumentException("Should not happen.") + } return ReportingDataOutput( id = reporting.id, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/RiskFactorDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/RiskFactorDataOutput.kt index 329d8ad0df..03066ec4e2 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/RiskFactorDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/RiskFactorDataOutput.kt @@ -24,29 +24,31 @@ data class RiskFactorDataOutput( val riskFactor: Double, ) { companion object { - fun fromVesselRiskFactor(vesselRiskFactor: VesselRiskFactor) = RiskFactorDataOutput( - gearOnboard = vesselRiskFactor.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) }, - segments = vesselRiskFactor.segments, - segmentHighestImpact = vesselRiskFactor.segmentHighestImpact, - segmentHighestPriority = vesselRiskFactor.segmentHighestPriority, - speciesOnboard = vesselRiskFactor.speciesOnboard?.map { - SpeciesLastPositionDataOutput.fromSpeciesLastPosition( - it, - ) - }, - controlPriorityLevel = vesselRiskFactor.controlPriorityLevel, - controlRateRiskFactor = vesselRiskFactor.controlRateRiskFactor, - numberControlsLastFiveYears = vesselRiskFactor.numberControlsLastFiveYears, - numberControlsLastThreeYears = vesselRiskFactor.numberControlsLastThreeYears, - numberInfractionsLastFiveYears = vesselRiskFactor.numberInfractionsLastFiveYears, - numberGearSeizuresLastFiveYears = vesselRiskFactor.numberGearSeizuresLastFiveYears, - numberSpeciesSeizuresLastFiveYears = vesselRiskFactor.numberSpeciesSeizuresLastFiveYears, - numberVesselSeizuresLastFiveYears = vesselRiskFactor.numberVesselSeizuresLastFiveYears, - lastControlDatetime = vesselRiskFactor.lastControlDatetime, - impactRiskFactor = vesselRiskFactor.impactRiskFactor, - probabilityRiskFactor = vesselRiskFactor.probabilityRiskFactor, - detectabilityRiskFactor = vesselRiskFactor.detectabilityRiskFactor, - riskFactor = vesselRiskFactor.riskFactor, - ) + fun fromVesselRiskFactor(vesselRiskFactor: VesselRiskFactor) = + RiskFactorDataOutput( + gearOnboard = vesselRiskFactor.gearOnboard?.map { GearLastPositionDataOutput.fromGearLastPosition(it) }, + segments = vesselRiskFactor.segments, + segmentHighestImpact = vesselRiskFactor.segmentHighestImpact, + segmentHighestPriority = vesselRiskFactor.segmentHighestPriority, + speciesOnboard = + vesselRiskFactor.speciesOnboard?.map { + SpeciesLastPositionDataOutput.fromSpeciesLastPosition( + it, + ) + }, + controlPriorityLevel = vesselRiskFactor.controlPriorityLevel, + controlRateRiskFactor = vesselRiskFactor.controlRateRiskFactor, + numberControlsLastFiveYears = vesselRiskFactor.numberControlsLastFiveYears, + numberControlsLastThreeYears = vesselRiskFactor.numberControlsLastThreeYears, + numberInfractionsLastFiveYears = vesselRiskFactor.numberInfractionsLastFiveYears, + numberGearSeizuresLastFiveYears = vesselRiskFactor.numberGearSeizuresLastFiveYears, + numberSpeciesSeizuresLastFiveYears = vesselRiskFactor.numberSpeciesSeizuresLastFiveYears, + numberVesselSeizuresLastFiveYears = vesselRiskFactor.numberVesselSeizuresLastFiveYears, + lastControlDatetime = vesselRiskFactor.lastControlDatetime, + impactRiskFactor = vesselRiskFactor.impactRiskFactor, + probabilityRiskFactor = vesselRiskFactor.probabilityRiskFactor, + detectabilityRiskFactor = vesselRiskFactor.detectabilityRiskFactor, + riskFactor = vesselRiskFactor.riskFactor, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/SilencedAlertDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/SilencedAlertDataOutput.kt index f94b56aa14..f26977b765 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/SilencedAlertDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/SilencedAlertDataOutput.kt @@ -19,17 +19,18 @@ class SilencedAlertDataOutput( val value: AlertType, ) { companion object { - fun fromSilencedAlert(silencedAlert: SilencedAlert) = SilencedAlertDataOutput( - id = silencedAlert.id, - vesselId = silencedAlert.vesselId, - vesselName = silencedAlert.vesselName, - internalReferenceNumber = silencedAlert.internalReferenceNumber, - externalReferenceNumber = silencedAlert.externalReferenceNumber, - ircs = silencedAlert.ircs, - vesselIdentifier = silencedAlert.vesselIdentifier, - flagState = silencedAlert.flagState, - silencedBeforeDate = silencedAlert.silencedBeforeDate, - value = silencedAlert.value, - ) + fun fromSilencedAlert(silencedAlert: SilencedAlert) = + SilencedAlertDataOutput( + id = silencedAlert.id, + vesselId = silencedAlert.vesselId, + vesselName = silencedAlert.vesselName, + internalReferenceNumber = silencedAlert.internalReferenceNumber, + externalReferenceNumber = silencedAlert.externalReferenceNumber, + ircs = silencedAlert.ircs, + vesselIdentifier = silencedAlert.vesselIdentifier, + flagState = silencedAlert.flagState, + silencedBeforeDate = silencedAlert.silencedBeforeDate, + value = silencedAlert.value, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/SpeciesLastPositionDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/SpeciesLastPositionDataOutput.kt index ce8eeda31a..267d58d636 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/SpeciesLastPositionDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/SpeciesLastPositionDataOutput.kt @@ -9,11 +9,12 @@ data class SpeciesLastPositionDataOutput( var gear: String? = null, ) { companion object { - fun fromSpeciesLastPosition(species: Species) = SpeciesLastPositionDataOutput( - weight = species.weight, - species = species.species, - faoZone = species.faoZone, - gear = species.gear, - ) + fun fromSpeciesLastPosition(species: Species) = + SpeciesLastPositionDataOutput( + weight = species.weight, + species = species.species, + faoZone = species.faoZone, + gear = species.gear, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VesselAndPositionsDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VesselAndPositionsDataOutput.kt index a9cd06549d..6d52ab732b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VesselAndPositionsDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VesselAndPositionsDataOutput.kt @@ -9,14 +9,16 @@ data class VesselAndPositionsDataOutput( companion object { fun fromVesselInformation(vesselInformation: VesselInformation): VesselAndPositionsDataOutput { return VesselAndPositionsDataOutput( - vessel = VesselDataOutput.fromVesselAndRelatedDatas( - vesselInformation.vessel, - vesselInformation.beacon, - vesselInformation.vesselRiskFactor, - ), - positions = vesselInformation.positions.map { - PositionDataOutput.fromPosition(it) - }, + vessel = + VesselDataOutput.fromVesselAndRelatedDatas( + vesselInformation.vessel, + vesselInformation.beacon, + vesselInformation.vesselRiskFactor, + ), + positions = + vesselInformation.positions.map { + PositionDataOutput.fromPosition(it) + }, ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VesselDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VesselDataOutput.kt index caebc5c1dc..bc0d92ea49 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VesselDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VesselDataOutput.kt @@ -45,7 +45,11 @@ data class VesselDataOutput( val hasVisioCaptures: Boolean? = null, ) { companion object { - fun fromVesselAndRelatedDatas(vessel: Vessel?, beacon: Beacon?, vesselRiskFactor: VesselRiskFactor): VesselDataOutput? { + fun fromVesselAndRelatedDatas( + vessel: Vessel?, + beacon: Beacon?, + vesselRiskFactor: VesselRiskFactor, + ): VesselDataOutput? { if (vessel == null) { return null } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VoyageDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VoyageDataOutput.kt index 132c225071..6d5b16ae77 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VoyageDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/outputs/VoyageDataOutput.kt @@ -19,8 +19,9 @@ data class VoyageDataOutput( startDate = voyage.startDate, endDate = voyage.endDate, tripNumber = voyage.tripNumber, - logbookMessagesAndAlerts = LogbookMessagesAndAlertsDataOutput - .fromLogbookMessagesAndAlerts(voyage.logbookMessagesAndAlerts), + logbookMessagesAndAlerts = + LogbookMessagesAndAlertsDataOutput + .fromLogbookMessagesAndAlerts(voyage.logbookMessagesAndAlerts), ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/HealthcheckController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/HealthcheckController.kt index f598ce0178..0cfc8eb114 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/HealthcheckController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/HealthcheckController.kt @@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RestController class HealthcheckController( private val getHealthcheck: GetHealthcheck, ) { - @GetMapping("") @Operation(summary = "Get healthcheck of positions and logbook") fun getHealthcheck(): HealthDataOutput { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionController.kt index a152b884f2..7954b4214a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionController.kt @@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RestController @RequestMapping("/api/v1/infractions") @Tag(name = "APIs for Infractions") class InfractionController(private val getAllInfractions: GetAllInfractions) { - @GetMapping("") @Operation(summary = "Get all infractions") fun getAllInfractionsController(): List { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PositionsController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PositionsController.kt index 1ab3a913f3..6ed9466bcd 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PositionsController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PositionsController.kt @@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.* class PositionsController( private val parseAndSavePosition: ParseAndSavePosition, ) { - @PostMapping(value = ["/v1/positions"]) @Operation(summary = "Receive position") @ResponseStatus(HttpStatus.CREATED) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicBeaconMalfunctionController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicBeaconMalfunctionController.kt index 145ff71d4c..9e9de6a4c2 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicBeaconMalfunctionController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicBeaconMalfunctionController.kt @@ -17,7 +17,6 @@ class PublicBeaconMalfunctionController( private val updateBeaconMalfunction: UpdateBeaconMalfunction, private val requestNotification: RequestNotification, ) { - @PutMapping(value = ["/{beaconMalfunctionId}"], consumes = ["application/json"]) @Operation(summary = "Update a beacon malfunction") fun updateBeaconMalfunction( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsController.kt index 8e5727ba5b..8b0608559a 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsController.kt @@ -18,7 +18,6 @@ class PublicMissionActionsController( private val getMissionActions: GetMissionActions, private val patchMissionAction: PatchMissionAction, ) { - @GetMapping("") @Operation(summary = "Get mission actions of specified mission") fun getMissionActions( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicOperationalAlertController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicOperationalAlertController.kt index cbc13af24b..99e4e07dc4 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicOperationalAlertController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicOperationalAlertController.kt @@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RestController class PublicOperationalAlertController( private val validatePendingAlert: ValidatePendingAlert, ) { - @PutMapping(value = ["/{id}/validate"]) @Operation(summary = "Validate an operational alert") fun validateAlert( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicReportingController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicReportingController.kt index e20218ad28..3d0ee00f69 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicReportingController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicReportingController.kt @@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RestController class PublicReportingController( private val archiveReporting: ArchiveReporting, ) { - @PutMapping(value = ["/{reportingId}/archive"]) @Operation(summary = "Archive a reporting") fun archiveReporting( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/SpaController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/SpaController.kt index c3c2b81ab5..08ee105b05 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/SpaController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/SpaController.kt @@ -13,7 +13,10 @@ import org.springframework.web.bind.annotation.RequestMapping @Controller class SpaController : ErrorController { @RequestMapping("/error") - fun error(request: HttpServletRequest, response: HttpServletResponse): Any { + fun error( + request: HttpServletRequest, + response: HttpServletResponse, + ): Any { if (response.status != HttpStatus.UNAUTHORIZED.value()) { response.status = HttpStatus.OK.value() return "forward:/index.html" diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/UserManagementController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/UserManagementController.kt index 8f7f6696ae..dabfd2c677 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/UserManagementController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/UserManagementController.kt @@ -16,7 +16,6 @@ class UserManagementController( private val saveUser: SaveUser, private val deleteUser: DeleteUser, ) { - @PostMapping(value = [""], consumes = ["application/json"]) @ResponseStatus(HttpStatus.CREATED) @Operation(summary = "Create a new user") diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/VersionController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/VersionController.kt index a0f695ad8c..92fe3f5283 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/VersionController.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/VersionController.kt @@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.RestController @RestController class VersionController(val buildProperties: BuildProperties) { - @GetMapping("/version") fun version(): Map { return mapOf( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/BffFilterConfig.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/BffFilterConfig.kt index 72c38b5d45..c718a7fcbc 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/BffFilterConfig.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/BffFilterConfig.kt @@ -24,12 +24,13 @@ class BffFilterConfig( val registrationBean = FilterRegistrationBean() registrationBean.order = USER_AUTH_FILTER_PRECEDENCE - registrationBean.filter = UserAuthorizationCheckFilter( - oidcProperties, - protectedPathsAPIProperties, - apiClient, - getIsAuthorizedUser, - ) + registrationBean.filter = + UserAuthorizationCheckFilter( + oidcProperties, + protectedPathsAPIProperties, + apiClient, + getIsAuthorizedUser, + ) registrationBean.urlPatterns = protectedPathsAPIProperties.paths if (registrationBean.urlPatterns == null) { @@ -50,9 +51,10 @@ class BffFilterConfig( val registrationBean = FilterRegistrationBean() registrationBean.order = API_KEY_FILTER_PRECEDENCE - registrationBean.filter = ApiKeyCheckFilter( - protectedPathsAPIProperties, - ) + registrationBean.filter = + ApiKeyCheckFilter( + protectedPathsAPIProperties, + ) registrationBean.urlPatterns = protectedPathsAPIProperties.publicPaths if (registrationBean.urlPatterns == null) { logger.warn( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/UserAuthorizationCheckFilter.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/UserAuthorizationCheckFilter.kt index ceb338fe2c..4cdd825a32 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/UserAuthorizationCheckFilter.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/UserAuthorizationCheckFilter.kt @@ -27,6 +27,7 @@ class UserAuthorizationCheckFilter( companion object { val EMAIL_HEADER = "EMAIL" } + private val CURRENT_USER_AUTHORIZATION_CONTROLLER_PATH = "/bff/v1/authorization/current" private val BEARER_HEADER_TYPE = "Bearer" @@ -75,19 +76,21 @@ class UserAuthorizationCheckFilter( } try { - val userInfoResponse = apiClient.httpClient.get( - oidcProperties.issuerUri!! + oidcProperties.userinfoEndpoint!!, - ) { - headers { - append(Authorization, authorizationHeaderContent!!) - } - }.body() - - val isSuperUserPath = protectedPathsAPIProperties.superUserPaths?.any { - request.requestURI.contains( - it, - ) - } ?: false + val userInfoResponse = + apiClient.httpClient.get( + oidcProperties.issuerUri!! + oidcProperties.userinfoEndpoint!!, + ) { + headers { + append(Authorization, authorizationHeaderContent!!) + } + }.body() + + val isSuperUserPath = + protectedPathsAPIProperties.superUserPaths?.any { + request.requestURI.contains( + it, + ) + } ?: false val isAuthorized = getIsAuthorizedUser.execute(userInfoResponse.email, isSuperUserPath) if (!isAuthorized) { logger.info("$INSUFFICIENT_AUTHORIZATION_MESSAGE: ${request.requestURI!!} (${userInfoResponse.email})") diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/cache/CaffeineConfiguration.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/cache/CaffeineConfiguration.kt index f61fb24c98..66238da9a7 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/cache/CaffeineConfiguration.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/cache/CaffeineConfiguration.kt @@ -147,11 +147,12 @@ class CaffeineConfiguration { val vesselsCache = buildMinutesCache(vessels, ticker, 120) val vesselsAllPositionsCache = buildSecondsCache(vesselsAllPositions, ticker, 30) val vesselsPositionsCache = buildSecondsCache(vesselsPositions, ticker, 30) - val vesselsPositionsWithBeaconMalfunctionsCache = buildMinutesCache( - vesselsPositionsWithBeaconMalfunctions, - ticker, - 1, - ) + val vesselsPositionsWithBeaconMalfunctionsCache = + buildMinutesCache( + vesselsPositionsWithBeaconMalfunctions, + ticker, + 1, + ) val vesselCharterCache = buildMinutesCache(vesselCharter, ticker, 30) // Others @@ -213,7 +214,11 @@ class CaffeineConfiguration { return manager } - private fun buildMinutesCache(name: String, ticker: Ticker, minutesToExpire: Int): CaffeineCache { + private fun buildMinutesCache( + name: String, + ticker: Ticker, + minutesToExpire: Int, + ): CaffeineCache { return CaffeineCache( name, Caffeine.newBuilder() @@ -224,7 +229,11 @@ class CaffeineConfiguration { ) } - private fun buildSecondsCache(name: String, ticker: Ticker, secondsToExpire: Int): CaffeineCache { + private fun buildSecondsCache( + name: String, + ticker: Ticker, + secondsToExpire: Int, + ): CaffeineCache { return CaffeineCache( name, Caffeine.newBuilder() diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconEntity.kt index 4754937f06..e5e774988e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconEntity.kt @@ -23,15 +23,14 @@ data class BeaconEntity( val isCoastal: Boolean? = null, @Column(name = "logging_datetime_utc") val loggingDatetimeUtc: Instant? = null, - ) { - - fun toBeacon() = Beacon( - beaconNumber = beaconNumber, - vesselId = vesselId, - beaconStatus = beaconStatus, - satelliteOperatorId = satelliteOperatorId, - isCoastal = isCoastal, - loggingDatetimeUtc = loggingDatetimeUtc?.atZone(ZoneOffset.UTC), - ) + fun toBeacon() = + Beacon( + beaconNumber = beaconNumber, + vesselId = vesselId, + beaconStatus = beaconStatus, + satelliteOperatorId = satelliteOperatorId, + isCoastal = isCoastal, + loggingDatetimeUtc = loggingDatetimeUtc?.atZone(ZoneOffset.UTC), + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionActionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionActionEntity.kt index 16fc634348..358198afdb 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionActionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionActionEntity.kt @@ -28,15 +28,15 @@ data class BeaconMalfunctionActionEntity( @Column(name = "date_time_utc") val dateTime: Instant, ) { - - fun toBeaconMalfunctionAction() = BeaconMalfunctionAction( - id = id!!, - beaconMalfunctionId = beaconMalfunctionId, - propertyName = propertyName, - previousValue = previousValue, - nextValue = nextValue, - dateTime = dateTime.atZone(ZoneOffset.UTC), - ) + fun toBeaconMalfunctionAction() = + BeaconMalfunctionAction( + id = id!!, + beaconMalfunctionId = beaconMalfunctionId, + propertyName = propertyName, + previousValue = previousValue, + nextValue = nextValue, + dateTime = dateTime.atZone(ZoneOffset.UTC), + ) companion object { fun fromBeaconMalfunctionAction( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionCommentEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionCommentEntity.kt index 8cb8602fe0..bc17107a1b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionCommentEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionCommentEntity.kt @@ -24,24 +24,23 @@ data class BeaconMalfunctionCommentEntity( @Column(name = "date_time_utc") val dateTime: Instant, ) { - - fun toBeaconMalfunctionComment() = BeaconMalfunctionComment( - id = id!!, - beaconMalfunctionId = beaconMalfunctionId, - comment = comment, - userType = userType, - dateTime = dateTime.atZone(ZoneOffset.UTC), - ) + fun toBeaconMalfunctionComment() = + BeaconMalfunctionComment( + id = id!!, + beaconMalfunctionId = beaconMalfunctionId, + comment = comment, + userType = userType, + dateTime = dateTime.atZone(ZoneOffset.UTC), + ) companion object { - fun fromBeaconMalfunctionComment( - beaconMalfunctionComment: BeaconMalfunctionComment, - ) = BeaconMalfunctionCommentEntity( - id = beaconMalfunctionComment.id, - beaconMalfunctionId = beaconMalfunctionComment.beaconMalfunctionId, - comment = beaconMalfunctionComment.comment, - userType = beaconMalfunctionComment.userType, - dateTime = beaconMalfunctionComment.dateTime.toInstant(), - ) + fun fromBeaconMalfunctionComment(beaconMalfunctionComment: BeaconMalfunctionComment) = + BeaconMalfunctionCommentEntity( + id = beaconMalfunctionComment.id, + beaconMalfunctionId = beaconMalfunctionComment.beaconMalfunctionId, + comment = beaconMalfunctionComment.comment, + userType = beaconMalfunctionComment.userType, + dateTime = beaconMalfunctionComment.dateTime.toInstant(), + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionEntity.kt index 3e09134346..fa943b1e80 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionEntity.kt @@ -53,24 +53,25 @@ data class BeaconMalfunctionEntity( @Column(name = "beacon_status_at_malfunction_creation") val beaconStatusAtMalfunctionCreation: BeaconStatus, ) { - fun toBeaconMalfunction() = BeaconMalfunction( - id = id, - internalReferenceNumber = internalReferenceNumber, - ircs = ircs, - externalReferenceNumber = externalReferenceNumber, - vesselName = vesselName, - flagState = flagState, - vesselIdentifier = vesselIdentifier, - vesselStatus = vesselStatus, - stage = stage, - malfunctionStartDateTime = malfunctionStartDateTime.atZone(ZoneOffset.UTC), - malfunctionEndDateTime = malfunctionEndDateTime?.atZone(ZoneOffset.UTC), - vesselStatusLastModificationDateTime = vesselStatusLastModificationDateTime.atZone(ZoneOffset.UTC), - endOfBeaconMalfunctionReason = endOfBeaconMalfunctionReason, - vesselId = vesselId, - notificationRequested = notificationRequested, - requestedNotificationForeignFmcCode = requestedNotificationForeignFmcCode, - beaconNumber = beaconNumber, - beaconStatusAtMalfunctionCreation = beaconStatusAtMalfunctionCreation, - ) + fun toBeaconMalfunction() = + BeaconMalfunction( + id = id, + internalReferenceNumber = internalReferenceNumber, + ircs = ircs, + externalReferenceNumber = externalReferenceNumber, + vesselName = vesselName, + flagState = flagState, + vesselIdentifier = vesselIdentifier, + vesselStatus = vesselStatus, + stage = stage, + malfunctionStartDateTime = malfunctionStartDateTime.atZone(ZoneOffset.UTC), + malfunctionEndDateTime = malfunctionEndDateTime?.atZone(ZoneOffset.UTC), + vesselStatusLastModificationDateTime = vesselStatusLastModificationDateTime.atZone(ZoneOffset.UTC), + endOfBeaconMalfunctionReason = endOfBeaconMalfunctionReason, + vesselId = vesselId, + notificationRequested = notificationRequested, + requestedNotificationForeignFmcCode = requestedNotificationForeignFmcCode, + beaconNumber = beaconNumber, + beaconStatusAtMalfunctionCreation = beaconStatusAtMalfunctionCreation, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionNotificationEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionNotificationEntity.kt index b1685f1586..0e3d5050d0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionNotificationEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/BeaconMalfunctionNotificationEntity.kt @@ -36,17 +36,17 @@ data class BeaconMalfunctionNotificationEntity( @Column(name = "error_message") val errorMessage: String? = null, ) { - - fun toBeaconMalfunctionNotification() = BeaconMalfunctionNotification( - id = id, - beaconMalfunctionId = beaconMalfunctionId, - dateTimeUtc = dateTimeUtc.atZone(ZoneOffset.UTC), - notificationType = notificationType, - communicationMeans = communicationMeans, - recipientFunction = recipientFunction, - recipientName = recipientName, - recipientAddressOrNumber = recipientAddressOrNumber, - success = success, - errorMessage = errorMessage, - ) + fun toBeaconMalfunctionNotification() = + BeaconMalfunctionNotification( + id = id, + beaconMalfunctionId = beaconMalfunctionId, + dateTimeUtc = dateTimeUtc.atZone(ZoneOffset.UTC), + notificationType = notificationType, + communicationMeans = communicationMeans, + recipientFunction = recipientFunction, + recipientName = recipientName, + recipientAddressOrNumber = recipientAddressOrNumber, + success = success, + errorMessage = errorMessage, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ControlObjectivesEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ControlObjectivesEntity.kt index d54214e808..9fd734c34e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ControlObjectivesEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ControlObjectivesEntity.kt @@ -25,16 +25,16 @@ data class ControlObjectivesEntity( @Column(name = "control_priority_level") val controlPriorityLevel: Double, ) { - - fun toControlObjective() = ControlObjective( - id = id, - facade = Seafront.from(facade).toString(), - segment = segment, - year = year, - targetNumberOfControlsAtSea = targetNumberOfControlsAtSea, - targetNumberOfControlsAtPort = targetNumberOfControlsAtPort, - controlPriorityLevel = controlPriorityLevel, - ) + fun toControlObjective() = + ControlObjective( + id = id, + facade = Seafront.from(facade).toString(), + segment = segment, + year = year, + targetNumberOfControlsAtSea = targetNumberOfControlsAtSea, + targetNumberOfControlsAtPort = targetNumberOfControlsAtPort, + controlPriorityLevel = controlPriorityLevel, + ) companion object { fun fromControlObjective(controlObjective: ControlObjective): ControlObjectivesEntity { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/DistrictEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/DistrictEntity.kt index d0b79585ac..85836cd070 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/DistrictEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/DistrictEntity.kt @@ -23,13 +23,13 @@ data class DistrictEntity( @Column(name = "facade") val facade: String? = null, ) { - - fun toDistrict() = District( - districtCode = districtCode, - district = district, - departmentCode = departmentCode, - department = department, - dml = dml, - facade = facade, - ) + fun toDistrict() = + District( + districtCode = districtCode, + district = district, + departmentCode = departmentCode, + department = department, + dml = dml, + facade = facade, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FacadeAreaEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FacadeAreaEntity.kt index 31ce0b6aec..e07aa9e4a8 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FacadeAreaEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FacadeAreaEntity.kt @@ -19,9 +19,9 @@ data class FacadeAreaEntity( @Column(name = "geometry", columnDefinition = "Geometry") val geometry: Geometry, ) { - - fun toFacadeArea() = FacadeArea( - facade = Seafront.from(facade).toString(), - geometry = geometry, - ) + fun toFacadeArea() = + FacadeArea( + facade = Seafront.from(facade).toString(), + geometry = geometry, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FaoAreaEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FaoAreaEntity.kt index 0ba6b5dcae..07915eb4fe 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FaoAreaEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FaoAreaEntity.kt @@ -13,7 +13,8 @@ data class FaoAreaEntity( @Column(name = "f_code") val faoCode: String, ) { - fun toFaoArea() = FaoArea( - faoCode = faoCode, - ) + fun toFaoArea() = + FaoArea( + faoCode = faoCode, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FleetSegmentEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FleetSegmentEntity.kt index 1e7f2e0061..27af0ff0f8 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FleetSegmentEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/FleetSegmentEntity.kt @@ -29,30 +29,31 @@ data class FleetSegmentEntity( @Column(name = "year", nullable = false) val year: Int, ) { - - fun toFleetSegment() = FleetSegment( - segment = this.segment, - segmentName = this.segmentName, - dirm = this.dirm, - gears = this.gears, - faoAreas = this.faoAreas, - targetSpecies = this.targetSpecies, - bycatchSpecies = this.bycatchSpecies, - impactRiskFactor = this.impactRiskFactor, - year = this.year, - ) + fun toFleetSegment() = + FleetSegment( + segment = this.segment, + segmentName = this.segmentName, + dirm = this.dirm, + gears = this.gears, + faoAreas = this.faoAreas, + targetSpecies = this.targetSpecies, + bycatchSpecies = this.bycatchSpecies, + impactRiskFactor = this.impactRiskFactor, + year = this.year, + ) companion object { - fun fromFleetSegment(fleetSegment: FleetSegment) = FleetSegmentEntity( - segment = fleetSegment.segment, - segmentName = fleetSegment.segmentName, - dirm = fleetSegment.dirm, - gears = fleetSegment.gears, - faoAreas = fleetSegment.faoAreas, - targetSpecies = fleetSegment.targetSpecies, - bycatchSpecies = fleetSegment.bycatchSpecies, - impactRiskFactor = fleetSegment.impactRiskFactor, - year = fleetSegment.year, - ) + fun fromFleetSegment(fleetSegment: FleetSegment) = + FleetSegmentEntity( + segment = fleetSegment.segment, + segmentName = fleetSegment.segmentName, + dirm = fleetSegment.dirm, + gears = fleetSegment.gears, + faoAreas = fleetSegment.faoAreas, + targetSpecies = fleetSegment.targetSpecies, + bycatchSpecies = fleetSegment.bycatchSpecies, + impactRiskFactor = fleetSegment.impactRiskFactor, + year = fleetSegment.year, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ForeignFmcEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ForeignFmcEntity.kt index ee5753b3b5..a53f1b5164 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ForeignFmcEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ForeignFmcEntity.kt @@ -17,10 +17,10 @@ data class ForeignFmcEntity( @Column(name = "email_addresses", columnDefinition = "varchar[]") var emailAddresses: List? = null, ) { - - fun toForeignFMC() = ForeignFMC( - countryCodeIso3 = countryCodeIso3, - countryName = countryName, - emailAddresses = emailAddresses, - ) + fun toForeignFMC() = + ForeignFMC( + countryCodeIso3 = countryCodeIso3, + countryName = countryName, + emailAddresses = emailAddresses, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/GearCodeGroupEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/GearCodeGroupEntity.kt index 57421b6437..87d007ee41 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/GearCodeGroupEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/GearCodeGroupEntity.kt @@ -15,9 +15,9 @@ data class GearCodeGroupEntity( @Column(name = "fishing_gear_group_id") val groupId: Int, ) { - - fun toGearCodeGroup() = GearCodeGroup( - code = code, - groupId = groupId, - ) + fun toGearCodeGroup() = + GearCodeGroup( + code = code, + groupId = groupId, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/GearEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/GearEntity.kt index a6ebb5b3cf..7e68b23dad 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/GearEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/GearEntity.kt @@ -17,10 +17,10 @@ data class GearEntity( @Column(name = "fishing_gear_category") val category: String? = null, ) { - - fun toGear() = Gear( - code = code, - name = name, - category = category, - ) + fun toGear() = + Gear( + code = code, + name = name, + category = category, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt index c844776a74..cf51259158 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/InfractionEntity.kt @@ -17,15 +17,16 @@ data class InfractionEntity( @Column(name = "infraction") var infraction: String? = null, ) { - - fun toInfraction() = Infraction( - natinfCode = natinfCode, - regulation = regulation, - infractionCategory = infractionCategory?.let { category -> - InfractionCategory.entries.firstOrNull { - it.value == category - } - }, - infraction = infraction, - ) + fun toInfraction() = + Infraction( + natinfCode = natinfCode, + regulation = regulation, + infractionCategory = + infractionCategory?.let { category -> + InfractionCategory.entries.firstOrNull { + it.value == category + } + }, + infraction = infraction, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LastPositionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LastPositionEntity.kt index f00ce8f0a5..2d666771be 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LastPositionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LastPositionEntity.kt @@ -36,7 +36,6 @@ data class LastPositionEntity( val flagState: String? = null, @Column(name = "trip_number") val tripNumber: String? = null, - @Column(name = "latitude") val latitude: Double? = null, @Column(name = "longitude") @@ -51,7 +50,6 @@ data class LastPositionEntity( val course: Double? = null, @Column(name = "last_position_datetime_utc") val dateTime: ZonedDateTime, - @Column(name = "emission_period") val emissionPeriod: Duration? = null, @Column(name = "last_logbook_message_datetime_utc") @@ -106,62 +104,65 @@ data class LastPositionEntity( @Column(name = "reportings", columnDefinition = "varchar(200)[]") val reportings: List? = listOf(), ) : Serializable { - - fun toLastPosition(mapper: ObjectMapper) = LastPosition( - vesselId = vesselId, - internalReferenceNumber = internalReferenceNumber, - ircs = ircs, - mmsi = mmsi, - externalReferenceNumber = externalReferenceNumber, - dateTime = dateTime, - latitude = latitude, - longitude = longitude, - estimatedCurrentLatitude = estimatedCurrentLatitude, - estimatedCurrentLongitude = estimatedCurrentLongitude, - vesselName = vesselName, - speed = speed, - course = course, - flagState = flagState?.let { - try { - CountryCode.valueOf(it) - } catch (e: IllegalArgumentException) { - CountryCode.UNDEFINED - } - } ?: CountryCode.UNDEFINED, - tripNumber = tripNumber, - positionType = PositionType.VMS, - emissionPeriod = emissionPeriod, - lastLogbookMessageDateTime = lastLogbookMessageDateTime, - departureDateTime = departureDateTime, - width = width, - length = length, - registryPortName = registryPort, - district = district, - districtCode = districtCode, - gearOnboard = mapper.readValue( - gearOnboard, - mapper.typeFactory - .constructCollectionType(MutableList::class.java, Gear::class.java), - ), - segments = segments, - speciesOnboard = mapper.readValue( - speciesOnboard, - mapper.typeFactory - .constructCollectionType(MutableList::class.java, Species::class.java), - ), - totalWeightOnboard = totalWeightOnboard, - lastControlDateTime = lastControlDateTime, - lastControlInfraction = lastControlInfraction, - postControlComment = postControlComment, - vesselIdentifier = vesselIdentifier, - impactRiskFactor = impactRiskFactor, - probabilityRiskFactor = probabilityRiskFactor, - detectabilityRiskFactor = detectabilityRiskFactor, - riskFactor = riskFactor, - underCharter = underCharter, - isAtPort = isAtPort, - alerts = alerts, - beaconMalfunctionId = beaconMalfunctionId, - reportings = reportings ?: listOf(), - ) + fun toLastPosition(mapper: ObjectMapper) = + LastPosition( + vesselId = vesselId, + internalReferenceNumber = internalReferenceNumber, + ircs = ircs, + mmsi = mmsi, + externalReferenceNumber = externalReferenceNumber, + dateTime = dateTime, + latitude = latitude, + longitude = longitude, + estimatedCurrentLatitude = estimatedCurrentLatitude, + estimatedCurrentLongitude = estimatedCurrentLongitude, + vesselName = vesselName, + speed = speed, + course = course, + flagState = + flagState?.let { + try { + CountryCode.valueOf(it) + } catch (e: IllegalArgumentException) { + CountryCode.UNDEFINED + } + } ?: CountryCode.UNDEFINED, + tripNumber = tripNumber, + positionType = PositionType.VMS, + emissionPeriod = emissionPeriod, + lastLogbookMessageDateTime = lastLogbookMessageDateTime, + departureDateTime = departureDateTime, + width = width, + length = length, + registryPortName = registryPort, + district = district, + districtCode = districtCode, + gearOnboard = + mapper.readValue( + gearOnboard, + mapper.typeFactory + .constructCollectionType(MutableList::class.java, Gear::class.java), + ), + segments = segments, + speciesOnboard = + mapper.readValue( + speciesOnboard, + mapper.typeFactory + .constructCollectionType(MutableList::class.java, Species::class.java), + ), + totalWeightOnboard = totalWeightOnboard, + lastControlDateTime = lastControlDateTime, + lastControlInfraction = lastControlInfraction, + postControlComment = postControlComment, + vesselIdentifier = vesselIdentifier, + impactRiskFactor = impactRiskFactor, + probabilityRiskFactor = probabilityRiskFactor, + detectabilityRiskFactor = detectabilityRiskFactor, + riskFactor = riskFactor, + underCharter = underCharter, + isAtPort = isAtPort, + alerts = alerts, + beaconMalfunctionId = beaconMalfunctionId, + reportings = reportings ?: listOf(), + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookRawMessageEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookRawMessageEntity.kt index 39edb97198..8d6a72cd1d 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookRawMessageEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookRawMessageEntity.kt @@ -16,9 +16,10 @@ data class LogbookRawMessageEntity( val rawMessage: String? = null, ) { companion object { - fun fromLogbookRawMessage(logbookRawMessage: LogbookRawMessage) = LogbookRawMessageEntity( - operationNumber = logbookRawMessage.operationNumber, - rawMessage = logbookRawMessage.rawMessage, - ) + fun fromLogbookRawMessage(logbookRawMessage: LogbookRawMessage) = + LogbookRawMessageEntity( + operationNumber = logbookRawMessage.operationNumber, + rawMessage = logbookRawMessage.rawMessage, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookReportEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookReportEntity.kt index 7a39b334a3..bc1ea0ed05 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookReportEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/LogbookReportEntity.kt @@ -72,7 +72,6 @@ data class LogbookReportEntity( val tripSegments: String?, @Column(name = "is_test_message") val isTestMessage: Boolean = false, - ) { companion object { fun fromLogbookMessage( @@ -94,7 +93,6 @@ data class LogbookReportEntity( imo = logbookMessage.imo, software = logbookMessage.software, transmissionFormat = logbookMessage.transmissionFormat, - isEnriched = logbookMessage.isEnriched, message = mapper.writeValueAsString(logbookMessage.message), messageType = logbookMessage.messageType, @@ -127,7 +125,6 @@ data class LogbookReportEntity( imo = imo, software = software, transmissionFormat = transmissionFormat, - isEnriched = isEnriched, message = message, messageType = messageType, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ManualPriorNotificationEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ManualPriorNotificationEntity.kt index 580b00760a..72ed5457bf 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ManualPriorNotificationEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ManualPriorNotificationEntity.kt @@ -17,47 +17,34 @@ data class ManualPriorNotificationEntity( @Column(name = "report_id", updatable = false) @GeneratedValue(strategy = GenerationType.IDENTITY) val reportId: String?, - @Column(name = "vessel_id", nullable = false) val vesselId: Int, - @Column(name = "cfr") val cfr: String?, - @Column(name = "external_immatriculation") val externalReferenceNumber: String? = null, - @Column(name = "ircs") val ircs: String? = null, - @Column(name = "created_at") val createdAt: ZonedDateTime, - @Column(name = "did_not_fish_after_zero_notice") val didNotFishAfterZeroNotice: Boolean, - // ISO Alpha-3 country code @Column(name = "flag_state") val flagState: String?, - @Column(name = "sent_at") val sentAt: ZonedDateTime, - @Column(name = "trip_gears", nullable = true, columnDefinition = "jsonb") @Type(JsonBinaryType::class) val tripGears: List?, - @Column(name = "trip_segments", nullable = true, columnDefinition = "jsonb") @Type(JsonBinaryType::class) val tripSegments: List?, - @Column(name = "updated_at") val updatedAt: ZonedDateTime, - @Column(name = "value", nullable = true, columnDefinition = "jsonb") @Type(JsonBinaryType::class) val value: PNO, - @Column(name = "vessel_name") val vesselName: String?, ) { @@ -70,11 +57,12 @@ data class ManualPriorNotificationEntity( val pnoLogbookMessage = priorNotification.logbookMessageAndValue.logbookMessage val pnoLogbookMessageValue = priorNotification.logbookMessageAndValue.value val createdAt = priorNotification.createdAt ?: ZonedDateTime.now() - val updatedAt = if (isUpdate || priorNotification.updatedAt == null) { - ZonedDateTime.now() - } else { - priorNotification.updatedAt - } + val updatedAt = + if (isUpdate || priorNotification.updatedAt == null) { + ZonedDateTime.now() + } else { + priorNotification.updatedAt + } val sentAt = requireNotNull(priorNotification.sentAt) { "`sentAt` is null." } val vesselId = requireNotNull(pnoLogbookMessage.vesselId) { "`vesselId` is null." } @@ -108,27 +96,28 @@ data class ManualPriorNotificationEntity( try { val reportId = requireNotNull(reportId) { "`reportId` is null." } - val pnoLogbookMessage = LogbookMessage( - id = null, - reportId = reportId, - flagState = flagState, - isEnriched = true, - integrationDateTime = createdAt, - internalReferenceNumber = cfr, - ircs = ircs, - externalReferenceNumber = externalReferenceNumber, - message = value, - messageType = LogbookMessageTypeMapping.PNO.name, - operationDateTime = createdAt, - operationNumber = null, - operationType = LogbookOperationType.DAT, - reportDateTime = sentAt, - transmissionFormat = null, - tripGears = tripGears, - tripSegments = tripSegments, - vesselName = vesselName, - vesselId = vesselId, - ) + val pnoLogbookMessage = + LogbookMessage( + id = null, + reportId = reportId, + flagState = flagState, + isEnriched = true, + integrationDateTime = createdAt, + internalReferenceNumber = cfr, + ircs = ircs, + externalReferenceNumber = externalReferenceNumber, + message = value, + messageType = LogbookMessageTypeMapping.PNO.name, + operationDateTime = createdAt, + operationNumber = null, + operationType = LogbookOperationType.DAT, + reportDateTime = sentAt, + transmissionFormat = null, + tripGears = tripGears, + tripSegments = tripSegments, + vesselName = vesselName, + vesselId = vesselId, + ) // For practical reasons `vessel` can't be `null`, so we temporarily set it to "Navire inconnu" val vessel = UNKNOWN_VESSEL val logbookMessageAndValue = LogbookMessageAndValue(pnoLogbookMessage, PNO::class.java) @@ -141,7 +130,6 @@ data class ManualPriorNotificationEntity( reportId = reportId, sentAt = sentAt, updatedAt = updatedAt, - // These props need to be calculated in the use case port = null, reportingCount = null, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt index d81c44c111..2be143f331 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/MissionActionEntity.kt @@ -148,7 +148,6 @@ class MissionActionEntity( @Column(name = "observations_by_unit") val observationsByUnit: String? = null, ) { - companion object { fun fromMissionAction( mapper: ObjectMapper, @@ -225,11 +224,12 @@ class MissionActionEntity( flagState = flagState, districtCode = districtCode, faoAreas = faoAreas ?: listOf(), - flightGoals = flightGoals?.map { - FlightGoal.valueOf( - it, - ) - } ?: listOf(), + flightGoals = + flightGoals?.map { + FlightGoal.valueOf( + it, + ) + } ?: listOf(), actionType = actionType, actionDatetimeUtc = actionDatetimeUtc.atZone(ZoneOffset.UTC), actionEndDatetimeUtc = actionEndDatetimeUtc?.let { it.atZone(ZoneOffset.UTC) }, @@ -240,17 +240,19 @@ class MissionActionEntity( speciesWeightControlled = speciesWeightControlled, speciesSizeControlled = speciesSizeControlled, separateStowageOfPreservedSpecies = separateStowageOfPreservedSpecies, - logbookInfractions = deserializeJSONList( - mapper, - logbookInfractions, - LogbookInfraction::class.java, - ), + logbookInfractions = + deserializeJSONList( + mapper, + logbookInfractions, + LogbookInfraction::class.java, + ), licencesAndLogbookObservations = licencesAndLogbookObservations, - gearInfractions = deserializeJSONList( - mapper, - gearInfractions, - GearInfraction::class.java, - ), + gearInfractions = + deserializeJSONList( + mapper, + gearInfractions, + GearInfraction::class.java, + ), speciesInfractions = deserializeJSONList(mapper, speciesInfractions, SpeciesInfraction::class.java), speciesObservations = speciesObservations, seizureAndDiversion = seizureAndDiversion, @@ -260,11 +262,12 @@ class MissionActionEntity( controlQualityComments = controlQualityComments, feedbackSheetRequired = feedbackSheetRequired, userTrigram = userTrigram, - segments = deserializeJSONList( - mapper, - segments, - FleetSegment::class.java, - ), + segments = + deserializeJSONList( + mapper, + segments, + FleetSegment::class.java, + ), facade = facade?.let { Seafront.from(it).toString() }, longitude = longitude, latitude = latitude, @@ -272,11 +275,12 @@ class MissionActionEntity( vesselTargeted = vesselTargeted, seizureAndDiversionComments = seizureAndDiversionComments, otherComments = otherComments, - gearOnboard = deserializeJSONList( - mapper, - gearOnboard, - GearControl::class.java, - ), + gearOnboard = + deserializeJSONList( + mapper, + gearOnboard, + GearControl::class.java, + ), speciesOnboard = deserializeJSONList(mapper, speciesOnboard, SpeciesControl::class.java), isDeleted = isDeleted, hasSomeGearsSeized = hasSomeGearsSeized, @@ -292,13 +296,18 @@ class MissionActionEntity( observationsByUnit = observationsByUnit, ) - private fun deserializeJSONList(mapper: ObjectMapper, json: String?, clazz: Class): List = json?.let { - mapper.readValue( - json, - mapper.typeFactory - .constructCollectionType(MutableList::class.java, clazz), - ) - } ?: listOf() + private fun deserializeJSONList( + mapper: ObjectMapper, + json: String?, + clazz: Class, + ): List = + json?.let { + mapper.readValue( + json, + mapper.typeFactory + .constructCollectionType(MutableList::class.java, clazz), + ) + } ?: listOf() override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PendingAlertEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PendingAlertEntity.kt index 39713e3714..ee6bac5412 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PendingAlertEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PendingAlertEntity.kt @@ -50,7 +50,6 @@ data class PendingAlertEntity( @Column(name = "longitude") val longitude: Double? = null, ) { - fun toPendingAlert(mapper: ObjectMapper): PendingAlert { return PendingAlert( id = id, @@ -70,7 +69,10 @@ data class PendingAlertEntity( } companion object { - fun fromPendingAlert(alert: PendingAlert, mapper: ObjectMapper) = PendingAlertEntity( + fun fromPendingAlert( + alert: PendingAlert, + mapper: ObjectMapper, + ) = PendingAlertEntity( vesselName = alert.vesselName, internalReferenceNumber = alert.internalReferenceNumber, externalReferenceNumber = alert.externalReferenceNumber, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoAndLanAlertEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoAndLanAlertEntity.kt index 171d978890..f8366631c0 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoAndLanAlertEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoAndLanAlertEntity.kt @@ -29,7 +29,6 @@ data class PnoAndLanAlertEntity( @Column(name = "value", nullable = false, columnDefinition = "jsonb") val value: String, ) { - fun toAlert(mapper: ObjectMapper): PNOAndLANAlert { return PNOAndLANAlert( id = id, @@ -43,7 +42,10 @@ data class PnoAndLanAlertEntity( } companion object { - fun fromAlert(alert: PNOAndLANAlert, mapper: ObjectMapper) = PnoAndLanAlertEntity( + fun fromAlert( + alert: PNOAndLANAlert, + mapper: ObjectMapper, + ) = PnoAndLanAlertEntity( id = alert.id, internalReferenceNumber = alert.internalReferenceNumber, externalReferenceNumber = alert.externalReferenceNumber, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoPortSubscriptionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoPortSubscriptionEntity.kt index 08f08e7fc8..6e33716127 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoPortSubscriptionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoPortSubscriptionEntity.kt @@ -11,7 +11,6 @@ class PnoPortSubscriptionId(val controlUnitId: Int, val portLocode: String) : Se data class PnoPortSubscriptionEntity( @EmbeddedId val id: PnoPortSubscriptionId, - @Column(name = "receive_all_pnos", updatable = false) val receiveAllPnos: Boolean, ) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoSegmentSubscriptionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoSegmentSubscriptionEntity.kt index f223aa9ca3..2b2ba260b1 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoSegmentSubscriptionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoSegmentSubscriptionEntity.kt @@ -6,7 +6,6 @@ import java.io.Serializable @Embeddable class PnoSegmentSubscriptionId( val controlUnitId: Int, - @Column(name = "segment", updatable = false) val segmentCode: String, ) : Serializable diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoTypeEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoTypeEntity.kt index b8e08bbda3..29882db7ef 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoTypeEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoTypeEntity.kt @@ -9,25 +9,21 @@ data class PnoTypeEntity( @Id @Column(name = "id", unique = true) val id: Int = 0, - @Column(name = "name", nullable = false) val name: String, - @Column(name = "minimum_notification_period", nullable = false) val minimumNotificationPeriod: Double = -1.0, - @Column(name = "has_designated_ports", nullable = false) val hasDesignatedPorts: Boolean = false, - @OneToMany(mappedBy = "pnoType", cascade = [CascadeType.ALL], orphanRemoval = true) val pnoTypeRules: List = listOf(), ) { - - fun toPnoType() = PnoType( - id = id, - name = name, - minimumNotificationPeriod = minimumNotificationPeriod, - hasDesignatedPorts = hasDesignatedPorts, - pnoTypeRules = pnoTypeRules.map { it.toPnoTypeRule() }, - ) + fun toPnoType() = + PnoType( + id = id, + name = name, + minimumNotificationPeriod = minimumNotificationPeriod, + hasDesignatedPorts = hasDesignatedPorts, + pnoTypeRules = pnoTypeRules.map { it.toPnoTypeRule() }, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoTypeRuleEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoTypeRuleEntity.kt index 3df85b00bd..8bafc50e46 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoTypeRuleEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PnoTypeRuleEntity.kt @@ -10,37 +10,30 @@ data class PnoTypeRuleEntity( @Id @Column(name = "id", unique = true) val id: Int = 0, - @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "pno_type_id", nullable = false) val pnoType: PnoTypeEntity, - @Column(name = "species", nullable = false, columnDefinition = "VARCHAR[]") val species: List = listOf(), - @Column(name = "fao_areas", nullable = false, columnDefinition = "VARCHAR[]") val faoAreas: List = listOf(), - @Column(name = "cgpm_areas", nullable = false, columnDefinition = "VARCHAR[]") val cgpmAreas: List = listOf(), - @Column(name = "gears", nullable = false, columnDefinition = "VARCHAR[]") val gears: List = listOf(), - @Column(name = "flag_states", nullable = false, columnDefinition = "VARCHAR[]") val flagStates: List = listOf(), - @Column(name = "minimum_quantity_kg", nullable = false) val minimumQuantityKg: Double = 0.0, ) { - - fun toPnoTypeRule() = PnoTypeRule( - id = id, - species = species, - faoAreas = faoAreas, - cgpmAreas = cgpmAreas, - gears = gears, - flagStates = flagStates.map { CountryCode.getByAlpha3Code(it) }, - minimumQuantityKg = minimumQuantityKg, - ) + fun toPnoTypeRule() = + PnoTypeRule( + id = id, + species = species, + faoAreas = faoAreas, + cgpmAreas = cgpmAreas, + gears = gears, + flagStates = flagStates.map { CountryCode.getByAlpha3Code(it) }, + minimumQuantityKg = minimumQuantityKg, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PositionEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PositionEntity.kt index 2efd96a904..b9c481164c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PositionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PositionEntity.kt @@ -16,7 +16,6 @@ data class PositionEntity( @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "position_id_seq") @Column(name = "id") val id: Int? = null, - // Optional fields @Column(name = "internal_reference_number") val internalReferenceNumber: String? = null, @@ -48,7 +47,6 @@ data class PositionEntity( @Column(name = "network_type") @Enumerated(EnumType.STRING) val networkType: NetworkType? = null, - // Mandatory fields @Enumerated(EnumType.STRING) @Column(name = "position_type") @@ -64,29 +62,29 @@ data class PositionEntity( @Column(name = "date_time") val dateTime: ZonedDateTime, ) { - - fun toPosition() = Position( - id = id, - internalReferenceNumber = internalReferenceNumber, - ircs = ircs, - mmsi = mmsi, - externalReferenceNumber = externalReferenceNumber, - dateTime = dateTime, - latitude = latitude, - longitude = longitude, - vesselName = vesselName, - speed = speed, - course = course, - flagState = flagState, - destination = destination, - from = from, - tripNumber = tripNumber, - positionType = positionType, - isManual = isManual, - isFishing = isFishing, - isAtPort = isAtPort, - networkType = networkType, - ) + fun toPosition() = + Position( + id = id, + internalReferenceNumber = internalReferenceNumber, + ircs = ircs, + mmsi = mmsi, + externalReferenceNumber = externalReferenceNumber, + dateTime = dateTime, + latitude = latitude, + longitude = longitude, + vesselName = vesselName, + speed = speed, + course = course, + flagState = flagState, + destination = destination, + from = from, + tripNumber = tripNumber, + positionType = positionType, + isManual = isManual, + isFishing = isFishing, + isAtPort = isAtPort, + networkType = networkType, + ) companion object { fun fromPosition(position: Position): PositionEntity { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PriorNotificationPdfDocumentEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PriorNotificationPdfDocumentEntity.kt index 494e739cf2..e060d7a376 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PriorNotificationPdfDocumentEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/PriorNotificationPdfDocumentEntity.kt @@ -14,26 +14,23 @@ data class PriorNotificationPdfDocumentEntity( @Id @Column(name = "report_id") val reportId: String, - @Column(name = "source", columnDefinition = "prior_notification_source") @Enumerated(EnumType.STRING) @JdbcType(PostgreSQLEnumJdbcType::class) val source: PriorNotificationSource, - @Column(name = "generation_datetime_utc") val generationDatetimeUtc: ZonedDateTime, - @Column(name = "pdf_document") @JdbcType(BinaryJdbcType::class) val pdfDocument: ByteArray?, ) { - - fun toPdfDocument() = PdfDocument( - reportId = reportId, - source = source, - generationDatetimeUtc = generationDatetimeUtc, - pdfDocument = pdfDocument, - ) + fun toPdfDocument() = + PdfDocument( + reportId = reportId, + source = source, + generationDatetimeUtc = generationDatetimeUtc, + pdfDocument = pdfDocument, + ) override fun equals(other: Any?): Boolean { if (this === other) return true @@ -47,7 +44,9 @@ data class PriorNotificationPdfDocumentEntity( if (pdfDocument != null) { if (other.pdfDocument == null) return false if (!pdfDocument.contentEquals(other.pdfDocument)) return false - } else if (other.pdfDocument != null) return false + } else if (other.pdfDocument != null) { + return false + } return true } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ReportingEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ReportingEntity.kt index 83a7e82ea4..c07e646ae5 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ReportingEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/ReportingEntity.kt @@ -60,7 +60,6 @@ data class ReportingEntity( @Column(name = "longitude") val longitude: Double? = null, ) { - fun toReporting(mapper: ObjectMapper): Reporting { return Reporting( id = id, @@ -105,7 +104,10 @@ data class ReportingEntity( longitude = alert.longitude, ) - fun fromReporting(reporting: Reporting, mapper: ObjectMapper) = ReportingEntity( + fun fromReporting( + reporting: Reporting, + mapper: ObjectMapper, + ) = ReportingEntity( vesselName = reporting.vesselName, vesselId = reporting.vesselId, type = reporting.type, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/RiskFactorsEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/RiskFactorsEntity.kt index d0ddcb99d5..5eadb689e4 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/RiskFactorsEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/RiskFactorsEntity.kt @@ -69,16 +69,18 @@ data class RiskFactorsEntity( detectabilityRiskFactor = detectabilityRiskFactor, riskFactor = riskFactor, internalReferenceNumber = cfr, - gearOnboard = mapper.readValue( - gearOnboard, - mapper.typeFactory - .constructCollectionType(MutableList::class.java, Gear::class.java), - ), - speciesOnboard = mapper.readValue( - speciesOnboard, - mapper.typeFactory - .constructCollectionType(MutableList::class.java, Species::class.java), - ), + gearOnboard = + mapper.readValue( + gearOnboard, + mapper.typeFactory + .constructCollectionType(MutableList::class.java, Gear::class.java), + ), + speciesOnboard = + mapper.readValue( + speciesOnboard, + mapper.typeFactory + .constructCollectionType(MutableList::class.java, Species::class.java), + ), segments = segments, controlPriorityLevel = controlPriorityLevel, segmentHighestImpact = segmentHighestImpact, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SilencedAlertEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SilencedAlertEntity.kt index c85e3b2f00..bcc56bca90 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SilencedAlertEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SilencedAlertEntity.kt @@ -47,7 +47,6 @@ data class SilencedAlertEntity( @Column(name = "was_validated") val wasValidated: Boolean? = null, ) { - fun toSilencedAlert(mapper: ObjectMapper): SilencedAlert { return SilencedAlert( id = id, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SpeciesEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SpeciesEntity.kt index 8e0b688e0c..697335727e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SpeciesEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SpeciesEntity.kt @@ -17,9 +17,9 @@ data class SpeciesEntity( @Column(name = "species_name") val name: String, ) { - - fun toSpecies() = Species( - code = code, - name = name, - ) + fun toSpecies() = + Species( + code = code, + name = name, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SpeciesGroupEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SpeciesGroupEntity.kt index 716485f532..e4a60009be 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SpeciesGroupEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/SpeciesGroupEntity.kt @@ -17,9 +17,9 @@ data class SpeciesGroupEntity( @Column(name = "comment") val comment: String, ) { - - fun toSpeciesGroup() = SpeciesGroup( - group = group, - comment = comment, - ) + fun toSpeciesGroup() = + SpeciesGroup( + group = group, + comment = comment, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/UserAuthorizationEntity.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/UserAuthorizationEntity.kt index 8cd9b54628..100ab9e33e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/UserAuthorizationEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/entities/UserAuthorizationEntity.kt @@ -15,16 +15,17 @@ data class UserAuthorizationEntity( @Column(name = "is_super_user", nullable = false) val isSuperUser: Boolean, ) { - - fun toUserAuthorization() = UserAuthorization( - hashedEmail = hashedEmail, - isSuperUser = isSuperUser, - ) + fun toUserAuthorization() = + UserAuthorization( + hashedEmail = hashedEmail, + isSuperUser = isSuperUser, + ) companion object { - fun fromUserAuthorization(user: UserAuthorization) = UserAuthorizationEntity( - hashedEmail = user.hashedEmail, - isSuperUser = user.isSuperUser, - ) + fun fromUserAuthorization(user: UserAuthorization) = + UserAuthorizationEntity( + hashedEmail = user.hashedEmail, + isSuperUser = user.isSuperUser, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionsRepository.kt index 2e74be4ccd..a6ec967f84 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionsRepository.kt @@ -12,7 +12,6 @@ import java.time.ZonedDateTime class JpaBeaconMalfunctionsRepository( private val dbBeaconMalfunctionsRepository: DBBeaconMalfunctionsRepository, ) : BeaconMalfunctionsRepository { - override fun findAll(): List { return dbBeaconMalfunctionsRepository.findAll().map { it.toBeaconMalfunction() } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconRepository.kt index a4f8c50b4e..e06ffa3c36 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconRepository.kt @@ -9,7 +9,6 @@ import org.springframework.stereotype.Repository @Repository class JpaBeaconRepository(private val dbBeaconRepository: DBBeaconRepository) : BeaconRepository { - @Cacheable(value = ["search_beacons"]) override fun search(searched: String): List { if (searched.isEmpty()) { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaControlObjectivesRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaControlObjectivesRepository.kt index 00aaf9cdc9..f9428a672f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaControlObjectivesRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaControlObjectivesRepository.kt @@ -12,7 +12,6 @@ import org.springframework.transaction.annotation.Transactional class JpaControlObjectivesRepository( private val dbControlObjectivesRepository: DBControlObjectivesRepository, ) : ControlObjectivesRepository { - override fun findAllByYear(year: Int): List { return dbControlObjectivesRepository.findAllByYearEquals(year).map { it.toControlObjective() @@ -75,7 +74,10 @@ class JpaControlObjectivesRepository( } @Transactional - override fun addYear(currentYear: Int, nextYear: Int) { + override fun addYear( + currentYear: Int, + nextYear: Int, + ) { dbControlObjectivesRepository.duplicateCurrentYearAsNextYear(currentYear, nextYear) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaDistrictRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaDistrictRepository.kt index 2217ef5461..1a8c58ad6e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaDistrictRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaDistrictRepository.kt @@ -10,7 +10,6 @@ import org.springframework.stereotype.Repository @Repository class JpaDistrictRepository(private val dbDistrictRepository: DBDistrictRepository) : DistrictRepository { - @Cacheable(value = ["district"]) override fun find(districtCode: String): District { return try { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaFleetSegmentRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaFleetSegmentRepository.kt index 78587b111c..94c33309f6 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaFleetSegmentRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaFleetSegmentRepository.kt @@ -15,7 +15,6 @@ import org.springframework.stereotype.Repository class JpaFleetSegmentRepository( private val dbFleetSegmentRepository: DBFleetSegmentRepository, ) : FleetSegmentRepository { - override fun findAll(): List { return dbFleetSegmentRepository.findAll().map { it.toFleetSegment() @@ -30,7 +29,11 @@ class JpaFleetSegmentRepository( } @Transactional - override fun update(segment: String, fields: CreateOrUpdateFleetSegmentFields, year: Int): FleetSegment { + override fun update( + segment: String, + fields: CreateOrUpdateFleetSegmentFields, + year: Int, + ): FleetSegment { try { fields.segmentName?.let { dbFleetSegmentRepository.updateSegmentName(segment, it, year) @@ -71,7 +74,10 @@ class JpaFleetSegmentRepository( } @Transactional - override fun delete(segment: String, year: Int): List { + override fun delete( + segment: String, + year: Int, + ): List { try { dbFleetSegmentRepository.deleteBySegmentAndYearEquals(segment, year) @@ -92,7 +98,10 @@ class JpaFleetSegmentRepository( } @Transactional - override fun addYear(currentYear: Int, nextYear: Int) { + override fun addYear( + currentYear: Int, + nextYear: Int, + ) { dbFleetSegmentRepository.duplicateCurrentYearAsNextYear(currentYear, nextYear) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaForeignFMCRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaForeignFMCRepository.kt index c7473e582b..e72b3f37c1 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaForeignFMCRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaForeignFMCRepository.kt @@ -7,7 +7,6 @@ import org.springframework.stereotype.Repository @Repository class JpaForeignFMCRepository(private val dbForeignFMCRepository: DBForeignFMCRepository) : ForeignFMCRepository { - override fun findAll(): List { return dbForeignFMCRepository.findAll().map { it.toForeignFMC() } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearCodeGroupRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearCodeGroupRepository.kt index ca49c2ddc6..30a36e00ea 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearCodeGroupRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearCodeGroupRepository.kt @@ -12,7 +12,6 @@ import org.springframework.stereotype.Repository class JpaGearCodeGroupRepository( private val dbGearCodeGroupRepository: DBGearCodeGroupRepository, ) : GearCodeGroupRepository { - @Cacheable(value = ["gear_code_groups"]) override fun findAll(): List { return dbGearCodeGroupRepository.findAll().map { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearRepository.kt index 940f9250a8..316c755ed7 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearRepository.kt @@ -10,7 +10,6 @@ import org.springframework.stereotype.Repository @Repository class JpaGearRepository(private val dbGearRepository: DBGearRepository) : GearRepository { - @Cacheable(value = ["gears"]) override fun findAll(): List { return dbGearRepository.findAll().map { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLastPositionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLastPositionRepository.kt index ccacf0e13f..9ef52fd86b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLastPositionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLastPositionRepository.kt @@ -18,7 +18,6 @@ class JpaLastPositionRepository( private val dbLastPositionRepository: DBLastPositionRepository, private val mapper: ObjectMapper, ) : LastPositionRepository { - @Cacheable(value = ["vessels_all_position"]) override fun findAll(): List { return dbLastPositionRepository.findAll() diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookRawMessageRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookRawMessageRepository.kt index 19abfa1dab..68dd73d815 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookRawMessageRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookRawMessageRepository.kt @@ -13,7 +13,6 @@ import org.springframework.stereotype.Repository class JpaLogbookRawMessageRepository( private val dbLogbookRawMessageRepository: DBLogbookRawMessageRepository, ) : LogbookRawMessageRepository { - @Cacheable(value = ["logbook_raw_message"]) override fun findRawMessage(operationNumber: String): String? { return try { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookReportRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookReportRepository.kt index 1dcd32c13b..d7116aaaa2 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookReportRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookReportRepository.kt @@ -52,10 +52,11 @@ class JpaLogbookReportRepository( willArriveBefore = filter.willArriveBefore, ) - val referencedReportIds = logbookReportsWithDatCorAndDel - .filter { it.referencedReportId != null } - .map { it.referencedReportId } - .toSet() + val referencedReportIds = + logbookReportsWithDatCorAndDel + .filter { it.referencedReportId != null } + .map { it.referencedReportId } + .toSet() return logbookReportsWithDatCorAndDel .filter { report -> @@ -73,10 +74,11 @@ class JpaLogbookReportRepository( @Cacheable(value = ["pno_to_verify"]) override fun findAllPriorNotificationsToVerify(): List { - val filter = PriorNotificationsFilter( - willArriveAfter = CustomZonedDateTime(ZonedDateTime.now()).toString(), - willArriveBefore = CustomZonedDateTime(ZonedDateTime.now().plusHours(24)).toString(), - ) + val filter = + PriorNotificationsFilter( + willArriveAfter = CustomZonedDateTime(ZonedDateTime.now()).toString(), + willArriveBefore = CustomZonedDateTime(ZonedDateTime.now().plusHours(24)).toString(), + ) return findAllAcknowledgedPriorNotifications(filter).filter { it.logbookMessageAndValue.value.isInVerificationScope == true && @@ -95,8 +97,9 @@ class JpaLogbookReportRepository( reportId: String, operationDate: ZonedDateTime, ): PriorNotification? { - val logbookReport = dbLogbookReportRepository - .findAcknowledgedNonDeletedPnoDatAndCorsByReportId(reportId, operationDate.toString()).firstOrNull() + val logbookReport = + dbLogbookReportRepository + .findAcknowledgedNonDeletedPnoDatAndCorsByReportId(reportId, operationDate.toString()).firstOrNull() return logbookReport?.let { val pno = PriorNotification.fromLogbookMessage(it.toLogbookMessage(objectMapper)) @@ -346,25 +349,26 @@ class JpaLogbookReportRepository( override fun updatePriorNotificationState( reportId: String, operationDate: ZonedDateTime, - isBeingSent: Boolean, isSent: Boolean, isVerified: Boolean, ) { - val logbookReport = dbLogbookReportRepository - .findAcknowledgedNonDeletedPnoDatAndCorsByReportId( - reportId, - operationDate.withZoneSameInstant(UTC).toString(), - ).firstOrNull() - ?: throw BackendUsageException(BackendUsageErrorCode.NOT_FOUND) + val logbookReport = + dbLogbookReportRepository + .findAcknowledgedNonDeletedPnoDatAndCorsByReportId( + reportId, + operationDate.withZoneSameInstant(UTC).toString(), + ).firstOrNull() + ?: throw BackendUsageException(BackendUsageErrorCode.NOT_FOUND) val pnoValue = objectMapper.readValue(logbookReport.message, PNO::class.java) - val nextPnoValue = pnoValue.apply { - this.isBeingSent = isBeingSent - this.isSent = isSent - this.isVerified = isVerified - } + val nextPnoValue = + pnoValue.apply { + this.isBeingSent = isBeingSent + this.isSent = isSent + this.isVerified = isVerified + } val updatedLogbookReport = logbookReport.copy(message = objectMapper.writeValueAsString(nextPnoValue)) dbLogbookReportRepository.save(updatedLogbookReport) @@ -374,16 +378,16 @@ class JpaLogbookReportRepository( override fun updatePriorNotificationAuthorTrigramAndNote( reportId: String, operationDate: ZonedDateTime, - authorTrigram: String?, note: String?, ) { - val logbookReport = dbLogbookReportRepository - .findAcknowledgedNonDeletedPnoDatAndCorsByReportId( - reportId, - operationDate.withZoneSameInstant(UTC).toString(), - ).firstOrNull() - ?: throw BackendUsageException(BackendUsageErrorCode.NOT_FOUND) + val logbookReport = + dbLogbookReportRepository + .findAcknowledgedNonDeletedPnoDatAndCorsByReportId( + reportId, + operationDate.withZoneSameInstant(UTC).toString(), + ).firstOrNull() + ?: throw BackendUsageException(BackendUsageErrorCode.NOT_FOUND) val pnoValue = objectMapper.readValue(logbookReport.message, PNO::class.java) if ( @@ -393,18 +397,19 @@ class JpaLogbookReportRepository( return } - val nextPnoValue = pnoValue.apply { - this.authorTrigram = authorTrigram - this.note = note - /** - * The PNO states are re-initialized: - * - the PDF will be re-generated (done in the use case by deleting the old one) - * - the PNO will require another verification before sending - */ - this.isBeingSent = false - this.isSent = false - this.isVerified = false - } + val nextPnoValue = + pnoValue.apply { + this.authorTrigram = authorTrigram + this.note = note + /** + * The PNO states are re-initialized: + * - the PDF will be re-generated (done in the use case by deleting the old one) + * - the PNO will require another verification before sending + */ + this.isBeingSent = false + this.isSent = false + this.isVerified = false + } val updatedLogbookReport = logbookReport.copy(message = objectMapper.writeValueAsString(nextPnoValue)) dbLogbookReportRepository.save(updatedLogbookReport) @@ -412,19 +417,24 @@ class JpaLogbookReportRepository( @Transactional @CacheEvict(value = ["pno_to_verify"], allEntries = true) - override fun invalidate(reportId: String, operationDate: ZonedDateTime) { - val logbookReport = dbLogbookReportRepository - .findAcknowledgedNonDeletedPnoDatAndCorsByReportId( - reportId, - operationDate.withZoneSameInstant(UTC).toString(), - ).firstOrNull() - ?: throw BackendUsageException(BackendUsageErrorCode.NOT_FOUND) + override fun invalidate( + reportId: String, + operationDate: ZonedDateTime, + ) { + val logbookReport = + dbLogbookReportRepository + .findAcknowledgedNonDeletedPnoDatAndCorsByReportId( + reportId, + operationDate.withZoneSameInstant(UTC).toString(), + ).firstOrNull() + ?: throw BackendUsageException(BackendUsageErrorCode.NOT_FOUND) val pnoValue = objectMapper.readValue(logbookReport.message, PNO::class.java) - val nextPnoValue = pnoValue.apply { - this.isInvalidated = true - } + val nextPnoValue = + pnoValue.apply { + this.isInvalidated = true + } val updatedLogbookReport = logbookReport.copy(message = objectMapper.writeValueAsString(nextPnoValue)) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaManualPriorNotificationRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaManualPriorNotificationRepository.kt index 387815e11d..8cfd1ec62e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaManualPriorNotificationRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaManualPriorNotificationRepository.kt @@ -75,8 +75,9 @@ class JpaManualPriorNotificationRepository( @CacheEvict(value = ["manual_pno_to_verify"], allEntries = true) override fun save(newOrNextPriorNotification: PriorNotification): PriorNotification { try { - val manualPriorNotificationEntity = dbManualPriorNotificationRepository - .save(ManualPriorNotificationEntity.fromPriorNotification(newOrNextPriorNotification, true)) + val manualPriorNotificationEntity = + dbManualPriorNotificationRepository + .save(ManualPriorNotificationEntity.fromPriorNotification(newOrNextPriorNotification, true)) return manualPriorNotificationEntity.toPriorNotification() } catch (e: IllegalArgumentException) { @@ -89,7 +90,12 @@ class JpaManualPriorNotificationRepository( @Transactional @CacheEvict(value = ["manual_pno_to_verify"], allEntries = true) - override fun updateState(reportId: String, isBeingSent: Boolean, isSent: Boolean, isVerified: Boolean) { + override fun updateState( + reportId: String, + isBeingSent: Boolean, + isSent: Boolean, + isVerified: Boolean, + ) { val manualPriorNotification = dbManualPriorNotificationRepository.findByReportId(reportId) ?: throw BackendUsageException( BackendUsageErrorCode.NOT_FOUND, diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt index 4dffb405a7..4eecc1867b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionsRepository.kt @@ -14,7 +14,6 @@ class JpaMissionActionsRepository( private val dbMissionActionsRepository: DBMissionActionsRepository, private val mapper: ObjectMapper, ) : MissionActionsRepository { - override fun findVesselMissionActionsAfterDateTime( vesselId: Int, afterDateTime: ZonedDateTime, @@ -50,7 +49,10 @@ class JpaMissionActionsRepository( return dbMissionActionsRepository.findById(id).get().toMissionAction(mapper) } - override fun findSeaAndLandControlBetweenDates(beforeDateTime: ZonedDateTime, afterDateTime: ZonedDateTime): List { + override fun findSeaAndLandControlBetweenDates( + beforeDateTime: ZonedDateTime, + afterDateTime: ZonedDateTime, + ): List { return dbMissionActionsRepository.findAllByActionDatetimeUtcBeforeAndActionDatetimeUtcAfterAndIsDeletedIsFalseAndActionTypeIn( beforeDateTime.toInstant(), afterDateTime.toInstant(), diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPNOAndLANAlertRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPNOAndLANAlertRepository.kt index e7444b3ddf..038f8f39aa 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPNOAndLANAlertRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPNOAndLANAlertRepository.kt @@ -13,7 +13,6 @@ class JpaPNOAndLANAlertRepository( private val dbPNOAndLANAlertRepository: DBPNOAndLANAlertRepository, private val mapper: ObjectMapper, ) : PNOAndLANAlertRepository { - override fun save(alert: PNOAndLANAlert) { val alertEntity = PnoAndLanAlertEntity.fromAlert(alert, mapper) @@ -28,7 +27,11 @@ class JpaPNOAndLANAlertRepository( ) } - override fun findAlertsOfTypes(types: List, internalReferenceNumber: String, tripNumber: String): List { + override fun findAlertsOfTypes( + types: List, + internalReferenceNumber: String, + tripNumber: String, + ): List { val rulesAsString = types.map { it.name } return dbPNOAndLANAlertRepository.findAlertsOfRules(rulesAsString, internalReferenceNumber, tripNumber) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPendingAlertRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPendingAlertRepository.kt index 591f5ac822..8f446ae603 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPendingAlertRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPendingAlertRepository.kt @@ -13,7 +13,6 @@ class JpaPendingAlertRepository( private val dbPendingAlertRepository: DBPendingAlertRepository, private val mapper: ObjectMapper, ) : PendingAlertRepository { - override fun save(alert: PendingAlert) { dbPendingAlertRepository.save(PendingAlertEntity.fromPendingAlert(alert, mapper)) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPnoSegmentSubscriptionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPnoSegmentSubscriptionRepository.kt index 0468d0164e..5e92c76e6c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPnoSegmentSubscriptionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPnoSegmentSubscriptionRepository.kt @@ -8,7 +8,10 @@ import org.springframework.stereotype.Repository class JpaPnoSegmentSubscriptionRepository( private val dbPnoSegmentsSubscriptionsRepository: DBPnoSegmentsSubscriptionsRepository, ) : PnoSegmentSubscriptionRepository { - override fun has(portLocode: String, segmentCodes: List): Boolean { + override fun has( + portLocode: String, + segmentCodes: List, + ): Boolean { return dbPnoSegmentsSubscriptionsRepository.countByPortLocodeAndSegmentCodes(portLocode, segmentCodes) > 0 } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPnoTypeRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPnoTypeRepository.kt index 19f0d81f0a..53b849165c 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPnoTypeRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPnoTypeRepository.kt @@ -8,7 +8,6 @@ import org.springframework.stereotype.Repository @Repository class JpaPnoTypeRepository(private val dbPnoTypeRepository: DBPnoTypeRepository) : PnoTypeRepository { - @Cacheable(value = ["pno_types"]) override fun findAll(): List { return dbPnoTypeRepository.findAll().map { it.toPnoType() } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPortRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPortRepository.kt index dfe243b760..3d0d96606b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPortRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPortRepository.kt @@ -10,7 +10,6 @@ import org.springframework.stereotype.Repository @Repository class JpaPortRepository(private val dbPortRepository: DBPortRepository) : PortRepository { - @Cacheable(value = ["ports"]) override fun findAll(): List { return dbPortRepository.findAll().map { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPositionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPositionRepository.kt index e507de2a3e..a70cd6614b 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPositionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPositionRepository.kt @@ -14,7 +14,6 @@ import java.time.ZonedDateTime @Repository class JpaPositionRepository(private val dbPositionRepository: DBPositionRepository) : PositionRepository { - private val logger: Logger = LoggerFactory.getLogger(JpaPositionRepository::class.java) override fun findAll(): List { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRecentPositionsMetricsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRecentPositionsMetricsRepository.kt index 896672d02a..4b57c5ce25 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRecentPositionsMetricsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRecentPositionsMetricsRepository.kt @@ -9,7 +9,6 @@ import org.springframework.stereotype.Repository class JpaRecentPositionsMetricsRepository( private val recentPositionsMetricsRepository: DBRecentPositionsMetricsRepository, ) : RecentPositionsMetricsRepository { - @Cacheable(value = ["sudden_drop_of_positions_received"]) override fun findSuddenDropOfPositionsReceived(): Boolean { return recentPositionsMetricsRepository.findSuddenDropOfPositionsReceived() diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSilencedAlertRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSilencedAlertRepository.kt index 04731addbb..7b7ba29e23 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSilencedAlertRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSilencedAlertRepository.kt @@ -14,7 +14,6 @@ class JpaSilencedAlertRepository( private val dbSilencedAlertRepository: DBSilencedAlertRepository, private val mapper: ObjectMapper, ) : SilencedAlertRepository { - override fun save( alert: PendingAlert, silencedBeforeDate: ZonedDateTime, @@ -25,9 +24,7 @@ class JpaSilencedAlertRepository( ).toSilencedAlert(mapper) } - override fun save( - silencedAlert: SilencedAlert, - ): SilencedAlert { + override fun save(silencedAlert: SilencedAlert): SilencedAlert { return dbSilencedAlertRepository.save( SilencedAlertEntity.fromSilencedAlert(mapper, silencedAlert), ).toSilencedAlert(mapper) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesGroupRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesGroupRepository.kt index 3fbfd7c2ae..9e2be0a53e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesGroupRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesGroupRepository.kt @@ -10,7 +10,6 @@ import org.springframework.stereotype.Repository class JpaSpeciesGroupRepository( private val dbSpeciesGroupRepository: DBSpeciesGroupRepository, ) : SpeciesGroupRepository { - @Cacheable(value = ["all_species_groups"]) override fun findAll(): List { return dbSpeciesGroupRepository.findAll().map { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesRepository.kt index 3c058b9284..2451364ff5 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesRepository.kt @@ -10,7 +10,6 @@ import org.springframework.stereotype.Repository @Repository class JpaSpeciesRepository(private val dbSpeciesRepository: DBSpeciesRepository) : SpeciesRepository { - @Cacheable(value = ["all_species"]) override fun findAll(): List { return dbSpeciesRepository.findAll().map { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBBeaconMalfunctionsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBBeaconMalfunctionsRepository.kt index 9eb2df0b37..241ed0e309 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBBeaconMalfunctionsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBBeaconMalfunctionsRepository.kt @@ -22,14 +22,22 @@ interface DBBeaconMalfunctionsRepository : CrudRepository + fun findAllByVesselIdEqualsAfterDateTime( + vesselId: Int, + afterDateTime: Instant, + ): List @Modifying(clearAutomatically = true) @Query( diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBBeaconRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBBeaconRepository.kt index b446d1d9b8..cc40401d67 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBBeaconRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBBeaconRepository.kt @@ -7,7 +7,9 @@ import org.springframework.data.repository.query.Param interface DBBeaconRepository : CrudRepository { @Query(value = "SELECT * FROM beacons WHERE beacon_number LIKE %:searched% limit 20", nativeQuery = true) - fun searchBy(@Param("searched") searched: String): List + fun searchBy( + @Param("searched") searched: String, + ): List fun findByVesselId(vesselId: Int): BeaconEntity diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBControlObjectivesRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBControlObjectivesRepository.kt index 889bc3e023..12d4faee91 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBControlObjectivesRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBControlObjectivesRepository.kt @@ -11,21 +11,30 @@ interface DBControlObjectivesRepository : CrudRepository @@ -43,7 +52,10 @@ interface DBControlObjectivesRepository : CrudRepository { value = "UPDATE fleet_segments SET segment = :nextSegment WHERE segment = :segment and year = :year", nativeQuery = true, ) - fun updateSegment(segment: String, nextSegment: String, year: Int) + fun updateSegment( + segment: String, + nextSegment: String, + year: Int, + ) @Modifying(clearAutomatically = true) @Query( value = "UPDATE fleet_segments SET segment_name = :segmentName WHERE segment = :segment and year = :year", nativeQuery = true, ) - fun updateSegmentName(segment: String, segmentName: String, year: Int) + fun updateSegmentName( + segment: String, + segmentName: String, + year: Int, + ) @Modifying(clearAutomatically = true) @Query( value = "UPDATE fleet_segments SET gears = cast(:gears AS varchar[]) WHERE segment = :segment and year = :year", nativeQuery = true, ) - fun updateGears(segment: String, gears: String, year: Int) + fun updateGears( + segment: String, + gears: String, + year: Int, + ) @Modifying(clearAutomatically = true) @Query( value = "UPDATE fleet_segments SET fao_areas = cast(:faoAreas AS varchar[]) WHERE segment = :segment and year = :year", nativeQuery = true, ) - fun updateFAOAreas(segment: String, faoAreas: String, year: Int) + fun updateFAOAreas( + segment: String, + faoAreas: String, + year: Int, + ) @Modifying(clearAutomatically = true) @Query( value = "UPDATE fleet_segments SET target_species = cast(:targetSpecies AS varchar[]) WHERE segment = :segment and year = :year", nativeQuery = true, ) - fun updateTargetSpecies(segment: String, targetSpecies: String, year: Int) + fun updateTargetSpecies( + segment: String, + targetSpecies: String, + year: Int, + ) @Modifying(clearAutomatically = true) @Query( value = "UPDATE fleet_segments SET bycatch_species = cast(:bycatchSpecies AS varchar[]) WHERE segment = :segment and year = :year", nativeQuery = true, ) - fun updateBycatchSpecies(segment: String, bycatchSpecies: String, year: Int) + fun updateBycatchSpecies( + segment: String, + bycatchSpecies: String, + year: Int, + ) @Modifying(clearAutomatically = true) @Query( value = "UPDATE fleet_segments SET impact_risk_factor = :impactRiskFactor WHERE segment = :segment and year = :year", nativeQuery = true, ) - fun updateImpactRiskFactor(segment: String, impactRiskFactor: Double, year: Int) + fun updateImpactRiskFactor( + segment: String, + impactRiskFactor: Double, + year: Int, + ) @Query - fun findBySegmentAndYearEquals(segment: String, year: Int): FleetSegmentEntity + fun findBySegmentAndYearEquals( + segment: String, + year: Int, + ): FleetSegmentEntity @Modifying(clearAutomatically = true) @Query("DELETE FROM fleet_segments where segment = :segment and year = :year", nativeQuery = true) - fun deleteBySegmentAndYearEquals(segment: String, year: Int) + fun deleteBySegmentAndYearEquals( + segment: String, + year: Int, + ) @Query fun findAllByYearEquals(year: Int): List @@ -78,5 +112,8 @@ interface DBFleetSegmentRepository : CrudRepository { """, nativeQuery = true, ) - fun duplicateCurrentYearAsNextYear(currentYear: Int, nextYear: Int) + fun duplicateCurrentYearAsNextYear( + currentYear: Int, + nextYear: Int, + ) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBManualPriorNotificationRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBManualPriorNotificationRepository.kt index 29ce8ed7f8..2089806256 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBManualPriorNotificationRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBManualPriorNotificationRepository.kt @@ -23,7 +23,7 @@ interface DBManualPriorNotificationRepository : JpaRepository vesselId: Int, afterDateTime: Instant, ): List + fun findAllByActionDatetimeUtcBeforeAndActionDatetimeUtcAfterAndIsDeletedIsFalseAndActionTypeIn( beforeDateTime: Instant, afterDateTime: Instant, actionTypes: List, ): List + fun findAllByMissionIdAndIsDeletedIsFalse(missionId: Int): List + fun findAllByMissionIdInAndIsDeletedIsFalse(missionIds: List): List } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPnoSegmentsSubscriptionsRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPnoSegmentsSubscriptionsRepository.kt index 5d37284aa1..b5b6bf369f 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPnoSegmentsSubscriptionsRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPnoSegmentsSubscriptionsRepository.kt @@ -15,5 +15,8 @@ interface DBPnoSegmentsSubscriptionsRepository : JpaRepository): Long + fun countByPortLocodeAndSegmentCodes( + portLocode: String, + segmentCodes: List, + ): Long } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPortRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPortRepository.kt index d7156e544d..c75f7b91d8 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPortRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPortRepository.kt @@ -5,5 +5,6 @@ import org.springframework.data.repository.CrudRepository interface DBPortRepository : CrudRepository { fun findByLocodeEquals(locode: String): PortEntity + fun findAllByIsActiveIsTrue(): List } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPositionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPositionRepository.kt index 66ac01ae5a..e0fc2a5d55 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPositionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBPositionRepository.kt @@ -10,32 +10,33 @@ interface DBPositionRepository : CrudRepository { fun findAllByMmsi(mmsi: String): List @Query( - value = "select distinct " + - "p.internal_reference_number, " + - "p.external_reference_number, " + - "p.mmsi, " + - "p.ircs, " + - "p.id, " + - "p.date_time, " + - "p.vessel_name, " + - "p.flag_state, " + - "p.from_country, " + - "p.destination_country, " + - "p.trip_number, " + - "p.latitude, " + - "p.longitude, " + - "p.speed, " + - "p.course, " + - "p.position_type, " + - "p.is_manual, " + - "p.is_fishing, " + - "p.is_at_port, " + - "p.network_type " + - "from positions p " + - "where p.internal_reference_number = :internalReferenceNumber " + - "and p.date_time >= :from " + - "and p.date_time <= :to " + - "order by p.date_time DESC ", + value = + "select distinct " + + "p.internal_reference_number, " + + "p.external_reference_number, " + + "p.mmsi, " + + "p.ircs, " + + "p.id, " + + "p.date_time, " + + "p.vessel_name, " + + "p.flag_state, " + + "p.from_country, " + + "p.destination_country, " + + "p.trip_number, " + + "p.latitude, " + + "p.longitude, " + + "p.speed, " + + "p.course, " + + "p.position_type, " + + "p.is_manual, " + + "p.is_fishing, " + + "p.is_at_port, " + + "p.network_type " + + "from positions p " + + "where p.internal_reference_number = :internalReferenceNumber " + + "and p.date_time >= :from " + + "and p.date_time <= :to " + + "order by p.date_time DESC ", nativeQuery = true, ) fun findLastByInternalReferenceNumber( @@ -45,32 +46,33 @@ interface DBPositionRepository : CrudRepository { ): List @Query( - value = "select distinct " + - "p.internal_reference_number, " + - "p.external_reference_number, " + - "p.mmsi, " + - "p.ircs, " + - "p.id, " + - "p.date_time, " + - "p.vessel_name, " + - "p.flag_state, " + - "p.from_country, " + - "p.destination_country, " + - "p.trip_number, " + - "p.latitude, " + - "p.longitude, " + - "p.speed, " + - "p.course, " + - "p.position_type, " + - "p.is_manual, " + - "p.is_fishing, " + - "p.is_at_port, " + - "p.network_type " + - "from positions p " + - "where p.external_reference_number = :externalReferenceNumber " + - "and p.date_time >= :from " + - "and p.date_time <= :to " + - "order by p.date_time DESC ", + value = + "select distinct " + + "p.internal_reference_number, " + + "p.external_reference_number, " + + "p.mmsi, " + + "p.ircs, " + + "p.id, " + + "p.date_time, " + + "p.vessel_name, " + + "p.flag_state, " + + "p.from_country, " + + "p.destination_country, " + + "p.trip_number, " + + "p.latitude, " + + "p.longitude, " + + "p.speed, " + + "p.course, " + + "p.position_type, " + + "p.is_manual, " + + "p.is_fishing, " + + "p.is_at_port, " + + "p.network_type " + + "from positions p " + + "where p.external_reference_number = :externalReferenceNumber " + + "and p.date_time >= :from " + + "and p.date_time <= :to " + + "order by p.date_time DESC ", nativeQuery = true, ) fun findLastByExternalReferenceNumber( @@ -80,35 +82,40 @@ interface DBPositionRepository : CrudRepository { ): List @Query( - value = "select distinct " + - "p.internal_reference_number, " + - "p.external_reference_number, " + - "p.mmsi, " + - "p.ircs, " + - "p.id, " + - "p.date_time, " + - "p.vessel_name, " + - "p.flag_state, " + - "p.from_country, " + - "p.destination_country, " + - "p.trip_number, " + - "p.latitude, " + - "p.longitude, " + - "p.speed, " + - "p.course, " + - "p.position_type, " + - "p.is_manual, " + - "p.is_fishing, " + - "p.is_at_port, " + - "p.network_type " + - "from positions p " + - "where p.ircs = :ircs " + - "and p.date_time >= :from " + - "and p.date_time <= :to " + - "order by p.date_time DESC", + value = + "select distinct " + + "p.internal_reference_number, " + + "p.external_reference_number, " + + "p.mmsi, " + + "p.ircs, " + + "p.id, " + + "p.date_time, " + + "p.vessel_name, " + + "p.flag_state, " + + "p.from_country, " + + "p.destination_country, " + + "p.trip_number, " + + "p.latitude, " + + "p.longitude, " + + "p.speed, " + + "p.course, " + + "p.position_type, " + + "p.is_manual, " + + "p.is_fishing, " + + "p.is_at_port, " + + "p.network_type " + + "from positions p " + + "where p.ircs = :ircs " + + "and p.date_time >= :from " + + "and p.date_time <= :to " + + "order by p.date_time DESC", nativeQuery = true, ) - fun findLastByIrcs(ircs: String, from: ZonedDateTime, to: ZonedDateTime): List + fun findLastByIrcs( + ircs: String, + from: ZonedDateTime, + to: ZonedDateTime, + ): List @Query( "select date_time from positions where date_time < now() order by date_time desc limit 1", diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBRiskFactorRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBRiskFactorRepository.kt index 8898a6bd8c..f7e35dbf70 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBRiskFactorRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBRiskFactorRepository.kt @@ -14,5 +14,7 @@ interface DBRiskFactorRepository : JpaRepository { // Only used in tests @Query(value = "SELECT * FROM risk_factors WHERE cfr = :cfr LIMIT 1", nativeQuery = true) - fun findFirstByCfr(@Param("cfr") cfr: String): RiskFactorsEntity? + fun findFirstByCfr( + @Param("cfr") cfr: String, + ): RiskFactorsEntity? } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBVesselRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBVesselRepository.kt index 0be6148911..7b69dbbc5e 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBVesselRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/interfaces/DBVesselRepository.kt @@ -7,18 +7,23 @@ import org.springframework.data.repository.query.Param interface DBVesselRepository : CrudRepository { @Query( - value = "SELECT * FROM vessels WHERE cfr LIKE %:searched% " + - "OR mmsi LIKE %:searched% " + - "OR vessel_name LIKE %:searched% " + - "OR external_immatriculation LIKE %:searched% " + - "OR ircs LIKE %:searched% limit 50", + value = + "SELECT * FROM vessels WHERE cfr LIKE %:searched% " + + "OR mmsi LIKE %:searched% " + + "OR vessel_name LIKE %:searched% " + + "OR external_immatriculation LIKE %:searched% " + + "OR ircs LIKE %:searched% limit 50", nativeQuery = true, ) - fun searchBy(@Param("searched") searched: String): List + fun searchBy( + @Param("searched") searched: String, + ): List // Only used in tests @Query(value = "SELECT * FROM vessels WHERE cfr = :cfr LIMIT 1", nativeQuery = true) - fun findFirstByCfr(@Param("cfr") cfr: String): VesselEntity? + fun findFirstByCfr( + @Param("cfr") cfr: String, + ): VesselEntity? fun findByInternalReferenceNumber(internalReferenceNumber: String): VesselEntity @@ -58,5 +63,8 @@ interface DBVesselRepository : CrudRepository { """, nativeQuery = true, ) - fun findUnderCharterByVesselIdentifierEquals(vesselIdentifier: String, value: String): Boolean + fun findUnderCharterByVesselIdentifierEquals( + vesselIdentifier: String, + value: String, + ): Boolean } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepository.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepository.kt index 1e91c28717..90d96e7a89 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepository.kt @@ -29,7 +29,10 @@ class APIMissionRepository( private val zoneDateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.000X") @Cacheable(value = ["mission_control_units"]) - override fun findControlUnitsOfMission(scope: CoroutineScope, missionId: Int): Deferred> { + override fun findControlUnitsOfMission( + scope: CoroutineScope, + missionId: Int, + ): Deferred> { return scope.async { val missionsUrl = "${monitorenvProperties.url}/api/v1/missions/$missionId" @@ -54,30 +57,34 @@ class APIMissionRepository( seaFronts: List?, ): List { // For these parameters, if the list is null or empty, we don't send the param to the server to avoid filtering results - val missionTypesParameter = if (!missionTypes.isNullOrEmpty()) { - "missionTypes=${missionTypes.joinToString( - ",", - )}&" - } else { - "" - } - val missionStatusesParameter = if (!missionStatuses.isNullOrEmpty()) { - "missionStatus=${missionStatuses.joinToString( - ",", - )}&" - } else { - "" - } + val missionTypesParameter = + if (!missionTypes.isNullOrEmpty()) { + "missionTypes=${missionTypes.joinToString( + ",", + )}&" + } else { + "" + } + val missionStatusesParameter = + if (!missionStatuses.isNullOrEmpty()) { + "missionStatus=${missionStatuses.joinToString( + ",", + )}&" + } else { + "" + } val seaFrontsParameter = if (!seaFronts.isNullOrEmpty()) "seaFronts=${seaFronts.joinToString(",")}&" else "" - val missionSourcesParameter = if (!missionSources.isNullOrEmpty()) { - "missionSource=${missionSources.joinToString( - ",", - )}&" - } else { - "" - } + val missionSourcesParameter = + if (!missionSources.isNullOrEmpty()) { + "missionSource=${missionSources.joinToString( + ",", + )}&" + } else { + "" + } - val missionsUrl = """ + val missionsUrl = + """ ${monitorenvProperties.url}/api/v1/missions? pageNumber=${pageNumber ?: ""}& pageSize=${pageSize ?: ""}& @@ -87,7 +94,7 @@ class APIMissionRepository( $missionTypesParameter $missionStatusesParameter $seaFrontsParameter - """.trimIndent() + """.trimIndent() logger.info("Fetching missions at URL: $missionsUrl") return runBlocking { diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt index 4f9b7942d7..a9c1a43af3 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/EnvMissionActionDataResponse.kt @@ -19,12 +19,13 @@ data class EnvMissionActionDataResponse( val actionType: EnvMissionActionType, val observations: String? = null, ) { - fun toEnvMissionAction() = EnvMissionAction( - id = id, - actionStartDateTimeUtc = actionStartDateTimeUtc?.let { ZonedDateTime.parse(it) }, - actionType = actionType, - observations = observations, - ) + fun toEnvMissionAction() = + EnvMissionAction( + id = id, + actionStartDateTimeUtc = actionStartDateTimeUtc?.let { ZonedDateTime.parse(it) }, + actionType = actionType, + observations = observations, + ) } object UUIDSerializer : KSerializer { @@ -34,7 +35,10 @@ object UUIDSerializer : KSerializer { return UUID.fromString(decoder.decodeString()) } - override fun serialize(encoder: Encoder, value: UUID) { + override fun serialize( + encoder: Encoder, + value: UUID, + ) { encoder.encodeString(value.toString()) } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/MissionDataResponse.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/MissionDataResponse.kt index 330e546d16..5a2baca1a7 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/MissionDataResponse.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/input/MissionDataResponse.kt @@ -29,30 +29,32 @@ data class MissionDataResponse( val hasMissionOrder: Boolean? = false, val isUnderJdp: Boolean? = false, ) { - fun toMission() = Mission( - id = id, - controlUnits = controlUnits, - missionTypes = missionTypes, - openBy = openBy, - completedBy = completedBy, - observationsCacem = observationsCacem, - observationsCnsp = observationsCnsp, - facade = facade, - geom = geom, - startDateTimeUtc = ZonedDateTime.parse(startDateTimeUtc), - endDateTimeUtc = endDateTimeUtc?.let { ZonedDateTime.parse(endDateTimeUtc) }, - isGeometryComputedFromControls = isGeometryComputedFromControls, - missionSource = missionSource, - hasMissionOrder = hasMissionOrder, - isUnderJdp = isUnderJdp, - ) + fun toMission() = + Mission( + id = id, + controlUnits = controlUnits, + missionTypes = missionTypes, + openBy = openBy, + completedBy = completedBy, + observationsCacem = observationsCacem, + observationsCnsp = observationsCnsp, + facade = facade, + geom = geom, + startDateTimeUtc = ZonedDateTime.parse(startDateTimeUtc), + endDateTimeUtc = endDateTimeUtc?.let { ZonedDateTime.parse(endDateTimeUtc) }, + isGeometryComputedFromControls = isGeometryComputedFromControls, + missionSource = missionSource, + hasMissionOrder = hasMissionOrder, + isUnderJdp = isUnderJdp, + ) fun toFullMission(): Mission { - val mission = toMission().copy( - createdAtUtc = createdAtUtc?.let { ZonedDateTime.parse(createdAtUtc) }, - updatedAtUtc = updatedAtUtc?.let { ZonedDateTime.parse(updatedAtUtc) }, - envActions = envActions?.map { it.toEnvMissionAction() }, - ) + val mission = + toMission().copy( + createdAtUtc = createdAtUtc?.let { ZonedDateTime.parse(createdAtUtc) }, + updatedAtUtc = updatedAtUtc?.let { ZonedDateTime.parse(updatedAtUtc) }, + envActions = envActions?.map { it.toEnvMissionAction() }, + ) return mission } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTime.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTime.kt index 6bb08852c7..e4a9b67385 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTime.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTime.kt @@ -27,9 +27,10 @@ data class CustomZonedDateTime(private val dateAsZonedDateTime: ZonedDateTime) { } fun parse(dateAsString: String): CustomZonedDateTime { - val dateAsUtcZonedDateTime = ZonedDateTime - .parse(dateAsString, dateTimeFormatter) - .withZoneSameInstant(ZoneOffset.UTC) + val dateAsUtcZonedDateTime = + ZonedDateTime + .parse(dateAsString, dateTimeFormatter) + .withZoneSameInstant(ZoneOffset.UTC) return CustomZonedDateTime(dateAsUtcZonedDateTime) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTimeDeserializer.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTimeDeserializer.kt index c4465fedfb..af70bd1a55 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTimeDeserializer.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTimeDeserializer.kt @@ -12,9 +12,10 @@ class CustomZonedDateTimeDeserializer : JsonDeserializer() jsonParser: JsonParser, deserializationContext: DeserializationContext, ): CustomZonedDateTime { - val zonedDateTime = ZonedDateTime - .parse(jsonParser.text, DateTimeFormatter.ISO_DATE_TIME) - .withZoneSameInstant(ZoneOffset.UTC) + val zonedDateTime = + ZonedDateTime + .parse(jsonParser.text, DateTimeFormatter.ISO_DATE_TIME) + .withZoneSameInstant(ZoneOffset.UTC) return CustomZonedDateTime(zonedDateTime) } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTimeSerializer.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTimeSerializer.kt index 281d37f87a..a7544c96fb 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTimeSerializer.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/utils/CustomZonedDateTimeSerializer.kt @@ -11,10 +11,11 @@ class CustomZonedDateTimeSerializer : JsonSerializer() { jsonGenerator: JsonGenerator, serializerProvider: SerializerProvider, ) { - val dateAsString = zonedDateTime - .toZonedDateTime() - .withZoneSameInstant(ZoneOffset.UTC) - .format(CustomZonedDateTime.dateTimeFormatter) + val dateAsString = + zonedDateTime + .toZonedDateTime() + .withZoneSameInstant(ZoneOffset.UTC) + .format(CustomZonedDateTime.dateTimeFormatter) jsonGenerator.writeString(dateAsString) } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/CountryCodeUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/CountryCodeUTests.kt index 8de1cc4ceb..d936202e32 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/CountryCodeUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/CountryCodeUTests.kt @@ -8,264 +8,264 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class CountryCodeUTests { - @Test fun `country codes from NAVPRO should be included in CountryCode library`() { // Given these country codes from NAVPRO - val countryCodesFromNavpro = listOf( - "NA", - "NE", - "NF", - "NG", - "NI", - "NL", - "NO", - "NP", - "NR", - "NU", - "NZ", - "OM", - "PA", - "PE", - "PF", - "PG", - "PH", - "PK", - "PL", - "PM", - "PN", - "PR", - "PS", - "PT", - "PW", - "PY", - "QA", - "RE", - "RO", - "RU", - "RW", - "SA", - "SB", - "SC", - "SD", - "SE", - "SG", - "SH", - "SI", - "SJ", - "SK", - "SL", - "SM", - "SN", - "SO", - "SR", - "ST", - "SV", - "SY", - "SZ", - "TC", - "TD", - "TF", - "TG", - "TH", - "TJ", - "TK", - "TM", - "TN", - "TO", - "TP", - "TR", - "TT", - "TV", - "TW", - "TZ", - "UA", - "UG", - "UM", - "US", - "UY", - "UZ", - "VA", - "VC", - "VE", - "VG", - "VI", - "VN", - "VU", - "WF", - "WS", - "YE", - "YT", - "YU", - "ZA", - "ZM", - "ZW", - "CS", - "MA", - "AI", - "AQ", - "BO", - "BW", - "CF", - "CV", - "DO", - "ER", - "FX", - "GB", - "GQ", - "GT", - "GY", - "HM", - "IO", - "KH", - "KZ", - "LC", - "MP", - "MW", - "NC", - "BR", - "CH", - "CO", - "DM", - "EG", - "FJ", - "FO", - "GI", - "IL", - "JM", - "KI", - "KP", - "KY", - "LR", - "MH", - "MV", - "MZ", - "AE", - "AN", - "AS", - "BA", - "BH", - "BN", - "AG", - "BG", - "CD", - "FI", - "GW", - "IN", - "KR", - "LU", - "MT", - "MD", - "AD", - "AF", - "AL", - "AM", - "AO", - "AR", - "AT", - "AU", - "AW", - "AZ", - "BB", - "BD", - "BE", - "BF", - "BI", - "BJ", - "BM", - "BS", - "BT", - "BV", - "BY", - "BZ", - "CA", - "CC", - "CG", - "CI", - "CK", - "CL", - "CM", - "CN", - "CR", - "CU", - "CX", - "CY", - "CZ", - "DE", - "DJ", - "DK", - "DZ", - "EC", - "EE", - "EH", - "ES", - "ET", - "FK", - "FM", - "FR", - "GA", - "GD", - "GE", - "GF", - "GH", - "GL", - "GM", - "GN", - "GP", - "GR", - "GS", - "GU", - "HK", - "HN", - "HR", - "HT", - "HU", - "ID", - "IE", - "IQ", - "IR", - "IS", - "IT", - "JO", - "JP", - "KE", - "KG", - "KM", - "KN", - "KW", - "LA", - "LB", - "LI", - "LK", - "LS", - "LT", - "LV", - "LY", - "MC", - "MG", - "MK", - "ML", - "MM", - "MN", - "MO", - "MQ", - "MR", - "MS", - "MU", - "MX", - "MY", - "CW", - "GG", - "IM", - "JE", - "ME", - "BQ", - "BL", - "MF", - "SX", - "RS", - "SS", - ) + val countryCodesFromNavpro = + listOf( + "NA", + "NE", + "NF", + "NG", + "NI", + "NL", + "NO", + "NP", + "NR", + "NU", + "NZ", + "OM", + "PA", + "PE", + "PF", + "PG", + "PH", + "PK", + "PL", + "PM", + "PN", + "PR", + "PS", + "PT", + "PW", + "PY", + "QA", + "RE", + "RO", + "RU", + "RW", + "SA", + "SB", + "SC", + "SD", + "SE", + "SG", + "SH", + "SI", + "SJ", + "SK", + "SL", + "SM", + "SN", + "SO", + "SR", + "ST", + "SV", + "SY", + "SZ", + "TC", + "TD", + "TF", + "TG", + "TH", + "TJ", + "TK", + "TM", + "TN", + "TO", + "TP", + "TR", + "TT", + "TV", + "TW", + "TZ", + "UA", + "UG", + "UM", + "US", + "UY", + "UZ", + "VA", + "VC", + "VE", + "VG", + "VI", + "VN", + "VU", + "WF", + "WS", + "YE", + "YT", + "YU", + "ZA", + "ZM", + "ZW", + "CS", + "MA", + "AI", + "AQ", + "BO", + "BW", + "CF", + "CV", + "DO", + "ER", + "FX", + "GB", + "GQ", + "GT", + "GY", + "HM", + "IO", + "KH", + "KZ", + "LC", + "MP", + "MW", + "NC", + "BR", + "CH", + "CO", + "DM", + "EG", + "FJ", + "FO", + "GI", + "IL", + "JM", + "KI", + "KP", + "KY", + "LR", + "MH", + "MV", + "MZ", + "AE", + "AN", + "AS", + "BA", + "BH", + "BN", + "AG", + "BG", + "CD", + "FI", + "GW", + "IN", + "KR", + "LU", + "MT", + "MD", + "AD", + "AF", + "AL", + "AM", + "AO", + "AR", + "AT", + "AU", + "AW", + "AZ", + "BB", + "BD", + "BE", + "BF", + "BI", + "BJ", + "BM", + "BS", + "BT", + "BV", + "BY", + "BZ", + "CA", + "CC", + "CG", + "CI", + "CK", + "CL", + "CM", + "CN", + "CR", + "CU", + "CX", + "CY", + "CZ", + "DE", + "DJ", + "DK", + "DZ", + "EC", + "EE", + "EH", + "ES", + "ET", + "FK", + "FM", + "FR", + "GA", + "GD", + "GE", + "GF", + "GH", + "GL", + "GM", + "GN", + "GP", + "GR", + "GS", + "GU", + "HK", + "HN", + "HR", + "HT", + "HU", + "ID", + "IE", + "IQ", + "IR", + "IS", + "IT", + "JO", + "JP", + "KE", + "KG", + "KM", + "KN", + "KW", + "LA", + "LB", + "LI", + "LK", + "LS", + "LT", + "LV", + "LY", + "MC", + "MG", + "MK", + "ML", + "MM", + "MN", + "MO", + "MQ", + "MR", + "MS", + "MU", + "MX", + "MY", + "CW", + "GG", + "IM", + "JE", + "ME", + "BQ", + "BL", + "MF", + "SX", + "RS", + "SS", + ) // When countryCodesFromNavpro.forEach { diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/beacon_malfunctions/VesselBeaconMalfunctionsResumeUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/beacon_malfunctions/VesselBeaconMalfunctionsResumeUTests.kt index 14e196c4e7..52f6470a8b 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/beacon_malfunctions/VesselBeaconMalfunctionsResumeUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/beacon_malfunctions/VesselBeaconMalfunctionsResumeUTests.kt @@ -9,128 +9,140 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class VesselBeaconMalfunctionsResumeUTests { - @Test fun `fromBeaconMalfunctions Should create the resume When there is some actions`() { // Given val now = ZonedDateTime.now() val lastBeaconDateTime = now.minusMinutes(2) - val beaconMalfunctions = listOf( - BeaconMalfunctionWithDetails( - beaconMalfunction = BeaconMalfunction( - 1, "FR224226850", "1236514", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, - Stage.ARCHIVED, now.minusYears(2), null, now.minusYears(2), - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - beaconMalfunctionId = 1, - comment = "A comment", - userType = BeaconMalfunctionCommentUserType.SIP, - dateTime = now.minusYears(2), - ), - ), - actions = listOf( - BeaconMalfunctionAction( - beaconMalfunctionId = 1, - propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - nextValue = "A VALUE", - previousValue = VesselStatus.AT_SEA.toString(), - dateTime = now.minusYears(2), - ), - ), - ), - BeaconMalfunctionWithDetails( - beaconMalfunction = BeaconMalfunction( - 2, "FR224226850", "1236514", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, - Stage.ARCHIVED, now.minusMinutes(23), null, now.minusMinutes(23), - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - beaconMalfunctionId = 1, - comment = "A comment", - userType = BeaconMalfunctionCommentUserType.SIP, - dateTime = now.minusMinutes(23), - ), - ), - actions = listOf( - BeaconMalfunctionAction( - beaconMalfunctionId = 1, - propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - nextValue = "A VALUE", - previousValue = VesselStatus.AT_SEA.toString(), - dateTime = now.minusMinutes(23), - ), - ), - ), - BeaconMalfunctionWithDetails( - beaconMalfunction = BeaconMalfunction( - 3, "FR224226850", "1236514", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, - Stage.ARCHIVED, now.minusMinutes(5), null, now.minusMinutes(5), - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - beaconMalfunctionId = 1, - comment = "A comment", - userType = BeaconMalfunctionCommentUserType.SIP, - dateTime = now.minusMinutes(5), - ), - ), - actions = listOf( - BeaconMalfunctionAction( - beaconMalfunctionId = 1, - propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - nextValue = "A VALUE", - previousValue = VesselStatus.AT_PORT.toString(), - dateTime = now.minusMinutes(5), - ), - BeaconMalfunctionAction( - beaconMalfunctionId = 1, - propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - nextValue = "A VALUE", - previousValue = VesselStatus.AT_SEA.toString(), - dateTime = now.minusMinutes(4), - ), - ), - ), - BeaconMalfunctionWithDetails( - beaconMalfunction = BeaconMalfunction( - 4, "FR224226850", "1236514", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_PORT, - Stage.ARCHIVED, lastBeaconDateTime, null, lastBeaconDateTime, - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - beaconMalfunctionId = 1, - comment = "A comment", - userType = BeaconMalfunctionCommentUserType.SIP, - dateTime = lastBeaconDateTime, - ), - ), - actions = listOf( - BeaconMalfunctionAction( - beaconMalfunctionId = 1, - propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - nextValue = VesselStatus.ACTIVITY_DETECTED.toString(), - previousValue = VesselStatus.AT_SEA.toString(), - dateTime = lastBeaconDateTime, - ), - BeaconMalfunctionAction( - beaconMalfunctionId = 1, - propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - nextValue = VesselStatus.ACTIVITY_DETECTED.toString(), - previousValue = VesselStatus.ACTIVITY_DETECTED.toString(), - dateTime = now.minusMinutes(1), - ), - ), - ), - ) + val beaconMalfunctions = + listOf( + BeaconMalfunctionWithDetails( + beaconMalfunction = + BeaconMalfunction( + 1, "FR224226850", "1236514", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, + Stage.ARCHIVED, now.minusYears(2), null, now.minusYears(2), + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, + ), + comments = + listOf( + BeaconMalfunctionComment( + beaconMalfunctionId = 1, + comment = "A comment", + userType = BeaconMalfunctionCommentUserType.SIP, + dateTime = now.minusYears(2), + ), + ), + actions = + listOf( + BeaconMalfunctionAction( + beaconMalfunctionId = 1, + propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + nextValue = "A VALUE", + previousValue = VesselStatus.AT_SEA.toString(), + dateTime = now.minusYears(2), + ), + ), + ), + BeaconMalfunctionWithDetails( + beaconMalfunction = + BeaconMalfunction( + 2, "FR224226850", "1236514", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, + Stage.ARCHIVED, now.minusMinutes(23), null, now.minusMinutes(23), + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, + ), + comments = + listOf( + BeaconMalfunctionComment( + beaconMalfunctionId = 1, + comment = "A comment", + userType = BeaconMalfunctionCommentUserType.SIP, + dateTime = now.minusMinutes(23), + ), + ), + actions = + listOf( + BeaconMalfunctionAction( + beaconMalfunctionId = 1, + propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + nextValue = "A VALUE", + previousValue = VesselStatus.AT_SEA.toString(), + dateTime = now.minusMinutes(23), + ), + ), + ), + BeaconMalfunctionWithDetails( + beaconMalfunction = + BeaconMalfunction( + 3, "FR224226850", "1236514", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, + Stage.ARCHIVED, now.minusMinutes(5), null, now.minusMinutes(5), + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, + ), + comments = + listOf( + BeaconMalfunctionComment( + beaconMalfunctionId = 1, + comment = "A comment", + userType = BeaconMalfunctionCommentUserType.SIP, + dateTime = now.minusMinutes(5), + ), + ), + actions = + listOf( + BeaconMalfunctionAction( + beaconMalfunctionId = 1, + propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + nextValue = "A VALUE", + previousValue = VesselStatus.AT_PORT.toString(), + dateTime = now.minusMinutes(5), + ), + BeaconMalfunctionAction( + beaconMalfunctionId = 1, + propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + nextValue = "A VALUE", + previousValue = VesselStatus.AT_SEA.toString(), + dateTime = now.minusMinutes(4), + ), + ), + ), + BeaconMalfunctionWithDetails( + beaconMalfunction = + BeaconMalfunction( + 4, "FR224226850", "1236514", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_PORT, + Stage.ARCHIVED, lastBeaconDateTime, null, lastBeaconDateTime, + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, + ), + comments = + listOf( + BeaconMalfunctionComment( + beaconMalfunctionId = 1, + comment = "A comment", + userType = BeaconMalfunctionCommentUserType.SIP, + dateTime = lastBeaconDateTime, + ), + ), + actions = + listOf( + BeaconMalfunctionAction( + beaconMalfunctionId = 1, + propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + nextValue = VesselStatus.ACTIVITY_DETECTED.toString(), + previousValue = VesselStatus.AT_SEA.toString(), + dateTime = lastBeaconDateTime, + ), + BeaconMalfunctionAction( + beaconMalfunctionId = 1, + propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + nextValue = VesselStatus.ACTIVITY_DETECTED.toString(), + previousValue = VesselStatus.ACTIVITY_DETECTED.toString(), + dateTime = now.minusMinutes(1), + ), + ), + ), + ) // When val resume = VesselBeaconMalfunctionsResume.fromBeaconMalfunctions(beaconMalfunctions) @@ -147,42 +159,47 @@ class VesselBeaconMalfunctionsResumeUTests { // Given val now = ZonedDateTime.now() val lastBeaconDateTime = now.minusMinutes(2) - val beaconMalfunctions = listOf( - BeaconMalfunctionWithDetails( - beaconMalfunction = BeaconMalfunction( - 1, "FR224226850", "1236514", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, - Stage.ARCHIVED, lastBeaconDateTime, null, lastBeaconDateTime, - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - beaconMalfunctionId = 1, - comment = "A comment", - userType = BeaconMalfunctionCommentUserType.SIP, - dateTime = lastBeaconDateTime, - ), - ), - actions = listOf(), - ), - BeaconMalfunctionWithDetails( - beaconMalfunction = BeaconMalfunction( - 2, "FR224226852", "1236514", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_PORT, - Stage.ARCHIVED, now, null, now, - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - beaconMalfunctionId = 1, - comment = "A comment", - userType = BeaconMalfunctionCommentUserType.SIP, - dateTime = now, - ), - ), - actions = listOf(), - ), - ) + val beaconMalfunctions = + listOf( + BeaconMalfunctionWithDetails( + beaconMalfunction = + BeaconMalfunction( + 1, "FR224226850", "1236514", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, + Stage.ARCHIVED, lastBeaconDateTime, null, lastBeaconDateTime, + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, + ), + comments = + listOf( + BeaconMalfunctionComment( + beaconMalfunctionId = 1, + comment = "A comment", + userType = BeaconMalfunctionCommentUserType.SIP, + dateTime = lastBeaconDateTime, + ), + ), + actions = listOf(), + ), + BeaconMalfunctionWithDetails( + beaconMalfunction = + BeaconMalfunction( + 2, "FR224226852", "1236514", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_PORT, + Stage.ARCHIVED, now, null, now, + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, + ), + comments = + listOf( + BeaconMalfunctionComment( + beaconMalfunctionId = 1, + comment = "A comment", + userType = BeaconMalfunctionCommentUserType.SIP, + dateTime = now, + ), + ), + actions = listOf(), + ), + ) // When val resume = VesselBeaconMalfunctionsResume.fromBeaconMalfunctions(beaconMalfunctions) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessageUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessageUTests.kt index bde3151b61..7b47e56b4f 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessageUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessageUTests.kt @@ -41,16 +41,18 @@ class LogbookMessageUTests { @Test fun `setAcknowledge should create a new successful acknowledgment when current is null`() { // Given - val logbookMessage = getFakeLogbookMessage( - LogbookOperationType.DAT, - ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), - ) - val newAcknowledgmentMessage = getFakeLogbookMessage( - LogbookOperationType.RET, - ZonedDateTime.of(2024, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC), - logbookMessage.reportId, - Acknowledgment(returnStatus = "000"), - ) + val logbookMessage = + getFakeLogbookMessage( + LogbookOperationType.DAT, + ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), + ) + val newAcknowledgmentMessage = + getFakeLogbookMessage( + LogbookOperationType.RET, + ZonedDateTime.of(2024, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC), + logbookMessage.reportId, + Acknowledgment(returnStatus = "000"), + ) // When logbookMessage.setAcknowledge(newAcknowledgmentMessage) @@ -64,16 +66,18 @@ class LogbookMessageUTests { @Test fun `setAcknowledge should create a new unsuccessful acknowledgment when current is null`() { // Given - val logbookMessage = getFakeLogbookMessage( - LogbookOperationType.DAT, - ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), - ) - val newAcknowledgmentMessage = getFakeLogbookMessage( - LogbookOperationType.RET, - ZonedDateTime.of(2024, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC), - logbookMessage.reportId, - Acknowledgment(returnStatus = "001"), - ) + val logbookMessage = + getFakeLogbookMessage( + LogbookOperationType.DAT, + ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), + ) + val newAcknowledgmentMessage = + getFakeLogbookMessage( + LogbookOperationType.RET, + ZonedDateTime.of(2024, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC), + logbookMessage.reportId, + Acknowledgment(returnStatus = "001"), + ) // When logbookMessage.setAcknowledge(newAcknowledgmentMessage) @@ -87,21 +91,24 @@ class LogbookMessageUTests { @Test fun `setAcknowledge should update to a new acknowledgment when it's a SUCCESSFUL one while the current is a FAILED one, whenever it happened`() { // Given - val firstLogbookMessage = getFakeLogbookMessage( - LogbookOperationType.DAT, - ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), - ).copy( - acknowledgment = Acknowledgment( - isSuccess = false, - dateTime = ZonedDateTime.of(2024, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC), - ), - ) - val firstNewAcknowledgmentMessage = getFakeLogbookMessage( - LogbookOperationType.RET, - ZonedDateTime.of(2024, 1, 1, 0, 0, 2, 0, ZoneOffset.UTC), - firstLogbookMessage.reportId, - Acknowledgment(returnStatus = "000"), - ) + val firstLogbookMessage = + getFakeLogbookMessage( + LogbookOperationType.DAT, + ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), + ).copy( + acknowledgment = + Acknowledgment( + isSuccess = false, + dateTime = ZonedDateTime.of(2024, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC), + ), + ) + val firstNewAcknowledgmentMessage = + getFakeLogbookMessage( + LogbookOperationType.RET, + ZonedDateTime.of(2024, 1, 1, 0, 0, 2, 0, ZoneOffset.UTC), + firstLogbookMessage.reportId, + Acknowledgment(returnStatus = "000"), + ) // When firstLogbookMessage.setAcknowledge(firstNewAcknowledgmentMessage) @@ -112,21 +119,24 @@ class LogbookMessageUTests { .isEqualTo(ZonedDateTime.of(2024, 1, 1, 0, 0, 2, 0, ZoneOffset.UTC)) // Given - val secondLogbookMessage = getFakeLogbookMessage( - LogbookOperationType.DAT, - ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), - ).copy( - acknowledgment = Acknowledgment( - isSuccess = false, - dateTime = ZonedDateTime.of(2024, 1, 1, 0, 0, 3, 0, ZoneOffset.UTC), - ), - ) - val secondNewAcknowledgmentMessage = getFakeLogbookMessage( - LogbookOperationType.RET, - ZonedDateTime.of(2024, 1, 1, 0, 0, 2, 0, ZoneOffset.UTC), - secondLogbookMessage.reportId, - Acknowledgment(returnStatus = "000"), - ) + val secondLogbookMessage = + getFakeLogbookMessage( + LogbookOperationType.DAT, + ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), + ).copy( + acknowledgment = + Acknowledgment( + isSuccess = false, + dateTime = ZonedDateTime.of(2024, 1, 1, 0, 0, 3, 0, ZoneOffset.UTC), + ), + ) + val secondNewAcknowledgmentMessage = + getFakeLogbookMessage( + LogbookOperationType.RET, + ZonedDateTime.of(2024, 1, 1, 0, 0, 2, 0, ZoneOffset.UTC), + secondLogbookMessage.reportId, + Acknowledgment(returnStatus = "000"), + ) // When secondLogbookMessage.setAcknowledge(secondNewAcknowledgmentMessage) @@ -140,22 +150,25 @@ class LogbookMessageUTests { @Test fun `setAcknowledge should update to a new acknowledgement when it's more recent FAILED one than the current FAILED one`() { // Given - val logbookMessage = getFakeLogbookMessage( - LogbookOperationType.DAT, - ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), - ).copy( - acknowledgment = Acknowledgment( - isSuccess = false, - dateTime = ZonedDateTime.of(2024, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC), - returnStatus = "001", - ), - ) - val firstNewAcknowledgmentMessage = getFakeLogbookMessage( - LogbookOperationType.RET, - ZonedDateTime.of(2024, 1, 1, 0, 0, 3, 0, ZoneOffset.UTC), - logbookMessage.reportId, - Acknowledgment(returnStatus = "002"), - ) + val logbookMessage = + getFakeLogbookMessage( + LogbookOperationType.DAT, + ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), + ).copy( + acknowledgment = + Acknowledgment( + isSuccess = false, + dateTime = ZonedDateTime.of(2024, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC), + returnStatus = "001", + ), + ) + val firstNewAcknowledgmentMessage = + getFakeLogbookMessage( + LogbookOperationType.RET, + ZonedDateTime.of(2024, 1, 1, 0, 0, 3, 0, ZoneOffset.UTC), + logbookMessage.reportId, + Acknowledgment(returnStatus = "002"), + ) // When logbookMessage.setAcknowledge(firstNewAcknowledgmentMessage) @@ -167,12 +180,13 @@ class LogbookMessageUTests { assertThat(logbookMessage.acknowledgment?.returnStatus).isEqualTo("002") // Given - val secondNewAcknowledgmentMessage = getFakeLogbookMessage( - LogbookOperationType.RET, - ZonedDateTime.of(2024, 1, 1, 0, 0, 2, 0, ZoneOffset.UTC), - logbookMessage.reportId, - Acknowledgment(returnStatus = "001"), - ) + val secondNewAcknowledgmentMessage = + getFakeLogbookMessage( + LogbookOperationType.RET, + ZonedDateTime.of(2024, 1, 1, 0, 0, 2, 0, ZoneOffset.UTC), + logbookMessage.reportId, + Acknowledgment(returnStatus = "001"), + ) // When logbookMessage.setAcknowledge(secondNewAcknowledgmentMessage) @@ -187,22 +201,25 @@ class LogbookMessageUTests { @Test fun `setAcknowledge should NOT update to a new acknowledgement when it's more recent SUCCESSFUL one than the current SUCCESSFUL one`() { // Given - val logbookMessage = getFakeLogbookMessage( - LogbookOperationType.DAT, - ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), - ).copy( - acknowledgment = Acknowledgment( - isSuccess = true, - dateTime = ZonedDateTime.of(2024, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC), - returnStatus = "000", - ), - ) - val newAcknowledgmentMessage = getFakeLogbookMessage( - LogbookOperationType.RET, - ZonedDateTime.of(2024, 1, 1, 0, 0, 2, 0, ZoneOffset.UTC), - logbookMessage.reportId, - Acknowledgment(returnStatus = "000"), - ) + val logbookMessage = + getFakeLogbookMessage( + LogbookOperationType.DAT, + ZonedDateTime.of(2024, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), + ).copy( + acknowledgment = + Acknowledgment( + isSuccess = true, + dateTime = ZonedDateTime.of(2024, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC), + returnStatus = "000", + ), + ) + val newAcknowledgmentMessage = + getFakeLogbookMessage( + LogbookOperationType.RET, + ZonedDateTime.of(2024, 1, 1, 0, 0, 2, 0, ZoneOffset.UTC), + logbookMessage.reportId, + Acknowledgment(returnStatus = "000"), + ) // When logbookMessage.setAcknowledge(newAcknowledgmentMessage) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt index 9f598c0ce1..2b383342e6 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/MissionActionUTests.kt @@ -10,29 +10,29 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class MissionActionUTests { - @Test fun `verify Should throw an exception When the vesselId is missing in a control`() { // Given - val action = MissionAction( - id = null, - vesselId = null, - missionId = 1, - longitude = 45.7, - latitude = 13.5, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - userTrigram = "LTH", - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - ) + val action = + MissionAction( + id = null, + vesselId = null, + missionId = 1, + longitude = 45.7, + latitude = 13.5, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + userTrigram = "LTH", + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + ) // When val throwable = catchThrowable { action.verify() } @@ -45,25 +45,26 @@ class MissionActionUTests { @Test fun `verify Should throw an exception When the userTrigram is missing in a control`() { // Given - val action = MissionAction( - id = null, - vesselId = 1, - missionId = 1, - longitude = 45.7, - latitude = 13.5, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - userTrigram = "", - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - ) + val action = + MissionAction( + id = null, + vesselId = 1, + missionId = 1, + longitude = 45.7, + latitude = 13.5, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + userTrigram = "", + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + ) // When val throwable = catchThrowable { action.verify() } @@ -78,27 +79,28 @@ class MissionActionUTests { @Test fun `verify Should throw an exception When the porLocode is missing in a control`() { // Given - val action = MissionAction( - id = null, - vesselId = 1, - missionId = 1, - longitude = 45.7, - latitude = 13.5, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = null, - portName = "Port Name", - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - userTrigram = "LTH", - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - isFromPoseidon = false, - flagState = CountryCode.FR, - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = 1, + missionId = 1, + longitude = 45.7, + latitude = 13.5, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = null, + portName = "Port Name", + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + userTrigram = "LTH", + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + isFromPoseidon = false, + flagState = CountryCode.FR, + completion = Completion.TO_COMPLETE, + ) // When val throwable = catchThrowable { action.verify() } @@ -111,26 +113,27 @@ class MissionActionUTests { @Test fun `verify Should throw an exception When the longitude is missing in a control`() { // Given - val action = MissionAction( - id = null, - vesselId = 1, - missionId = 1, - longitude = null, - latitude = 13.5, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - actionType = MissionActionType.SEA_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - userTrigram = "LTH", - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - isFromPoseidon = false, - flagState = CountryCode.FR, - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = 1, + missionId = 1, + longitude = null, + latitude = 13.5, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + actionType = MissionActionType.SEA_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + userTrigram = "LTH", + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + isFromPoseidon = false, + flagState = CountryCode.FR, + completion = Completion.TO_COMPLETE, + ) // When val throwable = catchThrowable { action.verify() } @@ -143,26 +146,27 @@ class MissionActionUTests { @Test fun `verify Should throw an exception When the latitude is missing in a control`() { // Given - val action = MissionAction( - id = null, - vesselId = 1, - missionId = 1, - longitude = 45.2, - latitude = null, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - actionType = MissionActionType.SEA_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - userTrigram = "LTH", - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - isFromPoseidon = false, - flagState = CountryCode.FR, - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = 1, + missionId = 1, + longitude = 45.2, + latitude = null, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + actionType = MissionActionType.SEA_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + userTrigram = "LTH", + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + isFromPoseidon = false, + flagState = CountryCode.FR, + completion = Completion.TO_COMPLETE, + ) // When val throwable = catchThrowable { action.verify() } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlanUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlanUTests.kt index 4fe06d9b0e..060ba5c1e3 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlanUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/mission/mission_actions/actrep/JointDeploymentPlanUTests.kt @@ -20,24 +20,25 @@ class JointDeploymentPlanUTests { jdp: JointDeploymentPlan, ) { // Given - val control = MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - faoAreas = listOf("27.4.b", "27.4.c"), - seizureAndDiversion = false, - speciesOnboard = getSpecies(listOf("HKE", "ANN", "BOR")), - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ) + val control = + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + faoAreas = listOf("27.4.b", "27.4.c"), + seizureAndDiversion = false, + speciesOnboard = getSpecies(listOf("HKE", "ANN", "BOR")), + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ) // When val isLandControlApplicable = jdp.isLandControlApplicable(control) @@ -52,28 +53,27 @@ class JointDeploymentPlanUTests { @ParameterizedTest @EnumSource(JointDeploymentPlan::class) - fun `isLandControlApplicable Should return true When it is a LAND control`( - jdp: JointDeploymentPlan, - ) { + fun `isLandControlApplicable Should return true When it is a LAND control`(jdp: JointDeploymentPlan) { // Given - val control = MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.LAND_CONTROL, - faoAreas = listOf("27.7.a"), - seizureAndDiversion = false, - speciesOnboard = getSpecies(listOf("SOL", "ANF")), - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.COMPLETED, - flagState = CountryCode.FR, - userTrigram = "LTH", - ) + val control = + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.LAND_CONTROL, + faoAreas = listOf("27.7.a"), + seizureAndDiversion = false, + speciesOnboard = getSpecies(listOf("SOL", "ANF")), + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.COMPLETED, + flagState = CountryCode.FR, + userTrigram = "LTH", + ) // When val isLandControlApplicable = jdp.isLandControlApplicable(control) @@ -92,25 +92,26 @@ class JointDeploymentPlanUTests { jdp: JointDeploymentPlan, ) { // Given - val control = MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - faoAreas = listOf("27.4.b", "27.4.c"), - seizureAndDiversion = false, - // The HKE specy is missing - speciesOnboard = getSpecies(listOf("ANN", "BOR")), - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ) + val control = + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + faoAreas = listOf("27.4.b", "27.4.c"), + seizureAndDiversion = false, + // The HKE specy is missing + speciesOnboard = getSpecies(listOf("ANN", "BOR")), + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ) // When val isLandControlApplicable = jdp.isLandControlApplicable(control) @@ -129,25 +130,26 @@ class JointDeploymentPlanUTests { jdp: JointDeploymentPlan, ) { // Given - val control = MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - // The "27.4" fao code is missing - faoAreas = listOf("27.5.b", "27.5.c"), - seizureAndDiversion = false, - speciesOnboard = getSpecies(listOf("HKE", "ANN", "BOR")), - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ) + val control = + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + // The "27.4" fao code is missing + faoAreas = listOf("27.5.b", "27.5.c"), + seizureAndDiversion = false, + speciesOnboard = getSpecies(listOf("HKE", "ANN", "BOR")), + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ) // When val isLandControlApplicable = jdp.isLandControlApplicable(control) @@ -166,25 +168,26 @@ class JointDeploymentPlanUTests { jdp: JointDeploymentPlan, ) { // Given - val control = MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - faoAreas = listOf("27.5.b", "27.5.c"), - seizureAndDiversion = false, - // ALB is contained in the quotas - speciesOnboard = getSpecies(listOf("HKE", "ANN", "BOR", "ALB")), - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.GB, - userTrigram = "LTH", - ) + val control = + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + faoAreas = listOf("27.5.b", "27.5.c"), + seizureAndDiversion = false, + // ALB is contained in the quotas + speciesOnboard = getSpecies(listOf("HKE", "ANN", "BOR", "ALB")), + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.GB, + userTrigram = "LTH", + ) // When val isLandControlApplicable = jdp.isLandControlApplicable(control) @@ -203,24 +206,25 @@ class JointDeploymentPlanUTests { jdp: JointDeploymentPlan, ) { // Given - val control = MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - faoAreas = listOf("27.5.b", "27.5.c"), - seizureAndDiversion = false, - speciesOnboard = getSpecies(listOf("HKE", "ANN", "BOR")), - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.GB, - userTrigram = "LTH", - ) + val control = + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + faoAreas = listOf("27.5.b", "27.5.c"), + seizureAndDiversion = false, + speciesOnboard = getSpecies(listOf("HKE", "ANN", "BOR")), + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.GB, + userTrigram = "LTH", + ) // When val isLandControlApplicable = jdp.isLandControlApplicable(control) @@ -239,23 +243,24 @@ class JointDeploymentPlanUTests { jdp: JointDeploymentPlan, ) { // Given - val control = MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - faoAreas = listOf("27.7.b", "27.4.c"), - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ) + val control = + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + faoAreas = listOf("27.7.b", "27.4.c"), + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ) // When val faoArea = jdp.getFirstFaoAreaIncludedInJdp(control) @@ -274,23 +279,24 @@ class JointDeploymentPlanUTests { jdp: JointDeploymentPlan, ) { // Given - val control = MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.LAND_CONTROL, - faoAreas = listOf("27.7.b", "27.4.c"), - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ) + val control = + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.LAND_CONTROL, + faoAreas = listOf("27.7.b", "27.4.c"), + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ) // When val faoArea = jdp.getFirstFaoAreaIncludedInJdp(control) @@ -313,24 +319,25 @@ class JointDeploymentPlanUTests { firstSpecy.speciesCode = "BFT" val secondSpecy = SpeciesControl() secondSpecy.speciesCode = "HKE" - val control = MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - faoAreas = listOf("27.7.b", "27.4.c"), - seizureAndDiversion = false, - speciesOnboard = listOf(firstSpecy, secondSpecy), - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ) + val control = + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + faoAreas = listOf("27.7.b", "27.4.c"), + seizureAndDiversion = false, + speciesOnboard = listOf(firstSpecy, secondSpecy), + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ) // When val faoArea = jdp.getFirstFaoAreaIncludedInJdp(control) @@ -351,24 +358,25 @@ class JointDeploymentPlanUTests { // Given val specy = SpeciesControl() specy.speciesCode = "HKE" - val control = MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - faoAreas = listOf("27.7.b", "27.4.c"), - seizureAndDiversion = false, - speciesOnboard = listOf(specy), - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ) + val control = + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + faoAreas = listOf("27.7.b", "27.4.c"), + seizureAndDiversion = false, + speciesOnboard = listOf(specy), + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ) // When val faoArea = jdp.getFirstFaoAreaIncludedInJdp(control) @@ -383,28 +391,27 @@ class JointDeploymentPlanUTests { @ParameterizedTest @EnumSource(JointDeploymentPlan::class) - fun `getFirstFaoAreaIncludedInJdp Should return the fao area for a LAND control`( - jdp: JointDeploymentPlan, - ) { + fun `getFirstFaoAreaIncludedInJdp Should return the fao area for a LAND control`(jdp: JointDeploymentPlan) { // Given - val control = MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.LAND_CONTROL, - faoAreas = listOf("27.4.a"), - seizureAndDiversion = false, - speciesOnboard = getSpecies(listOf("JAX", "CRF")), - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.GB, - userTrigram = "LTH", - ) + val control = + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.LAND_CONTROL, + faoAreas = listOf("27.4.a"), + seizureAndDiversion = false, + speciesOnboard = getSpecies(listOf("JAX", "CRF")), + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.GB, + userTrigram = "LTH", + ) // When val faoArea = jdp.getFirstFaoAreaIncludedInJdp(control) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/position/NetworkTypeUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/position/NetworkTypeUTests.kt index 6f1b297b55..f21551f6ca 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/position/NetworkTypeUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/position/NetworkTypeUTests.kt @@ -7,7 +7,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class CountryCodeUTests { - @Test fun `from Should return null if not found`() { // When diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/vessel/VesselUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/vessel/VesselUTests.kt index 5edc9c16f6..fb352fe20a 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/vessel/VesselUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/vessel/VesselUTests.kt @@ -12,16 +12,17 @@ class VesselUTests { @Test fun `getNationalIdentifier should return the identifier for a FR vessel`() { // Given - val vessel = Vessel( - id = 1, - internalReferenceNumber = "FRA00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - hasLogbookEsacapt = false, - ) + val vessel = + Vessel( + id = 1, + internalReferenceNumber = "FRA00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + hasLogbookEsacapt = false, + ) // When val nationalIdentifier = vessel.getNationalIdentifier() @@ -33,16 +34,17 @@ class VesselUTests { @Test fun `getNationalIdentifier should return the identifier for a FR vessel When district code is null`() { // Given - val vessel = Vessel( - id = 1, - internalReferenceNumber = "FRA00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "", - hasLogbookEsacapt = false, - ) + val vessel = + Vessel( + id = 1, + internalReferenceNumber = "FRA00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "", + hasLogbookEsacapt = false, + ) // When val nationalIdentifier = vessel.getNationalIdentifier() @@ -54,16 +56,17 @@ class VesselUTests { @Test fun `getNationalIdentifier should return the identifier for a GB vessel`() { // Given - val vessel = Vessel( - id = 1, - internalReferenceNumber = "GBR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.GB, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - hasLogbookEsacapt = false, - ) + val vessel = + Vessel( + id = 1, + internalReferenceNumber = "GBR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.GB, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + hasLogbookEsacapt = false, + ) // When val nationalIdentifier = vessel.getNationalIdentifier() diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ERSMapperUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ERSMapperUTests.kt index 553aab94bc..e886028ceb 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ERSMapperUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ERSMapperUTests.kt @@ -17,7 +17,6 @@ import java.time.ZonedDateTime @Import(MapperConfiguration::class) @JsonTest class ERSMapperUTests { - @Autowired private lateinit var mapper: ObjectMapper @@ -80,22 +79,23 @@ class ERSMapperUTests { @Test fun `getERSMessageValueFromJSON Should deserialize an example FAR message`() { // Given - val farMessage = "{\"hauls\":[{\"gear\": \"GTN\", \"mesh\": 100.0, \"catches\": [" + - "{\"weight\": 2.0, \"conversionFactor\": 1.0, \"nbFish\": null, \"species\": \"SCL\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 10.0, \"conversionFactor\": 1.0, \"nbFish\": null, \"species\": \"BRB\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 1.5, \"nbFish\": null, \"species\": \"LBE\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 18.0, \"nbFish\": null, \"species\": \"BSS\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 5.0, \"nbFish\": null, \"species\": \"SWA\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 30.0, \"nbFish\": null, \"species\": \"BIB\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 8.0, \"nbFish\": null, \"species\": \"COE\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 4.0, \"nbFish\": null, \"species\": \"SOL\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 1.0, \"nbFish\": null, \"species\": \"MKG\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 10.0, \"nbFish\": null, \"species\": \"MNZ\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 70.0, \"nbFish\": null, \"species\": \"POL\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 40.0, \"nbFish\": null, \"species\": \"USB\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 15.0, \"nbFish\": null, \"species\": \"RJH\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + - "{\"weight\": 15.0, \"nbFish\": null, \"species\": \"WHG\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}], \"farDatetimeUtc\": \"2019-12-05T11:55Z\"" + - "}]}" + val farMessage = + "{\"hauls\":[{\"gear\": \"GTN\", \"mesh\": 100.0, \"catches\": [" + + "{\"weight\": 2.0, \"conversionFactor\": 1.0, \"nbFish\": null, \"species\": \"SCL\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 10.0, \"conversionFactor\": 1.0, \"nbFish\": null, \"species\": \"BRB\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 1.5, \"nbFish\": null, \"species\": \"LBE\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 18.0, \"nbFish\": null, \"species\": \"BSS\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 5.0, \"nbFish\": null, \"species\": \"SWA\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 30.0, \"nbFish\": null, \"species\": \"BIB\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 8.0, \"nbFish\": null, \"species\": \"COE\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 4.0, \"nbFish\": null, \"species\": \"SOL\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 1.0, \"nbFish\": null, \"species\": \"MKG\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 10.0, \"nbFish\": null, \"species\": \"MNZ\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 70.0, \"nbFish\": null, \"species\": \"POL\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 40.0, \"nbFish\": null, \"species\": \"USB\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 15.0, \"nbFish\": null, \"species\": \"RJH\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}, " + + "{\"weight\": 15.0, \"nbFish\": null, \"species\": \"WHG\", \"faoZone\": \"27.8.a\", \"effortZone\": \"C\", \"economicZone\": \"FRA\", \"statisticalRectangle\": \"23E6\"}], \"farDatetimeUtc\": \"2019-12-05T11:55Z\"" + + "}]}" // When val parsedFARMessage = ERSMapper.getERSMessageValueFromJSON(mapper, farMessage, "FAR", LogbookOperationType.DAT) @@ -128,9 +128,10 @@ class ERSMapperUTests { @Test fun `getERSMessageValueFromJSON Should deserialize an example RET message`() { // Given - val retMessage = "{\"returnStatus\": \"002\", \"rejectionCause\": \"002 MGEN02 Message incorrect : " + - "la date/heure de l’événement RTP n° OOF20201105037001 est postérieure à la date/heure courante. " + - "Veuillez vérifier la date/heure de l’événement déclaré et renvoyer votre message.\"}" + val retMessage = + "{\"returnStatus\": \"002\", \"rejectionCause\": \"002 MGEN02 Message incorrect : " + + "la date/heure de l’événement RTP n° OOF20201105037001 est postérieure à la date/heure courante. " + + "Veuillez vérifier la date/heure de l’événement déclaré et renvoyer votre message.\"}" // When val parsedRETMessage = ERSMapper.getERSMessageValueFromJSON(mapper, retMessage, "", LogbookOperationType.RET) @@ -208,46 +209,47 @@ class ERSMapperUTests { @Test fun `second getERSMessageValueFromJSON Should deserialize an example CPS message`() { // Given - val cpsMessage = "{" + - "\"cpsDatetimeUtc\": \"2023-02-28T17:44:00Z\"," + - "\"gear\": \"GTR\"," + - "\"mesh\": 100.0," + - "\"dimensions\": \"50.0;2.0\"," + - "\"catches\": [" + - "{" + - "\"sex\": \"M\"," + - "\"healthState\": \"DEA\"," + - "\"careMinutes\": null," + - "\"ring\": \"1234567\"," + - "\"fate\": \"DIS\"," + - "\"comment\": null," + - "\"species\": \"DCO\"," + - "\"weight\": 60.0," + - "\"nbFish\": 1.0," + - "\"faoZone\": \"27.8.a\"," + - "\"economicZone\": \"FRA\"," + - "\"statisticalRectangle\": \"22E7\"," + - "\"effortZone\": \"C\"" + - "}," + + val cpsMessage = "{" + - "\"sex\": \"M\"," + - "\"healthState\": \"DEA\"," + - "\"careMinutes\": 40," + - "\"ring\": \"1234568\"," + - "\"fate\": \"DIS\"," + - "\"comment\": \"Pov' titi a eu bobo\"," + - "\"species\": \"DCO\"," + - "\"weight\": 80.0," + - "\"nbFish\": 1.0," + - "\"faoZone\": \"27.8.a\"," + - "\"economicZone\": \"FRA\"," + - "\"statisticalRectangle\": \"22E7\"," + - "\"effortZone\": \"C\"" + - "}" + - "]," + - "\"latitude\": 46.575," + - "\"longitude\": -2.741" + - "}" + "\"cpsDatetimeUtc\": \"2023-02-28T17:44:00Z\"," + + "\"gear\": \"GTR\"," + + "\"mesh\": 100.0," + + "\"dimensions\": \"50.0;2.0\"," + + "\"catches\": [" + + "{" + + "\"sex\": \"M\"," + + "\"healthState\": \"DEA\"," + + "\"careMinutes\": null," + + "\"ring\": \"1234567\"," + + "\"fate\": \"DIS\"," + + "\"comment\": null," + + "\"species\": \"DCO\"," + + "\"weight\": 60.0," + + "\"nbFish\": 1.0," + + "\"faoZone\": \"27.8.a\"," + + "\"economicZone\": \"FRA\"," + + "\"statisticalRectangle\": \"22E7\"," + + "\"effortZone\": \"C\"" + + "}," + + "{" + + "\"sex\": \"M\"," + + "\"healthState\": \"DEA\"," + + "\"careMinutes\": 40," + + "\"ring\": \"1234568\"," + + "\"fate\": \"DIS\"," + + "\"comment\": \"Pov' titi a eu bobo\"," + + "\"species\": \"DCO\"," + + "\"weight\": 80.0," + + "\"nbFish\": 1.0," + + "\"faoZone\": \"27.8.a\"," + + "\"economicZone\": \"FRA\"," + + "\"statisticalRectangle\": \"22E7\"," + + "\"effortZone\": \"C\"" + + "}" + + "]," + + "\"latitude\": 46.575," + + "\"longitude\": -2.741" + + "}" // When val parsedCPSMessage = ERSMapper.getERSMessageValueFromJSON(mapper, cpsMessage, "CPS", LogbookOperationType.DAT) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/NAFMessageMapperUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/NAFMessageMapperUTests.kt index 83e621f4bb..bf7f4a5100 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/NAFMessageMapperUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/NAFMessageMapperUTests.kt @@ -11,8 +11,9 @@ internal class NAFMessageMapperUTests { @Test internal fun `init should parse this example NAF message`() { // Given - val naf = "//SR//AD/FRA//FR/GBR//RD/20201006//RT/2141//FS/GBR//RC/MGXR6//IR/GBROOC21250//" + - "DA/20201006//TI/1625//LT/53.254//LG/.940//SP/96//CO/8//TM/POS//ER//" + val naf = + "//SR//AD/FRA//FR/GBR//RD/20201006//RT/2141//FS/GBR//RC/MGXR6//IR/GBROOC21250//" + + "DA/20201006//TI/1625//LT/53.254//LG/.940//SP/96//CO/8//TM/POS//ER//" // When val position = NAFMessageMapper(naf).toPosition() @@ -37,8 +38,9 @@ internal class NAFMessageMapperUTests { @Test internal fun `init should parse this other example NAF message`() { // Given - val naf = "//SR//AD/FRA//FR/NLD//RD/20201006//NA/GENGI//RT/2133//FS/NLD//RC/PCVC//XR/SCH43//" + - "IR/NLD201901153//DA/20201006//TI/2126//LT/52.099//LG/4.269//SP/0//CO/173//TM/POS//ER//" + val naf = + "//SR//AD/FRA//FR/NLD//RD/20201006//NA/GENGI//RT/2133//FS/NLD//RC/PCVC//XR/SCH43//" + + "IR/NLD201901153//DA/20201006//TI/2126//LT/52.099//LG/4.269//SP/0//CO/173//TM/POS//ER//" // When val position = NAFMessageMapper(naf).toPosition() @@ -63,8 +65,9 @@ internal class NAFMessageMapperUTests { @Test internal fun `init should parse this another example NAF message`() { // Given - val naf = "//SR//FR/SWE//TM/POS//RC/F1007//IR/SWE0000F1007//XR/EXT3//LT/57.037//LG/12.214//" + - "SP/50//CO/190//DA/20170817//TI/0500//NA/Ship1007//FS/SWE//ER//" + val naf = + "//SR//FR/SWE//TM/POS//RC/F1007//IR/SWE0000F1007//XR/EXT3//LT/57.037//LG/12.214//" + + "SP/50//CO/190//DA/20170817//TI/0500//NA/Ship1007//FS/SWE//ER//" // When val position = NAFMessageMapper(naf).toPosition() @@ -89,8 +92,9 @@ internal class NAFMessageMapperUTests { @Test internal fun `init should throw an exception When invalid message type`() { // Given - val naf = "//SR//AD/FRA//FR/NLD//RD/20201006//NA/GENGI//RT/2133//FS/NLD//RC/PCVC//XR/SCH43//" + - "IR/NLD201901153//DA/20201006//TI/2126//LT/52.099//LG/4.269//SP/0//CO/173//TM/ACK//ER//" + val naf = + "//SR//AD/FRA//FR/NLD//RD/20201006//NA/GENGI//RT/2133//FS/NLD//RC/PCVC//XR/SCH43//" + + "IR/NLD201901153//DA/20201006//TI/2126//LT/52.099//LG/4.269//SP/0//CO/173//TM/ACK//ER//" // When val throwable = catchThrowable { NAFMessageMapper(naf) } @@ -102,8 +106,9 @@ internal class NAFMessageMapperUTests { @Test internal fun `init Should throw an exception When no date or time`() { // Given - val naf = "//SR//AD/FRA//FR/NLD//RD/20201006//NA/GENGI//RT/2133//FS/NLD//RC/PCVC//XR/SCH43//" + - "IR/NLD201901153//DA/20201006//LT/52.099//LG/4.269//SP/0//CO/173//TM/POS//ER//" + val naf = + "//SR//AD/FRA//FR/NLD//RD/20201006//NA/GENGI//RT/2133//FS/NLD//RC/PCVC//XR/SCH43//" + + "IR/NLD201901153//DA/20201006//LT/52.099//LG/4.269//SP/0//CO/173//TM/POS//ER//" // When val throwable = catchThrowable { NAFMessageMapper(naf) } @@ -115,8 +120,9 @@ internal class NAFMessageMapperUTests { @Test internal fun `init Should throw an exception When bad from country three letters found`() { // Given - val naf = "//SR//AD/FRA//FR/LOL//RD/20201006//NA/GENGI//RT/2133//FS/NLD//RC/PCVC//XR/SCH43//" + - "TI/1025//IR/NLD201901153//DA/20201006//LT/52.099//LG/4.269//SP/0//CO/173//TM/POS//ER//" + val naf = + "//SR//AD/FRA//FR/LOL//RD/20201006//NA/GENGI//RT/2133//FS/NLD//RC/PCVC//XR/SCH43//" + + "TI/1025//IR/NLD201901153//DA/20201006//LT/52.099//LG/4.269//SP/0//CO/173//TM/POS//ER//" // When val throwable = catchThrowable { NAFMessageMapper(naf) } @@ -127,8 +133,9 @@ internal class NAFMessageMapperUTests { @Test internal fun `init Should parse invalid start record`() { - val naf = "//FR/SWE//AD/UVM//TM/POS//IR/SWE0000F1007//LT/57.037//LG/12.214//" + - "SP/50//CO/190//DA/20170817//TI/0500//ER//" + val naf = + "//FR/SWE//AD/UVM//TM/POS//IR/SWE0000F1007//LT/57.037//LG/12.214//" + + "SP/50//CO/190//DA/20170817//TI/0500//ER//" // When val throwable = catchThrowable { NAFMessageMapper(naf) } @@ -139,8 +146,9 @@ internal class NAFMessageMapperUTests { @Test internal fun `init Should parse invalid latitude`() { - val naf = "//SR//FR/SWE//TM/POS//IR/SWE0000F1007//LT/LOL//LG/12.214//" + - "SP/50//CO/190//DA/20170817//TI/0500//ER//" + val naf = + "//SR//FR/SWE//TM/POS//IR/SWE0000F1007//LT/LOL//LG/12.214//" + + "SP/50//CO/190//DA/20170817//TI/0500//ER//" // When val throwable = catchThrowable { NAFMessageMapper(naf) } @@ -151,8 +159,9 @@ internal class NAFMessageMapperUTests { @Test internal fun `init Should skip an empty field`() { - val naf = "//SR//FR/SWE//TM/POS//IR/SWE0000F1007//LT///LG/12.214//" + - "SP/50//CO/190//DA/20170817//TI/0500//ER//" + val naf = + "//SR//FR/SWE//TM/POS//IR/SWE0000F1007//LT///LG/12.214//" + + "SP/50//CO/190//DA/20170817//TI/0500//ER//" // When val throwable = catchThrowable { NAFMessageMapper(naf) } @@ -164,8 +173,9 @@ internal class NAFMessageMapperUTests { @Test internal fun `init Should not throw an exception When no course`() { // Given - val naf = "//SR//FR/SWE//TM/POS//RC/F1007//IR/SWE0000F1007//XR/EXT3//LT/57.037//LG/12.214" + - "//SP/0//DA/20170817//TI/0500//NA/Ship1007//FS/SWE//ER//" + val naf = + "//SR//FR/SWE//TM/POS//RC/F1007//IR/SWE0000F1007//XR/EXT3//LT/57.037//LG/12.214" + + "//SP/0//DA/20170817//TI/0500//NA/Ship1007//FS/SWE//ER//" // When val position = NAFMessageMapper(naf).toPosition() diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/PendingAlertMapperUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/PendingAlertMapperUTests.kt index 5caa7cf143..e4bae8c732 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/PendingAlertMapperUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/PendingAlertMapperUTests.kt @@ -13,7 +13,6 @@ import org.springframework.context.annotation.Import @Import(MapperConfiguration::class) @JsonTest class PendingAlertMapperUTests { - @Autowired private lateinit var mapper: ObjectMapper diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ReportingMapperUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ReportingMapperUTests.kt index e84e46c468..25e4e92384 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ReportingMapperUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/mappers/ReportingMapperUTests.kt @@ -14,16 +14,16 @@ import org.springframework.context.annotation.Import @Import(MapperConfiguration::class) @JsonTest class ReportingMapperUTests { - @Autowired private lateinit var mapper: ObjectMapper @Test fun `getReportingValueFromJSON Should throw an exception When the message value is null`() { // When - val throwable = catchThrowable { - ReportingMapper.getReportingValueFromJSON(mapper, "null", ReportingType.ALERT) - } + val throwable = + catchThrowable { + ReportingMapper.getReportingValueFromJSON(mapper, "null", ReportingType.ALERT) + } // Then assertThat(throwable).isNotNull @@ -63,15 +63,16 @@ class ReportingMapperUTests { @Test fun `readValue Should deserialize an OBSERVATION json`() { // Given - val observation = "{" + - "\"type\": \"OBSERVATION\"," + - "\"reportingActor\": \"OPS\"," + - "\"unit\": null, " + - "\"authorTrigram\": \"LTH\"," + - "\"authorContact\": null," + - "\"title\": \"A title !\"," + - "\"description\": \"A description !\"" + - "}" + val observation = + "{" + + "\"type\": \"OBSERVATION\"," + + "\"reportingActor\": \"OPS\"," + + "\"unit\": null, " + + "\"authorTrigram\": \"LTH\"," + + "\"authorContact\": null," + + "\"title\": \"A title !\"," + + "\"description\": \"A description !\"" + + "}" val parsedReporting = mapper.readValue(observation, InfractionSuspicionOrObservationType::class.java) @@ -89,24 +90,26 @@ class ReportingMapperUTests { @Test fun `getReportingValueFromJSON Should deserialize an INFRACTION_SUSPICION When a legacy flagState property is found`() { // Given - val infraction = "{" + - "\"type\": \"INFRACTION_SUSPICION\"," + - "\"reportingActor\": \"OPS\"," + - "\"unit\": null, " + - "\"authorTrigram\": \"LTH\"," + - "\"authorContact\": null," + - "\"title\": \"A title !\"," + - "\"flagState\": \"FR\"," + - "\"description\": \"A description !\"," + - "\"natinfCode\": 1234," + - "\"dml\": \"DML 56\"" + - "}" - - val parsedReporting = ReportingMapper.getReportingValueFromJSON( - mapper, - infraction, - ReportingType.INFRACTION_SUSPICION, - ) + val infraction = + "{" + + "\"type\": \"INFRACTION_SUSPICION\"," + + "\"reportingActor\": \"OPS\"," + + "\"unit\": null, " + + "\"authorTrigram\": \"LTH\"," + + "\"authorContact\": null," + + "\"title\": \"A title !\"," + + "\"flagState\": \"FR\"," + + "\"description\": \"A description !\"," + + "\"natinfCode\": 1234," + + "\"dml\": \"DML 56\"" + + "}" + + val parsedReporting = + ReportingMapper.getReportingValueFromJSON( + mapper, + infraction, + ReportingType.INFRACTION_SUSPICION, + ) // Then assertThat(parsedReporting).isInstanceOf(InfractionSuspicion::class.java) @@ -124,17 +127,18 @@ class ReportingMapperUTests { @Test fun `readValue Should deserialize an INFRACTION_SUSPICION`() { // Given - val infraction = "{" + - "\"type\": \"INFRACTION_SUSPICION\"," + - "\"reportingActor\": \"OPS\"," + - "\"unit\": null, " + - "\"authorTrigram\": \"LTH\"," + - "\"authorContact\": null," + - "\"title\": \"A title !\"," + - "\"description\": \"A description !\"," + - "\"natinfCode\": 1234," + - "\"dml\": \"DML 56\"" + - "}" + val infraction = + "{" + + "\"type\": \"INFRACTION_SUSPICION\"," + + "\"reportingActor\": \"OPS\"," + + "\"unit\": null, " + + "\"authorTrigram\": \"LTH\"," + + "\"authorContact\": null," + + "\"title\": \"A title !\"," + + "\"description\": \"A description !\"," + + "\"natinfCode\": 1234," + + "\"dml\": \"DML 56\"" + + "}" val parsedReporting = mapper.readValue(infraction, InfractionSuspicionOrObservationType::class.java) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/AddControlObjectiveYearUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/AddControlObjectiveYearUTests.kt index ebf7f1318a..6e4d8a6725 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/AddControlObjectiveYearUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/AddControlObjectiveYearUTests.kt @@ -17,7 +17,6 @@ import java.time.ZoneOffset @ExtendWith(SpringExtension::class) class AddControlObjectiveYearUTests { - @MockBean private lateinit var controlObjectivesRepository: ControlObjectivesRepository @@ -61,9 +60,10 @@ class AddControlObjectiveYearUTests { given(controlObjectivesRepository.findYearEntries()).willReturn(listOf(nextYear, currentYear, 2020)) // When - val throwable = catchThrowable { - AddControlObjectiveYear(controlObjectivesRepository, fixedClock).execute() - } + val throwable = + catchThrowable { + AddControlObjectiveYear(controlObjectivesRepository, fixedClock).execute() + } // Then assertThat(throwable).isNotNull diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/AddReportingUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/AddReportingUTests.kt index 3e3518262b..14767267d9 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/AddReportingUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/AddReportingUTests.kt @@ -22,7 +22,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class AddReportingUTests { - @MockBean private lateinit var reportingRepository: ReportingRepository @@ -35,28 +34,30 @@ class AddReportingUTests { @Test fun `execute Should throw an exception When the reporting is an alert`() { // Given - val reportingToAdd = Reporting( - id = 1, - type = ReportingType.ALERT, - vesselName = "BIDUBULE", - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - validationDate = ZonedDateTime.now(), - value = ThreeMilesTrawlingAlert() as ReportingValue, - isArchived = false, - isDeleted = false, - ) + val reportingToAdd = + Reporting( + id = 1, + type = ReportingType.ALERT, + vesselName = "BIDUBULE", + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + validationDate = ZonedDateTime.now(), + value = ThreeMilesTrawlingAlert() as ReportingValue, + isArchived = false, + isDeleted = false, + ) // When - val throwable = catchThrowable { - AddReporting(reportingRepository, getInfractionSuspicionWithDMLAndSeaFront, getAllControlUnits).execute( - reportingToAdd, - ) - } + val throwable = + catchThrowable { + AddReporting(reportingRepository, getInfractionSuspicionWithDMLAndSeaFront, getAllControlUnits).execute( + reportingToAdd, + ) + } // Then assertThat(throwable.message).contains("The reporting type must be OBSERVATION or INFRACTION_SUSPICION") @@ -68,33 +69,36 @@ class AddReportingUTests { reportingActor: ReportingActor, ) { // Given - val reportingToAdd = Reporting( - id = 1, - type = ReportingType.OBSERVATION, - vesselName = "BIDUBULE", - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - validationDate = ZonedDateTime.now(), - value = Observation( - reportingActor = reportingActor, - authorTrigram = "LTH", - title = "A title", - ), - isArchived = false, - isDeleted = false, - ) + val reportingToAdd = + Reporting( + id = 1, + type = ReportingType.OBSERVATION, + vesselName = "BIDUBULE", + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + validationDate = ZonedDateTime.now(), + value = + Observation( + reportingActor = reportingActor, + authorTrigram = "LTH", + title = "A title", + ), + isArchived = false, + isDeleted = false, + ) given(reportingRepository.save(any())).willReturn(reportingToAdd) // When - val throwable = catchThrowable { - AddReporting(reportingRepository, getInfractionSuspicionWithDMLAndSeaFront, getAllControlUnits).execute( - reportingToAdd, - ) - } + val throwable = + catchThrowable { + AddReporting(reportingRepository, getInfractionSuspicionWithDMLAndSeaFront, getAllControlUnits).execute( + reportingToAdd, + ) + } // Then when (reportingActor) { @@ -120,26 +124,28 @@ class AddReportingUTests { title = "Chalut en boeuf illégal", ), ) - val reportingToAdd = Reporting( - id = 1, - type = ReportingType.INFRACTION_SUSPICION, - vesselName = "BIDUBULE", - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - validationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - reportingActor = ReportingActor.OPS, - natinfCode = 1235, - authorTrigram = "LTH", - title = "Chalut en boeuf illégal", - ), - isArchived = false, - isDeleted = false, - ) + val reportingToAdd = + Reporting( + id = 1, + type = ReportingType.INFRACTION_SUSPICION, + vesselName = "BIDUBULE", + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + validationDate = ZonedDateTime.now(), + value = + InfractionSuspicion( + reportingActor = ReportingActor.OPS, + natinfCode = 1235, + authorTrigram = "LTH", + title = "Chalut en boeuf illégal", + ), + isArchived = false, + isDeleted = false, + ) given(reportingRepository.save(any())).willReturn(reportingToAdd) // When diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetAllCurrentReportingsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetAllCurrentReportingsUTests.kt index f0c16b6483..1e94d43200 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetAllCurrentReportingsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetAllCurrentReportingsUTests.kt @@ -43,12 +43,13 @@ class GetAllCurrentReportingsUTests { vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, flagState = CountryCode.FR, creationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ), + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), type = ReportingType.INFRACTION_SUSPICION, isDeleted = false, isArchived = false, @@ -88,12 +89,13 @@ class GetAllCurrentReportingsUTests { vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, flagState = CountryCode.FR, creationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ), + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), type = ReportingType.INFRACTION_SUSPICION, isDeleted = false, isArchived = false, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetInfractionSuspicionWithDMLAndSeafrontUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetInfractionSuspicionWithDMLAndSeafrontUTests.kt index 5e9b4797a2..a65c41a27c 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetInfractionSuspicionWithDMLAndSeafrontUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetInfractionSuspicionWithDMLAndSeafrontUTests.kt @@ -65,13 +65,14 @@ class GetInfractionSuspicionWithDMLAndSeafrontUTests { val throwable = catchThrowable { GetInfractionSuspicionWithDMLAndSeaFront(vesselRepository, districtRepository).execute( - infractionSuspicion = InfractionSuspicion( - reportingActor = ReportingActor.OPS, - dml = "", - natinfCode = 1235, - authorTrigram = "LTH", - title = "Chalut en boeuf illégal", - ), + infractionSuspicion = + InfractionSuspicion( + reportingActor = ReportingActor.OPS, + dml = "", + natinfCode = 1235, + authorTrigram = "LTH", + title = "Chalut en boeuf illégal", + ), vesselId = null, ) } @@ -89,13 +90,14 @@ class GetInfractionSuspicionWithDMLAndSeafrontUTests { val throwable = catchThrowable { GetInfractionSuspicionWithDMLAndSeaFront(vesselRepository, districtRepository).execute( - infractionSuspicion = InfractionSuspicion( - reportingActor = ReportingActor.OPS, - dml = "", - natinfCode = 1235, - authorTrigram = "LTH", - title = "Chalut en boeuf illégal", - ), + infractionSuspicion = + InfractionSuspicion( + reportingActor = ReportingActor.OPS, + dml = "", + natinfCode = 1235, + authorTrigram = "LTH", + title = "Chalut en boeuf illégal", + ), vesselId = 123, ) } @@ -117,13 +119,14 @@ class GetInfractionSuspicionWithDMLAndSeafrontUTests { val throwable = catchThrowable { GetInfractionSuspicionWithDMLAndSeaFront(vesselRepository, districtRepository).execute( - infractionSuspicion = InfractionSuspicion( - reportingActor = ReportingActor.OPS, - dml = "", - natinfCode = 1235, - authorTrigram = "LTH", - title = "Chalut en boeuf illégal", - ), + infractionSuspicion = + InfractionSuspicion( + reportingActor = ReportingActor.OPS, + dml = "", + natinfCode = 1235, + authorTrigram = "LTH", + title = "Chalut en boeuf illégal", + ), vesselId = 123, ) } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetLogbookMessagesUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetLogbookMessagesUTests.kt index 4f2c511fbd..dd7d62e6af 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetLogbookMessagesUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetLogbookMessagesUTests.kt @@ -289,9 +289,10 @@ class GetLogbookMessagesUTests { operationDateTime = ZonedDateTime.now(), operationNumber = "", operationType = LogbookOperationType.RET, - reportDateTime = ZonedDateTime.of(2021, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC).minusHours( - 12, - ), + reportDateTime = + ZonedDateTime.of(2021, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC).minusHours( + 12, + ), transmissionFormat = LogbookTransmissionFormat.ERS, ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetPendingAlertsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetPendingAlertsUTests.kt index 2f65ab51c3..286643704a 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetPendingAlertsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetPendingAlertsUTests.kt @@ -23,7 +23,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class GetPendingAlertsUTests { - @MockBean private lateinit var pendingAlertRepository: PendingAlertRepository @@ -33,17 +32,18 @@ class GetPendingAlertsUTests { @Test fun `execute Should return alerts with associated infractions`() { // Given - val pendingAlert = PendingAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = ThreeMilesTrawlingAlert(), - ) + val pendingAlert = + PendingAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = ThreeMilesTrawlingAlert(), + ) given(infractionRepository.findInfractionByNatinfCode(eq(7059))).willReturn( Infraction( natinfCode = 7059, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetSilencedAlertsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetSilencedAlertsUTests.kt index 51adadddd2..aaadcb67ca 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetSilencedAlertsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetSilencedAlertsUTests.kt @@ -16,42 +16,44 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class GetSilencedAlertsUTests { - @MockBean private lateinit var silencedAlertRepository: SilencedAlertRepository @Test fun `execute Should return silenced alerts without validated alerts`() { // Given - val silencedAlertOne = SilencedAlert( - internalReferenceNumber = "INTERNAL_REF_ONE", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - value = ThreeMilesTrawlingAlert(), - silencedBeforeDate = ZonedDateTime.now().plusHours(5), - ) - val silencedAlertTwo = SilencedAlert( - internalReferenceNumber = "INTERNAL_REF_TWO", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - value = ThreeMilesTrawlingAlert(), - silencedBeforeDate = ZonedDateTime.now().plusHours(5), - wasValidated = true, - ) - val silencedAlertThree = SilencedAlert( - internalReferenceNumber = "INTERNAL_REF_THREE", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - value = ThreeMilesTrawlingAlert(), - silencedBeforeDate = ZonedDateTime.now().plusHours(5), - wasValidated = false, - ) + val silencedAlertOne = + SilencedAlert( + internalReferenceNumber = "INTERNAL_REF_ONE", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + value = ThreeMilesTrawlingAlert(), + silencedBeforeDate = ZonedDateTime.now().plusHours(5), + ) + val silencedAlertTwo = + SilencedAlert( + internalReferenceNumber = "INTERNAL_REF_TWO", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + value = ThreeMilesTrawlingAlert(), + silencedBeforeDate = ZonedDateTime.now().plusHours(5), + wasValidated = true, + ) + val silencedAlertThree = + SilencedAlert( + internalReferenceNumber = "INTERNAL_REF_THREE", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + value = ThreeMilesTrawlingAlert(), + silencedBeforeDate = ZonedDateTime.now().plusHours(5), + wasValidated = false, + ) given(silencedAlertRepository.findAllCurrentSilencedAlerts()).willReturn( listOf( silencedAlertOne, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselPositionsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselPositionsUTests.kt index 0c144b5ab3..e06c455f19 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselPositionsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselPositionsUTests.kt @@ -23,7 +23,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class GetVesselPositionsUTests { - @MockBean private lateinit var positionRepository: PositionRepository @@ -34,82 +33,90 @@ class GetVesselPositionsUTests { fun `execute Should return the last 1 day positions When the DEP message is not found`() { // Given val now = ZonedDateTime.now().minusDays(1) - val firstPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 4, - ), - ) - val secondPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 3, - ), - ) - val thirdPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 2, - ), - ) - val fourthPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 1, - ), - ) + val firstPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 4, + ), + ) + val secondPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 3, + ), + ) + val thirdPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 2, + ), + ) + val fourthPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 1, + ), + ) given(positionRepository.findVesselLastPositionsByInternalReferenceNumber(any(), any(), any())).willReturn( listOf(firstPosition, fourthPosition, secondPosition, thirdPosition), ) @@ -118,18 +125,19 @@ class GetVesselPositionsUTests { ) // When - val pair = runBlocking { - GetVesselPositions(positionRepository, logbookReportRepository) - .execute( - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "", - ircs = "", - trackDepth = VesselTrackDepth.LAST_DEPARTURE, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - fromDateTime = null, - toDateTime = null, - ) - } + val pair = + runBlocking { + GetVesselPositions(positionRepository, logbookReportRepository) + .execute( + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "", + ircs = "", + trackDepth = VesselTrackDepth.LAST_DEPARTURE, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + fromDateTime = null, + toDateTime = null, + ) + } // Then assertThat(pair.first).isTrue @@ -147,20 +155,21 @@ class GetVesselPositionsUTests { ) // When - val throwable = catchThrowable { - runBlocking { - GetVesselPositions(positionRepository, logbookReportRepository) - .execute( - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "", - ircs = "", - trackDepth = VesselTrackDepth.TWELVE_HOURS, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - fromDateTime = null, - toDateTime = null, - ) + val throwable = + catchThrowable { + runBlocking { + GetVesselPositions(positionRepository, logbookReportRepository) + .execute( + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "", + ircs = "", + trackDepth = VesselTrackDepth.TWELVE_HOURS, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + fromDateTime = null, + toDateTime = null, + ) + } } - } // Then assertThat(throwable).isNull() @@ -174,20 +183,21 @@ class GetVesselPositionsUTests { ) // When - val throwable = catchThrowable { - runBlocking { - GetVesselPositions(positionRepository, logbookReportRepository) - .execute( - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "", - ircs = "", - trackDepth = VesselTrackDepth.LAST_DEPARTURE, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - fromDateTime = null, - toDateTime = null, - ) + val throwable = + catchThrowable { + runBlocking { + GetVesselPositions(positionRepository, logbookReportRepository) + .execute( + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "", + ircs = "", + trackDepth = VesselTrackDepth.LAST_DEPARTURE, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + fromDateTime = null, + toDateTime = null, + ) + } } - } // Then assertThat(throwable).isNull() @@ -201,20 +211,21 @@ class GetVesselPositionsUTests { ) // When - val throwable = catchThrowable { - runBlocking { - GetVesselPositions(positionRepository, logbookReportRepository) - .execute( - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "", - ircs = "", - trackDepth = VesselTrackDepth.CUSTOM, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - fromDateTime = null, - toDateTime = ZonedDateTime.now(), - ) + val throwable = + catchThrowable { + runBlocking { + GetVesselPositions(positionRepository, logbookReportRepository) + .execute( + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "", + ircs = "", + trackDepth = VesselTrackDepth.CUSTOM, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + fromDateTime = null, + toDateTime = ZonedDateTime.now(), + ) + } } - } // Then assertThat(throwable).isNotNull @@ -256,82 +267,90 @@ class GetVesselPositionsUTests { fun `execute Should call findVesselLastPositionsByInternalReferenceNumber When the INTERNAL_REFERENCE_NUMBER identifier is specified`() { // Given val now = ZonedDateTime.now().minusDays(1) - val firstPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 4, - ), - ) - val secondPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 3, - ), - ) - val thirdPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 2, - ), - ) - val fourthPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 1, - ), - ) + val firstPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 4, + ), + ) + val secondPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 3, + ), + ) + val thirdPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 2, + ), + ) + val fourthPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 1, + ), + ) given(positionRepository.findVesselLastPositionsByInternalReferenceNumber(any(), any(), any())).willReturn( listOf(firstPosition, fourthPosition, secondPosition, thirdPosition), ) @@ -362,82 +381,90 @@ class GetVesselPositionsUTests { fun `execute Should call findVesselLastPositionsWithoutSpecifiedIdentifier When the vessel identifier is null`() { // Given val now = ZonedDateTime.now().minusDays(1) - val firstPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 4, - ), - ) - val secondPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 3, - ), - ) - val thirdPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 2, - ), - ) - val fourthPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 1, - ), - ) + val firstPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 4, + ), + ) + val secondPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 3, + ), + ) + val thirdPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 2, + ), + ) + val fourthPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 1, + ), + ) given( positionRepository.findVesselLastPositionsWithoutSpecifiedIdentifier(any(), any(), any(), any(), any()), ).willReturn( @@ -445,18 +472,19 @@ class GetVesselPositionsUTests { ) // When - val pair = runBlocking { - GetVesselPositions(positionRepository, logbookReportRepository) - .execute( - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "", - ircs = "", - trackDepth = VesselTrackDepth.TWELVE_HOURS, - vesselIdentifier = null, - fromDateTime = null, - toDateTime = null, - ) - } + val pair = + runBlocking { + GetVesselPositions(positionRepository, logbookReportRepository) + .execute( + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "", + ircs = "", + trackDepth = VesselTrackDepth.TWELVE_HOURS, + vesselIdentifier = null, + fromDateTime = null, + toDateTime = null, + ) + } // Then runBlocking { diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselReportingsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselReportingsUTests.kt index 9b807e07c8..bdca2d94c3 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselReportingsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselReportingsUTests.kt @@ -23,7 +23,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class GetVesselReportingsUTests { - @MockBean private lateinit var reportingRepository: ReportingRepository @@ -42,18 +41,19 @@ class GetVesselReportingsUTests { ) // When - val currentAndArchivedReportings = GetVesselReportings( - reportingRepository, - infractionRepository, - getAllControlUnits, - ).execute( - null, - "FR224226850", - "1236514", - "IRCS", - VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - expectedDateTime, - ) + val currentAndArchivedReportings = + GetVesselReportings( + reportingRepository, + infractionRepository, + getAllControlUnits, + ).execute( + null, + "FR224226850", + "1236514", + "IRCS", + VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + expectedDateTime, + ) // Then val range = expectedDateTime.year..ZonedDateTime.now().year @@ -76,18 +76,19 @@ class GetVesselReportingsUTests { ) // When - val currentAndArchivedReportings = GetVesselReportings( - reportingRepository, - infractionRepository, - getAllControlUnits, - ).execute( - null, - "FR224226850", - "1236514", - "IRCS", - VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - ZonedDateTime.now().minusYears(1), - ) + val currentAndArchivedReportings = + GetVesselReportings( + reportingRepository, + infractionRepository, + getAllControlUnits, + ).execute( + null, + "FR224226850", + "1236514", + "IRCS", + VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + ZonedDateTime.now().minusYears(1), + ) // Then assertThat(currentAndArchivedReportings.current).hasSize(1) @@ -120,18 +121,19 @@ class GetVesselReportingsUTests { ) // When - val currentAndArchivedReportings = GetVesselReportings( - reportingRepository, - infractionRepository, - getAllControlUnits, - ).execute( - 123456, - "FR224226850", - "1236514", - "IRCS", - VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - ZonedDateTime.now().minusYears(1), - ) + val currentAndArchivedReportings = + GetVesselReportings( + reportingRepository, + infractionRepository, + getAllControlUnits, + ).execute( + 123456, + "FR224226850", + "1236514", + "IRCS", + VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + ZonedDateTime.now().minusYears(1), + ) // Then assertThat(currentAndArchivedReportings.current).hasSize(1) @@ -141,55 +143,60 @@ class GetVesselReportingsUTests { @Test fun `execute Should build the last reporting and other occurrences object`() { // Given - val firstReporting = createCurrentReporting( - id = 12345, - validationDate = ZonedDateTime.parse("2022-09-15T10:15:30Z"), - internalReferenceNumber = "FR224226850", - type = ReportingType.ALERT, - alertType = AlertTypeMapping.THREE_MILES_TRAWLING_ALERT, - ) - - val secondReporting = createCurrentReporting( - id = 123456, - validationDate = ZonedDateTime.parse("2022-11-20T08:00:00Z"), - internalReferenceNumber = "FR224226850", - type = ReportingType.ALERT, - alertType = AlertTypeMapping.THREE_MILES_TRAWLING_ALERT, - ) - - val thirdReporting = createCurrentReporting( - id = 1234567, - validationDate = ZonedDateTime.parse("2024-12-30T15:08:05.845121Z"), - internalReferenceNumber = "FR224226850", - type = ReportingType.ALERT, - alertType = AlertTypeMapping.THREE_MILES_TRAWLING_ALERT, - ) - - val fourthReporting = createCurrentReporting( - id = 12345678, - validationDate = ZonedDateTime.parse("2023-10-30T09:10:00Z"), - internalReferenceNumber = "FR224226850", - type = ReportingType.ALERT, - alertType = AlertTypeMapping.MISSING_FAR_ALERT, - ) + val firstReporting = + createCurrentReporting( + id = 12345, + validationDate = ZonedDateTime.parse("2022-09-15T10:15:30Z"), + internalReferenceNumber = "FR224226850", + type = ReportingType.ALERT, + alertType = AlertTypeMapping.THREE_MILES_TRAWLING_ALERT, + ) + + val secondReporting = + createCurrentReporting( + id = 123456, + validationDate = ZonedDateTime.parse("2022-11-20T08:00:00Z"), + internalReferenceNumber = "FR224226850", + type = ReportingType.ALERT, + alertType = AlertTypeMapping.THREE_MILES_TRAWLING_ALERT, + ) + + val thirdReporting = + createCurrentReporting( + id = 1234567, + validationDate = ZonedDateTime.parse("2024-12-30T15:08:05.845121Z"), + internalReferenceNumber = "FR224226850", + type = ReportingType.ALERT, + alertType = AlertTypeMapping.THREE_MILES_TRAWLING_ALERT, + ) + + val fourthReporting = + createCurrentReporting( + id = 12345678, + validationDate = ZonedDateTime.parse("2023-10-30T09:10:00Z"), + internalReferenceNumber = "FR224226850", + type = ReportingType.ALERT, + alertType = AlertTypeMapping.MISSING_FAR_ALERT, + ) given(reportingRepository.findCurrentAndArchivedByVesselIdentifierEquals(any(), any(), any())).willReturn( listOf(firstReporting, secondReporting, thirdReporting, fourthReporting), ) // When - val result = GetVesselReportings( - reportingRepository, - infractionRepository, - getAllControlUnits, - ).execute( - null, - "FR224226850", - "1236514", - "IRCS", - VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - ZonedDateTime.now().minusYears(1), - ) + val result = + GetVesselReportings( + reportingRepository, + infractionRepository, + getAllControlUnits, + ).execute( + null, + "FR224226850", + "1236514", + "IRCS", + VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + ZonedDateTime.now().minusYears(1), + ) // Then assertThat(result.current).hasSize(2) @@ -219,55 +226,60 @@ class GetVesselReportingsUTests { @Test fun `execute Should correctly process mixed ReportingTypes with ALERT and INFRACTION_SUSPICION`() { // Given - val alertReporting1 = createCurrentReporting( - id = 11223, - validationDate = ZonedDateTime.parse("2024-01-01T12:00:00Z"), - internalReferenceNumber = "FR55667788", - type = ReportingType.ALERT, - alertType = AlertTypeMapping.TWELVE_MILES_FISHING_ALERT, - ) - - val alertReporting2 = createCurrentReporting( - id = 22334, - validationDate = ZonedDateTime.parse("2024-02-01T12:00:00Z"), - internalReferenceNumber = "FR55667788", - type = ReportingType.ALERT, - alertType = AlertTypeMapping.TWELVE_MILES_FISHING_ALERT, - ) - - val infractionReporting = createCurrentReporting( - id = 33445, - validationDate = ZonedDateTime.parse("2024-03-01T12:00:00Z"), - internalReferenceNumber = "FR55667788", - type = ReportingType.INFRACTION_SUSPICION, - alertType = null, // Not applicable for INFRACTION_SUSPICION - ) - - val alertReporting3 = createCurrentReporting( - id = 44556, - validationDate = ZonedDateTime.parse("2024-04-01T12:00:00Z"), - internalReferenceNumber = "FR55667788", - type = ReportingType.ALERT, - alertType = AlertTypeMapping.MISSING_FAR_48_HOURS_ALERT, - ) + val alertReporting1 = + createCurrentReporting( + id = 11223, + validationDate = ZonedDateTime.parse("2024-01-01T12:00:00Z"), + internalReferenceNumber = "FR55667788", + type = ReportingType.ALERT, + alertType = AlertTypeMapping.TWELVE_MILES_FISHING_ALERT, + ) + + val alertReporting2 = + createCurrentReporting( + id = 22334, + validationDate = ZonedDateTime.parse("2024-02-01T12:00:00Z"), + internalReferenceNumber = "FR55667788", + type = ReportingType.ALERT, + alertType = AlertTypeMapping.TWELVE_MILES_FISHING_ALERT, + ) + + val infractionReporting = + createCurrentReporting( + id = 33445, + validationDate = ZonedDateTime.parse("2024-03-01T12:00:00Z"), + internalReferenceNumber = "FR55667788", + type = ReportingType.INFRACTION_SUSPICION, + alertType = null, // Not applicable for INFRACTION_SUSPICION + ) + + val alertReporting3 = + createCurrentReporting( + id = 44556, + validationDate = ZonedDateTime.parse("2024-04-01T12:00:00Z"), + internalReferenceNumber = "FR55667788", + type = ReportingType.ALERT, + alertType = AlertTypeMapping.MISSING_FAR_48_HOURS_ALERT, + ) given(reportingRepository.findCurrentAndArchivedByVesselIdentifierEquals(any(), any(), any())).willReturn( listOf(alertReporting1, alertReporting2, infractionReporting, alertReporting3), ) // When - val result = GetVesselReportings( - reportingRepository, - infractionRepository, - getAllControlUnits, - ).execute( - null, - "FR55667788", - "1234567", - "IRCS", - VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - ZonedDateTime.now().minusYears(1), - ) + val result = + GetVesselReportings( + reportingRepository, + infractionRepository, + getAllControlUnits, + ).execute( + null, + "FR55667788", + "1234567", + "IRCS", + VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + ZonedDateTime.now().minusYears(1), + ) // Then assertThat(result.current).hasSize(3) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselUTests.kt index 50a2718ec8..54ab845a70 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselUTests.kt @@ -57,9 +57,10 @@ class GetVesselUTests { longitude = 48.2525, speed = 1.8, course = 180.0, - dateTime = now.minusHours( - 4, - ), + dateTime = + now.minusHours( + 4, + ), ) val secondPosition = Position( @@ -77,9 +78,10 @@ class GetVesselUTests { longitude = 48.2525, speed = 1.8, course = 180.0, - dateTime = now.minusHours( - 3, - ), + dateTime = + now.minusHours( + 3, + ), ) val thirdPosition = Position( @@ -97,9 +99,10 @@ class GetVesselUTests { longitude = 48.2525, speed = 1.8, course = 180.0, - dateTime = now.minusHours( - 2, - ), + dateTime = + now.minusHours( + 2, + ), ) val fourthPosition = Position( @@ -117,9 +120,10 @@ class GetVesselUTests { longitude = 48.2525, speed = 1.8, course = 180.0, - dateTime = now.minusHours( - 1, - ), + dateTime = + now.minusHours( + 1, + ), ) given(positionRepository.findVesselLastPositionsByInternalReferenceNumber(any(), any(), any())).willReturn( listOf(firstPosition, fourthPosition, secondPosition, thirdPosition), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselVoyageUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselVoyageUTests.kt index d8555fdeba..40a6def21c 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselVoyageUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/GetVesselVoyageUTests.kt @@ -21,7 +21,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class GetVesselVoyageUTests { - @MockBean private lateinit var logbookReportRepository: LogbookReportRepository @@ -44,8 +43,9 @@ class GetVesselVoyageUTests { ) // When - val voyage = GetVesselVoyage(logbookReportRepository, PNOAndLANAlertRepository, getLogbookMessages) - .execute("FR224226850", VoyageRequest.LAST, null) + val voyage = + GetVesselVoyage(logbookReportRepository, PNOAndLANAlertRepository, getLogbookMessages) + .execute("FR224226850", VoyageRequest.LAST, null) val (_, alerts) = voyage.logbookMessagesAndAlerts @@ -63,10 +63,11 @@ class GetVesselVoyageUTests { @Test fun `execute Should throw an Exception When requesting a PREVIOUS voyage with current trip number as null`() { // When - val throwable = catchThrowable { - GetVesselVoyage(logbookReportRepository, PNOAndLANAlertRepository, getLogbookMessages) - .execute("FR224226850", VoyageRequest.PREVIOUS, null) - } + val throwable = + catchThrowable { + GetVesselVoyage(logbookReportRepository, PNOAndLANAlertRepository, getLogbookMessages) + .execute("FR224226850", VoyageRequest.PREVIOUS, null) + } // Then assertThat(throwable).isNotNull @@ -86,8 +87,9 @@ class GetVesselVoyageUTests { ) // When - val voyage = GetVesselVoyage(logbookReportRepository, PNOAndLANAlertRepository, getLogbookMessages) - .execute("FR224226850", VoyageRequest.LAST, "12345") + val voyage = + GetVesselVoyage(logbookReportRepository, PNOAndLANAlertRepository, getLogbookMessages) + .execute("FR224226850", VoyageRequest.LAST, "12345") val (_, alerts) = voyage.logbookMessagesAndAlerts @@ -116,8 +118,9 @@ class GetVesselVoyageUTests { ) // When - val voyage = GetVesselVoyage(logbookReportRepository, PNOAndLANAlertRepository, getLogbookMessages) - .execute("FR224226850", VoyageRequest.NEXT, "123456788") + val voyage = + GetVesselVoyage(logbookReportRepository, PNOAndLANAlertRepository, getLogbookMessages) + .execute("FR224226850", VoyageRequest.NEXT, "123456788") val (_, alerts) = voyage.logbookMessagesAndAlerts @@ -139,8 +142,9 @@ class GetVesselVoyageUTests { ) // When - val voyage = GetVesselVoyage(logbookReportRepository, PNOAndLANAlertRepository, getLogbookMessages) - .execute("FR224226850", VoyageRequest.EQUALS, "123456788") + val voyage = + GetVesselVoyage(logbookReportRepository, PNOAndLANAlertRepository, getLogbookMessages) + .execute("FR224226850", VoyageRequest.EQUALS, "123456788") val (_, alerts) = voyage.logbookMessagesAndAlerts diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SearchVesselsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SearchVesselsUTests.kt index caae2e0503..a17121cdb8 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SearchVesselsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SearchVesselsUTests.kt @@ -17,7 +17,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class SearchVesselsUTests { - @MockBean private lateinit var vesselRepository: VesselRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SilenceAlertUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SilenceAlertUTests.kt index f33acee339..b683a4b325 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SilenceAlertUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SilenceAlertUTests.kt @@ -19,7 +19,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class SilenceAlertUTests { - @MockBean private lateinit var silencedAlertRepository: SilencedAlertRepository @@ -27,16 +26,17 @@ class SilenceAlertUTests { fun `execute Should silence an alert`() { // Given val now = ZonedDateTime.now() - val alertToSilence = SilencedAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - value = ThreeMilesTrawlingAlert(), - silencedBeforeDate = now.plusDays(25), - ) + val alertToSilence = + SilencedAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + value = ThreeMilesTrawlingAlert(), + silencedBeforeDate = now.plusDays(25), + ) given(silencedAlertRepository.save(any())).willReturn(alertToSilence) // When @@ -57,16 +57,17 @@ class SilenceAlertUTests { fun `execute Should silence two alert When a MISSING_FAR_ALERT is silenced`() { // Given val now = ZonedDateTime.now() - val alertToSilence = SilencedAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - value = MissingFARAlert(), - silencedBeforeDate = now.plusDays(25), - ) + val alertToSilence = + SilencedAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + value = MissingFARAlert(), + silencedBeforeDate = now.plusDays(25), + ) given(silencedAlertRepository.save(any())).willReturn(alertToSilence) // When @@ -92,16 +93,17 @@ class SilenceAlertUTests { fun `execute Should silence two alert When a MISSING_FAR_48_HOURS_ALERT is silenced`() { // Given val now = ZonedDateTime.now() - val alertToSilence = SilencedAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - value = MissingFAR48HoursAlert(), - silencedBeforeDate = now.plusDays(25), - ) + val alertToSilence = + SilencedAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + value = MissingFAR48HoursAlert(), + silencedBeforeDate = now.plusDays(25), + ) given(silencedAlertRepository.save(any())).willReturn(alertToSilence) // When diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SilencePendingAlertUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SilencePendingAlertUTests.kt index 722dbf93c4..c10df2787f 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SilencePendingAlertUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/SilencePendingAlertUTests.kt @@ -22,7 +22,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class SilencePendingAlertUTests { - @MockBean private lateinit var pendingAlertRepository: PendingAlertRepository @@ -35,17 +34,18 @@ class SilencePendingAlertUTests { @Test fun `execute Should silence a pending alert for one day`() { // Given - val pendingAlert = PendingAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = ThreeMilesTrawlingAlert(), - ) + val pendingAlert = + PendingAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = ThreeMilesTrawlingAlert(), + ) given(pendingAlertRepository.find(any())).willReturn(pendingAlert) // When @@ -74,17 +74,18 @@ class SilencePendingAlertUTests { @Test fun `execute Should silence a pending alert for a custom period`() { // Given - val pendingAlert = PendingAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = ThreeMilesTrawlingAlert(), - ) + val pendingAlert = + PendingAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = ThreeMilesTrawlingAlert(), + ) given(pendingAlertRepository.find(any())).willReturn(pendingAlert) // When @@ -111,31 +112,33 @@ class SilencePendingAlertUTests { @Test fun `execute Should throw an exception When silencing a pending alert for a custom period Without after or before dates`() { // Given - val pendingAlert = PendingAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = ThreeMilesTrawlingAlert(), - ) + val pendingAlert = + PendingAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = ThreeMilesTrawlingAlert(), + ) given(pendingAlertRepository.find(any())).willReturn(pendingAlert) // When - val throwable = catchThrowable { - SilencePendingAlert( - pendingAlertRepository, - silencedAlertRepository, - lastPositionRepository, - ).execute( - 666, - SilenceAlertPeriod.CUSTOM, - null, - ) - } + val throwable = + catchThrowable { + SilencePendingAlert( + pendingAlertRepository, + silencedAlertRepository, + lastPositionRepository, + ).execute( + 666, + SilenceAlertPeriod.CUSTOM, + null, + ) + } // Then assertThat(throwable).isNotNull diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/TestUtils.kt index 40bb6c18c8..5f1eabf7ab 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/TestUtils.kt @@ -14,12 +14,13 @@ import java.time.ZoneOffset.UTC import java.time.ZonedDateTime object TestUtils { - val DUMMY_VESSEL = Vessel( - id = 123, - internalReferenceNumber = "DUMMY_CFR", - flagState = CountryCode.FR, - hasLogbookEsacapt = false, - ) + val DUMMY_VESSEL = + Vessel( + id = 123, + internalReferenceNumber = "DUMMY_CFR", + flagState = CountryCode.FR, + hasLogbookEsacapt = false, + ) fun createCurrentReporting( internalReferenceNumber: String, @@ -35,24 +36,29 @@ object TestUtils { type = type, isArchived = false, isDeleted = false, - infraction = Infraction( - natinfCode = 2610, - infractionCategory = InfractionCategory.FISHING, - ), - value = when (alertType) { - AlertTypeMapping.PNO_LAN_WEIGHT_TOLERANCE_ALERT -> throw IllegalArgumentException("Unhandled test case") - AlertTypeMapping.THREE_MILES_TRAWLING_ALERT -> ThreeMilesTrawlingAlert(seaFront = NAMO.toString()) - AlertTypeMapping.FRENCH_EEZ_FISHING_ALERT -> FrenchEEZFishingAlert(seaFront = NAMO.toString()) - AlertTypeMapping.TWELVE_MILES_FISHING_ALERT -> TwelveMilesFishingAlert(seaFront = NAMO.toString()) - AlertTypeMapping.MISSING_FAR_ALERT -> MissingFARAlert(seaFront = NAMO.toString()) - AlertTypeMapping.MISSING_FAR_48_HOURS_ALERT -> MissingFAR48HoursAlert(seaFront = NAMO.toString()) - else -> InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ) - }, + infraction = + Infraction( + natinfCode = 2610, + infractionCategory = InfractionCategory.FISHING, + ), + value = + when (alertType) { + AlertTypeMapping.PNO_LAN_WEIGHT_TOLERANCE_ALERT -> throw IllegalArgumentException( + "Unhandled test case", + ) + AlertTypeMapping.THREE_MILES_TRAWLING_ALERT -> ThreeMilesTrawlingAlert(seaFront = NAMO.toString()) + AlertTypeMapping.FRENCH_EEZ_FISHING_ALERT -> FrenchEEZFishingAlert(seaFront = NAMO.toString()) + AlertTypeMapping.TWELVE_MILES_FISHING_ALERT -> TwelveMilesFishingAlert(seaFront = NAMO.toString()) + AlertTypeMapping.MISSING_FAR_ALERT -> MissingFARAlert(seaFront = NAMO.toString()) + AlertTypeMapping.MISSING_FAR_48_HOURS_ALERT -> MissingFAR48HoursAlert(seaFront = NAMO.toString()) + else -> + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ) + }, underCharter = null, vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, internalReferenceNumber = internalReferenceNumber, @@ -172,16 +178,17 @@ object TestUtils { messageType = "FAR", software = "TurboCatch (3.7-1)", message = far, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(12), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(12), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -196,16 +203,17 @@ object TestUtils { messageType = "DEP", software = "e-Sacapt Secours ERSV3 V 1.0.10", message = dep, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(24), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(24), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -220,16 +228,17 @@ object TestUtils { messageType = "PNO", software = "e-Sacapt Secours ERSV3 V 1.0.7", message = pno, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(0), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(0), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -244,16 +253,17 @@ object TestUtils { messageType = "COE", software = "e-Sacapt Secours ERSV3 V 1.0.7", message = coe, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(3), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(3), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -268,9 +278,10 @@ object TestUtils { messageType = "COX", software = "e-Sacapt Secours ERSV3 V 1.0.7", message = cox, - reportDateTime = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, UTC).minusHours(0).minusMinutes( - 20, - ), + reportDateTime = + ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, UTC).minusHours(0).minusMinutes( + 20, + ), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -285,9 +296,10 @@ object TestUtils { messageType = "CPS", software = "", message = cpsMessage, - reportDateTime = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, UTC).minusHours(0).minusMinutes( - 20, - ), + reportDateTime = + ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, UTC).minusHours(0).minusMinutes( + 20, + ), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -335,16 +347,17 @@ object TestUtils { messageType = "DEP", software = "FT/VISIOCaptures V1.4.7", message = dep, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(24), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(24), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -359,16 +372,17 @@ object TestUtils { messageType = "FAR", software = "FP/VISIOCaptures V1.4.7", message = far, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(12), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(12), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -383,16 +397,17 @@ object TestUtils { messageType = "PNO", software = "TurboCatch (3.6-1)", message = pno, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(0), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(0), transmissionFormat = LogbookTransmissionFormat.FLUX, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -432,16 +447,17 @@ object TestUtils { operationType = LogbookOperationType.DAT, messageType = "FAR", message = far, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(12), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(12), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -456,16 +472,17 @@ object TestUtils { operationType = LogbookOperationType.COR, messageType = "FAR", message = correctedFar, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(12), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(12), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -512,16 +529,17 @@ object TestUtils { operationType = LogbookOperationType.DAT, messageType = "FAR", message = far, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(12), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(12), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -535,16 +553,17 @@ object TestUtils { operationType = LogbookOperationType.RET, messageType = "", message = farBadAck, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(12), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(12), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -558,16 +577,17 @@ object TestUtils { operationType = LogbookOperationType.DAT, messageType = "FAR", message = farTwo, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(12), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(12), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -581,16 +601,17 @@ object TestUtils { operationType = LogbookOperationType.RET, messageType = "", message = farAck, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(12), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(12), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -603,16 +624,17 @@ object TestUtils { operationType = LogbookOperationType.DEL, messageType = "", message = farAck, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 4, - 5, - 3, - UTC, - ).minusHours(12), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(12), transmissionFormat = LogbookTransmissionFormat.ERS, integrationDateTime = ZonedDateTime.now(), isEnriched = false, @@ -626,16 +648,17 @@ object TestUtils { operationType = LogbookOperationType.DAT, messageType = "FAR", message = far, - reportDateTime = ZonedDateTime.of( - 2020, - 5, - 5, - 3, - 9, - 5, - 3, - UTC, - ).minusHours(12), + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 9, + 5, + 3, + UTC, + ).minusHours(12), transmissionFormat = LogbookTransmissionFormat.FLUX, integrationDateTime = ZonedDateTime.now(), isEnriched = false, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/UpdateControlObjectiveUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/UpdateControlObjectiveUTests.kt index 471d850ccb..fd48433cca 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/UpdateControlObjectiveUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/UpdateControlObjectiveUTests.kt @@ -11,16 +11,16 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class UpdateControlObjectiveUTests { - @MockBean private lateinit var controlObjectivesRepository: ControlObjectivesRepository @Test fun `execute Should throw an exception When no field to update is given`() { // When - val throwable = catchThrowable { - UpdateControlObjective(controlObjectivesRepository).execute(1, null, null, null) - } + val throwable = + catchThrowable { + UpdateControlObjective(controlObjectivesRepository).execute(1, null, null, null) + } // Then assertThat(throwable).isInstanceOf(IllegalArgumentException::class.java) @@ -30,9 +30,10 @@ class UpdateControlObjectiveUTests { @Test fun `execute Should not throw an exception When a field to update is given`() { // When - val throwable = catchThrowable { - UpdateControlObjective(controlObjectivesRepository).execute(1, 123, null, null) - } + val throwable = + catchThrowable { + UpdateControlObjective(controlObjectivesRepository).execute(1, 123, null, null) + } // Then assertThat(throwable).isNull() diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/UpdateReportingUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/UpdateReportingUTests.kt index 2f6f522067..b40d46220b 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/UpdateReportingUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/UpdateReportingUTests.kt @@ -22,7 +22,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class UpdateReportingUTests { - @MockBean private lateinit var reportingRepository: ReportingRepository @@ -54,18 +53,19 @@ class UpdateReportingUTests { ) // When - val throwable = catchThrowable { - UpdateReporting(reportingRepository, getInfractionSuspicionWithDMLAndSeaFront, getAllControlUnits) - .execute( - 1, - UpdatedInfractionSuspicionOrObservation( - reportingActor = ReportingActor.UNIT, - type = ReportingType.OBSERVATION, - authorTrigram = "LTH", - title = "A reporting", - ), - ) - } + val throwable = + catchThrowable { + UpdateReporting(reportingRepository, getInfractionSuspicionWithDMLAndSeaFront, getAllControlUnits) + .execute( + 1, + UpdatedInfractionSuspicionOrObservation( + reportingActor = ReportingActor.UNIT, + type = ReportingType.OBSERVATION, + authorTrigram = "LTH", + title = "A reporting", + ), + ) + } // Then assertThat(throwable.message).contains("The edited reporting must be an INFRACTION_SUSPICION or an OBSERVATION") @@ -86,30 +86,32 @@ class UpdateReportingUTests { flagState = CountryCode.FR, creationDate = ZonedDateTime.now(), validationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - reportingActor = ReportingActor.UNIT, - authorTrigram = "LTH", - title = "Test", - natinfCode = 1234, - ) as ReportingValue, + value = + InfractionSuspicion( + reportingActor = ReportingActor.UNIT, + authorTrigram = "LTH", + title = "Test", + natinfCode = 1234, + ) as ReportingValue, isArchived = false, isDeleted = false, ), ) // When - val throwable = catchThrowable { - UpdateReporting(reportingRepository, getInfractionSuspicionWithDMLAndSeaFront, getAllControlUnits) - .execute( - 1, - UpdatedInfractionSuspicionOrObservation( - reportingActor = ReportingActor.UNIT, - type = ReportingType.ALERT, - authorTrigram = "LTH", - title = "A reporting", - ), - ) - } + val throwable = + catchThrowable { + UpdateReporting(reportingRepository, getInfractionSuspicionWithDMLAndSeaFront, getAllControlUnits) + .execute( + 1, + UpdatedInfractionSuspicionOrObservation( + reportingActor = ReportingActor.UNIT, + type = ReportingType.ALERT, + authorTrigram = "LTH", + title = "A reporting", + ), + ) + } // Then assertThat(throwable.message).contains( @@ -123,26 +125,28 @@ class UpdateReportingUTests { reportingActor: ReportingActor, ) { // Given - val reporting = Reporting( - id = 1, - type = ReportingType.INFRACTION_SUSPICION, - vesselName = "BIDUBULE", - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - validationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - reportingActor = ReportingActor.UNIT, - authorTrigram = "LTH", - title = "Test", - natinfCode = 1234, - ) as ReportingValue, - isArchived = false, - isDeleted = false, - ) + val reporting = + Reporting( + id = 1, + type = ReportingType.INFRACTION_SUSPICION, + vesselName = "BIDUBULE", + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + validationDate = ZonedDateTime.now(), + value = + InfractionSuspicion( + reportingActor = ReportingActor.UNIT, + authorTrigram = "LTH", + title = "Test", + natinfCode = 1234, + ) as ReportingValue, + isArchived = false, + isDeleted = false, + ) given(reportingRepository.findById(any())).willReturn(reporting) given(reportingRepository.update(any(), isA())).willReturn(reporting) given(getInfractionSuspicionWithDMLAndSeaFront.execute(any(), anyOrNull())).willReturn( @@ -155,19 +159,20 @@ class UpdateReportingUTests { ) // When - val throwable = catchThrowable { - UpdateReporting(reportingRepository, getInfractionSuspicionWithDMLAndSeaFront, getAllControlUnits) - .execute( - 1, - UpdatedInfractionSuspicionOrObservation( - reportingActor = reportingActor, - type = ReportingType.INFRACTION_SUSPICION, - authorTrigram = "LTH", - title = "A reporting", - natinfCode = 123456, - ), - ) - } + val throwable = + catchThrowable { + UpdateReporting(reportingRepository, getInfractionSuspicionWithDMLAndSeaFront, getAllControlUnits) + .execute( + 1, + UpdatedInfractionSuspicionOrObservation( + reportingActor = reportingActor, + type = ReportingType.INFRACTION_SUSPICION, + authorTrigram = "LTH", + title = "A reporting", + natinfCode = 123456, + ), + ) + } // Then when (reportingActor) { @@ -195,29 +200,35 @@ class UpdateReportingUTests { flagState = CountryCode.FR, creationDate = ZonedDateTime.now(), validationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - reportingActor = ReportingActor.UNIT, - authorTrigram = "LTH", - title = "Test", - natinfCode = 1234, - ) as ReportingValue, + value = + InfractionSuspicion( + reportingActor = ReportingActor.UNIT, + authorTrigram = "LTH", + title = "Test", + natinfCode = 1234, + ) as ReportingValue, isArchived = false, isDeleted = false, ), ) // When - val throwable = catchThrowable { - UpdateReporting(reportingRepository, getInfractionSuspicionWithDMLAndSeaFront, getAllControlUnits).execute( - 1, - UpdatedInfractionSuspicionOrObservation( - reportingActor = ReportingActor.UNIT, - type = ReportingType.INFRACTION_SUSPICION, - authorTrigram = "LTH", - title = "A reporting", - ), - ) - } + val throwable = + catchThrowable { + UpdateReporting( + reportingRepository, + getInfractionSuspicionWithDMLAndSeaFront, + getAllControlUnits, + ).execute( + 1, + UpdatedInfractionSuspicionOrObservation( + reportingActor = ReportingActor.UNIT, + type = ReportingType.INFRACTION_SUSPICION, + authorTrigram = "LTH", + title = "A reporting", + ), + ) + } // Then assertThat(throwable.message).contains("NATINF code should not be null") @@ -226,28 +237,30 @@ class UpdateReportingUTests { @Test fun `execute Should update the reporting`() { // Given - val observation = Observation( - reportingActor = ReportingActor.UNIT, - controlUnitId = 1, - title = "A title", - authorTrigram = "LTH", - description = "Before update", - ) - val reporting = Reporting( - id = 1, - type = ReportingType.OBSERVATION, - vesselName = "BIDUBULE", - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - validationDate = ZonedDateTime.now(), - value = observation as ReportingValue, - isArchived = false, - isDeleted = false, - ) + val observation = + Observation( + reportingActor = ReportingActor.UNIT, + controlUnitId = 1, + title = "A title", + authorTrigram = "LTH", + description = "Before update", + ) + val reporting = + Reporting( + id = 1, + type = ReportingType.OBSERVATION, + vesselName = "BIDUBULE", + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + validationDate = ZonedDateTime.now(), + value = observation as ReportingValue, + isArchived = false, + isDeleted = false, + ) given(reportingRepository.findById(any())).willReturn(reporting) given(reportingRepository.update(any(), isA())).willReturn(reporting) @@ -276,26 +289,28 @@ class UpdateReportingUTests { @Test fun `execute Should update the reporting type`() { // Given - val reporting = Reporting( - id = 1, - type = ReportingType.INFRACTION_SUSPICION, - vesselName = "BIDUBULE", - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - validationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - reportingActor = ReportingActor.UNIT, - authorTrigram = "LTH", - title = "Test", - natinfCode = 1234, - ) as ReportingValue, - isArchived = false, - isDeleted = false, - ) + val reporting = + Reporting( + id = 1, + type = ReportingType.INFRACTION_SUSPICION, + vesselName = "BIDUBULE", + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + validationDate = ZonedDateTime.now(), + value = + InfractionSuspicion( + reportingActor = ReportingActor.UNIT, + authorTrigram = "LTH", + title = "Test", + natinfCode = 1234, + ) as ReportingValue, + isArchived = false, + isDeleted = false, + ) given(reportingRepository.findById(any())).willReturn(reporting) given(reportingRepository.update(any(), isA())).willReturn(reporting) @@ -326,26 +341,28 @@ class UpdateReportingUTests { @Test fun `execute Should add the flagState, the DML and the sea front of the reporting When the reporting is an INFRACTION_SUSPICION`() { // Given - val reporting = Reporting( - id = 1, - type = ReportingType.INFRACTION_SUSPICION, - vesselName = "BIDUBULE", - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - validationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - reportingActor = ReportingActor.UNIT, - title = "Test", - natinfCode = 1234, - authorTrigram = "LTH", - ) as ReportingValue, - isArchived = false, - isDeleted = false, - ) + val reporting = + Reporting( + id = 1, + type = ReportingType.INFRACTION_SUSPICION, + vesselName = "BIDUBULE", + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + validationDate = ZonedDateTime.now(), + value = + InfractionSuspicion( + reportingActor = ReportingActor.UNIT, + title = "Test", + natinfCode = 1234, + authorTrigram = "LTH", + ) as ReportingValue, + isArchived = false, + isDeleted = false, + ) given(reportingRepository.findById(any())).willReturn(reporting) given(reportingRepository.update(any(), isA())).willReturn(reporting) given(getInfractionSuspicionWithDMLAndSeaFront.execute(any(), anyOrNull())).willReturn( @@ -385,25 +402,27 @@ class UpdateReportingUTests { @Test fun `execute Should add the flagState of the previous reporting When the reporting is an OBSERVATION`() { // Given - val reporting = Reporting( - id = 1, - type = ReportingType.OBSERVATION, - vesselName = "BIDUBULE", - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - validationDate = ZonedDateTime.now(), - value = Observation( - reportingActor = ReportingActor.UNIT, - title = "Test", - authorTrigram = "LTH", - ) as ReportingValue, - isArchived = false, - isDeleted = false, - ) + val reporting = + Reporting( + id = 1, + type = ReportingType.OBSERVATION, + vesselName = "BIDUBULE", + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + validationDate = ZonedDateTime.now(), + value = + Observation( + reportingActor = ReportingActor.UNIT, + title = "Test", + authorTrigram = "LTH", + ) as ReportingValue, + isArchived = false, + isDeleted = false, + ) given(reportingRepository.findById(any())).willReturn(reporting) given(reportingRepository.update(any(), isA())).willReturn(reporting) @@ -429,25 +448,27 @@ class UpdateReportingUTests { @Test fun `execute Should migrate an OBSERVATION reporting to an INFRACTION_SUSPICION`() { // Given - val reporting = Reporting( - id = 1, - type = ReportingType.OBSERVATION, - vesselName = "BIDUBULE", - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - validationDate = ZonedDateTime.now(), - value = Observation( - reportingActor = ReportingActor.UNIT, - title = "Test", - authorTrigram = "LTH", - ) as ReportingValue, - isArchived = false, - isDeleted = false, - ) + val reporting = + Reporting( + id = 1, + type = ReportingType.OBSERVATION, + vesselName = "BIDUBULE", + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + validationDate = ZonedDateTime.now(), + value = + Observation( + reportingActor = ReportingActor.UNIT, + title = "Test", + authorTrigram = "LTH", + ) as ReportingValue, + isArchived = false, + isDeleted = false, + ) given(reportingRepository.findById(any())).willReturn(reporting) given(reportingRepository.update(any(), isA())).willReturn(reporting) given(getInfractionSuspicionWithDMLAndSeaFront.execute(any(), anyOrNull())).willReturn( diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/ValidatePendingAlertUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/ValidatePendingAlertUTests.kt index 6b1269b488..c8897a7c4e 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/ValidatePendingAlertUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/ValidatePendingAlertUTests.kt @@ -22,7 +22,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class ValidatePendingAlertUTests { - @MockBean private lateinit var pendingAlertRepository: PendingAlertRepository @@ -38,19 +37,20 @@ class ValidatePendingAlertUTests { @Test fun `execute Should validate a pending alert`() { // Given - val pendingAlert = PendingAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = ThreeMilesTrawlingAlert(), - latitude = 12.123, - longitude = -5.5698, - ) + val pendingAlert = + PendingAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = ThreeMilesTrawlingAlert(), + latitude = 12.123, + longitude = -5.5698, + ) given(pendingAlertRepository.find(any())).willReturn(pendingAlert) // When diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/GetIsAuthorizedUserUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/GetIsAuthorizedUserUTests.kt index af94ea745c..1d7bebafcb 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/GetIsAuthorizedUserUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/authorization/GetIsAuthorizedUserUTests.kt @@ -13,7 +13,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class GetIsAuthorizedUserUTests { - @MockBean private lateinit var userAuthorizationRepository: JpaUserAuthorizationRepository @@ -24,10 +23,11 @@ class GetIsAuthorizedUserUTests { ) // When - val isAuthorized = GetIsAuthorizedUser(userAuthorizationRepository).execute( - "test", - true, - ) + val isAuthorized = + GetIsAuthorizedUser(userAuthorizationRepository).execute( + "test", + true, + ) // Then assertThat(isAuthorized).isTrue() @@ -40,10 +40,11 @@ class GetIsAuthorizedUserUTests { ) // When - val isAuthorized = GetIsAuthorizedUser(userAuthorizationRepository).execute( - "test", - true, - ) + val isAuthorized = + GetIsAuthorizedUser(userAuthorizationRepository).execute( + "test", + true, + ) // Then assertThat(isAuthorized).isFalse() @@ -52,10 +53,11 @@ class GetIsAuthorizedUserUTests { @Test fun `execute Should return true When the path is not super-user protected`() { // When - val isAuthorized = GetIsAuthorizedUser(userAuthorizationRepository).execute( - "test", - false, - ) + val isAuthorized = + GetIsAuthorizedUser(userAuthorizationRepository).execute( + "test", + false, + ) // Then assertThat(isAuthorized).isTrue() @@ -68,10 +70,11 @@ class GetIsAuthorizedUserUTests { ) // When - val isAuthorized = GetIsAuthorizedUser(userAuthorizationRepository).execute( - "test", - true, - ) + val isAuthorized = + GetIsAuthorizedUser(userAuthorizationRepository).execute( + "test", + true, + ) // Then assertThat(isAuthorized).isFalse() diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetAllBeaconMalfunctionsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetAllBeaconMalfunctionsUTests.kt index 686f32ab03..cbfa55d513 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetAllBeaconMalfunctionsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetAllBeaconMalfunctionsUTests.kt @@ -18,7 +18,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class GetAllBeaconMalfunctionsUTests { - @MockBean private lateinit var beaconMalfunctionsRepository: BeaconMalfunctionsRepository @@ -32,34 +31,42 @@ class GetAllBeaconMalfunctionsUTests { fun `execute Should return the beacon malfunctions filtered and enriched with the risk factor found in the last position table`() { // Given val now = ZonedDateTime.now().minusDays(1) - val firstPosition = LastPosition( - null, null, "FR224226850", "224226850", null, null, null, CountryCode.FR, PositionType.AIS, 16.445, 48.2525, 1.8, 180.0, riskFactor = 1.23, - dateTime = now.minusHours( - 4, - ), - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - ) - val secondPosition = LastPosition( - null, null, "FR123456785", "224226850", null, null, null, CountryCode.FR, PositionType.AIS, 16.445, 48.2525, 1.8, 180.0, riskFactor = 1.54, - dateTime = now.minusHours( - 3, - ), - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - ) - val thirdPosition = LastPosition( - null, null, "FR224226856", "224226850", null, null, null, CountryCode.FR, PositionType.AIS, 16.445, 48.2525, 1.8, 180.0, riskFactor = 1.98, - dateTime = now.minusHours( - 2, - ), - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - ) - val fourthPosition = LastPosition( - null, null, "FR224226857", "224226850", null, null, null, CountryCode.FR, PositionType.AIS, 16.445, 48.2525, 1.8, 180.0, riskFactor = 1.24, - dateTime = now.minusHours( - 1, - ), - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - ) + val firstPosition = + LastPosition( + null, null, "FR224226850", "224226850", null, null, null, CountryCode.FR, PositionType.AIS, 16.445, 48.2525, 1.8, 180.0, riskFactor = 1.23, + dateTime = + now.minusHours( + 4, + ), + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + ) + val secondPosition = + LastPosition( + null, null, "FR123456785", "224226850", null, null, null, CountryCode.FR, PositionType.AIS, 16.445, 48.2525, 1.8, 180.0, riskFactor = 1.54, + dateTime = + now.minusHours( + 3, + ), + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + ) + val thirdPosition = + LastPosition( + null, null, "FR224226856", "224226850", null, null, null, CountryCode.FR, PositionType.AIS, 16.445, 48.2525, 1.8, 180.0, riskFactor = 1.98, + dateTime = + now.minusHours( + 2, + ), + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + ) + val fourthPosition = + LastPosition( + null, null, "FR224226857", "224226850", null, null, null, CountryCode.FR, PositionType.AIS, 16.445, 48.2525, 1.8, 180.0, riskFactor = 1.24, + dateTime = + now.minusHours( + 1, + ), + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + ) given(lastPositionRepository.findAll()).willReturn( listOf(firstPosition, fourthPosition, secondPosition, thirdPosition), ) @@ -99,11 +106,12 @@ class GetAllBeaconMalfunctionsUTests { given(beaconRepository.findActivatedBeaconNumbers()).willReturn(listOf("123465", "another active beacon")) // When - val filteredAndEnrichedBeaconMalfunctions = GetAllBeaconMalfunctions( - beaconMalfunctionsRepository, - lastPositionRepository, - beaconRepository, - ).execute() + val filteredAndEnrichedBeaconMalfunctions = + GetAllBeaconMalfunctions( + beaconMalfunctionsRepository, + lastPositionRepository, + beaconRepository, + ).execute() // Then assertThat(filteredAndEnrichedBeaconMalfunctions).hasSize(3) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetBeaconMalfunctionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetBeaconMalfunctionUTests.kt index eec9cff517..8ab9376261 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetBeaconMalfunctionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetBeaconMalfunctionUTests.kt @@ -16,7 +16,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class GetBeaconMalfunctionUTests { - @MockBean private lateinit var beaconMalfunctionsRepository: BeaconMalfunctionsRepository @@ -115,14 +114,15 @@ class GetBeaconMalfunctionUTests { ) // When - val beaconMalfunctions = GetBeaconMalfunction( - beaconMalfunctionsRepository, - beaconMalfunctionCommentsRepository, - beaconMalfunctionActionsRepository, - lastPositionRepository, - beaconMalfunctionNotificationsRepository, - ) - .execute(1) + val beaconMalfunctions = + GetBeaconMalfunction( + beaconMalfunctionsRepository, + beaconMalfunctionCommentsRepository, + beaconMalfunctionActionsRepository, + lastPositionRepository, + beaconMalfunctionNotificationsRepository, + ) + .execute(1) // Then assertThat(beaconMalfunctions.resume?.numberOfBeaconsAtSea).isEqualTo(1) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetVesselBeaconMalfunctionsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetVesselBeaconMalfunctionsUTests.kt index 642c705b3a..6e8168c9e6 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetVesselBeaconMalfunctionsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/GetVesselBeaconMalfunctionsUTests.kt @@ -16,7 +16,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class GetVesselBeaconMalfunctionsUTests { - @MockBean private lateinit var beaconMalfunctionsRepository: BeaconMalfunctionsRepository @@ -75,12 +74,13 @@ class GetVesselBeaconMalfunctionsUTests { ) // When - val enrichedBeaconMalfunctions = GetVesselBeaconMalfunctions( - beaconMalfunctionsRepository, - beaconMalfunctionCommentsRepository, - beaconMalfunctionActionsRepository, - ) - .execute(1, now.minusYears(1)) + val enrichedBeaconMalfunctions = + GetVesselBeaconMalfunctions( + beaconMalfunctionsRepository, + beaconMalfunctionCommentsRepository, + beaconMalfunctionActionsRepository, + ) + .execute(1, now.minusYears(1)) // Then assertThat(enrichedBeaconMalfunctions.history).hasSize(1) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/RequestNotificationUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/RequestNotificationUTests.kt index 553fd5c828..796e2d088a 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/RequestNotificationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/RequestNotificationUTests.kt @@ -12,19 +12,19 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class RequestNotificationUTests { - @MockBean private lateinit var beaconMalfunctionsRepository: BeaconMalfunctionsRepository @Test fun `execute Should throw an exception When notificationRequested is MALFUNCTION_NOTIFICATION_TO_FOREIGN_FMC and no foreignFmcCode is given`() { // When - val throwable = catchThrowable { - RequestNotification( - beaconMalfunctionsRepository, - ) - .execute(1, BeaconMalfunctionNotificationType.MALFUNCTION_NOTIFICATION_TO_FOREIGN_FMC, null) - } + val throwable = + catchThrowable { + RequestNotification( + beaconMalfunctionsRepository, + ) + .execute(1, BeaconMalfunctionNotificationType.MALFUNCTION_NOTIFICATION_TO_FOREIGN_FMC, null) + } // Then assertThat(throwable).isInstanceOf(IllegalArgumentException::class.java) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/UpdateBeaconMalfunctionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/UpdateBeaconMalfunctionUTests.kt index a3ce6f68b3..7ebd61dfd7 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/UpdateBeaconMalfunctionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/beacon_malfunction/UpdateBeaconMalfunctionUTests.kt @@ -18,7 +18,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class UpdateBeaconMalfunctionUTests { - @MockBean private lateinit var beaconMalfunctionsRepository: BeaconMalfunctionsRepository @@ -34,14 +33,15 @@ class UpdateBeaconMalfunctionUTests { @Test fun `execute Should throw an exception When no field to update is given`() { // When - val throwable = catchThrowable { - UpdateBeaconMalfunction( - beaconMalfunctionsRepository, - beaconMalfunctionActionRepository, - getBeaconMalfunction, - ) - .execute(1, null, null, null) - } + val throwable = + catchThrowable { + UpdateBeaconMalfunction( + beaconMalfunctionsRepository, + beaconMalfunctionActionRepository, + getBeaconMalfunction, + ) + .execute(1, null, null, null) + } // Then assertThat(throwable).isInstanceOf(IllegalArgumentException::class.java) @@ -51,14 +51,15 @@ class UpdateBeaconMalfunctionUTests { @Test fun `execute Should throw an exception When the Stage is ARCHIVED but there si no endOfBeaconMalfunctionReason`() { // When - val throwable = catchThrowable { - UpdateBeaconMalfunction( - beaconMalfunctionsRepository, - beaconMalfunctionActionRepository, - getBeaconMalfunction, - ) - .execute(1, null, Stage.ARCHIVED, null) - } + val throwable = + catchThrowable { + UpdateBeaconMalfunction( + beaconMalfunctionsRepository, + beaconMalfunctionActionRepository, + getBeaconMalfunction, + ) + .execute(1, null, Stage.ARCHIVED, null) + } // Then assertThat(throwable).isInstanceOf(IllegalArgumentException::class.java) @@ -93,58 +94,64 @@ class UpdateBeaconMalfunctionUTests { given(getBeaconMalfunction.execute(1)) .willReturn( BeaconMalfunctionResumeAndDetails( - beaconMalfunction = BeaconMalfunction( - 1, "CFR", "EXTERNAL_IMMAT", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, - ZonedDateTime.now(), null, ZonedDateTime.now(), - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - 1, - 1, - "A comment", - BeaconMalfunctionCommentUserType.SIP, - ZonedDateTime.now(), + beaconMalfunction = + BeaconMalfunction( + 1, "CFR", "EXTERNAL_IMMAT", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, + ZonedDateTime.now(), null, ZonedDateTime.now(), + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, ), - ), - actions = listOf( - BeaconMalfunctionAction( - 1, - 1, - BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - "PREVIOUS", - "NEXT", - ZonedDateTime.now(), + comments = + listOf( + BeaconMalfunctionComment( + 1, + 1, + "A comment", + BeaconMalfunctionCommentUserType.SIP, + ZonedDateTime.now(), + ), ), - ), - notifications = listOf( - BeaconMalfunctionNotifications( - beaconMalfunctionId = 1, - dateTimeUtc = ZonedDateTime.now(), - notificationType = BeaconMalfunctionNotificationType.MALFUNCTION_AT_PORT_INITIAL_NOTIFICATION, - notifications = listOf( - BeaconMalfunctionNotification( - id = 1, beaconMalfunctionId = 1, dateTimeUtc = ZonedDateTime.now(), - notificationType = BeaconMalfunctionNotificationType.MALFUNCTION_AT_PORT_INITIAL_NOTIFICATION, - communicationMeans = CommunicationMeans.SMS, - recipientFunction = BeaconMalfunctionNotificationRecipientFunction.VESSEL_CAPTAIN, - recipientName = "Jack Sparrow", recipientAddressOrNumber = "0000000000", - success = false, errorMessage = "This message could not be delivered", - ), + actions = + listOf( + BeaconMalfunctionAction( + 1, + 1, + BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + "PREVIOUS", + "NEXT", + ZonedDateTime.now(), + ), + ), + notifications = + listOf( + BeaconMalfunctionNotifications( + beaconMalfunctionId = 1, + dateTimeUtc = ZonedDateTime.now(), + notificationType = BeaconMalfunctionNotificationType.MALFUNCTION_AT_PORT_INITIAL_NOTIFICATION, + notifications = + listOf( + BeaconMalfunctionNotification( + id = 1, beaconMalfunctionId = 1, dateTimeUtc = ZonedDateTime.now(), + notificationType = BeaconMalfunctionNotificationType.MALFUNCTION_AT_PORT_INITIAL_NOTIFICATION, + communicationMeans = CommunicationMeans.SMS, + recipientFunction = BeaconMalfunctionNotificationRecipientFunction.VESSEL_CAPTAIN, + recipientName = "Jack Sparrow", recipientAddressOrNumber = "0000000000", + success = false, errorMessage = "This message could not be delivered", + ), + ), ), ), - ), ), ) // When - val updatedBeaconMalfunction = UpdateBeaconMalfunction( - beaconMalfunctionsRepository, - beaconMalfunctionActionRepository, - getBeaconMalfunction, - ) - .execute(1, VesselStatus.AT_SEA, null, null) + val updatedBeaconMalfunction = + UpdateBeaconMalfunction( + beaconMalfunctionsRepository, + beaconMalfunctionActionRepository, + getBeaconMalfunction, + ) + .execute(1, VesselStatus.AT_SEA, null, null) // Then assertThat(updatedBeaconMalfunction.actions).hasSize(1) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeFaoAreasFromCoordinatesUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeFaoAreasFromCoordinatesUTests.kt index 7801e5d7dd..43c2b62a95 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeFaoAreasFromCoordinatesUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeFaoAreasFromCoordinatesUTests.kt @@ -16,7 +16,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class ComputeFaoAreasFromCoordinatesUTests { - @MockBean private lateinit var faoAreaRepository: FaoAreaRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeVesselFaoAreasUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeVesselFaoAreasUTests.kt index a6cad4a795..0b84767906 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeVesselFaoAreasUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fao_areas/ComputeVesselFaoAreasUTests.kt @@ -16,7 +16,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class ComputeVesselFaoAreasUTests { - @MockBean private lateinit var riskFactorRepository: RiskFactorRepository @@ -36,8 +35,9 @@ class ComputeVesselFaoAreasUTests { ) // When - val faoAreas = ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) - .execute(null, 12.5, 45.1, null) + val faoAreas = + ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) + .execute(null, 12.5, 45.1, null) // Then assertThat(faoAreas).isEqualTo(listOf("27.8.c", "27.8")) @@ -46,8 +46,9 @@ class ComputeVesselFaoAreasUTests { @Test fun `execute Should return no fao area When a coordinate parameter is null`() { // When - val faoAreas = ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) - .execute(null, null, 45.1, null) + val faoAreas = + ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) + .execute(null, null, 45.1, null) // Then assertThat(faoAreas).isEmpty() @@ -65,8 +66,9 @@ class ComputeVesselFaoAreasUTests { ) // When - val faoAreas = ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) - .execute("DUMMY_CFR", 12.5, 45.1, null) + val faoAreas = + ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) + .execute("DUMMY_CFR", 12.5, 45.1, null) // Then assertThat(faoAreas).isEqualTo(listOf("27.8.c", "27.8")) @@ -84,8 +86,9 @@ class ComputeVesselFaoAreasUTests { ) // When - val faoAreas = ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) - .execute("DUMMY_CFR", 12.5, 45.1, null) + val faoAreas = + ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) + .execute("DUMMY_CFR", 12.5, 45.1, null) // Then assertThat(faoAreas).isEqualTo(listOf("27.8.c", "27.8")) @@ -97,8 +100,9 @@ class ComputeVesselFaoAreasUTests { .willReturn(VesselRiskFactor(speciesOnboard = listOf(Species(faoZone = "27.8.c")))) // When - val faoAreas = ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) - .execute("DUMMY_CFR", 12.5, 45.1, null) + val faoAreas = + ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) + .execute("DUMMY_CFR", 12.5, 45.1, null) // Then assertThat(faoAreas).isEqualTo(listOf("27.8.c")) @@ -111,8 +115,9 @@ class ComputeVesselFaoAreasUTests { ) // When - val faoAreas = ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) - .execute(null, null, null, "AEFAT") + val faoAreas = + ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) + .execute(null, null, null, "AEFAT") // Then assertThat(faoAreas).isEqualTo(listOf("27.8.c", "27.8")) @@ -125,8 +130,9 @@ class ComputeVesselFaoAreasUTests { ) // When - val faoAreas = ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) - .execute("DUMMY_CFR", null, null, "AEFAT") + val faoAreas = + ComputeVesselFaoAreas(riskFactorRepository, portRepository, computeFAOAreasFromCoordinates) + .execute("DUMMY_CFR", null, null, "AEFAT") // Then assertThat(faoAreas).isEqualTo(listOf("27.8.c", "27.8")) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/ComputeFleetSegmentsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/ComputeFleetSegmentsUTests.kt index f09ccc1bb9..646cfe65dc 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/ComputeFleetSegmentsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/ComputeFleetSegmentsUTests.kt @@ -13,7 +13,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class ComputeFleetSegmentsUTests { - @MockBean private lateinit var fleetSegmentRepository: FleetSegmentRepository @@ -26,11 +25,12 @@ class ComputeFleetSegmentsUTests { given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(getDummyFleetSegments()) // When - val segment = ComputeFleetSegments( - fleetSegmentRepository, - fixedClock, - ) - .execute(listOf("27.1", "27.8.c"), listOf(), listOf("HKE", "SOL")) + val segment = + ComputeFleetSegments( + fleetSegmentRepository, + fixedClock, + ) + .execute(listOf("27.1", "27.8.c"), listOf(), listOf("HKE", "SOL")) // Then assertThat(segment).isEmpty() @@ -41,11 +41,12 @@ class ComputeFleetSegmentsUTests { given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(getDummyFleetSegments()) // When - val segment = ComputeFleetSegments( - fleetSegmentRepository, - fixedClock, - ) - .execute(listOf("27.1", "27.8.c"), listOf("OTB", "OTT"), listOf()) + val segment = + ComputeFleetSegments( + fleetSegmentRepository, + fixedClock, + ) + .execute(listOf("27.1", "27.8.c"), listOf("OTB", "OTT"), listOf()) // Then assertThat(segment).isEmpty() @@ -56,11 +57,12 @@ class ComputeFleetSegmentsUTests { given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(getDummyFleetSegments()) // When - val segment = ComputeFleetSegments( - fleetSegmentRepository, - fixedClock, - ) - .execute(listOf("27.1", "27.8.c"), listOf("OTB", "OTT"), listOf("HKE", "SOL")) + val segment = + ComputeFleetSegments( + fleetSegmentRepository, + fixedClock, + ) + .execute(listOf("27.1", "27.8.c"), listOf("OTB", "OTT"), listOf("HKE", "SOL")) // Then assertThat(segment).hasSize(1) @@ -72,11 +74,12 @@ class ComputeFleetSegmentsUTests { given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(getDummyFleetSegments()) // When - val segment = ComputeFleetSegments( - fleetSegmentRepository, - fixedClock, - ) - .execute(listOf("27.5.b"), listOf("TB"), listOf("ANF")) + val segment = + ComputeFleetSegments( + fleetSegmentRepository, + fixedClock, + ) + .execute(listOf("27.5.b"), listOf("TB"), listOf("ANF")) // Then assertThat(segment).hasSize(1) @@ -88,11 +91,12 @@ class ComputeFleetSegmentsUTests { given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(getDummyFleetSegments()) // When - val segment = ComputeFleetSegments( - fleetSegmentRepository, - fixedClock, - ) - .execute(listOf("27.1", "27.8.c"), listOf("OTB", "OTT", "OTM"), listOf("HKE", "SOL")) + val segment = + ComputeFleetSegments( + fleetSegmentRepository, + fixedClock, + ) + .execute(listOf("27.1", "27.8.c"), listOf("OTB", "OTT", "OTM"), listOf("HKE", "SOL")) // Then assertThat(segment).hasSize(2) @@ -105,11 +109,12 @@ class ComputeFleetSegmentsUTests { given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(getDummyFleetSegments()) // When - val segment = ComputeFleetSegments( - fleetSegmentRepository, - fixedClock, - ) - .execute(listOf("27.9"), listOf(), listOf("HKE", "SOL")) + val segment = + ComputeFleetSegments( + fleetSegmentRepository, + fixedClock, + ) + .execute(listOf("27.9"), listOf(), listOf("HKE", "SOL")) // Then assertThat(segment).hasSize(1) @@ -121,11 +126,12 @@ class ComputeFleetSegmentsUTests { given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(getDummyFleetSegments()) // When - val segment = ComputeFleetSegments( - fleetSegmentRepository, - fixedClock, - ) - .execute(listOf("27.9"), listOf("SDN"), listOf()) + val segment = + ComputeFleetSegments( + fleetSegmentRepository, + fixedClock, + ) + .execute(listOf("27.9"), listOf("SDN"), listOf()) // Then assertThat(segment).hasSize(1) @@ -137,11 +143,12 @@ class ComputeFleetSegmentsUTests { given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(getDummyFleetSegments()) // When - val segment = ComputeFleetSegments( - fleetSegmentRepository, - fixedClock, - ) - .execute(listOf(), listOf("SDN"), listOf("HKE")) + val segment = + ComputeFleetSegments( + fleetSegmentRepository, + fixedClock, + ) + .execute(listOf(), listOf("SDN"), listOf("HKE")) // Then assertThat(segment).hasSize(1) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UpdateFleetSegmentUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UpdateFleetSegmentUTests.kt index 6b1fa5ffd1..a73215a956 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UpdateFleetSegmentUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UpdateFleetSegmentUTests.kt @@ -12,16 +12,16 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class UpdateFleetSegmentUTests { - @MockBean private lateinit var fleetSegmentRepository: FleetSegmentRepository @Test fun `execute Should throw an exception When there is no fields given`() { // When - val throwable = catchThrowable { - UpdateFleetSegment(fleetSegmentRepository).execute("SEGMENT", CreateOrUpdateFleetSegmentFields(), 2021) - } + val throwable = + catchThrowable { + UpdateFleetSegment(fleetSegmentRepository).execute("SEGMENT", CreateOrUpdateFleetSegmentFields(), 2021) + } // Then assertThat(throwable).isNotNull diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UtilsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UtilsUTests.kt index 4279f57600..ff38f20767 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UtilsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/UtilsUTests.kt @@ -8,17 +8,17 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class UtilsUTests { - @Test fun `removeRedundantFaoArea Should remove redundant fao codes`() { // Given - val faoAreas = listOf( - FaoArea(faoCode = "27.1.B"), - FaoArea(faoCode = "27.1"), - FaoArea(faoCode = "27.1"), - FaoArea(faoCode = "18"), - FaoArea(faoCode = "27.1.B.a"), - ) + val faoAreas = + listOf( + FaoArea(faoCode = "27.1.B"), + FaoArea(faoCode = "27.1"), + FaoArea(faoCode = "27.1"), + FaoArea(faoCode = "18"), + FaoArea(faoCode = "27.1.B.a"), + ) // When val filteredFaoAreas = removeRedundantFaoArea(faoAreas) @@ -32,12 +32,13 @@ class UtilsUTests { @Test fun `removeRedundantFaoArea Should keep different fao codes`() { // Given - val faoAreas = listOf( - FaoArea(faoCode = "27.1.B"), - FaoArea(faoCode = "27.1.B"), - FaoArea(faoCode = "27.1.B"), - FaoArea(faoCode = "27.1.C"), - ) + val faoAreas = + listOf( + FaoArea(faoCode = "27.1.B"), + FaoArea(faoCode = "27.1.B"), + FaoArea(faoCode = "27.1.B"), + FaoArea(faoCode = "27.1.C"), + ) // When val filteredFaoAreas = removeRedundantFaoArea(faoAreas) @@ -51,11 +52,12 @@ class UtilsUTests { @Test fun `removeRedundantFaoArea Should not remove redundant fao codes When fao code is not located at the start of the string`() { // Given - val faoAreas = listOf( - FaoArea(faoCode = "27"), - FaoArea(faoCode = "22.1.27"), - FaoArea(faoCode = "18"), - ) + val faoAreas = + listOf( + FaoArea(faoCode = "27"), + FaoArea(faoCode = "22.1.27"), + FaoArea(faoCode = "18"), + ) // When val filteredFaoAreas = removeRedundantFaoArea(faoAreas) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissionsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissionsUTests.kt index 9ccf088cd1..63bda96a7b 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissionsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetAllMissionsUTests.kt @@ -14,7 +14,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class GetAllMissionsUTests { - @MockBean private lateinit var missionActionsRepository: MissionActionsRepository @@ -55,20 +54,21 @@ class GetAllMissionsUTests { .willReturn(getDummyMissionActions(fourthChunk)) // When - val missionsAndActions = GetAllMissions( - missionRepository, - missionActionsRepository, - databaseProperties, - ).execute( - null, - null, - null, - null, - null, - null, - null, - null, - ) + val missionsAndActions = + GetAllMissions( + missionRepository, + missionActionsRepository, + databaseProperties, + ).execute( + null, + null, + null, + null, + null, + null, + null, + null, + ) // Then assertThat(missionsAndActions).hasSize(20) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt index 9d2e08bca2..e31f371eac 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/GetMissionUTests.kt @@ -23,7 +23,6 @@ import java.util.* @ExtendWith(SpringExtension::class) class GetMissionUTests { - @MockBean private lateinit var getMissionActions: GetMissionActions @@ -41,24 +40,26 @@ class GetMissionUTests { startDateTimeUtc = ZonedDateTime.now(), isGeometryComputedFromControls = false, missionSource = MissionSource.MONITORFISH, - envActions = listOf( - EnvMissionAction( - id = UUID.randomUUID(), - actionStartDateTimeUtc = ZonedDateTime.now(), - actionType = EnvMissionActionType.CONTROL, + envActions = + listOf( + EnvMissionAction( + id = UUID.randomUUID(), + actionStartDateTimeUtc = ZonedDateTime.now(), + actionType = EnvMissionActionType.CONTROL, + ), ), - ), ), ) given(getMissionActions.execute(any())).willReturn(getDummyMissionActions(listOf(1, 2))) // When - val missionsAndActions = runBlocking { - return@runBlocking GetMission( - missionRepository, - getMissionActions, - ).execute(123) - } + val missionsAndActions = + runBlocking { + return@runBlocking GetMission( + missionRepository, + getMissionActions, + ).execute(123) + } // Then assertThat(missionsAndActions.mission.envActions).hasSize(1) @@ -72,14 +73,15 @@ class GetMissionUTests { given(getMissionActions.execute(any())).willReturn(getDummyMissionActions(listOf(123, 456))) // When - val throwable = catchThrowable { - runBlocking { - GetMission( - missionRepository, - getMissionActions, - ).execute(123) + val throwable = + catchThrowable { + runBlocking { + GetMission( + missionRepository, + getMissionActions, + ).execute(123) + } } - } // Then assertThat(throwable).isNotNull() diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionActionUTests.kt index fb255f4666..00725fe8bc 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/AddMissionActionUTests.kt @@ -20,7 +20,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class AddMissionActionUTests { - @MockBean private lateinit var missionActionsRepository: MissionActionsRepository @@ -30,31 +29,33 @@ class AddMissionActionUTests { @Test fun `execute Should throw an exception When the id is not null`() { // Given - val action = MissionAction( - id = 1, - vesselId = null, - missionId = 1, - longitude = 45.7, - latitude = 13.5, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - userTrigram = "LTH", - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - isFromPoseidon = false, - flagState = CountryCode.FR, - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = 1, + vesselId = null, + missionId = 1, + longitude = 45.7, + latitude = 13.5, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + userTrigram = "LTH", + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + isFromPoseidon = false, + flagState = CountryCode.FR, + completion = Completion.TO_COMPLETE, + ) // When - val throwable = catchThrowable { - AddMissionAction(missionActionsRepository, getMissionActionFacade).execute(action) - } + val throwable = + catchThrowable { + AddMissionAction(missionActionsRepository, getMissionActionFacade).execute(action) + } // Then assertThat(throwable).isNotNull() @@ -64,27 +65,28 @@ class AddMissionActionUTests { @Test fun `execute Should not throw an exception When the vesselId is given in a control`() { // Given - val action = MissionAction( - id = null, - vesselId = 1, - missionId = 1, - longitude = 45.7, - latitude = 13.5, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - portName = "Port name", - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - userTrigram = "LTH", - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - isFromPoseidon = false, - flagState = CountryCode.FR, - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = 1, + missionId = 1, + longitude = 45.7, + latitude = 13.5, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + portName = "Port name", + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + userTrigram = "LTH", + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + isFromPoseidon = false, + flagState = CountryCode.FR, + completion = Completion.TO_COMPLETE, + ) given(missionActionsRepository.save(anyOrNull())).willReturn(action) given(getMissionActionFacade.execute(anyOrNull())).willReturn(Seafront.NAMO) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionActionUTests.kt index 3bca5b0599..974193c59a 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/DeleteMissionActionUTests.kt @@ -15,31 +15,31 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class DeleteMissionActionUTests { - @MockBean private lateinit var missionActionsRepository: MissionActionsRepository @Test fun `execute Should delete an action`() { // Given - val action = MissionAction( - id = null, - vesselId = null, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = null, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ) given(missionActionsRepository.findById(any())).willReturn(action) // When diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt index 18f7d2028e..467b8be662 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetActivityReportsUTests.kt @@ -26,7 +26,6 @@ import fr.gouv.cnsp.monitorfish.domain.entities.fleet_segment.FleetSegment as Fu @ExtendWith(SpringExtension::class) class GetActivityReportsUTests { - @MockBean private lateinit var missionActionsRepository: MissionActionsRepository @@ -52,131 +51,136 @@ class GetActivityReportsUTests { val species = SpeciesControl() species.speciesCode = "HKE" - val controls = listOf( - MissionAction( - id = 1, - vesselId = 1, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - faoAreas = listOf("27.7.b", "27.4.c"), - segments = listOf( - FleetSegment("NWW01/02", "Trawl"), - FleetSegment("NS01/03", "North sea"), - ), - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - speciesOnboard = listOf(species), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ), - MissionAction( - id = 2, - vesselId = 1, - missionId = 2, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - faoAreas = listOf("27.7.b", "27.4.c"), - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - faoAreas = listOf("27.7.b", "27.4.c"), - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - ) + val controls = + listOf( + MissionAction( + id = 1, + vesselId = 1, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + faoAreas = listOf("27.7.b", "27.4.c"), + segments = + listOf( + FleetSegment("NWW01/02", "Trawl"), + FleetSegment("NS01/03", "North sea"), + ), + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + speciesOnboard = listOf(species), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ), + MissionAction( + id = 2, + vesselId = 1, + missionId = 2, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + faoAreas = listOf("27.7.b", "27.4.c"), + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + faoAreas = listOf("27.7.b", "27.4.c"), + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + ) given(missionActionsRepository.findSeaAndLandControlBetweenDates(any(), any())).willReturn(controls) - val vessels = listOf( - Vessel( - id = 1, - internalReferenceNumber = "FR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - hasLogbookEsacapt = false, - ), - Vessel( - id = 2, - internalReferenceNumber = "FR00065455", - vesselName = "MY SECOND AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "LO", - hasLogbookEsacapt = false, - ), - ) + val vessels = + listOf( + Vessel( + id = 1, + internalReferenceNumber = "FR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + hasLogbookEsacapt = false, + ), + Vessel( + id = 2, + internalReferenceNumber = "FR00065455", + vesselName = "MY SECOND AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "LO", + hasLogbookEsacapt = false, + ), + ) given(vesselRepository.findVesselsByIds(eq(listOf(1, 2)))).willReturn(vessels) - val missions = listOf( - Mission( - 1, - missionTypes = listOf(MissionType.LAND), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = false, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - Mission( - 2, - missionTypes = listOf(MissionType.SEA), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = true, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - Mission( - 2, - missionTypes = listOf(MissionType.SEA), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = false, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - ) + val missions = + listOf( + Mission( + 1, + missionTypes = listOf(MissionType.LAND), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = false, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + Mission( + 2, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = true, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + Mission( + 2, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = false, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + ) given(missionRepository.findByIds(listOf(1, 2, 3))).willReturn(missions) given(portRepository.findByLocode(eq("AEFAT"))).willReturn(Port("AEFAT", "Al Jazeera Port")) // When - val activityReports = GetActivityReports( - missionActionsRepository, - portRepository, - vesselRepository, - missionRepository, - ).execute( - ZonedDateTime.now(), - ZonedDateTime.now().minusDays(1), - JointDeploymentPlan.WESTERN_WATERS, - ) + val activityReports = + GetActivityReports( + missionActionsRepository, + portRepository, + vesselRepository, + missionRepository, + ).execute( + ZonedDateTime.now(), + ZonedDateTime.now().minusDays(1), + JointDeploymentPlan.WESTERN_WATERS, + ) // Then assertThat(activityReports.jdpSpecies).hasSize(35) @@ -193,131 +197,136 @@ class GetActivityReportsUTests { val species = SpeciesControl() species.speciesCode = "HKE" - val controls = listOf( - MissionAction( - id = 1, - vesselId = 1, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - faoAreas = listOf("27.7.b", "27.4.c"), - segments = listOf( - FleetSegment("NWW01/02", "Trawl"), - FleetSegment("NS01/03", "North sea"), - ), - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - speciesOnboard = listOf(species), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ), - MissionAction( - id = 2, - vesselId = 1, - missionId = 2, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - faoAreas = listOf("27.7.b", "27.4.c"), - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ), - MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - faoAreas = listOf("27.7.b", "27.4.c"), - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ), - ) + val controls = + listOf( + MissionAction( + id = 1, + vesselId = 1, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + faoAreas = listOf("27.7.b", "27.4.c"), + segments = + listOf( + FleetSegment("NWW01/02", "Trawl"), + FleetSegment("NS01/03", "North sea"), + ), + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + speciesOnboard = listOf(species), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ), + MissionAction( + id = 2, + vesselId = 1, + missionId = 2, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + faoAreas = listOf("27.7.b", "27.4.c"), + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ), + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + faoAreas = listOf("27.7.b", "27.4.c"), + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ), + ) given(missionActionsRepository.findSeaAndLandControlBetweenDates(any(), any())).willReturn(controls) - val vessels = listOf( - Vessel( - id = 1, - internalReferenceNumber = "FR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - hasLogbookEsacapt = false, - ), - Vessel( - id = 2, - internalReferenceNumber = "FR00065455", - vesselName = "MY SECOND AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "LO", - hasLogbookEsacapt = false, - ), - ) + val vessels = + listOf( + Vessel( + id = 1, + internalReferenceNumber = "FR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + hasLogbookEsacapt = false, + ), + Vessel( + id = 2, + internalReferenceNumber = "FR00065455", + vesselName = "MY SECOND AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "LO", + hasLogbookEsacapt = false, + ), + ) given(vesselRepository.findVesselsByIds(eq(listOf(1, 2)))).willReturn(vessels) - val missions = listOf( - Mission( - 1, - missionTypes = listOf(MissionType.LAND), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = false, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - Mission( - 2, - missionTypes = listOf(MissionType.SEA), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = true, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - Mission( - 2, - missionTypes = listOf(MissionType.SEA), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = false, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - ) + val missions = + listOf( + Mission( + 1, + missionTypes = listOf(MissionType.LAND), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = false, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + Mission( + 2, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = true, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + Mission( + 2, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = false, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + ) given(missionRepository.findByIds(listOf(1, 2, 3))).willReturn(missions) given(portRepository.findByLocode(eq("AEFAT"))).willReturn(Port("AEFAT", "Al Jazeera Port")) // When - val activityReports = GetActivityReports( - missionActionsRepository, - portRepository, - vesselRepository, - missionRepository, - ).execute( - ZonedDateTime.now(), - ZonedDateTime.now().minusDays(1), - JointDeploymentPlan.NORTH_SEA, - ) + val activityReports = + GetActivityReports( + missionActionsRepository, + portRepository, + vesselRepository, + missionRepository, + ).execute( + ZonedDateTime.now(), + ZonedDateTime.now().minusDays(1), + JointDeploymentPlan.NORTH_SEA, + ) // Then assertThat(activityReports.jdpSpecies).hasSize(38) @@ -357,70 +366,75 @@ class GetActivityReportsUTests { ), ) - val controls = listOf( - MissionAction( - id = 1, - vesselId = 1, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - faoAreas = listOf("27.4.a"), - segments = listOf( - FleetSegment("NS01/03", "North Sea"), - ), - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - speciesOnboard = listOf(species), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ), - ) + val controls = + listOf( + MissionAction( + id = 1, + vesselId = 1, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + faoAreas = listOf("27.4.a"), + segments = + listOf( + FleetSegment("NS01/03", "North Sea"), + ), + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + speciesOnboard = listOf(species), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ), + ) given(missionActionsRepository.findSeaAndLandControlBetweenDates(any(), any())).willReturn(controls) - val vessels = listOf( - Vessel( - id = 1, - internalReferenceNumber = "FR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - hasLogbookEsacapt = false, - ), - ) + val vessels = + listOf( + Vessel( + id = 1, + internalReferenceNumber = "FR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + hasLogbookEsacapt = false, + ), + ) given(vesselRepository.findVesselsByIds(eq(listOf(1)))).willReturn(vessels) - val missions = listOf( - Mission( - 1, - missionTypes = listOf(MissionType.LAND), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = false, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - ) + val missions = + listOf( + Mission( + 1, + missionTypes = listOf(MissionType.LAND), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = false, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + ) given(missionRepository.findByIds(eq(listOf(1)))).willReturn(missions) given(portRepository.findByLocode(eq("AEFAT"))).willReturn(Port("AEFAT", "Al Jazeera Port")) // When - val activityReports = GetActivityReports( - missionActionsRepository, - portRepository, - vesselRepository, - missionRepository, - ).execute( - ZonedDateTime.now(), - ZonedDateTime.now().minusDays(1), - JointDeploymentPlan.NORTH_SEA, - ) + val activityReports = + GetActivityReports( + missionActionsRepository, + portRepository, + vesselRepository, + missionRepository, + ).execute( + ZonedDateTime.now(), + ZonedDateTime.now().minusDays(1), + JointDeploymentPlan.NORTH_SEA, + ) // Then assertThat(activityReports.activityReports).hasSize(1) @@ -443,65 +457,69 @@ class GetActivityReportsUTests { val species = SpeciesControl() species.speciesCode = "HKE" - val controls = listOf( - MissionAction( - id = 2, - vesselId = 1, - missionId = 2, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - // These fao areas are outside WESTERN WATERS - faoAreas = listOf("27.4.c", "27.4.b"), - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ), - ) + val controls = + listOf( + MissionAction( + id = 2, + vesselId = 1, + missionId = 2, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + // These fao areas are outside WESTERN WATERS + faoAreas = listOf("27.4.c", "27.4.b"), + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ), + ) given(missionActionsRepository.findSeaAndLandControlBetweenDates(any(), any())).willReturn(controls) - val vessels = listOf( - Vessel( - id = 1, - internalReferenceNumber = "FR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - hasLogbookEsacapt = false, - ), - ) + val vessels = + listOf( + Vessel( + id = 1, + internalReferenceNumber = "FR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + hasLogbookEsacapt = false, + ), + ) given(vesselRepository.findVesselsByIds(eq(listOf(1)))).willReturn(vessels) - val missions = listOf( - Mission( - 2, - missionTypes = listOf(MissionType.SEA), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = true, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - ) + val missions = + listOf( + Mission( + 2, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = true, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + ) given(missionRepository.findByIds(listOf(2))).willReturn(missions) // When - val activityReports = GetActivityReports( - missionActionsRepository, - portRepository, - vesselRepository, - missionRepository, - ).execute( - ZonedDateTime.now(), - ZonedDateTime.now().minusDays(1), - JointDeploymentPlan.WESTERN_WATERS, - ) + val activityReports = + GetActivityReports( + missionActionsRepository, + portRepository, + vesselRepository, + missionRepository, + ).execute( + ZonedDateTime.now(), + ZonedDateTime.now().minusDays(1), + JointDeploymentPlan.WESTERN_WATERS, + ) // Then assertThat(activityReports.activityReports).hasSize(0) @@ -517,66 +535,70 @@ class GetActivityReportsUTests { val species = SpeciesControl() species.speciesCode = "HKE" - val controls = listOf( - MissionAction( - id = 2, - vesselId = 1, - missionId = 2, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - // The first fao area "27.7.c" is within WESTERN_WATERS - // The second fao area "27.4.b" is within NORTH_SEA - faoAreas = listOf("27.7.c", "27.4.b"), - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", - ), - ) + val controls = + listOf( + MissionAction( + id = 2, + vesselId = 1, + missionId = 2, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + // The first fao area "27.7.c" is within WESTERN_WATERS + // The second fao area "27.4.b" is within NORTH_SEA + faoAreas = listOf("27.7.c", "27.4.b"), + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ), + ) given(missionActionsRepository.findSeaAndLandControlBetweenDates(any(), any())).willReturn(controls) - val vessels = listOf( - Vessel( - id = 1, - internalReferenceNumber = "FR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - hasLogbookEsacapt = false, - ), - ) + val vessels = + listOf( + Vessel( + id = 1, + internalReferenceNumber = "FR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + hasLogbookEsacapt = false, + ), + ) given(vesselRepository.findVesselsByIds(eq(listOf(1)))).willReturn(vessels) - val missions = listOf( - Mission( - 2, - missionTypes = listOf(MissionType.SEA), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = true, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - ) + val missions = + listOf( + Mission( + 2, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = true, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + ) given(missionRepository.findByIds(listOf(2))).willReturn(missions) // When - val activityReports = GetActivityReports( - missionActionsRepository, - portRepository, - vesselRepository, - missionRepository, - ).execute( - ZonedDateTime.now(), - ZonedDateTime.now().minusDays(1), - JointDeploymentPlan.NORTH_SEA, - ) + val activityReports = + GetActivityReports( + missionActionsRepository, + portRepository, + vesselRepository, + missionRepository, + ).execute( + ZonedDateTime.now(), + ZonedDateTime.now().minusDays(1), + JointDeploymentPlan.NORTH_SEA, + ) // Then assertThat(activityReports.activityReports).hasSize(1) @@ -592,118 +614,122 @@ class GetActivityReportsUTests { val species = SpeciesControl() species.speciesCode = "HKE" - val controls = listOf( - MissionAction( - id = 1, - vesselId = 1, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - faoAreas = listOf("27.4.b", "27.4.c"), - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - speciesOnboard = listOf(species), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - MissionAction( - id = 2, - vesselId = 1, - missionId = 2, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - ) + val controls = + listOf( + MissionAction( + id = 1, + vesselId = 1, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + faoAreas = listOf("27.4.b", "27.4.c"), + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + speciesOnboard = listOf(species), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + MissionAction( + id = 2, + vesselId = 1, + missionId = 2, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + ) given(missionActionsRepository.findSeaAndLandControlBetweenDates(any(), any())).willReturn(controls) - val vessels = listOf( - Vessel( - id = 1, - internalReferenceNumber = "FR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - hasLogbookEsacapt = false, - ), - Vessel( - id = 2, - internalReferenceNumber = "FR00065455", - vesselName = "MY SECOND AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "LO", - hasLogbookEsacapt = false, - ), - ) + val vessels = + listOf( + Vessel( + id = 1, + internalReferenceNumber = "FR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + hasLogbookEsacapt = false, + ), + Vessel( + id = 2, + internalReferenceNumber = "FR00065455", + vesselName = "MY SECOND AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "LO", + hasLogbookEsacapt = false, + ), + ) given(vesselRepository.findVesselsByIds(eq(listOf(1, 2)))).willReturn(vessels) - val missions = listOf( - Mission( - 1, - missionTypes = listOf(MissionType.LAND), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = false, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - Mission( - 3, - missionTypes = listOf(MissionType.SEA), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = false, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - ) + val missions = + listOf( + Mission( + 1, + missionTypes = listOf(MissionType.LAND), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = false, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + Mission( + 3, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = false, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + ) // The mission id 2 is not returned given(missionRepository.findByIds(listOf(1, 2, 3))).willReturn(missions) given(portRepository.findByLocode(eq("AEFAT"))).willReturn(Port("AEFAT", "Al Jazeera Port")) // When - val activityReports = GetActivityReports( - missionActionsRepository, - portRepository, - vesselRepository, - missionRepository, - ).execute( - ZonedDateTime.now(), - ZonedDateTime.now().minusDays(1), - JointDeploymentPlan.NORTH_SEA, - ) + val activityReports = + GetActivityReports( + missionActionsRepository, + portRepository, + vesselRepository, + missionRepository, + ).execute( + ZonedDateTime.now(), + ZonedDateTime.now().minusDays(1), + JointDeploymentPlan.NORTH_SEA, + ) // Then assertThat(activityReports.jdpSpecies).hasSize(38) @@ -723,94 +749,98 @@ class GetActivityReportsUTests { val species = SpeciesControl() species.speciesCode = "HKE" - val controls = listOf( - MissionAction( - id = 1, - vesselId = 1, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - faoAreas = listOf("27.4.b", "27.4.c"), - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - speciesOnboard = listOf(species), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - MissionAction( - id = 3, - vesselId = 2, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - ) + val controls = + listOf( + MissionAction( + id = 1, + vesselId = 1, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + faoAreas = listOf("27.4.b", "27.4.c"), + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + speciesOnboard = listOf(species), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + MissionAction( + id = 3, + vesselId = 2, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + ) given(missionActionsRepository.findSeaAndLandControlBetweenDates(any(), any())).willReturn(controls) - val vessels = listOf( - Vessel( - id = 1, - internalReferenceNumber = "FR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - hasLogbookEsacapt = false, - ), - Vessel( - id = 2, - internalReferenceNumber = "FR00065455", - vesselName = "MY SECOND AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "LO", - hasLogbookEsacapt = false, - ), - ) + val vessels = + listOf( + Vessel( + id = 1, + internalReferenceNumber = "FR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + hasLogbookEsacapt = false, + ), + Vessel( + id = 2, + internalReferenceNumber = "FR00065455", + vesselName = "MY SECOND AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "LO", + hasLogbookEsacapt = false, + ), + ) given(vesselRepository.findVesselsByIds(eq(listOf(1, 2)))).willReturn(vessels) - val missions = listOf( - Mission( - 3, - missionTypes = listOf(MissionType.SEA), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = false, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - ) + val missions = + listOf( + Mission( + 3, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = false, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + ) // The mission id 1 is not returned given(missionRepository.findByIds(listOf(1, 3))).willReturn(missions) given(portRepository.findByLocode(eq("AEFAT"))).willReturn(Port("AEFAT", "Al Jazeera Port")) // When - val activityReports = GetActivityReports( - missionActionsRepository, - portRepository, - vesselRepository, - missionRepository, - ).execute( - ZonedDateTime.now(), - ZonedDateTime.now().minusDays(1), - JointDeploymentPlan.NORTH_SEA, - ) + val activityReports = + GetActivityReports( + missionActionsRepository, + portRepository, + vesselRepository, + missionRepository, + ).execute( + ZonedDateTime.now(), + ZonedDateTime.now().minusDays(1), + JointDeploymentPlan.NORTH_SEA, + ) // Then assertThat(activityReports.activityReports).hasSize(0) @@ -819,71 +849,74 @@ class GetActivityReportsUTests { @Test fun `execute Should filter a control done by an AECP unit`() { // Given - val controls = listOf( - MissionAction( - id = 1, - vesselId = 1, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - faoAreas = listOf("27.4.b", "27.4.c"), - actionType = MissionActionType.SEA_CONTROL, - gearOnboard = listOf(), - controlUnits = listOf(), - speciesOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "CPAMOI", - ), - ) + val controls = + listOf( + MissionAction( + id = 1, + vesselId = 1, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + faoAreas = listOf("27.4.b", "27.4.c"), + actionType = MissionActionType.SEA_CONTROL, + gearOnboard = listOf(), + controlUnits = listOf(), + speciesOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "CPAMOI", + ), + ) given(missionActionsRepository.findSeaAndLandControlBetweenDates(any(), any())).willReturn(controls) - val vessels = listOf( - Vessel( - id = 1, - internalReferenceNumber = "FR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - hasLogbookEsacapt = false, - ), - ) + val vessels = + listOf( + Vessel( + id = 1, + internalReferenceNumber = "FR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + hasLogbookEsacapt = false, + ), + ) given(vesselRepository.findVesselsByIds(eq(listOf(1)))).willReturn(vessels) - val missions = listOf( - Mission( - 1, - missionTypes = listOf(MissionType.SEA), - missionSource = MissionSource.MONITORFISH, - isUnderJdp = true, - controlUnits = listOf(ControlUnit(123, "AECP", false, "Unit AECP", listOf())), - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - - ) + val missions = + listOf( + Mission( + 1, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isUnderJdp = true, + controlUnits = listOf(ControlUnit(123, "AECP", false, "Unit AECP", listOf())), + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + ) // The mission id 2 is not returned given(missionRepository.findByIds(listOf(1))).willReturn(missions) given(portRepository.findByLocode(eq("AEFAT"))).willReturn(Port("AEFAT", "Al Jazeera Port")) // When - val activityReports = GetActivityReports( - missionActionsRepository, - portRepository, - vesselRepository, - missionRepository, - ).execute( - ZonedDateTime.now(), - ZonedDateTime.now().minusDays(1), - JointDeploymentPlan.NORTH_SEA, - ) + val activityReports = + GetActivityReports( + missionActionsRepository, + portRepository, + vesselRepository, + missionRepository, + ).execute( + ZonedDateTime.now(), + ZonedDateTime.now().minusDays(1), + JointDeploymentPlan.NORTH_SEA, + ) // Then assertThat(activityReports.jdpSpecies).hasSize(38) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionSeafrontUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionSeafrontUTests.kt index 354eae21e2..1289d4c597 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionSeafrontUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetMissionActionSeafrontUTests.kt @@ -22,7 +22,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class GetMissionActionSeafrontUTests { - @MockBean private lateinit var facadeAreasRepository: FacadeAreasRepository @@ -32,23 +31,24 @@ class GetMissionActionSeafrontUTests { @Test fun `execute Should get the facade for a land control with a known port`() { // Given - val action = MissionAction( - id = null, - vesselId = null, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = null, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ) given(portRepository.findByLocode(any())).willReturn(Port("AEFAT", name = "Dummy name", facade = "NAMO")) // When @@ -61,23 +61,24 @@ class GetMissionActionSeafrontUTests { @Test fun `execute Should return null for a land control with unknown port`() { // Given - val action = MissionAction( - id = null, - vesselId = null, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = null, - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = null, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = null, + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ) // When val facade = GetMissionActionFacade(portRepository, facadeAreasRepository).execute(action) @@ -89,24 +90,25 @@ class GetMissionActionSeafrontUTests { @Test fun `execute Should get the facade for a sea control with coordinates`() { // Given - val action = MissionAction( - id = null, - vesselId = null, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - latitude = 47.3, - longitude = -2.6, - actionType = MissionActionType.SEA_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = null, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + latitude = 47.3, + longitude = -2.6, + actionType = MissionActionType.SEA_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ) given(facadeAreasRepository.findByIncluding(any())).willReturn( listOf( FacadeArea( @@ -128,24 +130,25 @@ class GetMissionActionSeafrontUTests { @Test fun `execute Should return null for a sea control with no coordinates`() { // Given - val action = MissionAction( - id = null, - vesselId = null, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - latitude = null, - longitude = null, - actionType = MissionActionType.SEA_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = null, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + latitude = null, + longitude = null, + actionType = MissionActionType.SEA_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ) // When val facade = GetMissionActionFacade(portRepository, facadeAreasRepository).execute(action) @@ -157,24 +160,25 @@ class GetMissionActionSeafrontUTests { @Test fun `execute Should return null for a sea control with no facade found`() { // Given - val action = MissionAction( - id = null, - vesselId = null, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - latitude = 47.3, - longitude = -2.6, - actionType = MissionActionType.SEA_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = null, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + latitude = 47.3, + longitude = -2.6, + actionType = MissionActionType.SEA_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ) given(facadeAreasRepository.findByIncluding(any())).willReturn(listOf()) // When diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControlsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControlsUTests.kt index f146c48f4d..b30900deeb 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControlsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/GetVesselControlsUTests.kt @@ -25,7 +25,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class GetVesselControlsUTests { - @MockBean private lateinit var missionActionsRepository: MissionActionsRepository @@ -39,95 +38,98 @@ class GetVesselControlsUTests { private lateinit var gearRepository: GearRepository @Test - fun `execute Should return the controls of a specified vessel`() = runBlocking { - // Given - val now = ZonedDateTime.now().minusDays(1) - val vesselId = 1 + fun `execute Should return the controls of a specified vessel`() = + runBlocking { + // Given + val now = ZonedDateTime.now().minusDays(1) + val vesselId = 1 - val gearControl = GearControl() - gearControl.gearWasControlled = true - gearControl.gearCode = "OTB" - gearControl.declaredMesh = 60.0 - gearControl.controlledMesh = 58.6 - gearControl.hasUncontrolledMesh = false - val gearControls = listOf(gearControl) + val gearControl = GearControl() + gearControl.gearWasControlled = true + gearControl.gearCode = "OTB" + gearControl.declaredMesh = 60.0 + gearControl.controlledMesh = 58.6 + gearControl.hasUncontrolledMesh = false + val gearControls = listOf(gearControl) - val speciesInfraction = SpeciesInfraction() - speciesInfraction.natinf = 12345 + val speciesInfraction = SpeciesInfraction() + speciesInfraction.natinf = 12345 - val expectedControls = listOf( - MissionAction( - id = 1, - vesselId = 1, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = gearControls, - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - MissionAction( - id = 2, - vesselId = 1, - missionId = 2, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - seizureAndDiversion = false, - speciesInfractions = listOf(speciesInfraction), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - MissionAction( - id = 3, - vesselId = 1, - missionId = 3, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - seizureAndDiversion = false, - speciesInfractions = listOf(speciesInfraction), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - ) - given(missionActionsRepository.findVesselMissionActionsAfterDateTime(any(), any())).willReturn( - expectedControls, - ) - given(portRepository.findByLocode(eq("AEFAT"))).willReturn(Port("AEFAT", "Al Jazeera Port")) - given(gearRepository.findByCode(eq("OTB"))).willReturn(Gear("OTB", "Chalut de fond")) + val expectedControls = + listOf( + MissionAction( + id = 1, + vesselId = 1, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = gearControls, + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + MissionAction( + id = 2, + vesselId = 1, + missionId = 2, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + seizureAndDiversion = false, + speciesInfractions = listOf(speciesInfraction), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + MissionAction( + id = 3, + vesselId = 1, + missionId = 3, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + seizureAndDiversion = false, + speciesInfractions = listOf(speciesInfraction), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + ) + given(missionActionsRepository.findVesselMissionActionsAfterDateTime(any(), any())).willReturn( + expectedControls, + ) + given(portRepository.findByLocode(eq("AEFAT"))).willReturn(Port("AEFAT", "Al Jazeera Port")) + given(gearRepository.findByCode(eq("OTB"))).willReturn(Gear("OTB", "Chalut de fond")) - // When - val controlResumeAndControls = GetVesselControls( - missionActionsRepository, - portRepository, - gearRepository, - missionRepository, - ).execute(vesselId, now) + // When + val controlResumeAndControls = + GetVesselControls( + missionActionsRepository, + portRepository, + gearRepository, + missionRepository, + ).execute(vesselId, now) - // Then - assertThat(controlResumeAndControls.numberOfDiversions).isEqualTo(1) - assertThat(controlResumeAndControls.numberOfControlsWithSomeGearsSeized).isEqualTo(0) - assertThat(controlResumeAndControls.numberOfControlsWithSomeSpeciesSeized).isEqualTo(2) + // Then + assertThat(controlResumeAndControls.numberOfDiversions).isEqualTo(1) + assertThat(controlResumeAndControls.numberOfControlsWithSomeGearsSeized).isEqualTo(0) + assertThat(controlResumeAndControls.numberOfControlsWithSomeSpeciesSeized).isEqualTo(2) - assertThat(controlResumeAndControls.controls.first().portName).isEqualTo("Al Jazeera Port") - assertThat(controlResumeAndControls.controls.first().gearOnboard.first().gearName).isEqualTo( - "Chalut de fond", - ) - } + assertThat(controlResumeAndControls.controls.first().portName).isEqualTo("Al Jazeera Port") + assertThat(controlResumeAndControls.controls.first().gearOnboard.first().gearName).isEqualTo( + "Chalut de fond", + ) + } } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/PatchMissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/PatchMissionActionUTests.kt index 6b673fb1d4..b8826aa165 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/PatchMissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/PatchMissionActionUTests.kt @@ -21,7 +21,6 @@ import java.util.* @ExtendWith(SpringExtension::class) class PatchMissionActionUTests { - @MockBean private lateinit var missionActionsRepository: MissionActionsRepository @@ -33,31 +32,33 @@ class PatchMissionActionUTests { val originalDateTime = ZonedDateTime.now() val expectedDateTime = originalDateTime.plusDays(1) val expectedEndDateTime = originalDateTime.plusDays(2) - val action = MissionAction( - id = null, - vesselId = null, - missionId = 1, - actionDatetimeUtc = originalDateTime, - portLocode = "AEFAT", - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = null, + missionId = 1, + actionDatetimeUtc = originalDateTime, + portLocode = "AEFAT", + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ) given(missionActionsRepository.findById(any())).willReturn(action) - val patch = PatchableMissionAction( - actionDatetimeUtc = Optional.of(expectedDateTime), - actionEndDatetimeUtc = Optional.of(expectedEndDateTime), - observationsByUnit = Optional.of("An observation"), - ) + val patch = + PatchableMissionAction( + actionDatetimeUtc = Optional.of(expectedDateTime), + actionEndDatetimeUtc = Optional.of(expectedEndDateTime), + observationsByUnit = Optional.of("An observation"), + ) // When PatchMissionAction(missionActionsRepository, patchMissionAction).execute(123, patch) @@ -79,31 +80,33 @@ class PatchMissionActionUTests { // Given val originalDateTime = ZonedDateTime.now() val expectedEndDateTime = originalDateTime.plusDays(2) - val action = MissionAction( - id = null, - vesselId = null, - missionId = 1, - actionDatetimeUtc = originalDateTime, - portLocode = "AEFAT", - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = null, + missionId = 1, + actionDatetimeUtc = originalDateTime, + portLocode = "AEFAT", + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ) given(missionActionsRepository.findById(any())).willReturn(action) - val patch = PatchableMissionAction( - actionDatetimeUtc = null, - actionEndDatetimeUtc = Optional.of(expectedEndDateTime), - observationsByUnit = null, - ) + val patch = + PatchableMissionAction( + actionDatetimeUtc = null, + actionEndDatetimeUtc = Optional.of(expectedEndDateTime), + observationsByUnit = null, + ) // When PatchMissionAction(missionActionsRepository, patchMissionAction).execute(123, patch) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt index 556394edeb..308db004de 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/mission/mission_actions/UpdateMissionActionUTests.kt @@ -15,7 +15,6 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) class UpdateMissionActionUTests { - @MockBean private lateinit var missionActionsRepository: MissionActionsRepository @@ -25,28 +24,30 @@ class UpdateMissionActionUTests { @Test fun `execute Should throw an exception When the vesselId is missing in a control`() { // Given - val action = MissionAction( - id = null, - vesselId = null, - missionId = 1, - actionDatetimeUtc = ZonedDateTime.now(), - portLocode = "AEFAT", - actionType = MissionActionType.LAND_CONTROL, - gearOnboard = listOf(), - seizureAndDiversion = true, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ) + val action = + MissionAction( + id = null, + vesselId = null, + missionId = 1, + actionDatetimeUtc = ZonedDateTime.now(), + portLocode = "AEFAT", + actionType = MissionActionType.LAND_CONTROL, + gearOnboard = listOf(), + seizureAndDiversion = true, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ) // When - val throwable = catchThrowable { - UpdateMissionAction(missionActionsRepository, getMissionActionFacade).execute(123, action) - } + val throwable = + catchThrowable { + UpdateMissionAction(missionActionsRepository, getMissionActionFacade).execute(123, action) + } // Then assertThat(throwable).isNotNull() diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputePnoTypesUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputePnoTypesUTests.kt index eb40afece0..88e69ff622 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputePnoTypesUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputePnoTypesUTests.kt @@ -103,11 +103,12 @@ class ComputePnoTypesUTests { @Test fun `execute Should return single type When multiple catches are given`() { // Given - val catchToLand = listOf( - LogbookFishingCatch(species = "BSS", faoZone = "27.7.d", weight = 800.0), - LogbookFishingCatch(species = "COD", faoZone = "27.8.c", weight = 800.0), - LogbookFishingCatch(species = "COD", faoZone = "27.10.c", weight = 800.0), - ) + val catchToLand = + listOf( + LogbookFishingCatch(species = "BSS", faoZone = "27.7.d", weight = 800.0), + LogbookFishingCatch(species = "COD", faoZone = "27.8.c", weight = 800.0), + LogbookFishingCatch(species = "COD", faoZone = "27.10.c", weight = 800.0), + ) val gearCodes = listOf("OTB") val flagState = CountryCode.FR given(pnoTypeRepository.findAll()).willReturn(TestUtils.getDummyPnoTypes()) @@ -124,11 +125,12 @@ class ComputePnoTypesUTests { @Test fun `execute Should return types 1 and 2 When multiple catches with types 1 and 2 are given`() { // Given - val catchToLand = listOf( - LogbookFishingCatch(species = "MAC", faoZone = "27.7.d", weight = 5000.0), - LogbookFishingCatch(species = "HOM", faoZone = "27.8.a", weight = 5000.0), - LogbookFishingCatch(species = "HER", faoZone = "34.1.2", weight = 5000.0), - ) + val catchToLand = + listOf( + LogbookFishingCatch(species = "MAC", faoZone = "27.7.d", weight = 5000.0), + LogbookFishingCatch(species = "HOM", faoZone = "27.8.a", weight = 5000.0), + LogbookFishingCatch(species = "HER", faoZone = "34.1.2", weight = 5000.0), + ) val gearCodes = listOf("PTM") val flagState = CountryCode.FR given(pnoTypeRepository.findAll()).willReturn(TestUtils.getDummyPnoTypes()) @@ -262,13 +264,14 @@ class ComputePnoTypesUTests { given(pnoTypeRepository.findAll()).willReturn(TestUtils.getDummyPnoTypes()) // When - val throwable = catchThrowable { - ComputePnoTypes(pnoTypeRepository).execute( - listOf(LogbookFishingCatch(species = "HKE", weight = 3500.0)), - listOf(), - CountryCode.FR, - ) - } + val throwable = + catchThrowable { + ComputePnoTypes(pnoTypeRepository).execute( + listOf(LogbookFishingCatch(species = "HKE", weight = 3500.0)), + listOf(), + CountryCode.FR, + ) + } // Then assertThat(throwable).hasMessage("All `faoZone` of catches must be given.") @@ -280,23 +283,25 @@ class ComputePnoTypesUTests { val catchToLand = listOf() val gearCodes = listOf("OTM") val flagState = CountryCode.AD - val pnoType = PnoType( - id = 8, - name = "Préavis sans règle", - minimumNotificationPeriod = 4.0, - hasDesignatedPorts = true, - pnoTypeRules = listOf( - PnoTypeRule( - id = 10, - species = listOf(), - faoAreas = listOf(), - cgpmAreas = listOf(), - gears = listOf(), - flagStates = listOf(), - minimumQuantityKg = 0.0, - ), - ), - ) + val pnoType = + PnoType( + id = 8, + name = "Préavis sans règle", + minimumNotificationPeriod = 4.0, + hasDesignatedPorts = true, + pnoTypeRules = + listOf( + PnoTypeRule( + id = 10, + species = listOf(), + faoAreas = listOf(), + cgpmAreas = listOf(), + gears = listOf(), + flagStates = listOf(), + minimumQuantityKg = 0.0, + ), + ), + ) given(pnoTypeRepository.findAll()).willReturn(listOf(pnoType)) // When @@ -308,12 +313,13 @@ class ComputePnoTypesUTests { assertThat(resultPnoTypeNames).containsAll(listOf("Préavis sans règle")) } - private fun getCatches(speciesAndFaoArea: List>) = speciesAndFaoArea.map { - val aCatch = LogbookFishingCatch(weight = 123.0) - aCatch.species = it[0] - aCatch.faoZone = it[1] - aCatch.weight = it[2].toDouble() + private fun getCatches(speciesAndFaoArea: List>) = + speciesAndFaoArea.map { + val aCatch = LogbookFishingCatch(weight = 123.0) + aCatch.species = it[0] + aCatch.faoZone = it[1] + aCatch.weight = it[2].toDouble() - return@map aCatch - } + return@map aCatch + } } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeRiskFactorUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeRiskFactorUTests.kt index c90dae83e0..e8bc071689 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeRiskFactorUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/ComputeRiskFactorUTests.kt @@ -44,11 +44,12 @@ class ComputeRiskFactorUTests { given(controlObjectivesRepository.findAllByYear(anyInt())).willReturn(listOf()) // When - val result = ComputeRiskFactor(riskFactorRepository, portRepository, controlObjectivesRepository, FIXED_CLOCK).execute( - portLocode, - fleetSegments, - vesselCfr, - ) + val result = + ComputeRiskFactor(riskFactorRepository, portRepository, controlObjectivesRepository, FIXED_CLOCK).execute( + portLocode, + fleetSegments, + vesselCfr, + ) // Then assertThat(result).isEqualTo( @@ -63,26 +64,27 @@ class ComputeRiskFactorUTests { fun `execute Should use highest impact risk factor When multiple fleet segments are given`() { // Given val portLocode = "LOCODE" - val fleetSegments = listOf( - FleetSegment( - segment = "NWW01", - segmentName = "A segment", - impactRiskFactor = 0.5, - year = 2024, - gears = listOf(), - faoAreas = listOf(), - targetSpecies = listOf(), - ), - FleetSegment( - segment = "SW85", - segmentName = "Another segment", - impactRiskFactor = 1.5, - year = 2024, - gears = listOf(), - faoAreas = listOf(), - targetSpecies = listOf(), - ), - ) + val fleetSegments = + listOf( + FleetSegment( + segment = "NWW01", + segmentName = "A segment", + impactRiskFactor = 0.5, + year = 2024, + gears = listOf(), + faoAreas = listOf(), + targetSpecies = listOf(), + ), + FleetSegment( + segment = "SW85", + segmentName = "Another segment", + impactRiskFactor = 1.5, + year = 2024, + gears = listOf(), + faoAreas = listOf(), + targetSpecies = listOf(), + ), + ) val vesselCfr = "CFR" val port = Port(locode = portLocode, name = "Port name", facade = "") given(portRepository.findByLocode(portLocode)).willReturn(port) @@ -90,11 +92,12 @@ class ComputeRiskFactorUTests { given(controlObjectivesRepository.findAllByYear(anyInt())).willReturn(listOf()) // When - val result = ComputeRiskFactor(riskFactorRepository, portRepository, controlObjectivesRepository, FIXED_CLOCK).execute( - portLocode, - fleetSegments, - vesselCfr, - ) + val result = + ComputeRiskFactor(riskFactorRepository, portRepository, controlObjectivesRepository, FIXED_CLOCK).execute( + portLocode, + fleetSegments, + vesselCfr, + ) // Then assertThat(result).isEqualTo( @@ -109,17 +112,18 @@ class ComputeRiskFactorUTests { fun `execute Should use stored risk factors When available`() { // Given val portLocode = "LOCODE" - val fleetSegments = listOf( - FleetSegment( - segment = "NWW01", - segmentName = "A segment", - impactRiskFactor = 0.5, - year = 2024, - gears = listOf(), - faoAreas = listOf(), - targetSpecies = listOf(), - ), - ) + val fleetSegments = + listOf( + FleetSegment( + segment = "NWW01", + segmentName = "A segment", + impactRiskFactor = 0.5, + year = 2024, + gears = listOf(), + faoAreas = listOf(), + targetSpecies = listOf(), + ), + ) val vesselCfr = "CFR" val port = Port(locode = portLocode, name = "Port name", facade = "") val storedRiskFactor = VesselRiskFactor(probabilityRiskFactor = 0.6, controlRateRiskFactor = 0.7) @@ -128,11 +132,12 @@ class ComputeRiskFactorUTests { given(controlObjectivesRepository.findAllByYear(anyInt())).willReturn(listOf()) // When - val result = ComputeRiskFactor(riskFactorRepository, portRepository, controlObjectivesRepository, FIXED_CLOCK).execute( - portLocode, - fleetSegments, - vesselCfr, - ) + val result = + ComputeRiskFactor(riskFactorRepository, portRepository, controlObjectivesRepository, FIXED_CLOCK).execute( + portLocode, + fleetSegments, + vesselCfr, + ) // Then assertThat(result).isEqualTo( @@ -147,55 +152,58 @@ class ComputeRiskFactorUTests { fun `execute Should use highest control priority level When control objectives are available`() { // Given val portLocode = "LOCODE" - val fleetSegments = listOf( - FleetSegment( - segment = "NWW01", - segmentName = "A segment", - impactRiskFactor = 0.5, - year = 2024, - gears = listOf(), - faoAreas = listOf(), - targetSpecies = listOf(), - ), - ) + val fleetSegments = + listOf( + FleetSegment( + segment = "NWW01", + segmentName = "A segment", + impactRiskFactor = 0.5, + year = 2024, + gears = listOf(), + faoAreas = listOf(), + targetSpecies = listOf(), + ), + ) val vesselCfr = "CFR" - val controlObjectives = listOf( - ControlObjective( - facade = "MED", - segment = "NWW01", - year = ZonedDateTime.now(FIXED_CLOCK).year, - controlPriorityLevel = 1.2, - targetNumberOfControlsAtSea = 1, - targetNumberOfControlsAtPort = 2, - ), - ControlObjective( - facade = "MEMN", - segment = "DF23", - year = ZonedDateTime.now(FIXED_CLOCK).year, - controlPriorityLevel = 1.5, - targetNumberOfControlsAtSea = 1, - targetNumberOfControlsAtPort = 2, - ), - ControlObjective( - facade = "MED", - segment = "NWW01", - year = 2021, - controlPriorityLevel = 1.2, - targetNumberOfControlsAtSea = 1, - targetNumberOfControlsAtPort = 2, - ), - ) + val controlObjectives = + listOf( + ControlObjective( + facade = "MED", + segment = "NWW01", + year = ZonedDateTime.now(FIXED_CLOCK).year, + controlPriorityLevel = 1.2, + targetNumberOfControlsAtSea = 1, + targetNumberOfControlsAtPort = 2, + ), + ControlObjective( + facade = "MEMN", + segment = "DF23", + year = ZonedDateTime.now(FIXED_CLOCK).year, + controlPriorityLevel = 1.5, + targetNumberOfControlsAtSea = 1, + targetNumberOfControlsAtPort = 2, + ), + ControlObjective( + facade = "MED", + segment = "NWW01", + year = 2021, + controlPriorityLevel = 1.2, + targetNumberOfControlsAtSea = 1, + targetNumberOfControlsAtPort = 2, + ), + ) val port = Port(locode = portLocode, name = "Port name", facade = "MED") given(portRepository.findByLocode(portLocode)).willReturn(port) given(riskFactorRepository.findByInternalReferenceNumber(vesselCfr)).willReturn(null) given(controlObjectivesRepository.findAllByYear(anyInt())).willReturn(controlObjectives) // When - val result = ComputeRiskFactor(riskFactorRepository, portRepository, controlObjectivesRepository, FIXED_CLOCK).execute( - portLocode, - fleetSegments, - vesselCfr, - ) + val result = + ComputeRiskFactor(riskFactorRepository, portRepository, controlObjectivesRepository, FIXED_CLOCK).execute( + portLocode, + fleetSegments, + vesselCfr, + ) // Then assertThat(result).isEqualTo( @@ -210,57 +218,60 @@ class ComputeRiskFactorUTests { fun `execute Should return correct risk factor When all factors are combined`() { // Given val portLocode = "LOCODE" - val fleetSegments = listOf( - FleetSegment( - segment = "NWW01", - segmentName = "A segment", - impactRiskFactor = 0.5, - year = 2024, - gears = listOf(), - faoAreas = listOf(), - targetSpecies = listOf(), - ), - FleetSegment( - segment = "NWW02", - segmentName = "Another segment", - impactRiskFactor = 2.5, - year = 2024, - gears = listOf(), - faoAreas = listOf(), - targetSpecies = listOf(), - ), - ) + val fleetSegments = + listOf( + FleetSegment( + segment = "NWW01", + segmentName = "A segment", + impactRiskFactor = 0.5, + year = 2024, + gears = listOf(), + faoAreas = listOf(), + targetSpecies = listOf(), + ), + FleetSegment( + segment = "NWW02", + segmentName = "Another segment", + impactRiskFactor = 2.5, + year = 2024, + gears = listOf(), + faoAreas = listOf(), + targetSpecies = listOf(), + ), + ) val vesselCfr = "CFR" val storedRiskFactor = VesselRiskFactor(probabilityRiskFactor = 0.6, controlRateRiskFactor = 0.7) - val controlObjectives = listOf( - ControlObjective( - facade = "MED", - segment = "NWW01", - year = ZonedDateTime.now(FIXED_CLOCK).year, - controlPriorityLevel = 1.2, - targetNumberOfControlsAtSea = 1, - targetNumberOfControlsAtPort = 2, - ), - ControlObjective( - facade = "MEMN", - segment = "DF23", - year = ZonedDateTime.now(FIXED_CLOCK).year, - controlPriorityLevel = 1.5, - targetNumberOfControlsAtSea = 1, - targetNumberOfControlsAtPort = 2, - ), - ) + val controlObjectives = + listOf( + ControlObjective( + facade = "MED", + segment = "NWW01", + year = ZonedDateTime.now(FIXED_CLOCK).year, + controlPriorityLevel = 1.2, + targetNumberOfControlsAtSea = 1, + targetNumberOfControlsAtPort = 2, + ), + ControlObjective( + facade = "MEMN", + segment = "DF23", + year = ZonedDateTime.now(FIXED_CLOCK).year, + controlPriorityLevel = 1.5, + targetNumberOfControlsAtSea = 1, + targetNumberOfControlsAtPort = 2, + ), + ) val port = Port(locode = portLocode, name = "Port name", facade = "MED") given(portRepository.findByLocode(portLocode)).willReturn(port) given(riskFactorRepository.findByInternalReferenceNumber(vesselCfr)).willReturn(storedRiskFactor) given(controlObjectivesRepository.findAllByYear(anyInt())).willReturn(controlObjectives) // When - val result = ComputeRiskFactor(riskFactorRepository, portRepository, controlObjectivesRepository, FIXED_CLOCK).execute( - portLocode, - fleetSegments, - vesselCfr, - ) + val result = + ComputeRiskFactor(riskFactorRepository, portRepository, controlObjectivesRepository, FIXED_CLOCK).execute( + portLocode, + fleetSegments, + vesselCfr, + ) // Then assertThat(result).isEqualTo( diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotificationITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotificationITests.kt index 405c81a314..b481e1cabe 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotificationITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotificationITests.kt @@ -335,7 +335,9 @@ class CreateOrUpdateManualPriorNotificationITests : AbstractDBTests() { @ParameterizedTest @MethodSource("getOutOfVerificationScopeTestCases") @Transactional - fun `Should transition manual prior notification states as expected (out of verification scope)`(testCase: TestCase) { + fun `Should transition manual prior notification states as expected (out of verification scope)`( + testCase: TestCase, + ) { // Given val reportId = testCase.reportId @@ -351,24 +353,24 @@ class CreateOrUpdateManualPriorNotificationITests : AbstractDBTests() { ) // When - val afterPriorNotification = createOrUpdateManualPriorNotification.execute( - reportId = reportId, - - authorTrigram = "ABC", - didNotFishAfterZeroNotice = false, - expectedArrivalDate = ZonedDateTime.now(), - expectedLandingDate = ZonedDateTime.now(), - globalFaoArea = "FAKE_FAO_AREA", - fishingCatches = emptyList(), - hasPortEntranceAuthorization = false, - hasPortLandingAuthorization = false, - note = null, - portLocode = "FRVNE", - purpose = LogbookMessagePurpose.LAN, - sentAt = ZonedDateTime.now(), - tripGearCodes = emptyList(), - vesselId = 1, - ) + val afterPriorNotification = + createOrUpdateManualPriorNotification.execute( + reportId = reportId, + authorTrigram = "ABC", + didNotFishAfterZeroNotice = false, + expectedArrivalDate = ZonedDateTime.now(), + expectedLandingDate = ZonedDateTime.now(), + globalFaoArea = "FAKE_FAO_AREA", + fishingCatches = emptyList(), + hasPortEntranceAuthorization = false, + hasPortLandingAuthorization = false, + note = null, + portLocode = "FRVNE", + purpose = LogbookMessagePurpose.LAN, + sentAt = ZonedDateTime.now(), + tripGearCodes = emptyList(), + vesselId = 1, + ) // Then val afterPnoValue = afterPriorNotification.logbookMessageAndValue.value @@ -400,24 +402,24 @@ class CreateOrUpdateManualPriorNotificationITests : AbstractDBTests() { ) // When - val afterPriorNotification = createOrUpdateManualPriorNotification.execute( - reportId = reportId, - - authorTrigram = "ABC", - didNotFishAfterZeroNotice = false, - expectedArrivalDate = ZonedDateTime.now(), - expectedLandingDate = ZonedDateTime.now(), - globalFaoArea = "FAKE_FAO_AREA", - fishingCatches = emptyList(), - hasPortEntranceAuthorization = false, - hasPortLandingAuthorization = false, - note = null, - portLocode = "FRVNE", - purpose = LogbookMessagePurpose.LAN, - sentAt = ZonedDateTime.now(), - tripGearCodes = emptyList(), - vesselId = 1, - ) + val afterPriorNotification = + createOrUpdateManualPriorNotification.execute( + reportId = reportId, + authorTrigram = "ABC", + didNotFishAfterZeroNotice = false, + expectedArrivalDate = ZonedDateTime.now(), + expectedLandingDate = ZonedDateTime.now(), + globalFaoArea = "FAKE_FAO_AREA", + fishingCatches = emptyList(), + hasPortEntranceAuthorization = false, + hasPortLandingAuthorization = false, + note = null, + portLocode = "FRVNE", + purpose = LogbookMessagePurpose.LAN, + sentAt = ZonedDateTime.now(), + tripGearCodes = emptyList(), + vesselId = 1, + ) // Then val afterPnoValue = afterPriorNotification.logbookMessageAndValue.value diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotificationUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotificationUTests.kt index e6aa75694a..2cfc85bc15 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotificationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotificationUTests.kt @@ -72,35 +72,35 @@ class CreateOrUpdateManualPriorNotificationUTests { ).willReturn(fakePriorNotification) // When - val result = CreateOrUpdateManualPriorNotification( - gearRepository, - manualPriorNotificationRepository, - pnoPortSubscriptionRepository, - pnoSegmentSubscriptionRepository, - pnoVesselSubscriptionRepository, - portRepository, - priorNotificationPdfDocumentRepository, - vesselRepository, - - computeManualPriorNotification, - getPriorNotification, - ).execute( - hasPortEntranceAuthorization = true, - hasPortLandingAuthorization = true, - purpose = LogbookMessagePurpose.LAN, - authorTrigram = "ABC", - didNotFishAfterZeroNotice = false, - expectedArrivalDate = ZonedDateTime.parse("2024-01-01T00:00:00Z"), - expectedLandingDate = ZonedDateTime.parse("2024-01-01T00:00:00Z"), - globalFaoArea = "FAKE_FAO_AREA", - fishingCatches = emptyList(), - note = null, - portLocode = "FAKE_PORT_LOCODE", - reportId = fakePriorNotification.reportId!!, - sentAt = ZonedDateTime.parse("2024-01-01T00:00:00Z"), - tripGearCodes = emptyList(), - vesselId = 1, - ) + val result = + CreateOrUpdateManualPriorNotification( + gearRepository, + manualPriorNotificationRepository, + pnoPortSubscriptionRepository, + pnoSegmentSubscriptionRepository, + pnoVesselSubscriptionRepository, + portRepository, + priorNotificationPdfDocumentRepository, + vesselRepository, + computeManualPriorNotification, + getPriorNotification, + ).execute( + hasPortEntranceAuthorization = true, + hasPortLandingAuthorization = true, + purpose = LogbookMessagePurpose.LAN, + authorTrigram = "ABC", + didNotFishAfterZeroNotice = false, + expectedArrivalDate = ZonedDateTime.parse("2024-01-01T00:00:00Z"), + expectedLandingDate = ZonedDateTime.parse("2024-01-01T00:00:00Z"), + globalFaoArea = "FAKE_FAO_AREA", + fishingCatches = emptyList(), + note = null, + portLocode = "FAKE_PORT_LOCODE", + reportId = fakePriorNotification.reportId!!, + sentAt = ZonedDateTime.parse("2024-01-01T00:00:00Z"), + tripGearCodes = emptyList(), + vesselId = 1, + ) // Then assertThat(result.reportId!!).isEqualTo(fakePriorNotification.reportId!!) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetNumberToVerifyUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetNumberToVerifyUTests.kt index ba1a4ba8e8..dd1e782e21 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetNumberToVerifyUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetNumberToVerifyUTests.kt @@ -48,24 +48,26 @@ class GetNumberToVerifyUTests { createdAt = null, didNotFishAfterZeroNotice = false, isManuallyCreated = false, - logbookMessageAndValue = LogbookMessageAndValue( - clazz = PNO::class.java, - logbookMessage = LogbookMessage( - id = 1, - reportId = "FAKE_REPORT_ID_1", - referencedReportId = null, - integrationDateTime = ZonedDateTime.now(), - isCorrectedByNewerMessage = false, - isDeleted = false, - isEnriched = false, - message = PNO().apply { port = "AEFJR" }, - operationDateTime = ZonedDateTime.now(), - operationNumber = "1", - operationType = LogbookOperationType.DAT, - reportDateTime = ZonedDateTime.now(), - transmissionFormat = LogbookTransmissionFormat.ERS, + logbookMessageAndValue = + LogbookMessageAndValue( + clazz = PNO::class.java, + logbookMessage = + LogbookMessage( + id = 1, + reportId = "FAKE_REPORT_ID_1", + referencedReportId = null, + integrationDateTime = ZonedDateTime.now(), + isCorrectedByNewerMessage = false, + isDeleted = false, + isEnriched = false, + message = PNO().apply { port = "AEFJR" }, + operationDateTime = ZonedDateTime.now(), + operationNumber = "1", + operationType = LogbookOperationType.DAT, + reportDateTime = ZonedDateTime.now(), + transmissionFormat = LogbookTransmissionFormat.ERS, + ), ), - ), port = null, reportingCount = null, seafront = null, @@ -74,30 +76,31 @@ class GetNumberToVerifyUTests { vessel = null, lastControlDateTime = null, ), - PriorNotification( reportId = "FAKE_REPORT_ID_2", createdAt = null, didNotFishAfterZeroNotice = false, isManuallyCreated = false, - logbookMessageAndValue = LogbookMessageAndValue( - clazz = PNO::class.java, - logbookMessage = LogbookMessage( - id = 1, - reportId = "FAKE_REPORT_ID_2_COR", - referencedReportId = "FAKE_NONEXISTENT_REPORT_ID_2", - integrationDateTime = ZonedDateTime.now(), - isCorrectedByNewerMessage = false, - isDeleted = false, - isEnriched = false, - message = PNO().apply { port = "AEFAT" }, - operationDateTime = ZonedDateTime.now(), - operationNumber = "1", - operationType = LogbookOperationType.COR, - reportDateTime = ZonedDateTime.now(), - transmissionFormat = LogbookTransmissionFormat.ERS, + logbookMessageAndValue = + LogbookMessageAndValue( + clazz = PNO::class.java, + logbookMessage = + LogbookMessage( + id = 1, + reportId = "FAKE_REPORT_ID_2_COR", + referencedReportId = "FAKE_NONEXISTENT_REPORT_ID_2", + integrationDateTime = ZonedDateTime.now(), + isCorrectedByNewerMessage = false, + isDeleted = false, + isEnriched = false, + message = PNO().apply { port = "AEFAT" }, + operationDateTime = ZonedDateTime.now(), + operationNumber = "1", + operationType = LogbookOperationType.COR, + reportDateTime = ZonedDateTime.now(), + transmissionFormat = LogbookTransmissionFormat.ERS, + ), ), - ), port = null, reportingCount = null, seafront = null, @@ -110,12 +113,13 @@ class GetNumberToVerifyUTests { ) // When - val result = GetNumberToVerify( - logbookReportRepository, - manualPriorNotificationRepository, - portRepository, - riskFactorRepository, - ).execute() + val result = + GetNumberToVerify( + logbookReportRepository, + manualPriorNotificationRepository, + portRepository, + riskFactorRepository, + ).execute() // Then assertThat(result.perSeafrontGroupCount.values).hasSize(8) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationUTests.kt index 83813036b3..960ccf4996 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationUTests.kt @@ -58,21 +58,22 @@ class GetPriorNotificationUTests { .willReturn(fakePriorNotification) // When - val result = GetPriorNotification( - gearRepository, - logbookRawMessageRepository, - logbookReportRepository, - manualPriorNotificationRepository, - portRepository, - reportingRepository, - riskFactorRepository, - speciesRepository, - vesselRepository, - ).execute( - fakePriorNotification.reportId!!, - fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, - false, - ) + val result = + GetPriorNotification( + gearRepository, + logbookRawMessageRepository, + logbookReportRepository, + manualPriorNotificationRepository, + portRepository, + reportingRepository, + riskFactorRepository, + speciesRepository, + vesselRepository, + ).execute( + fakePriorNotification.reportId!!, + fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, + false, + ) // Then assertThat(result.logbookMessageAndValue.logbookMessage.reportId) @@ -83,28 +84,31 @@ class GetPriorNotificationUTests { @Test fun `execute Should return a prior notification with a corrected logbook report operation`() { val fakeLogbookMessageReferenceReportId = "FAKE_REPORT_ID_1" - val fakePriorNotification = PriorNotificationFaker.fakePriorNotification().copy( - reportId = null, - logbookMessageAndValue = LogbookMessageAndValue( - clazz = PNO::class.java, - logbookMessage = LogbookMessage( - id = 2, - reportId = null, - referencedReportId = fakeLogbookMessageReferenceReportId, - isDeleted = false, - integrationDateTime = ZonedDateTime.now(), - isCorrectedByNewerMessage = true, - isEnriched = true, - message = PNO(), - messageType = "PNO", - operationDateTime = ZonedDateTime.now(), - operationNumber = "2", - operationType = LogbookOperationType.COR, - reportDateTime = ZonedDateTime.now(), - transmissionFormat = LogbookTransmissionFormat.ERS, - ), - ), - ) + val fakePriorNotification = + PriorNotificationFaker.fakePriorNotification().copy( + reportId = null, + logbookMessageAndValue = + LogbookMessageAndValue( + clazz = PNO::class.java, + logbookMessage = + LogbookMessage( + id = 2, + reportId = null, + referencedReportId = fakeLogbookMessageReferenceReportId, + isDeleted = false, + integrationDateTime = ZonedDateTime.now(), + isCorrectedByNewerMessage = true, + isEnriched = true, + message = PNO(), + messageType = "PNO", + operationDateTime = ZonedDateTime.now(), + operationNumber = "2", + operationType = LogbookOperationType.COR, + reportDateTime = ZonedDateTime.now(), + transmissionFormat = LogbookTransmissionFormat.ERS, + ), + ), + ) // Given given( @@ -116,21 +120,22 @@ class GetPriorNotificationUTests { .willReturn(fakePriorNotification) // When - val result = GetPriorNotification( - gearRepository, - logbookRawMessageRepository, - logbookReportRepository, - manualPriorNotificationRepository, - portRepository, - reportingRepository, - riskFactorRepository, - speciesRepository, - vesselRepository, - ).execute( - fakeLogbookMessageReferenceReportId, - fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, - false, - ) + val result = + GetPriorNotification( + gearRepository, + logbookRawMessageRepository, + logbookReportRepository, + manualPriorNotificationRepository, + portRepository, + reportingRepository, + riskFactorRepository, + speciesRepository, + vesselRepository, + ).execute( + fakeLogbookMessageReferenceReportId, + fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, + false, + ) // Then assertThat(result.reportId).isNull() diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationsITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationsITests.kt index fb36e2dd96..4de0712239 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationsITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationsITests.kt @@ -47,10 +47,11 @@ class GetPriorNotificationsITests : AbstractDBTests() { @Autowired private lateinit var vesselRepository: VesselRepository - private val defaultFilter = PriorNotificationsFilter( - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2099-12-31T00:00:00Z", - ) + private val defaultFilter = + PriorNotificationsFilter( + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2099-12-31T00:00:00Z", + ) private val defaultSeafrontGroup = SeafrontGroup.ALL private val defaultStates = null private val defaultSortColumn = PriorNotificationsSortColumn.EXPECTED_ARRIVAL_DATE @@ -66,20 +67,22 @@ class GetPriorNotificationsITests : AbstractDBTests() { val sortDirection = Sort.Direction.ASC // When - val result = getPriorNotifications - .execute( - defaultFilter, - defaultSeafrontGroup, - defaultStates, - sortColumn, - sortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + defaultSeafrontGroup, + defaultStates, + sortColumn, + sortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then - val firstPriorNotificationWithNonNullArrivalDate = result.data - .first { it.logbookMessageAndValue.value.predictedArrivalDatetimeUtc != null } + val firstPriorNotificationWithNonNullArrivalDate = + result.data + .first { it.logbookMessageAndValue.value.predictedArrivalDatetimeUtc != null } assertThat( firstPriorNotificationWithNonNullArrivalDate.logbookMessageAndValue.value.predictedArrivalDatetimeUtc, ) @@ -95,20 +98,22 @@ class GetPriorNotificationsITests : AbstractDBTests() { val sortDirection = Sort.Direction.DESC // When - val result = getPriorNotifications - .execute( - defaultFilter, - defaultSeafrontGroup, - defaultStates, - sortColumn, - sortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + defaultSeafrontGroup, + defaultStates, + sortColumn, + sortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then - val firstPriorNotificationWithNonNullArrivalDate = result.data - .first { it.logbookMessageAndValue.value.predictedArrivalDatetimeUtc != null } + val firstPriorNotificationWithNonNullArrivalDate = + result.data + .first { it.logbookMessageAndValue.value.predictedArrivalDatetimeUtc != null } assertThat( firstPriorNotificationWithNonNullArrivalDate.logbookMessageAndValue.value.predictedArrivalDatetimeUtc, ) @@ -124,20 +129,22 @@ class GetPriorNotificationsITests : AbstractDBTests() { val sortDirection = Sort.Direction.ASC // When - val result = getPriorNotifications - .execute( - defaultFilter, - defaultSeafrontGroup, - defaultStates, - sortColumn, - sortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + defaultSeafrontGroup, + defaultStates, + sortColumn, + sortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then - val firstPriorNotificationWithNonNullLandingDate = result.data - .first { it.logbookMessageAndValue.value.predictedLandingDatetimeUtc != null } + val firstPriorNotificationWithNonNullLandingDate = + result.data + .first { it.logbookMessageAndValue.value.predictedLandingDatetimeUtc != null } assertThat( firstPriorNotificationWithNonNullLandingDate.logbookMessageAndValue.value.predictedLandingDatetimeUtc, ) @@ -153,20 +160,22 @@ class GetPriorNotificationsITests : AbstractDBTests() { val sortDirection = Sort.Direction.DESC // When - val result = getPriorNotifications - .execute( - defaultFilter, - defaultSeafrontGroup, - defaultStates, - sortColumn, - sortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + defaultSeafrontGroup, + defaultStates, + sortColumn, + sortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then - val firstPriorNotificationWithNonNullLandingDate = result.data - .first { it.logbookMessageAndValue.value.predictedLandingDatetimeUtc != null } + val firstPriorNotificationWithNonNullLandingDate = + result.data + .first { it.logbookMessageAndValue.value.predictedLandingDatetimeUtc != null } assertThat( firstPriorNotificationWithNonNullLandingDate.logbookMessageAndValue.value.predictedLandingDatetimeUtc, ) @@ -182,16 +191,17 @@ class GetPriorNotificationsITests : AbstractDBTests() { val sortDirection = Sort.Direction.ASC // When - val result = getPriorNotifications - .execute( - defaultFilter, - defaultSeafrontGroup, - defaultStates, - sortColumn, - sortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + defaultSeafrontGroup, + defaultStates, + sortColumn, + sortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then val firstPriorNotificationWithNonNullPort = result.data.first { it.port != null } @@ -208,16 +218,17 @@ class GetPriorNotificationsITests : AbstractDBTests() { val sortDirection = Sort.Direction.DESC // When - val result = getPriorNotifications - .execute( - defaultFilter, - defaultSeafrontGroup, - defaultStates, - sortColumn, - sortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + defaultSeafrontGroup, + defaultStates, + sortColumn, + sortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then val firstPriorNotificationWithNonNullPort = result.data.first { it.port != null } @@ -234,16 +245,17 @@ class GetPriorNotificationsITests : AbstractDBTests() { val sortDirection = Sort.Direction.ASC // When - val result = getPriorNotifications - .execute( - defaultFilter, - defaultSeafrontGroup, - defaultStates, - sortColumn, - sortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + defaultSeafrontGroup, + defaultStates, + sortColumn, + sortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then val firstPriorNotificationWithKnownVessel = result.data.first { it.vessel!!.id != -1 } @@ -265,16 +277,17 @@ class GetPriorNotificationsITests : AbstractDBTests() { val sortDirection = Sort.Direction.DESC // When - val result = getPriorNotifications - .execute( - defaultFilter, - defaultSeafrontGroup, - defaultStates, - sortColumn, - sortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + defaultSeafrontGroup, + defaultStates, + sortColumn, + sortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then val firstPriorNotificationWithKnownVessel = result.data.first { it.vessel!!.id != -1 } @@ -296,16 +309,17 @@ class GetPriorNotificationsITests : AbstractDBTests() { val sortDirection = Sort.Direction.ASC // When - val result = getPriorNotifications - .execute( - defaultFilter, - defaultSeafrontGroup, - defaultStates, - sortColumn, - sortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + defaultSeafrontGroup, + defaultStates, + sortColumn, + sortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then val firstPriorNotificationWithNonNullRiskFactor = @@ -324,16 +338,17 @@ class GetPriorNotificationsITests : AbstractDBTests() { val sortDirection = Sort.Direction.DESC // When - val result = getPriorNotifications - .execute( - defaultFilter, - defaultSeafrontGroup, - defaultStates, - sortColumn, - sortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + defaultSeafrontGroup, + defaultStates, + sortColumn, + sortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then val firstPriorNotificationWithNonNullRiskFactor = @@ -351,16 +366,17 @@ class GetPriorNotificationsITests : AbstractDBTests() { val seafrontGroup = SeafrontGroup.NAMO // When - val result = getPriorNotifications - .execute( - defaultFilter, - seafrontGroup, - defaultStates, - defaultSortColumn, - defaultSortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + seafrontGroup, + defaultStates, + defaultSortColumn, + defaultSortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then assertThat(result.data).hasSizeGreaterThan(0) @@ -374,16 +390,17 @@ class GetPriorNotificationsITests : AbstractDBTests() { val states = listOf(PriorNotificationState.PENDING_SEND, PriorNotificationState.OUT_OF_VERIFICATION_SCOPE) // When - val result = getPriorNotifications - .execute( - defaultFilter, - defaultSeafrontGroup, - states, - defaultSortColumn, - defaultSortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + getPriorNotifications + .execute( + defaultFilter, + defaultSeafrontGroup, + states, + defaultSortColumn, + defaultSortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then assertThat(result.data).hasSizeGreaterThan(0) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationsUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationsUTests.kt index 55901ba4cd..31f2ba8785 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationsUTests.kt @@ -45,10 +45,11 @@ class GetPriorNotificationsUTests { @MockBean private lateinit var vesselRepository: VesselRepository - private val defaultFilter = PriorNotificationsFilter( - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2099-12-31T00:00:00Z", - ) + private val defaultFilter = + PriorNotificationsFilter( + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2099-12-31T00:00:00Z", + ) private val defaultSeafrontGroup = SeafrontGroup.ALL private val defaultStates = null private val defaultSortColumn = PriorNotificationsSortColumn.EXPECTED_ARRIVAL_DATE @@ -66,24 +67,26 @@ class GetPriorNotificationsUTests { createdAt = null, didNotFishAfterZeroNotice = false, isManuallyCreated = false, - logbookMessageAndValue = LogbookMessageAndValue( - clazz = PNO::class.java, - logbookMessage = LogbookMessage( - id = 1, - reportId = "FAKE_REPORT_ID_1", - referencedReportId = null, - integrationDateTime = ZonedDateTime.now(), - isCorrectedByNewerMessage = false, - isDeleted = false, - isEnriched = false, - message = PNO(), - operationDateTime = ZonedDateTime.now(), - operationNumber = "1", - operationType = LogbookOperationType.DAT, - reportDateTime = ZonedDateTime.now(), - transmissionFormat = LogbookTransmissionFormat.ERS, + logbookMessageAndValue = + LogbookMessageAndValue( + clazz = PNO::class.java, + logbookMessage = + LogbookMessage( + id = 1, + reportId = "FAKE_REPORT_ID_1", + referencedReportId = null, + integrationDateTime = ZonedDateTime.now(), + isCorrectedByNewerMessage = false, + isDeleted = false, + isEnriched = false, + message = PNO(), + operationDateTime = ZonedDateTime.now(), + operationNumber = "1", + operationType = LogbookOperationType.DAT, + reportDateTime = ZonedDateTime.now(), + transmissionFormat = LogbookTransmissionFormat.ERS, + ), ), - ), port = null, reportingCount = null, seafront = null, @@ -92,30 +95,31 @@ class GetPriorNotificationsUTests { vessel = null, lastControlDateTime = null, ), - PriorNotification( reportId = "FAKE_REPORT_ID_2", createdAt = null, didNotFishAfterZeroNotice = false, isManuallyCreated = false, - logbookMessageAndValue = LogbookMessageAndValue( - clazz = PNO::class.java, - logbookMessage = LogbookMessage( - id = 1, - reportId = "FAKE_REPORT_ID_2_COR", - referencedReportId = "FAKE_NONEXISTENT_REPORT_ID_2", - integrationDateTime = ZonedDateTime.now(), - isCorrectedByNewerMessage = false, - isDeleted = false, - isEnriched = false, - message = PNO(), - operationDateTime = ZonedDateTime.now(), - operationNumber = "1", - operationType = LogbookOperationType.COR, - reportDateTime = ZonedDateTime.now(), - transmissionFormat = LogbookTransmissionFormat.ERS, + logbookMessageAndValue = + LogbookMessageAndValue( + clazz = PNO::class.java, + logbookMessage = + LogbookMessage( + id = 1, + reportId = "FAKE_REPORT_ID_2_COR", + referencedReportId = "FAKE_NONEXISTENT_REPORT_ID_2", + integrationDateTime = ZonedDateTime.now(), + isCorrectedByNewerMessage = false, + isDeleted = false, + isEnriched = false, + message = PNO(), + operationDateTime = ZonedDateTime.now(), + operationNumber = "1", + operationType = LogbookOperationType.COR, + reportDateTime = ZonedDateTime.now(), + transmissionFormat = LogbookTransmissionFormat.ERS, + ), ), - ), port = null, reportingCount = null, seafront = null, @@ -128,24 +132,25 @@ class GetPriorNotificationsUTests { ) // When - val result = GetPriorNotifications( - gearRepository, - logbookReportRepository, - manualPriorNotificationRepository, - portRepository, - reportingRepository, - riskFactorRepository, - speciesRepository, - vesselRepository, - ).execute( - defaultFilter, - defaultSeafrontGroup, - defaultStates, - defaultSortColumn, - defaultSortDirection, - defaultPageNumber, - defaultPageSize, - ) + val result = + GetPriorNotifications( + gearRepository, + logbookReportRepository, + manualPriorNotificationRepository, + portRepository, + reportingRepository, + riskFactorRepository, + speciesRepository, + vesselRepository, + ).execute( + defaultFilter, + defaultSeafrontGroup, + defaultStates, + defaultSortColumn, + defaultSortDirection, + defaultPageNumber, + defaultPageSize, + ) // Then assertThat(result.data).hasSize(2) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/TestUtils.kt index 10c30bf0ee..b0afb13cc9 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/TestUtils.kt @@ -6,191 +6,208 @@ import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PnoTypeRule object TestUtils { fun getDummyPnoTypes(): List { - val pnoType1 = PnoType( - id = 1, - name = "Préavis type 1", - minimumNotificationPeriod = 4.0, - hasDesignatedPorts = true, - pnoTypeRules = listOf( - PnoTypeRule( - id = 1, - species = listOf("HKE", "BSS", "COD", "ANF", "SOL"), - faoAreas = listOf( - "27.3.a", - "27.4", - "27.6", - "27.7", - "27.8.a", - "27.8.b", - "27.8.c", - "27.8.d", - "27.9.a", + val pnoType1 = + PnoType( + id = 1, + name = "Préavis type 1", + minimumNotificationPeriod = 4.0, + hasDesignatedPorts = true, + pnoTypeRules = + listOf( + PnoTypeRule( + id = 1, + species = listOf("HKE", "BSS", "COD", "ANF", "SOL"), + faoAreas = + listOf( + "27.3.a", + "27.4", + "27.6", + "27.7", + "27.8.a", + "27.8.b", + "27.8.c", + "27.8.d", + "27.9.a", + ), + cgpmAreas = listOf(), + gears = listOf(), + flagStates = listOf(), + minimumQuantityKg = 0.0, + ), + PnoTypeRule( + id = 2, + species = listOf("HKE"), + faoAreas = listOf("37"), + cgpmAreas = listOf("30.01", "30.05", "30.06", "30.07", "30.09", "30.10", "30.11"), + gears = listOf(), + flagStates = listOf(), + minimumQuantityKg = 0.0, + ), + PnoTypeRule( + id = 3, + species = listOf("HER", "MAC", "HOM", "WHB"), + faoAreas = listOf("27", "34.1.2", "34.2"), + cgpmAreas = listOf(), + gears = listOf(), + flagStates = listOf(), + minimumQuantityKg = 10000.0, + ), ), - cgpmAreas = listOf(), - gears = listOf(), - flagStates = listOf(), - minimumQuantityKg = 0.0, - ), - PnoTypeRule( - id = 2, - species = listOf("HKE"), - faoAreas = listOf("37"), - cgpmAreas = listOf("30.01", "30.05", "30.06", "30.07", "30.09", "30.10", "30.11"), - gears = listOf(), - flagStates = listOf(), - minimumQuantityKg = 0.0, - ), - PnoTypeRule( - id = 3, - species = listOf("HER", "MAC", "HOM", "WHB"), - faoAreas = listOf("27", "34.1.2", "34.2"), - cgpmAreas = listOf(), - gears = listOf(), - flagStates = listOf(), - minimumQuantityKg = 10000.0, - ), - ), - ) + ) - val pnoType2 = PnoType( - id = 2, - name = "Préavis type 2", - minimumNotificationPeriod = 4.0, - hasDesignatedPorts = true, - pnoTypeRules = listOf( - PnoTypeRule( - id = 4, - species = listOf("HKE", "BSS", "COD", "ANF", "SOL"), - faoAreas = listOf( - "27.3.a", - "27.4", - "27.6", - "27.7", - "27.8.a", - "27.8.b", - "27.8.c", - "27.8.d", - "27.9.a", + val pnoType2 = + PnoType( + id = 2, + name = "Préavis type 2", + minimumNotificationPeriod = 4.0, + hasDesignatedPorts = true, + pnoTypeRules = + listOf( + PnoTypeRule( + id = 4, + species = listOf("HKE", "BSS", "COD", "ANF", "SOL"), + faoAreas = + listOf( + "27.3.a", + "27.4", + "27.6", + "27.7", + "27.8.a", + "27.8.b", + "27.8.c", + "27.8.d", + "27.9.a", + ), + cgpmAreas = listOf(), + gears = listOf(), + flagStates = listOf(), + minimumQuantityKg = 2000.0, + ), + PnoTypeRule( + id = 5, + species = listOf("HER", "MAC", "HOM", "WHB"), + faoAreas = + listOf( + "27", + "34.1.2", + "34.2", + ), + cgpmAreas = listOf(), + gears = listOf(), + flagStates = listOf(), + minimumQuantityKg = 10000.0, + ), ), - cgpmAreas = listOf(), - gears = listOf(), - flagStates = listOf(), - minimumQuantityKg = 2000.0, - ), - PnoTypeRule( - id = 5, - species = listOf("HER", "MAC", "HOM", "WHB"), - faoAreas = listOf( - "27", - "34.1.2", - "34.2", - ), - cgpmAreas = listOf(), - gears = listOf(), - flagStates = listOf(), - minimumQuantityKg = 10000.0, - ), - ), - ) + ) - val pnoType3 = PnoType( - id = 3, - name = "Préavis par pavillon", - minimumNotificationPeriod = 4.0, - hasDesignatedPorts = true, - pnoTypeRules = listOf( - PnoTypeRule( - id = 6, - species = listOf(), - faoAreas = listOf(), - cgpmAreas = listOf(), - gears = listOf(), - flagStates = listOf(CountryCode.GB, CountryCode.VE), - minimumQuantityKg = 0.0, - ), - ), - ) + val pnoType3 = + PnoType( + id = 3, + name = "Préavis par pavillon", + minimumNotificationPeriod = 4.0, + hasDesignatedPorts = true, + pnoTypeRules = + listOf( + PnoTypeRule( + id = 6, + species = listOf(), + faoAreas = listOf(), + cgpmAreas = listOf(), + gears = listOf(), + flagStates = listOf(CountryCode.GB, CountryCode.VE), + minimumQuantityKg = 0.0, + ), + ), + ) - val pnoType4 = PnoType( - id = 4, - name = "Préavis par engin", - minimumNotificationPeriod = 4.0, - hasDesignatedPorts = true, - pnoTypeRules = listOf( - PnoTypeRule( - id = 7, - species = listOf(), - faoAreas = listOf(), - cgpmAreas = listOf(), - gears = listOf("SB"), - flagStates = listOf(), - minimumQuantityKg = 0.0, - ), - ), - ) + val pnoType4 = + PnoType( + id = 4, + name = "Préavis par engin", + minimumNotificationPeriod = 4.0, + hasDesignatedPorts = true, + pnoTypeRules = + listOf( + PnoTypeRule( + id = 7, + species = listOf(), + faoAreas = listOf(), + cgpmAreas = listOf(), + gears = listOf("SB"), + flagStates = listOf(), + minimumQuantityKg = 0.0, + ), + ), + ) - val pnoType5 = PnoType( - id = 5, - name = "Préavis par engin et pavillon", - minimumNotificationPeriod = 4.0, - hasDesignatedPorts = true, - pnoTypeRules = listOf( - PnoTypeRule( - id = 7, - species = listOf(), - faoAreas = listOf(), - cgpmAreas = listOf(), - gears = listOf("OTB"), - flagStates = listOf(CountryCode.AD), - minimumQuantityKg = 0.0, - ), - ), - ) + val pnoType5 = + PnoType( + id = 5, + name = "Préavis par engin et pavillon", + minimumNotificationPeriod = 4.0, + hasDesignatedPorts = true, + pnoTypeRules = + listOf( + PnoTypeRule( + id = 7, + species = listOf(), + faoAreas = listOf(), + cgpmAreas = listOf(), + gears = listOf("OTB"), + flagStates = listOf(CountryCode.AD), + minimumQuantityKg = 0.0, + ), + ), + ) - val pnoType6 = PnoType( - id = 6, - name = "Préavis par espèce, fao et pavillon", - minimumNotificationPeriod = 4.0, - hasDesignatedPorts = true, - pnoTypeRules = listOf( - PnoTypeRule( - id = 8, - species = listOf("AMZ"), - faoAreas = listOf("37"), - cgpmAreas = listOf("30.01", "30.05", "30.06", "30.07", "30.09", "30.10", "30.11"), - gears = listOf(), - flagStates = listOf(CountryCode.AD), - minimumQuantityKg = 250.0, - ), - ), - ) + val pnoType6 = + PnoType( + id = 6, + name = "Préavis par espèce, fao et pavillon", + minimumNotificationPeriod = 4.0, + hasDesignatedPorts = true, + pnoTypeRules = + listOf( + PnoTypeRule( + id = 8, + species = listOf("AMZ"), + faoAreas = listOf("37"), + cgpmAreas = listOf("30.01", "30.05", "30.06", "30.07", "30.09", "30.10", "30.11"), + gears = listOf(), + flagStates = listOf(CountryCode.AD), + minimumQuantityKg = 250.0, + ), + ), + ) - val pnoType7 = PnoType( - id = 7, - name = "Préavis type 7", - minimumNotificationPeriod = 4.0, - hasDesignatedPorts = true, - pnoTypeRules = listOf( - PnoTypeRule( - id = 9, - species = listOf(), - faoAreas = listOf(), - cgpmAreas = listOf(), - gears = listOf("OTT"), - flagStates = listOf(CountryCode.GB), - minimumQuantityKg = 2000.0, - ), - PnoTypeRule( - id = 10, - species = listOf(), - faoAreas = listOf(), - cgpmAreas = listOf(), - gears = listOf("PTB"), - flagStates = listOf(CountryCode.BB), - minimumQuantityKg = 10000.0, - ), - ), - ) + val pnoType7 = + PnoType( + id = 7, + name = "Préavis type 7", + minimumNotificationPeriod = 4.0, + hasDesignatedPorts = true, + pnoTypeRules = + listOf( + PnoTypeRule( + id = 9, + species = listOf(), + faoAreas = listOf(), + cgpmAreas = listOf(), + gears = listOf("OTT"), + flagStates = listOf(CountryCode.GB), + minimumQuantityKg = 2000.0, + ), + PnoTypeRule( + id = 10, + species = listOf(), + faoAreas = listOf(), + cgpmAreas = listOf(), + gears = listOf("PTB"), + flagStates = listOf(CountryCode.BB), + minimumQuantityKg = 10000.0, + ), + ), + ) return listOf(pnoType1, pnoType2, pnoType3, pnoType4, pnoType5, pnoType6, pnoType7) } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/UpdateLogbookPriorNotificationUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/UpdateLogbookPriorNotificationUTests.kt index 6c78ee0a2b..53bb57d0c0 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/UpdateLogbookPriorNotificationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/UpdateLogbookPriorNotificationUTests.kt @@ -35,16 +35,17 @@ class UpdateLogbookPriorNotificationUTests { ).willReturn(fakePriorNotification) // When - val result = UpdateLogbookPriorNotification( - logbookReportRepository, - priorNotificationPdfDocumentRepository, - getPriorNotification, - ).execute( - reportId = fakePriorNotification.reportId!!, - operationDate = fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, - authorTrigram = "ABC", - note = null, - ) + val result = + UpdateLogbookPriorNotification( + logbookReportRepository, + priorNotificationPdfDocumentRepository, + getPriorNotification, + ).execute( + reportId = fakePriorNotification.reportId!!, + operationDate = fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, + authorTrigram = "ABC", + note = null, + ) // Then assertThat(result.reportId).isEqualTo(fakePriorNotification.reportId) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotificationITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotificationITests.kt index 15de691a2a..0dcc9cc267 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotificationITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotificationITests.kt @@ -55,7 +55,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { return Stream.of( // ------------------------------------------------------------- // Logbook prior notifications - // "00000" -> "00101" TestCase( "FAKE_OPERATION_101", @@ -76,7 +75,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "00001" -> "00101" TestCase( "FAKE_OPERATION_102", @@ -97,7 +95,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "00010" -> "00101" TestCase( "FAKE_OPERATION_103", @@ -118,7 +115,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "00100" -> "00101" TestCase( "FAKE_OPERATION_104", @@ -139,7 +135,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "00101" -> "00101" TestCase( "FAKE_OPERATION_105", @@ -160,7 +155,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "00110" -> "00101" TestCase( "FAKE_OPERATION_106", @@ -181,7 +175,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "01000" -> "01101" TestCase( "FAKE_OPERATION_107", @@ -202,7 +195,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "01100" -> "01101" TestCase( "FAKE_OPERATION_108", @@ -223,7 +215,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "01101" -> "01101" TestCase( "FAKE_OPERATION_109_COR", @@ -244,7 +235,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "01110" -> "01101" TestCase( "FAKE_OPERATION_110", @@ -265,10 +255,8 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // ------------------------------------------------------------- // Manual prior notifications - // "10000" -> "10101" TestCase( "00000000-0000-4000-0000-000000000001", @@ -289,7 +277,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "10001" -> "10101" TestCase( "00000000-0000-4000-0000-000000000002", @@ -310,7 +297,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "10010" -> "10101" TestCase( "00000000-0000-4000-0000-000000000003", @@ -331,7 +317,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "10100" -> "10101" TestCase( "00000000-0000-4000-0000-000000000004", @@ -352,7 +337,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "10101" -> "10101" TestCase( "00000000-0000-4000-0000-000000000005", @@ -373,7 +357,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "10110" -> "10101" TestCase( "00000000-0000-4000-0000-000000000006", @@ -394,7 +377,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "11000" -> "11101" TestCase( "00000000-0000-4000-0000-000000000007", @@ -415,7 +397,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "11100" -> "11101" TestCase( "00000000-0000-4000-0000-000000000008", @@ -436,7 +417,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "11101" -> "11101" TestCase( "00000000-0000-4000-0000-000000000009", @@ -457,7 +437,6 @@ class VerifyAndSendPriorNotificationITests : AbstractDBTests() { ), PriorNotificationState.PENDING_SEND, ), - // "11110" -> "11101" TestCase( "00000000-0000-4000-0000-000000000010", diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotificationUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotificationUTests.kt index ae4ce40861..92891a31f9 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotificationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/VerifyAndSendPriorNotificationUTests.kt @@ -45,15 +45,16 @@ class VerifyAndSendPriorNotificationUTests { .willReturn(fakePriorNotification) // When - val result = VerifyAndSendPriorNotification( - logbookReportRepository, - manualPriorNotificationRepository, - getPriorNotification, - ).execute( - fakePriorNotification.reportId!!, - fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, - false, - ) + val result = + VerifyAndSendPriorNotification( + logbookReportRepository, + manualPriorNotificationRepository, + getPriorNotification, + ).execute( + fakePriorNotification.reportId!!, + fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, + false, + ) // Then Assertions.assertThat(result.reportId).isEqualTo(fakePriorNotification.reportId!!) @@ -83,15 +84,16 @@ class VerifyAndSendPriorNotificationUTests { .willReturn(fakePriorNotification) // When - val result = VerifyAndSendPriorNotification( - logbookReportRepository, - manualPriorNotificationRepository, - getPriorNotification, - ).execute( - fakePriorNotification.reportId!!, - fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, - true, - ) + val result = + VerifyAndSendPriorNotification( + logbookReportRepository, + manualPriorNotificationRepository, + getPriorNotification, + ).execute( + fakePriorNotification.reportId!!, + fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime, + true, + ) // Then Assertions.assertThat(result.reportId).isEqualTo(fakePriorNotification.reportId!!) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/utils/PaginatedListUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/utils/PaginatedListUTests.kt index 9d98b578e0..a7bf90366a 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/utils/PaginatedListUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/utils/PaginatedListUTests.kt @@ -16,13 +16,14 @@ class PaginatedListUTests { @Test fun `new Should return the expected list from the first page`() { // Given - val items = listOf( - FakeCollectionItem(1, "Item 1"), - FakeCollectionItem(2, "Item 2"), - FakeCollectionItem(3, "Item 3"), - FakeCollectionItem(4, "Item 4"), - FakeCollectionItem(5, "Item 5"), - ) + val items = + listOf( + FakeCollectionItem(1, "Item 1"), + FakeCollectionItem(2, "Item 2"), + FakeCollectionItem(3, "Item 3"), + FakeCollectionItem(4, "Item 4"), + FakeCollectionItem(5, "Item 5"), + ) val pageNumber = 0 val pageSize = 2 val extraData = FakeCollectionExtraData(extraProp = 42) @@ -33,10 +34,11 @@ class PaginatedListUTests { // Then assertThat(result).isEqualTo( PaginatedList( - data = listOf( - FakeCollectionItem(1, "Item 1"), - FakeCollectionItem(2, "Item 2"), - ), + data = + listOf( + FakeCollectionItem(1, "Item 1"), + FakeCollectionItem(2, "Item 2"), + ), extraData = extraData, lastPageNumber = 2, pageNumber = pageNumber, @@ -73,13 +75,14 @@ class PaginatedListUTests { @Test fun `new Should return the expected list from the last page`() { // Given - val items = listOf( - FakeCollectionItem(1, "Item 1"), - FakeCollectionItem(2, "Item 2"), - FakeCollectionItem(3, "Item 3"), - FakeCollectionItem(4, "Item 4"), - FakeCollectionItem(5, "Item 5"), - ) + val items = + listOf( + FakeCollectionItem(1, "Item 1"), + FakeCollectionItem(2, "Item 2"), + FakeCollectionItem(3, "Item 3"), + FakeCollectionItem(4, "Item 4"), + FakeCollectionItem(5, "Item 5"), + ) val pageNumber = 2 val pageSize = 2 val extraData = FakeCollectionExtraData(extraProp = 42) @@ -103,11 +106,12 @@ class PaginatedListUTests { @Test fun `new Should return an empty list when the page number exceeds the last page number`() { // Given - val items = listOf( - FakeCollectionItem(1, "Item 1"), - FakeCollectionItem(2, "Item 2"), - FakeCollectionItem(3, "Item 3"), - ) + val items = + listOf( + FakeCollectionItem(1, "Item 1"), + FakeCollectionItem(2, "Item 2"), + FakeCollectionItem(3, "Item 3"), + ) val pageNumber = 2 val pageSize = 2 val extraData = FakeCollectionExtraData(extraProp = 42) @@ -131,11 +135,12 @@ class PaginatedListUTests { @Test fun `new Should return null extra data when there is none`() { // Given - val items = listOf( - FakeCollectionItem(1, "Item 1"), - FakeCollectionItem(2, "Item 2"), - FakeCollectionItem(3, "Item 3"), - ) + val items = + listOf( + FakeCollectionItem(1, "Item 1"), + FakeCollectionItem(2, "Item 2"), + FakeCollectionItem(3, "Item 3"), + ) val pageNumber = 1 val pageSize = 2 diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/fakers/PriorNotificationFaker.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/fakers/PriorNotificationFaker.kt index 85bc628139..658ad24e91 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/fakers/PriorNotificationFaker.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/fakers/PriorNotificationFaker.kt @@ -13,10 +13,11 @@ class PriorNotificationFaker { createdAt = ZonedDateTime.now(), didNotFishAfterZeroNotice = false, isManuallyCreated = false, - logbookMessageAndValue = LogbookMessageAndValue( - clazz = PNO::class.java, - logbookMessage = LogbookMessageFaker.fakePnoLogbookMessage(index), - ), + logbookMessageAndValue = + LogbookMessageAndValue( + clazz = PNO::class.java, + logbookMessage = LogbookMessageFaker.fakePnoLogbookMessage(index), + ), port = PortFaker.fakePort(), reportingCount = null, seafront = null, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/LoggingFormatterUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/LoggingFormatterUTests.kt index 7eb12f7299..3b8807de97 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/LoggingFormatterUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/LoggingFormatterUTests.kt @@ -34,17 +34,18 @@ class LoggingFormatterUTests { request.setContent("TEST".toByteArray()) // When - val log = LoggingFormatter.formatRequest( - mapper, - request, - UpdateReportingDataInput( - reportingActor = ReportingActor.OPS, - type = ReportingType.INFRACTION_SUSPICION, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ), - ) + val log = + LoggingFormatter.formatRequest( + mapper, + request, + UpdateReportingDataInput( + reportingActor = ReportingActor.OPS, + type = ReportingType.INFRACTION_SUSPICION, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), + ) // Then assertThat(log).isEqualTo( @@ -68,25 +69,27 @@ class LoggingFormatterUTests { val dateTime = ZonedDateTime.of(2019, 1, 18, 7, 19, 45, 45, ZoneOffset.UTC) // When - val log = LoggingFormatter.formatRequest( - mapper, - request, - CreateReportingDataInput( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = dateTime, - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", + val log = + LoggingFormatter.formatRequest( + mapper, + request, + CreateReportingDataInput( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = dateTime, + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), + type = ReportingType.INFRACTION_SUSPICION, ), - type = ReportingType.INFRACTION_SUSPICION, - ), - ) + ) // Then assertThat(log).isEqualTo( @@ -121,13 +124,14 @@ class LoggingFormatterUTests { val request = MockHttpServletRequest("POST", "/healthcheck") val response = MockHttpServletResponse() response.status = 201 - val body = UpdateReportingDataInput( - reportingActor = ReportingActor.OPS, - type = ReportingType.INFRACTION_SUSPICION, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ) + val body = + UpdateReportingDataInput( + reportingActor = ReportingActor.OPS, + type = ReportingType.INFRACTION_SUSPICION, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ) // When val log = LoggingFormatter.formatResponse(mapper, request, response, body) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/BeaconMalfunctionControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/BeaconMalfunctionControllerITests.kt index 3c99954749..8cea50b599 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/BeaconMalfunctionControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/BeaconMalfunctionControllerITests.kt @@ -33,7 +33,6 @@ import java.time.ZonedDateTime @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(BeaconMalfunctionController::class)]) class BeaconMalfunctionControllerITests { - @Autowired private lateinit var api: MockMvc @@ -88,31 +87,34 @@ class BeaconMalfunctionControllerITests { given(this.updateBeaconMalfunction.execute(123, VesselStatus.AT_SEA, null, null)) .willReturn( BeaconMalfunctionResumeAndDetails( - beaconMalfunction = BeaconMalfunction( - 1, "CFR", "EXTERNAL_IMMAT", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, - ZonedDateTime.now(), null, ZonedDateTime.now(), - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - 1, - 1, - "A comment", - BeaconMalfunctionCommentUserType.SIP, - ZonedDateTime.now(), + beaconMalfunction = + BeaconMalfunction( + 1, "CFR", "EXTERNAL_IMMAT", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, + ZonedDateTime.now(), null, ZonedDateTime.now(), + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, ), - ), - actions = listOf( - BeaconMalfunctionAction( - 1, - 1, - BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - "PREVIOUS", - "NEXT", - ZonedDateTime.now(), + comments = + listOf( + BeaconMalfunctionComment( + 1, + 1, + "A comment", + BeaconMalfunctionCommentUserType.SIP, + ZonedDateTime.now(), + ), + ), + actions = + listOf( + BeaconMalfunctionAction( + 1, + 1, + BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + "PREVIOUS", + "NEXT", + ZonedDateTime.now(), + ), ), - ), ), ) @@ -155,49 +157,54 @@ class BeaconMalfunctionControllerITests { given(this.getBeaconMalfunction.execute(123)) .willReturn( BeaconMalfunctionResumeAndDetails( - beaconMalfunction = BeaconMalfunction( - 1, "CFR", "EXTERNAL_IMMAT", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, - ZonedDateTime.now(), null, ZonedDateTime.now(), - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), + beaconMalfunction = + BeaconMalfunction( + 1, "CFR", "EXTERNAL_IMMAT", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, + ZonedDateTime.now(), null, ZonedDateTime.now(), + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, + ), resume = VesselBeaconMalfunctionsResume(1, 2, null, null), - comments = listOf( - BeaconMalfunctionComment( - 1, - 1, - "A comment", - BeaconMalfunctionCommentUserType.SIP, - ZonedDateTime.now(), + comments = + listOf( + BeaconMalfunctionComment( + 1, + 1, + "A comment", + BeaconMalfunctionCommentUserType.SIP, + ZonedDateTime.now(), + ), ), - ), - actions = listOf( - BeaconMalfunctionAction( - 1, - 1, - BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - "PREVIOUS", - "NEXT", - ZonedDateTime.now(), + actions = + listOf( + BeaconMalfunctionAction( + 1, + 1, + BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + "PREVIOUS", + "NEXT", + ZonedDateTime.now(), + ), ), - ), - notifications = listOf( - BeaconMalfunctionNotifications( - beaconMalfunctionId = 1, - dateTimeUtc = dateTimeUtc, - notificationType = BeaconMalfunctionNotificationType.MALFUNCTION_AT_PORT_INITIAL_NOTIFICATION, - notifications = listOf( - BeaconMalfunctionNotification( - id = 1, beaconMalfunctionId = 1, dateTimeUtc = dateTimeUtc, - notificationType = BeaconMalfunctionNotificationType.MALFUNCTION_AT_PORT_INITIAL_NOTIFICATION, - communicationMeans = CommunicationMeans.SMS, - recipientFunction = BeaconMalfunctionNotificationRecipientFunction.VESSEL_CAPTAIN, - recipientName = "Jack Sparrow", recipientAddressOrNumber = "0000000000", - success = false, errorMessage = "This message could not be delivered", - ), + notifications = + listOf( + BeaconMalfunctionNotifications( + beaconMalfunctionId = 1, + dateTimeUtc = dateTimeUtc, + notificationType = BeaconMalfunctionNotificationType.MALFUNCTION_AT_PORT_INITIAL_NOTIFICATION, + notifications = + listOf( + BeaconMalfunctionNotification( + id = 1, beaconMalfunctionId = 1, dateTimeUtc = dateTimeUtc, + notificationType = BeaconMalfunctionNotificationType.MALFUNCTION_AT_PORT_INITIAL_NOTIFICATION, + communicationMeans = CommunicationMeans.SMS, + recipientFunction = BeaconMalfunctionNotificationRecipientFunction.VESSEL_CAPTAIN, + recipientName = "Jack Sparrow", recipientAddressOrNumber = "0000000000", + success = false, errorMessage = "This message could not be delivered", + ), + ), ), ), - ), ), ) @@ -229,31 +236,34 @@ class BeaconMalfunctionControllerITests { given(this.getBeaconMalfunction.execute(123)) .willReturn( BeaconMalfunctionResumeAndDetails( - beaconMalfunction = BeaconMalfunction( - 1, "CFR", "EXTERNAL_IMMAT", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, - ZonedDateTime.now(), null, ZonedDateTime.now(), - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - 1, - 1, - "A comment", - BeaconMalfunctionCommentUserType.SIP, - ZonedDateTime.now(), + beaconMalfunction = + BeaconMalfunction( + 1, "CFR", "EXTERNAL_IMMAT", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, + ZonedDateTime.now(), null, ZonedDateTime.now(), + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, ), - ), - actions = listOf( - BeaconMalfunctionAction( - 1, - 1, - BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - "PREVIOUS", - "NEXT", - ZonedDateTime.now(), + comments = + listOf( + BeaconMalfunctionComment( + 1, + 1, + "A comment", + BeaconMalfunctionCommentUserType.SIP, + ZonedDateTime.now(), + ), + ), + actions = + listOf( + BeaconMalfunctionAction( + 1, + 1, + BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + "PREVIOUS", + "NEXT", + ZonedDateTime.now(), + ), ), - ), ), ) @@ -273,31 +283,34 @@ class BeaconMalfunctionControllerITests { fun `Should save a beacon malfunction comment`() { given(this.saveBeaconMalfunctionComment.execute(any(), any(), any())).willReturn( BeaconMalfunctionResumeAndDetails( - beaconMalfunction = BeaconMalfunction( - 1, "CFR", "EXTERNAL_IMMAT", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, - ZonedDateTime.now(), null, ZonedDateTime.now(), - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - 1, - 1, - "A comment", - BeaconMalfunctionCommentUserType.SIP, - ZonedDateTime.now(), + beaconMalfunction = + BeaconMalfunction( + 1, "CFR", "EXTERNAL_IMMAT", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, + ZonedDateTime.now(), null, ZonedDateTime.now(), + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, ), - ), - actions = listOf( - BeaconMalfunctionAction( - 1, - 1, - BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - "PREVIOUS", - "NEXT", - ZonedDateTime.now(), + comments = + listOf( + BeaconMalfunctionComment( + 1, + 1, + "A comment", + BeaconMalfunctionCommentUserType.SIP, + ZonedDateTime.now(), + ), + ), + actions = + listOf( + BeaconMalfunctionAction( + 1, + 1, + BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + "PREVIOUS", + "NEXT", + ZonedDateTime.now(), + ), ), - ), ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ControlObjectiveAdminControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ControlObjectiveAdminControllerITests.kt index 1f5a2f3487..b8846cbe0d 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ControlObjectiveAdminControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ControlObjectiveAdminControllerITests.kt @@ -24,7 +24,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(ControlObjectiveAdminController::class)]) class ControlObjectiveAdminControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/DataReferentialControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/DataReferentialControllerITests.kt index d4299c88cd..d0a4443fb6 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/DataReferentialControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/DataReferentialControllerITests.kt @@ -25,7 +25,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(DataReferentialController::class)]) class DataReferentialControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FaoAreaControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FaoAreaControllerITests.kt index ccaeb42fe7..9850fd16b3 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FaoAreaControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FaoAreaControllerITests.kt @@ -23,7 +23,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(FaoAreaController::class)]) class FaoAreaControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentAdminControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentAdminControllerITests.kt index dd60e34c36..47ddd3409a 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentAdminControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentAdminControllerITests.kt @@ -27,7 +27,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(FleetSegmentAdminController::class)]) class FleetSegmentAdminControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentControllerITests.kt index 12d63f7a3e..5a8748280d 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/FleetSegmentControllerITests.kt @@ -24,7 +24,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(FleetSegmentController::class)]) class FleetSegmentControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ForeignFMCsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ForeignFMCsControllerITests.kt index 25438eba22..883b1a683a 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ForeignFMCsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ForeignFMCsControllerITests.kt @@ -20,7 +20,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(ForeignFMCsController::class)]) class ForeignFMCsControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt index e6c8df7dac..a7399e48fe 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionActionsControllerITests.kt @@ -35,7 +35,6 @@ import java.time.ZonedDateTime @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(MissionActionsController::class)]) class MissionActionsControllerITests { - @Autowired private lateinit var api: MockMvc @@ -158,27 +157,30 @@ class MissionActionsControllerITests { missionId = 2, vesselId = 2, actionType = MissionActionType.SEA_CONTROL, - logbookInfractions = listOf( - LogbookInfraction( - InfractionType.WITH_RECORD, - 27689, - "Poids à bord MNZ supérieur de 50% au poids déclaré", + logbookInfractions = + listOf( + LogbookInfraction( + InfractionType.WITH_RECORD, + 27689, + "Poids à bord MNZ supérieur de 50% au poids déclaré", + ), ), - ), faoAreas = listOf("25.6.9", "25.7.9"), - segments = listOf( - FleetSegment( - segment = "WWSS10", - segmentName = "World Wide Segment", + segments = + listOf( + FleetSegment( + segment = "WWSS10", + segmentName = "World Wide Segment", + ), ), - ), - gearInfractions = listOf( - GearInfraction( - InfractionType.WITH_RECORD, - 27689, - "Maille trop petite", + gearInfractions = + listOf( + GearInfraction( + InfractionType.WITH_RECORD, + 27689, + "Maille trop petite", + ), ), - ), hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, isAdministrativeControl = true, @@ -239,27 +241,30 @@ class MissionActionsControllerITests { missionId = 2, vesselId = 2, actionType = MissionActionType.SEA_CONTROL, - logbookInfractions = listOf( - LogbookInfraction( - InfractionType.WITH_RECORD, - 27689, - "Poids à bord MNZ supérieur de 50% au poids déclaré", + logbookInfractions = + listOf( + LogbookInfraction( + InfractionType.WITH_RECORD, + 27689, + "Poids à bord MNZ supérieur de 50% au poids déclaré", + ), ), - ), faoAreas = listOf("25.6.9", "25.7.9"), - segments = listOf( - FleetSegment( - segment = "WWSS10", - segmentName = "World Wide Segment", + segments = + listOf( + FleetSegment( + segment = "WWSS10", + segmentName = "World Wide Segment", + ), ), - ), - gearInfractions = listOf( - GearInfraction( - InfractionType.WITH_RECORD, - 27689, - "Maille trop petite", + gearInfractions = + listOf( + GearInfraction( + InfractionType.WITH_RECORD, + 27689, + "Maille trop petite", + ), ), - ), gearOnboard = listOf(gearControl), hasSomeGearsSeized = false, hasSomeSpeciesSeized = false, @@ -349,39 +354,42 @@ class MissionActionsControllerITests { // Given given(getActivityReports.execute(any(), any(), any())).willReturn( ActivityReports( - activityReports = listOf( - ActivityReport( - action = MissionAction( - 1, - 1, - 1, - actionType = MissionActionType.SEA_CONTROL, - actionDatetimeUtc = ZonedDateTime.now(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = true, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, - ), - activityCode = ActivityCode.FIS, - vesselNationalIdentifier = "AYFR000654", - controlUnits = listOf(ControlUnit(1234, "DIRM", false, "Cross Etel", listOf())), - faoArea = "27.7.c", - segment = "NS01/03", - vessel = Vessel( - id = 1, - internalReferenceNumber = "FR00022680", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - districtCode = "AY", - hasLogbookEsacapt = false, + activityReports = + listOf( + ActivityReport( + action = + MissionAction( + 1, + 1, + 1, + actionType = MissionActionType.SEA_CONTROL, + actionDatetimeUtc = ZonedDateTime.now(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = true, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), + activityCode = ActivityCode.FIS, + vesselNationalIdentifier = "AYFR000654", + controlUnits = listOf(ControlUnit(1234, "DIRM", false, "Cross Etel", listOf())), + faoArea = "27.7.c", + segment = "NS01/03", + vessel = + Vessel( + id = 1, + internalReferenceNumber = "FR00022680", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + districtCode = "AY", + hasLogbookEsacapt = false, + ), ), ), - ), jdpSpecies = listOf("BSS", "MAK", "LTH"), ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt index 3c5dd459d3..cf91781da8 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/MissionsControllerITests.kt @@ -34,7 +34,6 @@ import java.time.ZonedDateTime @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(MissionController::class)]) class MissionsControllerITests { - @Autowired private lateinit var api: MockMvc @@ -61,31 +60,33 @@ class MissionsControllerITests { }.willReturn( listOf( MissionAndActions( - mission = Mission( - 123, - missionTypes = listOf(MissionType.SEA), - missionSource = MissionSource.MONITORFISH, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - actions = listOf( - MissionAction( - id = 3, - vesselId = 1, - missionId = 123, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - flagState = CountryCode.FR, - userTrigram = "LTH", - completion = Completion.TO_COMPLETE, + mission = + Mission( + 123, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + actions = + listOf( + MissionAction( + id = 3, + vesselId = 1, + missionId = 123, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + flagState = CountryCode.FR, + userTrigram = "LTH", + completion = Completion.TO_COMPLETE, + ), ), - ), ), ), ) @@ -132,31 +133,33 @@ class MissionsControllerITests { getMission.execute(any()) }.willReturn( MissionAndActions( - mission = Mission( - 123, - missionTypes = listOf(MissionType.SEA), - missionSource = MissionSource.MONITORFISH, - isGeometryComputedFromControls = false, - startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ), - actions = listOf( - MissionAction( - id = 3, - vesselId = 1, - missionId = 123, - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - seizureAndDiversion = false, - speciesInfractions = listOf(), - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - flagState = CountryCode.FR, - userTrigram = "LTH", + mission = + Mission( + 123, + missionTypes = listOf(MissionType.SEA), + missionSource = MissionSource.MONITORFISH, + isGeometryComputedFromControls = false, + startDateTimeUtc = ZonedDateTime.of(2020, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ), + actions = + listOf( + MissionAction( + id = 3, + vesselId = 1, + missionId = 123, + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + seizureAndDiversion = false, + speciesInfractions = listOf(), + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + flagState = CountryCode.FR, + userTrigram = "LTH", + ), ), - ), ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PendingAlertControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PendingAlertControllerITests.kt index 6642e79c4a..f9ae15d4e3 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PendingAlertControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PendingAlertControllerITests.kt @@ -33,7 +33,6 @@ import java.time.ZonedDateTime @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(PendingAlertController::class)]) class PendingAlertControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PortControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PortControllerITests.kt index 3e36a3d9cc..ab59cedf33 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PortControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PortControllerITests.kt @@ -20,7 +20,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(PortController::class)]) class PortControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PriorNotificationControllerUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PriorNotificationControllerUTests.kt index f789690322..16183538fb 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PriorNotificationControllerUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PriorNotificationControllerUTests.kt @@ -119,12 +119,13 @@ class PriorNotificationControllerUTests { .willReturn(fakePriorNotification) // When - val requestBody = objectMapper.writeValueAsString( - LogbookPriorNotificationFormDataInput( - authorTrigram = "ABC", - note = "Test !", - ), - ) + val requestBody = + objectMapper.writeValueAsString( + LogbookPriorNotificationFormDataInput( + authorTrigram = "ABC", + note = "Test !", + ), + ) val pnoValue = fakePriorNotification.logbookMessageAndValue.value api.perform( put( @@ -154,15 +155,16 @@ class PriorNotificationControllerUTests { ) // When - val requestBody = objectMapper.writeValueAsString( - ManualPriorNotificationComputeDataInput( - globalFaoArea = "FAO AREA 51", - fishingCatches = emptyList(), - portLocode = "FRABC", - tripGearCodes = emptyList(), - vesselId = 42, - ), - ) + val requestBody = + objectMapper.writeValueAsString( + ManualPriorNotificationComputeDataInput( + globalFaoArea = "FAO AREA 51", + fishingCatches = emptyList(), + portLocode = "FRABC", + tripGearCodes = emptyList(), + vesselId = 42, + ), + ) api.perform( post("/bff/v1/prior_notifications/manual/compute") .contentType(MediaType.APPLICATION_JSON) @@ -201,24 +203,25 @@ class PriorNotificationControllerUTests { .willReturn(fakePriorNotification) // When - val requestBody = objectMapper.writeValueAsString( - ManualPriorNotificationFormDataInput( - hasPortEntranceAuthorization = true, - hasPortLandingAuthorization = true, - authorTrigram = "ABC", - didNotFishAfterZeroNotice = false, - expectedArrivalDate = ZonedDateTime.now(), - expectedLandingDate = ZonedDateTime.now(), - globalFaoArea = "FAO AREA 51", - fishingCatches = emptyList(), - note = null, - portLocode = "FRABVC", - sentAt = ZonedDateTime.now(), - purpose = LogbookMessagePurpose.LAN, - tripGearCodes = emptyList(), - vesselId = 42, - ), - ) + val requestBody = + objectMapper.writeValueAsString( + ManualPriorNotificationFormDataInput( + hasPortEntranceAuthorization = true, + hasPortLandingAuthorization = true, + authorTrigram = "ABC", + didNotFishAfterZeroNotice = false, + expectedArrivalDate = ZonedDateTime.now(), + expectedLandingDate = ZonedDateTime.now(), + globalFaoArea = "FAO AREA 51", + fishingCatches = emptyList(), + note = null, + portLocode = "FRABVC", + sentAt = ZonedDateTime.now(), + purpose = LogbookMessagePurpose.LAN, + tripGearCodes = emptyList(), + vesselId = 42, + ), + ) api.perform( post("/bff/v1/prior_notifications/manual") .contentType(MediaType.APPLICATION_JSON) @@ -257,24 +260,25 @@ class PriorNotificationControllerUTests { .willReturn(fakePriorNotification) // When - val requestBody = objectMapper.writeValueAsString( - ManualPriorNotificationFormDataInput( - hasPortEntranceAuthorization = true, - hasPortLandingAuthorization = true, - authorTrigram = "ABC", - didNotFishAfterZeroNotice = false, - expectedArrivalDate = ZonedDateTime.now(), - expectedLandingDate = ZonedDateTime.now(), - globalFaoArea = "FAO AREA 51", - fishingCatches = emptyList(), - note = null, - portLocode = "FRABVC", - sentAt = ZonedDateTime.now(), - purpose = LogbookMessagePurpose.LAN, - tripGearCodes = emptyList(), - vesselId = 42, - ), - ) + val requestBody = + objectMapper.writeValueAsString( + ManualPriorNotificationFormDataInput( + hasPortEntranceAuthorization = true, + hasPortLandingAuthorization = true, + authorTrigram = "ABC", + didNotFishAfterZeroNotice = false, + expectedArrivalDate = ZonedDateTime.now(), + expectedLandingDate = ZonedDateTime.now(), + globalFaoArea = "FAO AREA 51", + fishingCatches = emptyList(), + note = null, + portLocode = "FRABVC", + sentAt = ZonedDateTime.now(), + purpose = LogbookMessagePurpose.LAN, + tripGearCodes = emptyList(), + vesselId = 42, + ), + ) api.perform( put("/bff/v1/prior_notifications/manual/${fakePriorNotification.reportId!!}") .contentType(MediaType.APPLICATION_JSON) @@ -344,7 +348,8 @@ class PriorNotificationControllerUTests { @Test fun `getPdf Should get the PDF of a prior notification`() { - val dummyPdfContent = """ + val dummyPdfContent = + """ %PDF-1.4 1 0 obj << /Type /Catalog /Pages 2 0 R >> @@ -377,7 +382,7 @@ class PriorNotificationControllerUTests { startxref 291 %%EOF - """.trimIndent().toByteArray() + """.trimIndent().toByteArray() // Given given(getPriorNotificationPdfDocument.execute("REPORT_ID", false)) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ReportingControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ReportingControllerITests.kt index 8afe62769c..3d385b4f3a 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ReportingControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/ReportingControllerITests.kt @@ -35,7 +35,6 @@ import java.time.ZonedDateTime @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [ReportingController::class]) class ReportingControllerITests { - @Autowired private lateinit var api: MockMvc @@ -114,23 +113,25 @@ class ReportingControllerITests { @Test fun `Should create a reporting`() { // Given - val reporting = Reporting( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ), - type = ReportingType.INFRACTION_SUSPICION, - isDeleted = false, - isArchived = false, - ) + val reporting = + Reporting( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), + type = ReportingType.INFRACTION_SUSPICION, + isDeleted = false, + isArchived = false, + ) given(addReporting.execute(any())).willReturn(Pair(reporting, null)) // When @@ -145,12 +146,13 @@ class ReportingControllerITests { vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, flagState = CountryCode.FR, creationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ), + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), type = ReportingType.INFRACTION_SUSPICION, ), ), @@ -170,24 +172,26 @@ class ReportingControllerITests { @Test fun `Should create a reporting And return an augmented payload with the control unit object When a control unit id is given`() { // Given - val reporting = Reporting( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - ReportingActor.UNIT, - natinfCode = 123456, - controlUnitId = 1234, - authorTrigram = "LTH", - title = "A title", - ), - type = ReportingType.INFRACTION_SUSPICION, - isDeleted = false, - isArchived = false, - ) + val reporting = + Reporting( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + value = + InfractionSuspicion( + ReportingActor.UNIT, + natinfCode = 123456, + controlUnitId = 1234, + authorTrigram = "LTH", + title = "A title", + ), + type = ReportingType.INFRACTION_SUSPICION, + isDeleted = false, + isArchived = false, + ) given(addReporting.execute(any())).willReturn( Pair(reporting, ControlUnit(1234, "DIRM", false, "Cross Etel", listOf())), ) @@ -204,13 +208,14 @@ class ReportingControllerITests { vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, flagState = CountryCode.FR, creationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - controlUnitId = 1234, - authorTrigram = "LTH", - title = "A title", - ), + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + controlUnitId = 1234, + authorTrigram = "LTH", + title = "A title", + ), type = ReportingType.INFRACTION_SUSPICION, ), ), @@ -232,24 +237,26 @@ class ReportingControllerITests { @Test fun `Should get all current reportings`() { // Given - val reporting = Reporting( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ), - type = ReportingType.INFRACTION_SUSPICION, - isDeleted = false, - isArchived = false, - underCharter = true, - ) + val reporting = + Reporting( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), + type = ReportingType.INFRACTION_SUSPICION, + isDeleted = false, + isArchived = false, + underCharter = true, + ) given(getAllCurrentReportings.execute()).willReturn( listOf(Pair(reporting, null)), ) @@ -268,24 +275,26 @@ class ReportingControllerITests { @Test fun `Should update a reporting`() { // Given - val reporting = Reporting( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ), - type = ReportingType.INFRACTION_SUSPICION, - isDeleted = false, - isArchived = false, - underCharter = true, - ) + val reporting = + Reporting( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), + type = ReportingType.INFRACTION_SUSPICION, + isDeleted = false, + isArchived = false, + underCharter = true, + ) given(updateReporting.execute(any(), any())).willReturn(Pair(reporting, null)) // When @@ -313,22 +322,24 @@ class ReportingControllerITests { @Test fun `Should create a reporting When no vesselIdentifier given`() { // Given - val reporting = Reporting( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - flagState = CountryCode.FR, - ircs = "6554fEE", - creationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ), - type = ReportingType.INFRACTION_SUSPICION, - isDeleted = false, - isArchived = false, - ) + val reporting = + Reporting( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + flagState = CountryCode.FR, + ircs = "6554fEE", + creationDate = ZonedDateTime.now(), + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), + type = ReportingType.INFRACTION_SUSPICION, + isDeleted = false, + isArchived = false, + ) given(addReporting.execute(any())).willReturn(Pair(reporting, null)) // When @@ -342,12 +353,13 @@ class ReportingControllerITests { flagState = CountryCode.FR, ircs = "6554fEE", creationDate = ZonedDateTime.now(), - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ), + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), type = ReportingType.INFRACTION_SUSPICION, ), ), diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt index bd0f232195..634a1d8c39 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/VesselControllerITests.kt @@ -47,7 +47,6 @@ import java.time.ZonedDateTime @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(VesselController::class)]) class VesselControllerITests { - @Autowired private lateinit var api: MockMvc @@ -110,9 +109,10 @@ class VesselControllerITests { speed = 1.8, course = 180.0, dateTime = farPastFixedDateTime, vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - gearOnboard = listOf( - gear, - ), + gearOnboard = + listOf( + gear, + ), ) given(this.getLastPositions.execute()).willReturn(listOf(position)) @@ -142,85 +142,93 @@ class VesselControllerITests { } private fun givenSuspended(block: suspend () -> T) = given(runBlocking { block() })!! + private infix fun BDDMockito.BDDMyOngoingStubbing.willReturn(block: () -> T) = willReturn(block()) @Test fun `Should get vessels with last positions and risk factor`() { // Given val now = ZonedDateTime.now().minusDays(1) - val firstPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 4, - ), - ) - val secondPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 3, - ), - ) - val thirdPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 2, - ), - ) + val firstPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 4, + ), + ) + val secondPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 3, + ), + ) + val thirdPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 2, + ), + ) givenSuspended { getVessel.execute(eq(123), any(), any(), any(), any(), any(), eq(null), eq(null)) } willReturn { Pair( false, VesselInformation( - vessel = Vessel( - id = 123, - internalReferenceNumber = "FR224226850", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - underCharter = true, - hasLogbookEsacapt = false, - ), + vessel = + Vessel( + id = 123, + internalReferenceNumber = "FR224226850", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + underCharter = true, + hasLogbookEsacapt = false, + ), beacon = null, positions = listOf(firstPosition, secondPosition, thirdPosition), vesselRiskFactor = VesselRiskFactor(2.3, 2.0, 1.9, 3.2), @@ -330,63 +338,69 @@ class VesselControllerITests { fun `Should get vessels positions`() { // Given val now = ZonedDateTime.now().minusDays(1) - val firstPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 4, - ), - ) - val secondPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 3, - ), - ) - val thirdPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - latitude = 16.445, - longitude = 48.2525, - speed = 1.8, - course = 180.0, - dateTime = now.minusHours( - 2, - ), - ) + val firstPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 4, + ), + ) + val secondPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 3, + ), + ) + val thirdPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + latitude = 16.445, + longitude = 48.2525, + speed = 1.8, + course = 180.0, + dateTime = + now.minusHours( + 2, + ), + ) givenSuspended { getVesselPositions.execute(any(), any(), any(), any(), any(), eq(null), eq(null)) } willReturn { @@ -422,27 +436,29 @@ class VesselControllerITests { given(this.searchVessels.execute(any())).willReturn( listOf( VesselAndBeacon( - vessel = Vessel( - id = 1, - internalReferenceNumber = "FR224226850", - vesselName = "MY AWESOME VESSEL", - flagState = CountryCode.FR, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - hasLogbookEsacapt = false, - ), + vessel = + Vessel( + id = 1, + internalReferenceNumber = "FR224226850", + vesselName = "MY AWESOME VESSEL", + flagState = CountryCode.FR, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + hasLogbookEsacapt = false, + ), beacon = Beacon(beaconNumber = "123456", vesselId = 1), ), VesselAndBeacon( - vessel = Vessel( - id = 2, - internalReferenceNumber = "GBR21555445", - vesselName = "ANOTHER VESSEL", - flagState = CountryCode.GB, - declaredFishingGears = listOf("Trémails"), - vesselType = "Fishing", - hasLogbookEsacapt = false, - ), + vessel = + Vessel( + id = 2, + internalReferenceNumber = "GBR21555445", + vesselName = "ANOTHER VESSEL", + flagState = CountryCode.GB, + declaredFishingGears = listOf("Trémails"), + vesselType = "Fishing", + hasLogbookEsacapt = false, + ), beacon = null, ), ), @@ -467,14 +483,15 @@ class VesselControllerITests { @Test fun `Should find the last logbook messages of vessels`() { // Given - val voyage = Voyage( - isLastVoyage = true, - isFirstVoyage = false, - startDate = ZonedDateTime.parse("2021-01-21T10:21:26.617301+01:00"), - endDate = null, - tripNumber = "1234", - logbookMessagesAndAlerts = LogbookMessagesAndAlerts(TestUtils.getDummyLogbookMessages(), listOf()), - ) + val voyage = + Voyage( + isLastVoyage = true, + isFirstVoyage = false, + startDate = ZonedDateTime.parse("2021-01-21T10:21:26.617301+01:00"), + endDate = null, + tripNumber = "1234", + logbookMessagesAndAlerts = LogbookMessagesAndAlerts(TestUtils.getDummyLogbookMessages(), listOf()), + ) given(this.getVesselVoyage.execute(any(), any(), anyOrNull())).willReturn(voyage) // When @@ -512,14 +529,15 @@ class VesselControllerITests { @Test fun `Should find the logbook messages of vessels before a specified date`() { // Given - val voyage = Voyage( - isLastVoyage = true, - isFirstVoyage = false, - startDate = ZonedDateTime.now().minusMonths(5), - endDate = null, - tripNumber = "1234", - logbookMessagesAndAlerts = LogbookMessagesAndAlerts(TestUtils.getDummyLogbookMessages(), listOf()), - ) + val voyage = + Voyage( + isLastVoyage = true, + isFirstVoyage = false, + startDate = ZonedDateTime.now().minusMonths(5), + endDate = null, + tripNumber = "1234", + logbookMessagesAndAlerts = LogbookMessagesAndAlerts(TestUtils.getDummyLogbookMessages(), listOf()), + ) given(this.getVesselVoyage.execute(any(), any(), any())).willReturn(voyage) // When @@ -549,76 +567,84 @@ class VesselControllerITests { .willReturn( VesselBeaconMalfunctionsResumeAndHistory( resume = VesselBeaconMalfunctionsResume(1, 2, null, null), - history = listOf( - BeaconMalfunctionWithDetails( - beaconMalfunction = BeaconMalfunction( - id = 1, - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - flagState = "fr", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - vesselName = "BIDUBULE", - vesselStatus = VesselStatus.AT_SEA, - stage = Stage.ARCHIVED, - malfunctionStartDateTime = ZonedDateTime.now(), - malfunctionEndDateTime = null, - vesselStatusLastModificationDateTime = ZonedDateTime.now(), endOfBeaconMalfunctionReason = EndOfBeaconMalfunctionReason.RESUMED_TRANSMISSION, - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, + history = + listOf( + BeaconMalfunctionWithDetails( + beaconMalfunction = + BeaconMalfunction( + id = 1, + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + flagState = "fr", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + vesselName = "BIDUBULE", + vesselStatus = VesselStatus.AT_SEA, + stage = Stage.ARCHIVED, + malfunctionStartDateTime = ZonedDateTime.now(), + malfunctionEndDateTime = null, + vesselStatusLastModificationDateTime = ZonedDateTime.now(), endOfBeaconMalfunctionReason = EndOfBeaconMalfunctionReason.RESUMED_TRANSMISSION, + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, + ), + comments = + listOf( + BeaconMalfunctionComment( + beaconMalfunctionId = 1, + comment = "A comment", + userType = BeaconMalfunctionCommentUserType.SIP, + dateTime = now, + ), + ), + actions = + listOf( + BeaconMalfunctionAction( + beaconMalfunctionId = 1, + propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + nextValue = "A VALUE", + previousValue = "A VALUE", + dateTime = now, + ), + ), ), - comments = listOf( - BeaconMalfunctionComment( - beaconMalfunctionId = 1, - comment = "A comment", - userType = BeaconMalfunctionCommentUserType.SIP, - dateTime = now, + ), + current = + BeaconMalfunctionWithDetails( + beaconMalfunction = + BeaconMalfunction( + id = 2, + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + flagState = "fr", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + vesselName = "BIDUBULE", + vesselStatus = VesselStatus.AT_SEA, + stage = Stage.INITIAL_ENCOUNTER, + malfunctionStartDateTime = ZonedDateTime.now(), + malfunctionEndDateTime = null, + vesselStatusLastModificationDateTime = ZonedDateTime.now(), + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, ), - ), - actions = listOf( - BeaconMalfunctionAction( - beaconMalfunctionId = 1, - propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - nextValue = "A VALUE", - previousValue = "A VALUE", - dateTime = now, + comments = + listOf( + BeaconMalfunctionComment( + beaconMalfunctionId = 1, + comment = "A comment", + userType = BeaconMalfunctionCommentUserType.SIP, + dateTime = now, + ), + ), + actions = + listOf( + BeaconMalfunctionAction( + beaconMalfunctionId = 1, + propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + nextValue = "A VALUE", + previousValue = "A VALUE", + dateTime = now, + ), ), - ), - ), - ), - current = BeaconMalfunctionWithDetails( - beaconMalfunction = BeaconMalfunction( - id = 2, - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - flagState = "fr", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - vesselName = "BIDUBULE", - vesselStatus = VesselStatus.AT_SEA, - stage = Stage.INITIAL_ENCOUNTER, - malfunctionStartDateTime = ZonedDateTime.now(), - malfunctionEndDateTime = null, - vesselStatusLastModificationDateTime = ZonedDateTime.now(), - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - beaconMalfunctionId = 1, - comment = "A comment", - userType = BeaconMalfunctionCommentUserType.SIP, - dateTime = now, - ), - ), - actions = listOf( - BeaconMalfunctionAction( - beaconMalfunctionId = 1, - propertyName = BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - nextValue = "A VALUE", - previousValue = "A VALUE", - dateTime = now, - ), ), - ), ), ) @@ -655,41 +681,44 @@ class VesselControllerITests { @Test fun `Should get vessel's reporting`() { // Given - val currentReporting = Reporting( - id = 1, - type = ReportingType.ALERT, - vesselName = "BIDUBULE", - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now(), - validationDate = ZonedDateTime.now(), - value = ThreeMilesTrawlingAlert() as ReportingValue, - isArchived = false, - isDeleted = false, - infraction = Infraction( - natinfCode = 7059, - infractionCategory = InfractionCategory.FISHING, - ), - ) + val currentReporting = + Reporting( + id = 1, + type = ReportingType.ALERT, + vesselName = "BIDUBULE", + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now(), + validationDate = ZonedDateTime.now(), + value = ThreeMilesTrawlingAlert() as ReportingValue, + isArchived = false, + isDeleted = false, + infraction = + Infraction( + natinfCode = 7059, + infractionCategory = InfractionCategory.FISHING, + ), + ) - val archivedReporting = Reporting( - id = 666, - type = ReportingType.ALERT, - vesselName = "BIDUBULE", - internalReferenceNumber = "FR224226850", - externalReferenceNumber = "1236514", - ircs = "IRCS", - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - creationDate = ZonedDateTime.now().minusYears(1), - validationDate = ZonedDateTime.now().minusYears(1), - value = ThreeMilesTrawlingAlert() as ReportingValue, - isArchived = true, - isDeleted = false, - ) + val archivedReporting = + Reporting( + id = 666, + type = ReportingType.ALERT, + vesselName = "BIDUBULE", + internalReferenceNumber = "FR224226850", + externalReferenceNumber = "1236514", + ircs = "IRCS", + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + creationDate = ZonedDateTime.now().minusYears(1), + validationDate = ZonedDateTime.now().minusYears(1), + value = ThreeMilesTrawlingAlert() as ReportingValue, + isArchived = true, + isDeleted = false, + ) given( this.getVesselReportings.execute( @@ -703,30 +732,33 @@ class VesselControllerITests { ) .willReturn( CurrentAndArchivedReportings( - current = listOf( - ReportingAndOccurrences( - otherOccurrencesOfSameAlert = listOf(), - reporting = currentReporting, - controlUnit = null, - ), - ReportingAndOccurrences( - otherOccurrencesOfSameAlert = listOf(), - reporting = currentReporting, - controlUnit = null, - ), - ), - archived = mapOf( - 2024 to listOf( + current = + listOf( + ReportingAndOccurrences( + otherOccurrencesOfSameAlert = listOf(), + reporting = currentReporting, + controlUnit = null, + ), ReportingAndOccurrences( otherOccurrencesOfSameAlert = listOf(), - reporting = archivedReporting, + reporting = currentReporting, controlUnit = null, ), ), - 2023 to emptyList(), - 2022 to emptyList(), - 2021 to emptyList(), - ), + archived = + mapOf( + 2024 to + listOf( + ReportingAndOccurrences( + otherOccurrencesOfSameAlert = listOf(), + reporting = archivedReporting, + controlUnit = null, + ), + ), + 2023 to emptyList(), + 2022 to emptyList(), + 2021 to emptyList(), + ), ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/VesselLightControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/VesselLightControllerITests.kt index ccbeb6bdcb..c87cb55eb4 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/VesselLightControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/light/VesselLightControllerITests.kt @@ -43,7 +43,6 @@ import java.time.ZonedDateTime @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(VesselLightController::class)]) class VesselLightControllerITests { - @Autowired private lateinit var api: MockMvc @@ -110,72 +109,79 @@ class VesselLightControllerITests { } private fun givenSuspended(block: suspend () -> T) = given(runBlocking { block() })!! + private infix fun BDDMockito.BDDMyOngoingStubbing.willReturn(block: () -> T) = willReturn(block()) @Test fun `Should get vessels with last positions`() { // Given val now = ZonedDateTime.now().minusDays(1) - val firstPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - isAtPort = false, - dateTime = now.minusHours( - 4, - ), - ) - val secondPosition = Position( - id = null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - isAtPort = false, - dateTime = now.minusHours( - 3, - ), - ) - val thirdPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - isAtPort = false, - dateTime = now.minusHours( - 2, - ), - ) + val firstPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + isAtPort = false, + dateTime = + now.minusHours( + 4, + ), + ) + val secondPosition = + Position( + id = null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + isAtPort = false, + dateTime = + now.minusHours( + 3, + ), + ) + val thirdPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + isAtPort = false, + dateTime = + now.minusHours( + 2, + ), + ) givenSuspended { getVessel.execute(eq(123), any(), any(), any(), any(), any(), eq(null), eq(null)) } willReturn { @@ -233,14 +239,15 @@ class VesselLightControllerITests { @Test fun `Should find the last logbook messages of vessels`() { // Given - val voyage = Voyage( - isLastVoyage = true, - isFirstVoyage = false, - startDate = ZonedDateTime.parse("2021-01-21T10:21:26.617301+01:00"), - endDate = null, - tripNumber = "1234", - logbookMessagesAndAlerts = LogbookMessagesAndAlerts(TestUtils.getDummyLogbookMessages(), listOf()), - ) + val voyage = + Voyage( + isLastVoyage = true, + isFirstVoyage = false, + startDate = ZonedDateTime.parse("2021-01-21T10:21:26.617301+01:00"), + endDate = null, + tripNumber = "1234", + logbookMessagesAndAlerts = LogbookMessagesAndAlerts(TestUtils.getDummyLogbookMessages(), listOf()), + ) given(this.getVesselVoyage.execute(any(), any(), anyOrNull())).willReturn(voyage) // When diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/HealthcheckControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/HealthcheckControllerITests.kt index dc8cb9b65b..2f0a0548f1 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/HealthcheckControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/HealthcheckControllerITests.kt @@ -21,7 +21,6 @@ import java.time.ZonedDateTime @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(HealthcheckController::class)]) class HealthcheckControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt index a78e54e40c..9c9cc58d66 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/InfractionControllerITests.kt @@ -21,7 +21,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(InfractionController::class)]) class InfractionControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PositionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PositionsControllerITests.kt index 24b379653b..191724a0f3 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PositionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PositionsControllerITests.kt @@ -20,7 +20,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(PositionsController::class)]) class PositionsControllerITests { - @Autowired private lateinit var api: MockMvc @@ -33,10 +32,11 @@ class PositionsControllerITests { given(parseAndSavePosition.execute(anyString())).willAnswer { throw NAFMessageParsingException("ARGH", "NAF") } // When - val body = api.perform(post("/api/v1/positions").content("TEST")) - // Then - .andExpect(status().isOk) - .andReturn().response.contentAsString + val body = + api.perform(post("/api/v1/positions").content("TEST")) + // Then + .andExpect(status().isOk) + .andReturn().response.contentAsString assertThat(body).contains("ARGH for NAF message") } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicBeaconMalfunctionControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicBeaconMalfunctionControllerITests.kt index d6f197f353..f06a78f97d 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicBeaconMalfunctionControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicBeaconMalfunctionControllerITests.kt @@ -30,7 +30,6 @@ import java.time.ZonedDateTime @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(PublicBeaconMalfunctionController::class)]) class PublicBeaconMalfunctionControllerITests { - @Autowired private lateinit var api: MockMvc @@ -48,31 +47,34 @@ class PublicBeaconMalfunctionControllerITests { given(this.updateBeaconMalfunction.execute(123, VesselStatus.AT_SEA, null, null)) .willReturn( BeaconMalfunctionResumeAndDetails( - beaconMalfunction = BeaconMalfunction( - 1, "CFR", "EXTERNAL_IMMAT", "IRCS", - "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, - ZonedDateTime.now(), null, ZonedDateTime.now(), - beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, - ), - comments = listOf( - BeaconMalfunctionComment( - 1, - 1, - "A comment", - BeaconMalfunctionCommentUserType.SIP, - ZonedDateTime.now(), + beaconMalfunction = + BeaconMalfunction( + 1, "CFR", "EXTERNAL_IMMAT", "IRCS", + "fr", VesselIdentifier.INTERNAL_REFERENCE_NUMBER, "BIDUBULE", VesselStatus.AT_SEA, Stage.INITIAL_ENCOUNTER, + ZonedDateTime.now(), null, ZonedDateTime.now(), + beaconNumber = "123465", beaconStatusAtMalfunctionCreation = BeaconStatus.ACTIVATED, vesselId = 123, ), - ), - actions = listOf( - BeaconMalfunctionAction( - 1, - 1, - BeaconMalfunctionActionPropertyName.VESSEL_STATUS, - "PREVIOUS", - "NEXT", - ZonedDateTime.now(), + comments = + listOf( + BeaconMalfunctionComment( + 1, + 1, + "A comment", + BeaconMalfunctionCommentUserType.SIP, + ZonedDateTime.now(), + ), + ), + actions = + listOf( + BeaconMalfunctionAction( + 1, + 1, + BeaconMalfunctionActionPropertyName.VESSEL_STATUS, + "PREVIOUS", + "NEXT", + ZonedDateTime.now(), + ), ), - ), ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt index d7b2e5dba9..81b5b71023 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicMissionActionsControllerITests.kt @@ -32,7 +32,6 @@ import java.time.ZonedDateTime @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(PublicMissionActionsController::class)]) class PublicMissionActionsControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPendingAlertControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPendingAlertControllerITests.kt index e914b7ad14..087248353a 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPendingAlertControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPendingAlertControllerITests.kt @@ -16,7 +16,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(PublicOperationalAlertController::class)]) class PublicPendingAlertControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicReportingControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicReportingControllerITests.kt index 78ec96ff74..8ca83ed9f4 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicReportingControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicReportingControllerITests.kt @@ -17,7 +17,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [PublicReportingController::class]) class PublicReportingControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/UserManagementControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/UserManagementControllerITests.kt index c0360f894d..accb7cb0f2 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/UserManagementControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/UserManagementControllerITests.kt @@ -21,7 +21,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(UserManagementController::class)]) class UserManagementControllerITests { - @Autowired private lateinit var api: MockMvc diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/ApiKeyCheckFilterUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/ApiKeyCheckFilterUTests.kt index f3cb768263..a64ec77a1c 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/ApiKeyCheckFilterUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/ApiKeyCheckFilterUTests.kt @@ -14,7 +14,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) class ApiKeyCheckFilterUTests { - @Test fun `Should return Ok When the token is right`() { // Given diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/TestUtils.kt index d691ba6a91..919c20c3d9 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/security/TestUtils.kt @@ -8,17 +8,19 @@ import io.ktor.utils.io.* class TestUtils { companion object { fun getMockApiClient(): ApiClient { - val mockEngine = MockEngine { _ -> - respond( - content = ByteReadChannel( - """{ + val mockEngine = + MockEngine { _ -> + respond( + content = + ByteReadChannel( + """{ "email": "email@domain-name.com" }""", - ), - status = HttpStatusCode.OK, - headers = headersOf(HttpHeaders.ContentType, "application/json"), - ) - } + ), + status = HttpStatusCode.OK, + headers = headersOf(HttpHeaders.ContentType, "application/json"), + ) + } return ApiClient(mockEngine) } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/AbstractDBTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/AbstractDBTests.kt index d90742a05a..693f6399b9 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/AbstractDBTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/AbstractDBTests.kt @@ -28,18 +28,19 @@ abstract class AbstractDBTests { companion object { @JvmStatic - val container = GenericContainer("ghcr.io/mtes-mct/monitorfish/monitorfish-database:pg16-ts2.14.2-postgis3.4.2") - .apply { - withExposedPorts(5432) - withEnv("POSTGRES_DB", "testdb") - withEnv("POSTGRES_USER", "postgres") - withEnv("POSTGRES_PASSWORD", "postgres") - waitingFor( - Wait.forLogMessage(".*ready to accept connections.*\\s", 2), - ) - withStartupTimeout(Duration.of(60L, ChronoUnit.SECONDS)) - this.start() - } + val container = + GenericContainer("ghcr.io/mtes-mct/monitorfish/monitorfish-database:pg16-ts2.14.2-postgis3.4.2") + .apply { + withExposedPorts(5432) + withEnv("POSTGRES_DB", "testdb") + withEnv("POSTGRES_USER", "postgres") + withEnv("POSTGRES_PASSWORD", "postgres") + waitingFor( + Wait.forLogMessage(".*ready to accept connections.*\\s", 2), + ) + withStartupTimeout(Duration.of(60L, ChronoUnit.SECONDS)) + this.start() + } @JvmStatic @DynamicPropertySource @@ -51,9 +52,10 @@ abstract class AbstractDBTests { val toStringConsumer = ToStringConsumer() container.followOutput(toStringConsumer, OutputFrame.OutputType.STDOUT) - return "jdbc:postgresql://" + container.host + ":" + container.getMappedPort( - PostgreSQLContainer.POSTGRESQL_PORT, - ).toString() + "/testdb?user=postgres&password=postgres" + return "jdbc:postgresql://" + container.host + ":" + + container.getMappedPort( + PostgreSQLContainer.POSTGRESQL_PORT, + ).toString() + "/testdb?user=postgres&password=postgres" } } } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionActionsRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionActionsRepositoryITests.kt index 8157fa0311..0ec5d5e4ee 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionActionsRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionActionsRepositoryITests.kt @@ -10,7 +10,6 @@ import org.springframework.transaction.annotation.Transactional import java.time.ZonedDateTime class JpaBeaconMalfunctionActionsRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaBeaconMalfunctionActionsRepository: JpaBeaconMalfunctionActionsRepository @@ -36,14 +35,15 @@ class JpaBeaconMalfunctionActionsRepositoryITests : AbstractDBTests() { assertThat(jpaBeaconMalfunctionActionsRepository.findAllByBeaconMalfunctionId(1)).hasSize(1) // When - val action = BeaconMalfunctionAction( - null, - 1, - BeaconMalfunctionActionPropertyName.STAGE, - Stage.FOUR_HOUR_REPORT.toString(), - Stage.FOUR_HOUR_REPORT.toString(), - ZonedDateTime.now(), - ) + val action = + BeaconMalfunctionAction( + null, + 1, + BeaconMalfunctionActionPropertyName.STAGE, + Stage.FOUR_HOUR_REPORT.toString(), + Stage.FOUR_HOUR_REPORT.toString(), + ZonedDateTime.now(), + ) jpaBeaconMalfunctionActionsRepository.save(action) // Then diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionCommentsRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionCommentsRepositoryITests.kt index 090ff66daa..75d4927940 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionCommentsRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionCommentsRepositoryITests.kt @@ -9,7 +9,6 @@ import org.springframework.transaction.annotation.Transactional import java.time.ZonedDateTime class JpaBeaconMalfunctionCommentsRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaBeaconMalfunctionCommentsRepository: JpaBeaconMalfunctionCommentsRepository @@ -38,13 +37,14 @@ class JpaBeaconMalfunctionCommentsRepositoryITests : AbstractDBTests() { assertThat(jpaBeaconMalfunctionCommentsRepository.findAllByBeaconMalfunctionId(1)).hasSize(2) // When - val comment = BeaconMalfunctionComment( - null, - 1, - "A comment", - BeaconMalfunctionCommentUserType.SIP, - ZonedDateTime.now(), - ) + val comment = + BeaconMalfunctionComment( + null, + 1, + "A comment", + BeaconMalfunctionCommentUserType.SIP, + ZonedDateTime.now(), + ) jpaBeaconMalfunctionCommentsRepository.save(comment) // Then diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionNotificationsRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionNotificationsRepositoryITests.kt index 75e9e3526a..4d6a70b6f2 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionNotificationsRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionNotificationsRepositoryITests.kt @@ -9,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.transaction.annotation.Transactional class JpaBeaconMalfunctionNotificationsRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaBeaconMalfunctionNotificationsRepository: JpaBeaconMalfunctionNotificationsRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionsRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionsRepositoryITests.kt index 1ff9cb8d44..429891de66 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionsRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconMalfunctionsRepositoryITests.kt @@ -13,7 +13,6 @@ import java.time.ZonedDateTime import java.time.temporal.ChronoUnit class JpaBeaconMalfunctionsRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaBeaconMalfunctionsRepository: JpaBeaconMalfunctionsRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconRepositoryITests.kt index 0c312f0a80..71844e26cf 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaBeaconRepositoryITests.kt @@ -8,7 +8,6 @@ import org.springframework.cache.CacheManager import org.springframework.transaction.annotation.Transactional class JpaBeaconRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaBeaconRepository: JpaBeaconRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaDistrictRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaDistrictRepositoryITests.kt index 55a5a69ee5..01f7837959 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaDistrictRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaDistrictRepositoryITests.kt @@ -10,7 +10,6 @@ import org.springframework.cache.CacheManager import org.springframework.transaction.annotation.Transactional class JpaDistrictRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaDistrictRepository: JpaDistrictRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaFleetSegmentRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaFleetSegmentRepositoryITests.kt index e3c141887b..42b47245a3 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaFleetSegmentRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaFleetSegmentRepositoryITests.kt @@ -60,11 +60,12 @@ class JpaFleetSegmentRepositoryITests : AbstractDBTests() { assertThat(fleetSegments.first().segment).isEqualTo("ATL01") // When - val updatedFleetSegment = jpaFleetSegmentRepository.update( - "ATL01", - CreateOrUpdateFleetSegmentFields("NEXT_ATL01", "A segment name"), - currentYear, - ) + val updatedFleetSegment = + jpaFleetSegmentRepository.update( + "ATL01", + CreateOrUpdateFleetSegmentFields("NEXT_ATL01", "A segment name"), + currentYear, + ) // Then assertThat(updatedFleetSegment.segment).isEqualTo("NEXT_ATL01") @@ -82,11 +83,12 @@ class JpaFleetSegmentRepositoryITests : AbstractDBTests() { assertThat(fleetSegments.first().segmentName).isEqualTo("All Trawls 3") // When - val updatedFleetSegment = jpaFleetSegmentRepository.update( - "ATL01", - CreateOrUpdateFleetSegmentFields(segmentName = "All Trawls 666"), - currentYear, - ) + val updatedFleetSegment = + jpaFleetSegmentRepository.update( + "ATL01", + CreateOrUpdateFleetSegmentFields(segmentName = "All Trawls 666"), + currentYear, + ) // Then assertThat(updatedFleetSegment.segmentName).isEqualTo("All Trawls 666") @@ -106,11 +108,12 @@ class JpaFleetSegmentRepositoryITests : AbstractDBTests() { ) // When - val updatedFleetSegment = jpaFleetSegmentRepository.update( - "ATL01", - CreateOrUpdateFleetSegmentFields(gears = listOf("OTB", "DOF")), - currentYear, - ) + val updatedFleetSegment = + jpaFleetSegmentRepository.update( + "ATL01", + CreateOrUpdateFleetSegmentFields(gears = listOf("OTB", "DOF")), + currentYear, + ) // Then assertThat(updatedFleetSegment.segment).isEqualTo("ATL01") @@ -129,11 +132,12 @@ class JpaFleetSegmentRepositoryITests : AbstractDBTests() { assertThat(fleetSegments.first().faoAreas).isEqualTo(listOf("27.7", "27.8", "27.9", "27.10")) // When - val updatedFleetSegment = jpaFleetSegmentRepository.update( - "ATL01", - CreateOrUpdateFleetSegmentFields(faoAreas = listOf("66.6.6", "66.6.7")), - currentYear, - ) + val updatedFleetSegment = + jpaFleetSegmentRepository.update( + "ATL01", + CreateOrUpdateFleetSegmentFields(faoAreas = listOf("66.6.6", "66.6.7")), + currentYear, + ) // Then assertThat(updatedFleetSegment.segment).isEqualTo("ATL01") diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaForeignFMCRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaForeignFMCRepositoryITests.kt index e42c1d31a0..1cbc34bb09 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaForeignFMCRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaForeignFMCRepositoryITests.kt @@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.transaction.annotation.Transactional class JpaForeignFMCRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaForeignFMCRepository: JpaForeignFMCRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearRepositoryITests.kt index 524f366828..a157cf8e95 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaGearRepositoryITests.kt @@ -10,7 +10,6 @@ import org.springframework.cache.CacheManager import org.springframework.transaction.annotation.Transactional class JpaGearRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaGearRepository: JpaGearRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt index 05c45df805..8c14dc9c7e 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaInfractionRepositoryITests.kt @@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.transaction.annotation.Transactional class JpaInfractionRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaInfractionRepository: JpaInfractionRepository @@ -31,9 +30,10 @@ class JpaInfractionRepositoryITests : AbstractDBTests() { @Transactional fun `findInfractionByNatinfCode Should throw an exception When the natinf code is not found`() { // When - val throwable = catchThrowable { - jpaInfractionRepository.findInfractionByNatinfCode(666) - } + val throwable = + catchThrowable { + jpaInfractionRepository.findInfractionByNatinfCode(666) + } // Then assertThat(throwable.message).contains("NATINF code 666 not found") diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLastPositionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLastPositionRepositoryITests.kt index 8c23311914..98a5f0ed8e 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLastPositionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLastPositionRepositoryITests.kt @@ -11,7 +11,6 @@ import org.springframework.transaction.annotation.Transactional import java.time.ZonedDateTime class JpaLastPositionRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaLastPositionRepository: JpaLastPositionRepository @@ -29,9 +28,10 @@ class JpaLastPositionRepositoryITests : AbstractDBTests() { // Then val positions = jpaLastPositionRepository.findAll() - val position = positions.find { - it.internalReferenceNumber == "FAK000999999" - } + val position = + positions.find { + it.internalReferenceNumber == "FAK000999999" + } assertThat(position?.gearOnboard).hasSize(1) assertThat(position?.gearOnboard?.first()?.dimensions).isEqualTo("45.0") assertThat(position?.gearOnboard?.first()?.gear).isEqualTo("OTB") diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookReportRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookReportRepositoryITests.kt index 576dd806ed..cba717f6f7 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookReportRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaLogbookReportRepositoryITests.kt @@ -542,22 +542,24 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return PNO logbook reports from ESP & FRA vessels`() { // Given - val filter = PriorNotificationsFilter( - flagStates = listOf("ESP", "FRA"), - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val filter = + PriorNotificationsFilter( + flagStates = listOf("ESP", "FRA"), + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val result = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(filter) // Then assertThat(result).hasSizeGreaterThan(0) - val resultVessels = result.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val resultVessels = + result.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(resultVessels).hasSize(result.size) assertThat(resultVessels.all { listOf(CountryCode.ES, CountryCode.FR).contains(it.flagState) }).isTrue() } @@ -568,11 +570,12 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { val expectedLogbookReportIdsWithOneOrMoreReportings = listOf(102L, 104L) // Given - val firstFilter = PriorNotificationsFilter( - hasOneOrMoreReportings = true, - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val firstFilter = + PriorNotificationsFilter( + hasOneOrMoreReportings = true, + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val firstResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(firstFilter) @@ -586,11 +589,12 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { ).isTrue() // Given - val secondFilter = PriorNotificationsFilter( - hasOneOrMoreReportings = false, - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val secondFilter = + PriorNotificationsFilter( + hasOneOrMoreReportings = false, + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val secondResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(secondFilter) @@ -608,42 +612,46 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return PNO logbook reports for less or more than 12 meters long vessels`() { // Given - val firstFilter = PriorNotificationsFilter( - isLessThanTwelveMetersVessel = true, - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val firstFilter = + PriorNotificationsFilter( + isLessThanTwelveMetersVessel = true, + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val firstResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(firstFilter) // Then assertThat(firstResult).hasSizeGreaterThan(0) - val firstResultVessels = firstResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val firstResultVessels = + firstResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(firstResultVessels).hasSize(firstResult.size) assertThat(firstResultVessels.all { it.length!! < 12 }).isTrue() // Given - val secondFilter = PriorNotificationsFilter( - isLessThanTwelveMetersVessel = false, - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val secondFilter = + PriorNotificationsFilter( + isLessThanTwelveMetersVessel = false, + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val secondResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(secondFilter) // Then assertThat(secondResult).hasSizeGreaterThan(0) - val secondResultVessels = secondResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val secondResultVessels = + secondResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(secondResultVessels).hasSize(secondResult.size) assertThat(secondResultVessels.all { it.length!! >= 12 }).isTrue() } @@ -652,22 +660,24 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return PNO logbook reports for vessels controlled after or before January 1st, 2024`() { // Given - val firstFilter = PriorNotificationsFilter( - lastControlledAfter = "2024-01-01T00:00:00Z", - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val firstFilter = + PriorNotificationsFilter( + lastControlledAfter = "2024-01-01T00:00:00Z", + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val firstResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(firstFilter) // Then assertThat(firstResult).hasSizeGreaterThan(0) - val firstResultRiskFactors = firstResult.mapNotNull { - jpaRiskFactorRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val firstResultRiskFactors = + firstResult.mapNotNull { + jpaRiskFactorRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(firstResultRiskFactors).hasSize(firstResult.size) assertThat( firstResultRiskFactors.all { @@ -676,22 +686,24 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { ).isTrue() // Given - val secondFilter = PriorNotificationsFilter( - lastControlledBefore = "2024-01-01T00:00:00Z", - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val secondFilter = + PriorNotificationsFilter( + lastControlledBefore = "2024-01-01T00:00:00Z", + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val secondResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(secondFilter) // Then assertThat(secondResult).hasSizeGreaterThan(0) - val secondResultRiskFactors = secondResult.mapNotNull { - jpaRiskFactorRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val secondResultRiskFactors = + secondResult.mapNotNull { + jpaRiskFactorRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(secondResultRiskFactors).hasSize(secondResult.size) assertThat( secondResultRiskFactors.all { @@ -704,11 +716,12 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return PNO logbook reports for FRSML & FRVNE ports`() { // Given - val filter = PriorNotificationsFilter( - portLocodes = listOf("FRSML", "FRVNE"), - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val filter = + PriorNotificationsFilter( + portLocodes = listOf("FRSML", "FRVNE"), + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val result = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(filter) @@ -726,42 +739,46 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return PNO logbook reports When using a vessel name`() { // Given - val firstFilter = PriorNotificationsFilter( - searchQuery = "pheno", - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val firstFilter = + PriorNotificationsFilter( + searchQuery = "pheno", + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val firstResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(firstFilter) // Then assertThat(firstResult).hasSizeGreaterThan(0) - val firstResultVessels = firstResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val firstResultVessels = + firstResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(firstResultVessels).hasSize(firstResult.size) assertThat(firstResultVessels.all { it.vesselName == "PHENOMENE" }).isTrue() // Given - val secondFilter = PriorNotificationsFilter( - searchQuery = "hénO", - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val secondFilter = + PriorNotificationsFilter( + searchQuery = "hénO", + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val secondResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(secondFilter) // Then assertThat(secondResult).hasSizeGreaterThan(0) - val secondResultVessels = secondResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val secondResultVessels = + secondResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(secondResultVessels).hasSize(secondResult.size) assertThat(secondResultVessels.all { it.vesselName == "PHENOMENE" }).isTrue() } @@ -770,42 +787,46 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return PNO logbook reports When using a CFR`() { // Given - val firstFilter = PriorNotificationsFilter( - searchQuery = "FAK000999999", - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val firstFilter = + PriorNotificationsFilter( + searchQuery = "FAK000999999", + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val firstResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(firstFilter) // Then assertThat(firstResult).hasSizeGreaterThan(0) - val firstResultVessels = firstResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val firstResultVessels = + firstResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(firstResultVessels).hasSize(firstResult.size) assertThat(firstResultVessels.all { it.vesselName == "PHENOMENE" }).isTrue() // Given - val secondFilter = PriorNotificationsFilter( - searchQuery = "999999", - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val secondFilter = + PriorNotificationsFilter( + searchQuery = "999999", + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val secondResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(secondFilter) // Then assertThat(secondResult).hasSizeGreaterThan(0) - val secondResultVessels = secondResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val secondResultVessels = + secondResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(secondResultVessels).hasSize(secondResult.size) assertThat(secondResultVessels.all { it.vesselName == "PHENOMENE" }).isTrue() } @@ -814,11 +835,12 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return PNO logbook reports for COD & HKE species`() { // Given - val filter = PriorNotificationsFilter( - specyCodes = listOf("COD", "HKE"), - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val filter = + PriorNotificationsFilter( + specyCodes = listOf("COD", "HKE"), + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val result = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(filter) @@ -837,11 +859,12 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return PNO logbook reports for Préavis type A & Préavis type C types`() { // Given - val filter = PriorNotificationsFilter( - priorNotificationTypes = listOf("Préavis type A", "Préavis type C"), - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val filter = + PriorNotificationsFilter( + priorNotificationTypes = listOf("Préavis type A", "Préavis type C"), + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val result = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(filter) @@ -860,11 +883,12 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return PNO logbook reports for SWW06 & NWW03 segments`() { // Given - val filter = PriorNotificationsFilter( - tripSegmentCodes = listOf("SWW06", "NWW03"), - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val filter = + PriorNotificationsFilter( + tripSegmentCodes = listOf("SWW06", "NWW03"), + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val result = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(filter) @@ -887,11 +911,12 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return PNO logbook reports for OTT & TB gears`() { // Given - val filter = PriorNotificationsFilter( - tripGearCodes = listOf("OTT", "TB"), - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val filter = + PriorNotificationsFilter( + tripGearCodes = listOf("OTT", "TB"), + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val result = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(filter) @@ -910,10 +935,11 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return PNO logbook reports for vessels arriving after or before January 1st, 2024`() { // Given - val firstFilter = PriorNotificationsFilter( - willArriveAfter = "2024-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val firstFilter = + PriorNotificationsFilter( + willArriveAfter = "2024-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val firstResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(firstFilter) @@ -928,10 +954,11 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { ).isTrue() // Given - val secondFilter = PriorNotificationsFilter( - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2024-01-01T00:00:00Z", - ) + val secondFilter = + PriorNotificationsFilter( + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2024-01-01T00:00:00Z", + ) // When val secondResult = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(secondFilter) @@ -950,12 +977,13 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() { @Transactional fun `findAllPriorNotifications Should return the expected PNO logbook reports with multiple filters`() { // Given - val filter = PriorNotificationsFilter( - priorNotificationTypes = listOf("Préavis type A", "Préavis type C"), - tripGearCodes = listOf("OTT", "TB"), - willArriveAfter = "2024-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val filter = + PriorNotificationsFilter( + priorNotificationTypes = listOf("Préavis type A", "Préavis type C"), + tripGearCodes = listOf("OTT", "TB"), + willArriveAfter = "2024-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val result = jpaLogbookReportRepository.findAllAcknowledgedPriorNotifications(filter) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaManualPriorNotificationRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaManualPriorNotificationRepositoryITests.kt index 3eaf2d7410..236d046ec9 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaManualPriorNotificationRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaManualPriorNotificationRepositoryITests.kt @@ -28,10 +28,11 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { private var allManualPriorNotificationsLength: Int = 0 - val defaultPriorNotificationsFilter = PriorNotificationsFilter( - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2099-12-31T00:00:00Z", - ) + val defaultPriorNotificationsFilter = + PriorNotificationsFilter( + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2099-12-31T00:00:00Z", + ) @BeforeEach fun beforeEach() { @@ -60,11 +61,12 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { // Then assertThat(result).hasSizeBetween(1, allManualPriorNotificationsLength - 1) - val resultVessels = result.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val resultVessels = + result.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(resultVessels).hasSize(result.size) assertThat(resultVessels.all { listOf(CountryCode.BE, CountryCode.IT).contains(it.flagState) }).isTrue() } @@ -113,11 +115,12 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { val firstResult = jpaManualPriorNotificationRepository.findAll(firstFilter) // Then - val firstResultVessels = firstResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val firstResultVessels = + firstResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(firstResultVessels).hasSize(firstResult.size) assertThat(firstResultVessels.all { it.length!! < 12 }).isTrue() @@ -129,11 +132,12 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { // Then - val secondResultVessels = secondResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val secondResultVessels = + secondResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(secondResultVessels).hasSize(secondResult.size) assertThat(secondResultVessels.all { it.length!! >= 12 }).isTrue() } @@ -149,11 +153,12 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { // Then assertThat(firstResult).hasSizeBetween(1, allManualPriorNotificationsLength - 1) - val firstResultRiskFactors = firstResult.mapNotNull { - jpaRiskFactorRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val firstResultRiskFactors = + firstResult.mapNotNull { + jpaRiskFactorRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(firstResultRiskFactors).hasSize(firstResult.size) assertThat( firstResultRiskFactors.all { @@ -169,11 +174,12 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { // Then assertThat(secondResult).hasSizeBetween(1, allManualPriorNotificationsLength - 1) - val secondResultRiskFactors = secondResult.mapNotNull { - jpaRiskFactorRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val secondResultRiskFactors = + secondResult.mapNotNull { + jpaRiskFactorRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(secondResultRiskFactors).hasSize(secondResult.size) assertThat( secondResultRiskFactors.all { @@ -214,11 +220,12 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { assertThat( firstResult.all { it.logbookMessageAndValue.logbookMessage.vesselName == "NAVIRE RENOMMÉ (ANCIEN NOM)" }, ).isTrue() - val firstResultVessels = firstResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val firstResultVessels = + firstResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(firstResultVessels).hasSize(firstResult.size) assertThat(firstResultVessels.all { it.vesselName == "NAVIRE RENOMMÉ (NOUVEAU NOM)" }).isTrue() @@ -233,11 +240,12 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { assertThat( secondResult.all { it.logbookMessageAndValue.logbookMessage.vesselName == "NAVIRE RENOMMÉ (ANCIEN NOM)" }, ).isTrue() - val secondResultVessels = secondResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val secondResultVessels = + secondResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(secondResultVessels).hasSize(secondResult.size) assertThat(secondResultVessels.all { it.vesselName == "NAVIRE RENOMMÉ (NOUVEAU NOM)" }).isTrue() } @@ -256,11 +264,12 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { assertThat( firstResult.all { it.logbookMessageAndValue.logbookMessage.vesselName == "NAVIRE RENOMMÉ (ANCIEN NOM)" }, ).isTrue() - val firstResultVessels = firstResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val firstResultVessels = + firstResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(firstResultVessels).hasSize(firstResult.size) assertThat(firstResultVessels.all { it.vesselName == "NAVIRE RENOMMÉ (NOUVEAU NOM)" }).isTrue() @@ -275,11 +284,12 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { assertThat( secondResult.all { it.logbookMessageAndValue.logbookMessage.vesselName == "NAVIRE RENOMMÉ (ANCIEN NOM)" }, ).isTrue() - val secondResultVessels = secondResult.mapNotNull { - jpaVesselRepository.findFirstByInternalReferenceNumber( - it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, - ) - } + val secondResultVessels = + secondResult.mapNotNull { + jpaVesselRepository.findFirstByInternalReferenceNumber( + it.logbookMessageAndValue.logbookMessage.internalReferenceNumber!!, + ) + } assertThat(secondResultVessels).hasSize(secondResult.size) assertThat(secondResultVessels.all { it.vesselName == "NAVIRE RENOMMÉ (NOUVEAU NOM)" }).isTrue() } @@ -375,10 +385,11 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { @Transactional fun `findAll Should return manual prior notifications for vessels arriving after or before January 1st, 2024`() { // Given - val firstFilter = PriorNotificationsFilter( - willArriveAfter = "2024-01-01T00:00:00Z", - willArriveBefore = "2100-01-01T00:00:00Z", - ) + val firstFilter = + PriorNotificationsFilter( + willArriveAfter = "2024-01-01T00:00:00Z", + willArriveBefore = "2100-01-01T00:00:00Z", + ) // When val firstResult = jpaManualPriorNotificationRepository.findAll(firstFilter) @@ -393,10 +404,11 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { ).isTrue() // Given - val secondFilter = PriorNotificationsFilter( - willArriveAfter = "2000-01-01T00:00:00Z", - willArriveBefore = "2024-01-01T00:00:00Z", - ) + val secondFilter = + PriorNotificationsFilter( + willArriveAfter = "2000-01-01T00:00:00Z", + willArriveBefore = "2024-01-01T00:00:00Z", + ) // When val secondResult = jpaManualPriorNotificationRepository.findAll(secondFilter) @@ -415,10 +427,11 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { @Transactional fun `findAll Should return the expected manual prior notifications with multiple filters`() { // Given - val filter = defaultPriorNotificationsFilter.copy( - priorNotificationTypes = listOf("Préavis type A", "Préavis type C"), - tripGearCodes = listOf("OTT", "TB"), - ) + val filter = + defaultPriorNotificationsFilter.copy( + priorNotificationTypes = listOf("Préavis type A", "Préavis type C"), + tripGearCodes = listOf("OTT", "TB"), + ) // When val result = jpaManualPriorNotificationRepository.findAll(filter) @@ -462,9 +475,10 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { @Test @Transactional fun `save Should create and update a manual prior notification`() { - val originalPriorNotificationsSize = jpaManualPriorNotificationRepository - .findAll(defaultPriorNotificationsFilter) - .size + val originalPriorNotificationsSize = + jpaManualPriorNotificationRepository + .findAll(defaultPriorNotificationsFilter) + .size // Given val newPriorNotification = @@ -473,46 +487,48 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { createdAt = null, didNotFishAfterZeroNotice = false, isManuallyCreated = false, - logbookMessageAndValue = LogbookMessageAndValue( - LogbookMessage( - id = null, - internalReferenceNumber = "CFR123", - ircs = "123", - externalReferenceNumber = "456", - // Replaced by the generated `createdAt` during the save operation. - integrationDateTime = ZonedDateTime.now(), - message = PNO().apply { - authorTrigram = "ABC" - catchOnboard = emptyList() - catchToLand = emptyList() - economicZone = null - effortZone = null - faoZone = null - latitude = null - longitude = null - pnoTypes = emptyList() - port = "FRVNE" - portName = "Vannes" - predictedArrivalDatetimeUtc = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC) - predictedLandingDatetimeUtc = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC) - purpose = LogbookMessagePurpose.LAN - riskFactor = 2.1 - statisticalRectangle = null - tripStartDate = null - }, - messageType = "PNO", - // Replaced by the generated `createdAt` during the save operation. - operationDateTime = ZonedDateTime.now(), - operationNumber = null, - operationType = LogbookOperationType.DAT, - // Replaced by the generated `sentAt` during the save operation. - reportDateTime = ZonedDateTime.now(), - transmissionFormat = null, - vesselName = "Vessel Name", - vesselId = 123, + logbookMessageAndValue = + LogbookMessageAndValue( + LogbookMessage( + id = null, + internalReferenceNumber = "CFR123", + ircs = "123", + externalReferenceNumber = "456", + // Replaced by the generated `createdAt` during the save operation. + integrationDateTime = ZonedDateTime.now(), + message = + PNO().apply { + authorTrigram = "ABC" + catchOnboard = emptyList() + catchToLand = emptyList() + economicZone = null + effortZone = null + faoZone = null + latitude = null + longitude = null + pnoTypes = emptyList() + port = "FRVNE" + portName = "Vannes" + predictedArrivalDatetimeUtc = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC) + predictedLandingDatetimeUtc = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC) + purpose = LogbookMessagePurpose.LAN + riskFactor = 2.1 + statisticalRectangle = null + tripStartDate = null + }, + messageType = "PNO", + // Replaced by the generated `createdAt` during the save operation. + operationDateTime = ZonedDateTime.now(), + operationNumber = null, + operationType = LogbookOperationType.DAT, + // Replaced by the generated `sentAt` during the save operation. + reportDateTime = ZonedDateTime.now(), + transmissionFormat = null, + vesselName = "Vessel Name", + vesselId = 123, + ), + PNO::class.java, ), - PNO::class.java, - ), port = null, reportingCount = null, seafront = null, @@ -524,9 +540,10 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { // When val createdPriorNotification = jpaManualPriorNotificationRepository.save(newPriorNotification) - val priorNotifications = jpaManualPriorNotificationRepository - .findAll(defaultPriorNotificationsFilter) - .sortedBy { it.createdAt } + val priorNotifications = + jpaManualPriorNotificationRepository + .findAll(defaultPriorNotificationsFilter) + .sortedBy { it.createdAt } // Then val lastPriorNotification = priorNotifications.last() @@ -548,8 +565,9 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { @Transactional fun `updateState Should update writable state values for an existing PNO logbook report`() { // Given - val currentManualPriorNotification = jpaManualPriorNotificationRepository - .findByReportId("00000000-0000-4000-0000-000000000001")!! + val currentManualPriorNotification = + jpaManualPriorNotificationRepository + .findByReportId("00000000-0000-4000-0000-000000000001")!! assertThat(currentManualPriorNotification.logbookMessageAndValue.value.isBeingSent).isEqualTo(false) assertThat(currentManualPriorNotification.logbookMessageAndValue.value.isVerified).isEqualTo(false) @@ -562,8 +580,9 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { ) // Then - val updatedManualPriorNotification = jpaManualPriorNotificationRepository - .findByReportId("00000000-0000-4000-0000-000000000001")!! + val updatedManualPriorNotification = + jpaManualPriorNotificationRepository + .findByReportId("00000000-0000-4000-0000-000000000001")!! assertThat(updatedManualPriorNotification.logbookMessageAndValue.value.isBeingSent).isEqualTo(true) assertThat(updatedManualPriorNotification.logbookMessageAndValue.value.isSent).isEqualTo(false) assertThat(updatedManualPriorNotification.logbookMessageAndValue.value.isVerified).isEqualTo(true) @@ -586,8 +605,9 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { @Transactional fun `invalidate Should invalidate an existing PNO logbook report`() { // Given - val currentManualPriorNotification = jpaManualPriorNotificationRepository - .findByReportId("00000000-0000-4000-0000-000000000001")!! + val currentManualPriorNotification = + jpaManualPriorNotificationRepository + .findByReportId("00000000-0000-4000-0000-000000000001")!! assertThat(currentManualPriorNotification.logbookMessageAndValue.value.isInvalidated).isNull() // When @@ -596,8 +616,9 @@ class JpaManualPriorNotificationRepositoryITests : AbstractDBTests() { ) // Then - val updatedManualPriorNotification = jpaManualPriorNotificationRepository - .findByReportId("00000000-0000-4000-0000-000000000001")!! + val updatedManualPriorNotification = + jpaManualPriorNotificationRepository + .findByReportId("00000000-0000-4000-0000-000000000001")!! assertThat(updatedManualPriorNotification.logbookMessageAndValue.value.isInvalidated).isEqualTo(true) } } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt index bb3a32883b..a41ec3622e 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaMissionActionRepositoryITests.kt @@ -13,7 +13,6 @@ import java.time.ZoneOffset import java.time.ZonedDateTime class JpaMissionActionRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaMissionActionsRepository: JpaMissionActionsRepository @@ -35,9 +34,10 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { @Transactional fun `findVesselMissionActionsAfterDateTime Should return all vessel's controls after a date time`() { // Given - val dateTime = ZonedDateTime.now() - .minusYears(1) - .minusMonths(1) + val dateTime = + ZonedDateTime.now() + .minusYears(1) + .minusMonths(1) // When val controls = jpaMissionActionsRepository.findVesselMissionActionsAfterDateTime(1, dateTime) @@ -167,9 +167,10 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { val newMission = getDummyMissionAction(dateTime) // When - val throwable = catchThrowable { - jpaMissionActionsRepository.save(newMission.copy(facade = "BAD_FACADE")) - } + val throwable = + catchThrowable { + jpaMissionActionsRepository.save(newMission.copy(facade = "BAD_FACADE")) + } // Then assertThat(throwable).isNotNull() @@ -205,58 +206,59 @@ class JpaMissionActionRepositoryITests : AbstractDBTests() { val existingAction = jpaMissionActionsRepository.findById(expectedId) assertThat(existingAction.internalReferenceNumber).isNull() - val actionToUpdate = MissionAction( - actionDatetimeUtc = ZonedDateTime.now(), - actionType = MissionActionType.SEA_CONTROL, - controlQualityComments = null, - controlUnits = listOf(), - districtCode = null, - emitsAis = null, - emitsVms = ControlCheck.NOT_APPLICABLE, - externalReferenceNumber = "DONTSINK", - facade = "Sud Océan Indien", - faoAreas = listOf(), - feedbackSheetRequired = false, - flagState = CountryCode.FR, - flightGoals = listOf(), - gearInfractions = listOf(), - gearOnboard = listOf(), - id = expectedId, - internalReferenceNumber = "FAK000999999", - ircs = "CALLME", - latitude = 49.44, - licencesAndLogbookObservations = null, - licencesMatchActivity = ControlCheck.NOT_APPLICABLE, - logbookInfractions = listOf(), - logbookMatchesActivity = ControlCheck.NOT_APPLICABLE, - longitude = -0.56, - missionId = 34, - numberOfVesselsFlownOver = null, - otherComments = "Commentaires post contrôle", - otherInfractions = listOf(), - portLocode = null, - portName = null, - segments = listOf(), - seizureAndDiversion = false, - seizureAndDiversionComments = null, - separateStowageOfPreservedSpecies = ControlCheck.NO, - speciesInfractions = listOf(), - speciesObservations = null, - speciesOnboard = listOf(), - speciesSizeControlled = null, - speciesWeightControlled = null, - unitWithoutOmegaGauge = false, - userTrigram = "JKL", - vesselId = 1, - vesselName = "PHENOMENE", - vesselTargeted = ControlCheck.YES, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - isFromPoseidon = false, - completion = Completion.TO_COMPLETE, - ) + val actionToUpdate = + MissionAction( + actionDatetimeUtc = ZonedDateTime.now(), + actionType = MissionActionType.SEA_CONTROL, + controlQualityComments = null, + controlUnits = listOf(), + districtCode = null, + emitsAis = null, + emitsVms = ControlCheck.NOT_APPLICABLE, + externalReferenceNumber = "DONTSINK", + facade = "Sud Océan Indien", + faoAreas = listOf(), + feedbackSheetRequired = false, + flagState = CountryCode.FR, + flightGoals = listOf(), + gearInfractions = listOf(), + gearOnboard = listOf(), + id = expectedId, + internalReferenceNumber = "FAK000999999", + ircs = "CALLME", + latitude = 49.44, + licencesAndLogbookObservations = null, + licencesMatchActivity = ControlCheck.NOT_APPLICABLE, + logbookInfractions = listOf(), + logbookMatchesActivity = ControlCheck.NOT_APPLICABLE, + longitude = -0.56, + missionId = 34, + numberOfVesselsFlownOver = null, + otherComments = "Commentaires post contrôle", + otherInfractions = listOf(), + portLocode = null, + portName = null, + segments = listOf(), + seizureAndDiversion = false, + seizureAndDiversionComments = null, + separateStowageOfPreservedSpecies = ControlCheck.NO, + speciesInfractions = listOf(), + speciesObservations = null, + speciesOnboard = listOf(), + speciesSizeControlled = null, + speciesWeightControlled = null, + unitWithoutOmegaGauge = false, + userTrigram = "JKL", + vesselId = 1, + vesselName = "PHENOMENE", + vesselTargeted = ControlCheck.YES, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + isFromPoseidon = false, + completion = Completion.TO_COMPLETE, + ) // When val updatedMissionAction = jpaMissionActionsRepository.save(actionToUpdate) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPNOAndLANAlertRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPNOAndLANAlertRepositoryITests.kt index f4c46691bf..fc280f6540 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPNOAndLANAlertRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPNOAndLANAlertRepositoryITests.kt @@ -11,7 +11,6 @@ import java.time.ZonedDateTime import java.util.* class JpaPNOAndLANAlertRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaAlertRepository: JpaPNOAndLANAlertRepository @@ -19,34 +18,37 @@ class JpaPNOAndLANAlertRepositoryITests : AbstractDBTests() { @Transactional fun `findAlertsOfTypes Should return all alert of a specific rule`() { // Given - val alertOne = PNOAndLANAlert( - id = UUID.randomUUID(), - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = PNOAndLANWeightToleranceAlert(), - ) + val alertOne = + PNOAndLANAlert( + id = UUID.randomUUID(), + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = PNOAndLANWeightToleranceAlert(), + ) jpaAlertRepository.save(alertOne) - val alertTwo = PNOAndLANAlert( - id = UUID.randomUUID(), - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = PNOAndLANWeightToleranceAlert(), - ) + val alertTwo = + PNOAndLANAlert( + id = UUID.randomUUID(), + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = PNOAndLANWeightToleranceAlert(), + ) jpaAlertRepository.save(alertTwo) // When - val alerts = jpaAlertRepository.findAlertsOfTypes( - listOf(AlertTypeMapping.PNO_LAN_WEIGHT_TOLERANCE_ALERT), - "FRFGRGR", - "123456", - ) + val alerts = + jpaAlertRepository.findAlertsOfTypes( + listOf(AlertTypeMapping.PNO_LAN_WEIGHT_TOLERANCE_ALERT), + "FRFGRGR", + "123456", + ) // Then assertThat(alerts).hasSize(2) @@ -56,23 +58,25 @@ class JpaPNOAndLANAlertRepositoryITests : AbstractDBTests() { @Transactional fun `findAlertsOfTypes Should return no alert When the rule name is wrong`() { // Given - val alertOne = PNOAndLANAlert( - id = UUID.randomUUID(), - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = PNOAndLANWeightToleranceAlert(), - ) + val alertOne = + PNOAndLANAlert( + id = UUID.randomUUID(), + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = PNOAndLANWeightToleranceAlert(), + ) jpaAlertRepository.save(alertOne) // When - val alerts = jpaAlertRepository.findAlertsOfTypes( - listOf(AlertTypeMapping.THREE_MILES_TRAWLING_ALERT), - "FRFGRGR", - "123456", - ) + val alerts = + jpaAlertRepository.findAlertsOfTypes( + listOf(AlertTypeMapping.THREE_MILES_TRAWLING_ALERT), + "FRFGRGR", + "123456", + ) // Then assertThat(alerts).hasSize(0) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPendingAlertRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPendingAlertRepositoryITests.kt index a7d75541c1..8f339743de 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPendingAlertRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPendingAlertRepositoryITests.kt @@ -12,7 +12,6 @@ import org.springframework.transaction.annotation.Transactional import java.time.ZonedDateTime class JpaPendingAlertRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaPendingAlertRepository: JpaPendingAlertRepository @@ -20,17 +19,18 @@ class JpaPendingAlertRepositoryITests : AbstractDBTests() { @Transactional fun `findAlertsOfTypes Should return an alert with the type entered`() { // Given - val alertOne = PendingAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = ThreeMilesTrawlingAlert(), - ) + val alertOne = + PendingAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = ThreeMilesTrawlingAlert(), + ) jpaPendingAlertRepository.save(alertOne) // When diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPositionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPositionRepositoryITests.kt index c3fad203c5..941c98275d 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPositionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPositionRepositoryITests.kt @@ -14,7 +14,6 @@ import java.time.ZoneId import java.time.ZonedDateTime class JpaPositionRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaPositionRepository: JpaPositionRepository @@ -56,9 +55,10 @@ class JpaPositionRepositoryITests : AbstractDBTests() { // Then val positions = jpaPositionRepository.findAll() - val sameMMSIPositions = positions.filter { - it.mmsi == "224136470" - } + val sameMMSIPositions = + positions.filter { + it.mmsi == "224136470" + } assertThat(sameMMSIPositions).hasSize(1) assertThat(positions).hasSize(69240) assertThat(positions.last().dateTime.toString()).isEqualTo("1970-01-01T00:00:00.999999999Z[UTC]") @@ -69,95 +69,104 @@ class JpaPositionRepositoryITests : AbstractDBTests() { fun `findVesselLastPositionsWithoutSpecifiedIdentifier Should filter the list of positions based on the from and to parameter`() { // Given val now = ZonedDateTime.now() - val firstPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 4, - ), - ) - val secondPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 3, - ), - ) - val thirdPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 2, - ), - ) - val fourthPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusMinutes( - 1, - ), - ) + val firstPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 4, + ), + ) + val secondPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 3, + ), + ) + val thirdPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 2, + ), + ) + val fourthPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusMinutes( + 1, + ), + ) // When jpaPositionRepository.save(firstPosition) jpaPositionRepository.save(secondPosition) jpaPositionRepository.save(thirdPosition) jpaPositionRepository.save(fourthPosition) - val lastPositions = jpaPositionRepository.findVesselLastPositionsWithoutSpecifiedIdentifier( - "FR224226850", - "", - "", - ZonedDateTime.now().minusHours(2).minusMinutes(10), - ZonedDateTime.now(), - ) + val lastPositions = + jpaPositionRepository.findVesselLastPositionsWithoutSpecifiedIdentifier( + "FR224226850", + "", + "", + ZonedDateTime.now().minusHours(2).minusMinutes(10), + ZonedDateTime.now(), + ) // Then // For this vessel, we inserted @@ -169,95 +178,104 @@ class JpaPositionRepositoryITests : AbstractDBTests() { fun `findVesselLastPositionsWithoutSpecifiedIdentifier Should return the list of last positions for a given vessel When the CFR is not empty`() { // Given val now = ZonedDateTime.now() - val firstPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 4, - ), - ) - val secondPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 3, - ), - ) - val thirdPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 2, - ), - ) - val fourthPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = null, - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 1, - ), - ) + val firstPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 4, + ), + ) + val secondPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 3, + ), + ) + val thirdPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 2, + ), + ) + val fourthPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = null, + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 1, + ), + ) // When jpaPositionRepository.save(firstPosition) jpaPositionRepository.save(secondPosition) jpaPositionRepository.save(thirdPosition) jpaPositionRepository.save(fourthPosition) - val lastPositions = jpaPositionRepository.findVesselLastPositionsWithoutSpecifiedIdentifier( - "FR224226850", - "", - "", - ZonedDateTime.now().minusHours(6), - ZonedDateTime.now(), - ) + val lastPositions = + jpaPositionRepository.findVesselLastPositionsWithoutSpecifiedIdentifier( + "FR224226850", + "", + "", + ZonedDateTime.now().minusHours(6), + ZonedDateTime.now(), + ) // Then // For this vessel, we inserted @@ -269,95 +287,104 @@ class JpaPositionRepositoryITests : AbstractDBTests() { fun `findVesselLastPositionsWithoutSpecifiedIdentifier Should return the list of last positions for a given vessel When the external marking is not empty`() { // Given val now = ZonedDateTime.now() - val firstPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = "NOT_NULL", - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 4, - ), - ) - val secondPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = "NOT_NULL", - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 3, - ), - ) - val thirdPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = "NOT_NULL", - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 2, - ), - ) - val fourthPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = null, - externalReferenceNumber = "NOT_NULL", - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 1, - ), - ) + val firstPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = "NOT_NULL", + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 4, + ), + ) + val secondPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = "NOT_NULL", + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 3, + ), + ) + val thirdPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = "NOT_NULL", + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 2, + ), + ) + val fourthPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = null, + externalReferenceNumber = "NOT_NULL", + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 1, + ), + ) // When jpaPositionRepository.save(firstPosition) jpaPositionRepository.save(secondPosition) jpaPositionRepository.save(thirdPosition) jpaPositionRepository.save(fourthPosition) - val lastPositions = jpaPositionRepository.findVesselLastPositionsWithoutSpecifiedIdentifier( - "", - "NOT_NULL", - "", - ZonedDateTime.now().minusHours(6), - ZonedDateTime.now(), - ) + val lastPositions = + jpaPositionRepository.findVesselLastPositionsWithoutSpecifiedIdentifier( + "", + "NOT_NULL", + "", + ZonedDateTime.now().minusHours(6), + ZonedDateTime.now(), + ) // Then assertThat(lastPositions).hasSize(4) @@ -368,95 +395,104 @@ class JpaPositionRepositoryITests : AbstractDBTests() { fun `findVesselLastPositionsWithoutSpecifiedIdentifier Should return the list of last positions for a given vessel When the IRCS is not empty`() { // Given val now = ZonedDateTime.now() - val firstPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = "NOT_NULL", - externalReferenceNumber = "", - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 4, - ), - ) - val secondPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = "NOT_NULL", - externalReferenceNumber = "", - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 3, - ), - ) - val thirdPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = "NOT_NULL", - externalReferenceNumber = "", - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 2, - ), - ) - val fourthPosition = Position( - null, - internalReferenceNumber = "FR224226850", - mmsi = "224226850", - ircs = "NOT_NULL", - externalReferenceNumber = "", - vesselName = null, - flagState = null, - positionType = PositionType.AIS, - isManual = false, - isFishing = false, - course = 16.445, - latitude = 48.2525, - longitude = 1.8, - speed = 180.0, - dateTime = now.minusHours( - 1, - ), - ) + val firstPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = "NOT_NULL", + externalReferenceNumber = "", + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 4, + ), + ) + val secondPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = "NOT_NULL", + externalReferenceNumber = "", + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 3, + ), + ) + val thirdPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = "NOT_NULL", + externalReferenceNumber = "", + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 2, + ), + ) + val fourthPosition = + Position( + null, + internalReferenceNumber = "FR224226850", + mmsi = "224226850", + ircs = "NOT_NULL", + externalReferenceNumber = "", + vesselName = null, + flagState = null, + positionType = PositionType.AIS, + isManual = false, + isFishing = false, + course = 16.445, + latitude = 48.2525, + longitude = 1.8, + speed = 180.0, + dateTime = + now.minusHours( + 1, + ), + ) // When jpaPositionRepository.save(firstPosition) jpaPositionRepository.save(secondPosition) jpaPositionRepository.save(thirdPosition) jpaPositionRepository.save(fourthPosition) - val lastPositions = jpaPositionRepository.findVesselLastPositionsWithoutSpecifiedIdentifier( - "", - "", - "NOT_NULL", - ZonedDateTime.now().minusHours(6), - ZonedDateTime.now(), - ) + val lastPositions = + jpaPositionRepository.findVesselLastPositionsWithoutSpecifiedIdentifier( + "", + "", + "NOT_NULL", + ZonedDateTime.now().minusHours(6), + ZonedDateTime.now(), + ) // Then assertThat(lastPositions).hasSize(4) diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPriorNotificationPdfDocumentRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPriorNotificationPdfDocumentRepositoryITests.kt index dbdce51c43..70b15711ca 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPriorNotificationPdfDocumentRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaPriorNotificationPdfDocumentRepositoryITests.kt @@ -11,7 +11,6 @@ import org.springframework.transaction.annotation.Transactional import java.time.ZonedDateTime class JpaPriorNotificationPdfDocumentRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaPriorNotificationPdfDocumentRepository: JpaPriorNotificationPdfDocumentRepository @@ -39,9 +38,10 @@ class JpaPriorNotificationPdfDocumentRepositoryITests : AbstractDBTests() { jpaPriorNotificationPdfDocumentRepository.deleteByReportId("FAKE_OPERATION_102") // Then - val throwable = catchThrowable { - jpaPriorNotificationPdfDocumentRepository.findByReportId("FAKE_OPERATION_102") - } + val throwable = + catchThrowable { + jpaPriorNotificationPdfDocumentRepository.findByReportId("FAKE_OPERATION_102") + } // Then assertThat(throwable).isNotNull() diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRecentPositionsMetricsRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRecentPositionsMetricsRepositoryITests.kt index 7e9123f9ff..4557901e08 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRecentPositionsMetricsRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRecentPositionsMetricsRepositoryITests.kt @@ -5,7 +5,6 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.transaction.annotation.Transactional class JpaRecentPositionsMetricsRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaRecentPositionsMetricsRepository: JpaRecentPositionsMetricsRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaReportingRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaReportingRepositoryITests.kt index 95127cdc6b..fdfcb18852 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaReportingRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaReportingRepositoryITests.kt @@ -68,12 +68,13 @@ class JpaReportingRepositoryITests : AbstractDBTests() { vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, flagState = CountryCode.FR, creationDate = creationDate, - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ), + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), type = ReportingType.INFRACTION_SUSPICION, isDeleted = false, isArchived = false, @@ -110,12 +111,13 @@ class JpaReportingRepositoryITests : AbstractDBTests() { vesselId = 523, creationDate = creationDate, flagState = CountryCode.FR, - value = InfractionSuspicion( - ReportingActor.OPS, - natinfCode = 123456, - authorTrigram = "LTH", - title = "A title", - ), + value = + InfractionSuspicion( + ReportingActor.OPS, + natinfCode = 123456, + authorTrigram = "LTH", + title = "A title", + ), type = ReportingType.INFRACTION_SUSPICION, isDeleted = false, isArchived = false, diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRiskFactorRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRiskFactorRepositoryITests.kt index 271c903731..eccc967fdf 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRiskFactorRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaRiskFactorRepositoryITests.kt @@ -9,7 +9,6 @@ import org.springframework.cache.CacheManager import org.springframework.transaction.annotation.Transactional class JpaRiskFactorRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaRiskFactorRepository: JpaRiskFactorRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSilencedAlertRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSilencedAlertRepositoryITests.kt index f4083dc8eb..7346f7de97 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSilencedAlertRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSilencedAlertRepositoryITests.kt @@ -13,7 +13,6 @@ import org.springframework.transaction.annotation.Transactional import java.time.ZonedDateTime class JpaSilencedAlertRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaSilencedAlertRepository: JpaSilencedAlertRepository @@ -22,16 +21,17 @@ class JpaSilencedAlertRepositoryITests : AbstractDBTests() { fun `save Should save a silenced alert created from scratch`() { // Given val now = ZonedDateTime.now() - val alertToSilence = SilencedAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - value = ThreeMilesTrawlingAlert(), - silencedBeforeDate = now.plusDays(25), - ) + val alertToSilence = + SilencedAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + value = ThreeMilesTrawlingAlert(), + silencedBeforeDate = now.plusDays(25), + ) // When val silencedAlert = jpaSilencedAlertRepository.save(alertToSilence) @@ -52,17 +52,18 @@ class JpaSilencedAlertRepositoryITests : AbstractDBTests() { fun `save Should save a silenced alert from the pending alert`() { // Given val now = ZonedDateTime.now() - val alertOne = PendingAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = ThreeMilesTrawlingAlert(), - ) + val alertOne = + PendingAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = ThreeMilesTrawlingAlert(), + ) // When val silencedAlert = jpaSilencedAlertRepository.save(alertOne, now.plusHours(1), false) @@ -83,17 +84,18 @@ class JpaSilencedAlertRepositoryITests : AbstractDBTests() { fun `save Should save a silenced alert When the ircs is null`() { // Given val now = ZonedDateTime.now() - val alertOne = PendingAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = null, - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = ThreeMilesTrawlingAlert(), - ) + val alertOne = + PendingAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = null, + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = ThreeMilesTrawlingAlert(), + ) // When val silencedAlert = jpaSilencedAlertRepository.save(alertOne, now.plusHours(1), false) @@ -114,17 +116,18 @@ class JpaSilencedAlertRepositoryITests : AbstractDBTests() { // Given assertThat(jpaSilencedAlertRepository.findAllCurrentSilencedAlerts()).hasSize(4) val now = ZonedDateTime.now() - val alertOne = PendingAlert( - internalReferenceNumber = "FRFGRGR", - externalReferenceNumber = "RGD", - ircs = "6554fEE", - vesselId = 123, - vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - flagState = CountryCode.FR, - tripNumber = "123456", - creationDate = ZonedDateTime.now(), - value = ThreeMilesTrawlingAlert(), - ) + val alertOne = + PendingAlert( + internalReferenceNumber = "FRFGRGR", + externalReferenceNumber = "RGD", + ircs = "6554fEE", + vesselId = 123, + vesselIdentifier = VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + flagState = CountryCode.FR, + tripNumber = "123456", + creationDate = ZonedDateTime.now(), + value = ThreeMilesTrawlingAlert(), + ) jpaSilencedAlertRepository.save(alertOne, now, false) // When diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesGroupRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesGroupRepositoryITests.kt index 63f4c97b95..662c1844e4 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesGroupRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesGroupRepositoryITests.kt @@ -8,7 +8,6 @@ import org.springframework.cache.CacheManager import org.springframework.transaction.annotation.Transactional class JpaSpeciesGroupRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaSpeciesGroupRepository: JpaSpeciesGroupRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesRepositoryITests.kt index a94f60798e..8f0849fcf3 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaSpeciesRepositoryITests.kt @@ -10,7 +10,6 @@ import org.springframework.cache.CacheManager import org.springframework.transaction.annotation.Transactional class JpaSpeciesRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaSpeciesRepository: JpaSpeciesRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaUserAuthorisationRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaUserAuthorisationRepositoryITests.kt index 215dc9db1d..45cfc0aca9 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaUserAuthorisationRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaUserAuthorisationRepositoryITests.kt @@ -9,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.transaction.annotation.Transactional class JpaUserAuthorisationRepositoryITests : AbstractDBTests() { - @Autowired private lateinit var jpaUserAuthorizationRepository: JpaUserAuthorizationRepository diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaVesselRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaVesselRepositoryITests.kt index b6a31365bf..5814195783 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaVesselRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/JpaVesselRepositoryITests.kt @@ -136,18 +136,21 @@ class JpaVesselRepositoryITests : AbstractDBTests() { @Transactional fun `findUnderCharterForVessel Should get the underCharter field of a vessel`() { // When - val notUnderCharterOnCfr = jpaVesselRepository.findUnderCharterForVessel( - VesselIdentifier.INTERNAL_REFERENCE_NUMBER, - "FAK000999999", - ) - val underCharterOnIrcs = jpaVesselRepository.findUnderCharterForVessel( - VesselIdentifier.IRCS, - "QGDF", - ) - val underCharterOnExternalImmatriculation = jpaVesselRepository.findUnderCharterForVessel( - VesselIdentifier.EXTERNAL_REFERENCE_NUMBER, - "08FR65324", - ) + val notUnderCharterOnCfr = + jpaVesselRepository.findUnderCharterForVessel( + VesselIdentifier.INTERNAL_REFERENCE_NUMBER, + "FAK000999999", + ) + val underCharterOnIrcs = + jpaVesselRepository.findUnderCharterForVessel( + VesselIdentifier.IRCS, + "QGDF", + ) + val underCharterOnExternalImmatriculation = + jpaVesselRepository.findUnderCharterForVessel( + VesselIdentifier.EXTERNAL_REFERENCE_NUMBER, + "08FR65324", + ) // Then assertThat(notUnderCharterOnCfr).isFalse diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt index eaf34ddaf6..72588b11b4 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/TestUtils.kt @@ -6,63 +6,69 @@ import fr.gouv.cnsp.monitorfish.domain.entities.mission.mission_actions.Completi import java.time.ZonedDateTime object TestUtils { - fun getDummyMissionAction(dateTime: ZonedDateTime, id: Int? = null) = - MissionAction( - id = id, - actionDatetimeUtc = dateTime, - missionId = 2, - vesselId = 2, - internalReferenceNumber = "FR0564654", - externalReferenceNumber = "FDEY874", - ircs = "FDZFEE", - flagState = CountryCode.FR, - actionType = MissionActionType.SEA_CONTROL, - flightGoals = listOf( + fun getDummyMissionAction( + dateTime: ZonedDateTime, + id: Int? = null, + ) = MissionAction( + id = id, + actionDatetimeUtc = dateTime, + missionId = 2, + vesselId = 2, + internalReferenceNumber = "FR0564654", + externalReferenceNumber = "FDEY874", + ircs = "FDZFEE", + flagState = CountryCode.FR, + actionType = MissionActionType.SEA_CONTROL, + flightGoals = + listOf( FlightGoal.CLOSED_AREA, FlightGoal.UNAUTHORIZED_FISHING, ), - emitsVms = ControlCheck.YES, - emitsAis = ControlCheck.NOT_APPLICABLE, - logbookMatchesActivity = ControlCheck.NO, - speciesWeightControlled = true, - speciesSizeControlled = true, - separateStowageOfPreservedSpecies = ControlCheck.YES, - logbookInfractions = listOf( + emitsVms = ControlCheck.YES, + emitsAis = ControlCheck.NOT_APPLICABLE, + logbookMatchesActivity = ControlCheck.NO, + speciesWeightControlled = true, + speciesSizeControlled = true, + separateStowageOfPreservedSpecies = ControlCheck.YES, + logbookInfractions = + listOf( LogbookInfraction( InfractionType.WITH_RECORD, 27689, "Poids à bord MNZ supérieur de 50% au poids déclaré", ), ), - faoAreas = listOf("25.6.9", "25.7.9"), - segments = listOf( + faoAreas = listOf("25.6.9", "25.7.9"), + segments = + listOf( FleetSegment( segment = "WWSS10", segmentName = "World Wide Segment", ), ), - gearInfractions = listOf( + gearInfractions = + listOf( GearInfraction( InfractionType.WITH_RECORD, 27689, "Maille trop petite", ), ), - controlQualityComments = "Ciblage CNSP respecté", - feedbackSheetRequired = true, - userTrigram = "DEF", - facade = "NAMO", - longitude = -6.56, - latitude = 45.12, - isDeleted = false, - hasSomeGearsSeized = false, - hasSomeSpeciesSeized = false, - completedBy = "XYZ", - completion = Completion.TO_COMPLETE, - isFromPoseidon = true, - isAdministrativeControl = true, - isComplianceWithWaterRegulationsControl = true, - isSafetyEquipmentAndStandardsComplianceControl = true, - isSeafarersControl = true, - ) + controlQualityComments = "Ciblage CNSP respecté", + feedbackSheetRequired = true, + userTrigram = "DEF", + facade = "NAMO", + longitude = -6.56, + latitude = 45.12, + isDeleted = false, + hasSomeGearsSeized = false, + hasSomeSpeciesSeized = false, + completedBy = "XYZ", + completion = Completion.TO_COMPLETE, + isFromPoseidon = true, + isAdministrativeControl = true, + isComplianceWithWaterRegulationsControl = true, + isSafetyEquipmentAndStandardsComplianceControl = true, + isSeafarersControl = true, + ) } diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt index 8843ce4bd8..a86ee62495 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/APIMissionRepositoryITest.kt @@ -16,15 +16,16 @@ import java.time.ZoneOffset import java.time.ZonedDateTime class APIMissionRepositoryITest { - @Test fun `findControlUnitsByMissionId Should return the mission`() { runBlocking { // Given - val mockEngine = MockEngine { _ -> - respond( - content = ByteReadChannel( - """{ + val mockEngine = + MockEngine { _ -> + respond( + content = + ByteReadChannel( + """{ "id": 34, "missionTypes": ["SEA"], "controlUnits": [ @@ -131,18 +132,19 @@ class APIMissionRepositoryITest { "missionSource": "MONITORENV", "isUnderJdp": false }""", - ), - status = HttpStatusCode.OK, - headers = headersOf(HttpHeaders.ContentType, "application/json"), - ) - } + ), + status = HttpStatusCode.OK, + headers = headersOf(HttpHeaders.ContentType, "application/json"), + ) + } val apiClient = ApiClient(mockEngine) val monitorenvProperties = MonitorenvProperties() monitorenvProperties.url = "http://test" // When - val controlUnits = APIMissionRepository(monitorenvProperties, apiClient) - .findControlUnitsOfMission(this, 1).await() + val controlUnits = + APIMissionRepository(monitorenvProperties, apiClient) + .findControlUnitsOfMission(this, 1).await() // Then assertThat(controlUnits).hasSize(3) @@ -158,19 +160,21 @@ class APIMissionRepositoryITest { fun `findControlUnitsByMissionId Should not thrown an exception When the request fail`() { runBlocking { // Given - val mockEngine = MockEngine { _ -> - respond( - content = "NOT FOUND", - status = HttpStatusCode.NotFound, - ) - } + val mockEngine = + MockEngine { _ -> + respond( + content = "NOT FOUND", + status = HttpStatusCode.NotFound, + ) + } val apiClient = ApiClient(mockEngine) val monitorenvProperties = MonitorenvProperties() monitorenvProperties.url = "http://test" // When - val controlUnits = APIMissionRepository(monitorenvProperties, apiClient) - .findControlUnitsOfMission(this, 1).await() + val controlUnits = + APIMissionRepository(monitorenvProperties, apiClient) + .findControlUnitsOfMission(this, 1).await() // Then assertThat(controlUnits).hasSize(0) @@ -181,29 +185,31 @@ class APIMissionRepositoryITest { fun `findMissions Should return the missions`() { runBlocking { // Given - val mockEngine = MockEngine { _ -> - respond( - content = ByteReadChannel(getDummyMissions()), - status = HttpStatusCode.OK, - headers = headersOf(HttpHeaders.ContentType, "application/json"), - ) - } + val mockEngine = + MockEngine { _ -> + respond( + content = ByteReadChannel(getDummyMissions()), + status = HttpStatusCode.OK, + headers = headersOf(HttpHeaders.ContentType, "application/json"), + ) + } val apiClient = ApiClient(mockEngine) val monitorenvProperties = MonitorenvProperties() monitorenvProperties.url = "http://test" // When - val missions = APIMissionRepository(monitorenvProperties, apiClient) - .findAllMissions( - null, - null, - null, - null, - null, - null, - null, - null, - ) + val missions = + APIMissionRepository(monitorenvProperties, apiClient) + .findAllMissions( + null, + null, + null, + null, + null, + null, + null, + null, + ) // Then assertThat(missions).hasSize(12) @@ -218,29 +224,31 @@ class APIMissionRepositoryITest { fun `findMissions Should return the missions When some parameters are given`() { runBlocking { // Given - val mockEngine = MockEngine { _ -> - respond( - content = ByteReadChannel(getDummyMissions()), - status = HttpStatusCode.OK, - headers = headersOf(HttpHeaders.ContentType, "application/json"), - ) - } + val mockEngine = + MockEngine { _ -> + respond( + content = ByteReadChannel(getDummyMissions()), + status = HttpStatusCode.OK, + headers = headersOf(HttpHeaders.ContentType, "application/json"), + ) + } val apiClient = ApiClient(mockEngine) val monitorenvProperties = MonitorenvProperties() monitorenvProperties.url = "http://test" // When - val missions = APIMissionRepository(monitorenvProperties, apiClient) - .findAllMissions( - 1, - 2, - ZonedDateTime.of(2021, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - ZonedDateTime.of(2022, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), - listOf("MONITORFISH"), - listOf(MissionType.SEA.toString(), MissionType.LAND.toString()), - listOf(), - listOf("MED"), - ) + val missions = + APIMissionRepository(monitorenvProperties, apiClient) + .findAllMissions( + 1, + 2, + ZonedDateTime.of(2021, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + ZonedDateTime.of(2022, 5, 5, 3, 4, 5, 3, ZoneOffset.UTC), + listOf("MONITORFISH"), + listOf(MissionType.SEA.toString(), MissionType.LAND.toString()), + listOf(), + listOf("MED"), + ) // Then assertThat(missions).hasSize(12) @@ -264,20 +272,22 @@ class APIMissionRepositoryITest { fun `findAllIncludedIn Should return the missions`() { runBlocking { // Given - val mockEngine = MockEngine { _ -> - respond( - content = ByteReadChannel(getDummyMissions()), - status = HttpStatusCode.OK, - headers = headersOf(HttpHeaders.ContentType, "application/json"), - ) - } + val mockEngine = + MockEngine { _ -> + respond( + content = ByteReadChannel(getDummyMissions()), + status = HttpStatusCode.OK, + headers = headersOf(HttpHeaders.ContentType, "application/json"), + ) + } val apiClient = ApiClient(mockEngine) val monitorenvProperties = MonitorenvProperties() monitorenvProperties.url = "http://test" // When - val missions = APIMissionRepository(monitorenvProperties, apiClient) - .findByIds(listOf(123, 456)) + val missions = + APIMissionRepository(monitorenvProperties, apiClient) + .findByIds(listOf(123, 456)) // Then assertThat(missions).hasSize(12) @@ -292,20 +302,22 @@ class APIMissionRepositoryITest { fun `findById Should return a mission`() { runBlocking { // Given - val mockEngine = MockEngine { _ -> - respond( - content = ByteReadChannel(getDummyMission()), - status = HttpStatusCode.OK, - headers = headersOf(HttpHeaders.ContentType, "application/json"), - ) - } + val mockEngine = + MockEngine { _ -> + respond( + content = ByteReadChannel(getDummyMission()), + status = HttpStatusCode.OK, + headers = headersOf(HttpHeaders.ContentType, "application/json"), + ) + } val apiClient = ApiClient(mockEngine) val monitorenvProperties = MonitorenvProperties() monitorenvProperties.url = "http://test" // When - val mission = APIMissionRepository(monitorenvProperties, apiClient) - .findById(123) + val mission = + APIMissionRepository(monitorenvProperties, apiClient) + .findById(123) // Then assertThat(mission.createdAtUtc.toString()).isEqualTo("2023-04-20T09:57Z") diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt index 9ae70cd08b..fe8fe4a9cd 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/monitorenv/TestUtils.kt @@ -39,7 +39,7 @@ class TestUtils { "isGeometryComputedFromControls":false, "missionSource":"MONITORFISH" } - """.trimIndent() + """.trimIndent() } fun getDummyMissions(): String { @@ -331,7 +331,7 @@ class TestUtils { "isGeometryComputedFromControls":false, "missionSource":"MONITORFISH" }] - """.trimIndent() + """.trimIndent() } } } diff --git a/frontend/src/features/PriorNotification/components/LogbookPriorNotificationForm/Form.tsx b/frontend/src/features/PriorNotification/components/LogbookPriorNotificationForm/Form.tsx index ddc1bd722a..a0d8b0471e 100644 --- a/frontend/src/features/PriorNotification/components/LogbookPriorNotificationForm/Form.tsx +++ b/frontend/src/features/PriorNotification/components/LogbookPriorNotificationForm/Form.tsx @@ -81,17 +81,15 @@ export function Form({ detail, initialFormValues }: FormProps) { {isSuperUser && ( - {!isInvalidated && ( - - )} +