Skip to content

Commit

Permalink
PI-1581 updated external reference to be urn
Browse files Browse the repository at this point in the history
  • Loading branch information
stevomcallister committed Oct 25, 2023
1 parent d12e95b commit 65e0cae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
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 @@ -21,12 +23,31 @@ data class BookingCancelled(
val cancellationReason: String,
val cancellationContext: String?
)
{
val urn = "urn:hmpps:cas3:booking-cancelled:$bookingId"
}

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-provisional:$bookingId"
}

data class BookingProvisionalOrConfirmed(
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 65e0cae

Please sign in to comment.