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

[Mission] Amélioration continue #1895

Merged
merged 10 commits into from
Dec 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ data class InfractionEntity(
val formalNotice: FormalNoticeEnum,
val mmsi: String? = null,
val nbTarget: Int = 1,
val toProcess: Boolean,
val controlledPersonIdentity: String? = null,
val vesselName: String? = null,
val vesselSize: Number? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ data class MissionEnvActionControlInfractionDataInput(
val nbTarget: Int,
val observations: String? = null,
val registrationNumber: String? = null,
val relevantCourt: String? = null,
val toProcess: Boolean,
val vesselName: String? = null,
val vesselType: VesselTypeEnum? = null,
val vesselSize: Number? = null,
Expand All @@ -39,8 +37,6 @@ data class MissionEnvActionControlInfractionDataInput(
nbTarget = nbTarget,
observations = observations,
registrationNumber = registrationNumber,
relevantCourt = relevantCourt,
toProcess = toProcess,
vesselName = vesselName,
vesselType = vesselType,
vesselSize = vesselSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.envActionContr
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.MissionModel
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBControlPlanSubThemeRepository
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBControlPlanTagRepository
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBControlPlanThemeRepository
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBControlUnitResourceRepository
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBMissionRepository
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.*
import org.apache.commons.lang3.StringUtils
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Pageable
Expand Down Expand Up @@ -137,22 +133,26 @@ class JpaMissionRepository(
return true
}

return mission.envActions?.any { action ->
(action as? EnvActionControlEntity)?.infractions?.any { infraction ->
listOf(
infraction.imo,
infraction.mmsi,
infraction.registrationNumber,
infraction.vesselName,
infraction.companyName,
infraction.controlledPersonIdentity,
).any { field ->
!field.isNullOrBlank() &&
normalizeField(field)
.contains(normalizeField(searchQuery), ignoreCase = true)
}
return mission.id?.toString()?.let {
normalizeField(it)
.contains(normalizeField(searchQuery), ignoreCase = true)
} == true ||
mission.envActions?.any { action ->
(action as? EnvActionControlEntity)?.infractions?.any { infraction ->
listOf(
infraction.imo,
infraction.mmsi,
infraction.registrationNumber,
infraction.vesselName,
infraction.companyName,
infraction.controlledPersonIdentity,
).any { field ->
!field.isNullOrBlank() &&
normalizeField(field)
.contains(normalizeField(searchQuery), ignoreCase = true)
}
} ?: false
} ?: false
} ?: false
}

private fun normalizeField(input: String): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UPDATE public.env_actions
SET value = value - 'revelantCourt' - 'toProcess';
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ COPY public.env_actions (id, mission_id, action_type, value, action_start_dateti
dfb9710a-2217-4f98-94dc-283d3b7bbaae 14 SURVEILLANCE {"actionTheme": "Activités et manifestations soumises à évaluation d’incidence Natura 2000"} \N \N
d8e580fe-8e71-4303-a0c3-a76e1d4e4fc2 14 CONTROL {"actionTheme": "", "infractions": [], "vehicleType": "VESSEL", "actionSubTheme": "", "actionTargetType": "VEHICLE", "protectedSpecies": [], "actionNumberOfControls": 0, "actionStartDateTimeUtc": null} 2022-11-24 20:31:41.719 0104000020E61000000200000001010000001953F2E2ABBA05C0E86DA621AE164840010100000088DE5EA999B305C08EE55DF500184840
88713755-3966-4ca4-ae18-10cab6249485 34 SURVEILLANCE {"duration": 1.0, "actionTheme": "Police des activités de cultures marines", "observations": "Surveillance ok", "actionSubTheme": "Contrôle du schéma des structures", "protectedSpecies": []} 2022-11-28 13:59:20.176 \N
b05d96b8-387f-4599-bff0-cd7dab71dfb8 34 CONTROL {"actionTheme": "Activités et manifestations soumises à évaluation d’incidence Natura 2000", "infractions": [{"id": "c52c6f20-e495-4b29-b3df-d7edfb67fdd7", "natinf": ["10038", "10054"], "toProcess": false, "vesselSize": "FROM_24_TO_46m", "vesselType": "COMMERCIAL", "companyName": null, "formalNotice": "PENDING", "observations": "Pas d'observations", "relevantCourt": "LOCAL_COURT", "infractionType": "WITH_REPORT", "registrationNumber": "BALTIK", "controlledPersonIdentity": "John Doe"}], "vehicleType": "VESSEL", "actionSubTheme": "Contrôle administratif", "actionTargetType": "VEHICLE", "protectedSpecies": [], "actionNumberOfControls": 1, "actionStartDateTimeUtc": null} 2022-11-17 13:59:51.108 0104000020E6100000010000000101000000E48FE404EC2CE2BF1C3DBD1E1CBA4840
b05d96b8-387f-4599-bff0-cd7dab71dfb8 34 CONTROL {"actionTheme": "Activités et manifestations soumises à évaluation d’incidence Natura 2000", "infractions": [{"id": "c52c6f20-e495-4b29-b3df-d7edfb67fdd7", "natinf": ["10038", "10054"], "vesselSize": "FROM_24_TO_46m", "vesselType": "COMMERCIAL", "companyName": null, "formalNotice": "PENDING", "observations": "Pas d'observations", "infractionType": "WITH_REPORT", "registrationNumber": "BALTIK", "controlledPersonIdentity": "John Doe"}], "vehicleType": "VESSEL", "actionSubTheme": "Contrôle administratif", "actionTargetType": "VEHICLE", "protectedSpecies": [], "actionNumberOfControls": 1, "actionStartDateTimeUtc": null} 2022-11-17 13:59:51.108 0104000020E6100000010000000101000000E48FE404EC2CE2BF1C3DBD1E1CBA4840
dedbd2c2-10f5-4d75-8fe9-c50db2ae5d0b 38 CONTROL {"actionTheme": "", "infractions": [], "vehicleType": "VESSEL", "actionSubTheme": "", "actionTargetType": "VEHICLE", "protectedSpecies": [], "actionNumberOfControls": 0, "actionStartDateTimeUtc": null} 2022-11-24 20:31:41.719 0104000020E61000000200000001010000001953F2E2ABBA05C0E86DA621AE164840010100000088DE5EA999B305C08EE55DF500184840
\.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ VALUES ('e2257638-ddef-4611-960c-7675a3254c38', 38, 'SURVEILLANCE', '{
"natinf": [
"10041"
],
"toProcess": false,
"vesselSize": 23,
"vesselType": "COMMERCIAL",
"companyName": "MASOCIETE",
"formalNotice": "YES",
"observations": "RAS",
"relevantCourt": "LOCAL_COURT",
"infractionType": "WITH_REPORT",
"administrativeResponse": "REGULARIZATION",
"registrationNumber": null,
Expand Down Expand Up @@ -58,13 +56,11 @@ VALUES ('e2257638-ddef-4611-960c-7675a3254c38', 38, 'SURVEILLANCE', '{
"10231",
"10228"
],
"toProcess": true,
"vesselSize": 11,
"vesselType": null,
"companyName": null,
"formalNotice": "PENDING",
"observations": "RAS",
"relevantCourt": "PRE",
"infractionType": "WAITING",
"administrativeResponse": "PENDING",
"registrationNumber": null,
Expand Down Expand Up @@ -92,13 +88,11 @@ VALUES ('e2257638-ddef-4611-960c-7675a3254c38', 38, 'SURVEILLANCE', '{
"10038",
"10231"
],
"toProcess": false,
"vesselSize": 45,
"vesselType": "COMMERCIAL",
"companyName": null,
"formalNotice": "PENDING",
"observations": "Pas d''observations",
"relevantCourt": "LOCAL_COURT",
"infractionType": "WITH_REPORT",
"administrativeResponse": "PENDING",
"registrationNumber": "BALTIK",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,25 @@ import java.util.UUID
@AutoConfigureMockMvc(addFilters = false)
@WebMvcTest(value = [(Missions::class)])
class MissionsITests {
@Autowired
private lateinit var mockMvc: MockMvc
@Autowired private lateinit var mockMvc: MockMvc

@MockBean
private lateinit var createOrUpdateMissionWithActionsAndAttachedReporting:
CreateOrUpdateMissionWithActionsAndAttachedReporting

@MockBean
private lateinit var getFullMissions: GetFullMissions
@MockBean private lateinit var getFullMissions: GetFullMissions

@MockBean
private lateinit var getFullMissionWithFishAndRapportNavActions: GetFullMissionWithFishAndRapportNavActions
private lateinit var getFullMissionWithFishAndRapportNavActions:
GetFullMissionWithFishAndRapportNavActions

@MockBean
private lateinit var deleteMission: DeleteMission
@MockBean private lateinit var deleteMission: DeleteMission

@MockBean
private lateinit var canDeleteMission: CanDeleteMission
@MockBean private lateinit var canDeleteMission: CanDeleteMission

@MockBean
private lateinit var getEngagedControlUnits: GetEngagedControlUnits
@MockBean private lateinit var getEngagedControlUnits: GetEngagedControlUnits

@Autowired
private lateinit var objectMapper: ObjectMapper
@Autowired private lateinit var objectMapper: ObjectMapper

private val polygon =
WKTReader()
Expand Down Expand Up @@ -172,12 +167,13 @@ class MissionsITests {
),
)
// we test only if the route is called with the right arg
given(getFullMissionWithFishAndRapportNavActions.execute(requestedId)).willReturn(
Pair(
false,
expectedFirstMission,
),
)
given(getFullMissionWithFishAndRapportNavActions.execute(requestedId))
.willReturn(
Pair(
false,
expectedFirstMission,
),
)

// When
mockMvc.perform(get("/bff/v1/missions/$requestedId"))
Expand Down Expand Up @@ -429,12 +425,6 @@ class MissionsITests {
equalTo("Company Name"),
),
)
.andExpect(
jsonPath(
"$[0].envActions[0].infractions[0].relevantCourt",
equalTo("LOCAL_COURT"),
),
)
.andExpect(
jsonPath(
"$[0].envActions[0].infractions[0].infractionType",
Expand All @@ -447,7 +437,6 @@ class MissionsITests {
equalTo(FormalNoticeEnum.NO.toString()),
),
)
.andExpect(jsonPath("$[0].envActions[0].infractions[0].toProcess", equalTo(false)))
.andExpect(
jsonPath(
"$[0].envActions[0].infractions[0].controlledPersonIdentity",
Expand Down Expand Up @@ -585,12 +574,13 @@ class MissionsITests {
)

// we test only if the route is called with the right arg
given(getFullMissionWithFishAndRapportNavActions.execute(requestedId)).willReturn(
Pair(
true,
expectedFirstMission,
),
)
given(getFullMissionWithFishAndRapportNavActions.execute(requestedId))
.willReturn(
Pair(
true,
expectedFirstMission,
),
)

// When
mockMvc.perform(get("/bff/v1/missions/$requestedId"))
Expand Down Expand Up @@ -706,12 +696,6 @@ class MissionsITests {
equalTo("Company Name"),
),
)
.andExpect(
jsonPath(
"$.envActions[0].infractions[0].relevantCourt",
equalTo("LOCAL_COURT"),
),
)
.andExpect(
jsonPath(
"$.envActions[0].infractions[0].infractionType",
Expand All @@ -724,7 +708,6 @@ class MissionsITests {
equalTo(FormalNoticeEnum.NO.toString()),
),
)
.andExpect(jsonPath("$.envActions[0].infractions[0].toProcess", equalTo(false)))
.andExpect(
jsonPath(
"$.envActions[0].infractions[0].controlledPersonIdentity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class TestUtils {
observations = "Observations de l'infraction",
registrationNumber = "AB-123-CD",
companyName = "Company Name",
relevantCourt = "LOCAL_COURT",
infractionType = InfractionTypeEnum.WAITING,
formalNotice = FormalNoticeEnum.NO,
toProcess = false,
controlledPersonIdentity = "Captain Flame",
vesselType = VesselTypeEnum.COMMERCIAL,
vesselSize = 23,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException
import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.transaction.annotation.Transactional
import java.time.ZonedDateTime
import java.util.UUID
import java.util.*

@ExtendWith(SpringExtension::class)
@Import(DataSourceProxyBeanPostProcessor::class)
Expand Down Expand Up @@ -351,6 +351,27 @@ class JpaMissionRepositoryITests : AbstractDBTests() {
println("Number of Queries Executed: $queryCount")
}

@Test
@Transactional
fun `findAll Should return filtered missions when search query is an id`() {
// When
val missions =
jpaMissionRepository.findAllFullMissions(
startedAfter = ZonedDateTime.parse("2000-01-01T00:01:00Z").toInstant(),
startedBefore = null,
missionTypes = null,
seaFronts = null,
missionStatuses = null,
pageNumber = null,
pageSize = null,
searchQuery = "53",
)
assertThat(missions).hasSize(1)

val queryCount = customQueryCountListener!!.getQueryCount()
println("Number of Queries Executed: $queryCount")
}

@Test
@Transactional
fun `findAll with pagenumber and pagesize Should return subset of missions`() {
Expand Down Expand Up @@ -519,7 +540,8 @@ class JpaMissionRepositoryITests : AbstractDBTests() {
assertThat(existingMissions).hasSize(21)

val noteObservations = "Quelqu'un aurait vu quelque chose quelque part à un certain moment."
val noteObservationsByUnit = "Une unité aurait vu quelque chose quelque part à un certain moment."
val noteObservationsByUnit =
"Une unité aurait vu quelque chose quelque part à un certain moment."

val newMission =
MissionEntity(
Expand Down Expand Up @@ -860,10 +882,8 @@ class JpaMissionRepositoryITests : AbstractDBTests() {
observations = "This is an infraction",
registrationNumber = "REGISTRATION NUM",
companyName = "ACME inc.",
relevantCourt = "MARITIME_COURT",
infractionType = InfractionTypeEnum.WITHOUT_REPORT,
formalNotice = FormalNoticeEnum.NO,
toProcess = false,
controlledPersonIdentity = "Dick Hoover",
vesselType = VesselTypeEnum.FISHING,
vesselSize = 23,
Expand Down
Loading
Loading