Skip to content

Commit

Permalink
[Reporting] clean cache for reporting and mission apis, add attached …
Browse files Browse the repository at this point in the history
…and detached mission date in back
  • Loading branch information
claire2212 committed Oct 13, 2023
1 parent 49056c8 commit 0fdfa03
Show file tree
Hide file tree
Showing 17 changed files with 427 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import fr.gouv.cacem.monitorenv.config.UseCase
import fr.gouv.cacem.monitorenv.domain.entities.reporting.ReportingEntity
import fr.gouv.cacem.monitorenv.domain.repositories.*
import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingDTO
import java.time.ZonedDateTime
import org.slf4j.Logger
import org.slf4j.LoggerFactory

@UseCase
class CreateOrUpdateReporting(
private val reportingRepository: IReportingRepository,
private val controlUnitRepository: IControlUnitRepository,
private val semaphoreRepository: ISemaphoreRepository,
private val facadeRepository: IFacadeAreasRepository,
private val missionRepository: IMissionRepository,
private val reportingRepository: IReportingRepository,
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?): ReportingDTO {
require(reporting != null) {
"No reporting to create or update"
}
require(reporting != null) { "No reporting to create or update" }
logger.info("Create or update reporting: $reporting.id")
reporting.checkValidity()

Expand All @@ -30,7 +29,25 @@ class CreateOrUpdateReporting(
seaFront = facadeRepository.findFacadeFromGeometry(reporting.geom)
}

val savedReport = reportingRepository.save(reporting.copy(seaFront = seaFront))
var attachedToMissionAtUtc: ZonedDateTime? = null
var detachedFromMissionAtUtc: ZonedDateTime? = null
if (reporting.missionId != null) {
attachedToMissionAtUtc = ZonedDateTime.now()
detachedFromMissionAtUtc = null
}

if (reporting.missionId == null && reporting.attachedToMissionAtUtc != null) {
detachedFromMissionAtUtc = ZonedDateTime.now()
}

val savedReport =
reportingRepository.save(
reporting.copy(
seaFront = seaFront,
attachedToMissionAtUtc = attachedToMissionAtUtc,
detachedFromMissionAtUtc = detachedFromMissionAtUtc
)
)

return savedReport
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,111 +1,117 @@
package fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs

import fr.gouv.cacem.monitorenv.domain.entities.VehicleTypeEnum
import fr.gouv.cacem.monitorenv.domain.entities.reporting.ControlStatusEnum
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.TargetDetailsEntity
import fr.gouv.cacem.monitorenv.domain.entities.reporting.TargetTypeEnum
import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingDTO
import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.publicapi.outputs.ControlUnitDataOutput
import org.locationtech.jts.geom.Geometry
import java.time.ZonedDateTime
import java.util.UUID
import org.locationtech.jts.geom.Geometry

data class ReportingDataOutput(
val id: Int,
val reportingId: Long? = null,
val sourceType: SourceTypeEnum? = null,
val semaphoreId: Int? = null,
val semaphore: SemaphoreDataOutput? = null,
val controlUnitId: Int? = null,
val controlUnit: ControlUnitDataOutput? = null,
val displayedSource: String? = null,
val sourceName: String? = null,
val targetType: TargetTypeEnum? = null,
val vehicleType: VehicleTypeEnum? = null,
val targetDetails: List<TargetDetailsEntity>? = listOf(),
val geom: Geometry? = null,
val seaFront: String? = null,
val description: String? = null,
val reportType: ReportingTypeEnum? = null,
val theme: String? = null,
val subThemes: List<String>? = listOf(),
val actionTaken: String? = null,
val isControlRequired: Boolean? = null,
val hasNoUnitAvailable: Boolean? = null,
val createdAt: ZonedDateTime,
val validityTime: Int? = null,
val isArchived: Boolean,
val openBy: String? = null,
val missionId: Int? = null,
val attachedToMissionAtUtc: ZonedDateTime? = null,
val detachedFromMissionAtUtc: ZonedDateTime? = null,
val attachedEnvActionId: UUID? = null,
val attachedMission: ReportingMissionDataOutput? = null,
val id: Int,
val reportingId: Long? = null,
val sourceType: SourceTypeEnum? = null,
val semaphoreId: Int? = null,
val semaphore: SemaphoreDataOutput? = null,
val controlUnitId: Int? = null,
val controlUnit: ControlUnitDataOutput? = null,
val displayedSource: String? = null,
val sourceName: String? = null,
val targetType: TargetTypeEnum? = null,
val vehicleType: VehicleTypeEnum? = null,
val targetDetails: List<TargetDetailsEntity>? = listOf(),
val geom: Geometry? = null,
val seaFront: String? = null,
val description: String? = null,
val reportType: ReportingTypeEnum? = null,
val theme: String? = null,
val subThemes: List<String>? = listOf(),
val actionTaken: String? = null,
val isControlRequired: Boolean? = null,
val hasNoUnitAvailable: Boolean? = null,
val createdAt: ZonedDateTime,
val validityTime: Int? = null,
val isArchived: Boolean,
val openBy: String? = null,
val missionId: Int? = null,
val attachedToMissionAtUtc: ZonedDateTime? = null,
val detachedFromMissionAtUtc: ZonedDateTime? = null,
val attachedEnvActionId: UUID? = null,
val attachedMission: ReportingMissionDataOutput? = null,
val controlStatus: ControlStatusEnum? = null,
) {
companion object {
fun fromReportingDTO(
dto: ReportingDTO,
dto: ReportingDTO,
): ReportingDataOutput {
requireNotNull(dto.reporting.id) { "ReportingEntity.id cannot be null" }
return ReportingDataOutput(
id = dto.reporting.id!!,
reportingId = dto.reporting.reportingId,
sourceType = dto.reporting.sourceType,
semaphoreId = dto.reporting.semaphoreId,
semaphore = if (dto.semaphore != null) {
SemaphoreDataOutput.fromSemaphoreEntity(
dto.semaphore,
)
} else {
null
},
controlUnitId = dto.reporting.controlUnitId,
controlUnit =
if (dto.controlUnit != null) {
ControlUnitDataOutput
.fromFullControlUnit(
dto.controlUnit,
)
} else {
null
},
displayedSource =
when (dto.reporting.sourceType) {
SourceTypeEnum.SEMAPHORE -> dto?.semaphore?.unit ?: dto?.semaphore?.name
// TODO This is really strange : `fullControlUnit?.controlUnit` can't be null and I have to add another `?`...
SourceTypeEnum.CONTROL_UNIT -> dto?.controlUnit?.controlUnit?.name
SourceTypeEnum.OTHER -> dto.reporting.sourceName
else -> ""
},
sourceName = dto.reporting.sourceName,
targetType = dto.reporting.targetType,
vehicleType = dto.reporting.vehicleType,
targetDetails = dto.reporting.targetDetails,
geom = dto.reporting.geom,
seaFront = dto.reporting.seaFront,
description = dto.reporting.description,
reportType = dto.reporting.reportType,
theme = dto.reporting.theme,
subThemes = dto.reporting.subThemes,
actionTaken = dto.reporting.actionTaken,
isControlRequired = dto.reporting.isControlRequired,
hasNoUnitAvailable = dto.reporting.hasNoUnitAvailable,
createdAt = dto.reporting.createdAt,
validityTime = dto.reporting.validityTime,
isArchived = dto.reporting.isArchived,
openBy = dto.reporting.openBy,
missionId = dto.reporting.missionId,
attachedToMissionAtUtc = dto.reporting.attachedToMissionAtUtc,
detachedFromMissionAtUtc = dto.reporting.detachedFromMissionAtUtc,
attachedEnvActionId = dto.reporting.attachedEnvActionId,
attachedMission = if (dto.attachedMission != null) {
ReportingMissionDataOutput.fromMission(
dto.attachedMission,
)
} else {
null
},
id = dto.reporting.id!!,
reportingId = dto.reporting.reportingId,
sourceType = dto.reporting.sourceType,
semaphoreId = dto.reporting.semaphoreId,
semaphore =
if (dto.semaphore != null) {
SemaphoreDataOutput.fromSemaphoreEntity(
dto.semaphore,
)
} else {
null
},
controlUnitId = dto.reporting.controlUnitId,
controlUnit =
if (dto.controlUnit != null) {
ControlUnitDataOutput.fromFullControlUnit(
dto.controlUnit,
)
} else {
null
},
displayedSource =
when (dto.reporting.sourceType) {
SourceTypeEnum.SEMAPHORE -> dto?.semaphore?.unit
?: dto?.semaphore?.name
// TODO This is really strange : `fullControlUnit?.controlUnit`
// can't be null and I have to add another `?`...
SourceTypeEnum.CONTROL_UNIT -> dto?.controlUnit?.controlUnit?.name
SourceTypeEnum.OTHER -> dto.reporting.sourceName
else -> ""
},
sourceName = dto.reporting.sourceName,
targetType = dto.reporting.targetType,
vehicleType = dto.reporting.vehicleType,
targetDetails = dto.reporting.targetDetails,
geom = dto.reporting.geom,
seaFront = dto.reporting.seaFront,
description = dto.reporting.description,
reportType = dto.reporting.reportType,
theme = dto.reporting.theme,
subThemes = dto.reporting.subThemes,
actionTaken = dto.reporting.actionTaken,
isControlRequired = dto.reporting.isControlRequired,
hasNoUnitAvailable = dto.reporting.hasNoUnitAvailable,
createdAt = dto.reporting.createdAt,
validityTime = dto.reporting.validityTime,
isArchived = dto.reporting.isArchived,
openBy = dto.reporting.openBy,
controlStatus = dto.controlStatus,
missionId = dto.reporting.missionId,
attachedToMissionAtUtc = dto.reporting.attachedToMissionAtUtc,
detachedFromMissionAtUtc = dto.reporting.detachedFromMissionAtUtc,
attachedEnvActionId = dto.reporting.attachedEnvActionId,
attachedMission =
if (dto.attachedMission != null) {
ReportingMissionDataOutput.fromMission(
dto.attachedMission,
)
} else {
null
},
)
}
}
Expand Down
Loading

0 comments on commit 0fdfa03

Please sign in to comment.