Skip to content

Commit

Permalink
[Signalements] Ajout du backend signalements (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
thoomasbro authored Oct 12, 2023
2 parents 60b08a4 + 132a732 commit 254c585
Show file tree
Hide file tree
Showing 64 changed files with 2,305 additions and 938 deletions.
28 changes: 14 additions & 14 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<version>3.1.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>fr.gouv.cacem</groupId>
Expand All @@ -16,9 +16,9 @@

<properties>
<java.version>17</java.version>
<spring.version>3.1.2</spring.version>
<kotlin.version>1.8.21</kotlin.version>
<testcontainers.version>1.18.3</testcontainers.version>
<spring.version>${project.parent.version}</spring.version>
<kotlin.version>1.9.10</kotlin.version>
<testcontainers.version>1.19.0</testcontainers.version>
<commit.hash>COMMIT_TO_CHANGE</commit.hash>
<main.class>fr.gouv.cacem.monitorenv.MonitorEnvApplicationKt</main.class>
</properties>
Expand All @@ -38,7 +38,7 @@
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.0.Final</version>
<version>8.0.1.Final</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
Expand Down Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>6.1.7.Final</version>
<version>6.2.9.Final</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
Expand Down Expand Up @@ -106,7 +106,7 @@
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>9.19.0</version>
<version>9.22.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
Expand All @@ -128,7 +128,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.5.4</version>
<version>42.6.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
Expand All @@ -140,7 +140,7 @@
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>1.7.1</version>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>com.neovisionaries</groupId>
Expand Down Expand Up @@ -200,11 +200,11 @@
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
</dependency>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-60</artifactId>
<version>2.21.1</version>
</dependency>
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-62</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.EnableScheduling

@ConditionalOnProperty(
value = ["monitorenv.scheduling.enable"],
value = ["monitorenv.scheduling.enabled"],
havingValue = "true",
matchIfMissing = true,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ data class ControlUnitResourceEntity(
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as ControlUnitResourceEntity

if (id != other.id) return false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fr.gouv.cacem.monitorenv.domain.entities.reporting

enum class ControlStatusEnum {
CONTROL_TO_BE_DONE,
CONTROL_DONE,
SURVEILLANCE_DONE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package fr.gouv.cacem.monitorenv.domain.entities.reporting
import fr.gouv.cacem.monitorenv.domain.entities.VehicleTypeEnum
import org.locationtech.jts.geom.Geometry
import java.time.ZonedDateTime
import java.util.UUID

data class ReportingEntity(
val id: Int? = null,
val reportingId: Int? = null,
val reportingId: Long? = null,
val sourceType: SourceTypeEnum? = null,
val semaphoreId: Int? = null,
val controlUnitId: Int? = null,
Expand All @@ -22,12 +23,16 @@ data class ReportingEntity(
val subThemes: List<String>? = listOf(),
val actionTaken: String? = null,
val isControlRequired: Boolean? = null,
val isUnitAvailable: Boolean? = null,
val hasNoUnitAvailable: Boolean? = null,
val createdAt: ZonedDateTime,
val validityTime: Int? = null,
val isArchived: Boolean,
val isDeleted: Boolean,
val openBy: String? = null,
val missionId: Int? = null,
val attachedToMissionAtUtc: ZonedDateTime? = null,
val detachedFromMissionAtUtc: ZonedDateTime? = null,
val attachedEnvActionId: UUID? = null,
) {
fun checkValidity() {
when (sourceType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ import java.util.UUID
object EnvActionMapper {
private const val jsonbNullString = "null"

fun getEnvActionEntityFromJSON(mapper: ObjectMapper, id: UUID, actionStartDateTimeUtc: ZonedDateTime?, actionEndDateTimeUtc: ZonedDateTime?, geom: Geometry?, actionType: ActionTypeEnum, facade: String?, department: String?, value: String?): EnvActionEntity {
fun getEnvActionEntityFromJSON(
mapper: ObjectMapper,
id: UUID,
actionStartDateTimeUtc: ZonedDateTime?,
actionEndDateTimeUtc: ZonedDateTime?,
geom: Geometry?,
actionType: ActionTypeEnum,
facade: String?,
department: String?,
value: String?,
): EnvActionEntity {
return try {
if (!value.isNullOrEmpty() && value != jsonbNullString) {
when (actionType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package fr.gouv.cacem.monitorenv.domain.repositories

import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity
import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum
import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO
import org.springframework.data.domain.Pageable
import java.time.Instant

interface IMissionRepository {
fun findById(missionId: Int): MissionEntity
fun findById(missionId: Int): MissionDTO
fun findAll(
startedAfter: Instant,
startedBefore: Instant?,
Expand All @@ -15,9 +16,9 @@ interface IMissionRepository {
missionSources: List<MissionSourceEnum>? = null,
seaFronts: List<String>?,
pageable: Pageable,
): List<MissionEntity>
): List<MissionDTO>

fun save(mission: MissionEntity): MissionEntity
fun save(mission: MissionEntity): MissionDTO
fun delete(missionId: Int)
fun count(): Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ package fr.gouv.cacem.monitorenv.domain.repositories
import fr.gouv.cacem.monitorenv.domain.entities.reporting.ReportingEntity
import fr.gouv.cacem.monitorenv.domain.entities.reporting.ReportingTypeEnum
import fr.gouv.cacem.monitorenv.domain.entities.reporting.SourceTypeEnum
import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingDTO
import org.springframework.data.domain.Pageable
import java.time.Instant

interface IReportingRepository {
fun findById(reportingId: Int): ReportingEntity
fun archiveOutdatedReportings(): Int

fun archiveReportings(ids: List<Int>)

fun attachReportingsToMission(reportingIds: List<Int>, missionId: Int)

fun count(): Long

fun delete(reportingId: Int)

fun deleteReportings(ids: List<Int>)

fun findAll(
pageable: Pageable,
reportingType: List<ReportingTypeEnum>?,
Expand All @@ -16,11 +28,11 @@ interface IReportingRepository {
startedAfter: Instant,
startedBefore: Instant?,
status: List<String>?,
): List<ReportingEntity>
fun save(reporting: ReportingEntity): ReportingEntity
fun delete(reportingId: Int)
fun count(): Long
fun archiveOutdatedReportings(): Int
fun archiveReportings(ids: List<Int>)
fun deleteReportings(ids: List<Int>)
): List<ReportingDTO>

fun findByMissionId(missionId: Int): List<ReportingDTO>

fun findById(reportingId: Int): ReportingDTO

fun save(reporting: ReportingEntity): ReportingDTO
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IBaseRepository
import fr.gouv.cacem.monitorenv.domain.repositories.IDepartmentAreaRepository
import fr.gouv.cacem.monitorenv.domain.repositories.IFacadeAreasRepository
import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository
import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository
import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO

@UseCase
class CreateOrUpdateMission(
private val baseRepository: IBaseRepository,
private val departmentRepository: IDepartmentAreaRepository,
private val missionRepository: IMissionRepository,
private val facadeRepository: IFacadeAreasRepository,
private val reportingRepository: IReportingRepository,

) {
@Throws(IllegalArgumentException::class)
fun execute(mission: MissionEntity?): MissionEntity {
fun execute(mission: MissionEntity?, attachedReportingIds: List<Int>? = null): MissionDTO {
require(mission != null) {
"No mission to create or update"
}
Expand Down Expand Up @@ -76,7 +79,16 @@ class CreateOrUpdateMission(
facade = facade,
envActions = envActions,
)
val savedMission = missionRepository.save(missionToSave)

return missionRepository.save(missionToSave)
if (savedMission.mission.id == null) {
throw IllegalArgumentException("Mission id is null")
}

if (attachedReportingIds != null) {
reportingRepository.attachReportingsToMission(attachedReportingIds, savedMission.mission.id)
}

return missionRepository.findById(savedMission.mission.id)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package fr.gouv.cacem.monitorenv.domain.use_cases.missions // ktlint-disable package-name
@file:Suppress("ktlint:standard:package-name")

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

import fr.gouv.cacem.monitorenv.config.UseCase
import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitEntity
Expand All @@ -22,7 +24,7 @@ class GetEngagedControlUnits(private val getMissions: GetMissions) {
)

val controlUnits = openedMissions
.map { it.controlUnits }
.map { it.mission.controlUnits }
.flatten()
.distinctBy { it.id }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
package fr.gouv.cacem.monitorenv.domain.use_cases.missions

import fr.gouv.cacem.monitorenv.config.UseCase
import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity
import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository
import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO

@UseCase
class GetMissionById(private val missionRepository: IMissionRepository) {
fun execute(missionId: Int): MissionEntity {
fun execute(missionId: Int): MissionDTO {
return missionRepository.findById(missionId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
package fr.gouv.cacem.monitorenv.domain.use_cases.missions

import fr.gouv.cacem.monitorenv.config.UseCase
import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity
import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum
import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository
import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO
import org.slf4j.LoggerFactory
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Pageable
Expand All @@ -24,7 +24,7 @@ class GetMissions(private val missionRepository: IMissionRepository) {
pageNumber: Int?,
pageSize: Int?,
seaFronts: List<String>?,
): List<MissionEntity> {
): List<MissionDTO> {
val missions = missionRepository.findAll(
startedAfter = startedAfterDateTime?.toInstant() ?: ZonedDateTime.now().minusDays(30).toInstant(),
startedBefore = startedBeforeDateTime?.toInstant(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
package fr.gouv.cacem.monitorenv.domain.use_cases.missions

import fr.gouv.cacem.monitorenv.config.UseCase
import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity
import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum
import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository
import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO
import org.slf4j.LoggerFactory
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Pageable
Expand All @@ -24,7 +24,7 @@ class GetMonitorEnvMissions(private val missionRepository: IMissionRepository) {
pageNumber: Int?,
pageSize: Int?,
seaFronts: List<String>?,
): List<MissionEntity> {
): List<MissionDTO> {
val missions = missionRepository.findAll(
startedAfter = startedAfterDateTime?.toInstant() ?: ZonedDateTime.now().minusDays(30).toInstant(),
startedBefore = startedBeforeDateTime?.toInstant(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos

import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity
import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingDTO

data class MissionDTO(
val mission: MissionEntity,
val attachedReportings: List<ReportingDTO>? = listOf(),
val attachedReportingIds: List<Int>? = listOf(),
val detachedReportings: List<ReportingDTO>? = listOf(),
val detachedReportingIds: List<Int>? = listOf(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.reportings

import fr.gouv.cacem.monitorenv.config.UseCase
import fr.gouv.cacem.monitorenv.domain.entities.reporting.ReportingEntity
import fr.gouv.cacem.monitorenv.domain.entities.semaphore.SemaphoreEntity
import fr.gouv.cacem.monitorenv.domain.repositories.*
import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.dtos.FullControlUnitDTO
import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingDTO
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Expand All @@ -14,11 +13,12 @@ class CreateOrUpdateReporting(
private val controlUnitRepository: IControlUnitRepository,
private val semaphoreRepository: ISemaphoreRepository,
private val facadeRepository: IFacadeAreasRepository,
private val missionRepository: IMissionRepository,
) {
private val logger: Logger = LoggerFactory.getLogger(CreateOrUpdateReporting::class.java)

@Throws(IllegalArgumentException::class)
fun execute(reporting: ReportingEntity?): Triple<ReportingEntity, FullControlUnitDTO?, SemaphoreEntity?> {
fun execute(reporting: ReportingEntity?): ReportingDTO {
require(reporting != null) {
"No reporting to create or update"
}
Expand All @@ -32,11 +32,6 @@ class CreateOrUpdateReporting(

val savedReport = reportingRepository.save(reporting.copy(seaFront = seaFront))

val fullControlUnit =
if (savedReport.controlUnitId != null) controlUnitRepository.findById(savedReport.controlUnitId) else null
val semaphore =
if (savedReport.semaphoreId != null) semaphoreRepository.findById(savedReport.semaphoreId) else null

return Triple(savedReport, fullControlUnit, semaphore)
return savedReport
}
}
Loading

0 comments on commit 254c585

Please sign in to comment.