Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI-1585 Added person arrived and departed messages #2450

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class DataLoader(
ContactTypeGenerator.EACA_CONTACT_TYPE,
ContactTypeGenerator.EACO_CONTACT_TYPE,
ContactTypeGenerator.EABP_CONTACT_TYPE,
ContactTypeGenerator.EAAR_CONTACT_TYPE,
ContactTypeGenerator.EADP_CONTACT_TYPE,
PersonGenerator.PERSON_CRN,
PersonGenerator.generatePersonManager(PersonGenerator.PERSON_CRN)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ object ContactTypeGenerator {
"EABP",
false
)
val EADP_CONTACT_TYPE = ContactType(
IdGenerator.getAndIncrement(),
"EADP",
false
)
val EAAR_CONTACT_TYPE = ContactType(
IdGenerator.getAndIncrement(),
"EAAR",
false
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"eventType": "accommodation.cas3.person.arrived",
"version": 1,
"description": "A cas3 person has arrived",
"detailUrl": "http://localhost:{wiremock.port}/cas3-api/events/person-arrived/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,18 @@
{
"eventType": "accommodation.cas3.person.departed",
"version": 1,
"description": "A cas3 person departed",
"detailUrl": "http://localhost:{wiremock.port}/cas3-api/events/person-departed/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.person-arrived",
"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",
"arrivedAt": "2022-11-30T12:00:00",
"notes": "person arrived"
}
}
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.person-departed ",
"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",
"departedAt": "2022-11-30T12:00:00",
"notes": "Person departed."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"status": 200,
"bodyFileName": "cas3-booking-confirmed.json"
}
}
,
},
{
"request": {
"method": "GET",
Expand All @@ -52,6 +51,32 @@
"status": 200,
"bodyFileName": "cas3-booking-provisionally-made.json"
}
},
{
"request": {
"method": "GET",
"urlPath": "/cas3-api/events/person-arrived/1234"
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 200,
"bodyFileName": "cas3-person-arrived.json"
}
},
{
"request": {
"method": "GET",
"urlPath": "/cas3-api/events/person-departed/1234"
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 200,
"bodyFileName": "cas3-person-departed.json"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,36 @@ internal class CASIntegrationTest {

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EABP"))
}

@Test
fun `person arrived message is processed correctly`() {
val event = prepEvent("person-arrived", 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("urn:hmpps:cas3:person-arrived:14c80733-4b6d-4f35-b724-66955aac320e")

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EAAR"))
}

@Test
fun `person departed message is processed correctly`() {
val event = prepEvent("person-departed", 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("urn:hmpps:cas3:person-departed:14c80733-4b6d-4f35-b724-66955aac320e")

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EADP"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ interface Cas3ApiClient {

@GetMapping
fun getBookingProvisionallyMade(uri: URI): EventDetails<BookingProvisional>

@GetMapping
fun getPersonArrived(uri: URI): EventDetails<PersonArrived>

@GetMapping
fun getPersonDeparted(uri: URI): EventDetails<PersonDeparted>
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package uk.gov.justice.digital.hmpps.integrations.approvedpremesis

import uk.gov.justice.digital.hmpps.datetime.DeliusDateFormatter
import uk.gov.justice.digital.hmpps.integrations.delius.entity.ContactType
import java.time.ZonedDateTime

data class EventDetails<T>(
data class EventDetails<out T : Cas3Event>(
val id: String,
val timestamp: ZonedDateTime,
val eventType: String,
Expand All @@ -11,8 +13,16 @@ data class EventDetails<T>(

data class ApplicationSubmitted(
val applicationId: String
) {
val urn = "urn:hmpps:cas3:application-submitted:$applicationId"
) : Cas3Event {
override val urn = "urn:hmpps:cas3:application-submitted:$applicationId"
override val contactTypeCode = ContactType.REFERRAL_SUBMITTED
override val noteText = ""
}

interface Cas3Event {
val urn: String
val noteText: String
val contactTypeCode: String
}

data class BookingCancelled(
Expand All @@ -22,8 +32,10 @@ data class BookingCancelled(
val bookingUrl: String,
val cancellationReason: String,
val cancellationContext: String?
) {
val urn = "urn:hmpps:cas3:booking-cancelled:$bookingId"
) : Cas3Event {
override val urn = "urn:hmpps:cas3:booking-cancelled:$bookingId"
override val noteText = "$cancellationReason $cancellationContext $bookingUrl"
override val contactTypeCode = ContactType.BOOKING_CANCELLED
}

data class BookingProvisional(
Expand All @@ -33,8 +45,10 @@ data class BookingProvisional(
val bookingUrl: String,
val expectedArrivedAt: ZonedDateTime,
val notes: String
) {
val urn = "urn:hmpps:cas3:booking-provisionally-made:$bookingId"
) : Cas3Event {
override val urn = "urn:hmpps:cas3:booking-provisionally-made:$bookingId"
override val noteText = "${DeliusDateFormatter.format(expectedArrivedAt)} $notes $bookingUrl"
override val contactTypeCode = ContactType.BOOKING_PROVISIONAL
}

data class BookingConfirmed(
Expand All @@ -44,6 +58,34 @@ data class BookingConfirmed(
val bookingUrl: String,
val expectedArrivedAt: ZonedDateTime,
val notes: String
) {
val urn = "urn:hmpps:cas3:booking-confirmed:$bookingId"
) : Cas3Event {
override val urn = "urn:hmpps:cas3:booking-confirmed:$bookingId"
override val noteText = "${DeliusDateFormatter.format(expectedArrivedAt)} $notes $bookingUrl"
override val contactTypeCode = ContactType.BOOKING_CONFIRMED
}

data class PersonArrived(
val applicationId: String?,
val applicationUrl: String?,
val bookingId: String,
val bookingUrl: String,
val arrivedAt: ZonedDateTime,
val notes: String
) : Cas3Event {
override val urn = "urn:hmpps:cas3:person-arrived:$bookingId"
override val noteText = "${DeliusDateFormatter.format(arrivedAt)} $notes $bookingUrl"
override val contactTypeCode = ContactType.PERSON_ARRIVED
}

data class PersonDeparted(
val applicationId: String?,
val applicationUrl: String?,
val bookingId: String,
val bookingUrl: String,
val departedAt: ZonedDateTime,
val notes: String
) : Cas3Event {
override val urn = "urn:hmpps:cas3:person-departed:$bookingId"
override val noteText = "${DeliusDateFormatter.format(departedAt)} $notes $bookingUrl"
override val contactTypeCode = ContactType.PERSON_DEPARTED
}
Loading
Loading