Skip to content

Commit 688f39d

Browse files
refacto: rebased
1 parent cc370d4 commit 688f39d

File tree

38 files changed

+280
-186
lines changed

38 files changed

+280
-186
lines changed

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/repositories/IRegulatoryAreaNewRepository.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ interface IRegulatoryAreaNewRepository {
1111
seaFronts: List<String>? = null,
1212
tags: List<Int>? = null,
1313
themes: List<Int>? = null,
14+
withGeometry: Boolean = true,
15+
zoom: Int? = null,
16+
bbox: List<Double>? = null,
1417
): List<RegulatoryAreaEntity>
1518

1619
fun findAllIdsByGeometry(geometry: Geometry): List<Int>

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAMPsByIds.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPsByIds.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class GetAllAMPsByIds(
1616
ids: List<Int>,
1717
axis: AxisEnum,
1818
): List<AMPEntity> {
19-
logger.info("Attempt to GET AMPs with ids: $ids")
19+
logger.info("Attempt to GET AMPs with ids: $ids")
2020
val amps = ampRepository.findAllByIds(ids, axis)
2121
logger.info("Found ${amps.size} AMPs")
2222

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllNewRegulatoryAreas.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class GetAllNewRegulatoryAreas(
1717
seaFronts: List<String>?,
1818
tags: List<Int>?,
1919
themes: List<Int>?,
20+
withGeometry: Boolean,
21+
zoom: Int?,
22+
bbox: List<Double>?,
2023
): AllRegulatoryAreasAndTotal {
2124
logger.info("Attempt to GET all regulatory areas")
2225

@@ -27,6 +30,9 @@ class GetAllNewRegulatoryAreas(
2730
seaFronts = seaFronts,
2831
tags = tags,
2932
themes = themes,
33+
withGeometry = withGeometry,
34+
zoom = zoom,
35+
bbox = bbox,
3036
)
3137

3238
val totalCount = allAreas.size.toLong()

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/Amps.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fr.gouv.cacem.monitorenv.infrastructure.api.endpoints.bff.v1
22

33
import fr.gouv.cacem.monitorenv.domain.use_cases.amps.GetAMPById
4-
import fr.gouv.cacem.monitorenv.domain.use_cases.amps.GetAMPsByIds
54
import fr.gouv.cacem.monitorenv.domain.use_cases.amps.GetAllAMPs
65
import fr.gouv.cacem.monitorenv.domain.use_cases.amps.GetAllAMPsByIds
76
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.inputs.amps.AmpByIdsDataInput

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v2/RegulatoryAreas.kt

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
package fr.gouv.cacem.monitorenv.infrastructure.api.endpoints.bff.v2
22

3-
import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas.CreateOrUpdateRegulatoryArea
4-
import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas.GetAllLayerNames
5-
import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas.GetAllNewRegulatoryAreas
6-
import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas.GetAllRegulatoryAreasToComplete
7-
import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas.GetNewRegulatoryAreaById
8-
import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas.GetRegulatoryAreaByIds
3+
import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas.*
94
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.inputs.regulatoryArea.RegulatoryAreaByIdsDataInput
105
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.inputs.regulatoryArea.RegulatoryAreaDataInput
116
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.regulatoryArea.LayerNamesDataOutput
127
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.regulatoryArea.RegulatoryAreaDataOutput
8+
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.regulatoryArea.RegulatoryAreaDataOutput.Companion.fromRegulatoryAreaEntity
139
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.regulatoryArea.RegulatoryAreaToCompleteDataOuput
14-
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.regulatoryArea.RegulatoryAreasDataOutput
10+
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.regulatoryArea.RegulatoryAreasDataOutput.Companion.fromRegulatoryAreaEntity
1511
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.regulatoryArea.RegulatoryAreasWithTotalDataOutput
1612
import io.swagger.v3.oas.annotations.Operation
1713
import io.swagger.v3.oas.annotations.Parameter
1814
import io.swagger.v3.oas.annotations.tags.Tag
1915
import jakarta.websocket.server.PathParam
20-
import org.springframework.web.bind.annotation.GetMapping
21-
import org.springframework.web.bind.annotation.PathVariable
22-
import org.springframework.web.bind.annotation.PostMapping
23-
import org.springframework.web.bind.annotation.PutMapping
24-
import org.springframework.web.bind.annotation.RequestBody
25-
import org.springframework.web.bind.annotation.RequestMapping
26-
import org.springframework.web.bind.annotation.RequestParam
27-
import org.springframework.web.bind.annotation.RestController
16+
import org.springframework.web.bind.annotation.*
2817

2918
@RestController("regulatoryAreasV2")
3019
@RequestMapping("/bff/v2/regulatory-areas")
@@ -55,6 +44,11 @@ class RegulatoryAreas(
5544
@Parameter(description = "Façades")
5645
@RequestParam(name = "seaFronts", required = false)
5746
seaFronts: List<String>?,
47+
@Parameter(description = "Avec geometrie")
48+
@RequestParam(name = "withGeometry", required = false)
49+
withGeometry: Boolean = true,
50+
@RequestParam(name = "zoom", required = false) zoom: Int?,
51+
@RequestParam(name = "bbox", required = false) bbox: List<Double>?,
5852
): RegulatoryAreasWithTotalDataOutput {
5953
val (regulatoryAreasGrouped, totalCount) =
6054
getAllNewRegulatoryAreas.execute(
@@ -63,10 +57,13 @@ class RegulatoryAreas(
6357
seaFronts = seaFronts,
6458
tags = tags,
6559
themes = themes,
60+
withGeometry = withGeometry,
61+
zoom = zoom,
62+
bbox = bbox,
6663
)
6764

6865
val groupedDto =
69-
regulatoryAreasGrouped.map { RegulatoryAreasDataOutput.Companion.fromRegulatoryAreaEntity(it) }
66+
regulatoryAreasGrouped.map { fromRegulatoryAreaEntity(it) }
7067

7168
return RegulatoryAreasWithTotalDataOutput(
7269
totalCount = totalCount,
@@ -82,7 +79,7 @@ class RegulatoryAreas(
8279
): List<RegulatoryAreaDataOutput> =
8380
getRegulatoryAreaByIds
8481
.execute(body.ids, body.axis)
85-
.map { RegulatoryAreaDataOutput.Companion.fromRegulatoryAreaEntity(it) }
82+
.map { fromRegulatoryAreaEntity(it) }
8683

8784
@GetMapping("/{regulatoryAreaId}")
8885
@Operation(summary = "Get regulatory area by Id")
@@ -92,15 +89,15 @@ class RegulatoryAreas(
9289
regulatoryAreaId: Int,
9390
): RegulatoryAreaDataOutput? =
9491
getNewRegulatoryAreaById.execute(regulatoryAreaId = regulatoryAreaId)?.let {
95-
RegulatoryAreaDataOutput.Companion.fromRegulatoryAreaEntity(it)
92+
fromRegulatoryAreaEntity(it)
9693
}
9794

9895
@PutMapping("", consumes = ["application/json"])
9996
@Operation(summary = "create or update the given regulatory area")
10097
fun put(
10198
@RequestBody regulatoryAreaDataInput: RegulatoryAreaDataInput,
10299
): RegulatoryAreaDataOutput =
103-
RegulatoryAreaDataOutput.Companion.fromRegulatoryAreaEntity(
100+
fromRegulatoryAreaEntity(
104101
createOrUpdateRegulatoryArea.execute(regulatoryAreaDataInput.toRegulatoryAreaEntity()),
105102
)
106103

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/RegulatoryAreaNewModel.kt

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,46 @@ data class RegulatoryAreaNewModel(
6666
@Column(name = "authorization_periods") val authorizationPeriods: String?,
6767
@Column(name = "prohibition_periods") val prohibitionPeriods: String?,
6868
) {
69-
fun toRegulatoryArea(mapper: JsonMapper) =
70-
RegulatoryAreaEntity(
71-
id = id,
72-
creation = creation?.atZone(ZoneOffset.UTC),
73-
plan = plan,
74-
date = date?.atZone(ZoneOffset.UTC),
75-
dateFin = dateFin?.atZone(ZoneOffset.UTC),
76-
dureeValidite = dureeValidite,
77-
editeur = editeur,
78-
editionBo = editionBo?.atZone(ZoneOffset.UTC),
79-
editionCacem = editionCacem?.atZone(ZoneOffset.UTC),
80-
facade = facade,
81-
geom = geom,
82-
layerName = layerName,
83-
polyName = polyName,
84-
observation = observation,
85-
refReg = refReg,
86-
resume = resume,
87-
source = source,
88-
temporalite = temporalite,
89-
tags = TagRegulatoryAreaNewModel.Companion.toTagEntities(tags),
90-
themes = ThemeRegulatoryAreaNewModel.Companion.toThemeEntities(themes),
91-
type = type,
92-
url = url,
93-
additionalRefReg =
94-
additionalRefReg.let {
95-
mapper.convertValue(
96-
it,
97-
object : TypeReference<
98-
List<
99-
AdditionalRefRegEntity,
100-
>,
101-
>() {},
102-
)
103-
},
104-
authorizationPeriods = authorizationPeriods,
105-
prohibitionPeriods = prohibitionPeriods,
106-
)
69+
fun toRegulatoryArea(
70+
mapper: JsonMapper,
71+
withGeometry: Boolean = true,
72+
) = RegulatoryAreaEntity(
73+
id = id,
74+
creation = creation?.atZone(ZoneOffset.UTC),
75+
plan = plan,
76+
date = date?.atZone(ZoneOffset.UTC),
77+
dateFin = dateFin?.atZone(ZoneOffset.UTC),
78+
dureeValidite = dureeValidite,
79+
editeur = editeur,
80+
editionBo = editionBo?.atZone(ZoneOffset.UTC),
81+
editionCacem = editionCacem?.atZone(ZoneOffset.UTC),
82+
facade = facade,
83+
geom = if (withGeometry) geom else null,
84+
layerName = layerName,
85+
polyName = polyName,
86+
observation = observation,
87+
refReg = refReg,
88+
resume = resume,
89+
source = source,
90+
temporalite = temporalite,
91+
tags = TagRegulatoryAreaNewModel.Companion.toTagEntities(tags),
92+
themes = ThemeRegulatoryAreaNewModel.Companion.toThemeEntities(themes),
93+
type = type,
94+
url = url,
95+
additionalRefReg =
96+
additionalRefReg.let {
97+
mapper.convertValue(
98+
it,
99+
object : TypeReference<
100+
List<
101+
AdditionalRefRegEntity,
102+
>,
103+
>() {},
104+
)
105+
},
106+
authorizationPeriods = authorizationPeriods,
107+
prohibitionPeriods = prohibitionPeriods,
108+
)
107109

108110
companion object {
109111
fun fromRegulatoryAreaEntity(

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaRegulatoryAreaNewRepository.kt

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import fr.gouv.cacem.monitorenv.domain.entities.regulatoryArea.v2.RegulatoryArea
55
import fr.gouv.cacem.monitorenv.domain.entities.tags.TagEntity
66
import fr.gouv.cacem.monitorenv.domain.entities.themes.ThemeEntity
77
import fr.gouv.cacem.monitorenv.domain.repositories.IRegulatoryAreaNewRepository
8-
import fr.gouv.cacem.monitorenv.infrastructure.database.model.RegulatoryAreaNewModel
9-
import fr.gouv.cacem.monitorenv.infrastructure.database.model.TagRegulatoryAreaNewModel
10-
import fr.gouv.cacem.monitorenv.infrastructure.database.model.TagRegulatoryAreaNewPk
11-
import fr.gouv.cacem.monitorenv.infrastructure.database.model.ThemeRegulatoryAreaNewModel
12-
import fr.gouv.cacem.monitorenv.infrastructure.database.model.ThemeRegulatoryAreaNewPk
8+
import fr.gouv.cacem.monitorenv.infrastructure.database.model.*
139
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBRegulatoryAreaNewRepository
1410
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBTagRegulatoryAreaRepository
1511
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBThemeRegulatoryAreaRepository
1612
import org.apache.commons.lang3.StringUtils
13+
import org.locationtech.jts.geom.Coordinate
1714
import org.locationtech.jts.geom.Geometry
15+
import org.locationtech.jts.geom.GeometryFactory
16+
import org.locationtech.jts.geom.PrecisionModel
1817
import org.springframework.data.repository.findByIdOrNull
1918
import org.springframework.stereotype.Repository
2019
import org.springframework.transaction.annotation.Transactional
@@ -36,12 +35,42 @@ class JpaRegulatoryAreaNewRepository(
3635
seaFronts: List<String>?,
3736
tags: List<Int>?,
3837
themes: List<Int>?,
38+
withGeometry: Boolean,
39+
zoom: Int?,
40+
bbox: List<Double>?,
3941
): List<RegulatoryAreaEntity> =
4042
dbRegulatoryAreaRepository
41-
.findAll(controlPlan = controlPlan, seaFronts = seaFronts, tags = tags, themes = themes)
42-
.map { it.toRegulatoryArea(mapper) }
43+
.findAll(
44+
controlPlan = controlPlan,
45+
seaFronts = seaFronts,
46+
tags = tags,
47+
themes = themes,
48+
withGeometry = withGeometry,
49+
zoom = zoom,
50+
geom = bbox?.let { bboxToPolygon(it) },
51+
).map { it.toRegulatoryArea(mapper, withGeometry) }
4352
.filter { findBySearchQuery(it, query) }
4453

54+
fun bboxToPolygon(bbox: List<Double>): Geometry {
55+
val minX = bbox[0]
56+
val minY = bbox[1]
57+
val maxX = bbox[2]
58+
val maxY = bbox[3]
59+
60+
val gf = GeometryFactory(PrecisionModel(), 4326)
61+
62+
val coords: Array<Coordinate?> =
63+
arrayOf(
64+
Coordinate(minX, minY),
65+
Coordinate(maxX, minY),
66+
Coordinate(maxX, maxY),
67+
Coordinate(minX, maxY),
68+
Coordinate(minX, minY),
69+
)
70+
71+
return gf.createPolygon(coords)
72+
}
73+
4574
override fun findAllLayerNames(): Map<String, Long> =
4675
dbRegulatoryAreaRepository.findAllLayerNames().associate { row ->
4776
row[0] as String to row[1] as Long

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBRegulatoryAreaNewRepository.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ interface IDBRegulatoryAreaNewRepository : JpaRepository<RegulatoryAreaNewModel,
1414
LEFT JOIN regulatoryArea.themes th
1515
LEFT JOIN regulatoryArea.tags tg
1616
WHERE (:seaFronts IS NULL OR regulatoryArea.facade IN (:seaFronts))
17-
AND (:themes IS NULL OR th.theme.id IN :themes)
18-
AND (:tags IS NULL OR tg.tag.id IN :tags)
19-
AND (:controlPlan IS NULL OR regulatoryArea.plan LIKE %:controlPlan%)
20-
AND regulatoryArea.creation IS NOT NULL
17+
AND (:themes IS NULL OR th.theme.id IN :themes)
18+
AND (:tags IS NULL OR tg.tag.id IN :tags)
19+
AND (:controlPlan IS NULL OR regulatoryArea.plan LIKE %:controlPlan%)
20+
AND regulatoryArea.creation IS NOT NULL
21+
AND
22+
((:withGeometry IS FALSE OR :geom IS NULL)
23+
OR intersects(regulatoryArea.geom, :geom) = true)
2124
ORDER BY regulatoryArea.layerName
2225
""",
2326
)
@@ -26,6 +29,9 @@ interface IDBRegulatoryAreaNewRepository : JpaRepository<RegulatoryAreaNewModel,
2629
seaFronts: List<String>? = null,
2730
tags: List<Int>? = null,
2831
themes: List<Int>? = null,
32+
withGeometry: Boolean,
33+
zoom: Int?,
34+
geom: Geometry?,
2935
): List<RegulatoryAreaNewModel>
3036

3137
fun findAllByCreationIsNull(): List<RegulatoryAreaNewModel>

backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllNewRegulatoryAreasUTest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class GetAllNewRegulatoryAreasUTest {
3636
seaFronts = null,
3737
tags = null,
3838
themes = null,
39+
withGeometry = true,
40+
bbox = null,
41+
zoom = null,
3942
)
4043

4144
// Then
@@ -72,6 +75,9 @@ class GetAllNewRegulatoryAreasUTest {
7275
seaFronts = null,
7376
tags = null,
7477
themes = null,
78+
withGeometry = true,
79+
bbox = null,
80+
zoom = null,
7581
)
7682

7783
// Then

0 commit comments

Comments
 (0)