-
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.
Préavis – Ajouter des pastilles indiquant le nombre de préavis à véri…
- Loading branch information
Showing
46 changed files
with
574 additions
and
73 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
43 changes: 43 additions & 0 deletions
43
.../kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetNumberToVerify.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,43 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification | ||
|
||
import fr.gouv.cnsp.monitorfish.config.UseCase | ||
import fr.gouv.cnsp.monitorfish.domain.entities.facade.SeafrontGroup | ||
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotificationStats | ||
import fr.gouv.cnsp.monitorfish.domain.repositories.* | ||
|
||
@UseCase | ||
class GetNumberToVerify( | ||
private val logbookReportRepository: LogbookReportRepository, | ||
private val manualPriorNotificationRepository: ManualPriorNotificationRepository, | ||
private val portRepository: PortRepository, | ||
private val riskFactorRepository: RiskFactorRepository, | ||
private val vesselRepository: VesselRepository, | ||
) { | ||
fun execute(): PriorNotificationStats { | ||
val allPorts = portRepository.findAll() | ||
val allRiskFactors = riskFactorRepository.findAll() | ||
val allVessels = vesselRepository.findAll() | ||
|
||
val automaticPriorNotifications = logbookReportRepository.findAllPriorNotificationsToVerify() | ||
val manualPriorNotifications = manualPriorNotificationRepository.findAllToVerify() | ||
val incompletePriorNotifications = automaticPriorNotifications + manualPriorNotifications | ||
|
||
val undeletedPriorNotifications = incompletePriorNotifications | ||
.filter { !it.logbookMessageTyped.logbookMessage.isDeleted } | ||
|
||
val priorNotifications = undeletedPriorNotifications | ||
.map { priorNotification -> | ||
priorNotification.enrich(allPorts, allRiskFactors, allVessels, priorNotification.isManuallyCreated) | ||
|
||
priorNotification | ||
} | ||
|
||
return PriorNotificationStats( | ||
perSeafrontGroupCount = SeafrontGroup.entries.associateWith { seafrontGroupEntry -> | ||
priorNotifications.count { priorNotification -> | ||
seafrontGroupEntry.hasSeafront(priorNotification.seafront) | ||
} | ||
}, | ||
) | ||
} | ||
} |
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
135 changes: 135 additions & 0 deletions
135
...n/fr/gouv/cnsp/monitorfish/domain/use_cases/prior_notification/GetNumberToVerifyUTests.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,135 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification | ||
|
||
import com.nhaarman.mockitokotlin2.given | ||
import fr.gouv.cnsp.monitorfish.domain.entities.facade.SeafrontGroup | ||
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookMessage | ||
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookMessageTyped | ||
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookOperationType | ||
import fr.gouv.cnsp.monitorfish.domain.entities.logbook.LogbookTransmissionFormat | ||
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.repositories.* | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
import java.time.ZonedDateTime | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class GetNumberToVerifyUTests { | ||
@MockBean | ||
private lateinit var logbookReportRepository: LogbookReportRepository | ||
|
||
@MockBean | ||
private lateinit var manualPriorNotificationRepository: ManualPriorNotificationRepository | ||
|
||
@MockBean | ||
private lateinit var portRepository: PortRepository | ||
|
||
@MockBean | ||
private lateinit var riskFactorRepository: RiskFactorRepository | ||
|
||
@MockBean | ||
private lateinit var vesselRepository: VesselRepository | ||
|
||
@Test | ||
fun `execute Should return a map of PNO for each facade to verify`() { | ||
// Given | ||
given(portRepository.findAll()).willReturn( | ||
listOf( | ||
Port("AEFJR", "Al Jazeera Port", facade = "NAMO"), | ||
Port("AEFAT", "Al Jazeera Port", facade = "Guyane"), | ||
Port("AEJAZ", "Arzanah Island", facade = "SA"), | ||
), | ||
) | ||
given(logbookReportRepository.findAllPriorNotificationsToVerify()).willReturn( | ||
listOf( | ||
PriorNotification( | ||
reportId = "FAKE_REPORT_ID_1", | ||
authorTrigram = null, | ||
createdAt = null, | ||
didNotFishAfterZeroNotice = false, | ||
isManuallyCreated = false, | ||
logbookMessageTyped = LogbookMessageTyped( | ||
clazz = PNO::class.java, | ||
logbookMessage = LogbookMessage( | ||
id = 1, | ||
reportId = "FAKE_REPORT_ID_1", | ||
referencedReportId = null, | ||
integrationDateTime = ZonedDateTime.now(), | ||
isCorrectedByNewerMessage = false, | ||
isDeleted = false, | ||
isEnriched = false, | ||
message = PNO().apply { port = "AEFJR" }, | ||
operationDateTime = ZonedDateTime.now(), | ||
operationNumber = "1", | ||
operationType = LogbookOperationType.DAT, | ||
reportDateTime = ZonedDateTime.now(), | ||
transmissionFormat = LogbookTransmissionFormat.ERS, | ||
), | ||
), | ||
port = null, | ||
reportingCount = null, | ||
seafront = null, | ||
sentAt = null, | ||
state = null, | ||
updatedAt = null, | ||
vessel = null, | ||
lastControlDateTime = null, | ||
), | ||
|
||
PriorNotification( | ||
reportId = "FAKE_REPORT_ID_2", | ||
authorTrigram = null, | ||
createdAt = null, | ||
didNotFishAfterZeroNotice = false, | ||
isManuallyCreated = false, | ||
logbookMessageTyped = LogbookMessageTyped( | ||
clazz = PNO::class.java, | ||
logbookMessage = LogbookMessage( | ||
id = 1, | ||
reportId = "FAKE_REPORT_ID_2_COR", | ||
referencedReportId = "FAKE_NONEXISTENT_REPORT_ID_2", | ||
integrationDateTime = ZonedDateTime.now(), | ||
isCorrectedByNewerMessage = false, | ||
isDeleted = false, | ||
isEnriched = false, | ||
message = PNO().apply { port = "AEFAT" }, | ||
operationDateTime = ZonedDateTime.now(), | ||
operationNumber = "1", | ||
operationType = LogbookOperationType.COR, | ||
reportDateTime = ZonedDateTime.now(), | ||
transmissionFormat = LogbookTransmissionFormat.ERS, | ||
), | ||
), | ||
port = null, | ||
reportingCount = null, | ||
seafront = null, | ||
sentAt = null, | ||
state = null, | ||
updatedAt = null, | ||
vessel = null, | ||
lastControlDateTime = null, | ||
), | ||
), | ||
) | ||
|
||
// When | ||
val result = GetNumberToVerify( | ||
logbookReportRepository, | ||
manualPriorNotificationRepository, | ||
portRepository, | ||
riskFactorRepository, | ||
vesselRepository, | ||
).execute() | ||
|
||
// Then | ||
assertThat(result.perSeafrontGroupCount.values).hasSize(8) | ||
assertThat(result.perSeafrontGroupCount[SeafrontGroup.ALL]).isEqualTo(2) | ||
assertThat(result.perSeafrontGroupCount[SeafrontGroup.NAMO]).isEqualTo(1) | ||
assertThat(result.perSeafrontGroupCount[SeafrontGroup.OUTREMEROA]).isEqualTo(1) | ||
assertThat(result.perSeafrontGroupCount[SeafrontGroup.NONE]).isEqualTo(0) | ||
} | ||
} |
Oops, something went wrong.