Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Préavis – Ajoute le statut 'Invalidé' et regroupe les états en attente dans le filtre des status de diffusion #3627

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ class CreatePriorNotificationUpload(
private val manualPriorNotificationRepository: ManualPriorNotificationRepository,
private val priorNotificationUploadRepository: PriorNotificationUploadRepository,
) {
fun execute(identifier: PriorNotificationIdentifier, content: ByteArray, fileName: String, mimeType: String) {
fun execute(
identifier: PriorNotificationIdentifier,
content: ByteArray,
fileName: String,
mimeType: String,
) {
val createdAt = CustomZonedDateTime.now()

val newPriorNotificationDocument = PriorNotificationDocument(
id = null,
content = content,
createdAt = createdAt,
fileName = fileName,
isManualPriorNotification = identifier.isManualPriorNotification,
mimeType = mimeType,
reportId = identifier.reportId,
updatedAt = createdAt,
)
val newPriorNotificationDocument =
PriorNotificationDocument(
id = null,
content = content,
createdAt = createdAt,
fileName = fileName,
isManualPriorNotification = identifier.isManualPriorNotification,
mimeType = mimeType,
reportId = identifier.reportId,
updatedAt = createdAt,
)

priorNotificationUploadRepository.save(newPriorNotificationDocument)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class DeletePriorNotificationUpload(
private val manualPriorNotificationRepository: ManualPriorNotificationRepository,
private val priorNotificationUploadRepository: PriorNotificationUploadRepository,
) {
fun execute(identifier: PriorNotificationIdentifier, priorNotificationUploadId: String) {
fun execute(
identifier: PriorNotificationIdentifier,
priorNotificationUploadId: String,
) {
priorNotificationUploadRepository.deleteById(priorNotificationUploadId)

if (identifier.isManualPriorNotification) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class GetPriorNotifications(

fun execute(
filter: PriorNotificationsFilter,
isInvalidated: Boolean?,
seafrontGroup: SeafrontGroup,
states: List<PriorNotificationState>?,
sortColumn: PriorNotificationsSortColumn,
Expand Down Expand Up @@ -90,7 +91,13 @@ class GetPriorNotifications(
compareByDescending<PriorNotification> { getSortKey(it, sortColumn) }
.thenByDescending { it.logbookMessageAndValue.logbookMessage.id }, // Tie-breaker
)
}.filter { seafrontGroup.hasSeafront(it.seafront) && (states.isNullOrEmpty() || states.contains(it.state)) }
}.filter { priorNotification ->
seafrontGroup.hasSeafront(priorNotification.seafront) && (
(states.isNullOrEmpty() && isInvalidated == null) ||
(!states.isNullOrEmpty() && states.contains(priorNotification.state)) ||
(isInvalidated != null && priorNotification.logbookMessageAndValue.value.isInvalidated == isInvalidated)
)
}
}
logger.info(
"TIME_RECORD - 'sortedAndFilteredPriorNotifications' took $sortedAndFilteredPriorNotificationsTimeTaken.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class PriorNotificationController(
@Parameter(description = "Vessels that have one or more reportings.")
@RequestParam(name = "hasOneOrMoreReportings")
hasOneOrMoreReportings: Boolean? = null,
@Parameter(description = "Include or exclude invalidated prior notifications.")
@RequestParam(name = "isInvalidated")
isInvalidated: Boolean? = null,
@Parameter(description = "Vessels that are less than 12 meters in length.")
@RequestParam(name = "isLessThanTwelveMetersVessel")
isLessThanTwelveMetersVessel: Boolean? = null,
Expand Down Expand Up @@ -129,6 +132,7 @@ class PriorNotificationController(
getPriorNotifications
.execute(
priorNotificationsFilter,
isInvalidated,
seafrontGroup,
states,
sortColumn,
Expand Down Expand Up @@ -378,10 +382,11 @@ class PriorNotificationController(
): ResponseEntity<ByteArray> {
val document = getPriorNotificationUpload.execute(priorNotificationUploadId)

val headers = HttpHeaders().apply {
contentType = MediaType.parseMediaType(document.mimeType)
setContentDispositionFormData("attachment", document.fileName)
}
val headers =
HttpHeaders().apply {
contentType = MediaType.parseMediaType(document.mimeType)
setContentDispositionFormData("attachment", document.fileName)
}

return ResponseEntity(document.content, headers, HttpStatus.OK)
}
Expand Down Expand Up @@ -412,12 +417,15 @@ class PriorNotificationController(
@RequestParam("file")
file: MultipartFile,
): ResponseEntity<*> {
val content = file.bytes
?: throw BackendRequestException(BackendRequestErrorCode.EMPTY_UPLOADED_FILE)
val fileName = file.originalFilename
?: throw BackendRequestException(BackendRequestErrorCode.MISSING_UPLOADED_FILE_NAME)
val mimeType = file.contentType
?: throw BackendRequestException(BackendRequestErrorCode.MISSING_UPLOADED_FILE_TYPE)
val content =
file.bytes
?: throw BackendRequestException(BackendRequestErrorCode.EMPTY_UPLOADED_FILE)
val fileName =
file.originalFilename
?: throw BackendRequestException(BackendRequestErrorCode.MISSING_UPLOADED_FILE_NAME)
val mimeType =
file.contentType
?: throw BackendRequestException(BackendRequestErrorCode.MISSING_UPLOADED_FILE_TYPE)

val identifier = PriorNotificationIdentifier(reportId, operationDate, isManualPriorNotification)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ class PriorNotificationUploadDataOutput(
val updatedAt: CustomZonedDateTime,
) {
companion object {
fun fromPriorNotificationDocument(priorNotificationDocument: PriorNotificationDocument): PriorNotificationUploadDataOutput {
val id = requireNotNull(priorNotificationDocument.id) {
"`id` is null."
}
fun fromPriorNotificationDocument(
priorNotificationDocument: PriorNotificationDocument,
): PriorNotificationUploadDataOutput {
val id =
requireNotNull(priorNotificationDocument.id) {
"`id` is null."
}

return PriorNotificationUploadDataOutput(
id = id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,22 @@ data class PriorNotificationUploadEntity(
@Column(name = "id", updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: String?,

@Column(name = "content", nullable = false)
@JdbcType(BinaryJdbcType::class)
val content: ByteArray,

@Column(name = "created_at", nullable = false)
val createdAt: ZonedDateTime,

@Column(name = "file_name", nullable = false)
val fileName: String,

@Column(name = "is_manual_prior_notification", nullable = false)
val isManualPriorNotification: Boolean,

@Column(name = "mime_type", nullable = false)
val mimeType: String,

@Column(name = "report_id", nullable = false)
val reportId: String,

@Column(name = "updated_at", nullable = false)
val updatedAt: ZonedDateTime,
) {

fun toDocument(): PriorNotificationDocument {
return PriorNotificationDocument(
id = id!!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
willArriveAfter = "2000-01-01T00:00:00Z",
willArriveBefore = "2099-12-31T00:00:00Z",
)
private val defaultIsInvalidated = null
private val defaultSeafrontGroup = SeafrontGroup.ALL
private val defaultStates = null
private val defaultSortColumn = PriorNotificationsSortColumn.EXPECTED_ARRIVAL_DATE
Expand All @@ -71,6 +72,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
defaultStates,
sortColumn,
Expand Down Expand Up @@ -102,6 +104,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
defaultStates,
sortColumn,
Expand Down Expand Up @@ -133,6 +136,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
defaultStates,
sortColumn,
Expand Down Expand Up @@ -164,6 +168,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
defaultStates,
sortColumn,
Expand Down Expand Up @@ -195,6 +200,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
defaultStates,
sortColumn,
Expand Down Expand Up @@ -222,6 +228,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
defaultStates,
sortColumn,
Expand Down Expand Up @@ -249,6 +256,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
defaultStates,
sortColumn,
Expand Down Expand Up @@ -281,6 +289,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
defaultStates,
sortColumn,
Expand Down Expand Up @@ -313,6 +322,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
defaultStates,
sortColumn,
Expand Down Expand Up @@ -342,6 +352,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
defaultStates,
sortColumn,
Expand Down Expand Up @@ -370,6 +381,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
seafrontGroup,
defaultStates,
defaultSortColumn,
Expand All @@ -394,6 +406,7 @@ class GetPriorNotificationsITests : AbstractDBTests() {
getPriorNotifications
.execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
states,
defaultSortColumn,
Expand All @@ -413,4 +426,61 @@ class GetPriorNotificationsITests : AbstractDBTests() {
},
).isTrue()
}

@Test
@Transactional
fun `execute should return a list of invalidated prior notifications`() {
// Given
val isInvalidated = true

// When
val result =
getPriorNotifications
.execute(
defaultFilter,
isInvalidated,
defaultSeafrontGroup,
defaultStates,
defaultSortColumn,
defaultSortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
assertThat(result.data).hasSizeGreaterThan(0)
assertThat(result.data.all { it.logbookMessageAndValue.value.isInvalidated == true }).isTrue()
}

@Test
@Transactional
fun `execute should return a list of either pending send or invalidated prior notifications`() {
// Given
val isInvalidated = true
val states = listOf(PriorNotificationState.PENDING_SEND)

// When
val result =
getPriorNotifications
.execute(
defaultFilter,
isInvalidated,
defaultSeafrontGroup,
states,
defaultSortColumn,
defaultSortDirection,
defaultPageNumber,
defaultPageSize,
)

// Then
val invalidatedPriorNotifications = result.data.filter { it.logbookMessageAndValue.value.isInvalidated == true }
val pendingSendPriorNotifications = result.data.filter { it.state == PriorNotificationState.PENDING_SEND }
val pendingSendPriorNotificationReportIds = pendingSendPriorNotifications.map { it.reportId!! }
assertThat(invalidatedPriorNotifications).hasSizeGreaterThan(0)
assertThat(pendingSendPriorNotifications).hasSizeGreaterThan(0)
assertThat(
invalidatedPriorNotifications.none { pendingSendPriorNotificationReportIds.contains(it.reportId!!) },
).isTrue()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class GetPriorNotificationsUTests {
willArriveAfter = "2000-01-01T00:00:00Z",
willArriveBefore = "2099-12-31T00:00:00Z",
)
private val defaultIsInvalidated = null
private val defaultSeafrontGroup = SeafrontGroup.ALL
private val defaultStates = null
private val defaultSortColumn = PriorNotificationsSortColumn.EXPECTED_ARRIVAL_DATE
Expand Down Expand Up @@ -144,6 +145,7 @@ class GetPriorNotificationsUTests {
vesselRepository,
).execute(
defaultFilter,
defaultIsInvalidated,
defaultSeafrontGroup,
defaultStates,
defaultSortColumn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,18 @@ class PriorNotificationControllerUTests {
val secondFakePriorNotification = PriorNotificationFaker.fakePriorNotification(2)

// Given
given(getPriorNotifications.execute(any(), any(), anyOrNull(), any(), any(), any(), any())).willReturn(
given(
getPriorNotifications.execute(
any(),
anyOrNull(),
any(),
anyOrNull(),
any(),
any(),
any(),
any(),
),
).willReturn(
PaginatedList(
data = listOf(firstFakePriorNotification, secondFakePriorNotification),
extraData = PriorNotificationStats(perSeafrontGroupCount = emptyMap()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ class JpaPriorNotificationPdfDocumentRepositoryITests : AbstractDBTests() {
jpaPriorNotificationPdfDocumentRepository.deleteByReportId(reportId)

// Then
val throwable = catchThrowable {
jpaPriorNotificationPdfDocumentRepository.findByReportId(reportId)
}
val throwable =
catchThrowable {
jpaPriorNotificationPdfDocumentRepository.findByReportId(reportId)
}
assertThat(throwable).isNotNull()
assertThat((throwable as BackendUsageException).code).isEqualTo(BackendUsageErrorCode.NOT_FOUND)
}
Expand Down
Loading
Loading