From fbe8dc29db144af4ed7e5bf590673e24d72dee8f Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Tue, 17 Dec 2024 11:05:54 +0100 Subject: [PATCH 1/4] Fix various bugs --- .../entities/beaconMalfunction/constants.tsx | 2 +- .../src/domain/entities/vessel/riskFactor/index.ts | 11 +++++++++-- .../useCases/downloadActivityReports.ts | 14 +++++++++----- .../details/DetectabilityRiskFactorDetails.tsx | 9 ++++----- frontend/src/features/Vessel/slice.ts | 12 ++++-------- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/frontend/src/domain/entities/beaconMalfunction/constants.tsx b/frontend/src/domain/entities/beaconMalfunction/constants.tsx index 44f259b714..f9c237382c 100644 --- a/frontend/src/domain/entities/beaconMalfunction/constants.tsx +++ b/frontend/src/domain/entities/beaconMalfunction/constants.tsx @@ -60,7 +60,7 @@ const VESSEL_STATUS: BeaconMalfunctionStatusValue[] = [ }, { color: theme.color.powderBlue, - hoursOffsetToRetrieveMalfunctionCreation: 6, + hoursOffsetToRetrieveMalfunctionCreation: 4, icon: , label: 'Navire en mer', textColor: theme.color.charcoal, diff --git a/frontend/src/domain/entities/vessel/riskFactor/index.ts b/frontend/src/domain/entities/vessel/riskFactor/index.ts index 51d79a2f1b..bb418d50cf 100644 --- a/frontend/src/domain/entities/vessel/riskFactor/index.ts +++ b/frontend/src/domain/entities/vessel/riskFactor/index.ts @@ -77,16 +77,23 @@ export const getDetectabilityRiskFactorText = (riskFactor: number, isTextReduced return undefined } -export const getControlPriorityLevel = (riskFactor: number) => { - if (riskFactor >= 1 && riskFactor < 1.75) { +export const getControlPriorityLevel = (riskFactor: number, segmentHighestPriority: string | undefined | null) => { + if (!segmentHighestPriority) { return 'pas de segment' } + + if (riskFactor >= 1 && riskFactor < 1.75) { + return 'basse' + } + if (riskFactor >= 1.75 && riskFactor < 2.5) { return 'moyenne' } + if (riskFactor >= 2.5 && riskFactor < 3.25) { return 'élevée' } + if (riskFactor >= 3.25 && riskFactor <= 4) { return 'très élevée' } diff --git a/frontend/src/features/ActivityReport/useCases/downloadActivityReports.ts b/frontend/src/features/ActivityReport/useCases/downloadActivityReports.ts index 578592d77a..9d9019ba88 100644 --- a/frontend/src/features/ActivityReport/useCases/downloadActivityReports.ts +++ b/frontend/src/features/ActivityReport/useCases/downloadActivityReports.ts @@ -1,3 +1,4 @@ +import { RTK_FORCE_REFETCH_QUERY_OPTIONS } from '@api/constants' import { customDayjs, logSoftError } from '@mtes-mct/monitor-ui' import { downloadAsCsv } from '@utils/downloadAsCsv' @@ -16,11 +17,14 @@ export const downloadActivityReports = const { data: { activityReports, jdpSpecies } }: { data: ActivityReports } = await dispatch( - activityReportApi.endpoints.getActivityReports.initiate({ - afterDateTime, - beforeDateTime, - jdp - }) + activityReportApi.endpoints.getActivityReports.initiate( + { + afterDateTime, + beforeDateTime, + jdp + }, + RTK_FORCE_REFETCH_QUERY_OPTIONS + ) ) if (!activityReports?.length) { diff --git a/frontend/src/features/Vessel/components/VesselSidebar/risk_factor/details/DetectabilityRiskFactorDetails.tsx b/frontend/src/features/Vessel/components/VesselSidebar/risk_factor/details/DetectabilityRiskFactorDetails.tsx index fd3413df85..28dcc1e71a 100644 --- a/frontend/src/features/Vessel/components/VesselSidebar/risk_factor/details/DetectabilityRiskFactorDetails.tsx +++ b/frontend/src/features/Vessel/components/VesselSidebar/risk_factor/details/DetectabilityRiskFactorDetails.tsx @@ -1,3 +1,4 @@ +import { useMainAppSelector } from '@hooks/useMainAppSelector' import styled from 'styled-components' import { @@ -5,7 +6,6 @@ import { getControlRateRiskFactorText, getRiskFactorColor } from '../../../../../../domain/entities/vessel/riskFactor' -import { useMainAppSelector } from '../../../../../../hooks/useMainAppSelector' import { getDate } from '../../../../../../utils' import { RiskFactorCursor } from '../RiskFactorCursor' @@ -23,13 +23,12 @@ export function DetectabilityRiskFactorDetails({ isOpen }: DetectabilityRiskFact - - Priorité du segment {riskFactor?.segmentHighestPriority ? riskFactor?.segmentHighestPriority : null} - + Priorité du segment {riskFactor?.segmentHighestPriority} {riskFactor?.controlPriorityLevel ? ( `${riskFactor?.controlPriorityLevel?.toFixed(1)} – ${getControlPriorityLevel( - riskFactor?.controlPriorityLevel + riskFactor?.controlPriorityLevel, + riskFactor?.segmentHighestPriority )}` ) : ( - diff --git a/frontend/src/features/Vessel/slice.ts b/frontend/src/features/Vessel/slice.ts index 2e48f2731d..5ed46dc56c 100644 --- a/frontend/src/features/Vessel/slice.ts +++ b/frontend/src/features/Vessel/slice.ts @@ -252,10 +252,8 @@ const vesselSlice = createSlice({ ) { const vessel = vesselSelectors.selectById(state.vessels, action.payload.vesselFeatureId) if (vessel) { - const vesselReportingWithoutFirstFoundReportingType = vessel.reportings?.reduce( - filterFirstFoundReportingType(action.payload.reportingType), - [] - ) + const vesselReportingWithoutFirstFoundReportingType = + vessel.reportings?.reduce(filterFirstFoundReportingType(action.payload.reportingType), []) || [] const nextVessel = { ...vessel, @@ -272,10 +270,8 @@ const vesselSlice = createSlice({ state.selectedVessel && Vessel.getVesselFeatureId(state.selectedVesselIdentity) === action.payload.vesselFeatureId ) { - const vesselReportingWithoutFirstFoundReportingType = state.selectedVessel.reportings?.reduce( - filterFirstFoundReportingType(action.payload.reportingType), - [] - ) + const vesselReportingWithoutFirstFoundReportingType = + state.selectedVessel.reportings?.reduce(filterFirstFoundReportingType(action.payload.reportingType), []) || [] state.selectedVessel = { ...state.selectedVessel, From fd05821b0ac1f32c9723c87bf8a6fde9dd9ff251 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Tue, 17 Dec 2024 14:16:40 +0100 Subject: [PATCH 2/4] Flag multiple logbook messages with a single RET message --- .../domain/entities/logbook/LogbookMessage.kt | 22 ++- .../GetPriorNotifications.kt | 2 +- ...nsert_logbook_raw_messages_and_reports.sql | 2 +- .../monitorfish/domain/use_cases/TestUtils.kt | 12 +- .../vessel/GetLogbookMessagesUTests.kt | 158 +++++++----------- 5 files changed, 80 insertions(+), 116 deletions(-) diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt index 23af696383..cc6a669058 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookMessage.kt @@ -136,23 +136,27 @@ data class LogbookMessage( } private fun enrichAcknowledgeCorrectionAndDeletion(contextLogbookMessages: List) { - val referenceLogbookMessage = findReferencedLogbookMessage(contextLogbookMessages) + val referenceLogbookMessages = findReferencedLogbookMessages(contextLogbookMessages) val relatedLogbookMessages = filterRelatedLogbookMessages(contextLogbookMessages) when (true) { (operationType == LogbookOperationType.COR) -> { - if (referenceLogbookMessage == null) { + if (referenceLogbookMessages.isEmpty()) { logger.warn( "Original message $referencedReportId corrected by message COR $operationNumber is not found.", ) } - referenceLogbookMessage?.isCorrectedByNewerMessage = true + referenceLogbookMessages.forEach { + it.isCorrectedByNewerMessage = true + } setIsCorrectedByNewerMessage(relatedLogbookMessages) } (operationType == LogbookOperationType.RET && !referencedReportId.isNullOrEmpty()) -> { - referenceLogbookMessage?.setAcknowledge(this.copy()) + referenceLogbookMessages.forEach { + it.setAcknowledge(this.copy()) + } } (transmissionFormat == LogbookTransmissionFormat.FLUX), @@ -162,7 +166,9 @@ data class LogbookMessage( } (operationType == LogbookOperationType.DEL && !referencedReportId.isNullOrEmpty()) -> { - referenceLogbookMessage?.isDeleted = true + referenceLogbookMessages.forEach { + it.isDeleted = true + } } else -> {} @@ -186,11 +192,11 @@ data class LogbookMessage( } } - private fun findReferencedLogbookMessage(messages: List): LogbookMessage? { + private fun findReferencedLogbookMessages(messages: List): List { return if (!referencedReportId.isNullOrEmpty()) { - messages.find { it.reportId == referencedReportId } + messages.filter { it.reportId == referencedReportId } } else { - null + listOf() } } diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt index 095f6fe742..cd8569d989 100644 --- a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt @@ -160,7 +160,7 @@ class GetPriorNotifications( vesselInternalReferenceNumbers = internalReferenceNumbers, isArchived = false, isDeleted = false, - types = listOf(ReportingType.INFRACTION_SUSPICION), + types = listOf(ReportingType.INFRACTION_SUSPICION, ReportingType.ALERT), ), ) diff --git a/backend/src/main/resources/db/testdata/V666.5.0__Insert_logbook_raw_messages_and_reports.sql b/backend/src/main/resources/db/testdata/V666.5.0__Insert_logbook_raw_messages_and_reports.sql index 57b541d4b6..0ebc567c73 100644 --- a/backend/src/main/resources/db/testdata/V666.5.0__Insert_logbook_raw_messages_and_reports.sql +++ b/backend/src/main/resources/db/testdata/V666.5.0__Insert_logbook_raw_messages_and_reports.sql @@ -304,7 +304,7 @@ VALUES ('OOF20190265896325', 9463701, 'OOF', '2018-02-17T01:05:00Z', 'DAT', 'OOF 'U_W0NTFINDME', 'QGDF', 'ABC123456', 'MALOTRU', 'FRA', null, 'PNO', '2018-02-20T13:45Z', '{"port": "AEJAZ", "purpose": "LAN", "catchOnboard": [{"weight": 36.0, "nbFish": null, "species": "SOL", "faoZone": "27.8.a", "effortZone": "C", "economicZone": "FRA", "statisticalRectangle": "23E6"}], "tripStartDate": "2018-02-20T00:00Z", "predictedArrivalDatetimeUtc": "2018-02-20T13:45Z"}', '2021-01-18T07:17:31.532639Z', 'ERS', 'TurboCatch (3.7-1)'), - ('OOF20190126036598', 9463711, 'OOF', '2019-01-18T11:45:00Z', 'DAT', 'OOF20190126036598', null, + ('OOF20190126036598', 9463711, 'OOF', '2019-01-18T11:45:00Z', 'DAT', 'OOF20180227051234', null, '2019-01-18T11:45:00Z', 'U_W0NTFINDME', 'QGDF', 'ABC123456', 'MALOTRU', 'FRA', null, 'FAR', '2019-01-15T11:45:00Z', '{"hauls": [{"gear": "GTN", "mesh": 100.0, "catches": [], "farDatetimeUtc": "2019-01-15T11:45:00Z"}]}', diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/TestUtils.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/TestUtils.kt index d1a9d7299d..8442029b52 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/TestUtils.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/TestUtils.kt @@ -176,7 +176,7 @@ object TestUtils { id = 2, operationNumber = "", tripNumber = "345", - reportId = "", + reportId = "REPORT_ID#1", operationType = LogbookOperationType.DAT, messageType = "FAR", software = "TurboCatch (3.7-1)", @@ -201,7 +201,7 @@ object TestUtils { id = 1, operationNumber = "", tripNumber = "345", - reportId = "", + reportId = "REPORT_ID#2", operationType = LogbookOperationType.DAT, messageType = "DEP", software = "e-Sacapt Secours ERSV3 V 1.0.10", @@ -226,7 +226,7 @@ object TestUtils { id = 3, operationNumber = "", tripNumber = "345", - reportId = "", + reportId = "REPORT_ID#3", operationType = LogbookOperationType.DAT, messageType = "PNO", software = "e-Sacapt Secours ERSV3 V 1.0.7", @@ -251,7 +251,7 @@ object TestUtils { id = 3, operationNumber = "", tripNumber = "345", - reportId = "", + reportId = "REPORT_ID#4", operationType = LogbookOperationType.DAT, messageType = "COE", software = "e-Sacapt Secours ERSV3 V 1.0.7", @@ -276,7 +276,7 @@ object TestUtils { id = 4, operationNumber = "", tripNumber = "345", - reportId = "", + reportId = "REPORT_ID#4", operationType = LogbookOperationType.DAT, messageType = "COX", software = "e-Sacapt Secours ERSV3 V 1.0.7", @@ -294,7 +294,7 @@ object TestUtils { id = 5, operationNumber = "", tripNumber = "345", - reportId = "", + reportId = "REPORT_ID#5", operationType = LogbookOperationType.DAT, messageType = "CPS", software = "", diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetLogbookMessagesUTests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetLogbookMessagesUTests.kt index 80e5212ec0..1eb41ac148 100644 --- a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetLogbookMessagesUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/vessel/GetLogbookMessagesUTests.kt @@ -18,6 +18,7 @@ import org.mockito.BDDMockito.given import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.test.context.junit.jupiter.SpringExtension import java.time.ZoneOffset +import java.time.ZoneOffset.UTC import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) @@ -141,26 +142,6 @@ class GetLogbookMessagesUTests { given(logbookReportRepository.findAllMessagesByTripNumberBetweenDates(any(), any(), any(), any())).willReturn( getDummyCorrectedLogbookMessages(), ) - given(logbookRawMessageRepository.findRawMessage(any())).willReturn("DUMMY XML MESSAGE") - given(gearRepository.findAll()).willReturn( - listOf( - Gear("OTB", "Chaluts de fond à panneaux"), - Gear("DRB", "Dragues remorquées par bateau"), - ), - ) - given(portRepository.findAll()).willReturn( - listOf( - PortFaker.fakePort(locode = "AEFAT", name = "Al Jazeera Port"), - PortFaker.fakePort(locode = "AEJAZ", name = "Arzanah Island"), - ), - ) - given(speciesRepository.findAll()).willReturn( - listOf( - Species("TTV", "TORPILLE OCELLÉE"), - Species("SMV", "STOMIAS BREVIBARBATUS"), - Species("PNB", "CREVETTE ROYALE ROSE"), - ), - ) // When val ersMessages = @@ -200,26 +181,6 @@ class GetLogbookMessagesUTests { given(logbookReportRepository.findAllMessagesByTripNumberBetweenDates(any(), any(), any(), any())).willReturn( getDummyRETLogbookMessages(), ) - given(logbookRawMessageRepository.findRawMessage(any())).willReturn("DUMMY XML MESSAGE") - given(gearRepository.findAll()).willReturn( - listOf( - Gear("OTB", "Chaluts de fond à panneaux"), - Gear("DRB", "Dragues remorquées par bateau"), - ), - ) - given(portRepository.findAll()).willReturn( - listOf( - PortFaker.fakePort(locode = "AEFAT", name = "Al Jazeera Port"), - PortFaker.fakePort(locode = "AEJAZ", name = "Arzanah Island"), - ), - ) - given(speciesRepository.findAll()).willReturn( - listOf( - Species("TTV", "TORPILLE OCELLÉE"), - Species("SMV", "STOMIAS BREVIBARBATUS"), - Species("PNB", "CREVETTE ROYALE ROSE"), - ), - ) // When val ersMessages = @@ -329,26 +290,6 @@ class GetLogbookMessagesUTests { given(logbookReportRepository.findAllMessagesByTripNumberBetweenDates(any(), any(), any(), any())).willReturn( getDummyRETLogbookMessages(), ) - given(logbookRawMessageRepository.findRawMessage(any())).willReturn("DUMMY XML MESSAGE") - given(gearRepository.findAll()).willReturn( - listOf( - Gear("OTB", "Chaluts de fond à panneaux"), - Gear("DRB", "Dragues remorquées par bateau"), - ), - ) - given(portRepository.findAll()).willReturn( - listOf( - PortFaker.fakePort(locode = "AEFAT", name = "Al Jazeera Port"), - PortFaker.fakePort(locode = "AEJAZ", name = "Arzanah Island"), - ), - ) - given(speciesRepository.findAll()).willReturn( - listOf( - Species("TTV", "TORPILLE OCELLÉE"), - Species("SMV", "STOMIAS BREVIBARBATUS"), - Species("PNB", "CREVETTE ROYALE ROSE"), - ), - ) // When val ersMessages = @@ -376,26 +317,6 @@ class GetLogbookMessagesUTests { given(logbookReportRepository.findAllMessagesByTripNumberBetweenDates(any(), any(), any(), any())).willReturn( getDummyFluxAndVisioCaptureLogbookMessages(), ) - given(logbookRawMessageRepository.findRawMessage(any())).willReturn("DUMMY XML MESSAGE") - given(gearRepository.findAll()).willReturn( - listOf( - Gear("OTB", "Chaluts de fond à panneaux"), - Gear("DRB", "Dragues remorquées par bateau"), - ), - ) - given(portRepository.findAll()).willReturn( - listOf( - PortFaker.fakePort(locode = "AEFAT", name = "Al Jazeera Port"), - PortFaker.fakePort(locode = "AEJAZ", name = "Arzanah Island"), - ), - ) - given(speciesRepository.findAll()).willReturn( - listOf( - Species("TTV", "TORPILLE OCELLÉE"), - Species("SMV", "STOMIAS BREVIBARBATUS"), - Species("PNB", "CREVETTE ROYALE ROSE"), - ), - ) // When val ersMessages = @@ -416,6 +337,10 @@ class GetLogbookMessagesUTests { assertThat(ersMessages[2].acknowledgment?.isSuccess).isTrue } + /** + * add two report_id for the same RET in the stub + */ + @Test fun `execute Should flag messages sent by the failover software e-Sacapt`() { // Given @@ -425,26 +350,6 @@ class GetLogbookMessagesUTests { given(logbookReportRepository.findAllMessagesByTripNumberBetweenDates(any(), any(), any(), any())).willReturn( getDummyLogbookMessages(), ) - given(logbookRawMessageRepository.findRawMessage(any())).willReturn("DUMMY XML MESSAGE") - given(gearRepository.findAll()).willReturn( - listOf( - Gear("OTB", "Chaluts de fond à panneaux"), - Gear("DRB", "Dragues remorquées par bateau"), - ), - ) - given(portRepository.findAll()).willReturn( - listOf( - PortFaker.fakePort(locode = "AEFAT", name = "Al Jazeera Port"), - PortFaker.fakePort(locode = "AEJAZ", name = "Arzanah Island"), - ), - ) - given(speciesRepository.findAll()).willReturn( - listOf( - Species("TTV", "TORPILLE OCELLÉE"), - Species("SMV", "STOMIAS BREVIBARBATUS"), - Species("PNB", "CREVETTE ROYALE ROSE"), - ), - ) // When val ersMessages = @@ -466,4 +371,57 @@ class GetLogbookMessagesUTests { assertThat(ersMessages[3].isSentByFailoverSoftware).isTrue assertThat(ersMessages[4].isSentByFailoverSoftware).isFalse } + + @Test + fun `execute Should acknowledge two messages with the same report id`() { + // Given + val retTargetingTwoMessages = + LogbookMessage( + id = 123, + operationNumber = "", + reportId = "906564681689", + referencedReportId = "REPORT_ID#4", + operationType = LogbookOperationType.RET, + messageType = "", + message = Acknowledgment().apply { returnStatus = "000" }, + reportDateTime = + ZonedDateTime.of( + 2020, + 5, + 5, + 3, + 4, + 5, + 3, + UTC, + ).minusHours(12), + transmissionFormat = LogbookTransmissionFormat.ERS, + integrationDateTime = ZonedDateTime.now(), + isEnriched = false, + operationDateTime = ZonedDateTime.now(), + ) + given(logbookReportRepository.findLastTripBeforeDateTime(any(), any())).willReturn( + VoyageDatesAndTripNumber("123", ZonedDateTime.now(), ZonedDateTime.now()), + ) + given(logbookReportRepository.findAllMessagesByTripNumberBetweenDates(any(), any(), any(), any())).willReturn( + getDummyLogbookMessages() + retTargetingTwoMessages, + ) + + // When + val ersMessages = + GetLogbookMessages( + logbookReportRepository, + gearRepository, + speciesRepository, + portRepository, + logbookRawMessageRepository, + ) + .execute("FR224226850", ZonedDateTime.now().minusMinutes(5), ZonedDateTime.now(), "345") + + // Then + assertThat(ersMessages).hasSize(6) + + assertThat(ersMessages[2].acknowledgment?.isSuccess).isTrue + assertThat(ersMessages[3].acknowledgment?.isSuccess).isTrue + } } From 4ab96cca86d08e066426b25fd50969c48579a1b8 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Tue, 17 Dec 2024 15:27:53 +0100 Subject: [PATCH 3/4] Add ports cache evict and fix test data for cypress tests --- .../api/public_api/PublicPortController.kt | 23 +++++++++++ ...nsert_logbook_raw_messages_and_reports.sql | 2 +- .../public_api/PublicPortControllerITests.kt | 41 +++++++++++++++++++ frontend/src/features/Vessel/vesselApi.ts | 1 - 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPortController.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPortControllerITests.kt diff --git a/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPortController.kt b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPortController.kt new file mode 100644 index 0000000000..5374709953 --- /dev/null +++ b/backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPortController.kt @@ -0,0 +1,23 @@ +package fr.gouv.cnsp.monitorfish.infrastructure.api.public_api + +import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.cache.CacheManager +import org.springframework.web.bind.annotation.PutMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/api/v1/ports") +@Tag(name = "Public APIs for ports") +class PublicPortController( + private val cacheManager: CacheManager, +) { + @PutMapping(value = ["/invalidate"]) + @Operation(summary = "Invalidate ports cache") + fun invalidatePorts() { + cacheManager.getCache("ports")?.invalidate() + cacheManager.getCache("port")?.invalidate() + cacheManager.getCache("active_ports")?.invalidate() + } +} diff --git a/backend/src/main/resources/db/testdata/V666.5.0__Insert_logbook_raw_messages_and_reports.sql b/backend/src/main/resources/db/testdata/V666.5.0__Insert_logbook_raw_messages_and_reports.sql index 0ebc567c73..57b541d4b6 100644 --- a/backend/src/main/resources/db/testdata/V666.5.0__Insert_logbook_raw_messages_and_reports.sql +++ b/backend/src/main/resources/db/testdata/V666.5.0__Insert_logbook_raw_messages_and_reports.sql @@ -304,7 +304,7 @@ VALUES ('OOF20190265896325', 9463701, 'OOF', '2018-02-17T01:05:00Z', 'DAT', 'OOF 'U_W0NTFINDME', 'QGDF', 'ABC123456', 'MALOTRU', 'FRA', null, 'PNO', '2018-02-20T13:45Z', '{"port": "AEJAZ", "purpose": "LAN", "catchOnboard": [{"weight": 36.0, "nbFish": null, "species": "SOL", "faoZone": "27.8.a", "effortZone": "C", "economicZone": "FRA", "statisticalRectangle": "23E6"}], "tripStartDate": "2018-02-20T00:00Z", "predictedArrivalDatetimeUtc": "2018-02-20T13:45Z"}', '2021-01-18T07:17:31.532639Z', 'ERS', 'TurboCatch (3.7-1)'), - ('OOF20190126036598', 9463711, 'OOF', '2019-01-18T11:45:00Z', 'DAT', 'OOF20180227051234', null, + ('OOF20190126036598', 9463711, 'OOF', '2019-01-18T11:45:00Z', 'DAT', 'OOF20190126036598', null, '2019-01-18T11:45:00Z', 'U_W0NTFINDME', 'QGDF', 'ABC123456', 'MALOTRU', 'FRA', null, 'FAR', '2019-01-15T11:45:00Z', '{"hauls": [{"gear": "GTN", "mesh": 100.0, "catches": [], "farDatetimeUtc": "2019-01-15T11:45:00Z"}]}', diff --git a/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPortControllerITests.kt b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPortControllerITests.kt new file mode 100644 index 0000000000..1e0e29e0cd --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicPortControllerITests.kt @@ -0,0 +1,41 @@ +package fr.gouv.cnsp.monitorfish.infrastructure.api.public_api + +import fr.gouv.cnsp.monitorfish.config.SentryConfig +import fr.gouv.cnsp.monitorfish.fakers.PortFaker +import fr.gouv.cnsp.monitorfish.infrastructure.cache.CaffeineConfiguration +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest +import org.springframework.cache.CacheManager +import org.springframework.context.annotation.Import +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status + +@Import(SentryConfig::class, CaffeineConfiguration::class) +@AutoConfigureMockMvc(addFilters = false) +@WebMvcTest(value = [PublicPortController::class]) +class PublicPortControllerITests { + @Autowired + private lateinit var api: MockMvc + + @Autowired + lateinit var cacheManager: CacheManager + + @Test + fun `Should invalidate the cache`() { + // Given + cacheManager.getCache("ports")?.put("PORT123", PortFaker.fakePort(locode = "AY", name = "Auray")) + assertThat(cacheManager.getCache("ports")?.get("PORT123")).isNotNull() + + // When + api.perform(put("/api/v1/ports/invalidate")) + .andExpect(status().isOk) + + // Then + val cache = cacheManager.getCache("ports")?.get("PORT123") + assertThat(cache).isNull() + } +} diff --git a/frontend/src/features/Vessel/vesselApi.ts b/frontend/src/features/Vessel/vesselApi.ts index ab8a611bea..40265a0a3c 100644 --- a/frontend/src/features/Vessel/vesselApi.ts +++ b/frontend/src/features/Vessel/vesselApi.ts @@ -74,7 +74,6 @@ export const vesselApi = monitorfishApi.injectEndpoints({ }) export const { - useGetRiskFactorQuery, useGetVesselQuery, useGetVesselReportingsByVesselIdentityQuery, useGetVesselsLastPositionsQuery From 037f823aec0b1534a199731b7f70c04880b20283 Mon Sep 17 00:00:00 2001 From: Loup Theron Date: Wed, 18 Dec 2024 11:55:58 +0100 Subject: [PATCH 4/4] Apply linter --- frontend/src/features/Vessel/vesselApi.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/frontend/src/features/Vessel/vesselApi.ts b/frontend/src/features/Vessel/vesselApi.ts index 40265a0a3c..370a6c0e0a 100644 --- a/frontend/src/features/Vessel/vesselApi.ts +++ b/frontend/src/features/Vessel/vesselApi.ts @@ -73,8 +73,5 @@ export const vesselApi = monitorfishApi.injectEndpoints({ }) }) -export const { - useGetVesselQuery, - useGetVesselReportingsByVesselIdentityQuery, - useGetVesselsLastPositionsQuery -} = vesselApi +export const { useGetVesselQuery, useGetVesselReportingsByVesselIdentityQuery, useGetVesselsLastPositionsQuery } = + vesselApi