Skip to content

Commit

Permalink
EIP1-11169 store is from applications api on certificate in database (#…
Browse files Browse the repository at this point in the history
…325)

* EIP-11169 Add isFromApplicationsApi to Certificate

* EIP-11169 Update ProcessPrintRequestBatchMessageListener to use isFromApplicationsApi stored on Certificate

* EIP-11169 Remove isApplicationsApi from internal queue messages
  • Loading branch information
DWRendell authored Dec 11, 2024
1 parent 2703fc9 commit 7555a9f
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class Certificate(
*/
var finalRetentionRemovalDate: LocalDate? = null,

/**
* Set to true when the certificate is associated with an application from the Applications API, rather than the
* legacy Voter Card Applications API
*/
var isFromApplicationsApi: Boolean? = false,

/**
* Certificate status corresponds to the current status of the most recent
* [PrintRequest], based on the requestDateTime that is included in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ProcessPrintRequestBatchMessageListener(

val certificates = processPrintBatchService.processBatch(batchId, printRequestCount)
certificates.forEach {
statisticsUpdateService.updateStatistics(it.sourceReference!!, payload.isFromApplicationsApi)
statisticsUpdateService.updateStatistics(it.sourceReference!!, it.isFromApplicationsApi)
}

logger.info("Successfully processed print request for batchId: $batchId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ProcessPrintResponseFileMessageListener(
override fun handleMessage(@Payload payload: ProcessPrintResponseFileMessage) {
with(payload) {
logger.info { "Begin processing PrintResponse file [$fileName] from directory [$directory]" }
printResponseFileService.processPrintResponseFile(directory, fileName, payload.isFromApplicationsApi)
printResponseFileService.processPrintResponseFile(directory, fileName)
logger.info { "Completed processing PrintResponse file [$fileName] from directory [$directory]" }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ProcessPrintResponseMessageListener(
override fun handleMessage(@Payload payload: ProcessPrintResponseMessage) {
logger.info { "Begin processing PrintResponse with requestId ${payload.requestId}" }
printResponseProcessingService.processPrintResponse(payload)?.also {
statisticsUpdateService.updateStatistics(it.sourceReference!!, payload.isFromApplicationsApi)
statisticsUpdateService.updateStatistics(it.sourceReference!!, it.isFromApplicationsApi)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class PrintResponseFileService(
val printResponseProcessingService: PrintResponseProcessingService,
val statisticsUpdateService: StatisticsUpdateService,
) {
fun processPrintResponseFile(directory: String, fileName: String, isFromApplicationsApi: Boolean? = null) {
fun processPrintResponseFile(directory: String, fileName: String) {
val printResponsesString = sftpService.fetchFileFromOutBoundDirectory(directory, fileName)
val printResponses = parsePrintResponseContent(printResponsesString)
val certificates = printResponseProcessingService.processBatchResponses(printResponses.batchResponses)
printResponseProcessingService.processPrintResponses(printResponses.printResponses)
removeFile(directory, fileName)

certificates.forEach {
statisticsUpdateService.updateStatistics(it.sourceReference!!, isFromApplicationsApi)
statisticsUpdateService.updateStatistics(it.sourceReference!!, it.isFromApplicationsApi)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@
<include relativeToChangelogFile="true" file="ddl/0028_alter_aed_contact_details_add_last_updated.xml"/>
<include relativeToChangelogFile="true" file="ddl/0029_alter_print_request_add_sanitized_surname.xml"/>
<include relativeToChangelogFile="true" file="ddl/0030_add_index_for_source_reference_to_certificate_and_temporary_certificate.xml"/>
<include relativeToChangelogFile="true" file="ddl/0031_EIP1-11169_add_is_from_applications_api_to_certificate.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">

<changeSet id="0031_EIP1-11169_add_is_from_applications_api_to_certificate" author="david.rendell@softwire.com" context="ddl">
<addColumn tableName="certificate">
<column name="is_from_applications_api" type="boolean">
<constraints nullable="true"/>
</column>
</addColumn>

<rollback>
<dropColumn tableName="certificate" columnName="is_from_applications_api"/>
</rollback>
</changeSet>
</databaseChangeLog>
13 changes: 2 additions & 11 deletions src/main/resources/openapi/sqs/print-api-sqs-messaging.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: Print API SQS Message Types
version: '1.9.6'
version: '1.10.0'
description: |-
Print API SQS Message Types
Expand Down Expand Up @@ -148,7 +148,7 @@ components:
example: fred.bloggs@some-domain.co.uk
isFromApplicationsApi:
type: boolean
description: It indicates that the message comes from Applications Api or not
description: It indicates that the message comes from the Applications Api or the legacy Voter Card Applications API
required:
- sourceReference
- sourceType
Expand Down Expand Up @@ -326,9 +326,6 @@ components:
printRequestCount:
type: integer
description: The number of print requests included in the batch
isFromApplicationsApi:
type: boolean
description: It indicates that the message comes from Applications Api or not
required:
- batchId

Expand All @@ -342,9 +339,6 @@ components:
fileName:
type: string
description: The file name to be processed
isFromApplicationsApi:
type: boolean
description: It indicates that the message comes from Applications Api or not
required:
- directory
- fileName
Expand Down Expand Up @@ -382,9 +376,6 @@ components:
type: string
maxLength: 255
description: Error description. Only populated if `status` is `FAILED`
isFromApplicationsApi:
type: boolean
description: It indicates that the message comes from Applications Api or not
required:
- requestId
- timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class CertificateMapperTest {
printRequests = mutableListOf(printRequest),
status = Status.PENDING_ASSIGNMENT_TO_BATCH,
photoLocationArn = photoLocation,
isFromApplicationsApi = null,
)
}

Expand Down Expand Up @@ -213,6 +214,94 @@ class CertificateMapperTest {
printRequests = mutableListOf(printRequest),
status = Status.PENDING_ASSIGNMENT_TO_BATCH,
photoLocationArn = photoLocation,
isFromApplicationsApi = null,
)
}

// When
val actual = mapper.toCertificate(message, ero)

// Then
assertThat(actual).usingRecursiveComparison().isEqualTo(expected)
verify(sourceTypeMapper).mapSqsToEntity(SourceTypeModel.VOTER_MINUS_CARD)
verify(idFactory).vacNumber()
verify(printRequestMapper).toPrintRequest(message, ero)
verify(instantMapper).toInstant(message.applicationReceivedDateTime)
}

@Test
fun `should map send application to print message for a Certificate from the Applications API`() {
// Given
val ero = buildEroDto(
welshContactDetails = null
)
val message = buildSendApplicationToPrintMessage(isFromApplicationsApi = true)
val requestId = aValidRequestId()
val vacNumber = aValidVacNumber()
given(sourceTypeMapper.mapSqsToEntity(any())).willReturn(SourceTypeEntity.VOTER_CARD)
given(idFactory.vacNumber()).willReturn(vacNumber)
given(instantMapper.toInstant(any())).willReturn(message.applicationReceivedDateTime.toInstant())

val englishEro = ero.englishContactDetails.toElectoralRegistrationOffice(ero.englishContactDetails.name)

val printRequest = with(message) {
PrintRequest(
requestDateTime = requestDateTime.toInstant(),
requestId = requestId,
firstName = firstName,
middleNames = middleNames,
surname = surname,
certificateLanguage = CertificateLanguageEntity.EN,
delivery = with(delivery) {
Delivery(
addressee = addressee,
address = with(address) {
Address(
street = street,
postcode = postcode,
property = property,
locality = locality,
town = town,
area = area,
uprn = uprn
)
},
deliveryClass = DeliveryClass.STANDARD,
deliveryAddressType = DeliveryAddressType.REGISTERED,
collectionReason = null,
addressFormat = AddressFormat.UK,
)
},
eroEnglish = englishEro,
eroWelsh = null,
statusHistory = mutableListOf(
PrintRequestStatus(
status = Status.PENDING_ASSIGNMENT_TO_BATCH,
dateCreated = FIXED_TIME,
eventDateTime = FIXED_TIME
)
),
userId = userId,
)
}
given(printRequestMapper.toPrintRequest(any(), any())).willReturn(printRequest)

val expected = with(message) {
Certificate(
id = null,
sourceReference = sourceReference,
applicationReference = applicationReference,
sourceType = SourceTypeEntity.VOTER_CARD,
vacNumber = vacNumber,
applicationReceivedDateTime = applicationReceivedDateTime.toInstant(),
gssCode = gssCode,
issuingAuthority = ero.englishContactDetails.name,
issuingAuthorityCy = null,
issueDate = LocalDate.now(),
printRequests = mutableListOf(printRequest),
status = Status.PENDING_ASSIGNMENT_TO_BATCH,
photoLocationArn = photoLocation,
isFromApplicationsApi = true,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ internal class ProcessPrintRequestBatchMessageListenerIntegrationTest : Integrat
)
)
)
)
),
isFromApplicationsApi = isFromApplicationsApi
)
certificate = certificateRepository.save(certificate)
TestTransaction.flagForCommit()
Expand All @@ -79,7 +80,7 @@ internal class ProcessPrintRequestBatchMessageListenerIntegrationTest : Integrat
assertThat(filterListForName(batchId)).isEmpty()

// add message to queue for processing
val payload = buildProcessPrintRequestBatchMessage(batchId = batchId, isFromApplicationsApi = isFromApplicationsApi)
val payload = buildProcessPrintRequestBatchMessage(batchId = batchId)

// When
TestTransaction.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package uk.gov.dluhc.printapi.messaging

import org.assertj.core.api.Assertions.assertThat
import org.awaitility.kotlin.await
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestInstance.Lifecycle
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource
import org.junit.jupiter.params.provider.NullSource
Expand All @@ -15,14 +13,12 @@ import uk.gov.dluhc.printapi.testsupport.testdata.entity.buildCertificate
import uk.gov.dluhc.printapi.testsupport.testdata.model.buildPrintResponses
import java.util.concurrent.TimeUnit

@TestInstance(Lifecycle.PER_CLASS)
internal class ProcessPrintResponseFileMessageListenerIntegrationTest : IntegrationTest() {

// @Test
@ParameterizedTest
@NullSource
@CsvSource("true", "false")
fun `should fetch remote print response file and send message to application api`(isFromApplicationsApi: Boolean?) {
fun `should fetch remote print response file and send message to source api`(isFromApplicationsApi: Boolean?) {
// Given
val filenameToProcess = "status-20220928235441999.json"
val printResponses = buildPrintResponses()
Expand All @@ -31,7 +27,8 @@ internal class ProcessPrintResponseFileMessageListenerIntegrationTest : Integrat
val certificates = printResponses.batchResponses.map {
buildCertificate(
status = PrintRequestStatus.Status.SENT_TO_PRINT_PROVIDER,
batchId = it.batchId
batchId = it.batchId,
isFromApplicationsApi = isFromApplicationsApi
)
}
certificateRepository.saveAll(certificates)
Expand All @@ -41,7 +38,6 @@ internal class ProcessPrintResponseFileMessageListenerIntegrationTest : Integrat
val message = ProcessPrintResponseFileMessage(
directory = PRINT_RESPONSE_DOWNLOAD_PATH,
fileName = filenameToProcess,
isFromApplicationsApi = isFromApplicationsApi,
)

// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ internal class ProcessPrintResponseMessageListenerIntegrationTest : IntegrationT
)
)
)
)
),
isFromApplicationsApi = isFromApplicationsApi
)
certificateRepository.save(certificate)

Expand All @@ -65,7 +66,6 @@ internal class ProcessPrintResponseMessageListenerIntegrationTest : IntegrationT
status = ProcessPrintResponseMessage.Status.SUCCESS,
statusStep = ProcessPrintResponseMessage.StatusStep.IN_MINUS_PRODUCTION,
message = printResponse.message,
isFromApplicationsApi = isFromApplicationsApi
)

// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ fun buildCertificate(
initialRetentionRemovalDate: LocalDate? = null,
initialRetentionDataRemoved: Boolean = false,
finalRetentionRemovalDate: LocalDate? = null,
isFromApplicationsApi: Boolean? = null,
): Certificate {
val certificate = Certificate(
id = if (persisted) randomUUID() else null,
Expand All @@ -89,6 +90,7 @@ fun buildCertificate(
finalRetentionRemovalDate = finalRetentionRemovalDate,
dateCreated = if (persisted) Instant.now() else null,
createdBy = if (persisted) "system" else null,
isFromApplicationsApi = isFromApplicationsApi,
)
printRequests.forEach { printRequest -> certificate.addPrintRequest(printRequest) }
return certificate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import uk.gov.dluhc.printapi.testsupport.testdata.aValidBatchId

fun buildProcessPrintRequestBatchMessage(
batchId: String = aValidBatchId(),
isFromApplicationsApi: Boolean? = null,
) = ProcessPrintRequestBatchMessage(
batchId = batchId,
isFromApplicationsApi = isFromApplicationsApi,
)

0 comments on commit 7555a9f

Please sign in to comment.