Skip to content

Commit

Permalink
Préavis – Garder une trace des différentes modifications (correction) (
Browse files Browse the repository at this point in the history
…#3812)

## Linked issues

- Resolve #3811
- Resolve #3346

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
louptheron authored Nov 5, 2024
2 parents a5c4d78 + 449a8fc commit 6b4be5d
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class CreateOrUpdateManualPriorNotification(
tripGearCodes: List<String>,
vesselId: Int,
): PriorNotification {
val existingMessageValue: PNO? =
val existingManualPriorNotification =
reportId?.let {
val manualPriorNotfication = manualPriorNotificationRepository.findByReportId(reportId)
manualPriorNotfication?.logbookMessageAndValue?.logbookMessage?.message as PNO
manualPriorNotificationRepository.findByReportId(reportId)
}
val existingMessageValue: PNO? = existingManualPriorNotification?.logbookMessageAndValue?.logbookMessage?.message as PNO?

// /!\ Backend computed vessel risk factor is only used as a real time Frontend indicator.
// The Backend should NEVER update `risk_factors` DB table, only the pipeline is allowed to update it.
Expand Down Expand Up @@ -138,8 +138,8 @@ class CreateOrUpdateManualPriorNotification(
isManuallyCreated = true,
logbookMessageAndValue = logbookMessageAndValue,
sentAt = sentAt,
createdAt = existingManualPriorNotification?.createdAt,
// All these props are useless for the save operation.
createdAt = null,
port = null,
reportingCount = null,
seafront = null,
Expand Down Expand Up @@ -189,15 +189,14 @@ class CreateOrUpdateManualPriorNotification(
val allPorts = portRepository.findAll()

val authorTrigram = existingMessageValue?.authorTrigram
val createdBy = existingMessageValue?.createdBy ?: author
val createdBy = existingMessageValue?.createdBy ?: existingMessageValue?.authorTrigram ?: author
val isInVerificationScope =
ManualPriorNotificationComputedValues
.isInVerificationScope(computedVesselFlagCountryCode, computedVesselRiskFactor)
// If the prior notification is not in verification scope,
// we pass `isBeingSent` as `true` in order to ask the workflow to send it.
val isBeingSent = !isInVerificationScope && isPartOfControlUnitSubscriptions
val portName = allPorts.find { it.locode == portLocode }?.name
val updatedBy = if (existingMessageValue != null) author else null

return PNO().apply {
this.authorTrigram = authorTrigram
Expand Down Expand Up @@ -230,7 +229,8 @@ class CreateOrUpdateManualPriorNotification(
this.statisticalRectangle = null
this.tripStartDate = null
this.riskFactor = computedVesselRiskFactor
this.updatedBy = updatedBy
this.updatedBy = author
this.updatedAt = ZonedDateTime.now()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,18 @@ data class ManualPriorNotificationEntity(
@Column(name = "trip_segments", nullable = true, columnDefinition = "jsonb")
@Type(JsonBinaryType::class)
val tripSegments: List<LogbookTripSegment>?,
@Column(name = "updated_at")
val updatedAt: ZonedDateTime,
@Column(name = "value", nullable = true, columnDefinition = "jsonb")
@Type(JsonBinaryType::class)
val value: PNO,
@Column(name = "vessel_name")
val vesselName: String?,
) {
companion object {
fun fromPriorNotification(
priorNotification: PriorNotification,
isUpdate: Boolean = false,
): ManualPriorNotificationEntity {
fun fromPriorNotification(priorNotification: PriorNotification): ManualPriorNotificationEntity {
try {
val pnoLogbookMessage = priorNotification.logbookMessageAndValue.logbookMessage
val pnoLogbookMessageValue = priorNotification.logbookMessageAndValue.value
val createdAt = priorNotification.createdAt ?: ZonedDateTime.now()
val updatedAt =
if (isUpdate || priorNotification.updatedAt == null) {
ZonedDateTime.now()
} else {
priorNotification.updatedAt
}

val sentAt = requireNotNull(priorNotification.sentAt) { "`sentAt` is null." }
val vesselId = requireNotNull(pnoLogbookMessage.vesselId) { "`vesselId` is null." }
Expand All @@ -78,7 +67,6 @@ data class ManualPriorNotificationEntity(
sentAt = sentAt,
tripGears = pnoLogbookMessage.tripGears,
tripSegments = pnoLogbookMessage.tripSegments,
updatedAt = updatedAt,
value = pnoLogbookMessageValue,
vesselName = pnoLogbookMessage.vesselName,
vesselId = vesselId,
Expand Down Expand Up @@ -129,7 +117,7 @@ data class ManualPriorNotificationEntity(
logbookMessageAndValue = logbookMessageAndValue,
reportId = reportId,
sentAt = sentAt,
updatedAt = updatedAt,
updatedAt = logbookMessageAndValue.value.updatedAt,
// These props need to be calculated in the use case
port = null,
reportingCount = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class JpaManualPriorNotificationRepository(
try {
val manualPriorNotificationEntity =
dbManualPriorNotificationRepository
.save(ManualPriorNotificationEntity.fromPriorNotification(newOrNextPriorNotification, true))
.save(ManualPriorNotificationEntity.fromPriorNotification(newOrNextPriorNotification))

return manualPriorNotificationEntity.toPriorNotification()
} catch (e: IllegalArgumentException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE public.manual_prior_notifications
DROP COLUMN updated_at;
Loading

0 comments on commit 6b4be5d

Please sign in to comment.