Skip to content

Commit

Permalink
PI-1581 updated external reference to be urn (#2449)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevomcallister authored Oct 25, 2023
1 parent d12e95b commit 57967e1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class CASIntegrationTest {
Mockito.verify(telemetryService).notificationReceived(event)

val contact =
contactRepository.getByExternalReference(event.message.additionalInformation["applicationId"] as String)
contactRepository.getByExternalReference("urn:hmpps:cas3:application-submitted:${event.message.additionalInformation["applicationId"] as String}")

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EARS"))
}
Expand All @@ -64,7 +64,7 @@ internal class CASIntegrationTest {
Mockito.verify(telemetryService).notificationReceived(event)

val contact =
contactRepository.getByExternalReference("14c80733-4b6d-4f35-b724-66955aac320c")
contactRepository.getByExternalReference("urn:hmpps:cas3:booking-cancelled:14c80733-4b6d-4f35-b724-66955aac320c")

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EACA"))
}
Expand All @@ -80,7 +80,7 @@ internal class CASIntegrationTest {
Mockito.verify(telemetryService).notificationReceived(event)

val contact =
contactRepository.getByExternalReference("14c80733-4b6d-4f35-b724-66955aac320d")
contactRepository.getByExternalReference("urn:hmpps:cas3:booking-confirmed:14c80733-4b6d-4f35-b724-66955aac320d")

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EACO"))
}
Expand All @@ -96,7 +96,7 @@ internal class CASIntegrationTest {
Mockito.verify(telemetryService).notificationReceived(event)

val contact =
contactRepository.getByExternalReference("14c80733-4b6d-4f35-b724-66955aac320e")
contactRepository.getByExternalReference("urn:hmpps:cas3:booking-provisionally-made:14c80733-4b6d-4f35-b724-66955aac320e")

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EABP"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ interface Cas3ApiClient {
fun getBookingCancelledDetails(uri: URI): EventDetails<BookingCancelled>

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

@GetMapping
fun getBookingProvisionallyMade(uri: URI): EventDetails<BookingProvisionalOrConfirmed>
fun getBookingProvisionallyMade(uri: URI): EventDetails<BookingProvisional>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ data class EventDetails<T>(

data class ApplicationSubmitted(
val applicationId: String
)
) {
val urn = "urn:hmpps:cas3:application-submitted:$applicationId"
}

data class BookingCancelled(
val applicationId: String?,
Expand All @@ -20,13 +22,28 @@ data class BookingCancelled(
val bookingUrl: String,
val cancellationReason: String,
val cancellationContext: String?
)
) {
val urn = "urn:hmpps:cas3:booking-cancelled:$bookingId"
}

data class BookingProvisionalOrConfirmed(
data class BookingProvisional(
val applicationId: String?,
val applicationUrl: String?,
val bookingId: String,
val bookingUrl: String,
val expectedArrivedAt: ZonedDateTime,
val notes: String
)
) {
val urn = "urn:hmpps:cas3:booking-provisionally-made:$bookingId"
}

data class BookingConfirmed(
val applicationId: String?,
val applicationUrl: String?,
val bookingId: String,
val bookingUrl: String,
val expectedArrivedAt: ZonedDateTime,
val notes: String
) {
val urn = "urn:hmpps:cas3:booking-confirmed:$bookingId"
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ContactService(
fun createReferralSubmitted(event: HmppsDomainEvent) {
val details = cas3ApiClient.getApplicationSubmittedDetails(event.url()).eventDetails
val crn = event.crn()
val externalReference = details.applicationId
val externalReference = details.urn

if (contactRepository.getByExternalReference(externalReference) != null) {
telemetryService.trackEvent("Duplicate ApplicationSubmitted event received for crn $crn")
Expand All @@ -54,39 +54,36 @@ class ContactService(
fun createBookingCancelled(event: HmppsDomainEvent) {
val details = cas3ApiClient.getBookingCancelledDetails(event.url()).eventDetails
val crn = event.crn()
val externalReference = details.bookingId
createContact(
event.occurredAt,
crn,
"${details.cancellationReason} ${details.cancellationContext} ${details.bookingUrl}",
BOOKING_CANCELLED,
externalReference
details.urn
)
}

fun createBookingConfirmed(event: HmppsDomainEvent) {
val details = cas3ApiClient.getBookingConfirmedDetails(event.url()).eventDetails
val crn = event.crn()
val externalReference = details.bookingId
createContact(
event.occurredAt,
crn,
"${details.expectedArrivedAt} ${details.notes} ${details.bookingUrl}",
BOOKING_CONFIRMED,
externalReference
details.urn
)
}

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
details.urn
)
}

Expand Down

0 comments on commit 57967e1

Please sign in to comment.