Skip to content

Commit

Permalink
Remove author trigram field from pno forms
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Oct 16, 2024
1 parent ed1b7e4 commit c59076b
Show file tree
Hide file tree
Showing 24 changed files with 28 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class PNO() : LogbookMessageValue {
var hasPortEntranceAuthorization: Boolean? = null
var hasPortLandingAuthorization: Boolean? = null

@Deprecated(
"""
Kept because some historical messages used a manually entered trigram to identify the author of the message.
It's now automated via `createdBy` and `updatedBy` fields.
""",
)
var authorTrigram: String? = null
var catchOnboard: List<LogbookFishingCatch> = emptyList()
var catchToLand: List<LogbookFishingCatch> = emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ interface LogbookReportRepository {

fun findAllPriorNotificationsToVerify(): List<PriorNotification>

fun updatePriorNotificationAuthorTrigramAndNote(
fun updatePriorNotificationNote(
reportId: String,
operationDate: ZonedDateTime,
authorTrigram: String?,
note: String?,
updatedBy: String?,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class CreateOrUpdateManualPriorNotification(
val portName = allPorts.find { it.locode == portLocode }?.name

return PNO().apply {
this.authorTrigram = authorTrigram
this.catchOnboard = fishingCatches
this.catchToLand = fishingCatches
this.economicZone = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class UpdateLogbookPriorNotification(
fun execute(
reportId: String,
operationDate: ZonedDateTime,
authorTrigram: String?,
note: String?,
updatedBy: String?,
): PriorNotification {
Expand All @@ -31,10 +30,9 @@ class UpdateLogbookPriorNotification(
logger.warn("Could not delete existing PDF document", e)
}

logbookReportRepository.updatePriorNotificationAuthorTrigramAndNote(
logbookReportRepository.updatePriorNotificationNote(
reportId = reportId,
operationDate = operationDate,
authorTrigram = authorTrigram,
note = note,
updatedBy = updatedBy,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ class PriorNotificationController(
updateLogbookPriorNotification.execute(
reportId = reportId,
operationDate = operationDate,
authorTrigram = logbookPriorNotificationFormDataInput.authorTrigram,
note = logbookPriorNotificationFormDataInput.note,
updatedBy = response.getHeader(UserAuthorizationCheckFilter.EMAIL_HEADER),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.gouv.cnsp.monitorfish.infrastructure.api.input

data class LogbookPriorNotificationFormDataInput(
val authorTrigram: String?,
val note: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotification

data class LogbookPriorNotificationFormDataOutput(
val authorTrigram: String?,
val note: String?,
) {
companion object {
fun fromPriorNotification(priorNotification: PriorNotification): LogbookPriorNotificationFormDataOutput {
return LogbookPriorNotificationFormDataOutput(
authorTrigram = priorNotification.logbookMessageAndValue.value.authorTrigram,
note = priorNotification.logbookMessageAndValue.value.note,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import java.time.ZonedDateTime

data class ManualPriorNotificationFormDataOutput(
val reportId: String,
val hasPortEntranceAuthorization: Boolean,
val hasPortLandingAuthorization: Boolean,
val authorTrigram: String,
val didNotFishAfterZeroNotice: Boolean,
val expectedArrivalDate: String,
val expectedLandingDate: String,
val fishingCatches: List<ManualPriorNotificationFishingCatchDataOutput>,
val globalFaoArea: String?,
val hasPortEntranceAuthorization: Boolean,
val hasPortLandingAuthorization: Boolean,
val note: String?,
val portLocode: String,
val sentAt: ZonedDateTime,
Expand All @@ -29,10 +28,6 @@ data class ManualPriorNotificationFormDataOutput(
val logbookMessage = priorNotification.logbookMessageAndValue.logbookMessage
val pnoValue = priorNotification.logbookMessageAndValue.value

val authorTrigram =
requireNotNull(pnoValue.authorTrigram) {
"`pnoValue.authorTrigram` is null."
}
val expectedArrivalDate =
CustomZonedDateTime.fromZonedDateTime(
requireNotNull(pnoValue.predictedArrivalDatetimeUtc) {
Expand Down Expand Up @@ -64,8 +59,8 @@ data class ManualPriorNotificationFormDataOutput(
"`priorNotification.vessel` is null."
}.id

val hasPortEntranceAuthorization = pnoValue.hasPortEntranceAuthorization ?: true
val hasPortLandingAuthorization = pnoValue.hasPortLandingAuthorization ?: true
val hasPortEntranceAuthorization = pnoValue.hasPortEntranceAuthorization != false
val hasPortLandingAuthorization = pnoValue.hasPortLandingAuthorization != false
// 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 All @@ -85,7 +80,6 @@ data class ManualPriorNotificationFormDataOutput(

return ManualPriorNotificationFormDataOutput(
reportId = reportId,
authorTrigram = authorTrigram,
didNotFishAfterZeroNotice = priorNotification.didNotFishAfterZeroNotice,
expectedArrivalDate = expectedArrivalDate,
expectedLandingDate = expectedLandingDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,9 @@ class JpaLogbookReportRepository(
}

@Transactional
override fun updatePriorNotificationAuthorTrigramAndNote(
override fun updatePriorNotificationNote(
reportId: String,
operationDate: ZonedDateTime,
authorTrigram: String?,
note: String?,
updatedBy: String?,
) {
Expand All @@ -410,16 +409,12 @@ class JpaLogbookReportRepository(
?: throw BackendUsageException(BackendUsageErrorCode.NOT_FOUND)

val pnoValue = objectMapper.readValue(logbookReport.message, PNO::class.java)
if (
Utils.areStringsEqual(authorTrigram, pnoValue.authorTrigram) &&
Utils.areStringsEqual(note, pnoValue.note)
) {
if (Utils.areStringsEqual(note, pnoValue.note)) {
return
}

val nextPnoValue =
pnoValue.apply {
this.authorTrigram = authorTrigram
this.note = note
this.updatedBy = updatedBy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class UpdateLogbookPriorNotificationITests : AbstractDBTests() {

// When
val afterPriorNotification =
updateLogbookPriorNotification.execute(reportId, operationDate, "ABC", "Une note.", "bob@example.org")
updateLogbookPriorNotification.execute(reportId, operationDate, "ABC", "editor@example.org")

// Then
val afterPnoValue = afterPriorNotification.logbookMessageAndValue.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ class UpdateLogbookPriorNotificationUTests {
).execute(
reportId = fakePriorNotification.reportId!!,
operationDate = fakePriorNotification.logbookMessageAndValue.logbookMessage.operationDateTime,
authorTrigram = "ABC",
note = null,
updatedBy = "bob@example.org",
updatedBy = "editor@example.org",
)

// Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,14 @@ class PriorNotificationControllerUTests {
updateLogbookPriorNotification.execute(
reportId = anyOrNull(),
operationDate = anyOrNull(),
authorTrigram = anyOrNull(),
note = anyOrNull(),
updatedBy = anyOrNull(),
),
)
.willReturn(fakePriorNotification)

// When
val requestBody =
objectMapper.writeValueAsString(
LogbookPriorNotificationFormDataInput(
authorTrigram = "ABC",
note = "Test !",
),
)
val requestBody = objectMapper.writeValueAsString(LogbookPriorNotificationFormDataInput(note = "Test !"))
val pnoValue = fakePriorNotification.logbookMessageAndValue.value
api.perform(
put(
Expand All @@ -164,7 +157,6 @@ class PriorNotificationControllerUTests {
)
// Then
.andExpect(status().isOk)
.andExpect(jsonPath("$.authorTrigram", equalTo(pnoValue.authorTrigram)))
.andExpect(jsonPath("$.note", equalTo(pnoValue.note)))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,18 +1126,18 @@ class JpaLogbookReportRepositoryITests : AbstractDBTests() {
assertThat((currentCorReport.message as PNO).note).isNull()

// When
jpaLogbookReportRepository.updatePriorNotificationAuthorTrigramAndNote(
jpaLogbookReportRepository.updatePriorNotificationNote(
reportId = "FAKE_OPERATION_109_COR",
operationDate = ZonedDateTime.now().minusMinutes(15),
authorTrigram = "ABC",
note = "A wonderful note",
updatedBy = "bob@example.org",
updatedBy = "editor@example.org",
)

// Then
val updatedCorReport = jpaLogbookReportRepository.findById(2109)
assertThat((updatedCorReport.message as PNO).authorTrigram).isNull()
assertThat((updatedCorReport.message as PNO).note).isEqualTo("A wonderful note")
assertThat((updatedCorReport.message as PNO).updatedBy).isEqualTo("bob@example.org")
assertThat((updatedCorReport.message as PNO).updatedBy).isEqualTo("editor@example.org")
assertThat((updatedCorReport.message as PNO).isBeingSent).isEqualTo(false)
assertThat((updatedCorReport.message as PNO).isVerified).isEqualTo(false)
assertThat((updatedCorReport.message as PNO).isSent).isEqualTo(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ context('Side Window > Logbook Prior Notification Form > Behavior', () => {
cy.get('.Component-Banner').contains(`Le préavis est en cours de diffusion.`)

cy.get('textarea[name=note]').should('have.attr', 'readonly')
cy.get('input[name=authorTrigram]').should('have.attr', 'readonly')

cy.contains('button', 'Télécharger').should('be.disabled')
cy.contains('button', 'Diffuser').should('be.disabled')
Expand All @@ -39,7 +38,6 @@ context('Side Window > Logbook Prior Notification Form > Behavior', () => {
const operationDate = dayjs().subtract(6, 'hours').toISOString()
cy.request('PUT', `/bff/v1/prior_notifications/logbook/FAKE_OPERATION_116?operationDate=${operationDate}`, {
body: {
authorTrigram: null,
note: null
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ context('Side Window > Logbook Prior Notification Form > Form', () => {
const operationDate = dayjs().subtract(6, 'hours').toISOString()
cy.request('PUT', `/bff/v1/prior_notifications/logbook/FAKE_OPERATION_115?operationDate=${operationDate}`, {
body: {
authorTrigram: null,
note: null
}
})
Expand All @@ -23,7 +22,6 @@ context('Side Window > Logbook Prior Notification Form > Form', () => {
)

cy.get('[name="note"]').should('have.value', '')
cy.get('[name="authorTrigram"]').should('have.value', '')

// When
cy.fill("Points d'attention identifiés par le CNSP", "Un point d'attention.")
Expand All @@ -38,12 +36,10 @@ context('Side Window > Logbook Prior Notification Form > Form', () => {
editSideWindowPriorNotification(`MER À BOIRE`, 'FAKE_OPERATION_115')

cy.get('[name="note"]').should('have.value', "Un point d'attention.")
cy.get('[name="authorTrigram"]').should('have.value', 'ABC')

// Reset
cy.request('PUT', `/bff/v1/prior_notifications/logbook/FAKE_OPERATION_115?operationDate=${operationDate}`, {
body: {
authorTrigram: null,
note: null
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export function getPriorNotificationFakeResponse({
isDeleted: false,
isSentByFailoverSoftware: false,
message: {
authorTrigram: 'ABC',
authorTrigram: null,
catchOnboard: [
{
conversionFactor: null,
Expand Down Expand Up @@ -235,7 +235,7 @@ export function getPriorNotificationFakeResponse({
riskFactor: 3.2,
statisticalRectangle: null,
tripStartDate,
updatedBy: null
updatedBy: 'editor@example.org'
},
messageType: Logbook.MessageType.PNO,
operationDateTime: updatedAt,
Expand Down Expand Up @@ -272,11 +272,9 @@ export function getPriorNotificationFakeResponse({
return {
...commonData,
asLogbookForm: {
authorTrigram: 'ABC',
note: null
},
asManualDraft: {
authorTrigram: 'ABC',
didNotFishAfterZeroNotice: false,
expectedArrivalDate,
expectedLandingDate: expectedArrivalDate,
Expand All @@ -303,7 +301,6 @@ export function getPriorNotificationFakeResponse({
asLogbookForm: null,
asManualDraft: null,
asManualForm: {
authorTrigram: 'ABC',
didNotFishAfterZeroNotice: false,
expectedArrivalDate,
expectedLandingDate: expectedArrivalDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ context('Side Window > Manual Prior Notification Form > Behavior', () => {
cy.get('.Component-Banner').contains(`Le préavis est en cours de diffusion.`)

cy.get('textarea[name=note]').should('have.attr', 'readonly')
cy.get('input[name=authorTrigram]').should('have.attr', 'readonly')

cy.contains('button', 'Enregistrer').should('be.disabled')
cy.contains('button', 'Diffuser').should('be.disabled')
Expand All @@ -134,7 +133,6 @@ context('Side Window > Manual Prior Notification Form > Behavior', () => {
cy.get('.Component-Banner').contains(`Le préavis est en cours d’envoi aux unités qui l’ont demandé.`)

cy.get('textarea[name=note]').should('have.attr', 'readonly')
cy.get('input[name=authorTrigram]').should('have.attr', 'readonly')

cy.contains('button', 'Enregistrer').should('be.disabled')
cy.contains('button', 'Diffuser').should('be.disabled')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ context('Side Window > Manual Prior Notification Form > Form', () => {
weight: 200.0
})
assert.deepInclude(createdPriorNotification, {
authorTrigram: 'BOB',
didNotFishAfterZeroNotice: false,
expectedArrivalDate: arrivalDateAsString,
expectedLandingDate: landingDateAsString,
Expand Down Expand Up @@ -334,7 +333,6 @@ context('Side Window > Manual Prior Notification Form > Form', () => {
weight: 5000.0
})
assert.deepInclude(createdPriorNotification, {
authorTrigram: 'BOB',
didNotFishAfterZeroNotice: false,
expectedArrivalDate: arrivalDateAsString,
// Should be the same as the arrival date since we checked "équivalentes à celles de l'arrivée au port"
Expand Down Expand Up @@ -556,7 +554,6 @@ context('Side Window > Manual Prior Notification Form > Form', () => {
weight: 50.0
})
assert.deepInclude(createdPriorNotification, {
authorTrigram: 'BOB',
didNotFishAfterZeroNotice: false,
expectedArrivalDate: arrivalDateAsString,
expectedLandingDate: arrivalDateAsString, // Checked "équivalentes à celles de l'arrivée au port"
Expand Down Expand Up @@ -602,7 +599,6 @@ context('Side Window > Manual Prior Notification Form > Form', () => {
weight: 50.0
})
assert.deepInclude(firstUpdatedPriorNotification, {
authorTrigram: 'BOB',
didNotFishAfterZeroNotice: false,
expectedArrivalDate: arrivalDateAsString,
expectedLandingDate: arrivalDateAsString, // Checked "équivalentes à celles de l'arrivée au port"
Expand Down Expand Up @@ -643,7 +639,6 @@ context('Side Window > Manual Prior Notification Form > Form', () => {
weight: 50.0
})
assert.deepInclude(secondUpdatedPriorNotification, {
authorTrigram: 'BOB',
didNotFishAfterZeroNotice: false,
expectedArrivalDate: arrivalDateAsString,
expectedLandingDate: arrivalDateAsString, // Checked "équivalentes à celles de l'arrivée au port"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ context('Side Window > Reporting List > Actions', () => {
// Then
cy.wait('@updateReporting').then(({ request, response }) => {
expect(request.body.type).contains('OBSERVATION')
expect(request.body.authorTrigram).contains('LTH')
expect(response && response.statusCode).equal(200)

cy.getDataCy('ReportingList-reporting').should('have.length', numberOfReportings - 1)
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/features/Logbook/Logbook.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ export namespace Logbook {
}

export interface PnoMessageValue {
/**
* @deprecated
* Kept because some historical messages used a manually entered trigram to identify the author of the message.
* It's now automated via `createdBy` and `updatedBy` fields.
*/
authorTrigram: string | undefined
catchOnboard: Catch[] | undefined
catchToLand: Catch[] | undefined
Expand Down
Loading

0 comments on commit c59076b

Please sign in to comment.