Skip to content

Commit

Permalink
Fix updatedBy logic in CreateOrUpdateManualPriorNotification use case
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Oct 17, 2024
1 parent a1db22d commit 00fb33d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CreateOrUpdateManualPriorNotification(

fun execute(
reportId: String?,
author: String?,
didNotFishAfterZeroNotice: Boolean,
expectedArrivalDate: ZonedDateTime,
expectedLandingDate: ZonedDateTime,
Expand All @@ -43,10 +44,9 @@ class CreateOrUpdateManualPriorNotification(
hasPortLandingAuthorization: Boolean,
note: String?,
portLocode: String,
sentAt: ZonedDateTime,
purpose: LogbookMessagePurpose,
sentAt: ZonedDateTime,
tripGearCodes: List<String>,
updatedBy: String?,
vesselId: Int,
): PriorNotification {
val existingMessageValue: PNO? =
Expand All @@ -55,8 +55,6 @@ class CreateOrUpdateManualPriorNotification(
manualPriorNotfication?.logbookMessageAndValue?.logbookMessage?.message as PNO
}

println("existingMessageValue: $existingMessageValue")

// /!\ 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.
val computedValues =
Expand Down Expand Up @@ -94,7 +92,7 @@ class CreateOrUpdateManualPriorNotification(
pnoTypes = priorNotificationTypes,
portLocode = portLocode,
purpose = purpose,
updatedBy = updatedBy,
author = author,
computedVesselFlagCountryCode = vessel?.flagState,
computedVesselRiskFactor = computedValues.vesselRiskFactor,
isPartOfControlUnitSubscriptions = isPartOfControlUnitSubscriptions,
Expand Down Expand Up @@ -183,22 +181,23 @@ class CreateOrUpdateManualPriorNotification(
note: String?,
pnoTypes: List<PriorNotificationType>,
portLocode: String,
updatedBy: String?,
author: String?,
computedVesselFlagCountryCode: CountryCode?,
computedVesselRiskFactor: Double?,
isPartOfControlUnitSubscriptions: Boolean,
): PNO {
val allPorts = portRepository.findAll()

val authorTrigram = existingMessageValue?.authorTrigram
val createdBy = existingMessageValue?.createdBy ?: updatedBy
val createdBy = existingMessageValue?.createdBy ?: 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
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class PriorNotificationController(
): ManualPriorNotificationFormDataOutput {
val createdPriorNotification =
createOrUpdateManualPriorNotification.execute(
author = response.getHeader(UserAuthorizationCheckFilter.EMAIL_HEADER),
didNotFishAfterZeroNotice = manualPriorNotificationFormDataInput.didNotFishAfterZeroNotice,
expectedArrivalDate = manualPriorNotificationFormDataInput.expectedArrivalDate,
expectedLandingDate = manualPriorNotificationFormDataInput.expectedLandingDate,
Expand All @@ -233,7 +234,6 @@ class PriorNotificationController(
sentAt = manualPriorNotificationFormDataInput.sentAt,
purpose = manualPriorNotificationFormDataInput.purpose,
tripGearCodes = manualPriorNotificationFormDataInput.tripGearCodes,
updatedBy = response.getHeader(UserAuthorizationCheckFilter.EMAIL_HEADER),
vesselId = manualPriorNotificationFormDataInput.vesselId,
)

Expand All @@ -252,6 +252,7 @@ class PriorNotificationController(
): ManualPriorNotificationFormDataOutput {
val updatedPriorNotification =
createOrUpdateManualPriorNotification.execute(
author = response.getHeader(UserAuthorizationCheckFilter.EMAIL_HEADER),
didNotFishAfterZeroNotice = manualPriorNotificationFormDataInput.didNotFishAfterZeroNotice,
expectedArrivalDate = manualPriorNotificationFormDataInput.expectedArrivalDate,
expectedLandingDate = manualPriorNotificationFormDataInput.expectedLandingDate,
Expand All @@ -265,7 +266,6 @@ class PriorNotificationController(
sentAt = manualPriorNotificationFormDataInput.sentAt,
purpose = manualPriorNotificationFormDataInput.purpose,
tripGearCodes = manualPriorNotificationFormDataInput.tripGearCodes,
updatedBy = response.getHeader(UserAuthorizationCheckFilter.EMAIL_HEADER),
vesselId = manualPriorNotificationFormDataInput.vesselId,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fr.gouv.cnsp.monitorfish.utils.CustomZonedDateTime
import java.time.ZoneOffset
import java.time.ZonedDateTime

@Suppress("NullableBooleanElvis")
data class ManualPriorNotificationFormDataOutput(
val reportId: String,
val didNotFishAfterZeroNotice: Boolean,
Expand Down Expand Up @@ -59,8 +60,8 @@ data class ManualPriorNotificationFormDataOutput(
"`priorNotification.vessel` is null."
}.id

val hasPortEntranceAuthorization = pnoValue.hasPortEntranceAuthorization != false
val hasPortLandingAuthorization = pnoValue.hasPortLandingAuthorization != false
val hasPortEntranceAuthorization = pnoValue.hasPortEntranceAuthorization ?: true
val hasPortLandingAuthorization = pnoValue.hasPortLandingAuthorization ?: true
// In Frontend form, manual prior notifications can:
// - either have a single global FAO area field
// - or have an FAO area field per fishing catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ class CreateOrUpdateManualPriorNotificationITests : AbstractDBTests() {
val afterPriorNotification =
createOrUpdateManualPriorNotification.execute(
reportId = reportId,
author = "[email protected]",
didNotFishAfterZeroNotice = false,
expectedArrivalDate = ZonedDateTime.now(),
expectedLandingDate = ZonedDateTime.now(),
Expand All @@ -368,7 +369,6 @@ class CreateOrUpdateManualPriorNotificationITests : AbstractDBTests() {
purpose = LogbookMessagePurpose.LAN,
sentAt = ZonedDateTime.now(),
tripGearCodes = emptyList(),
updatedBy = "[email protected]",
vesselId = 1,
)

Expand Down Expand Up @@ -405,6 +405,7 @@ class CreateOrUpdateManualPriorNotificationITests : AbstractDBTests() {
val afterPriorNotification =
createOrUpdateManualPriorNotification.execute(
reportId = reportId,
author = "[email protected]",
didNotFishAfterZeroNotice = false,
expectedArrivalDate = ZonedDateTime.now(),
expectedLandingDate = ZonedDateTime.now(),
Expand All @@ -417,7 +418,6 @@ class CreateOrUpdateManualPriorNotificationITests : AbstractDBTests() {
purpose = LogbookMessagePurpose.LAN,
sentAt = ZonedDateTime.now(),
tripGearCodes = emptyList(),
updatedBy = "[email protected]",
vesselId = 1,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CreateOrUpdateManualPriorNotificationUTests {
computeManualPriorNotification,
getPriorNotification,
).execute(
purpose = LogbookMessagePurpose.LAN,
author = "[email protected]",
didNotFishAfterZeroNotice = false,
expectedArrivalDate = ZonedDateTime.parse("2024-01-01T00:00:00Z"),
expectedLandingDate = ZonedDateTime.parse("2024-01-01T00:00:00Z"),
Expand All @@ -95,10 +95,10 @@ class CreateOrUpdateManualPriorNotificationUTests {
hasPortLandingAuthorization = true,
note = null,
portLocode = "FAKE_PORT_LOCODE",
purpose = LogbookMessagePurpose.LAN,
reportId = null,
sentAt = ZonedDateTime.parse("2024-01-01T00:00:00Z"),
tripGearCodes = emptyList(),
updatedBy = "[email protected]",
vesselId = 1,
)

Expand Down Expand Up @@ -148,7 +148,7 @@ class CreateOrUpdateManualPriorNotificationUTests {
computeManualPriorNotification,
getPriorNotification,
).execute(
purpose = LogbookMessagePurpose.LAN,
author = "[email protected]",
didNotFishAfterZeroNotice = false,
expectedArrivalDate = ZonedDateTime.parse("2024-01-01T00:00:00Z"),
expectedLandingDate = ZonedDateTime.parse("2024-01-01T00:00:00Z"),
Expand All @@ -158,10 +158,10 @@ class CreateOrUpdateManualPriorNotificationUTests {
hasPortLandingAuthorization = true,
note = null,
portLocode = "FAKE_PORT_LOCODE",
purpose = LogbookMessagePurpose.LAN,
reportId = existingFakePriorNotification.reportId!!,
sentAt = ZonedDateTime.parse("2024-01-01T00:00:00Z"),
tripGearCodes = emptyList(),
updatedBy = "[email protected]",
vesselId = 1,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class PriorNotificationControllerUTests {
given(
createOrUpdateManualPriorNotification.execute(
reportId = any(),
author = anyOrNull(),
didNotFishAfterZeroNotice = anyOrNull(),
expectedArrivalDate = anyOrNull(),
expectedLandingDate = anyOrNull(),
Expand All @@ -272,7 +273,6 @@ class PriorNotificationControllerUTests {
sentAt = anyOrNull(),
purpose = anyOrNull(),
tripGearCodes = anyOrNull(),
updatedBy = anyOrNull(),
vesselId = anyOrNull(),
),
)
Expand Down

0 comments on commit 00fb33d

Please sign in to comment.