-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic prior notification list & filters Backend
- Loading branch information
1 parent
f86c2bb
commit e45eb46
Showing
48 changed files
with
2,044 additions
and
752 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
.../src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookOperationType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.entities.logbook | ||
|
||
enum class LogbookOperationType { | ||
/** Transmission. */ | ||
DAT, | ||
|
||
/** Correction. */ | ||
COR, | ||
|
||
/** Suppression. */ | ||
DEL, | ||
|
||
/** Acquittement. */ | ||
RET, | ||
} |
7 changes: 7 additions & 0 deletions
7
backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookTripGear.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.entities.logbook | ||
|
||
data class LogbookTripGear( | ||
val gear: String, | ||
val mesh: Int, | ||
val dimensions: String, | ||
) |
9 changes: 9 additions & 0 deletions
9
...nd/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/logbook/LogbookTripSegment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.entities.logbook | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class LogbookTripSegment( | ||
val segment: String, | ||
@JsonProperty("segment_name") | ||
val segmentName: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/entities/vessel/VesselId.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.entities.vessel | ||
|
||
data class VesselId( | ||
val identifier: VesselIdentifier, | ||
val value: String, | ||
) |
15 changes: 15 additions & 0 deletions
15
backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/filters/LogbookReportFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.filters | ||
|
||
import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselId | ||
|
||
data class LogbookReportFilter( | ||
val flagStates: List<String>? = null, | ||
val integratedAfter: String? = null, | ||
val integratedBefore: String? = null, | ||
val portLocodes: List<String>? = null, | ||
val searchQuery: String? = null, | ||
val specyCodes: List<String>? = null, | ||
val tripSegmentSegments: List<String>? = null, | ||
val tripGearCodes: List<String>? = null, | ||
val vesselId: VesselId? = null, | ||
) |
21 changes: 21 additions & 0 deletions
21
backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/filters/PriorNotificationFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.filters | ||
|
||
data class PriorNotificationFilter( | ||
val countryCodes: List<String>? = null, | ||
val fleetSegmentSegments: List<String>? = null, | ||
val gearCodes: List<String>? = listOf(), | ||
val hasOneOrMoreReportings: Boolean? = null, | ||
val isLessThanTwelveMetersVessel: Boolean? = null, | ||
val isSent: Boolean? = null, | ||
val isVesselPretargeted: Boolean? = null, | ||
val lastControlStartDate: String? = null, | ||
val lastControlEndDate: String? = null, | ||
val portLocodes: List<String>? = null, | ||
val query: String? = null, | ||
val receivedAtStartDate: String? = null, | ||
val receivedAtEndDate: String? = null, | ||
// val seaFrontGroup: SeaFrontGroup | 'EXTRA', | ||
val specyCodes: List<String>? = null, | ||
val searchQuery: String? = null, | ||
// val types: PriorNotification.PriorNotificationType[] | ||
) |
10 changes: 10 additions & 0 deletions
10
backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/filters/ReportingFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.filters | ||
|
||
import fr.gouv.cnsp.monitorfish.domain.entities.reporting.ReportingType | ||
|
||
data class ReportingFilter( | ||
val isArchived: Boolean? = null, | ||
val isDeleted: Boolean? = null, | ||
val types: List<ReportingType>? = null, | ||
val vesselId: Int? = null, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...lin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetPriorNotifications.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification | ||
|
||
import fr.gouv.cnsp.monitorfish.config.UseCase | ||
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.use_cases.prior_notification.dtos.PriorNotification | ||
import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.* | ||
import org.locationtech.jts.geom.Coordinate | ||
import org.locationtech.jts.geom.GeometryFactory | ||
|
||
@UseCase | ||
class GetPriorNotifications( | ||
private val facadeAreasRepository: JpaFacadeAreasRepository, | ||
private val logbookReportRepository: JpaLogbookReportRepository, | ||
private val portRepository: JpaPortRepository, | ||
private val reportingRepository: JpaReportingRepository, | ||
private val riskFactorRepository: JpaRiskFactorsRepository, | ||
private val vesselRepository: JpaVesselRepository, | ||
) { | ||
fun execute(filter: LogbookReportFilter): List<PriorNotification> { | ||
val priorNotifications = | ||
logbookReportRepository.findAllPriorNotifications(filter).map { priorNotification -> | ||
val port = | ||
try { | ||
priorNotification.portLocode?.let { | ||
portRepository.find(it) | ||
} | ||
} catch (e: CodeNotFoundException) { | ||
null | ||
} | ||
|
||
// TODO Doesn't seem to work. | ||
val seaFront = | ||
port?.latitude?.let { latitude -> | ||
port.longitude?.let { longitude -> | ||
val point = GeometryFactory().createPoint(Coordinate(longitude, latitude)) | ||
|
||
facadeAreasRepository.findByIncluding(point).firstOrNull()?.facade | ||
} | ||
} | ||
|
||
val vessel = | ||
vesselRepository.findVessel( | ||
priorNotification.logbookMessage?.internalReferenceNumber, | ||
priorNotification.logbookMessage?.externalReferenceNumber, | ||
priorNotification.logbookMessage?.ircs, | ||
) | ||
|
||
val reportingsCount = | ||
vessel?.id.let { vesselId -> | ||
val reportingsFilter = | ||
ReportingFilter( | ||
isArchived = false, | ||
isDeleted = false, | ||
vesselId = vesselId, | ||
) | ||
|
||
reportingRepository.findAll(reportingsFilter).count() | ||
} | ||
|
||
val vesselRiskFactor = | ||
priorNotification.logbookMessage?.internalReferenceNumber?.let { | ||
riskFactorRepository.findVesselRiskFactors(it) | ||
} | ||
|
||
priorNotification.copy( | ||
port = port, | ||
reportingsCount = reportingsCount, | ||
seaFront = seaFront, | ||
vessel = vessel, | ||
vesselRiskFactor = vesselRiskFactor, | ||
) | ||
} | ||
|
||
return priorNotifications | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...in/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/dtos/PriorNotification.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification.dtos | ||
|
||
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookMessage | ||
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookTripGear | ||
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookTripSegment | ||
import fr.gouv.cnsp.monitorfish.domain.entities.port.Port | ||
import fr.gouv.cnsp.monitorfish.domain.entities.risk_factor.VesselRiskFactor | ||
import fr.gouv.cnsp.monitorfish.domain.entities.vessel.Vessel | ||
|
||
data class PriorNotification( | ||
val id: Long, | ||
val logbookMessage: LogbookMessage?, | ||
// TODO It's only used for later use case resolution and not exposed in the data outpur. Maybe find a way to remove it from the DTO? | ||
val portLocode: String?, | ||
val reportingsCount: Int? = null, | ||
val tripGears: List<LogbookTripGear>, | ||
val tripSegments: List<LogbookTripSegment>, | ||
val port: Port? = null, | ||
val seaFront: String? = null, | ||
val vessel: Vessel? = null, | ||
val vesselRiskFactor: VesselRiskFactor? = null, | ||
) |
Oops, something went wrong.