diff --git a/Makefile b/Makefile index 6beadd19d..060428ea6 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ dev-check-config: dev-run-back-with-infra: dev-erase-db dev-run-infra dev-clean-target-env dev-run-back dev-run-back: - cd backend && ./gradlew bootRun --args='--spring.profiles.active=dev --spring.config.additional-location=$(BACKEND_CONFIGURATION_FOLDER)' + cd backend && ./mvnw spring-boot:run -Dspring-boot.run.arguments="--spring.config.additional-location="$(BACKEND_CONFIGURATION_FOLDER)"" -Dspring-boot.run.profiles="dev" dev-run-infra: @echo "Preparing database" @@ -223,5 +223,5 @@ logs-db: .PHONY: dev lint-back -dev: dev-run-back-with-infra +dev: dev-run-back lint-back: dev-lint-backend diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/ControlUnitResourceEntity.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/ControlUnitResourceEntity.kt index 48c1c211f..cca9ef7ea 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/ControlUnitResourceEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/ControlUnitResourceEntity.kt @@ -4,6 +4,7 @@ data class ControlUnitResourceEntity( val id: Int? = null, val baseId: Int, val controlUnitId: Int, + val isArchived: Boolean, val name: String, val note: String? = null, val photo: ByteArray? = byteArrayOf(), @@ -17,6 +18,7 @@ data class ControlUnitResourceEntity( if (id != other.id) return false if (baseId != other.baseId) return false if (controlUnitId != other.controlUnitId) return false + if (isArchived != other.isArchived) return false if (name != other.name) return false if (note != other.note) return false if (photo != null) { @@ -32,6 +34,7 @@ data class ControlUnitResourceEntity( var result = id ?: 0 result = 31 * result + baseId result = 31 * result + controlUnitId + result = 31 * result + isArchived.hashCode() result = 31 * result + name.hashCode() result = 31 * result + (note?.hashCode() ?: 0) result = 31 * result + (photo?.contentHashCode() ?: 0) @@ -39,4 +42,11 @@ data class ControlUnitResourceEntity( return result } + + fun toLegacyControlUnitEntity(): LegacyControlUnitResourceEntity { + return LegacyControlUnitResourceEntity( + id = requireNotNull(id), + name, + ) + } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/LegacyControlUnitEntity.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/LegacyControlUnitEntity.kt index a784fb5a5..aae3f3062 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/LegacyControlUnitEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/LegacyControlUnitEntity.kt @@ -1,11 +1,11 @@ package fr.gouv.cacem.monitorenv.domain.entities.controlUnit -// TODO Replace this entity with `FullControlUnitEntity`. It's left for `MissionEntity.units` backward compatibility. +// TODO Replace this entity with `ControlUnitEntity`. It's left for `MissionEntity.units` backward compatibility. data class LegacyControlUnitEntity( val id: Int, val administration: String, val isArchived: Boolean, val name: String, - val resources: List, + val resources: List, val contact: String? = null, ) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/LegacyControlUnitResourceEntity.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/LegacyControlUnitResourceEntity.kt new file mode 100644 index 000000000..5f39e0e2d --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/controlUnit/LegacyControlUnitResourceEntity.kt @@ -0,0 +1,7 @@ +package fr.gouv.cacem.monitorenv.domain.entities.controlUnit + +// TODO Replace this entity with `ControlUnitResourceEntity`. It's left for `MissionEntity.units` backward compatibility. +data class LegacyControlUnitResourceEntity( + val id: Int, + val name: String, +) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/exceptions/ControlResourceOrUnitNotFoundException.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/exceptions/ControlResourceOrUnitNotFoundException.kt deleted file mode 100644 index e62903cc0..000000000 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/exceptions/ControlResourceOrUnitNotFoundException.kt +++ /dev/null @@ -1,4 +0,0 @@ -package fr.gouv.cacem.monitorenv.domain.exceptions - -class ControlResourceOrUnitNotFoundException(message: String, cause: Throwable? = null) : - Throwable(message, cause) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/repositories/IControlUnitResourceRepository.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/repositories/IControlUnitResourceRepository.kt index d510ce62a..32da7aea6 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/repositories/IControlUnitResourceRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/repositories/IControlUnitResourceRepository.kt @@ -10,5 +10,7 @@ interface IControlUnitResourceRepository { fun findAll(): List + fun findAllById(controlUnitResourceIds: List): List + fun save(controlUnitResource: ControlUnitResourceEntity): ControlUnitResourceEntity } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/dtos/FullControlUnitDTO.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/dtos/FullControlUnitDTO.kt index 9b37fa3f9..41a965754 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/dtos/FullControlUnitDTO.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/dtos/FullControlUnitDTO.kt @@ -20,7 +20,7 @@ data class FullControlUnitDTO( administration = administration.name, isArchived = controlUnit.isArchived, name = controlUnit.name, - resources = controlUnitResources.map { it.toControlUnitResource() }, + resources = controlUnitResources.map { it.toLegacyControlUnitResource() }, ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/dtos/FullControlUnitResourceDTO.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/dtos/FullControlUnitResourceDTO.kt index b329af6bb..58ce840f3 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/dtos/FullControlUnitResourceDTO.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/dtos/FullControlUnitResourceDTO.kt @@ -3,21 +3,17 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.dtos import fr.gouv.cacem.monitorenv.domain.entities.base.BaseEntity import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitEntity import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceEntity +import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitResourceEntity data class FullControlUnitResourceDTO( val base: BaseEntity, val controlUnit: ControlUnitEntity, val controlUnitResource: ControlUnitResourceEntity, ) { - fun toControlUnitResource(): ControlUnitResourceEntity { - return ControlUnitResourceEntity( - id = controlUnitResource.id, - baseId = controlUnitResource.baseId, - controlUnitId = controlUnitResource.controlUnitId, + fun toLegacyControlUnitResource(): LegacyControlUnitResourceEntity { + return LegacyControlUnitResourceEntity( + id = requireNotNull(controlUnitResource.id), name = controlUnitResource.name, - note = controlUnitResource.note, - photo = controlUnitResource.photo, - type = controlUnitResource.type, ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/LegacyControlUnitDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/LegacyControlUnitDataOutput.kt index edd60ef89..36f235734 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/LegacyControlUnitDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/LegacyControlUnitDataOutput.kt @@ -10,14 +10,15 @@ data class LegacyControlUnitDataOutput( val resources: List, ) { companion object { - fun fromLegacyControlUnit(legacyControlUnit: LegacyControlUnitEntity) = LegacyControlUnitDataOutput( - id = legacyControlUnit.id, - administration = legacyControlUnit.administration, - name = legacyControlUnit.name, - isArchived = legacyControlUnit.isArchived, - resources = legacyControlUnit.resources.map { - LegacyControlUnitResourceDataOutput.fromControlResourceEntity(it) - }, - ) + fun fromLegacyControlUnit(legacyControlUnit: LegacyControlUnitEntity) = + LegacyControlUnitDataOutput( + id = legacyControlUnit.id, + administration = legacyControlUnit.administration, + name = legacyControlUnit.name, + isArchived = legacyControlUnit.isArchived, + resources = legacyControlUnit.resources.map { + LegacyControlUnitResourceDataOutput.fromLegacyControlResourceEntity(it) + }, + ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/LegacyControlUnitResourceDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/LegacyControlUnitResourceDataOutput.kt index ac972907f..af69bc308 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/LegacyControlUnitResourceDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/LegacyControlUnitResourceDataOutput.kt @@ -1,16 +1,18 @@ package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs -import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceEntity +import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitResourceEntity data class LegacyControlUnitResourceDataOutput( val id: Int, val name: String, ) { companion object { - fun fromControlResourceEntity(controlUnitResource: ControlUnitResourceEntity) = + fun fromLegacyControlResourceEntity( + legacyControlUnitResource: LegacyControlUnitResourceEntity, + ) = LegacyControlUnitResourceDataOutput( - id = requireNotNull(controlUnitResource.id), - name = controlUnitResource.name, + id = requireNotNull(legacyControlUnitResource.id), + name = legacyControlUnitResource.name, ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/inputs/CreateOrUpdateControlUnitResourceDataInput.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/inputs/CreateOrUpdateControlUnitResourceDataInput.kt index 621c8b33d..42a8fc212 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/inputs/CreateOrUpdateControlUnitResourceDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/inputs/CreateOrUpdateControlUnitResourceDataInput.kt @@ -7,6 +7,7 @@ data class CreateOrUpdateControlUnitResourceDataInput( val id: Int? = null, val baseId: Int, val controlUnitId: Int, + val isArchived: Boolean, val name: String, val note: String? = null, val photo: ByteArray? = byteArrayOf(), @@ -17,6 +18,7 @@ data class CreateOrUpdateControlUnitResourceDataInput( id = this.id, baseId = this.baseId, controlUnitId = this.controlUnitId, + isArchived = this.isArchived, name = this.name, note = this.note, photo = this.photo, diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/outputs/ControlUnitResourceDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/outputs/ControlUnitResourceDataOutput.kt index 7a78b7f2e..efd3c6aa4 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/outputs/ControlUnitResourceDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/outputs/ControlUnitResourceDataOutput.kt @@ -6,6 +6,7 @@ data class ControlUnitResourceDataOutput( val id: Int, val baseId: Int, val controlUnitId: Int, + val isArchived: Boolean, val name: String, val note: String? = null, val photo: ByteArray? = byteArrayOf(), @@ -17,6 +18,7 @@ data class ControlUnitResourceDataOutput( id = requireNotNull(controlUnitResource.id), baseId = controlUnitResource.baseId, controlUnitId = controlUnitResource.controlUnitId, + isArchived = controlUnitResource.isArchived, name = controlUnitResource.name, note = controlUnitResource.note, photo = controlUnitResource.photo, diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyControlUnitsController.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyControlUnitsController.kt index d6d027885..641292c1a 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyControlUnitsController.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyControlUnitsController.kt @@ -17,6 +17,8 @@ class ApiLegacyControlUnitsController( @GetMapping("") @Operation(summary = "Get legacy control units") fun getControlResourcesController(): List { - return getLegacyControlUnits.execute().map { LegacyControlUnitDataOutput.fromLegacyControlUnit(it) } + return getLegacyControlUnits.execute().map { + LegacyControlUnitDataOutput.fromLegacyControlUnit(it) + } } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitModel.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitModel.kt index 33b961271..88aad65d8 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitModel.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitModel.kt @@ -80,6 +80,28 @@ data class ControlUnitModel( termsNote = controlUnit.termsNote, ) } + + /** + * @param controlUnitContactModels Return control unit contacts relations when provided. + * @param controlUnitResourceModels Return control unit resources relations when provided. + */ + fun fromFullControlUnit( + fullControlUnit: FullControlUnitDTO, + controlUnitContactModels: List? = null, + controlUnitResourceModels: List? = null, + ): ControlUnitModel { + return ControlUnitModel( + id = fullControlUnit.controlUnit.id, + areaNote = fullControlUnit.controlUnit.areaNote, + administration = AdministrationModel.fromAdministration(fullControlUnit.administration), + controlUnitContacts = controlUnitContactModels, + controlUnitResources = controlUnitResourceModels, + departmentArea = fullControlUnit.departmentArea?.let { DepartmentAreaModel.fromDepartmentArea(it) }, + isArchived = fullControlUnit.controlUnit.isArchived, + name = fullControlUnit.controlUnit.name, + termsNote = fullControlUnit.controlUnit.termsNote, + ) + } } fun toControlUnit(): ControlUnitEntity { @@ -110,7 +132,7 @@ data class ControlUnitModel( administration = administration.name, isArchived, name, - resources = requireNotNull(controlUnitResources).map { it.toControlUnitResource() }, + resources = requireNotNull(controlUnitResources).map { it.toLegacyControlUnitResource() }, contact = "", ) } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitResourceModel.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitResourceModel.kt index f43b59229..e360faaec 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitResourceModel.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitResourceModel.kt @@ -3,6 +3,7 @@ package fr.gouv.cacem.monitorenv.infrastructure.database.model import com.fasterxml.jackson.annotation.JsonBackReference import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceEntity import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceType +import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitResourceEntity import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.dtos.FullControlUnitResourceDTO import io.hypersistence.utils.hibernate.type.basic.PostgreSQLEnumType import jakarta.persistence.* @@ -29,6 +30,9 @@ data class ControlUnitResourceModel( @JsonBackReference val controlUnit: ControlUnitModel, + @Column(name = "is_archived", nullable = false) + val isArchived: Boolean, + @Column(name = "name", nullable = false) val name: String, @@ -60,6 +64,7 @@ data class ControlUnitResourceModel( if (id != other.id) return false if (base != other.base) return false if (controlUnit != other.controlUnit) return false + if (isArchived != other.isArchived) return false if (name != other.name) return false if (note != other.note) return false if (photo != null) { @@ -83,6 +88,7 @@ data class ControlUnitResourceModel( id = controlUnitResource.id, base = baseModel, controlUnit = controlUnitModel, + isArchived = controlUnitResource.isArchived, name = controlUnitResource.name, note = controlUnitResource.note, photo = controlUnitResource.photo, @@ -95,6 +101,7 @@ data class ControlUnitResourceModel( var result = id ?: 0 result = 31 * result + base.hashCode() result = 31 * result + controlUnit.hashCode() + result = 31 * result + isArchived.hashCode() result = 31 * result + name.hashCode() result = 31 * result + (note?.hashCode() ?: 0) result = 31 * result + (photo?.contentHashCode() ?: 0) @@ -110,6 +117,7 @@ data class ControlUnitResourceModel( id, baseId = requireNotNull(base.id), controlUnitId = requireNotNull(controlUnit.id), + isArchived, name, note, photo, @@ -124,4 +132,11 @@ data class ControlUnitResourceModel( controlUnitResource = toControlUnitResource(), ) } + + fun toLegacyControlUnitResource(): LegacyControlUnitResourceEntity { + return LegacyControlUnitResourceEntity( + id = requireNotNull(id), + name, + ) + } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionControlResourceModel.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionControlResourceModel.kt index 77ffdb014..594a4695d 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionControlResourceModel.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionControlResourceModel.kt @@ -17,37 +17,18 @@ data class MissionControlResourceModel( @ManyToOne(fetch = FetchType.LAZY, optional = false, cascade = [CascadeType.MERGE]) @JoinColumn(name = "control_resource_id") - var ressource: ControlUnitResourceModel, + var resource: ControlUnitResourceModel, ) { - companion object { - fun fromControlUnitResource( - controlUnitResource: ControlUnitResourceEntity, - baseModel: BaseModel, - missionModel: MissionModel, - controlUnitModel: ControlUnitModel, - ) = MissionControlResourceModel( - ressource = ControlUnitResourceModel( - id = requireNotNull(controlUnitResource.id), - base = baseModel, - controlUnit = controlUnitModel, - name = controlUnitResource.name, - note = controlUnitResource.note, - photo = controlUnitResource.photo, - type = controlUnitResource.type, - ), - mission = missionModel, - ) - } - fun toControlUnitResource(): ControlUnitResourceEntity { return ControlUnitResourceEntity( - id = ressource.id, - baseId = requireNotNull(ressource.base.id), - controlUnitId = requireNotNull(ressource.controlUnit.id), - name = ressource.name, - note = ressource.note, + id = resource.id, + baseId = requireNotNull(resource.base.id), + controlUnitId = requireNotNull(resource.controlUnit.id), + isArchived = resource.isArchived, + name = resource.name, + note = resource.note, photo = byteArrayOf(), - type = ressource.type, + type = resource.type, ) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt index ef11a1ade..171976259 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt @@ -14,18 +14,7 @@ import fr.gouv.cacem.monitorenv.utils.mapOrElseEmpty import io.hypersistence.utils.hibernate.type.array.ListArrayType import io.hypersistence.utils.hibernate.type.array.internal.AbstractArrayType.SQL_ARRAY_TYPE import io.hypersistence.utils.hibernate.type.basic.PostgreSQLEnumType -import jakarta.persistence.Basic -import jakarta.persistence.CascadeType -import jakarta.persistence.Column -import jakarta.persistence.Entity -import jakarta.persistence.EnumType -import jakarta.persistence.Enumerated -import jakarta.persistence.FetchType -import jakarta.persistence.GeneratedValue -import jakarta.persistence.GenerationType -import jakarta.persistence.Id -import jakarta.persistence.OneToMany -import jakarta.persistence.Table +import jakarta.persistence.* import org.hibernate.Hibernate import org.hibernate.annotations.Fetch import org.hibernate.annotations.FetchMode @@ -140,16 +129,11 @@ data class MissionModel( ) { fun toMissionEntity(objectMapper: ObjectMapper): MissionEntity { val controlUnits = controlUnits.mapOrElseEmpty { missionControlUnitModel -> - val maybeMissionControlResourceModels = controlResources - ?.filter { missionControlResourceModel -> - missionControlResourceModel.ressource.controlUnit.id == missionControlUnitModel.unit.id - } - - val controlUnitResources = maybeMissionControlResourceModels.mapOrElseEmpty { it.toControlUnitResource() } + val controlUnitResources = controlResources.mapOrElseEmpty { it.toControlUnitResource() } missionControlUnitModel.unit.toLegacyControlUnit().copy( contact = missionControlUnitModel.contact, - resources = controlUnitResources, + resources = controlUnitResources.map { it.toLegacyControlUnitEntity() }, ) } @@ -186,7 +170,7 @@ data class MissionModel( fun fromMissionEntity( mission: MissionEntity, mapper: ObjectMapper, - baseModelMap: Map, + controlUnitResourceModelMap: Map, ): MissionModel { val missionModel = MissionModel( id = mission.id, @@ -212,20 +196,19 @@ data class MissionModel( } mission.controlUnits.map { - val controlUnitModel = MissionControlUnitModel.fromLegacyControlUnit( + val missionControlUnitModel = MissionControlUnitModel.fromLegacyControlUnit( it, missionModel, ) - missionModel.controlUnits?.add(controlUnitModel) + missionModel.controlUnits?.add(missionControlUnitModel) val missionControlUnitResourceModels = it.resources.map { controlUnitResource -> - val baseModel = requireNotNull(baseModelMap[controlUnitResource.baseId]) + val controlUnitResourceModel = requireNotNull(controlUnitResourceModelMap[controlUnitResource.id]) - MissionControlResourceModel.fromControlUnitResource( - controlUnitResource, - baseModel, - missionModel, - controlUnitModel.unit, + MissionControlResourceModel( + id = mission.id, + resource = controlUnitResourceModel, + mission = missionModel, ) } missionModel.controlResources?.addAll(missionControlUnitResourceModels) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitResourceRepository.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitResourceRepository.kt index 7f804f522..990d2ba3c 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitResourceRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitResourceRepository.kt @@ -27,6 +27,12 @@ class JpaControlUnitResourceRepository( return dbControlUnitResourceRepository.findAll().map { it.toFullControlUnitResource() } } + override fun findAllById(controlUnitResourceIds: List): List { + return dbControlUnitResourceRepository.findAllById(controlUnitResourceIds).map { + it.toFullControlUnitResource() + } + } + override fun findById(controlUnitResourceId: Int): FullControlUnitResourceDTO { return dbControlUnitResourceRepository.findById(controlUnitResourceId).get().toFullControlUnitResource() } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepository.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepository.kt index d5b18dbdd..3f2cf83c1 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepository.kt @@ -3,14 +3,11 @@ package fr.gouv.cacem.monitorenv.infrastructure.database.repositories import com.fasterxml.jackson.databind.ObjectMapper import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum -import fr.gouv.cacem.monitorenv.domain.exceptions.ControlResourceOrUnitNotFoundException import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO -import fr.gouv.cacem.monitorenv.infrastructure.database.model.BaseModel import fr.gouv.cacem.monitorenv.infrastructure.database.model.MissionModel +import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBControlUnitResourceRepository import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBMissionRepository -import org.springframework.dao.DataIntegrityViolationException -import org.springframework.dao.InvalidDataAccessApiUsageException import org.springframework.data.domain.Pageable import org.springframework.stereotype.Repository import org.springframework.transaction.annotation.Transactional @@ -18,7 +15,7 @@ import java.time.Instant @Repository class JpaMissionRepository( - private val dbBaseRepository: JpaBaseRepository, + private val dbControlUnitResourceRepository: IDBControlUnitResourceRepository, private val dbMissionRepository: IDBMissionRepository, private val mapper: ObjectMapper, ) : IMissionRepository { @@ -62,31 +59,18 @@ class JpaMissionRepository( @Transactional override fun save(mission: MissionEntity): MissionDTO { - return try { - // Extract all control units resources unique baseIds - val uniqueBaseIds = mission.controlUnits.flatMap { controlUnit -> - controlUnit.resources.map { it.baseId } - }.distinct() - // Fetch all of them as models - val baseModels = dbBaseRepository.findAllById(uniqueBaseIds).map { BaseModel.fromFullBase(it) } - // Create a `[baseId] → BaseModel` map - val baseModelMap = baseModels.associateBy { requireNotNull(it.id) } + // Extract all control units resources unique control unit resource IDs + val uniqueControlUnitResourceIds = mission.controlUnits.flatMap { controlUnit -> + controlUnit.resources.map { it.id } + }.distinct() + // Fetch all of them as models + val controlUnitResourceModels = dbControlUnitResourceRepository.findAllById(uniqueControlUnitResourceIds) + // Create an `[id] → ControlUnitResourceModel` map + val controlUnitResourceModelMap = controlUnitResourceModels.associateBy { requireNotNull(it.id) } - val missionModel = MissionModel.fromMissionEntity(mission, mapper, baseModelMap) - dbMissionRepository.save(missionModel).toMissionDTO(mapper) - } catch (e: Exception) { - when (e) { - // TODO Is `InvalidDataAccessApiUsageException` necessary? - is DataIntegrityViolationException, is InvalidDataAccessApiUsageException -> { - throw ControlResourceOrUnitNotFoundException( - "Invalid control unit or resource id: not found in referential.", - e, - ) - } + val missionModel = MissionModel.fromMissionEntity(mission, mapper, controlUnitResourceModelMap) - else -> throw e - } - } + return dbMissionRepository.save(missionModel).toMissionDTO(mapper) } private fun convertToPGArray(array: List?): String { diff --git a/backend/src/main/resources/db/migration/internal/V0.100__add_other_control_types_rapportnav.sql b/backend/src/main/resources/db/migration/internal/V0.100__add_other_control_types_rapportnav.sql new file mode 100644 index 000000000..88d04a106 --- /dev/null +++ b/backend/src/main/resources/db/migration/internal/V0.100__add_other_control_types_rapportnav.sql @@ -0,0 +1,2 @@ +ALTER TABLE public.control_unit_resources + ADD COLUMN is_archived BOOLEAN NOT NULL DEFAULT false; diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitResourceUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitResourceUTests.kt index 64dc017f2..fb39eb8b6 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitResourceUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitResourceUTests.kt @@ -23,6 +23,7 @@ class CreateOrUpdateControlUnitResourceUTests { val newControlUnitResource = ControlUnitResourceEntity( baseId = 2, controlUnitId = 3, + isArchived = false, name = "Control Unit Resource Name", note = null, photo = null, diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/MissionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/MissionsControllerITests.kt index ed93b19ac..44ac99d51 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/MissionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/MissionsControllerITests.kt @@ -4,24 +4,15 @@ import com.fasterxml.jackson.databind.ObjectMapper import fr.gouv.cacem.monitorenv.config.MapperConfiguration import fr.gouv.cacem.monitorenv.config.WebSecurityConfig import fr.gouv.cacem.monitorenv.domain.entities.VehicleTypeEnum -import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceEntity -import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceType import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitEntity -import fr.gouv.cacem.monitorenv.domain.entities.mission.ActionTargetTypeEnum -import fr.gouv.cacem.monitorenv.domain.entities.mission.EnvActionControlEntity -import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity -import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum -import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionTypeEnum +import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitResourceEntity +import fr.gouv.cacem.monitorenv.domain.entities.mission.* 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.entities.reporting.TargetTypeEnum import fr.gouv.cacem.monitorenv.domain.entities.semaphore.SemaphoreEntity -import fr.gouv.cacem.monitorenv.domain.use_cases.missions.CreateOrUpdateMission -import fr.gouv.cacem.monitorenv.domain.use_cases.missions.DeleteMission -import fr.gouv.cacem.monitorenv.domain.use_cases.missions.GetEngagedControlUnits -import fr.gouv.cacem.monitorenv.domain.use_cases.missions.GetMissionById -import fr.gouv.cacem.monitorenv.domain.use_cases.missions.GetMonitorEnvMissions +import fr.gouv.cacem.monitorenv.domain.use_cases.missions.* import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingDTO import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.inputs.CreateOrUpdateMissionDataInput @@ -39,14 +30,12 @@ import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.annotation.Import import org.springframework.http.MediaType import org.springframework.test.web.servlet.MockMvc -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.* import org.springframework.test.web.servlet.result.MockMvcResultHandlers import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status import java.time.ZonedDateTime -import java.util.UUID +import java.util.* @Import(WebSecurityConfig::class, MapperConfiguration::class) @WebMvcTest(value = [(MissionsController::class)]) @@ -128,7 +117,7 @@ class MissionsControllerITests { "MULTIPOLYGON (((-4.54877817 48.30555988, -4.54997332 48.30597601, -4.54998501 48.30718823, -4.5487929 48.30677461, -4.54877817 48.30555988)))" val polygon = wktReader.read(multipolygonString) as MultiPolygon - var point = wktReader.read("POINT (-4.54877816747593 48.305559876971)") as Point + val point = wktReader.read("POINT (-4.54877816747593 48.305559876971)") as Point val expectedFirstMission = MissionDTO( mission = MissionEntity( @@ -140,12 +129,9 @@ class MissionsControllerITests { name = "CU1", administration = "Admin 1", resources = listOf( - ControlUnitResourceEntity( + LegacyControlUnitResourceEntity( id = 2, - baseId = 3, name = "Ressource 2", - type = ControlUnitResourceType.BARGE, - controlUnitId = 1, ), ), isArchived = false, diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiControlUnitResourcesControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiControlUnitResourcesControllerITests.kt index 730b4a40b..45d0bc562 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiControlUnitResourcesControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiControlUnitResourcesControllerITests.kt @@ -56,6 +56,7 @@ class ApiControlUnitResourcesControllerITests { id = 1, baseId = 0, controlUnitId = 0, + isArchived = false, name = "Resource Name", note = null, photo = null, @@ -65,6 +66,7 @@ class ApiControlUnitResourcesControllerITests { val newControlUnitData = CreateOrUpdateControlUnitResourceDataInput( baseId = 0, controlUnitId = 0, + isArchived = false, name = "Resource Name", note = null, photo = null, @@ -107,6 +109,7 @@ class ApiControlUnitResourcesControllerITests { id = 1, baseId = 0, controlUnitId = 0, + isArchived = false, name = "Resource Name", note = null, photo = null, @@ -147,6 +150,7 @@ class ApiControlUnitResourcesControllerITests { id = 1, baseId = 0, controlUnitId = 3, + isArchived = false, name = "Resource Name", note = null, photo = null, @@ -174,6 +178,7 @@ class ApiControlUnitResourcesControllerITests { id = 2, baseId = 0, controlUnitId = 0, + isArchived = false, name = "Resource Name 2", note = null, photo = null, @@ -197,6 +202,7 @@ class ApiControlUnitResourcesControllerITests { id = 1, baseId = 0, controlUnitId = 0, + isArchived = false, name = "Updated Resource Name", note = null, photo = null, @@ -207,6 +213,7 @@ class ApiControlUnitResourcesControllerITests { id = 1, baseId = 0, controlUnitId = 0, + isArchived = false, name = "Updated Resource Name", note = null, photo = null, diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyControlUnitsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyControlUnitsControllerITests.kt index 01943df8a..59879d107 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyControlUnitsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyControlUnitsControllerITests.kt @@ -1,9 +1,8 @@ package fr.gouv.cacem.monitorenv.infrastructure.api.endpoints.publicapi import fr.gouv.cacem.monitorenv.config.WebSecurityConfig -import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceEntity -import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceType import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitEntity +import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitResourceEntity import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.GetLegacyControlUnits import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test @@ -35,12 +34,9 @@ class ApiLegacyControlUnitsControllerITests { isArchived = false, name = "DF 123", resources = listOf( - ControlUnitResourceEntity( + LegacyControlUnitResourceEntity( id = 0, - baseId = 0, - controlUnitId = 0, name = "Vedette", - type = ControlUnitResourceType.BARGE, ), ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiMissionsControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiMissionsControllerITests.kt index 9556293a8..c2ce1730e 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiMissionsControllerITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiMissionsControllerITests.kt @@ -6,16 +6,8 @@ import fr.gouv.cacem.monitorenv.config.MapperConfiguration import fr.gouv.cacem.monitorenv.config.WebSecurityConfig import fr.gouv.cacem.monitorenv.domain.entities.VehicleTypeEnum import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitEntity -import fr.gouv.cacem.monitorenv.domain.entities.mission.ActionTargetTypeEnum -import fr.gouv.cacem.monitorenv.domain.entities.mission.EnvActionControlEntity -import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity -import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum -import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionTypeEnum -import fr.gouv.cacem.monitorenv.domain.use_cases.missions.CreateOrUpdateMission -import fr.gouv.cacem.monitorenv.domain.use_cases.missions.DeleteMission -import fr.gouv.cacem.monitorenv.domain.use_cases.missions.GetEngagedControlUnits -import fr.gouv.cacem.monitorenv.domain.use_cases.missions.GetMissionById -import fr.gouv.cacem.monitorenv.domain.use_cases.missions.GetMissions +import fr.gouv.cacem.monitorenv.domain.entities.mission.* +import fr.gouv.cacem.monitorenv.domain.use_cases.missions.* import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.publicapi.inputs.CreateOrUpdateMissionDataInput import org.hamcrest.Matchers.equalTo diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaBaseRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaBaseRepositoryITests.kt index 7b86efc31..49a843537 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaBaseRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaBaseRepositoryITests.kt @@ -33,6 +33,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 1, baseId = 1, controlUnitId = 10000, + isArchived = false, name = "Semi-rigide 1", note = null, photo = null, @@ -42,6 +43,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 2, baseId = 1, controlUnitId = 10000, + isArchived = false, name = "Semi-rigide 2", note = null, photo = null, @@ -64,6 +66,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 5, baseId = 3, controlUnitId = 10002, + isArchived = false, name = "Voiture", note = null, photo = null, @@ -73,6 +76,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 7, baseId = 3, controlUnitId = 10003, + isArchived = false, name = "Semi-rigide", note = null, photo = null, @@ -82,6 +86,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 8, baseId = 3, controlUnitId = 10121, + isArchived = false, name = "PAM Jeanne Barret", note = null, photo = null, @@ -91,6 +96,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 9, baseId = 3, controlUnitId = 10080, + isArchived = false, name = "PAM Themis", note = null, photo = null, @@ -100,6 +106,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 10, baseId = 3, controlUnitId = 10018, + isArchived = false, name = "ALTAIR", note = null, photo = null, @@ -109,6 +116,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 11, baseId = 3, controlUnitId = 10018, + isArchived = false, name = "PHEROUSA", note = null, photo = null, @@ -118,6 +126,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 12, baseId = 3, controlUnitId = 10018, + isArchived = false, name = "ARIOLA", note = null, photo = null, @@ -146,6 +155,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 3, baseId = 2, controlUnitId = 10002, + isArchived = false, name = "Semi-rigide 1", note = null, photo = null, @@ -155,6 +165,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 4, baseId = 2, controlUnitId = 10002, + isArchived = false, name = "Semi-rigide 2", note = null, photo = null, @@ -164,6 +175,7 @@ class JpaBaseRepositoryITests : AbstractDBTests() { id = 6, baseId = 2, controlUnitId = 10003, + isArchived = false, name = "AR VECHEN", note = null, photo = null, diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitRepositoryITests.kt index 059e3276f..c4d5f7d35 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitRepositoryITests.kt @@ -91,6 +91,7 @@ class JpaControlUnitRepositoryITests : AbstractDBTests() { id = 1, baseId = 1, controlUnitId = 10000, + isArchived = false, name = "Semi-rigide 1", note = null, photo = null, @@ -117,6 +118,7 @@ class JpaControlUnitRepositoryITests : AbstractDBTests() { id = 2, baseId = 1, controlUnitId = 10000, + isArchived = false, name = "Semi-rigide 2", note = null, photo = null, @@ -164,6 +166,7 @@ class JpaControlUnitRepositoryITests : AbstractDBTests() { id = 8, baseId = 3, controlUnitId = 10121, + isArchived = false, name = "PAM Jeanne Barret", note = null, photo = null, @@ -233,6 +236,7 @@ class JpaControlUnitRepositoryITests : AbstractDBTests() { id = 1, baseId = 1, controlUnitId = 10000, + isArchived = false, name = "Semi-rigide 1", note = null, photo = null, @@ -259,6 +263,7 @@ class JpaControlUnitRepositoryITests : AbstractDBTests() { id = 2, baseId = 1, controlUnitId = 10000, + isArchived = false, name = "Semi-rigide 2", note = null, photo = null, diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitResourceRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitResourceRepositoryITests.kt index 185a2d95c..e96c930a0 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitResourceRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaControlUnitResourceRepositoryITests.kt @@ -45,6 +45,7 @@ class JpaControlUnitResourceRepositoryITests : AbstractDBTests() { id = 1, baseId = 1, controlUnitId = 10000, + isArchived = false, name = "Semi-rigide 1", note = null, photo = null, @@ -74,6 +75,7 @@ class JpaControlUnitResourceRepositoryITests : AbstractDBTests() { id = 12, baseId = 3, controlUnitId = 10018, + isArchived = false, name = "ARIOLA", note = null, photo = null, @@ -109,6 +111,7 @@ class JpaControlUnitResourceRepositoryITests : AbstractDBTests() { id = 1, baseId = 1, controlUnitId = 10000, + isArchived = false, name = "Semi-rigide 1", note = null, photo = null, @@ -127,6 +130,7 @@ class JpaControlUnitResourceRepositoryITests : AbstractDBTests() { val newControlUnitResource = ControlUnitResourceEntity( baseId = 1, controlUnitId = 10000, + isArchived = false, name = "Resource Name", note = "Resource Note", photo = null, @@ -144,6 +148,7 @@ class JpaControlUnitResourceRepositoryITests : AbstractDBTests() { id = 13, baseId = 2, controlUnitId = 10001, + isArchived = false, name = "Updated Resource Name", note = "Updated Resource Note", photo = null, diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt index db15805e5..258f4bd92 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt @@ -1,11 +1,9 @@ package fr.gouv.cacem.monitorenv.infrastructure.database.repositories import fr.gouv.cacem.monitorenv.domain.entities.VehicleTypeEnum -import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceEntity -import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceType import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitEntity +import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitResourceEntity import fr.gouv.cacem.monitorenv.domain.entities.mission.* -import fr.gouv.cacem.monitorenv.domain.exceptions.ControlResourceOrUnitNotFoundException import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable @@ -14,6 +12,8 @@ import org.locationtech.jts.geom.MultiPoint import org.locationtech.jts.geom.MultiPolygon import org.locationtech.jts.io.WKTReader import org.springframework.beans.factory.annotation.Autowired +import org.springframework.dao.DataIntegrityViolationException +import org.springframework.dao.InvalidDataAccessApiUsageException import org.springframework.data.domain.PageRequest import org.springframework.data.domain.Pageable import org.springframework.transaction.annotation.Transactional @@ -97,12 +97,9 @@ class JpaMissionRepositoryITests : AbstractDBTests() { administration = "DDTM", isArchived = false, resources = listOf( - ControlUnitResourceEntity( + LegacyControlUnitResourceEntity( id = 8, - baseId = 3, - controlUnitId = 10004, name = "PAM Jeanne Barret", - type = ControlUnitResourceType.BARGE, ), ), ), @@ -120,7 +117,6 @@ class JpaMissionRepositoryITests : AbstractDBTests() { assertThat(newMissionCreated.mission.controlUnits.first().administration).isEqualTo("DDTM") assertThat(newMissionCreated.mission.controlUnits.first().resources).hasSize(1) assertThat(newMissionCreated.mission.controlUnits.first().resources.first().id).isEqualTo(8) - assertThat(newMissionCreated.mission.controlUnits.first().resources.first().baseId).isEqualTo(3) assertThat(newMissionCreated.mission.controlUnits.first().resources.first().name).isEqualTo("PAM Jeanne Barret") assertThat(newMissionCreated.mission.envActions).hasSize(3) assertThat(newMissionCreated.mission.envActions?.first()?.facade).isEqualTo("Facade 1") @@ -162,12 +158,9 @@ class JpaMissionRepositoryITests : AbstractDBTests() { administration = "DDTM", isArchived = false, resources = listOf( - ControlUnitResourceEntity( + LegacyControlUnitResourceEntity( id = 8, - baseId = 3, - controlUnitId = 10004, name = "PAM Jeanne Barret", - type = ControlUnitResourceType.BARGE, ), ), ), @@ -186,19 +179,13 @@ class JpaMissionRepositoryITests : AbstractDBTests() { administration = "DDTM", isArchived = false, resources = listOf( - ControlUnitResourceEntity( + LegacyControlUnitResourceEntity( id = 8, - baseId = 3, - controlUnitId = 5, name = "PAM Jeanne Barret", - type = ControlUnitResourceType.BARGE, ), - ControlUnitResourceEntity( + LegacyControlUnitResourceEntity( id = 5, - baseId = 3, - controlUnitId = 5, name = "Voiture", - type = ControlUnitResourceType.BARGE, ), ), ), @@ -213,7 +200,6 @@ class JpaMissionRepositoryITests : AbstractDBTests() { assertThat(newMissionUpdated.mission.controlUnits.first().administration).isEqualTo("DDTM") assertThat(newMissionUpdated.mission.controlUnits.first().resources).hasSize(2) assertThat(newMissionUpdated.mission.controlUnits.first().resources.first().id).isEqualTo(8) - assertThat(newMissionUpdated.mission.controlUnits.first().resources.first().baseId).isEqualTo(3) assertThat(newMissionUpdated.mission.controlUnits.first().resources.first().name).isEqualTo("PAM Jeanne Barret") assertThat(newMissionUpdated.mission.controlUnits.first().resources.last().id).isEqualTo(5) assertThat(newMissionUpdated.mission.controlUnits.first().resources.last().name).isEqualTo("Voiture") @@ -238,12 +224,9 @@ class JpaMissionRepositoryITests : AbstractDBTests() { administration = "DDTM", isArchived = false, resources = listOf( - ControlUnitResourceEntity( + LegacyControlUnitResourceEntity( id = 123456, - baseId = 1, - controlUnitId = 5, name = "PAM Jeanne Barret", - type = ControlUnitResourceType.BARGE, ), ), ), @@ -257,8 +240,7 @@ class JpaMissionRepositoryITests : AbstractDBTests() { } // Then - assertThat(throwable).isInstanceOf(ControlResourceOrUnitNotFoundException::class.java) - assertThat(throwable.message).contains("Invalid control unit or resource id: not found in referential") + assertThat(throwable).isInstanceOf(InvalidDataAccessApiUsageException::class.java) } @Test @@ -291,8 +273,7 @@ class JpaMissionRepositoryITests : AbstractDBTests() { } // Then - assertThat(throwable).isInstanceOf(ControlResourceOrUnitNotFoundException::class.java) - assertThat(throwable.message).contains("Invalid control unit or resource id: not found in referential") + assertThat(throwable).isInstanceOf(DataIntegrityViolationException::class.java) } @Test @@ -527,26 +508,17 @@ class JpaMissionRepositoryITests : AbstractDBTests() { isArchived = false, name = "DML 2A", resources = listOf( - ControlUnitResourceEntity( + LegacyControlUnitResourceEntity( id = 3, - baseId = 2, - controlUnitId = 10002, name = "Semi-rigide 1", - type = ControlUnitResourceType.BARGE, ), - ControlUnitResourceEntity( + LegacyControlUnitResourceEntity( id = 4, - baseId = 2, - controlUnitId = 10002, name = "Semi-rigide 2", - type = ControlUnitResourceType.BARGE, ), - ControlUnitResourceEntity( + LegacyControlUnitResourceEntity( id = 5, - baseId = 3, - controlUnitId = 10002, name = "Voiture", - type = ControlUnitResourceType.CAR, ), ), ), diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaReportingITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaReportingITests.kt index 79aafe94a..18bacd8ce 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaReportingITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaReportingITests.kt @@ -65,7 +65,8 @@ class JpaReportingITests : AbstractDBTests() { isDeleted = false, openBy = "CDA", ) - val createdReporting = jpaReportingRepository.save(newReporting) + + jpaReportingRepository.save(newReporting) val reportingDTO = jpaReportingRepository.findById(9) @@ -173,7 +174,7 @@ class JpaReportingITests : AbstractDBTests() { // Given val numberOfExistingReportings = jpaReportingRepository.count() assertThat(numberOfExistingReportings).isEqualTo(8) - val existingReporting = jpaReportingRepository.findById(1) + // When jpaReportingRepository.delete(1) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 8904148be..2be866b25 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -81,6 +81,7 @@ "cypress": "13.2.0", "cypress-mouse-position": "1.0.0", "cypress-plugin-snapshots": "github:ivangabriele/cypress-plugin-snapshots", + "dotenv-cli": "7.3.0", "eslint": "8.22.0", "eslint-config-airbnb": "19.0.4", "eslint-config-airbnb-typescript": "17.1.0", @@ -13283,6 +13284,21 @@ "url": "https://github.com/motdotla/dotenv?sponsor=1" } }, + "node_modules/dotenv-cli": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-7.3.0.tgz", + "integrity": "sha512-314CA4TyK34YEJ6ntBf80eUY+t1XaFLyem1k9P0sX1gn30qThZ5qZr/ZwE318gEnzyYP9yj9HJk6SqwE0upkfw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.3", + "dotenv": "^16.3.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "bin": { + "dotenv": "cli.js" + } + }, "node_modules/dotenv-expand": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index e33246c08..702d928c3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -14,7 +14,7 @@ "build:prod": "REACT_APP_ENV=prod npm run build", "cypress:open": "cypress open --browser firefox --config-file ./config/cypress.config.ts --e2e", "cypress:run": "cypress run --browser firefox --config-file ./config/cypress.config.ts --e2e", - "dev": "BROWSER=none DISABLE_ESLINT_PLUGIN=true react-scripts start", + "dev": "dotenv -e ../infra/.env -v BROWSER=none -v DISABLE_ESLINT_PLUGIN=true react-scripts start", "eject": "react-scripts eject", "prepare": "cd .. && husky install ./frontend/.husky", "start": "react-scripts start", @@ -103,6 +103,7 @@ "cypress": "13.2.0", "cypress-mouse-position": "1.0.0", "cypress-plugin-snapshots": "github:ivangabriele/cypress-plugin-snapshots", + "dotenv-cli": "7.3.0", "eslint": "8.22.0", "eslint-config-airbnb": "19.0.4", "eslint-config-airbnb-typescript": "17.1.0", diff --git a/infra/.env.example b/infra/.env.example index 689a8fbb8..82f6471d6 100644 --- a/infra/.env.example +++ b/infra/.env.example @@ -40,7 +40,7 @@ REACT_APP_GEOSERVER_REMOTE_URL=//localhost:8081 REACT_APP_GEOSERVER_NAMESPACE=monitorenv REACT_APP_GOOGLEMAPS_API_KEY=googleapikey -REACT_APP_MAPBOX_KEY="" +REACT_APP_MAPBOX_KEY=pk.eyJ1IjoibW9uaXRvcmZpc2giLCJhIjoiY2tsdHJ6dHhhMGZ0eDJ2bjhtZmJlOHJmZiJ9.bdi1cO-cUcZKXdkEkqAoZQ REACT_APP_SHOM_KEY=rg8ele7cft4ujkwjspsmtwas REACT_APP_SENTRY_ENV=production