Skip to content

Commit

Permalink
Simplify prior notification sea front prop in Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Mar 26, 2024
1 parent 363a954 commit d98a91d
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ import fr.gouv.cnsp.monitorfish.domain.entities.facade.FacadeArea
import org.locationtech.jts.geom.Point

interface FacadeAreasRepository {
fun findAll(): List<FacadeArea>

fun findByIncluding(point: Point): List<FacadeArea>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification

import fr.gouv.cnsp.monitorfish.config.UseCase
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.messages.PNO
import fr.gouv.cnsp.monitorfish.domain.entities.port.Port
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotification
import fr.gouv.cnsp.monitorfish.domain.entities.reporting.ReportingType
import fr.gouv.cnsp.monitorfish.domain.exceptions.CodeNotFoundException
import fr.gouv.cnsp.monitorfish.domain.filters.LogbookReportFilter
import fr.gouv.cnsp.monitorfish.domain.filters.ReportingFilter
import fr.gouv.cnsp.monitorfish.domain.repositories.*
import org.locationtech.jts.geom.Coordinate
import org.locationtech.jts.geom.GeometryFactory

@UseCase
class GetPriorNotifications(
Expand All @@ -30,11 +27,9 @@ class GetPriorNotifications(
null
}

val seaFront = getSeaFrontFromPort(port)

priorNotification.copy(
port = port,
seaFront = seaFront,
seaFront = port?.facade,
)
}

Expand Down Expand Up @@ -65,18 +60,4 @@ class GetPriorNotifications(

return priorNotificationsWithReportingCount
}

private fun getSeaFrontFromPort(port: Port?): String? {
if (port?.latitude == null || port.longitude == null) {
return null
}

// Cached call
val facadeAreas = facadeAreasRepository.findAll()
val point = GeometryFactory().createPoint(Coordinate(port.longitude, port.latitude))

return facadeAreas.find { facadeArea ->
facadeArea.geometry.contains(point)
}?.facade
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ class PriorNotificationDataOutput(

return PriorNotificationDataOutput(
id = priorNotification.id,
expectedArrivalDate = message.predictedArrivalDateTime.toString(),
expectedLandingDate = message.predictedLandingDatetime.toString(),
expectedArrivalDate = message.predictedArrivalDateTime?.toString(),
expectedLandingDate = message.predictedLandingDatetime?.toString(),
onBoardCatches,
portLocode = priorNotification.port?.locode,
portName = priorNotification.port?.name,
purposeCode = message.purpose,
reportingsCount = priorNotification.reportingsCount,
seaFront = priorNotification.seaFront,
sentAt = priorNotification.logbookMessage.reportDateTime.toString(),
sentAt = priorNotification.logbookMessage.reportDateTime?.toString(),
tripGears,
tripSegments,
types,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class CaffeineConfiguration {
// FAO Areas
val faoAreas = "fao_areas"

// Facade Areas (Sea Fronts)
val faoFacades = "fao_facades"

// Gears
val gear = "gear"
val gearCodeGroup = "gear_code_group"
Expand Down Expand Up @@ -90,9 +87,6 @@ class CaffeineConfiguration {
// FAO Areas
val faoAreasCache = buildMinutesCache(faoAreas, ticker, oneWeek)

// FAO Facades
val faoFacadesCache = buildMinutesCache(faoFacades, ticker, oneWeek)

// Gears
val gearsCache = buildMinutesCache(gears, ticker, oneWeek)
val gearCache = buildMinutesCache(gear, ticker, oneWeek)
Expand Down Expand Up @@ -157,7 +151,6 @@ class CaffeineConfiguration {
currentSegmentsCache,
districtCache,
faoAreasCache,
faoFacadesCache,
findBeaconCache,
firstAndLastTripDates,
gearCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import jakarta.persistence.Table
data class PortEntity(
@Column(name = "country_code_iso2")
val countryCode: String? = null,
// TODO Can it be null in prod? It's used for the multi-cascader in Frontend.
@Column(name = "region")
val region: String? = null,
@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@ import fr.gouv.cnsp.monitorfish.domain.entities.facade.FacadeArea
import fr.gouv.cnsp.monitorfish.domain.repositories.FacadeAreasRepository
import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.interfaces.DBFacadeAreasRepository
import org.locationtech.jts.geom.Point
import org.springframework.cache.annotation.Cacheable
import org.springframework.stereotype.Repository

@Repository
class JpaFacadeAreasRepository(private val dbFacadeAreasRepository: DBFacadeAreasRepository) : FacadeAreasRepository {
@Cacheable(value = ["facade_areas"])
override fun findAll(): List<FacadeArea> {
return dbFacadeAreasRepository.findAll().map {
it.toFacadeArea()
}
}

// TODO This could be cached via a `findAll()`.
override fun findByIncluding(point: Point): List<FacadeArea> {
return dbFacadeAreasRepository.findByIncluding(point).map {
it.toFacadeArea()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ values ('AD', null, null, 'ADALV', 'Andorra la Vella', 42.5, 1.016666666
('AE', null, 'DU', 'AEHZP', 'Hamriya Free Zone Port', 25.3, 55.0833333333333, null, true),
('AE', null, 'DU', 'AEHSN', 'Hassyan', 24.9, 54.0666666666667, null, false),
('AE', null, null, 'AEHTL', 'Hulaylah Terminal', 25.9833333333333, 55.0833333333333, null, true),
('FR', null, '35', 'FRSML', 'Saint-Malo', 48.3833333333333, 00.2033333333333, null, true),
('FR', null, '56', 'FRVNE', 'Vannes', 47.39, 00.246, null, true),
('FR', null, '29', 'FRBES', 'Brest', 48.24, 00.429, null, true);

-- https://service.unece.org/trade/locode/fr.htm
('FR', 'NAMO', '29', 'FRBES', 'Brest', 48.24, 4.29, null, true),
('FR', 'MEMN', '29', 'FRMRS', 'Marseille', 43.18, 5.24, null, true),
('FR', 'MEMN', '29', 'FRNCE', 'Nice', 43.42, 7.16, null, true),
('FR', 'NAMO', '35', 'FRSML', 'Saint-Malo', 48.39, 2.01, null, true),
('FR', 'NAMO', '56', 'FRVNE', 'Vannes', 47.39, 2.46, null, true);
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
INSERT INTO vessels (id, cfr, mmsi, ircs, external_immatriculation, vessel_name, flag_state, length, under_charter) VALUES (101, 'CFR101', 'MMSI101', 'IRCS101', 'EXTIMM101', 'VIVA ESPANA', 'ES', 15, false);

INSERT INTO vessels (id, cfr, mmsi, ircs, external_immatriculation, vessel_name, flag_state, length, under_charter) VALUES (102, 'CFR102', 'MMSI102', 'IRCS102', 'EXTIMM102', 'LEVE NEDERLAND', 'NL', 20, true);

INSERT INTO vessels (id, cfr, mmsi, ircs, external_immatriculation, vessel_name, flag_state, length, under_charter) VALUES (103, 'CFR103', 'MMSI103', 'IRCS103', 'EXTIMM103', 'L''OM DU POISSON', 'FR', 11.99, true);
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ INSERT INTO logbook_raw_messages (operation_number) VALUES ('FAKE_OPERATION_104'

INSERT INTO logbook_raw_messages (operation_number) VALUES ('FAKE_OPERATION_105');

INSERT INTO logbook_raw_messages (operation_number) VALUES ('FAKE_OPERATION_106');

INSERT INTO logbook_reports (id, cfr, enriched, flag_state, integration_datetime_utc, log_type, operation_datetime_utc, operation_number, operation_type, report_datetime_utc, transmission_format, vessel_name, trip_gears, trip_segments, value) VALUES (101, 'FAK000999999', true, 'FRA', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'PNO', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'FAKE_OPERATION_101', 'DAT', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'ERS', 'PHENOMENE', '[{"gear":"TBN","mesh":100,"dimensions":"250;180"},{"gear":"OTT","mesh":120.5,"dimensions":"250;280"}]', '[{"segment":"SWW04","segmentName":"Chaluts pélagiques"},{"segment":"SWW06","segmentName":"Sennes"}]', '{"catchOnboard":[{"weight":25,"nbFish":null,"species":"COD","faoZone":"27.8.a","effortZone":"C","economicZone":"FRA","statisticalRectangle":"23E6"}],"pnoTypes":[{"pnoTypeName":"Préavis type A","minimumNotificationPeriod":4,"hasDesignatedPorts":false},{"pnoTypeName":"Préavis type B","minimumNotificationPeriod":8,"hasDesignatedPorts":true}],"port":"FRSML","predictedArrivalDatetimeUtc":null,"predictedLandingDatetimeUtc":null,"purpose":"LAN","tripStartDate":null}');
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '1 hour', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 101;
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '2 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 101;
Expand All @@ -30,3 +32,8 @@ UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUt
UPDATE logbook_reports SET value = JSONB_SET(value, '{tripStartDate}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '10 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 104;

INSERT INTO logbook_reports (id, cfr, enriched, flag_state, integration_datetime_utc, log_type, operation_datetime_utc, operation_number, operation_type, report_datetime_utc, transmission_format, vessel_name, trip_gears, trip_segments, value) VALUES (105, 'CFR102', true, 'NLD', '2024-03-01 15:00:00', 'PNO', '2024-03-01 15:00:00', 'FAKE_OPERATION_105', 'DAT', '2024-03-01 15:00:00', 'ERS', 'LEVE NEDERLAND', '[{"gear":"DHB","mesh":20.25,"dimensions":"500;500"},{"gear":"DRM","mesh":25.75,"dimensions":"1000;1000"}]', '[{"segment":"NWW03","segmentName":"Chalut de fond en eau profonde ≥100 mm"}]', '{"catchOnboard":[{"weight":25,"nbFish":null,"species":"FRF","faoZone":"27.8.a","effortZone":"C","economicZone":"FRA","statisticalRectangle":"23E6"}],"pnoTypes":[{"pnoTypeName":"Préavis type A","minimumNotificationPeriod":4,"hasDesignatedPorts":false},{"pnoTypeName":"Préavis type B","minimumNotificationPeriod":8,"hasDesignatedPorts":true}],"port":"FRVNE","predictedArrivalDatetimeUtc":"2024-03-01T17:00:00Z","predictedLandingDatetimeUtc":"2024-03-01T17:30:00Z","purpose":"LAN","tripStartDate":"2024-03-01T05:00:00Z"}');

INSERT INTO logbook_reports (id, cfr, enriched, flag_state, integration_datetime_utc, log_type, operation_datetime_utc, operation_number, operation_type, report_datetime_utc, transmission_format, vessel_name, trip_gears, trip_segments, value) VALUES (106, 'CFR103', true, 'FRA', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'PNO', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'FAKE_OPERATION_106', 'DAT', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'ERS', 'L''OM DU POISSON', '[{"gear":"DHB","mesh":20.25,"dimensions":"500;500"},{"gear":"DRM","mesh":25.75,"dimensions":"1000;1000"}]', '[{"segment":"NWW03","segmentName":"Chalut de fond en eau profonde ≥100 mm"}]', '{"catchOnboard":[{"weight":25,"nbFish":null,"species":"FRF","faoZone":"27.8.a","effortZone":"C","economicZone":"FRA","statisticalRectangle":"23E6"}],"pnoTypes":[{"pnoTypeName":"Préavis type E","minimumNotificationPeriod":4,"hasDesignatedPorts":false}],"port":"FRMRS","predictedArrivalDatetimeUtc":null,"predictedLandingDatetimeUtc":null,"purpose":"LAN","tripStartDate":null}');
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 106;
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '4 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 106;
UPDATE logbook_reports SET value = JSONB_SET(value, '{tripStartDate}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '10 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 106;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
"flag_state": "NL",
"length": 20,
"under_charter": true
},

// - Vessel: L'OM DU POISSON
{
"id": 103,
"cfr": "CFR103",
"mmsi": "MMSI103",
"ircs": "IRCS103",
"external_immatriculation": "EXTIMM103",
"vessel_name": "L'OM DU POISSON",
"flag_state": "FR",
"length": 11.99,
"under_charter": true
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
{ "operation_number": "FAKE_OPERATION_102" },
{ "operation_number": "FAKE_OPERATION_103" },
{ "operation_number": "FAKE_OPERATION_104" },
{ "operation_number": "FAKE_OPERATION_105" }
{ "operation_number": "FAKE_OPERATION_105" },
{ "operation_number": "FAKE_OPERATION_106" }
]
},
{
Expand Down Expand Up @@ -257,6 +258,54 @@
"purpose": "LAN",
"tripStartDate": "2024-03-01T05:00:00Z"
}
},

// - Vessel: L'OM DU POISSON
{
"id": 106,
"cfr": "CFR103",
"enriched": true,
"flag_state": "FRA",
"integration_datetime_utc:sql": "NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes'",
"log_type": "PNO",
"operation_datetime_utc:sql": "NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes'",
"operation_number": "FAKE_OPERATION_106",
"operation_type": "DAT",
"report_datetime_utc:sql": "NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes'",
"transmission_format": "ERS",
"vessel_name": "L'OM DU POISSON",
"trip_gears:jsonb": [
{ "gear": "DHB", "mesh": 20.25, "dimensions": "500;500" },
{ "gear": "DRM", "mesh": 25.75, "dimensions": "1000;1000" }
],
"trip_segments:jsonb": [
{ "segment": "NWW03", "segmentName": "Chalut de fond en eau profonde ≥100 mm" }
],
"value:jsonb": {
"catchOnboard": [
{
"weight": 25.0,
"nbFish": null,
"species": "FRF",
"faoZone": "27.8.a",
"effortZone": "C",
"economicZone": "FRA",
"statisticalRectangle": "23E6"
}
],
"pnoTypes": [
{
"pnoTypeName": "Préavis type E",
"minimumNotificationPeriod": 4.0,
"hasDesignatedPorts": false
}
],
"port": "FRMRS",
"predictedArrivalDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"predictedLandingDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '4 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"purpose": "LAN",
"tripStartDate:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '10 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')"
}
}
]
}
Expand Down

0 comments on commit d98a91d

Please sign in to comment.