Skip to content

Commit

Permalink
feat(services): add list of services to a mission
Browse files Browse the repository at this point in the history
 - update service repository to return service with list of control units
 - create use case to getserviceWith control unit
 - update getNavMission to return services attributes
 - Add services to service Entity
 - Update graphQl definition of mission to add services
 - Test every steps
  • Loading branch information
xtiannyeto committed Jun 6, 2024
1 parent 349573b commit 1422ff4
Show file tree
Hide file tree
Showing 15 changed files with 309 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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.nav.NavMissionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.ServiceEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ExtendedFishActionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.crew.MissionCrewEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.generalInfo.MissionGeneralInfoEntity
Expand Down Expand Up @@ -33,15 +34,16 @@ data class MissionEntity(
val generalInfo: MissionGeneralInfoEntity? = null,
val crew: List<MissionCrewEntity>? = null,
var status: MissionStatusEnum? = null,
var completenessForStats: CompletenessForStatsEntity? = null
var completenessForStats: CompletenessForStatsEntity? = null,
var services: List<ServiceEntity>? = null
) {

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

constructor(
envMission: ExtendedEnvMissionEntity,
navMission: NavMissionEntity? = null,
fishMissionActions: List<ExtendedFishActionEntity>? = null
fishMissionActions: List<ExtendedFishActionEntity>? = null,
) : this(
id = (envMission.mission.id)!!,
missionTypes = envMission.mission.missionTypes,
Expand All @@ -66,6 +68,7 @@ data class MissionEntity(
),
generalInfo = navMission?.generalInfo,
crew = navMission?.crew,
services = navMission?.services
) {
this.status = this.calculateMissionStatus(
startDateTimeUtc = envMission.mission.startDateTimeUtc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ data class NavMissionEntity(
val actions: List<NavActionEntity> = emptyList(),
val generalInfo: MissionGeneralInfoEntity? = null,
val crew: List<MissionCrewEntity>? = null,
val services: List<ServiceEntity>? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fr.gouv.dgampa.rapportnav.domain.repositories.mission.crew

import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.crew.AgentModel

interface IAgentRepository {

fun findAll(): List<AgentModel>
fun findByServiceId(serviceId: Int): List<AgentModel>

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package fr.gouv.dgampa.rapportnav.domain.repositories.mission.crew

import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.ControlUnit
import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.ServiceModel
import java.util.*

interface IServiceRepository {
fun existsById(id: Int): Boolean
fun findById(id: Int): Optional<ServiceModel>
fun findAll(): List<ServiceModel>
fun findByControlUnitId(controlUnitIds: List<Int>): List<ServiceModel>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package fr.gouv.dgampa.rapportnav.domain.use_cases.mission

import fr.gouv.dgampa.rapportnav.config.UseCase
import fr.gouv.dgampa.rapportnav.domain.entities.mission.MissionEntity
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.crew.GetAgentsCrewByMissionId
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.crew.GetServiceByControlUnit
import org.slf4j.LoggerFactory

@UseCase
Expand All @@ -15,7 +17,7 @@ class GetMissionById(
fun execute(missionId: Int): MissionEntity? {
val envMission = getEnvMissionById.execute(missionId = missionId) ?: return null
val fishMissionActions = getFishActionsByMissionId.execute(missionId = missionId)
val navMission = getNavMissionById.execute(missionId = missionId)
val navMission = getNavMissionById.execute(missionId = missionId, envMission.mission.controlUnits)

return MissionEntity(envMission, navMission, fishMissionActions)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package fr.gouv.dgampa.rapportnav.domain.use_cases.mission

import fr.gouv.dgampa.rapportnav.config.UseCase
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.controlResources.LegacyControlUnitEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.NavMissionEntity
import fr.gouv.dgampa.rapportnav.domain.repositories.mission.action.*
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.AttachControlsToActionControl
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.crew.GetAgentsCrewByMissionId
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.crew.GetServiceByControlUnit
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.generalInfo.GetMissionGeneralInfoByMissionId
import org.slf4j.LoggerFactory

Expand All @@ -16,6 +18,7 @@ class GetNavMissionById(
private val attachControlsToActionControl: AttachControlsToActionControl,
private val getMissionGeneralInfoByMissionId: GetMissionGeneralInfoByMissionId,
private val getAgentsCrewByMissionId: GetAgentsCrewByMissionId,
private val getServiceByControlUnit: GetServiceByControlUnit,
private val navRescueRepository: INavActionRescueRepository,
private val navNauticalEventRepository: INavActionNauticalEventRepository,
private val navVigimerRepository: INavActionVigimerRepository,
Expand All @@ -27,7 +30,7 @@ class GetNavMissionById(
) {
private val logger = LoggerFactory.getLogger(GetNavMissionById::class.java)

fun execute(missionId: Int): NavMissionEntity {
fun execute(missionId: Int, controlUnits: List<LegacyControlUnitEntity>? = null): NavMissionEntity {
val controls = navActionControlRepository
.findAllByMissionId(missionId = missionId)
.map { actionControl ->
Expand All @@ -48,6 +51,7 @@ class GetNavMissionById(

val generalInfo = getMissionGeneralInfoByMissionId.execute(missionId)


val crew = getAgentsCrewByMissionId.execute(
missionId = missionId
)
Expand Down Expand Up @@ -84,9 +88,17 @@ class GetNavMissionById(
.map { it.toActionIllegalImmigrationEntity() }
.map { it.toNavActionEntity() }

val services = getServiceByControlUnit.execute(controlUnits)

val actions =
controls + statuses + notes + rescues + nauticalEvents + vigimers + antiPollutions + baaemPermanences + representations + publicOrders + illegalImmigrations
val mission = NavMissionEntity(id = missionId, actions = actions, generalInfo = generalInfo, crew = crew)
val mission = NavMissionEntity(
id = missionId,
actions = actions,
generalInfo = generalInfo,
crew = crew,
services = services
)
return mission
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fr.gouv.dgampa.rapportnav.domain.use_cases.mission.crew

import fr.gouv.dgampa.rapportnav.config.UseCase
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.controlResources.LegacyControlUnitEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.ServiceEntity
import fr.gouv.dgampa.rapportnav.domain.repositories.mission.crew.IServiceRepository

@UseCase
class GetServiceByControlUnit(private val serviceRepository: IServiceRepository) {

fun execute(controlUnits: List<LegacyControlUnitEntity>? = null): List<ServiceEntity> {
if (controlUnits == null) return listOf<ServiceEntity>();
return this.serviceRepository.findByControlUnitId(controlUnits.map { controlUnit -> controlUnit.id })
.map { it.toServiceEntity() }
.sortedBy { it.id };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.MissionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.CompletenessForStatsEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.MissionStatusEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.ServiceEntity
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.action.Action
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.crew.MissionCrew
import fr.gouv.dgampa.rapportnav.infrastructure.api.bff.model.generalInfo.MissionGeneralInfo
Expand All @@ -20,7 +21,8 @@ data class Mission(
val status: MissionStatusEnum? = null,
val completenessForStats: CompletenessForStatsEntity? = null,
val crew: List<MissionCrew>? = null,
val generalInfo: MissionGeneralInfo? = null
val generalInfo: MissionGeneralInfo? = null,
val services: List<ServiceEntity>? = null
) {
companion object {
fun fromMissionEntity(mission: MissionEntity): Mission {
Expand Down Expand Up @@ -50,7 +52,8 @@ data class Mission(
crew = mission.crew?.map { MissionCrew.fromMissionCrewEntity(it) },
generalInfo = MissionGeneralInfo.fromMissionGeneralInfoEntity(mission.generalInfo),
status = mission.status,
completenessForStats = mission.completenessForStats
completenessForStats = mission.completenessForStats,
services = mission.services
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fr.gouv.dgampa.rapportnav.infrastructure.database.model.mission.ServiceMo
import fr.gouv.dgampa.rapportnav.infrastructure.database.repositories.interfaces.mission.crew.IDBServiceRepository
import org.springframework.stereotype.Repository
import java.util.*
import java.util.logging.Filter

@Repository
class JPAServiceRepository(
Expand All @@ -22,4 +23,8 @@ class JPAServiceRepository(
override fun findAll(): List<ServiceModel> {
return repo.findAll()
}

override fun findByControlUnitId(controlUnitIds: List<Int>): List<ServiceModel>{
return repo.findAll().filter { serviceModel -> (serviceModel.controlUnits)!!.containsAll(controlUnitIds) }
}
}
1 change: 1 addition & 0 deletions backend/src/main/resources/graphql/mission.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Mission {
openBy: String
status: MissionStatusEnum
completenessForStats: CompletenessForStats
services: [Service]
}

enum MissionSourceEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.*
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.ActionCompletionEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.MissionSourceEnum
import fr.gouv.dgampa.rapportnav.domain.entities.mission.fish.fishActions.Completion
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.ServiceEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.action.ExtendedFishActionEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.crew.AgentEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.crew.AgentRoleEntity
Expand Down Expand Up @@ -212,6 +213,33 @@ class MissionEntityTests {
)
assertThat(mission.completenessForStats).isEqualTo(expected)
}


@Test
fun `should return have list of services`() {
val expected = listOf(
ServiceEntity(
id = 3,
name = "firstService",
controlUnits = listOf(1, 3)
), ServiceEntity(
id = 4,
name = "SecondService",
controlUnits = listOf(3, 4)
)
);
val mission = MissionEntity(
envMission = ExtendedEnvMissionEntity.fromEnvMission(
EnvMissionMock.create()
),
fishMissionActions = listOf(),
navMission = NavMissionMock.create(
services = expected
)
)
assertThat(mission.services).isNotNull()
assertThat(mission.services).isEqualTo(expected);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package fr.gouv.gmampa.rapportnav.domain.use_cases.mission

import fr.gouv.dgampa.rapportnav.domain.entities.mission.env.controlResources.LegacyControlUnitEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.ServiceEntity
import fr.gouv.dgampa.rapportnav.domain.repositories.mission.action.*
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.GetNavMissionById
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.action.AttachControlsToActionControl
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.crew.GetAgentsCrewByMissionId
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.crew.GetServiceByControlUnit
import fr.gouv.dgampa.rapportnav.domain.use_cases.mission.generalInfo.GetMissionGeneralInfoByMissionId
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.mock.mockito.MockBean

@SpringBootTest(classes = [GetNavMissionById::class])
class GetNavMissionByIdTest {

@Autowired
private lateinit var getMissionNavById: GetNavMissionById

@MockBean
private lateinit var getServiceByControlUnit: GetServiceByControlUnit

private val controlUnits: List<LegacyControlUnitEntity> = listOf(
LegacyControlUnitEntity(
id = 3,
administration = "Administration",
isArchived = false, name = "Themis",
resources = listOf(),
)
)

@MockBean
private lateinit var navActionControlRepository: INavActionControlRepository;

@MockBean
private lateinit var navStatusRepository: INavActionStatusRepository;

@MockBean
private lateinit var navFreeNoteRepository: INavActionFreeNoteRepository;

@MockBean
private lateinit var attachControlsToActionControl: AttachControlsToActionControl;

@MockBean
private lateinit var getMissionGeneralInfoByMissionId: GetMissionGeneralInfoByMissionId;

@MockBean
private lateinit var getAgentsCrewByMissionId: GetAgentsCrewByMissionId;

@MockBean
private lateinit var navRescueRepository: INavActionRescueRepository;

@MockBean
private lateinit var navNauticalEventRepository: INavActionNauticalEventRepository;

@MockBean
private lateinit var navVigimerRepository: INavActionVigimerRepository;

@MockBean
private lateinit var navAntiPollutionRepository: INavActionAntiPollutionRepository;

@MockBean
private lateinit var navBAAEMRepository: INavActionBAAEMRepository;

@MockBean
private lateinit var navPublicOrderRepository: INavActionPublicOrderRepository;

@MockBean
private lateinit var navRepresentationRepository: INavActionRepresentationRepository;

@MockBean
private lateinit var navIllegalImmigrationRepository: INavActionIllegalImmigrationRepository

private val serviceEntities: List<ServiceEntity> = listOf(
ServiceEntity(
id = 3,
name = "firstService",
controlUnits = listOf(1, 3)
), ServiceEntity(
id = 4,
name = "SecondService",
controlUnits = listOf(3, 4)
)
);

@Test
fun `execute should have services in nav mission entity`() {
Mockito.`when`(getServiceByControlUnit.execute(controlUnits)).thenReturn(serviceEntities);
val response = getMissionNavById.execute(2, controlUnits)

assertThat(response).isNotNull();
assertThat(response.services).isNotNull();
assertThat(response.services?.size).isEqualTo(2);
assertThat(response.services?.map { service -> service.id }).containsAll(listOf(3, 4));
}

}
Loading

0 comments on commit 1422ff4

Please sign in to comment.