Skip to content
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
Expand Up @@ -133,7 +133,6 @@ class SecurityConfig(
}

private fun validateAndProcessUser(oidcUser: OidcUser): OidcUser {

if (oidcProperties.bypassEmailDomainsFilter == "true") {
logger.info("✅ OIDC is bypassing email domain checks.")
return oidcUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,21 @@ import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.LinkEntity
import fr.gouv.cacem.monitorenv.utils.WordUtils
import org.apache.poi.xwpf.usermodel.XWPFDocument
import org.apache.poi.xwpf.usermodel.XWPFTableCell
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale

data class EditableBriefVigilanceAreaEntity(
val color: String,
val comments: String? = null,
val endDatePeriod: ZonedDateTime? = null,
val endingOccurenceDate: String,
val frequency: String,
val id: Int,
val isAtAllTimes: Boolean,
override val image: String?,
val imagesAttachments: List<ImageEntity>? = null,
override val minimap: String?,
val linkedAMPs: String? = null,
val linkedRegulatoryAreas: String? = null,
val links: List<LinkEntity>? = null,
val name: String,
val startDatePeriod: ZonedDateTime? = null,
val themes: String? = null,
val visibility: String? = null,
val periods: List<EditableBriefVigilanceAreaPeriodEntity>? = null,
) : DetailWithImagesRenderable {
override val title = name

Expand All @@ -34,20 +27,26 @@ data class EditableBriefVigilanceAreaEntity(
private const val LINK_ROW_INDEX = 6
}

override fun buildDetailsRows(): List<List<String>> {
val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy", Locale.FRENCH)
val periodDate = "Du ${startDatePeriod?.format(formatter)} au ${endDatePeriod?.format(formatter)}"

return listOf(
listOf("Période", if (isAtAllTimes) "En tout temps" else periodDate),
override fun buildDetailsRows(): List<List<String>> =
listOf(
listOf(
"Période(s)",
periods?.joinToString("\n") { period ->
listOf(
period.getPeriodText(),
period.frequency,
period.endingOccurenceDate,
).filter { it.isNotEmpty() }.joinToString(", ")
}
?: "",
),
listOf("Thématique", themes ?: ""),
listOf("Visibilité", visibility ?: ""),
listOf("Commentaires", comments ?: ""),
listOf("Réglementations en lien", linkedRegulatoryAreas ?: ""),
listOf("Amps en lien", linkedAMPs ?: ""),
listOf("Liens utiles", ""),
)
}

override fun customizeValueCell(
rowIndex: Int,
Expand All @@ -62,11 +61,14 @@ data class EditableBriefVigilanceAreaEntity(
val cellRun = cell.addParagraph().createRun()
cellRun.fontFamily = "Arial"
cellRun.fontSize = 10
cellRun.setText(buildDetailsRows()[0][1])
cellRun.addBreak()
cellRun.setText(frequency)
cellRun.addBreak()
cellRun.setText(endingOccurenceDate)
val periodsText = buildDetailsRows()[0][1]
val lines = periodsText.split("\n")
lines.forEachIndexed { index, period ->
cellRun.setText(period)
if (index < lines.size - 1) {
cellRun.addBreak()
}
}
}

LINK_ROW_INDEX -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.gouv.cacem.monitorenv.domain.entities.dashboard

import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale
import java.util.UUID

data class EditableBriefVigilanceAreaPeriodEntity(
val id: UUID,
val isAtAllTimes: Boolean,
val startDatePeriod: ZonedDateTime? = null,
val endDatePeriod: ZonedDateTime? = null,
val endingOccurenceDate: String,
val frequency: String,
) {
fun getPeriodDate(): String {
val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy", Locale.FRENCH)
return "Du ${startDatePeriod?.format(formatter)} au ${endDatePeriod?.format(formatter)}"
}

fun getPeriodText(): String = if (isAtAllTimes) "En tout temps" else getPeriodDate()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ import java.time.ZonedDateTime
data class VigilanceAreaEntity(
val id: Int? = null,
val comments: String? = null,
val computedEndDate: ZonedDateTime? = null,
val createdBy: String? = null,
val endDatePeriod: ZonedDateTime? = null,
val endingCondition: EndingConditionEnum? = null,
val endingOccurrenceDate: ZonedDateTime? = null,
val endingOccurrencesNumber: Int? = null,
val frequency: FrequencyEnum? = null,
val geom: MultiPolygon? = null,
val images: List<ImageEntity>? = listOf(),
val isAtAllTimes: Boolean,
val isArchived: Boolean,
val isDeleted: Boolean,
val isDraft: Boolean,
val links: List<LinkEntity>? = null,
Expand All @@ -27,9 +19,9 @@ data class VigilanceAreaEntity(
val name: String,
val seaFront: String? = null,
val sources: List<VigilanceAreaSourceEntity>,
val startDatePeriod: ZonedDateTime? = null,
val themes: List<ThemeEntity>,
val tags: List<TagEntity>,
val periods: List<VigilanceAreaPeriodEntity>,
val visibility: VisibilityEnum? = null,
val createdAt: ZonedDateTime?,
val updatedAt: ZonedDateTime?,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea

import java.time.ZonedDateTime
import java.util.UUID

data class VigilanceAreaPeriodEntity(
val id: UUID?,
val computedEndDate: ZonedDateTime?,
val endDatePeriod: ZonedDateTime?,
val endingCondition: EndingConditionEnum?,
val endingOccurrenceDate: ZonedDateTime?,
val endingOccurrencesNumber: Int?,
val frequency: FrequencyEnum?,
val isAtAllTimes: Boolean,
val isCritical: Boolean?,
val startDatePeriod: ZonedDateTime?,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import fr.gouv.cacem.monitorenv.domain.use_cases.dashboard.SaveDashboard
import fr.gouv.cacem.monitorenv.domain.validators.UseCaseValidation
import fr.gouv.cacem.monitorenv.domain.validators.vigilance_area.VigilanceAreaValidator
import org.slf4j.LoggerFactory
import java.time.ZonedDateTime

@UseCase
class CreateOrUpdateVigilanceArea(
Expand All @@ -29,12 +28,7 @@ class CreateOrUpdateVigilanceArea(
vigilanceArea.geom?.let { nonNullGeom ->
facadeAreasRepository.findFacadeFromGeometry(nonNullGeom)
}
var vigilanceAreaToSave = vigilanceArea.copy(seaFront = seaFront)
if (vigilanceArea.isArchived &&
(vigilanceArea.computedEndDate?.isAfter(ZonedDateTime.now()) == true || vigilanceArea.isAtAllTimes)
) {
vigilanceAreaToSave = vigilanceAreaToSave.copy(isArchived = false)
}
val vigilanceAreaToSave = vigilanceArea.copy(seaFront = seaFront)

val savedVigilanceArea =
vigilanceAreaRepository.save(vigilanceAreaToSave)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,46 +48,48 @@ class VigilanceAreaValidator : Validator<VigilanceAreaEntity> {
data = "Un tag ou un thème est obligatoire",
)
}
if (!vigilanceArea.isAtAllTimes) {
if (vigilanceArea.startDatePeriod === null) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "La date de début est obligatoire",
)
}
if (vigilanceArea.endDatePeriod === null) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "La date de fin est obligatoire",
)
}
if (vigilanceArea.frequency === null) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "La fréquence est obligatoire",
)
}
if (vigilanceArea.frequency !== FrequencyEnum.NONE && vigilanceArea.endingCondition === null) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "La condition de fin est obligatoire",
)
}
if (vigilanceArea.endingCondition === EndingConditionEnum.END_DATE &&
vigilanceArea.endingOccurrenceDate === null
) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "La date de fin de l'occurence est obligatoire",
)
}
if (vigilanceArea.endingCondition === EndingConditionEnum.OCCURENCES_NUMBER &&
(vigilanceArea.endingOccurrencesNumber === null || vigilanceArea.endingOccurrencesNumber == 0)
) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "Le nombre d'occurence est obligatoire",
)
vigilanceArea.periods.forEach { period ->
if (!period.isAtAllTimes) {
if (period.startDatePeriod === null) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "La date de début est obligatoire",
)
}
if (period.endDatePeriod === null) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "La date de fin est obligatoire",
)
}
if (period.frequency === null) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "La fréquence est obligatoire",
)
}
if (period.frequency !== FrequencyEnum.NONE && period.endingCondition === null) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "La condition de fin est obligatoire",
)
}
if (period.endingCondition === EndingConditionEnum.END_DATE &&
period.endingOccurrenceDate === null
) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "La date de fin de l'occurence est obligatoire",
)
}
if (period.endingCondition === EndingConditionEnum.OCCURENCES_NUMBER &&
(period.endingOccurrencesNumber === null || period.endingOccurrencesNumber == 0)
) {
throw BackendUsageException(
code = BackendUsageErrorCode.UNVALID_PROPERTY,
data = "Le nombre d'occurence est obligatoire",
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.inputs.vigilanceArea

import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.EndingConditionEnum
import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.FrequencyEnum
import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.LinkEntity
import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.VigilanceAreaEntity
import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.VisibilityEnum
Expand All @@ -13,16 +11,8 @@ import java.time.ZonedDateTime
data class VigilanceAreaDataInput(
val id: Int? = null,
val comments: String? = null,
val computedEndDate: ZonedDateTime? = null,
val createdBy: String? = null,
val endDatePeriod: ZonedDateTime? = null,
val endingCondition: EndingConditionEnum? = null,
val endingOccurrenceDate: ZonedDateTime? = null,
val endingOccurrencesNumber: Int? = null,
val frequency: FrequencyEnum? = null,
val geom: MultiPolygon? = null,
val isArchived: Boolean,
val isAtAllTimes: Boolean,
val isDraft: Boolean,
val images: List<ImageDataInput>? = listOf(),
val links: List<LinkEntity>? = null,
Expand All @@ -31,28 +21,20 @@ data class VigilanceAreaDataInput(
val name: String,
val seaFront: String?,
val sources: List<VigilanceAreaSourceInput>,
val startDatePeriod: ZonedDateTime? = null,
val themes: List<ThemeInput> = listOf(),
val visibility: VisibilityEnum? = null,
val createdAt: ZonedDateTime? = null,
val updatedAt: ZonedDateTime? = null,
val tags: List<TagInput> = listOf(),
val validatedAt: ZonedDateTime? = null,
val periods: List<VigilanceAreaDataPeriodInput> = listOf(),
) {
fun toVigilanceAreaEntity(): VigilanceAreaEntity =
VigilanceAreaEntity(
id = this.id,
comments = this.comments,
computedEndDate = this.computedEndDate,
createdBy = this.createdBy,
endDatePeriod = this.endDatePeriod,
endingCondition = this.endingCondition,
endingOccurrenceDate = this.endingOccurrenceDate,
endingOccurrencesNumber = this.endingOccurrencesNumber,
frequency = this.frequency,
geom = this.geom,
isAtAllTimes = this.isAtAllTimes,
isArchived = this.isArchived,
isDeleted = false,
isDraft = this.isDraft,
images = this.images?.map { image -> image.toImageEntity() },
Expand All @@ -62,12 +44,12 @@ data class VigilanceAreaDataInput(
name = this.name,
seaFront = this.seaFront,
sources = this.sources.map { it.toVigilanceAreaSourceEntity() },
startDatePeriod = this.startDatePeriod,
themes = this.themes.map { it.toThemeEntity() },
visibility = this.visibility,
createdAt = this.createdAt,
updatedAt = this.updatedAt,
tags = tags.map { it.toTagEntity() },
validatedAt = this.validatedAt,
periods = periods.map { it.toVigilanceAreaPeriodEntity() },
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.inputs.vigilanceArea

import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.EndingConditionEnum
import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.FrequencyEnum
import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.VigilanceAreaPeriodEntity
import java.time.ZonedDateTime
import java.util.UUID

data class VigilanceAreaDataPeriodInput(
val id: UUID?,
val computedEndDate: ZonedDateTime? = null,
val endDatePeriod: ZonedDateTime? = null,
val endingCondition: EndingConditionEnum? = null,
val endingOccurrenceDate: ZonedDateTime? = null,
val endingOccurrencesNumber: Int? = null,
val frequency: FrequencyEnum? = null,
val isAtAllTimes: Boolean,
val isCritical: Boolean?,
val startDatePeriod: ZonedDateTime? = null,
) {
fun toVigilanceAreaPeriodEntity(): VigilanceAreaPeriodEntity =
VigilanceAreaPeriodEntity(
id = this.id,
computedEndDate = this.computedEndDate,
endDatePeriod = this.endDatePeriod,
endingCondition = this.endingCondition,
endingOccurrenceDate = this.endingOccurrenceDate,
endingOccurrencesNumber = this.endingOccurrencesNumber,
frequency = this.frequency,
isAtAllTimes = this.isAtAllTimes,
isCritical = this.isCritical,
startDatePeriod = this.startDatePeriod,
)
}
Loading
Loading