Skip to content

Commit

Permalink
Merge pull request #63 from MTES-MCT/localisation-on-rapportage
Browse files Browse the repository at this point in the history
Localisation on rapportage
  • Loading branch information
thoomasbro authored Jun 29, 2022
2 parents 7944dc7 + 367d805 commit de36ee2
Show file tree
Hide file tree
Showing 67 changed files with 826 additions and 266 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package fr.gouv.cacem.monitorenv.domain.entities.missions
import org.locationtech.jts.geom.MultiPolygon
import java.time.ZonedDateTime


Expand All @@ -10,9 +11,11 @@ data class MissionEntity(
val resources: List<String>? = listOf(),
val missionStatus: String? = null,
val author: String? = null,
val closed_by: String? = null,
val observations: String? = null,
val facade: String? = null,
val theme: String? = null,
val geom: MultiPolygon? = null,
val inputStartDatetimeUtc: ZonedDateTime? = null,
val inputEndDatetimeUtc: ZonedDateTime? = null,
val actions: List<ActionEntity>? = listOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class GetControlResources(private val controlResourceRepository: IControlResourc
private val logger = LoggerFactory.getLogger(GetControlResources::class.java)

fun execute(): List<ControlResourceEntity> {
val regulatoryAreas = controlResourceRepository.findControlResources()
logger.info("Found ${regulatoryAreas.size} control topics ")
val controlResources = controlResourceRepository.findControlResources()
logger.info("Found ${controlResources.size} control resources ")

return regulatoryAreas
return controlResources
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class GetControlTopics(private val controlTopicRepository: IControlTopicReposito
private val logger = LoggerFactory.getLogger(GetControlTopics::class.java)

fun execute(): List<ControlTopicEntity> {
val regulatoryAreas = controlTopicRepository.findControlTopics()
logger.info("Found ${regulatoryAreas.size} control topics ")
val controlTopics = controlTopicRepository.findControlTopics()
logger.info("Found ${controlTopics.size} control topics ")

return regulatoryAreas
return controlTopics
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.inputs
import fr.gouv.cacem.monitorenv.domain.entities.missions.ActionEntity
import fr.gouv.cacem.monitorenv.domain.entities.missions.MissionEntity
import fr.gouv.cacem.monitorenv.domain.entities.missions.MissionTypeEnum
import org.locationtech.jts.geom.MultiPolygon
import java.time.ZonedDateTime

data class CreateOrUpdateMissionDataInput(
Expand All @@ -13,9 +14,11 @@ data class CreateOrUpdateMissionDataInput(
val resources : List<String>? = listOf(),
val missionStatus: String? = null,
val author: String? = null,
val closed_by: String? = null,
val observations: String? = null,
val facade: String? = null,
val theme: String? = null,
val geom: MultiPolygon? = null,
val inputStartDatetimeUtc: ZonedDateTime? = null,
val inputEndDatetimeUtc: ZonedDateTime? = null,
val actions: List<ActionEntity>? = null,
Expand All @@ -29,9 +32,11 @@ data class CreateOrUpdateMissionDataInput(
resources = this.resources,
missionStatus = this.missionStatus,
author = this.author,
closed_by = this.author,
observations = this.observations,
facade = this.facade,
theme = this.theme,
geom = this.geom,
inputStartDatetimeUtc = this.inputStartDatetimeUtc,
inputEndDatetimeUtc = this.inputEndDatetimeUtc,
actions = this.actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.outputs
import fr.gouv.cacem.monitorenv.domain.entities.missions.ActionEntity
import fr.gouv.cacem.monitorenv.domain.entities.missions.MissionEntity
import fr.gouv.cacem.monitorenv.domain.entities.missions.MissionTypeEnum
import org.locationtech.jts.geom.MultiPolygon

import java.time.ZonedDateTime

Expand All @@ -14,9 +15,11 @@ data class MissionDataOutput(
val resources: List<String>? = null,
val missionStatus: String? = null,
val author: String? = null,
val closed_by: String? = null,
val observations: String? = null,
val facade: String? = null,
val theme: String? = null,
val geom: MultiPolygon? = null,
val inputStartDatetimeUtc: ZonedDateTime? = null,
val inputEndDatetimeUtc: ZonedDateTime? = null,
val actions: List<ActionEntity>? = null
Expand All @@ -34,9 +37,11 @@ data class MissionDataOutput(
resources = mission.resources,
missionStatus = mission.missionStatus,
author = mission.author,
closed_by = mission.closed_by,
observations= mission.observations,
facade = mission.facade,
theme = mission.theme,
geom = mission.geom,
inputStartDatetimeUtc = mission.inputStartDatetimeUtc,
inputEndDatetimeUtc = mission.inputEndDatetimeUtc,
actions = mission.actions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fr.gouv.cacem.monitorenv.infrastructure.api.endpoints

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import fr.gouv.cacem.monitorenv.domain.use_cases.crud.missions.CreateMission
import fr.gouv.cacem.monitorenv.domain.use_cases.crud.missions.GetMissionById
import fr.gouv.cacem.monitorenv.domain.use_cases.crud.missions.GetMissions
Expand All @@ -10,6 +13,7 @@ import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.inputs.*
import io.micrometer.core.instrument.MeterRegistry
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.n52.jackson.datatype.jts.JtsModule
import org.springframework.web.bind.annotation.*
import javax.websocket.server.PathParam

Expand All @@ -21,14 +25,14 @@ class MissionsController(
private val getMissions: GetMissions,
private val getMissionById: GetMissionById,
private val updateMission: UpdateMission,
private val objectMapper: ObjectMapper,
meterRegistry: MeterRegistry
) {

@GetMapping("")
@Operation(summary = "Get missions")
fun getMissionsController(): List<MissionDataOutput> {
val missions = getMissions.execute()

return missions.map { MissionDataOutput.fromMission(it) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import javax.websocket.server.PathParam
class RegulatoryAreasController(
private val getRegulatoryAreas: GetRegulatoryAreas,
private val getRegulatoryAreaById: GetRegulatoryAreaById,
private val objectMapper: ObjectMapper,
meterRegistry: MeterRegistry
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import org.hibernate.annotations.Type
import org.hibernate.annotations.TypeDef
import org.hibernate.annotations.TypeDefs
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import fr.gouv.cacem.monitorenv.domain.entities.missions.ActionEntity
import org.locationtech.jts.geom.MultiPolygon
import org.n52.jackson.datatype.jts.GeometryDeserializer
import org.n52.jackson.datatype.jts.GeometrySerializer
import java.time.Instant
import java.time.ZoneOffset.UTC
import javax.persistence.*
Expand Down Expand Up @@ -46,12 +51,18 @@ data class MissionModel(
var missionStatus: String? = null,
@Column(name = "author")
var author: String? = null,
@Column(name = "closed_by")
var closed_by: String? = null,
@Column(name = "observations")
var observations: String? = null,
@Column(name = "facade")
var facade: String? = null,
@Column(name = "theme")
var theme: String? = null,
@JsonSerialize(using = GeometrySerializer::class)
@JsonDeserialize(contentUsing = GeometryDeserializer::class)
@Column(name = "geom")
var geom: MultiPolygon? = null,
@Column(name = "input_start_datetime_utc")
var inputStartDatetimeUtc: Instant? = null,
@Column(name = "input_end_datetime_utc")
Expand All @@ -69,9 +80,11 @@ data class MissionModel(
resources = if (resources === null) listOf() else resources,
missionStatus = missionStatus,
author = author,
closed_by = closed_by,
observations = observations,
facade = facade,
theme = theme,
geom = geom,
inputStartDatetimeUtc = inputStartDatetimeUtc?.atZone(UTC),
inputEndDatetimeUtc = inputEndDatetimeUtc?.atZone(UTC),
actions = if (actions === null) listOf() else mapper.readValue(actions, mapper.typeFactory
Expand All @@ -87,9 +100,11 @@ data class MissionModel(
resources = mission.resources,
missionStatus = mission.missionStatus,
author = mission.author,
closed_by = mission.closed_by,
observations = mission.observations,
facade = mission.facade,
theme = mission.theme,
geom = mission.geom,
inputStartDatetimeUtc = mission.inputStartDatetimeUtc?.toInstant(),
inputEndDatetimeUtc = mission.inputEndDatetimeUtc?.toInstant(),
actions = if (mission.actions === null) null else mapper.writeValueAsString(mission.actions)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE public.missions ADD COLUMN geom geometry(MULTIPOLYGON,4326);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE public.missions ADD COLUMN closed_by text;
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import java.time.ZonedDateTime
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*
import com.fasterxml.jackson.databind.ObjectMapper
import fr.gouv.cacem.monitorenv.config.MapperConfiguration
import org.locationtech.jts.geom.MultiPolygon
import org.locationtech.jts.io.WKTReader
import org.springframework.test.web.servlet.result.MockMvcResultHandlers


@Import(MeterRegistryConfiguration::class)
@Import(MeterRegistryConfiguration::class, MapperConfiguration::class)
@ExtendWith(SpringExtension::class)
@WebMvcTest(value = [(MissionsController::class)])
class MissionsControllerITests {
Expand All @@ -54,13 +57,19 @@ class MissionsControllerITests {

@Test
fun `Should create a new mission`() {

val WKTreader = WKTReader()
val multipolygonString =
"MULTIPOLYGON (((-4.54877816747593 48.305559876971, -4.54997332394943 48.3059760121399, -4.54998501370013 48.3071882334181, -4.54879290083417 48.3067746138142, -4.54877816747593 48.305559876971)))"
val Polygon = WKTreader.read(multipolygonString) as MultiPolygon
// Given
val newMission = MissionEntity(
id = 10,
missionType = MissionTypeEnum.LAND,
missionStatus = "CLOSED",
facade = "Outre-Mer",
theme = "CONTROLE",
geom = Polygon,
observations = null,
inputStartDatetimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"),
inputEndDatetimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z")
Expand All @@ -70,31 +79,40 @@ class MissionsControllerITests {
missionStatus = "CLOSED",
facade = "Outre-Mer",
theme = "CONTROLE",
geom = Polygon,
observations = null,
inputStartDatetimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"),
inputEndDatetimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z")
)

val requestbody = objectMapper.writeValueAsString(newMissionRequest)
println(requestbody)
given(this.createMission.execute(mission = any())).willReturn(newMission)
// When
mockMvc.perform(
put("/bff/v1/missions")
.content(objectMapper.writeValueAsString(newMissionRequest))
.content(requestbody)
.contentType(MediaType.APPLICATION_JSON)
)
// Then
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk)
}

@Test
fun `Should get all missions`() {
// Given
val WKTreader = WKTReader()
val multipolygonString =
"MULTIPOLYGON (((-4.54877816747593 48.305559876971, -4.54997332394943 48.3059760121399, -4.54998501370013 48.3071882334181, -4.54879290083417 48.3067746138142, -4.54877816747593 48.305559876971)))"
val Polygon = WKTreader.read(multipolygonString) as MultiPolygon

val firstMission = MissionEntity(
id = 10,
missionType = MissionTypeEnum.SEA,
missionStatus = "CLOSED",
facade = "Outre-Mer",
theme = "CONTROLE",
geom = Polygon,
observations = null,
inputStartDatetimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"),
inputEndDatetimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"),
Expand All @@ -104,6 +122,7 @@ class MissionsControllerITests {
// When
mockMvc.perform(get("/bff/v1/missions"))
// Then
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk)
.andExpect(jsonPath("$[0].id", equalTo(firstMission.id)))
.andExpect(jsonPath("$[0].missionType", equalTo(firstMission.missionType.toString())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import fr.gouv.cacem.monitorenv.domain.entities.regulatoryAreas.RegulatoryAreaEntity
import org.locationtech.jts.geom.MultiPolygon
import org.locationtech.jts.io.WKTReader
import org.springframework.test.web.servlet.result.MockMvcResultHandlers

@Import(MeterRegistryConfiguration::class)
@ExtendWith(SpringExtension::class)
Expand All @@ -46,7 +47,7 @@ class RegulatoryAreasControllerITests {
val multipolygonString =
"MULTIPOLYGON (((-4.54877816747593 48.305559876971, -4.54997332394943 48.3059760121399, -4.54998501370013 48.3071882334181, -4.54879290083417 48.3067746138142, -4.54877816747593 48.305559876971)))"
val Polygon = WKTreader.read(multipolygonString) as MultiPolygon
val regulaotyrArea = RegulatoryAreaEntity(
val regulatoryArea = RegulatoryAreaEntity(
id = 17,
geom = Polygon,
entity_name = "Zone au sud de la cale",
Expand All @@ -67,21 +68,22 @@ class RegulatoryAreasControllerITests {
objet = "",
signataire = ""
)
given(this.getRegulatoryAreas.execute()).willReturn(listOf(regulaotyrArea))
given(this.getRegulatoryAreas.execute()).willReturn(listOf(regulatoryArea))

// When
mockMvc.perform(get("/bff/v1/regulatory"))
// Then
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk)
.andExpect(jsonPath("$[0].id", equalTo(regulaotyrArea.id)))
.andExpect(jsonPath("$[0].entity_name", equalTo(regulaotyrArea.entity_name)))
.andExpect(jsonPath("$[0].layer_name", equalTo(regulaotyrArea.layer_name)))
.andExpect(jsonPath("$[0].facade", equalTo(regulaotyrArea.facade)))
.andExpect(jsonPath("$[0].ref_reg", equalTo(regulaotyrArea.ref_reg)))
.andExpect(jsonPath("$[0].thematique", equalTo(regulaotyrArea.thematique)))
.andExpect(jsonPath("$[0].echelle", equalTo(regulaotyrArea.echelle)))
.andExpect(jsonPath("$[0].date", equalTo(regulaotyrArea.date)))
.andExpect(jsonPath("$[0].duree_validite", equalTo(regulaotyrArea.duree_validite)))
.andExpect(jsonPath("$[0].id", equalTo(regulatoryArea.id)))
.andExpect(jsonPath("$[0].entity_name", equalTo(regulatoryArea.entity_name)))
.andExpect(jsonPath("$[0].layer_name", equalTo(regulatoryArea.layer_name)))
.andExpect(jsonPath("$[0].facade", equalTo(regulatoryArea.facade)))
.andExpect(jsonPath("$[0].ref_reg", equalTo(regulatoryArea.ref_reg)))
.andExpect(jsonPath("$[0].thematique", equalTo(regulatoryArea.thematique)))
.andExpect(jsonPath("$[0].echelle", equalTo(regulatoryArea.echelle)))
.andExpect(jsonPath("$[0].date", equalTo(regulatoryArea.date)))
.andExpect(jsonPath("$[0].duree_validite", equalTo(regulatoryArea.duree_validite)))
}

@Test
Expand All @@ -91,7 +93,7 @@ class RegulatoryAreasControllerITests {
val multipolygonString =
"MULTIPOLYGON (((-4.54877816747593 48.305559876971, -4.54997332394943 48.3059760121399, -4.54998501370013 48.3071882334181, -4.54879290083417 48.3067746138142, -4.54877816747593 48.305559876971)))"
val Polygon = WKTreader.read(multipolygonString) as MultiPolygon
val regulaotryArea = RegulatoryAreaEntity(
val regulatoryArea = RegulatoryAreaEntity(
id = 17,
geom = Polygon,
entity_name = "Zone au sud de la cale",
Expand All @@ -113,20 +115,20 @@ class RegulatoryAreasControllerITests {
signataire = ""
)

given(this.getRegulatoryAreaById.execute(17)).willReturn(regulaotryArea)
given(this.getRegulatoryAreaById.execute(17)).willReturn(regulatoryArea)

// When
mockMvc.perform(get("/bff/v1/regulatory/17"))
// Then
.andExpect(status().isOk)
.andExpect(jsonPath("$.id", equalTo(regulaotryArea.id)))
.andExpect(jsonPath("$.entity_name", equalTo(regulaotryArea.entity_name)))
.andExpect(jsonPath("$.url", equalTo(regulaotryArea.url)))
.andExpect(jsonPath("$.facade", equalTo(regulaotryArea.facade)))
.andExpect(jsonPath("$.thematique", equalTo(regulaotryArea.thematique)))
.andExpect(jsonPath("$.layer_name", equalTo(regulaotryArea.layer_name)))
.andExpect(jsonPath("$.ref_reg", equalTo(regulaotryArea.ref_reg)))
.andExpect(jsonPath("$.date", equalTo(regulaotryArea.date)))
.andExpect(jsonPath("$.temporalite", equalTo(regulaotryArea.temporalite)))
.andExpect(jsonPath("$.id", equalTo(regulatoryArea.id)))
.andExpect(jsonPath("$.entity_name", equalTo(regulatoryArea.entity_name)))
.andExpect(jsonPath("$.url", equalTo(regulatoryArea.url)))
.andExpect(jsonPath("$.facade", equalTo(regulatoryArea.facade)))
.andExpect(jsonPath("$.thematique", equalTo(regulatoryArea.thematique)))
.andExpect(jsonPath("$.layer_name", equalTo(regulatoryArea.layer_name)))
.andExpect(jsonPath("$.ref_reg", equalTo(regulatoryArea.ref_reg)))
.andExpect(jsonPath("$.date", equalTo(regulatoryArea.date)))
.andExpect(jsonPath("$.temporalite", equalTo(regulatoryArea.temporalite)))
}
}
Loading

0 comments on commit de36ee2

Please sign in to comment.