Skip to content

Commit

Permalink
[Missions] Ajout des autres actions de contrôle en lien avec RapportN…
Browse files Browse the repository at this point in the history
…av (#828)

- Resolve #820
  • Loading branch information
thoomasbro committed Oct 17, 2023
2 parents fa7b9b3 + 238269c commit c35ded2
Show file tree
Hide file tree
Showing 23 changed files with 398 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ data class EnvActionControlEntity(
override val geom: Geometry? = null,
override val facade: String? = null,
override val department: String? = null,
override val isAdministrativeControl: Boolean? = null,
override val isComplianceWithWaterRegulationsControl: Boolean? = null,
override val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null,
override val isSeafarersControl: Boolean? = null,
val themes: List<ThemeEntity>? = listOf(),
val observations: String? = null,
val actionNumberOfControls: Int? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ data class EnvActionControlProperties(
facade: String?,
department: String?,
geom: Geometry?,
isAdministrativeControl: Boolean?,
isComplianceWithWaterRegulationsControl: Boolean?,
isSafetyEquipmentAndStandardsComplianceControl: Boolean?,
isSeafarersControl: Boolean?,
) = EnvActionControlEntity(
id = id,
actionStartDateTimeUtc = actionStartDateTimeUtc,
Expand All @@ -33,7 +37,12 @@ data class EnvActionControlProperties(
actionTargetType = actionTargetType,
vehicleType = vehicleType,
infractions = infractions,
isAdministrativeControl = isAdministrativeControl,
isComplianceWithWaterRegulationsControl = isComplianceWithWaterRegulationsControl,
isSafetyEquipmentAndStandardsComplianceControl = isSafetyEquipmentAndStandardsComplianceControl,
isSeafarersControl = isSeafarersControl,
)

companion object {
fun fromEnvActionControlEntity(envAction: EnvActionControlEntity) = EnvActionControlProperties(
themes = envAction.themes,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package fr.gouv.cacem.monitorenv.domain.entities.mission

import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
import org.locationtech.jts.geom.Geometry
Expand All @@ -24,4 +25,8 @@ abstract class EnvActionEntity(
open val department: String? = null,
open val facade: String? = null,
open val geom: Geometry? = null,
open val isAdministrativeControl: Boolean? = null,
open val isComplianceWithWaterRegulationsControl: Boolean? = null,
open val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null,
open val isSeafarersControl: Boolean? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ object EnvActionMapper {
facade: String?,
department: String?,
value: String?,
isAdministrativeControl: Boolean?,
isComplianceWithWaterRegulationsControl: Boolean?,
isSafetyEquipmentAndStandardsComplianceControl: Boolean?,
isSeafarersControl: Boolean?,
): EnvActionEntity {
return try {
if (!value.isNullOrEmpty() && value != jsonbNullString) {
Expand All @@ -54,6 +58,10 @@ object EnvActionMapper {
facade,
department,
geom,
isAdministrativeControl,
isComplianceWithWaterRegulationsControl,
isSafetyEquipmentAndStandardsComplianceControl,
isSeafarersControl,
)
ActionTypeEnum.NOTE -> mapper.readValue(
value,
Expand All @@ -67,6 +75,7 @@ object EnvActionMapper {
throw EntityConversionException("Error while converting 'action'. $value", e)
}
}

fun envActionEntityToJSON(mapper: ObjectMapper, envAction: EnvActionEntity): String {
return try {
when (envAction.actionType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.inputs

import fr.gouv.cacem.monitorenv.domain.entities.VehicleTypeEnum
import fr.gouv.cacem.monitorenv.domain.entities.mission.ActionTargetTypeEnum
import fr.gouv.cacem.monitorenv.domain.entities.mission.ActionTypeEnum
import fr.gouv.cacem.monitorenv.domain.entities.mission.EnvActionControlEntity
import fr.gouv.cacem.monitorenv.domain.entities.mission.EnvActionEntity
import fr.gouv.cacem.monitorenv.domain.entities.mission.EnvActionNoteEntity
import fr.gouv.cacem.monitorenv.domain.entities.mission.EnvActionSurveillanceEntity
import fr.gouv.cacem.monitorenv.domain.entities.mission.InfractionEntity
import fr.gouv.cacem.monitorenv.domain.entities.mission.ThemeEntity
import org.locationtech.jts.geom.Geometry
import java.time.ZonedDateTime
import java.util.UUID

data class CreateOrUpdateEnvActionDataInput(
val id: UUID,
val actionType: ActionTypeEnum,
val actionStartDateTimeUtc: ZonedDateTime? = null,
val actionEndDateTimeUtc: ZonedDateTime? = null,
val department: String? = null,
val facade: String? = null,
val geom: Geometry? = null,
val observations: String? = null,
val isAdministrativeControl: Boolean? = false,
val isComplianceWithWaterRegulationsControl: Boolean? = false,
val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = false,
val isSeafarersControl: Boolean? = false,
val themes: List<ThemeEntity>? = listOf(),
val actionNumberOfControls: Int? = null,
val actionTargetType: ActionTargetTypeEnum? = null,
val vehicleType: VehicleTypeEnum? = null,
val infractions: List<InfractionEntity>? = listOf(),
val coverMissionZone: Boolean? = null,
) {
fun toEnvActionEntity(): EnvActionEntity {
if (this.actionType == null) throw IllegalArgumentException("actionType is required")

when (actionType) {
ActionTypeEnum.CONTROL -> {
return EnvActionControlEntity(
id = id,
actionStartDateTimeUtc = actionStartDateTimeUtc,
actionEndDateTimeUtc = actionEndDateTimeUtc,
department = department,
facade = facade,
geom = geom,
isAdministrativeControl = isAdministrativeControl ?: false,
isComplianceWithWaterRegulationsControl = isComplianceWithWaterRegulationsControl ?: false,
isSafetyEquipmentAndStandardsComplianceControl = isSafetyEquipmentAndStandardsComplianceControl ?: false,
isSeafarersControl = isSeafarersControl ?: false,
themes = themes,
observations = observations,
actionNumberOfControls = actionNumberOfControls,
actionTargetType = actionTargetType,
vehicleType = vehicleType,
infractions = infractions,
)
}
ActionTypeEnum.SURVEILLANCE -> {
return EnvActionSurveillanceEntity(
id = id,
actionStartDateTimeUtc = actionStartDateTimeUtc,
actionEndDateTimeUtc = actionEndDateTimeUtc,
department = department,
facade = facade,
geom = geom,
themes = themes,
observations = observations,
coverMissionZone = coverMissionZone,
)
}
ActionTypeEnum.NOTE -> {
return EnvActionNoteEntity(
id = id,
actionStartDateTimeUtc = actionStartDateTimeUtc,
actionEndDateTimeUtc = actionEndDateTimeUtc,
observations = observations,
)
}
else -> {
throw IllegalArgumentException("actionType $actionType is not valid")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,46 @@ data class EnvActionModel(
@Type(JsonBinaryType::class)
@Column(name = "value", columnDefinition = "jsonb")
val value: String,

@Column(name = "facade")
val facade: String? = null,

@Column(name = "department")
val department: String? = null,

@ManyToOne(fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "mission_id")
@JsonBackReference
val mission: MissionModel,

@Column(name = "is_administrative_control")
val isAdministrativeControl: Boolean? = null,

@Column(name = "is_compliance_with_water_regulations_control")
val isComplianceWithWaterRegulationsControl: Boolean? = null,

@Column(name = "is_safety_equipment_and_standards_compliance_control")
val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null,

@Column(name = "is_seafarers_control")
val isSeafarersControl: Boolean? = null,
) {

fun toActionEntity(mapper: ObjectMapper): EnvActionEntity {
return EnvActionMapper.getEnvActionEntityFromJSON(
mapper,
id,
actionStartDateTime?.atZone(UTC),
actionEndDateTime?.atZone(UTC),
geom,
actionType,
facade,
department,
value,
mapper = mapper,
id = id,
actionStartDateTimeUtc = actionStartDateTime?.atZone(UTC),
actionEndDateTimeUtc = actionEndDateTime?.atZone(UTC),
geom = geom,
actionType = actionType,
facade = facade,
department = department,
value = value,
isAdministrativeControl = isAdministrativeControl,
isComplianceWithWaterRegulationsControl = isComplianceWithWaterRegulationsControl,
isSafetyEquipmentAndStandardsComplianceControl = isSafetyEquipmentAndStandardsComplianceControl,
isSeafarersControl = isSeafarersControl,
)
}
companion object {
Expand All @@ -95,6 +113,10 @@ data class EnvActionModel(
value = EnvActionMapper.envActionEntityToJSON(mapper, action),
mission = mission,
geom = action.geom,
isAdministrativeControl = action.isAdministrativeControl,
isComplianceWithWaterRegulationsControl = action.isComplianceWithWaterRegulationsControl,
isSafetyEquipmentAndStandardsComplianceControl = action.isSafetyEquipmentAndStandardsComplianceControl,
isSeafarersControl = action.isSeafarersControl,
)
}

Expand All @@ -110,6 +132,6 @@ data class EnvActionModel(

@Override
override fun toString(): String {
return this::class.simpleName + "(id = $id , geom = $geom , actionStartDateTime = $actionStartDateTime, actionEndDateTime = $actionEndDateTime, actionType = $actionType , value = $value )"
return this::class.simpleName + "(id = $id , geom = $geom , actionStartDateTime = $actionStartDateTime, actionEndDateTime = $actionEndDateTime, actionType = $actionType , value = $value, facade = $facade, department = $department, isAdministrativeControl = $isAdministrativeControl, isComplianceWithWaterRegulationsControl = $isComplianceWithWaterRegulationsControl, isSeafarersControl = $isSeafarersControl, isSafetyEquipmentAndStandardsComplianceControl = $isSafetyEquipmentAndStandardsComplianceControl )"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE env_actions
ADD COLUMN is_administrative_control boolean,
ADD COLUMN is_compliance_with_water_regulations_control boolean,
ADD COLUMN is_safety_equipment_and_standards_compliance_control boolean,
ADD COLUMN is_seafarers_control boolean;
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ VALUES
(10006, 1005, false, 'SML 33'),
(10007, 1005, false, 'SML 50'),
(10008, 1005, false, 'Police de l''eau – DDTM 11'),
(10009, 1009, false, 'PAM Jeanne Barret'),
(10010, 1009, false, 'PAM Themis'),
(10011, 1009, false, 'Cross Etel'),
(10012, 1009, false, 'Cross Gris Nez'),
(10013, 2, true, 'BGC Ajaccio'),
Expand All @@ -37,7 +35,13 @@ VALUES
(10031, 1004, false, 'Réserve Naturelle 7 Iles'),
(10032, 1005, false, 'Cultures marines – DDTM 30');

SELECT setval('control_units_id_seq', 10032, true);
INSERT INTO public.control_units(
id, administration_id, name) VALUES
( 10121, 1009, 'PAM Jeanne Barret'),
( 10080, 1009, 'PAM Themis');


SELECT setval('control_units_id_seq', (SELECT max(id) FROM control_units), true);

INSERT INTO public.control_unit_contacts
( id, control_unit_id, name)
Expand All @@ -58,8 +62,8 @@ VALUES
( 5, 10002, 'Voiture', 3, 'CAR'),
( 6, 10003, 'AR VECHEN', 2, 'FRIGATE'),
( 7, 10003, 'Semi-rigide', 3, 'BARGE'),
( 8, 10010, 'PAM Jeanne Barret', 3, 'FRIGATE'),
( 9, 10011, 'PAM Themis', 3, 'FRIGATE'),
( 8, 10121, 'PAM Jeanne Barret', 3, 'FRIGATE'),
( 9, 10080, 'PAM Themis', 3, 'FRIGATE'),
( 10, 10018, 'ALTAIR', 3, 'FRIGATE'),
( 11, 10018, 'PHEROUSA', 3, 'FRIGATE'),
( 12, 10018, 'ARIOLA', 3, 'FRIGATE');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ INSERT INTO missions_control_units
(mission_id, control_unit_id)
VALUES
( 0, 10002),
( 1, 10011),
( 1, 10080),
( 2, 10002),
( 3, 10004),
( 4, 10003),
Expand All @@ -82,10 +82,10 @@ VALUES
( 19, 10018),
( 20, 10002),
( 21, 10018),
( 22, 10010),
( 23, 10010),
( 22, 10121),
( 23, 10121),
( 24, 10000),
( 26, 10011),
( 26, 10080),
( 27, 10003),
( 28, 10019),
( 29, 10018),
Expand All @@ -105,7 +105,7 @@ VALUES
( 44, 10003),
( 45, 10014),
( 46, 10018),
( 48, 10011),
( 48, 10080),
( 49, 10002),
( 50, 10002),
( 51, 10002),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ INSERT INTO public.env_actions VALUES ('6d4b7d0a-79ce-47cf-ac26-2024d2b27f28', 4
INSERT INTO public.env_actions VALUES ('b8007c8a-5135-4bc3-816f-c69c7b75d807', 34, 'SURVEILLANCE', '{"themes": [{"theme": "Police des espèces protégées et de leurs habitats (faune et flore)", "subThemes": ["Destruction, capture, arrachage", "Atteinte aux habitats d''espèces protégées"], "protectedSpecies": ["FLORA", "BIRDS"]}, {"theme": "Police des mouillages", "subThemes": ["Mouillage individuel", "ZMEL"], "protectedSpecies": []}], "duration": 0.0, "observations": "RAS", "coverMissionZone": true, "protectedSpecies": []}', '2022-07-16 10:03:12.588693', NULL, NULL, NULL, '2022-07-16 12:03:12.588693');
INSERT INTO public.env_actions VALUES ('c52c6f20-e495-4b29-b3df-d7edfb67fdd7', 34, 'CONTROL', '{"themes": [{"theme": "Police des mouillages", "subThemes": ["Mouillage individuel", "ZMEL"], "protectedSpecies": []}], "observations": "RAS", "infractions": [{"id": "5d5b7829-68cd-4436-8c0b-1cc8db7788a0", "natinf": ["10038","10231"], "toProcess": false, "vesselSize": "FROM_24_TO_46m", "vesselType": "COMMERCIAL", "companyName": null, "formalNotice": "PENDING", "observations": "Pas d''observations", "relevantCourt": "LOCAL_COURT", "infractionType": "WITH_REPORT", "registrationNumber": "BALTIK", "controlledPersonIdentity": "John Doe"}], "vehicleType": "VESSEL", "actionTargetType": "VEHICLE", "actionNumberOfControls": 1}', '2022-07-16 09:03:12.588693', '0104000020E610000001000000010100000047A07E6651E3DEBF044620AB65C54840', NULL, NULL, '2022-07-16 12:03:12.588693');

INSERT INTO public.env_actions VALUES ('4d9a3139-6c60-49a5-b443-0e6238a6a120', 41, 'CONTROL', '{"themes": [{"theme": "Police des mouillages", "subThemes": ["Contrôle administratif"], "protectedSpecies": []}], "infractions": [], "vehicleType": null, "observations": "", "actionTargetType": null, "actionNumberOfControls": null}','2022-07-01 02:44:16.588693', NULL, NULL, NULL, NULL, TRUE, TRUE, TRUE, TRUE);

UPDATE public.env_actions SET
action_start_datetime_utc = action_start_datetime_utc + (now() - '2022-06-01 23:00:00'),
action_end_datetime_utc = action_end_datetime_utc + (now() - '2022-06-01 23:00:00')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() {
ControlUnitResourceEntity(
id = 8,
baseId = 3,
controlUnitId = 10010,
controlUnitId = 10121,
name = "PAM Jeanne Barret",
note = null,
photo = null,
Expand All @@ -102,7 +102,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() {
ControlUnitResourceEntity(
id = 9,
baseId = 3,
controlUnitId = 10011,
controlUnitId = 10080,
name = "PAM Themis",
note = null,
photo = null,
Expand Down
Loading

0 comments on commit c35ded2

Please sign in to comment.