Skip to content

Commit a56384e

Browse files
authored
[Préavis] Ajout d'un filtre "statut de diffusion" sur la liste (#3414)
## Linked issues - #3410 - #3407 ---- - [ ] Tests E2E (Cypress)
2 parents c40a79f + 820414a commit a56384e

File tree

14 files changed

+205
-24
lines changed

14 files changed

+205
-24
lines changed

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/CreateOrUpdateManualPriorNotification.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class CreateOrUpdateManualPriorNotification(
6262
val message = getMessage(
6363
hasPortEntranceAuthorization = hasPortEntranceAuthorization,
6464
hasPortLandingAuthorization = hasPortLandingAuthorization,
65-
existingPnoValue = existingPnoMessage,
6665
expectedArrivalDate = expectedArrivalDate,
6766
expectedLandingDate = expectedLandingDate,
6867
// At the moment, manual prior notifications only have a single global FAO area field in Frontend,
@@ -148,7 +147,6 @@ class CreateOrUpdateManualPriorNotification(
148147
}
149148

150149
private fun getMessage(
151-
existingPnoValue: PNO?,
152150
hasPortEntranceAuthorization: Boolean,
153151
hasPortLandingAuthorization: Boolean,
154152
purpose: LogbookMessagePurpose,
@@ -163,9 +161,11 @@ class CreateOrUpdateManualPriorNotification(
163161
): PNO {
164162
val allPorts = portRepository.findAll()
165163

166-
val isInVerificationScope = existingPnoValue?.isInVerificationScope
167-
?: ManualPriorNotificationComputedValues
168-
.computeIsInVerificationScope(computedVesselFlagCountryCode, computedVesselRiskFactor)
164+
val isInVerificationScope = ManualPriorNotificationComputedValues
165+
.computeIsInVerificationScope(computedVesselFlagCountryCode, computedVesselRiskFactor)
166+
// If the prior notification is not in verification scope,
167+
// we pass `isBeingSent` as `true` in order to ask the workflow to send it.
168+
val isBeingSent = !isInVerificationScope
169169
val portName = allPorts.find { it.locode == portLocode }?.name
170170

171171
return PNO().apply {
@@ -179,7 +179,9 @@ class CreateOrUpdateManualPriorNotification(
179179
// so we transform that single FAO area into an FAO area per fishing catch.
180180
// This means we don't need to set a global PNO message FAO area here.
181181
this.faoZone = null
182-
this.isBeingSent = false
182+
// If the prior notification is not in verification scope,
183+
// we pass `isBeingSent` as `true` in order to ask the workflow to send it.
184+
this.isBeingSent = isBeingSent
183185
this.isInVerificationScope = isInVerificationScope
184186
this.isSent = false
185187
this.isVerified = false

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification
33
import fr.gouv.cnsp.monitorfish.config.UseCase
44
import fr.gouv.cnsp.monitorfish.domain.entities.facade.SeafrontGroup
55
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotification
6+
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotificationState
67
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotificationStats
78
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.filters.PriorNotificationsFilter
89
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.sorters.PriorNotificationsSortColumn
@@ -24,6 +25,7 @@ class GetPriorNotifications(
2425
fun execute(
2526
filter: PriorNotificationsFilter,
2627
seafrontGroup: SeafrontGroup,
28+
states: List<PriorNotificationState>?,
2729
sortColumn: PriorNotificationsSortColumn,
2830
sortDirection: Sort.Direction,
2931
pageNumber: Int,
@@ -64,7 +66,7 @@ class GetPriorNotifications(
6466
compareByDescending<PriorNotification> { getSortKey(it, sortColumn) }
6567
.thenByDescending { it.logbookMessageTyped.logbookMessage.id }, // Tie-breaker
6668
)
67-
}.filter { seafrontGroup.hasSeafront(it.seafront) }
69+
}.filter { seafrontGroup.hasSeafront(it.seafront) && (states.isNullOrEmpty() || states.contains(it.state)) }
6870

6971
val extraData = PriorNotificationStats(
7072
perSeafrontGroupCount = SeafrontGroup.entries.associateWith { seafrontGroupEntry ->

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PriorNotificationController.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.gouv.cnsp.monitorfish.infrastructure.api.bff
22

33
import fr.gouv.cnsp.monitorfish.domain.entities.facade.SeafrontGroup
4+
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotificationState
45
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.filters.PriorNotificationsFilter
56
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.sorters.PriorNotificationsSortColumn
67
import fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification.*
@@ -74,6 +75,9 @@ class PriorNotificationController(
7475
@Parameter(description = "Seafront group.")
7576
@RequestParam(name = "seafrontGroup")
7677
seafrontGroup: SeafrontGroup,
78+
@Parameter(description = "States.")
79+
@RequestParam(name = "states")
80+
states: List<PriorNotificationState>? = null,
7781

7882
@Parameter(description = "Sort column.")
7983
@RequestParam(name = "sortColumn")
@@ -105,7 +109,7 @@ class PriorNotificationController(
105109
)
106110

107111
val paginatedPriorNotifications = getPriorNotifications
108-
.execute(priorNotificationsFilter, seafrontGroup, sortColumn, sortDirection, pageNumber, pageSize)
112+
.execute(priorNotificationsFilter, seafrontGroup, states, sortColumn, sortDirection, pageNumber, pageSize)
109113
val priorNotificationListItemDataOutputs = paginatedPriorNotifications.data
110114
.mapNotNull { PriorNotificationListItemDataOutput.fromPriorNotification(it) }
111115
val extraDataOutput = PriorNotificationsExtraDataOutput

backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationsITests.kt

Lines changed: 150 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification
22

33
import fr.gouv.cnsp.monitorfish.config.MapperConfiguration
4+
import fr.gouv.cnsp.monitorfish.domain.entities.facade.Seafront
45
import fr.gouv.cnsp.monitorfish.domain.entities.facade.SeafrontGroup
6+
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotificationState
57
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.filters.PriorNotificationsFilter
68
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.sorters.PriorNotificationsSortColumn
79
import fr.gouv.cnsp.monitorfish.domain.repositories.*
@@ -50,6 +52,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
5052
willArriveBefore = "2099-12-31T00:00:00Z",
5153
)
5254
private val defaultSeafrontGroup = SeafrontGroup.ALL
55+
private val defaultStates = null
5356
private val defaultSortColumn = PriorNotificationsSortColumn.EXPECTED_ARRIVAL_DATE
5457
private val defaultSortDirection = Sort.Direction.ASC
5558
private val defaultPageSize = 100
@@ -64,7 +67,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {
6467

6568
// When
6669
val result = getPriorNotifications
67-
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
70+
.execute(
71+
defaultFilter,
72+
defaultSeafrontGroup,
73+
defaultStates,
74+
sortColumn,
75+
sortDirection,
76+
defaultPageNumber,
77+
defaultPageSize,
78+
)
6879

6980
// Then
7081
val firstPriorNotificationWithNonNullArrivalDate = result.data
@@ -85,7 +96,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {
8596

8697
// When
8798
val result = getPriorNotifications
88-
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
99+
.execute(
100+
defaultFilter,
101+
defaultSeafrontGroup,
102+
defaultStates,
103+
sortColumn,
104+
sortDirection,
105+
defaultPageNumber,
106+
defaultPageSize,
107+
)
89108

90109
// Then
91110
val firstPriorNotificationWithNonNullArrivalDate = result.data
@@ -106,7 +125,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {
106125

107126
// When
108127
val result = getPriorNotifications
109-
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
128+
.execute(
129+
defaultFilter,
130+
defaultSeafrontGroup,
131+
defaultStates,
132+
sortColumn,
133+
sortDirection,
134+
defaultPageNumber,
135+
defaultPageSize,
136+
)
110137

111138
// Then
112139
val firstPriorNotificationWithNonNullLandingDate = result.data
@@ -127,7 +154,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {
127154

128155
// When
129156
val result = getPriorNotifications
130-
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
157+
.execute(
158+
defaultFilter,
159+
defaultSeafrontGroup,
160+
defaultStates,
161+
sortColumn,
162+
sortDirection,
163+
defaultPageNumber,
164+
defaultPageSize,
165+
)
131166

132167
// Then
133168
val firstPriorNotificationWithNonNullLandingDate = result.data
@@ -148,7 +183,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {
148183

149184
// When
150185
val result = getPriorNotifications
151-
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
186+
.execute(
187+
defaultFilter,
188+
defaultSeafrontGroup,
189+
defaultStates,
190+
sortColumn,
191+
sortDirection,
192+
defaultPageNumber,
193+
defaultPageSize,
194+
)
152195

153196
// Then
154197
val firstPriorNotificationWithNonNullPort = result.data.first { it.port != null }
@@ -166,7 +209,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {
166209

167210
// When
168211
val result = getPriorNotifications
169-
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
212+
.execute(
213+
defaultFilter,
214+
defaultSeafrontGroup,
215+
defaultStates,
216+
sortColumn,
217+
sortDirection,
218+
defaultPageNumber,
219+
defaultPageSize,
220+
)
170221

171222
// Then
172223
val firstPriorNotificationWithNonNullPort = result.data.first { it.port != null }
@@ -184,7 +235,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {
184235

185236
// When
186237
val result = getPriorNotifications
187-
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
238+
.execute(
239+
defaultFilter,
240+
defaultSeafrontGroup,
241+
defaultStates,
242+
sortColumn,
243+
sortDirection,
244+
defaultPageNumber,
245+
defaultPageSize,
246+
)
188247

189248
// Then
190249
val firstPriorNotificationWithKnownVessel = result.data.first { it.vessel!!.id != -1 }
@@ -207,7 +266,15 @@ class GetPriorNotificationsITests : AbstractDBTests() {
207266

208267
// When
209268
val result = getPriorNotifications
210-
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
269+
.execute(
270+
defaultFilter,
271+
defaultSeafrontGroup,
272+
defaultStates,
273+
sortColumn,
274+
sortDirection,
275+
defaultPageNumber,
276+
defaultPageSize,
277+
)
211278

212279
// Then
213280
val firstPriorNotificationWithKnownVessel = result.data.first { it.vessel!!.id != -1 }
@@ -230,10 +297,19 @@ class GetPriorNotificationsITests : AbstractDBTests() {
230297

231298
// When
232299
val result = getPriorNotifications
233-
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
300+
.execute(
301+
defaultFilter,
302+
defaultSeafrontGroup,
303+
defaultStates,
304+
sortColumn,
305+
sortDirection,
306+
defaultPageNumber,
307+
defaultPageSize,
308+
)
234309

235310
// Then
236-
val firstPriorNotificationWithNonNullRiskFactor = result.data.first { it.logbookMessageTyped.typedMessage.riskFactor != null }
311+
val firstPriorNotificationWithNonNullRiskFactor =
312+
result.data.first { it.logbookMessageTyped.typedMessage.riskFactor != null }
237313
assertThat(firstPriorNotificationWithNonNullRiskFactor.logbookMessageTyped.typedMessage.riskFactor!!).isEqualTo(
238314
1.5,
239315
)
@@ -249,13 +325,75 @@ class GetPriorNotificationsITests : AbstractDBTests() {
249325

250326
// When
251327
val result = getPriorNotifications
252-
.execute(defaultFilter, defaultSeafrontGroup, sortColumn, sortDirection, defaultPageNumber, defaultPageSize)
328+
.execute(
329+
defaultFilter,
330+
defaultSeafrontGroup,
331+
defaultStates,
332+
sortColumn,
333+
sortDirection,
334+
defaultPageNumber,
335+
defaultPageSize,
336+
)
253337

254338
// Then
255-
val firstPriorNotificationWithNonNullRiskFactor = result.data.first { it.logbookMessageTyped.typedMessage.riskFactor != null }
339+
val firstPriorNotificationWithNonNullRiskFactor =
340+
result.data.first { it.logbookMessageTyped.typedMessage.riskFactor != null }
256341
assertThat(firstPriorNotificationWithNonNullRiskFactor.logbookMessageTyped.typedMessage.riskFactor!!).isEqualTo(
257342
3.9,
258343
)
259344
assertThat(result.data).hasSizeGreaterThan(0)
260345
}
346+
347+
@Test
348+
@Transactional
349+
fun `execute should return a list of NAMO seafront group prior notifications`() {
350+
// Given
351+
val seafrontGroup = SeafrontGroup.NAMO
352+
353+
// When
354+
val result = getPriorNotifications
355+
.execute(
356+
defaultFilter,
357+
seafrontGroup,
358+
defaultStates,
359+
defaultSortColumn,
360+
defaultSortDirection,
361+
defaultPageNumber,
362+
defaultPageSize,
363+
)
364+
365+
// Then
366+
assertThat(result.data).hasSizeGreaterThan(0)
367+
assertThat(result.data.all { it.seafront === Seafront.NAMO }).isTrue()
368+
}
369+
370+
@Test
371+
@Transactional
372+
fun `execute should return a list of pending sent and out of verification scope prior notifications`() {
373+
// Given
374+
val states = listOf(PriorNotificationState.PENDING_SEND, PriorNotificationState.OUT_OF_VERIFICATION_SCOPE)
375+
376+
// When
377+
val result = getPriorNotifications
378+
.execute(
379+
defaultFilter,
380+
defaultSeafrontGroup,
381+
states,
382+
defaultSortColumn,
383+
defaultSortDirection,
384+
defaultPageNumber,
385+
defaultPageSize,
386+
)
387+
388+
// Then
389+
assertThat(result.data).hasSizeGreaterThan(0)
390+
assertThat(
391+
result.data.all {
392+
listOf(
393+
PriorNotificationState.PENDING_SEND,
394+
PriorNotificationState.OUT_OF_VERIFICATION_SCOPE,
395+
).contains(it.state)
396+
},
397+
).isTrue()
398+
}
261399
}

backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotificationsUTests.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class GetPriorNotificationsUTests {
5050
willArriveBefore = "2099-12-31T00:00:00Z",
5151
)
5252
private val defaultSeafrontGroup = SeafrontGroup.ALL
53+
private val defaultStates = null
5354
private val defaultSortColumn = PriorNotificationsSortColumn.EXPECTED_ARRIVAL_DATE
5455
private val defaultSortDirection = Sort.Direction.ASC
5556
private val defaultPageSize = 10
@@ -145,6 +146,7 @@ class GetPriorNotificationsUTests {
145146
).execute(
146147
defaultFilter,
147148
defaultSeafrontGroup,
149+
defaultStates,
148150
defaultSortColumn,
149151
defaultSortDirection,
150152
defaultPageNumber,

backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PriorNotificationControllerITests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class PriorNotificationControllerITests {
6565
val secondFakePriorNotification = PriorNotificationFaker.fakePriorNotification(2)
6666

6767
// Given
68-
given(getPriorNotifications.execute(any(), any(), any(), any(), any(), any())).willReturn(
68+
given(getPriorNotifications.execute(any(), any(), anyOrNull(), any(), any(), any(), any())).willReturn(
6969
PaginatedList(
7070
data = listOf(firstFakePriorNotification, secondFakePriorNotification),
7171
extraData = PriorNotificationStats(perSeafrontGroupCount = emptyMap()),

frontend/cypress/e2e/side_window/prior_notification_form/form.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,9 @@ context('Side Window > Prior Notification Form > Form', () => {
498498
}
499499

500500
assert.deepInclude(getInterception.response.body, {
501-
state: PriorNotification.State.OUT_OF_VERIFICATION_SCOPE
501+
// `PENDING_SEND` since this prior notification is out of verification scope
502+
// so the backend will ask the workflow to send it right away.
503+
state: PriorNotification.State.PENDING_SEND
502504
})
503505

504506
cy.get('.Element-Tag').contains('Hors diffusion').should('exist')

frontend/src/features/Logbook/LogbookMessage.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export namespace LogbookMessage {
274274
seafrontGroup: SeafrontGroup | AllSeafrontGroup | NoSeafrontGroup | undefined
275275
searchQuery: string | undefined
276276
specyCodes: string[] | undefined
277+
states: PriorNotification.State[] | undefined
277278
tripGearCodes: string[] | undefined
278279
tripSegmentCodes: string[] | undefined
279280
vesselLength: number | undefined

0 commit comments

Comments
 (0)