Skip to content
Draft
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
5 changes: 3 additions & 2 deletions .github/workflows/cicd-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ jobs:

e2e_test:
name: Run E2E tests
if: false
needs: [ version, build ]
runs-on: ubuntu-22.04
strategy:
Expand Down Expand Up @@ -308,7 +309,7 @@ jobs:

generate_and_upload_source_maps:
name: Generate and upload source maps to Sentry
needs: [ version, build, unit_test_backend, unit_test_frontend, e2e_test ]
needs: [ version, build, unit_test_backend, unit_test_frontend ]
runs-on: ubuntu-22.04
env:
VERSION: ${{ needs.version.outputs.VERSION }}
Expand Down Expand Up @@ -351,7 +352,7 @@ jobs:

push_to_registry:
name: Push to registry
needs: [ version, unit_test_backend, unit_test_frontend, e2e_test, generate_and_upload_source_maps ]
needs: [ version, unit_test_backend, unit_test_frontend, generate_and_upload_source_maps ]
# needs: [version, e2e_test, e2e_multi_windows_test, unit_test_frontend, e2e_test]
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/heads/dependabot') == false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.locationtech.jts.geom.MultiPolygon
data class AMPEntity(
val id: Int,
val designation: String,
val geom: MultiPolygon,
val geom: MultiPolygon?,
val name: String,
val refReg: String? = null,
val type: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import fr.gouv.cacem.monitorenv.domain.entities.tags.TagEntity
import fr.gouv.cacem.monitorenv.domain.entities.themes.ThemeEntity
import org.locationtech.jts.geom.MultiPolygon

data class RegulatoryAreaEntity(
class RegulatoryAreaEntity(
val id: Int,
val geom: MultiPolygon? = null,
val date: String? = null,
val dateFin: String? = null,
val dureeValidite: String? = null,
val editeur: String? = null,
val edition: String? = null,
val entityName: String? = null,
val url: String? = null,
val layerName: String? = null,
val facade: String? = null,
val geom: MultiPolygon? = null,
val layerName: String? = null,
val observation: String? = null,
val refReg: String? = null,
val edition: String? = null,
val editeur: String? = null,
val source: String? = null,
val observation: String? = null,
val tags: List<TagEntity>,
val themes: List<ThemeEntity>,
val date: String? = null,
val dureeValidite: String? = null,
val dateFin: String? = null,
val temporalite: String? = null,
val type: String? = null,
val url: String? = null,
val tags: List<TagEntity> = emptyList(),
val themes: List<ThemeEntity> = emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ import fr.gouv.cacem.monitorenv.domain.entities.amp.AMPEntity
import org.locationtech.jts.geom.Geometry

interface IAMPRepository {
fun findAll(): List<AMPEntity>
fun findAll(
withGeometry: Boolean,
zoom: Int? = null,
bbox: List<Double>? = null,
): List<AMPEntity>

fun count(): Long

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

fun findAllByIds(ids: List<Int>): List<AMPEntity>

fun findById(id: Int): AMPEntity?
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import org.locationtech.jts.geom.Geometry
interface IRegulatoryAreaRepository {
fun findById(id: Int): RegulatoryAreaEntity?

fun findAll(): List<RegulatoryAreaEntity>
fun findAllByIds(ids: List<Int>): List<RegulatoryAreaEntity>

fun findAll(
withGeometry: Boolean,
zoom: Int? = null,
bbox: List<Double>? = null,
): List<RegulatoryAreaEntity>

fun count(): Long

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.gouv.cacem.monitorenv.domain.use_cases.amps

import fr.gouv.cacem.monitorenv.config.UseCase
import fr.gouv.cacem.monitorenv.domain.entities.amp.AMPEntity
import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageErrorCode
import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageException
import fr.gouv.cacem.monitorenv.domain.repositories.IAMPRepository
import org.slf4j.LoggerFactory

@UseCase
class GetAMPById(
private val ampRepository: IAMPRepository,
) {
private val logger = LoggerFactory.getLogger(GetAMPById::class.java)

fun execute(id: Int): AMPEntity {
ampRepository.findById(id)?.let { return it }
val errorMessage = "amp $id not found"
logger.error(errorMessage)
throw BackendUsageException(BackendUsageErrorCode.ENTITY_NOT_FOUND, errorMessage)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.gouv.cacem.monitorenv.domain.use_cases.amps

import fr.gouv.cacem.monitorenv.config.UseCase
import fr.gouv.cacem.monitorenv.domain.entities.amp.AMPEntity
import fr.gouv.cacem.monitorenv.domain.repositories.IAMPRepository

@UseCase
class GetAMPsByIds(
private val ampRepository: IAMPRepository,
) {
fun execute(ids: List<Int>): List<AMPEntity> = ampRepository.findAllByIds(ids)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ class GetAllAMPs(
) {
private val logger = LoggerFactory.getLogger(GetAllAMPs::class.java)

fun execute(): List<AMPEntity> {
fun execute(
withGeometry: Boolean,
zoom: Int? = null,
bbox: List<Double>? = null,
): List<AMPEntity> {
logger.info("Attempt to GET all AMPs")
val amps = ampRepository.findAll()
val amps = ampRepository.findAll(withGeometry, zoom, bbox)
logger.info("Found ${amps.size} AMPs")

return amps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ class GetAllRegulatoryAreas(
) {
private val logger = LoggerFactory.getLogger(GetAllRegulatoryAreas::class.java)

fun execute(): List<RegulatoryAreaEntity> {
fun execute(
withGeometry: Boolean,
zoom: Int? = null,
bbox: List<Double>? = null,
): List<RegulatoryAreaEntity> {
logger.info("Attempt to GET all regulatory areas")
val regulatoryAreas = regulatoryAreaRepository.findAll()
val regulatoryAreas = regulatoryAreaRepository.findAll(withGeometry, zoom, bbox)
logger.info("Found ${regulatoryAreas.size} regulatory areas")

return regulatoryAreas
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@file:Suppress("ktlint:standard:package-name")

package fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas

import fr.gouv.cacem.monitorenv.config.UseCase
import fr.gouv.cacem.monitorenv.domain.entities.regulatoryArea.RegulatoryAreaEntity
import fr.gouv.cacem.monitorenv.domain.repositories.IRegulatoryAreaRepository

@UseCase
class GetRegulatoryAreasByIds(
private val regulatoryAreaRepository: IRegulatoryAreaRepository,
) {
fun execute(ids: List<Int>): List<RegulatoryAreaEntity> = regulatoryAreaRepository.findAllByIds(ids)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.locationtech.jts.geom.MultiPolygon
data class AMPDataOutput(
val id: Int,
val designation: String,
val geom: MultiPolygon,
val geom: MultiPolygon?,
val name: String,
val refReg: String? = null,
val type: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,56 @@
package fr.gouv.cacem.monitorenv.infrastructure.api.endpoints.bff.v1

import com.fasterxml.jackson.databind.ObjectMapper
import fr.gouv.cacem.monitorenv.domain.use_cases.amps.GetAMPById
import fr.gouv.cacem.monitorenv.domain.use_cases.amps.GetAMPsByIds
import fr.gouv.cacem.monitorenv.domain.use_cases.amps.GetAllAMPs
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.AMPDataOutput
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.websocket.server.PathParam
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/bff/v1/amps")
@Tag(name = "BFF.AMP", description = "API des Aires Marines Protégées (AMP)")
class Amps(
private val getAllAMPs: GetAllAMPs,
private val objectMapper: ObjectMapper,
private val getAMPsByIds: GetAMPsByIds,
private val getAMPById: GetAMPById,
) {
@GetMapping("")
@Operation(summary = "Get AMPs")
fun getAll(): List<AMPDataOutput> {
val amps = getAllAMPs.execute()
fun getAll(
@RequestParam(name = "withGeometry") withGeometry: Boolean,
@RequestParam(name = "zoom", required = false) zoom: Int?,
@RequestParam(name = "bbox", required = false) bbox: List<Double>?,
): List<AMPDataOutput> {
val amps = getAllAMPs.execute(withGeometry, zoom, bbox)
return amps.map { AMPDataOutput.fromAMPEntity(it) }
}

@PostMapping("")
@Operation(summary = "Get AMPs by ids")
fun getAll(
@RequestBody ids: List<Int>,
): List<AMPDataOutput> {
val amps = getAMPsByIds.execute(ids)
return amps.map { AMPDataOutput.fromAMPEntity(it) }
}

@GetMapping("/{ampId}")
@Operation(summary = "Get AMP by Id")
fun get(
@PathParam("Amp id")
@PathVariable(name = "ampId")
ampId: Int,
): AMPDataOutput? =
getAMPById.execute(id = ampId).let {
AMPDataOutput.fromAMPEntity(it)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package fr.gouv.cacem.monitorenv.infrastructure.api.endpoints.bff.v1

import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas.GetAllRegulatoryAreas
import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas.GetRegulatoryAreaById
import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas.GetRegulatoryAreasByIds
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.RegulatoryAreaWithMetadataDataOutput
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.websocket.server.PathParam
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
Expand All @@ -17,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController
class RegulatoryAreas(
private val getAllRegulatoryAreas: GetAllRegulatoryAreas,
private val getRegulatoryAreaById: GetRegulatoryAreaById,
private val getRegulatoryAreasByIds: GetRegulatoryAreasByIds,
) {
@GetMapping("/{regulatoryAreaId}")
@Operation(summary = "Get regulatory area by Id")
Expand All @@ -31,8 +36,21 @@ class RegulatoryAreas(

@GetMapping("")
@Operation(summary = "Get regulatory Areas")
fun getAll(): List<RegulatoryAreaWithMetadataDataOutput> {
val regulatoryAreas = getAllRegulatoryAreas.execute()
fun getAll(
@RequestParam(name = "withGeometry") withGeometry: Boolean,
@RequestParam(name = "zoom", required = false) zoom: Int?,
@RequestParam(name = "bbox", required = false) bbox: List<Double>?,
): List<RegulatoryAreaWithMetadataDataOutput> {
val regulatoryAreas = getAllRegulatoryAreas.execute(withGeometry, zoom, bbox)
return regulatoryAreas.map { RegulatoryAreaWithMetadataDataOutput.fromRegulatoryAreaEntity(it) }
}

@PostMapping("")
@Operation(summary = "Get regulatory Areas by ids")
fun getAll(
@RequestBody ids: List<Int>,
): List<RegulatoryAreaWithMetadataDataOutput> =
getRegulatoryAreasByIds
.execute(ids)
.map { RegulatoryAreaWithMetadataDataOutput.fromRegulatoryAreaEntity(it) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data class AMPModel(
@Column(name = "des_desigfr")
val designation: String,
@Column(name = "geom")
val geom: MultiPolygon,
val geom: MultiPolygon?,
@Column(name = "mpa_oriname")
val name: String,
@Column(name = "ref_reg")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ data class RegulatoryAreaModel(
mappedBy = "regulatoryArea",
fetch = FetchType.LAZY,
)
var tags: List<TagRegulatoryAreaModel>,
var tags: List<TagRegulatoryAreaModel> = emptyList(),
@OneToMany(
mappedBy = "regulatoryArea",
fetch = FetchType.LAZY,
)
var themes: List<ThemeRegulatoryAreaModel>,
var themes: List<ThemeRegulatoryAreaModel> = emptyList(),
@Column(name = "type") val type: String?,
@Column(name = "url") val url: String?,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,33 @@ import fr.gouv.cacem.monitorenv.domain.entities.amp.AMPEntity
import fr.gouv.cacem.monitorenv.domain.repositories.IAMPRepository
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBAMPRepository
import org.locationtech.jts.geom.Geometry
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Repository

@Repository
class JpaAMPRepository(
private val dbAMPRepository: IDBAMPRepository,
) : IAMPRepository {
override fun findAll(): List<AMPEntity> = dbAMPRepository.findAllByOrderByName().map { it.toAMP() }
override fun findAll(
withGeometry: Boolean,
zoom: Int?,
bbox: List<Double>?,
): List<AMPEntity> =
dbAMPRepository
.findAllByOrderByName(
zoom,
bbox?.get(0),
bbox?.get(1),
bbox?.get(2),
bbox?.get(3),
withGeometry,
).map { it.toAMP() }

override fun count(): Long = dbAMPRepository.count()

override fun findAllIdsByGeometry(geometry: Geometry): List<Int> = dbAMPRepository.findAllIdsByGeom(geometry)

override fun findAllByIds(ids: List<Int>): List<AMPEntity> = dbAMPRepository.findAllById(ids).map { it.toAMP() }

override fun findById(id: Int): AMPEntity? = dbAMPRepository.findByIdOrNull(id)?.toAMP()
}
Loading