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

Zones FAO - Correction de la liste des zones #3442

Merged
merged 1 commit into from
Jul 30, 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
@@ -1,3 +1,5 @@
package fr.gouv.cnsp.monitorfish.domain.entities.fao_area

data class FAOArea(val faoCode: String, val subArea: String? = null, val division: String? = null)
data class FAOArea(
val faoCode: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ class GetFAOAreas(private val faoAreasRepository: FAOAreasRepository) {
fun execute(): List<String> {
val faoAreas = faoAreasRepository.findAll()

return (
faoAreas.mapNotNull { it.division } +
faoAreas.mapNotNull { it.subArea }
)
return faoAreas.map { it.faoCode }
.distinct()
.sorted()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,16 @@ import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import org.locationtech.jts.geom.Geometry

@Entity
@Table(name = "fao_areas")
data class FAOAreasEntity(
@Id
@Column(name = "f_code")
val faoCode: String,
@Column(name = "f_subarea")
val subArea: String? = null,
@Column(name = "f_division")
val division: String? = null,
@Column(name = "wkb_geometry", columnDefinition = "Geometry")
val geometry: Geometry? = null,
) {

fun toFAOArea() = FAOArea(
faoCode = faoCode,
subArea = subArea,
division = division,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class GetFAOAreasUTests {
// Given
given(faoAreasRepository.findAll()).willReturn(
listOf(
FAOArea("123", "27.1", "27.1.0"),
FAOArea("124", "28.1", "28.1.0"),
FAOArea("125", "28.1", "28.1.1"),
FAOArea("27.1"),
FAOArea("27.1.0"),
FAOArea("28.1"),
FAOArea("28.1.0"),
FAOArea("28.1.1"),
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class UtilsUTests {
fun `removeRedundantFaoArea Should remove redundant fao codes`() {
// Given
val faoAreas = listOf(
FAOArea(faoCode = "27.1.B", null, null),
FAOArea(faoCode = "27.1", null, null),
FAOArea(faoCode = "27.1", null, null),
FAOArea(faoCode = "18", null, null),
FAOArea(faoCode = "27.1.B.a", null, null),
FAOArea(faoCode = "27.1.B"),
FAOArea(faoCode = "27.1"),
FAOArea(faoCode = "27.1"),
FAOArea(faoCode = "18"),
FAOArea(faoCode = "27.1.B.a"),
)

// When
Expand All @@ -33,10 +33,10 @@ class UtilsUTests {
fun `removeRedundantFaoArea Should keep different fao codes`() {
// Given
val faoAreas = listOf(
FAOArea(faoCode = "27.1.B", null, null),
FAOArea(faoCode = "27.1.B", null, null),
FAOArea(faoCode = "27.1.B", null, null),
FAOArea(faoCode = "27.1.C", null, null),
FAOArea(faoCode = "27.1.B"),
FAOArea(faoCode = "27.1.B"),
FAOArea(faoCode = "27.1.B"),
FAOArea(faoCode = "27.1.C"),
)

// When
Expand All @@ -52,9 +52,9 @@ class UtilsUTests {
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", null, null),
FAOArea(faoCode = "22.1.27", null, null),
FAOArea(faoCode = "18", null, null),
FAOArea(faoCode = "27"),
FAOArea(faoCode = "22.1.27"),
FAOArea(faoCode = "18"),
)

// When
Expand All @@ -66,16 +66,16 @@ class UtilsUTests {

@Test
fun `hasFaoCodeIncludedIn Should test fao areas included in another fao area`() {
val faoAreaOne = FAOArea(faoCode = "27.1.B", null, null)
val faoAreaOne = FAOArea(faoCode = "27.1.B")
assertThat(faoAreaOne.hasFaoCodeIncludedIn("27.1")).isTrue()

val faoAreaTwo = FAOArea(faoCode = "27.1", null, null)
val faoAreaTwo = FAOArea(faoCode = "27.1")
assertThat(faoAreaTwo.hasFaoCodeIncludedIn("27.1")).isTrue()

val faoAreaThree = FAOArea(faoCode = "28.1", null, null)
val faoAreaThree = FAOArea(faoCode = "28.1")
assertThat(faoAreaThree.hasFaoCodeIncludedIn("27.1")).isFalse()

val faoAreaFour = FAOArea(faoCode = "28.1.56", null, null)
val faoAreaFour = FAOArea(faoCode = "28.1.56")
assertThat(faoAreaFour.hasFaoCodeIncludedIn("56")).isFalse()
}
}
Loading