Skip to content

Commit e55ff69

Browse files
committed
Add year to compute fleet segment
1 parent 9932459 commit e55ff69

File tree

22 files changed

+87
-87
lines changed

22 files changed

+87
-87
lines changed

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/ComputeFleetSegments.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import fr.gouv.cnsp.monitorfish.domain.repositories.FleetSegmentRepository
88
import fr.gouv.cnsp.monitorfish.domain.repositories.VesselRepository
99
import fr.gouv.cnsp.monitorfish.domain.use_cases.fleet_segment.dtos.SpeciesCatchForSegmentCalculation
1010
import org.slf4j.LoggerFactory
11-
import java.time.Clock
12-
import java.time.ZonedDateTime
1311

1412
/**
1513
* Return the computed fleet segments from the species catches.
@@ -18,19 +16,18 @@ import java.time.ZonedDateTime
1816
class ComputeFleetSegments(
1917
private val fleetSegmentRepository: FleetSegmentRepository,
2018
private val vesselRepository: VesselRepository,
21-
private val clock: Clock,
2219
) {
2320
private val logger = LoggerFactory.getLogger(ComputeFleetSegments::class.java)
2421

2522
fun execute(
23+
year: Int,
2624
vesselId: Int,
2725
speciesCatches: List<SpeciesCatchForSegmentCalculation>,
2826
): List<FleetSegment> {
2927
logger.info("Got ${speciesCatches.size} catches to assign fleet segments")
3028

31-
val currentYear = ZonedDateTime.now(clock).year
3229
val vesselType = vesselRepository.findVesselById(vesselId)?.vesselType
33-
val fleetSegments = fleetSegmentRepository.findAllByYear(currentYear)
30+
val fleetSegments = fleetSegmentRepository.findAllByYear(year)
3431

3532
val controlledPelagicSpeciesWeight =
3633
speciesCatches

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/ComputeFleetSegmentsFromControl.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ class ComputeFleetSegmentsFromControl(
1919
faoAreas: List<String>,
2020
gears: List<GearControl>,
2121
species: List<SpeciesControl>,
22+
year: Int,
2223
): List<FleetSegment> {
2324
val allSpecies = speciesRepository.findAll()
2425

2526
val speciesCatches = getSpeciesCatchesForSegmentCalculation(faoAreas, gears, species, allSpecies)
2627

27-
return computeFleetSegments.execute(vesselId, speciesCatches)
28+
return computeFleetSegments.execute(year, vesselId, speciesCatches)
2829
}
2930
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ComputeManualPriorNotification(
2626
portLocode: String,
2727
tripGearCodes: List<String>,
2828
vesselId: Int,
29+
year: Int,
2930
): ManualPriorNotificationComputedValues {
3031
val vessel = vesselRepository.findVesselById(vesselId)
3132
requireNotNull(vessel) {
@@ -41,7 +42,7 @@ class ComputeManualPriorNotification(
4142
val vesselFlagCountryCode = vessel.flagState
4243

4344
val speciesCatch = getSpeciesCatchesForSegmentCalculation(tripGearCodes, fishingCatchesWithFaoArea, species)
44-
val tripSegments = computeFleetSegments.execute(vessel.id, speciesCatch)
45+
val tripSegments = computeFleetSegments.execute(year, vessel.id, speciesCatch)
4546
val types = computePnoTypes.execute(fishingCatchesWithFaoArea, tripGearCodes, vesselFlagCountryCode)
4647
val vesselRiskFactor = computeRiskFactor.execute(portLocode, tripSegments, vesselCfr)
4748

@@ -56,10 +57,10 @@ class ComputeManualPriorNotification(
5657

5758
return ManualPriorNotificationComputedValues(
5859
isVesselUnderCharter = vessel.underCharter,
59-
nextState,
60-
tripSegments,
61-
types,
62-
vesselRiskFactor,
60+
nextState = nextState,
61+
tripSegments = tripSegments,
62+
types = types,
63+
vesselRiskFactor = vesselRiskFactor,
6364
)
6465
}
6566
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ class CreateOrUpdateManualPriorNotification(
6363
// The Backend should NEVER update `risk_factors` DB table, only the pipeline is allowed to update it.
6464
val computedValues =
6565
computeManualPriorNotification.execute(
66-
fishingCatches,
67-
globalFaoArea,
68-
portLocode,
69-
tripGearCodes,
70-
vesselId,
66+
fishingCatches = fishingCatches,
67+
globalFaoArea = globalFaoArea,
68+
portLocode = portLocode,
69+
tripGearCodes = tripGearCodes,
70+
vesselId = vesselId,
71+
year = expectedLandingDate.year,
7172
)
7273

7374
val isPartOfControlUnitSubscriptions =

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class FleetSegmentController(
2828
}
2929

3030
@PostMapping("/compute")
31-
@Operation(summary = "compute fleet segments for the current year")
31+
@Operation(summary = "compute fleet segments for the given year")
3232
fun computeFleetSegments(
3333
@RequestBody
3434
computeFleetSegmentsDataInput: ComputeFleetSegmentsDataInput,
@@ -39,6 +39,7 @@ class FleetSegmentController(
3939
computeFleetSegmentsDataInput.faoAreas,
4040
computeFleetSegmentsDataInput.gears.map { it.toGearControl() },
4141
computeFleetSegmentsDataInput.species.map { it.toSpeciesControl() },
42+
computeFleetSegmentsDataInput.year,
4243
)
4344
return fleetSegments.map {
4445
FleetSegmentDataOutput.fromFleetSegment(it)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class PriorNotificationController(
207207
portLocode = manualPriorNotificationComputeDataInput.portLocode,
208208
tripGearCodes = manualPriorNotificationComputeDataInput.tripGearCodes,
209209
vesselId = manualPriorNotificationComputeDataInput.vesselId,
210+
year = manualPriorNotificationComputeDataInput.year,
210211
)
211212

212213
return ManualPriorNotificationComputedValuesDataOutput

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/ComputeFleetSegmentsDataInput.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ data class ComputeFleetSegmentsDataInput(
55
val vesselId: Int,
66
val gears: List<GearControlDataInput>,
77
val species: List<SpeciesControlDataInput>,
8+
val year: Int,
89
)

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/ManualPriorNotificationComputeDataInput.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ data class ManualPriorNotificationComputeDataInput(
66
val portLocode: String,
77
val tripGearCodes: List<String>,
88
val vesselId: Int,
9+
val year: Int,
910
)

backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/fleet_segment/ComputeFleetSegmentsUTests.kt

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.fleet_segment
22

33
import com.neovisionaries.i18n.CountryCode
44
import com.nhaarman.mockitokotlin2.any
5+
import com.nhaarman.mockitokotlin2.eq
56
import com.nhaarman.mockitokotlin2.given
67
import fr.gouv.cnsp.monitorfish.domain.entities.fleet_segment.ScipSpeciesType
78
import fr.gouv.cnsp.monitorfish.domain.entities.vessel.Vessel
@@ -14,8 +15,6 @@ import org.junit.jupiter.api.Test
1415
import org.junit.jupiter.api.extension.ExtendWith
1516
import org.springframework.boot.test.mock.mockito.MockBean
1617
import org.springframework.test.context.junit.jupiter.SpringExtension
17-
import java.time.Clock
18-
import java.time.ZonedDateTime
1918

2019
@ExtendWith(SpringExtension::class)
2120
class ComputeFleetSegmentsUTests {
@@ -25,10 +24,6 @@ class ComputeFleetSegmentsUTests {
2524
@MockBean
2625
private lateinit var vesselRepository: VesselRepository
2726

28-
companion object {
29-
val fixedClock: Clock = Clock.systemUTC()
30-
}
31-
3227
@Test
3328
fun `execute Should compute Lines segment`() {
3429
// Given
@@ -115,7 +110,7 @@ class ComputeFleetSegmentsUTests {
115110
scipSpeciesType = ScipSpeciesType.TUNA,
116111
),
117112
)
118-
given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(fleetSegmentsForComputation)
113+
given(fleetSegmentRepository.findAllByYear(eq(2025))).willReturn(fleetSegmentsForComputation)
119114
given(vesselRepository.findVesselById(any())).willReturn(
120115
Vessel(
121116
id = 1,
@@ -134,8 +129,7 @@ class ComputeFleetSegmentsUTests {
134129
ComputeFleetSegments(
135130
fleetSegmentRepository,
136131
vesselRepository,
137-
fixedClock,
138-
).execute(1, speciesCatches)
132+
).execute(2025, 1, speciesCatches)
139133

140134
// Then
141135
assertThat(fleetSegments).hasSize(1)
@@ -164,7 +158,7 @@ class ComputeFleetSegmentsUTests {
164158
scipSpeciesType = ScipSpeciesType.PELAGIC,
165159
),
166160
)
167-
given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(fleetSegmentsForComputation)
161+
given(fleetSegmentRepository.findAllByYear(eq(2025))).willReturn(fleetSegmentsForComputation)
168162
given(vesselRepository.findVesselById(any())).willReturn(
169163
Vessel(
170164
id = 1,
@@ -183,8 +177,7 @@ class ComputeFleetSegmentsUTests {
183177
ComputeFleetSegments(
184178
fleetSegmentRepository,
185179
vesselRepository,
186-
fixedClock,
187-
).execute(1, speciesCatches)
180+
).execute(2025, 1, speciesCatches)
188181

189182
// Then
190183
assertThat(fleetSegments).hasSize(1)
@@ -221,7 +214,7 @@ class ComputeFleetSegmentsUTests {
221214
scipSpeciesType = null,
222215
),
223216
)
224-
given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(fleetSegmentsForComputation)
217+
given(fleetSegmentRepository.findAllByYear(eq(2025))).willReturn(fleetSegmentsForComputation)
225218
given(vesselRepository.findVesselById(any())).willReturn(
226219
Vessel(
227220
id = 1,
@@ -240,8 +233,7 @@ class ComputeFleetSegmentsUTests {
240233
ComputeFleetSegments(
241234
fleetSegmentRepository,
242235
vesselRepository,
243-
fixedClock,
244-
).execute(1, speciesCatches)
236+
).execute(2025, 1, speciesCatches)
245237

246238
// Then
247239
assertThat(fleetSegments).hasSize(1)
@@ -278,7 +270,7 @@ class ComputeFleetSegmentsUTests {
278270
scipSpeciesType = null,
279271
),
280272
)
281-
given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(fleetSegmentsForComputation)
273+
given(fleetSegmentRepository.findAllByYear(eq(2025))).willReturn(fleetSegmentsForComputation)
282274
given(vesselRepository.findVesselById(any())).willReturn(
283275
Vessel(
284276
id = 1,
@@ -297,8 +289,7 @@ class ComputeFleetSegmentsUTests {
297289
ComputeFleetSegments(
298290
fleetSegmentRepository,
299291
vesselRepository,
300-
fixedClock,
301-
).execute(1, speciesCatches)
292+
).execute(2025, 1, speciesCatches)
302293

303294
// Then
304295
assertThat(fleetSegments).hasSize(1)
@@ -327,7 +318,7 @@ class ComputeFleetSegmentsUTests {
327318
scipSpeciesType = ScipSpeciesType.DEMERSAL,
328319
),
329320
)
330-
given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(fleetSegmentsForComputation)
321+
given(fleetSegmentRepository.findAllByYear(eq(2025))).willReturn(fleetSegmentsForComputation)
331322
given(vesselRepository.findVesselById(any())).willReturn(
332323
Vessel(
333324
id = 1,
@@ -346,8 +337,7 @@ class ComputeFleetSegmentsUTests {
346337
ComputeFleetSegments(
347338
fleetSegmentRepository,
348339
vesselRepository,
349-
fixedClock,
350-
).execute(1, speciesCatches)
340+
).execute(2025, 1, speciesCatches)
351341

352342
// Then
353343
assertThat(fleetSegments).hasSize(1)
@@ -376,7 +366,7 @@ class ComputeFleetSegmentsUTests {
376366
scipSpeciesType = ScipSpeciesType.DEMERSAL,
377367
),
378368
)
379-
given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(fleetSegmentsForComputation)
369+
given(fleetSegmentRepository.findAllByYear(eq(2025))).willReturn(fleetSegmentsForComputation)
380370
given(vesselRepository.findVesselById(any())).willReturn(
381371
Vessel(
382372
id = 1,
@@ -395,8 +385,7 @@ class ComputeFleetSegmentsUTests {
395385
ComputeFleetSegments(
396386
fleetSegmentRepository,
397387
vesselRepository,
398-
fixedClock,
399-
).execute(1, speciesCatches)
388+
).execute(2025, 1, speciesCatches)
400389

401390
// Then
402391
assertThat(fleetSegments).hasSize(1)
@@ -406,7 +395,7 @@ class ComputeFleetSegmentsUTests {
406395
@Test
407396
fun `execute Should compute no segment`() {
408397
// Given
409-
given(fleetSegmentRepository.findAllByYear(ZonedDateTime.now().year)).willReturn(fleetSegmentsForComputation)
398+
given(fleetSegmentRepository.findAllByYear(eq(2025))).willReturn(fleetSegmentsForComputation)
410399
given(vesselRepository.findVesselById(any())).willReturn(
411400
Vessel(
412401
id = 1,
@@ -425,8 +414,7 @@ class ComputeFleetSegmentsUTests {
425414
ComputeFleetSegments(
426415
fleetSegmentRepository,
427416
vesselRepository,
428-
fixedClock,
429-
).execute(1, listOf())
417+
).execute(2025, 1, listOf())
430418

431419
// Then
432420
assertThat(fleetSegments).hasSize(0)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class CreateOrUpdateManualPriorNotificationITests : AbstractDBTests() {
341341
// Given
342342
val reportId = testCase.reportId
343343

344-
given { computeManualPriorNotification.execute(any(), any(), any(), any(), any()) }
344+
given { computeManualPriorNotification.execute(any(), any(), any(), any(), any(), any()) }
345345
.willReturn(
346346
ManualPriorNotificationComputedValues(
347347
isVesselUnderCharter = false,
@@ -390,7 +390,7 @@ class CreateOrUpdateManualPriorNotificationITests : AbstractDBTests() {
390390
// Given
391391
val reportId = testCase.reportId
392392

393-
given { computeManualPriorNotification.execute(any(), any(), any(), any(), any()) }
393+
given { computeManualPriorNotification.execute(any(), any(), any(), any(), any(), any()) }
394394
.willReturn(
395395
ManualPriorNotificationComputedValues(
396396
isVesselUnderCharter = false,

0 commit comments

Comments
 (0)