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

[Act-Rep] Afficher l'identifiant navire pour tous les pavillons #2930

Merged
merged 1 commit into from
Feb 14, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,58 @@ data class Vessel(
val underCharter: Boolean? = null,
) {
fun getNationalIdentifier(): String {
val identifier = internalReferenceNumber?.replace("FRA000", "") ?: ""
val internalReferenceNumberCountryCode = LIKELY_CONTROLLED_COUNTRY_CODES.find { countryAlpha3 -> internalReferenceNumber?.contains(countryAlpha3) ?: false }
val identifier = internalReferenceNumber?.replace("${internalReferenceNumberCountryCode}000", "") ?: ""

if (districtCode.isNullOrEmpty()) {
return identifier
}

return "$districtCode$identifier"
}
}

val LIKELY_CONTROLLED_COUNTRY_CODES = listOf(
CountryCode.FR.alpha3,
CountryCode.RU.alpha3,
CountryCode.KR.alpha3,
CountryCode.JP.alpha3,
CountryCode.LY.alpha3,
CountryCode.VE.alpha3,
CountryCode.SC.alpha3,
CountryCode.AU.alpha3,
CountryCode.CN.alpha3,
CountryCode.MG.alpha3,
CountryCode.BR.alpha3,
CountryCode.PL.alpha3,
CountryCode.VU.alpha3,
CountryCode.KM.alpha3,
CountryCode.MC.alpha3,
CountryCode.BW.alpha3,
CountryCode.AI.alpha3,
CountryCode.LK.alpha3,
CountryCode.TW.alpha3,
CountryCode.TT.alpha3,
CountryCode.FO.alpha3,
CountryCode.GY.alpha3,
CountryCode.PA.alpha3,
CountryCode.SX.alpha3,
CountryCode.TN.alpha3,
CountryCode.TR.alpha3,
CountryCode.AL.alpha3,
CountryCode.GD.alpha3,
CountryCode.DZ.alpha3,
CountryCode.SX.alpha3,
CountryCode.BE.alpha3,
CountryCode.DK.alpha3,
CountryCode.DE.alpha3,
CountryCode.EE.alpha3,
CountryCode.IE.alpha3,
CountryCode.ES.alpha3,
CountryCode.IT.alpha3,
CountryCode.NL.alpha3,
CountryCode.NO.alpha3,
CountryCode.PT.alpha3,
CountryCode.SE.alpha3,
CountryCode.GB.alpha3,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package fr.gouv.cnsp.monitorfish.domain.entities.vessel

import com.neovisionaries.i18n.CountryCode
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.test.context.junit.jupiter.SpringExtension

@ExtendWith(SpringExtension::class)
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",
)

// When
val nationalIdentifier = vessel.getNationalIdentifier()

// Then
assertThat(nationalIdentifier).isEqualTo("AY22680")
}

@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 = "",
)

// When
val nationalIdentifier = vessel.getNationalIdentifier()

// Then
assertThat(nationalIdentifier).isEqualTo("22680")
}

@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",
)

// When
val nationalIdentifier = vessel.getNationalIdentifier()

// Then
assertThat(nationalIdentifier).isEqualTo("AY22680")
}
}
Loading