diff --git a/projects/cas3-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt b/projects/cas3-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt index f037aa3133..967c4b41f6 100644 --- a/projects/cas3-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt +++ b/projects/cas3-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt @@ -32,6 +32,7 @@ class DataLoader( ContactTypeGenerator.EARS_CONTACT_TYPE, ContactTypeGenerator.EACA_CONTACT_TYPE, ContactTypeGenerator.EACO_CONTACT_TYPE, + ContactTypeGenerator.EABP_CONTACT_TYPE, PersonGenerator.PERSON_CRN, PersonGenerator.generatePersonManager(PersonGenerator.PERSON_CRN) ) diff --git a/projects/cas3-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ContactTypeGenerator.kt b/projects/cas3-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ContactTypeGenerator.kt index c17d028a7b..6cfbde6d8c 100644 --- a/projects/cas3-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ContactTypeGenerator.kt +++ b/projects/cas3-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ContactTypeGenerator.kt @@ -18,4 +18,9 @@ object ContactTypeGenerator { "EACO", false ) + val EABP_CONTACT_TYPE = ContactType( + IdGenerator.getAndIncrement(), + "EABP", + false + ) } diff --git a/projects/cas3-and-delius/src/dev/resources/messages/booking-provisionally-made.json b/projects/cas3-and-delius/src/dev/resources/messages/booking-provisionally-made.json new file mode 100644 index 0000000000..c3f475ddef --- /dev/null +++ b/projects/cas3-and-delius/src/dev/resources/messages/booking-provisionally-made.json @@ -0,0 +1,18 @@ +{ + "eventType": "accommodation.cas3.booking.provisionally-made", + "version": 1, + "description": "A cas3 booking has been provisionally made", + "detailUrl": "http://localhost:{wiremock.port}/cas3-api/events/booking-provisionally-made/1234", + "occurredAt": "2022-12-04T10:42:43+00:00", + "additionalInformation": { + "applicationId": "68df9f6c-3fcb-4ec6-8fcf-96551cd9b080" + }, + "personReference": { + "identifiers": [ + { + "type": "CRN", + "value": "A000001" + } + ] + } +} \ No newline at end of file diff --git a/projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-booking-provisionally-made.json b/projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-booking-provisionally-made.json new file mode 100644 index 0000000000..7f9c907417 --- /dev/null +++ b/projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-booking-provisionally-made.json @@ -0,0 +1,17 @@ +{ + "id": "364145f9-0af8-488e-9901-b4c46cd9ba37", + "timestamp": "2022-11-30T14:53:44", + "eventType": "accommodation.cas3.booking.provisionally-made", + "eventDetails": { + "applicationId": "68df9f6c-3fcb-4ec6-8fcf-96551cd9b080", + "applicationUrl": "https://approved-premises-dev.hmpps.service.justice.gov.uk/booking/68df9f6c-3fcb-4ec6-8fcf-96551cd9b080", + "personReference": { + "crn": "A000001", + "noms": "A0001AA" + }, + "bookingId": "14c80733-4b6d-4f35-b724-66955aac320e", + "bookingUrl": "https://approved-premises-dev.hmpps.service.justice.gov.uk/someURLtoTheBooking", + "expectedArrivedAt": "2022-11-30T12:00:00", + "notes": "The actual time of arrival is unknown so has been defaulted to midday." + } +} \ No newline at end of file diff --git a/projects/cas3-and-delius/src/dev/resources/simulations/mappings/cas3-api.json b/projects/cas3-and-delius/src/dev/resources/simulations/mappings/cas3-api.json index bf145d28de..ecda31593d 100644 --- a/projects/cas3-and-delius/src/dev/resources/simulations/mappings/cas3-api.json +++ b/projects/cas3-and-delius/src/dev/resources/simulations/mappings/cas3-api.json @@ -39,5 +39,19 @@ "bodyFileName": "cas3-booking-confirmed.json" } } + , + { + "request": { + "method": "GET", + "urlPath": "/cas3-api/events/booking-provisionally-made/1234" + }, + "response": { + "headers": { + "Content-Type": "application/json" + }, + "status": 200, + "bodyFileName": "cas3-booking-provisionally-made.json" + } + } ] } \ No newline at end of file diff --git a/projects/cas3-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CASIntegrationTest.kt b/projects/cas3-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CASIntegrationTest.kt index 661b8bcbb3..03bc58fe1a 100644 --- a/projects/cas3-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CASIntegrationTest.kt +++ b/projects/cas3-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CASIntegrationTest.kt @@ -84,4 +84,20 @@ internal class CASIntegrationTest { MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EACO")) } + + @Test + fun `booking provisionally made message is processed correctly`() { + val event = prepEvent("booking-provisionally-made", wireMockServer.port()) + + // When it is received + channelManager.getChannel(queueName).publishAndWait(event) + + // Then it is logged to telemetry + Mockito.verify(telemetryService).notificationReceived(event) + + val contact = + contactRepository.getByExternalReference("14c80733-4b6d-4f35-b724-66955aac320e") + + MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EABP")) + } } diff --git a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/Cas3ApiClient.kt b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/Cas3ApiClient.kt index 5a024be19e..756df7281a 100644 --- a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/Cas3ApiClient.kt +++ b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/Cas3ApiClient.kt @@ -11,9 +11,15 @@ import java.net.URI configuration = [FeignOAuth2Config::class] ) interface Cas3ApiClient { - @GetMapping fun getApplicationSubmittedDetails(uri: URI): EventDetails + @GetMapping + fun getApplicationSubmittedDetails(uri: URI): EventDetails - @GetMapping fun getBookingCancelledDetails(uri: URI): EventDetails + @GetMapping + fun getBookingCancelledDetails(uri: URI): EventDetails - @GetMapping fun getBookingConfirmedDetails(uri: URI): EventDetails + @GetMapping + fun getBookingConfirmedDetails(uri: URI): EventDetails + + @GetMapping + fun getBookingProvisionallyMade(uri: URI): EventDetails } diff --git a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/EventDetails.kt b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/EventDetails.kt index 2ca4853a50..838406fafb 100644 --- a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/EventDetails.kt +++ b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremesis/EventDetails.kt @@ -14,7 +14,7 @@ data class ApplicationSubmitted( ) data class BookingCancelled( - val applicationId: String, + val applicationId: String?, val applicationUrl: String?, val bookingId: String, val bookingUrl: String, @@ -22,8 +22,8 @@ data class BookingCancelled( val cancellationContext: String? ) -data class BookingConfirmed( - val applicationId: String, +data class BookingProvisionalOrConfirmed( + val applicationId: String?, val applicationUrl: String?, val bookingId: String, val bookingUrl: String, diff --git a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/ContactService.kt b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/ContactService.kt index d5c34d3cf4..0566939a20 100644 --- a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/ContactService.kt +++ b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/ContactService.kt @@ -10,6 +10,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.entity.Contact import uk.gov.justice.digital.hmpps.integrations.delius.entity.ContactRepository import uk.gov.justice.digital.hmpps.integrations.delius.entity.ContactType.Companion.BOOKING_CANCELLED import uk.gov.justice.digital.hmpps.integrations.delius.entity.ContactType.Companion.BOOKING_CONFIRMED +import uk.gov.justice.digital.hmpps.integrations.delius.entity.ContactType.Companion.BOOKING_PROVISIONAL import uk.gov.justice.digital.hmpps.integrations.delius.entity.ContactType.Companion.REFERRAL_SUBMITTED import uk.gov.justice.digital.hmpps.integrations.delius.entity.ContactTypeRepository import uk.gov.justice.digital.hmpps.integrations.delius.entity.PersonManagerRepository @@ -76,6 +77,19 @@ class ContactService( ) } + fun createBookingProvisionallyMade(event: HmppsDomainEvent) { + val crn = event.crn() + val details = cas3ApiClient.getBookingProvisionallyMade(event.url()).eventDetails + val externalReference = details.bookingId + createContact( + event.occurredAt, + crn, + "${details.expectedArrivedAt} ${details.notes} ${details.bookingUrl}", + BOOKING_PROVISIONAL, + externalReference + ) + } + fun createContact( contactDate: ZonedDateTime, crn: String, diff --git a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Contact.kt b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Contact.kt index deea1e5bb1..059adb7d00 100644 --- a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Contact.kt +++ b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Contact.kt @@ -115,6 +115,7 @@ class ContactType( const val REFERRAL_SUBMITTED = "EARS" const val BOOKING_CANCELLED = "EACA" const val BOOKING_CONFIRMED = "EACO" + const val BOOKING_PROVISIONAL = "EABP" } } diff --git a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index eb14785b22..29f7c9db6b 100644 --- a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -31,6 +31,10 @@ class Handler( contactService.createBookingConfirmed(event) telemetryService.trackEvent("ApplicationSubmitted", event.telemetryProperties()) } + "accommodation.cas3.booking.provisionally-made" -> { + contactService.createBookingProvisionallyMade(event) + telemetryService.trackEvent("ApplicationSubmitted", event.telemetryProperties()) + } else -> throw IllegalArgumentException("Unexpected event type ${event.eventType}") }