From 741930420e36da62300402f784023fe2c79e68ee Mon Sep 17 00:00:00 2001 From: stevomcallister Date: Wed, 25 Oct 2023 15:41:54 +0100 Subject: [PATCH] PI-1585 Added person arrived and departed messages --- .../justice/digital/hmpps/data/DataLoader.kt | 2 + .../data/generator/ContactTypeGenerator.kt | 10 ++ .../resources/messages/person-arrived.json | 18 ++++ .../resources/messages/person-departed.json | 18 ++++ .../__files/cas3-person-arrived.json | 17 ++++ .../__files/cas3-person-departed.json | 17 ++++ .../simulations/mappings/cas3-api.json | 29 +++++- .../digital/hmpps/CASIntegrationTest.kt | 32 ++++++ .../approvedpremesis/Cas3ApiClient.kt | 6 ++ .../approvedpremesis/EventDetails.kt | 60 ++++++++++-- .../integrations/delius/ContactService.kt | 98 +++---------------- .../integrations/delius/entity/Contact.kt | 2 + .../delius/entity/PersonManager.kt | 2 +- .../digital/hmpps/messaging/Handler.kt | 38 ++++++- .../data/generator/CourtCaseNoteGenerator.kt | 1 - .../hmpps/data/generator/PersonGenerator.kt | 2 +- .../delius/contact/entity/CaseNote.kt | 3 - .../delius/person/entity/PersonManager.kt | 5 +- .../service/DeliusIntegrationService.kt | 1 - 19 files changed, 252 insertions(+), 109 deletions(-) create mode 100644 projects/cas3-and-delius/src/dev/resources/messages/person-arrived.json create mode 100644 projects/cas3-and-delius/src/dev/resources/messages/person-departed.json create mode 100644 projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-person-arrived.json create mode 100644 projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-person-departed.json 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 967c4b41f6..3d6d9dad45 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 @@ -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) ) 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 6cfbde6d8c..45546b90f4 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 @@ -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 + ) } diff --git a/projects/cas3-and-delius/src/dev/resources/messages/person-arrived.json b/projects/cas3-and-delius/src/dev/resources/messages/person-arrived.json new file mode 100644 index 0000000000..5d78e6de15 --- /dev/null +++ b/projects/cas3-and-delius/src/dev/resources/messages/person-arrived.json @@ -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" + } + ] + } +} \ No newline at end of file diff --git a/projects/cas3-and-delius/src/dev/resources/messages/person-departed.json b/projects/cas3-and-delius/src/dev/resources/messages/person-departed.json new file mode 100644 index 0000000000..ed279e101e --- /dev/null +++ b/projects/cas3-and-delius/src/dev/resources/messages/person-departed.json @@ -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" + } + ] + } +} \ No newline at end of file diff --git a/projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-person-arrived.json b/projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-person-arrived.json new file mode 100644 index 0000000000..43aa19ebcc --- /dev/null +++ b/projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-person-arrived.json @@ -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" + } +} \ No newline at end of file diff --git a/projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-person-departed.json b/projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-person-departed.json new file mode 100644 index 0000000000..181b6df54e --- /dev/null +++ b/projects/cas3-and-delius/src/dev/resources/simulations/__files/cas3-person-departed.json @@ -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." + } +} \ 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 ecda31593d..fafce4c948 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 @@ -38,8 +38,7 @@ "status": 200, "bodyFileName": "cas3-booking-confirmed.json" } - } - , + }, { "request": { "method": "GET", @@ -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" + } } ] } \ 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 d8dcaa5196..aa92dc3597 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 @@ -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")) + } } 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 61e83c6a5f..736da54391 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 @@ -22,4 +22,10 @@ interface Cas3ApiClient { @GetMapping fun getBookingProvisionallyMade(uri: URI): EventDetails + + @GetMapping + fun getPersonArrived(uri: URI): EventDetails + + @GetMapping + fun getPersonDeparted(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 69bf6e2c2a..1f40403fbd 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 @@ -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( +data class EventDetails( val id: String, val timestamp: ZonedDateTime, val eventType: String, @@ -11,8 +13,16 @@ data class EventDetails( 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( @@ -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( @@ -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( @@ -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 } 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 aa299f11cc..20b6b0503c 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 @@ -4,22 +4,15 @@ import org.springframework.stereotype.Service import uk.gov.justice.digital.hmpps.audit.service.AuditableService import uk.gov.justice.digital.hmpps.audit.service.AuditedInteractionService import uk.gov.justice.digital.hmpps.exception.NotFoundException -import uk.gov.justice.digital.hmpps.integrations.approvedpremesis.Cas3ApiClient +import uk.gov.justice.digital.hmpps.integrations.approvedpremesis.Cas3Event +import uk.gov.justice.digital.hmpps.integrations.approvedpremesis.EventDetails import uk.gov.justice.digital.hmpps.integrations.delius.audit.BusinessInteractionCode 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 import uk.gov.justice.digital.hmpps.integrations.delius.entity.PersonRepository import uk.gov.justice.digital.hmpps.integrations.delius.entity.getByCrn -import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent -import uk.gov.justice.digital.hmpps.messaging.crn -import uk.gov.justice.digital.hmpps.messaging.url -import uk.gov.justice.digital.hmpps.telemetry.TelemetryService import java.time.ZonedDateTime @Service @@ -28,85 +21,26 @@ class ContactService( private val personRepository: PersonRepository, private val personManagerRepository: PersonManagerRepository, private val contactRepository: ContactRepository, - private val contactTypeRepository: ContactTypeRepository, - private val telemetryService: TelemetryService, - private val cas3ApiClient: Cas3ApiClient + private val contactTypeRepository: ContactTypeRepository ) : AuditableService(auditedInteractionService) { - fun createReferralSubmitted(event: HmppsDomainEvent) { - val details = cas3ApiClient.getApplicationSubmittedDetails(event.url()).eventDetails - val crn = event.crn() - val externalReference = details.urn - - if (contactRepository.getByExternalReference(externalReference) != null) { - telemetryService.trackEvent("Duplicate ApplicationSubmitted event received for crn $crn") - } else { - createContact( - event.occurredAt, - crn, - "", - REFERRAL_SUBMITTED, - externalReference + fun createContact( + crn: String, + getEvent: () -> EventDetails + ) = audit(BusinessInteractionCode.UPDATE_CONTACT) { + val event = getEvent() + val person = personRepository.getByCrn(crn) + contactRepository.save( + newContact( + event.timestamp, + person.id, + event.eventDetails.contactTypeCode, + event.eventDetails.urn, + event.eventDetails.noteText ) - } - } - - fun createBookingCancelled(event: HmppsDomainEvent) { - val details = cas3ApiClient.getBookingCancelledDetails(event.url()).eventDetails - val crn = event.crn() - createContact( - event.occurredAt, - crn, - "${details.cancellationReason} ${details.cancellationContext} ${details.bookingUrl}", - BOOKING_CANCELLED, - details.urn - ) - } - - fun createBookingConfirmed(event: HmppsDomainEvent) { - val details = cas3ApiClient.getBookingConfirmedDetails(event.url()).eventDetails - val crn = event.crn() - createContact( - event.occurredAt, - crn, - "${details.expectedArrivedAt} ${details.notes} ${details.bookingUrl}", - BOOKING_CONFIRMED, - details.urn ) } - fun createBookingProvisionallyMade(event: HmppsDomainEvent) { - val crn = event.crn() - val details = cas3ApiClient.getBookingProvisionallyMade(event.url()).eventDetails - createContact( - event.occurredAt, - crn, - "${details.expectedArrivedAt} ${details.notes} ${details.bookingUrl}", - BOOKING_PROVISIONAL, - details.urn - ) - } - - fun createContact( - contactDate: ZonedDateTime, - crn: String, - notes: String, - contactTypeCode: String, - externalReference: String - ) = - audit(BusinessInteractionCode.UPDATE_CONTACT) { - val person = personRepository.getByCrn(crn) - contactRepository.save( - newContact( - contactDate, - person.id, - contactTypeCode, - externalReference, - notes - ) - ) - } - fun newContact( occurredAt: ZonedDateTime, personId: Long, 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 7c9883c9f0..1684e83cd6 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 @@ -113,6 +113,8 @@ class ContactType( const val BOOKING_CANCELLED = "EACA" const val BOOKING_CONFIRMED = "EACO" const val BOOKING_PROVISIONAL = "EABP" + const val PERSON_ARRIVED = "EAAR" + const val PERSON_DEPARTED = "EADP" } } diff --git a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/PersonManager.kt b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/PersonManager.kt index 63eff226cb..41b07ff700 100644 --- a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/PersonManager.kt +++ b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/PersonManager.kt @@ -17,7 +17,7 @@ class PersonManager( @Column(name = "offender_id") val personId: Long, - @Column(name = "provider_team_id") + @Column(name = "team_id") val teamId: Long, @Column(name = "allocation_staff_id") 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 29f7c9db6b..9ff73b06f1 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 @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.messaging import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.integrations.approvedpremesis.Cas3ApiClient import uk.gov.justice.digital.hmpps.integrations.delius.ContactService import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification @@ -13,29 +14,55 @@ import java.net.URI class Handler( override val converter: NotificationConverter, private val telemetryService: TelemetryService, - private val contactService: ContactService + private val contactService: ContactService, + private val cas3ApiClient: Cas3ApiClient ) : NotificationHandler { override fun handle(notification: Notification) { telemetryService.notificationReceived(notification) val event = notification.message when (event.eventType) { "accommodation.cas3.referral.submitted" -> { - contactService.createReferralSubmitted(event) + contactService.createContact(event.crn()) { + cas3ApiClient.getApplicationSubmittedDetails(event.url()) + } telemetryService.trackEvent("ApplicationSubmitted", event.telemetryProperties()) } + "accommodation.cas3.booking.cancelled" -> { - contactService.createBookingCancelled(event) + contactService.createContact(event.crn()) { + cas3ApiClient.getBookingCancelledDetails(event.url()) + } telemetryService.trackEvent("ApplicationSubmitted", event.telemetryProperties()) } + "accommodation.cas3.booking.confirmed" -> { - contactService.createBookingConfirmed(event) + contactService.createContact(event.crn()) { + cas3ApiClient.getBookingConfirmedDetails(event.url()) + } telemetryService.trackEvent("ApplicationSubmitted", event.telemetryProperties()) } + "accommodation.cas3.booking.provisionally-made" -> { - contactService.createBookingProvisionallyMade(event) + contactService.createContact(event.crn()) { + cas3ApiClient.getBookingProvisionallyMade(event.url()) + } telemetryService.trackEvent("ApplicationSubmitted", event.telemetryProperties()) } + "accommodation.cas3.person.arrived" -> { + contactService.createContact(event.crn()) { + cas3ApiClient.getPersonArrived(event.url()) + } + telemetryService.trackEvent("PersonArrived", event.telemetryProperties()) + } + + "accommodation.cas3.person.departed" -> { + contactService.createContact(event.crn()) { + cas3ApiClient.getPersonDeparted(event.url()) + } + telemetryService.trackEvent("PersonDeparted", event.telemetryProperties()) + } + else -> throw IllegalArgumentException("Unexpected event type ${event.eventType}") } } @@ -45,6 +72,7 @@ class Handler( "crn" to crn() ) } + fun HmppsDomainEvent.crn(): String = personReference.findCrn() ?: throw IllegalArgumentException("Missing CRN") fun HmppsDomainEvent.url(): URI = URI.create(detailUrl ?: throw IllegalArgumentException("Missing detail url")) diff --git a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CourtCaseNoteGenerator.kt b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CourtCaseNoteGenerator.kt index fa740fe4f9..9ee01b0373 100644 --- a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CourtCaseNoteGenerator.kt +++ b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CourtCaseNoteGenerator.kt @@ -14,7 +14,6 @@ object CourtCaseNoteGenerator { LocalDate.now(), ZonedDateTime.now(), StaffGenerator.ALLOCATED.id, - StaffGenerator.ALLOCATED.id, 1, 1, lastModifiedDateTime = ZonedDateTime.now().minusMinutes(1) diff --git a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt index 39a7fd0096..f18c0d936b 100644 --- a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt +++ b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt @@ -13,5 +13,5 @@ object PersonGenerator { Person(crn, softDeleted, id) fun generatePersonManager(person: Person) = - PersonManager(IdGenerator.getAndIncrement(), person.id, 1, StaffGenerator.ALLOCATED.id, StaffGenerator.ALLOCATED.id, 1) + PersonManager(IdGenerator.getAndIncrement(), person.id, 1, StaffGenerator.ALLOCATED.id, 1) } diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/contact/entity/CaseNote.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/contact/entity/CaseNote.kt index 53363700c9..dc9607f370 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/contact/entity/CaseNote.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/contact/entity/CaseNote.kt @@ -52,9 +52,6 @@ class CaseNote( @Column(updatable = false) val staffId: Long, - @Column(updatable = false) - val staffEmployeeId: Long, - @Column(updatable = false) val teamId: Long, diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/entity/PersonManager.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/entity/PersonManager.kt index 8c035a2bf0..21247af26c 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/entity/PersonManager.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/entity/PersonManager.kt @@ -15,15 +15,12 @@ class PersonManager( @Column(name = "offender_id") val personId: Long, - @Column(name = "provider_team_id") + @Column(name = "team_id") val teamId: Long, @Column(name = "allocation_staff_id") val staffId: Long, - @Column(name = "provider_employee_id") - val staffEmployeeId: Long, - @Column(name = "probation_area_id") val probationAreaId: Long, diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/DeliusIntegrationService.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/DeliusIntegrationService.kt index 8a4fb60f58..e7cbe4b328 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/DeliusIntegrationService.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/DeliusIntegrationService.kt @@ -85,7 +85,6 @@ class DeliusIntegrationService( probationAreaId = comDetails.probationAreaId, teamId = comDetails.teamId, staffId = comDetails.staffId, - staffEmployeeId = comDetails.staffEmployeeId, externalReference = reference ) }