-
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.
Signalements – Archiver automatiquement les signalements issus d'aler…
…tes (UPDATE ENV VAR) (#3659) ## Linked issues - Resolve #3189 - à rajouter en PROD : `MONITORFISH_SCHEDULING_ENABLED=true` ## Post MEP en PROD : Exécuter la requête pour récupérer les signalement pour **1 mois** (prends ~10s) ``` WITH recent_dep_messages AS ( SELECT lr.cfr, lr.ircs, lr.external_identification, lr.operation_number, MAX(lr.operation_datetime_utc) as last_dep_date_time FROM logbook_reports lr WHERE lr.operation_datetime_utc > NOW() - INTERVAL '1 month' AND lr.log_type = 'DEP' GROUP BY lr.cfr, lr.ircs, lr.external_identification, lr.operation_number ), acknowledged_report_ids AS ( SELECT DISTINCT referenced_report_id FROM logbook_reports lr WHERE lr.operation_datetime_utc > NOW() - INTERVAL '1 month' AND lr.operation_type = 'RET' AND lr.value->>'returnStatus' = '000' ) SELECT r.id as id, r.value as value FROM reportings r INNER JOIN (select * from recent_dep_messages) rdp ON CASE WHEN r.vessel_identifier = 'INTERNAL_REFERENCE_NUMBER' THEN r.internal_reference_number = rdp.cfr WHEN r.vessel_identifier = 'IRCS' THEN r.ircs = rdp.ircs WHEN r.vessel_identifier = 'EXTERNAL_REFERENCE_NUMBER' THEN r.external_reference_number = rdp.external_identification END WHERE r.archived is false AND r.deleted is false AND rdp.last_dep_date_time >= r.validation_date AND rdp.operation_number IN (SELECT referenced_report_id FROM acknowledged_report_ids) ``` Puis les archiver : ``` UPDATE reportings SET archived = TRUE WHERE id IN (:ids) ``` ---- - [ ] Tests E2E (Cypress)
- Loading branch information
Showing
21 changed files
with
272 additions
and
19 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
31 changes: 31 additions & 0 deletions
31
...n/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/ArchiveOutdatedReportings.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,31 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.use_cases.reporting | ||
|
||
import fr.gouv.cnsp.monitorfish.config.UseCase | ||
import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.AlertTypeMapping | ||
import fr.gouv.cnsp.monitorfish.domain.repositories.ReportingRepository | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.scheduling.annotation.Scheduled | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@UseCase | ||
class ArchiveOutdatedReportings(private val reportingRepository: ReportingRepository) { | ||
private val logger = LoggerFactory.getLogger(ArchiveOutdatedReportings::class.java) | ||
|
||
// At every 5 minutes, after 1 minute of initial delay | ||
@Scheduled(fixedDelay = 300000, initialDelay = 6000) | ||
@Transactional | ||
fun execute() { | ||
val reportingCandidatesToArchive = reportingRepository.findUnarchivedReportings() | ||
|
||
val filteredReportingIdsToArchive = | ||
reportingCandidatesToArchive.filter { | ||
it.second.type == AlertTypeMapping.MISSING_FAR_ALERT || | ||
it.second.type == AlertTypeMapping.THREE_MILES_TRAWLING_ALERT | ||
}.map { it.first } | ||
|
||
logger.info("Found ${filteredReportingIdsToArchive.size} reportings to archive.") | ||
val numberOfArchivedReportings = reportingRepository.archiveReportings(filteredReportingIdsToArchive) | ||
|
||
logger.info("Archived $numberOfArchivedReportings reportings") | ||
} | ||
} |
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
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
37 changes: 37 additions & 0 deletions
37
...in/fr/gouv/cnsp/monitorfish/domain/use_cases/reporting/ArchiveOutdatedReportingsUTests.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,37 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.use_cases.reporting | ||
|
||
import com.nhaarman.mockitokotlin2.eq | ||
import com.nhaarman.mockitokotlin2.verify | ||
import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.MissingFARAlert | ||
import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.ThreeMilesTrawlingAlert | ||
import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.TwelveMilesFishingAlert | ||
import fr.gouv.cnsp.monitorfish.domain.repositories.ReportingRepository | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.BDDMockito.given | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class ArchiveOutdatedReportingsUTests { | ||
@MockBean | ||
private lateinit var reportingRepository: ReportingRepository | ||
|
||
@Test | ||
fun `execute Should archive outdated reportings`() { | ||
// Given | ||
given(reportingRepository.findUnarchivedReportings()).willReturn( | ||
listOf( | ||
Pair(1, TwelveMilesFishingAlert("NAMO")), | ||
Pair(2, ThreeMilesTrawlingAlert("NAMO")), | ||
Pair(3, MissingFARAlert("NAMO")), | ||
), | ||
) | ||
|
||
// When | ||
ArchiveOutdatedReportings(reportingRepository).execute() | ||
|
||
// Then | ||
verify(reportingRepository).archiveReportings(eq(listOf(2, 3))) | ||
} | ||
} |
Oops, something went wrong.