-
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.
- Loading branch information
1 parent
e2f2d34
commit 9bb8b8f
Showing
21 changed files
with
393 additions
and
53 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
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
57 changes: 57 additions & 0 deletions
57
backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/alert/SilenceAlert.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,57 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.use_cases.alert | ||
|
||
import fr.gouv.cnsp.monitorfish.config.UseCase | ||
import fr.gouv.cnsp.monitorfish.domain.entities.alerts.SilencedAlert | ||
import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.* | ||
import fr.gouv.cnsp.monitorfish.domain.repositories.SilencedAlertRepository | ||
import org.slf4j.LoggerFactory | ||
|
||
@UseCase | ||
class SilenceAlert( | ||
private val silencedAlertRepository: SilencedAlertRepository, | ||
) { | ||
private val logger = LoggerFactory.getLogger(SilenceAlert::class.java) | ||
|
||
fun execute(silencedAlert: SilencedAlert): SilencedAlert { | ||
// We recreate the object from the `value.type` as the AlertType class from our domain contains the `natinfCode` | ||
val silencedAlertWithNatinf = getSilencedAlertWithNatinf(silencedAlert) | ||
|
||
val savedSilencedAlert = silencedAlertRepository.save(silencedAlertWithNatinf) | ||
|
||
// If the silenced alert is of type MISSING_FAR_ALERT or MISSING_FAR_48_HOURS_ALERT, we need to save the other silenced alert | ||
when (silencedAlert.value.type) { | ||
AlertTypeMapping.MISSING_FAR_ALERT -> { | ||
// If MISSING_FAR_ALERT was silenced, we also silence MISSING_FAR_48_HOURS_ALERT | ||
val missingFAR48HoursSilencedAlert = silencedAlert.copy(value = MissingFAR48HoursAlert()) | ||
silencedAlertRepository.save(missingFAR48HoursSilencedAlert) | ||
} | ||
AlertTypeMapping.MISSING_FAR_48_HOURS_ALERT -> { | ||
// If MISSING_FAR_48_HOURS_ALERT was silenced, we also silence MISSING_FAR_ALERT | ||
val missingFARSilencedAlert = silencedAlert.copy(value = MissingFARAlert()) | ||
silencedAlertRepository.save(missingFARSilencedAlert) | ||
} | ||
else -> {} | ||
} | ||
|
||
logger.info( | ||
"Alert ${savedSilencedAlert.value.type} has been silenced for vessel " + | ||
"${savedSilencedAlert.internalReferenceNumber}/${savedSilencedAlert.ircs}/${savedSilencedAlert.externalReferenceNumber}.", | ||
) | ||
|
||
return savedSilencedAlert | ||
} | ||
|
||
private fun getSilencedAlertWithNatinf(silencedAlert: SilencedAlert): SilencedAlert { | ||
val nextValueWithNatinf: AlertType = when (silencedAlert.value.type) { | ||
AlertTypeMapping.THREE_MILES_TRAWLING_ALERT -> ThreeMilesTrawlingAlert() | ||
AlertTypeMapping.FRENCH_EEZ_FISHING_ALERT -> FrenchEEZFishingAlert() | ||
AlertTypeMapping.TWELVE_MILES_FISHING_ALERT -> TwelveMilesFishingAlert() | ||
AlertTypeMapping.MISSING_FAR_ALERT -> MissingFARAlert() | ||
AlertTypeMapping.MISSING_FAR_48_HOURS_ALERT -> MissingFAR48HoursAlert() | ||
else -> { | ||
throw IllegalArgumentException("The alert type '${silencedAlert.value.type}' could not be silenced.") | ||
} | ||
} | ||
return silencedAlert.copy(value = nextValueWithNatinf) | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...c/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/input/SilencedAlertDataInput.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,32 @@ | ||
package fr.gouv.cnsp.monitorfish.infrastructure.api.input | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.neovisionaries.i18n.CountryCode | ||
import fr.gouv.cnsp.monitorfish.domain.entities.alerts.SilencedAlert | ||
import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.AlertType | ||
import fr.gouv.cnsp.monitorfish.domain.entities.vessel.VesselIdentifier | ||
import java.time.ZonedDateTime | ||
|
||
class SilencedAlertDataInput( | ||
val vesselId: Int? = null, | ||
val vesselName: String? = null, | ||
val internalReferenceNumber: String? = null, | ||
val externalReferenceNumber: String? = null, | ||
val ircs: String? = null, | ||
val vesselIdentifier: VesselIdentifier, | ||
val flagState: CountryCode, | ||
val silencedBeforeDate: ZonedDateTime, | ||
val value: String, | ||
) { | ||
fun toSilencedAlert(objectMapper: ObjectMapper) = SilencedAlert( | ||
vesselId = this.vesselId, | ||
vesselName = this.vesselName, | ||
internalReferenceNumber = this.internalReferenceNumber, | ||
externalReferenceNumber = this.externalReferenceNumber, | ||
ircs = this.ircs, | ||
vesselIdentifier = this.vesselIdentifier, | ||
flagState = this.flagState, | ||
silencedBeforeDate = this.silencedBeforeDate, | ||
value = objectMapper.readValue(value, AlertType::class.java), | ||
) | ||
} |
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
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
2 changes: 2 additions & 0 deletions
2
backend/src/main/resources/db/migration/internal/V0.232__Update_silenced_alerts_table.sql
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,2 @@ | ||
ALTER TABLE public.silenced_alerts | ||
ADD COLUMN vessel_id integer; |
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
Oops, something went wrong.