Skip to content

Commit

Permalink
[Reporting] some bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Oct 13, 2023
1 parent 0fdfa03 commit cfc8971
Show file tree
Hide file tree
Showing 23 changed files with 441 additions and 755 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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
import java.time.ZonedDateTime

@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)

Expand All @@ -32,6 +32,7 @@ class CreateOrUpdateReporting(
var attachedToMissionAtUtc: ZonedDateTime? = null
var detachedFromMissionAtUtc: ZonedDateTime? = null
if (reporting.missionId != null) {
// TO CHECK if the date is with or without UTC
attachedToMissionAtUtc = ZonedDateTime.now()
detachedFromMissionAtUtc = null
}
Expand All @@ -41,13 +42,13 @@ class CreateOrUpdateReporting(
}

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

return savedReport
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,110 +8,111 @@ 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 controlStatus: ControlStatusEnum? = 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,
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
},
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 cfc8971

Please sign in to comment.