Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Préavis – Corrige plusieurs petits bugs #3619

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 6 additions & 5 deletions backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JavaCompile>() {
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

tasks.withType<Javadoc>() {
tasks.withType<Javadoc> {
options.encoding = "UTF-8"
}

Expand Down
5 changes: 4 additions & 1 deletion backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 == " " }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.springframework.context.annotation.Configuration

@Configuration
class SwaggerConfig {

@Autowired
private val hostProperties: HostProperties? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Loading
Loading