Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Mission): getMission from Env #491

Merged
merged 1 commit into from
Jan 13, 2025
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 @@ -6,7 +6,7 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionTypeEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.controlResources.LegacyControlUnitEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionEntity
import org.locationtech.jts.geom.MultiPolygon
import java.time.ZonedDateTime
import java.time.Instant

data class MissionEnvEntity(
val id: Int? = null,
Expand All @@ -21,11 +21,11 @@ data class MissionEnvEntity(
val facade: String? = null,
val geom: MultiPolygon? = null,
@Patchable
var startDateTimeUtc: ZonedDateTime,
var startDateTimeUtc: Instant,
@Patchable
var endDateTimeUtc: ZonedDateTime? = null,
val createdAtUtc: ZonedDateTime? = null,
val updatedAtUtc: ZonedDateTime? = null,
var endDateTimeUtc: Instant? = null,
val createdAtUtc: Instant? = null,
val updatedAtUtc: Instant? = null,
val envActions: List<EnvActionEntity>? = listOf(),
val isDeleted: Boolean,
val isGeometryComputedFromControls: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2

import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionTypeEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.controlResources.LegacyControlUnitEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.env.MissionEnvEntity
import org.locationtech.jts.geom.MultiPolygon
import java.time.ZonedDateTime
import java.time.Instant

data class MissionEnv(
val id: Int? = null,
Expand All @@ -17,16 +18,17 @@ data class MissionEnv(
val observationsCnsp: String? = null,
val facade: String? = null,
val geom: MultiPolygon? = null,
val startDateTimeUtc: ZonedDateTime,
val endDateTimeUtc: ZonedDateTime? = null,
val startDateTimeUtc: Instant? = null,
val endDateTimeUtc: Instant? = null,
val missionSource: MissionSourceEnum,
val hasMissionOrder: Boolean,
val isUnderJdp: Boolean = false,
val isDeleted: Boolean? = null,
val isGeometryComputedFromControls: Boolean = false,
) {

companion object {
fun fromMissionEntity(mission: MissionEnvEntity): MissionEnv {
fun fromMissionEnvEntity(mission: MissionEnvEntity): MissionEnv {
return MissionEnv(
id = mission.id,
missionSource = mission.missionSource,
Expand All @@ -36,27 +38,29 @@ data class MissionEnv(
controlUnits = mission.controlUnits,
hasMissionOrder = mission.hasMissionOrder,
missionTypes = mission.missionTypes,
isDeleted = mission.isDeleted
)
}

fun fromMissionEntity(mission: MissionEntity): MissionEnv {
return MissionEnv(
id = mission.id,
missionTypes = mission.missionTypes,
controlUnits = mission.controlUnits,
openBy = mission.openBy,
completedBy = mission.completedBy,
observationsCacem = mission.observationsCacem,
observationsCnsp = mission.observationsCnsp,
facade = mission.facade,
geom = mission.geom,
startDateTimeUtc = mission.startDateTimeUtc,
endDateTimeUtc = mission.endDateTimeUtc,
isDeleted = mission.isDeleted,
missionSource = mission.missionSource,
hasMissionOrder = mission.hasMissionOrder,
isUnderJdp = mission.isUnderJdp,
isGeometryComputedFromControls = mission.isGeometryComputedFromControls,
)
}
}
fun toMissionEntity(): MissionEnvEntity {
return MissionEnvEntity(
id = this.id,
missionTypes = this.missionTypes,
controlUnits = this.controlUnits,
openBy = this.openBy,
completedBy = this.completedBy,
observationsCacem = this.observationsCacem,
observationsCnsp = this.observationsCnsp,
facade = this.facade,
geom = this.geom,
startDateTimeUtc = this.startDateTimeUtc,
endDateTimeUtc = this.endDateTimeUtc,
isDeleted = false,
missionSource = this.missionSource,
hasMissionOrder = this.hasMissionOrder,
isUnderJdp = this.isUnderJdp,
isGeometryComputedFromControls = this.isGeometryComputedFromControls,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.generalInfo
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionTypeEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionReinforcementTypeEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.MissionReportTypeEnum
import java.time.ZonedDateTime
import java.time.Instant

data class MissionGeneralInfo2(
val startDateTimeUtc: ZonedDateTime,
val endDateTimeUtc: ZonedDateTime? = null,
val startDateTimeUtc: Instant,
val endDateTimeUtc: Instant? = null,
val missionReportType: MissionReportTypeEnum,
val missionTypes: List<MissionTypeEnum>,
val reinforcementType: MissionReinforcementTypeEnum? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
package fr.gouv.dgampa.rapportnav.infrastructure.api.bff.v2

import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.CreateEnvMission
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.v2.GetEnvMissionById2
import fr.gouv.dgampa.rapportnav.domain.use_cases.user.GetControlUnitsForUser
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionEnv
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.generalInfo.MissionGeneralInfo2
import io.swagger.v3.oas.annotations.Operation
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/api/v2/missions")
class MissionRestController(
private val createEnvMission: CreateEnvMission,
private val getEnvMissionById2: GetEnvMissionById2,
private val getControlUnitsForUser: GetControlUnitsForUser,
) {

private val logger = LoggerFactory.getLogger(MissionRestController::class.java)

@GetMapping("{missionId}")
fun getMissionById(
@PathVariable(name = "missionId") missionId: Int
): MissionEnv? {
try {
val mission = getEnvMissionById2.execute(missionId) ?: return null
return MissionEnv.fromMissionEntity(mission)
}
catch (e: Exception) {
logger.error("Error while creating MonitorEnv mission : ", e)
return null
}
}

@PostMapping("")
@Operation(summary = "Create a new MonitorEnv mission")
fun createMission(
Expand All @@ -29,13 +42,8 @@ class MissionRestController(
val mission = createEnvMission.execute(
missionGeneralInfo = body,
controlUnitIds = getControlUnitsForUser.execute()
)

if (mission != null) {
return MissionEnv.fromMissionEntity(mission)
}

throw RuntimeException("Error - can't create new MonitorEnv mission")
)?: return null
return MissionEnv.fromMissionEnvEntity(mission)
}
catch (e: Exception) {
logger.error("Error while creating MonitorEnv mission : ", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionTypeEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.controlResources.LegacyControlUnitEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions.EnvActionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.env.MissionEnvEntity
import org.locationtech.jts.geom.MultiPolygon
import java.time.ZonedDateTime

Expand Down Expand Up @@ -51,4 +52,27 @@ data class MissionDataOutput @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) co
observationsByUnit = observationsByUnit
)
}

fun toMissionEnvEntity(): MissionEnvEntity {
return MissionEnvEntity(
id = id,
missionTypes = missionTypes,
controlUnits = controlUnits.orEmpty(),
openBy = openBy,
completedBy = completedBy,
observationsCacem = observationsCacem,
observationsCnsp = observationsCnsp,
facade = facade,
geom = geom,
startDateTimeUtc = startDateTimeUtc.toInstant(),
endDateTimeUtc = endDateTimeUtc?.toInstant(),
envActions = envActions,
missionSource = missionSource,
hasMissionOrder = hasMissionOrder,
isUnderJdp = isUnderJdp,
isGeometryComputedFromControls = isGeometryComputedFromControls,
isDeleted = false, // TODO this is weird,
observationsByUnit = observationsByUnit
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fr.gouv.dgampa.rapportnav.config.HttpClientFactory
import fr.gouv.dgampa.rapportnav.domain.entities.mission.v2.env.MissionEnvEntity
import fr.gouv.dgampa.rapportnav.domain.repositories.v2.mission.IEnvMissionRepository
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.v2.MissionEnv
import fr.gouv.dgampa.rapportnav.infrastructure.monitorenv.v2.outputs.MissionEnvDataOutput
import fr.gouv.dgampa.rapportnav.infrastructure.monitorenv.output.MissionDataOutput
import fr.gouv.dgampa.rapportnav.infrastructure.utils.GsonSerializer
import org.n52.jackson.datatype.jts.JtsModule
import org.slf4j.Logger
Expand Down Expand Up @@ -45,14 +45,14 @@ class APIEnvMissionRepositoryV2(
.build();

val response = client.send(request, HttpResponse.BodyHandlers.ofString());
logger.debug("Response received, Status code: ${response.statusCode()}");
logger.info("Response received, Status code: ${response.statusCode()}");

val body = response.body()
logger.debug(body)
logger.info(body)

mapper.registerModule(JtsModule())
val output: MissionEnvDataOutput? = mapper.readValue(body);
output?.toMissionEnvEntity()
val missionDataOutput: MissionDataOutput? = mapper.readValue(body);
missionDataOutput?.toMissionEnvEntity();
} catch (e: Exception) {
logger.error("Failed to POST request for Env action creation. URL: $url", e);
null;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading