Skip to content

Commit

Permalink
PI-1581 added booking provisionally confirmed processing
Browse files Browse the repository at this point in the history
  • Loading branch information
stevomcallister committed Oct 25, 2023
1 parent 47cd02e commit 8f395ac
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ object ContactTypeGenerator {
"EACO",
false
)
val EABP_CONTACT_TYPE = ContactType(
IdGenerator.getAndIncrement(),
"EABP",
false
)
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -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."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ import java.net.URI
configuration = [FeignOAuth2Config::class]
)
interface Cas3ApiClient {
@GetMapping fun getApplicationSubmittedDetails(uri: URI): EventDetails<ApplicationSubmitted>
@GetMapping
fun getApplicationSubmittedDetails(uri: URI): EventDetails<ApplicationSubmitted>

@GetMapping fun getBookingCancelledDetails(uri: URI): EventDetails<BookingCancelled>
@GetMapping
fun getBookingCancelledDetails(uri: URI): EventDetails<BookingCancelled>

@GetMapping fun getBookingConfirmedDetails(uri: URI): EventDetails<BookingConfirmed>
@GetMapping
fun getBookingConfirmedDetails(uri: URI): EventDetails<BookingProvisionalOrConfirmed>

@GetMapping
fun getBookingProvisionallyMade(uri: URI): EventDetails<BookingProvisionalOrConfirmed>
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ data class ApplicationSubmitted(
)

data class BookingCancelled(
val applicationId: String,
val applicationId: String?,
val applicationUrl: String?,
val bookingId: String,
val bookingUrl: String,
val cancellationReason: String,
val cancellationContext: String?
)

data class BookingConfirmed(
val applicationId: String,
data class BookingProvisionalOrConfirmed(
val applicationId: String?,
val applicationUrl: String?,
val bookingId: String,
val bookingUrl: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
Expand Down

0 comments on commit 8f395ac

Please sign in to comment.