diff --git a/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/detail/DomainEventDetailService.kt b/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/detail/DomainEventDetailService.kt new file mode 100644 index 0000000000..ca89a90b38 --- /dev/null +++ b/libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/detail/DomainEventDetailService.kt @@ -0,0 +1,38 @@ +package uk.gov.justice.digital.hmpps.detail + +import org.springframework.beans.factory.annotation.Qualifier +import org.springframework.beans.factory.annotation.Value +import org.springframework.core.ParameterizedTypeReference +import org.springframework.http.ResponseEntity +import org.springframework.stereotype.Service +import org.springframework.web.client.RestClient +import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent +import java.net.URI + +@Service +class DomainEventDetailService( + @Qualifier("oauth2Client") val restClient: RestClient?, + @Value("\${messaging.consumer.detail.urls:#{null}}") val allowedUrls: List? +) { + fun validate(detailUrl: String?): URI { + val uri = URI.create(requireNotNull(detailUrl) { "Detail URL must not be null" }) + val baseUrl = "${uri.scheme}://${uri.authority}" + require(allowedUrls == null || allowedUrls!!.contains(baseUrl)) { "Unexpected detail URL: $baseUrl" } + return uri + } + + final inline fun getDetail(event: HmppsDomainEvent): T = + getDetail(validate(event.detailUrl), object : ParameterizedTypeReference() {}) + + final inline fun getDetail(detailUrl: String?): T = + getDetail(validate(detailUrl), object : ParameterizedTypeReference() {}) + + fun getDetail(uri: URI, type: ParameterizedTypeReference): T = + requireNotNull(restClient).get().uri(uri).retrieve().body(type)!! + + final inline fun getDetailResponse(event: HmppsDomainEvent): ResponseEntity = + getDetailResponse(validate(event.detailUrl), object : ParameterizedTypeReference() {}) + + fun getDetailResponse(uri: URI, type: ParameterizedTypeReference): ResponseEntity = + requireNotNull(restClient).get().uri(uri).retrieve().toEntity(type) +} \ No newline at end of file diff --git a/libs/messaging/src/test/kotlin/uk/gov/justice/digital/hmpps/detail/DomainEventDetailServiceTest.kt b/libs/messaging/src/test/kotlin/uk/gov/justice/digital/hmpps/detail/DomainEventDetailServiceTest.kt new file mode 100644 index 0000000000..1cb940755a --- /dev/null +++ b/libs/messaging/src/test/kotlin/uk/gov/justice/digital/hmpps/detail/DomainEventDetailServiceTest.kt @@ -0,0 +1,84 @@ +package uk.gov.justice.digital.hmpps.detail + +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Answers +import org.mockito.Mock +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.any +import org.mockito.kotlin.whenever +import org.springframework.core.ParameterizedTypeReference +import org.springframework.web.client.RestClient +import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent +import java.net.URI + +@ExtendWith(MockitoExtension::class) +internal class DomainEventDetailServiceTest { + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + lateinit var client: RestClient + + lateinit var service: DomainEventDetailService + + @BeforeEach + fun beforeEach() { + service = DomainEventDetailService(client, listOf("http://localhost:8080")) + } + + @Test + fun `missing URL is rejected`() { + val exception = assertThrows { + service.getDetail( + HmppsDomainEvent( + eventType = "test", + version = 1 + ) + ) + } + assertThat(exception.message, equalTo("Detail URL must not be null")) + } + + @Test + fun `invalid URL is rejected`() { + assertThrows { + service.getDetail( + HmppsDomainEvent( + eventType = "test", + version = 1, + detailUrl = "invalid url" + ) + ) + } + } + + @Test + fun `URL must be in allowed list`() { + val exception = assertThrows { + service.getDetail( + HmppsDomainEvent( + eventType = "test", + version = 1, + detailUrl = "https://example.com" + ) + ) + } + assertThat(exception.message, equalTo("Unexpected detail URL: https://example.com")) + } + + @Test + fun `API is called if URL is valid`() { + whenever(client.get().uri(any()).retrieve().body(any>())) + .thenReturn("API Response") + val response = service.getDetail( + HmppsDomainEvent( + eventType = "test", + version = 1, + detailUrl = "http://localhost:8080" + ) + ) + assertThat(response, equalTo("API Response")) + } +} \ No newline at end of file diff --git a/projects/approved-premises-and-delius/deploy/values-dev.yml b/projects/approved-premises-and-delius/deploy/values-dev.yml index 7410a2b55a..b1d098ba75 100644 --- a/projects/approved-premises-and-delius/deploy/values-dev.yml +++ b/projects/approved-premises-and-delius/deploy/values-dev.yml @@ -12,7 +12,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer - INTEGRATIONS_APPROVED-PREMISES-API_URL: https://approved-premises-api-dev.hmpps.service.justice.gov.uk + MESSAGING_CONSUMER_DETAIL_URLS: https://approved-premises-api-dev.hmpps.service.justice.gov.uk INTEGRATIONS_ALFRESCO_URL: https://hmpps-delius-alfresco-test.apps.live.cloud-platform.service.justice.gov.uk/alfresco/service/noms-spg/ EVENT_EXCEPTION_THROWNOTFOUND: false diff --git a/projects/approved-premises-and-delius/deploy/values-preprod.yml b/projects/approved-premises-and-delius/deploy/values-preprod.yml index 37fc625194..08a7924541 100644 --- a/projects/approved-premises-and-delius/deploy/values-preprod.yml +++ b/projects/approved-premises-and-delius/deploy/values-preprod.yml @@ -10,7 +10,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer - INTEGRATIONS_APPROVED-PREMISES-API_URL: https://approved-premises-api-preprod.hmpps.service.justice.gov.uk + MESSAGING_CONSUMER_DETAIL_URLS: https://approved-premises-api-preprod.hmpps.service.justice.gov.uk INTEGRATIONS_ALFRESCO_URL: https://alfresco.pre-prod.delius.probation.hmpps.dsd.io/alfresco/service/noms-spg/ generic-prometheus-alerts: diff --git a/projects/approved-premises-and-delius/deploy/values-prod.yml b/projects/approved-premises-and-delius/deploy/values-prod.yml index bac33db587..dae6444606 100644 --- a/projects/approved-premises-and-delius/deploy/values-prod.yml +++ b/projects/approved-premises-and-delius/deploy/values-prod.yml @@ -7,5 +7,5 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer - INTEGRATIONS_APPROVED-PREMISES-API_URL: https://approved-premises-api.hmpps.service.justice.gov.uk + MESSAGING_CONSUMER_DETAIL_URLS: https://approved-premises-api.hmpps.service.justice.gov.uk INTEGRATIONS_ALFRESCO_URL: https://alfresco.probation.service.justice.gov.uk/alfresco/service/noms-spg/ \ No newline at end of file diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt deleted file mode 100644 index 229e7073ae..0000000000 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt +++ /dev/null @@ -1,13 +0,0 @@ -package uk.gov.justice.digital.hmpps.config - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.client.RestClient -import uk.gov.justice.digital.hmpps.config.security.createClient -import uk.gov.justice.digital.hmpps.integrations.approvedpremises.ApprovedPremisesApiClient - -@Configuration -class RestClientConfig(private val oauth2Client: RestClient) { - @Bean - fun approvedPremisesApiClient() = createClient(oauth2Client) -} diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremises/ApprovedPremisesApiClient.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremises/ApprovedPremisesApiClient.kt deleted file mode 100644 index 462db2582e..0000000000 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/approvedpremises/ApprovedPremisesApiClient.kt +++ /dev/null @@ -1,33 +0,0 @@ -package uk.gov.justice.digital.hmpps.integrations.approvedpremises - -import org.springframework.web.service.annotation.GetExchange -import java.net.URI - -interface ApprovedPremisesApiClient { - @GetExchange - fun getApplicationSubmittedDetails(uri: URI): EventDetails - - @GetExchange - fun getApplicationAssessedDetails(uri: URI): EventDetails - - @GetExchange - fun getApplicationWithdrawnDetails(uri: URI): EventDetails - - @GetExchange - fun getBookingMadeDetails(uri: URI): EventDetails - - @GetExchange - fun getBookingChangedDetails(uri: URI): EventDetails - - @GetExchange - fun getBookingCancelledDetails(uri: URI): EventDetails - - @GetExchange - fun getPersonNotArrivedDetails(uri: URI): EventDetails - - @GetExchange - fun getPersonArrivedDetails(uri: URI): EventDetails - - @GetExchange - fun getPersonDepartedDetails(uri: URI): EventDetails -} diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index f614d74e33..346e17e355 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -15,7 +15,6 @@ import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.service.ApprovedPremisesService import uk.gov.justice.digital.hmpps.telemetry.TelemetryMessagingExtensions.notificationReceived import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI @Component @Channel("approved-premises-and-delius-queue") @@ -113,4 +112,3 @@ fun HmppsDomainEvent.telemetryProperties() = listOfNotNull( ).toMap() 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/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ApprovedPremisesService.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ApprovedPremisesService.kt index bc18bf0d7c..414d756572 100644 --- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ApprovedPremisesService.kt +++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/ApprovedPremisesService.kt @@ -1,7 +1,8 @@ package uk.gov.justice.digital.hmpps.service import org.springframework.stereotype.Service -import uk.gov.justice.digital.hmpps.integrations.approvedpremises.ApprovedPremisesApiClient +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService +import uk.gov.justice.digital.hmpps.integrations.approvedpremises.* import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.ApprovedPremisesRepository import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.getApprovedPremises import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.EventRepository @@ -14,11 +15,10 @@ import uk.gov.justice.digital.hmpps.integrations.delius.staff.getByCode import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.messaging.Notifier import uk.gov.justice.digital.hmpps.messaging.crn -import uk.gov.justice.digital.hmpps.messaging.url @Service class ApprovedPremisesService( - private val approvedPremisesApiClient: ApprovedPremisesApiClient, + private val detailService: DomainEventDetailService, private val approvedPremisesRepository: ApprovedPremisesRepository, private val staffRepository: StaffRepository, private val personRepository: PersonRepository, @@ -29,7 +29,7 @@ class ApprovedPremisesService( private val notifier: Notifier, ) { fun applicationSubmitted(event: HmppsDomainEvent) { - val details = approvedPremisesApiClient.getApplicationSubmittedDetails(event.url()).eventDetails + val details = detailService.getDetail>(event).eventDetails val person = personRepository.getByCrn(event.crn()) val dEvent = eventRepository.getEvent(person.id, details.eventNumber) contactService.createContact( @@ -47,7 +47,7 @@ class ApprovedPremisesService( } fun applicationAssessed(event: HmppsDomainEvent) { - val details = approvedPremisesApiClient.getApplicationAssessedDetails(event.url()).eventDetails + val details = detailService.getDetail>(event).eventDetails val person = personRepository.getByCrn(event.crn()) val dEvent = eventRepository.getEvent(person.id, details.eventNumber) contactService.createContact( @@ -65,7 +65,7 @@ class ApprovedPremisesService( } fun applicationWithdrawn(event: HmppsDomainEvent) { - val details = approvedPremisesApiClient.getApplicationWithdrawnDetails(event.url()).eventDetails + val details = detailService.getDetail>(event).eventDetails val person = personRepository.getByCrn(event.crn()) val dEvent = eventRepository.getEvent(person.id, details.eventNumber) contactService.createContact( @@ -85,25 +85,25 @@ class ApprovedPremisesService( } fun bookingMade(event: HmppsDomainEvent) { - val details = approvedPremisesApiClient.getBookingMadeDetails(event.url()).eventDetails + val details = detailService.getDetail>(event).eventDetails val ap = approvedPremisesRepository.getApprovedPremises(details.premises.legacyApCode) referralService.bookingMade(event.crn(), details, ap) } fun bookingChanged(event: HmppsDomainEvent) { - val details = approvedPremisesApiClient.getBookingChangedDetails(event.url()).eventDetails + val details = detailService.getDetail>(event).eventDetails val ap = approvedPremisesRepository.getApprovedPremises(details.premises.legacyApCode) referralService.bookingChanged(event.crn(), details, ap) } fun bookingCancelled(event: HmppsDomainEvent) { - val details = approvedPremisesApiClient.getBookingCancelledDetails(event.url()).eventDetails + val details = detailService.getDetail>(event).eventDetails val ap = approvedPremisesRepository.getApprovedPremises(details.premises.legacyApCode) referralService.bookingCancelled(event.crn(), details, ap) } fun personNotArrived(event: HmppsDomainEvent) { - val details = approvedPremisesApiClient.getPersonNotArrivedDetails(event.url()) + val details = detailService.getDetail>(event) val ap = approvedPremisesRepository.getApprovedPremises(details.eventDetails.premises.legacyApCode) referralService.personNotArrived( personRepository.getByCrn(event.crn()), @@ -114,7 +114,7 @@ class ApprovedPremisesService( } fun personArrived(event: HmppsDomainEvent) { - val details = approvedPremisesApiClient.getPersonArrivedDetails(event.url()).eventDetails + val details = detailService.getDetail>(event).eventDetails val person = personRepository.getByCrn(event.crn()) val ap = approvedPremisesRepository.getApprovedPremises(details.premises.legacyApCode) nsiService.personArrived(person, details, ap)?.let { (previousAddress, newAddress) -> @@ -124,7 +124,7 @@ class ApprovedPremisesService( } fun personDeparted(event: HmppsDomainEvent) { - val details = approvedPremisesApiClient.getPersonDepartedDetails(event.url()).eventDetails + val details = detailService.getDetail>(event).eventDetails val person = personRepository.getByCrn(event.crn()) val ap = approvedPremisesRepository.getApprovedPremises(details.premises.legacyApCode) nsiService.personDeparted(person, details, ap)?.let { updatedAddress -> diff --git a/projects/approved-premises-and-delius/src/main/resources/application.yml b/projects/approved-premises-and-delius/src/main/resources/application.yml index 746e313e16..7f173e1a52 100644 --- a/projects/approved-premises-and-delius/src/main/resources/application.yml +++ b/projects/approved-premises-and-delius/src/main/resources/application.yml @@ -61,12 +61,9 @@ spring: seed.database: true wiremock.enabled: true -messaging.consumer.queue: message-queue messaging.producer.topic: domain-events - -integrations: - approved-premises-api: - url: http://localhost:${wiremock.port}/approved-premises-api +messaging.consumer.queue: message-queue +messaging.consumer.detail.urls: http://localhost:${wiremock.port} oauth2: client-id: $SERVICE_NAME diff --git a/projects/approved-premises-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt b/projects/approved-premises-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt index b9c9b943c6..d8a17e42e3 100644 --- a/projects/approved-premises-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt +++ b/projects/approved-premises-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt @@ -38,13 +38,6 @@ internal class HandlerTest { handler = Handler(telemetryService, approvedPremisesService, converter, true) } - @Test - fun `throws when no detail url is provided`() { - val event = HmppsDomainEvent(eventType = "test", version = 1, occurredAt = ZonedDateTime.now()) - val exception = assertThrows { event.url() } - assertThat(exception.message, equalTo("Missing detail url")) - } - @Test fun `throws when no crn is provided`() { val event = HmppsDomainEvent(eventType = "test", version = 1, occurredAt = ZonedDateTime.now()) diff --git a/projects/approved-premises-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ApprovedPremisesServiceTest.kt b/projects/approved-premises-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ApprovedPremisesServiceTest.kt index 12ef8facb2..5c31e74bcc 100644 --- a/projects/approved-premises-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ApprovedPremisesServiceTest.kt +++ b/projects/approved-premises-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/ApprovedPremisesServiceTest.kt @@ -10,10 +10,12 @@ import org.mockito.Mock import org.mockito.Mockito.any import org.mockito.Mockito.verify import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.check import org.mockito.kotlin.whenever import org.springframework.boot.context.event.ApplicationStartedEvent import uk.gov.justice.digital.hmpps.data.generator.* +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exception.NotFoundException import uk.gov.justice.digital.hmpps.integrations.approvedpremises.* import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.ApprovedPremisesRepository @@ -42,7 +44,6 @@ import uk.gov.justice.digital.hmpps.integrations.delius.team.Team import uk.gov.justice.digital.hmpps.integrations.delius.team.TeamRepository import uk.gov.justice.digital.hmpps.messaging.Notifier import uk.gov.justice.digital.hmpps.messaging.crn -import uk.gov.justice.digital.hmpps.messaging.url import uk.gov.justice.digital.hmpps.prepEvent import uk.gov.justice.digital.hmpps.security.ServiceContext import uk.gov.justice.digital.hmpps.set @@ -53,7 +54,7 @@ import java.time.ZonedDateTime @ExtendWith(MockitoExtension::class) internal class ApprovedPremisesServiceTest { @Mock - lateinit var approvedPremisesApiClient: ApprovedPremisesApiClient + lateinit var domainEventDetailService: DomainEventDetailService @Mock lateinit var approvedPremisesRepository: ApprovedPremisesRepository @@ -189,7 +190,7 @@ internal class ApprovedPremisesServiceTest { eventRepository ) approvedPremisesService = ApprovedPremisesService( - approvedPremisesApiClient, + domainEventDetailService, approvedPremisesRepository, staffRepository, personRepository, @@ -469,9 +470,7 @@ internal class ApprovedPremisesServiceTest { submittedBy: SubmittedBy = SubmittedByGenerator.generate() ): EventDetails { val details = EventDetailsGenerator.applicationSubmitted(submittedBy = submittedBy) - whenever(approvedPremisesApiClient.getApplicationSubmittedDetails(applicationSubmittedEvent.url())).thenReturn( - details - ) + whenever(domainEventDetailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(details) return details } @@ -479,9 +478,7 @@ internal class ApprovedPremisesServiceTest { assessedBy: AssessedBy = AssessedByGenerator.generate() ): EventDetails { val details = EventDetailsGenerator.applicationAssessed(assessedBy = assessedBy) - whenever(approvedPremisesApiClient.getApplicationAssessedDetails(applicationAssessedEvent.url())).thenReturn( - details - ) + whenever(domainEventDetailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(details) return details } @@ -489,7 +486,7 @@ internal class ApprovedPremisesServiceTest { bookedBy: BookedBy = BookedByGenerator.generate() ): EventDetails { val details = EventDetailsGenerator.bookingMade(bookedBy = bookedBy) - whenever(approvedPremisesApiClient.getBookingMadeDetails(bookingMadeEvent.url())).thenReturn(details) + whenever(domainEventDetailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(details) return details } @@ -497,7 +494,7 @@ internal class ApprovedPremisesServiceTest { recordedBy: Staff = StaffGenerator.generate() ): EventDetails { val details = EventDetailsGenerator.personNotArrived(recordedBy = recordedBy) - whenever(approvedPremisesApiClient.getPersonNotArrivedDetails(personNotArrivedEvent.url())).thenReturn(details) + whenever(domainEventDetailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(details) return details } @@ -505,7 +502,7 @@ internal class ApprovedPremisesServiceTest { keyWorker: Staff = StaffGenerator.generate() ): EventDetails { val details = EventDetailsGenerator.personArrived(keyWorker = keyWorker) - whenever(approvedPremisesApiClient.getPersonArrivedDetails(personArrivedEvent.url())).thenReturn(details) + whenever(domainEventDetailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(details) return details } diff --git a/projects/assessment-summary-and-delius/deploy/values-dev.yml b/projects/assessment-summary-and-delius/deploy/values-dev.yml index 4223ec55cd..959d15589f 100644 --- a/projects/assessment-summary-and-delius/deploy/values-dev.yml +++ b/projects/assessment-summary-and-delius/deploy/values-dev.yml @@ -10,6 +10,7 @@ generic-service: SENTRY_ENVIRONMENT: dev LOGGING_LEVEL_UK_GOV_DIGITAL_JUSTICE_HMPPS: DEBUG INTEGRATIONS_ORDS_URL: https://t2.oasys.service.justice.gov.uk/eor/oasys + MESSAGING_CONSUMER_DETAIL_URLS: https://t2.oasys.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true diff --git a/projects/assessment-summary-and-delius/deploy/values-preprod.yml b/projects/assessment-summary-and-delius/deploy/values-preprod.yml index 1a6a4f977e..d8d8a14935 100644 --- a/projects/assessment-summary-and-delius/deploy/values-preprod.yml +++ b/projects/assessment-summary-and-delius/deploy/values-preprod.yml @@ -8,6 +8,7 @@ generic-service: env: SENTRY_ENVIRONMENT: preprod INTEGRATIONS_ORDS_URL: https://pp-int.oasys.service.justice.gov.uk/eor/oasys + MESSAGING_CONSUMER_DETAIL_URLS: https://pp.oasys.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/assessment-summary-and-delius/deploy/values-prod.yml b/projects/assessment-summary-and-delius/deploy/values-prod.yml index 80a172647f..5f71acb8ad 100644 --- a/projects/assessment-summary-and-delius/deploy/values-prod.yml +++ b/projects/assessment-summary-and-delius/deploy/values-prod.yml @@ -4,4 +4,5 @@ generic-service: env: SENTRY_ENVIRONMENT: prod - INTEGRATIONS_ORDS_URL: https://int.oasys.service.justice.gov.uk/eor/oasys \ No newline at end of file + INTEGRATIONS_ORDS_URL: https://int.oasys.service.justice.gov.uk/eor/oasys + MESSAGING_CONSUMER_DETAIL_URLS: https://oasys.service.justice.gov.uk diff --git a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/oasys/OrdsClient.kt b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/oasys/OrdsClient.kt index 10a6ac9536..87c4effe0a 100644 --- a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/oasys/OrdsClient.kt +++ b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/oasys/OrdsClient.kt @@ -4,13 +4,9 @@ import com.fasterxml.jackson.annotation.JsonAlias import com.fasterxml.jackson.annotation.JsonFormat import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.service.annotation.GetExchange -import java.net.URI import java.time.LocalDate interface OrdsClient { - @GetExchange - fun getAssessmentSummary(uri: URI): AssessmentSummaries - @GetExchange(url = "/ass/sectionroshsumm/ALLOW/{assessmentPk}") fun getRoshSummary(@PathVariable("assessmentPk") assessmentPk: Long): RoshSummary? } diff --git a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index 59e1177701..6ce3cac86f 100644 --- a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -7,15 +7,15 @@ import com.asyncapi.kotlinasyncapi.annotation.channel.Publish import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.config.security.nullIfNotFound import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException.Companion.orIgnore -import uk.gov.justice.digital.hmpps.integrations.oasys.OrdsClient +import uk.gov.justice.digital.hmpps.integrations.oasys.AssessmentSummaries import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.service.AssessmentSubmitted import uk.gov.justice.digital.hmpps.telemetry.TelemetryMessagingExtensions.notificationReceived import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI const val AssessmentSummaryProduced = "assessment.summary.produced" @@ -23,7 +23,7 @@ const val AssessmentSummaryProduced = "assessment.summary.produced" @Channel("assessment-summary-and-delius-queue") class Handler( override val converter: NotificationConverter, - private val ordsClient: OrdsClient, + private val detailService: DomainEventDetailService, private val assessmentSubmitted: AssessmentSubmitted, private val telemetryService: TelemetryService ) : NotificationHandler { @@ -32,9 +32,9 @@ class Handler( try { if (notification.message.eventType == AssessmentSummaryProduced) { telemetryService.notificationReceived(notification) - notification.message.detailUrl - ?.let { nullIfNotFound { ordsClient.getAssessmentSummary(URI.create(it)) }.orIgnore { "No assessment in OASys" } } - ?.let { assessmentSubmitted.assessmentSubmitted(it.crn, it.assessments.first()) } + val summary = nullIfNotFound { detailService.getDetail(notification.message) } + .orIgnore { "No assessment in OASys" } + assessmentSubmitted.assessmentSubmitted(summary.crn, summary.assessments.first()) } } catch (ime: IgnorableMessageException) { telemetryService.trackEvent( diff --git a/projects/assessment-summary-and-delius/src/main/resources/application.yml b/projects/assessment-summary-and-delius/src/main/resources/application.yml index f0e53b7db7..d08dd99685 100644 --- a/projects/assessment-summary-and-delius/src/main/resources/application.yml +++ b/projects/assessment-summary-and-delius/src/main/resources/application.yml @@ -50,6 +50,7 @@ seed.database: true wiremock.enabled: true messaging.consumer.queue: message-queue +messaging.consumer.detail.urls: http://localhost:${wiremock.port} integrations: ords: diff --git a/projects/cas2-and-delius/deploy/values-dev.yml b/projects/cas2-and-delius/deploy/values-dev.yml index b86b010c97..ca6b269727 100644 --- a/projects/cas2-and-delius/deploy/values-dev.yml +++ b/projects/cas2-and-delius/deploy/values-dev.yml @@ -10,6 +10,7 @@ generic-service: SENTRY_ENVIRONMENT: dev LOGGING_LEVEL_UK_GOV_DIGITAL_JUSTICE_HMPPS: DEBUG SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/oauth/token + MESSAGING_CONSUMER_DETAIL_URLS: https://approved-premises-api-dev.hmpps.service.justice.gov.uk EVENT_EXCEPTION_THROWNOTFOUND: false generic-prometheus-alerts: diff --git a/projects/cas2-and-delius/deploy/values-preprod.yml b/projects/cas2-and-delius/deploy/values-preprod.yml index 1946ce93a7..07081240a6 100644 --- a/projects/cas2-and-delius/deploy/values-preprod.yml +++ b/projects/cas2-and-delius/deploy/values-preprod.yml @@ -8,6 +8,7 @@ generic-service: env: SENTRY_ENVIRONMENT: preprod SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/oauth/token + MESSAGING_CONSUMER_DETAIL_URLS: https://approved-premises-api-preprod.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/cas2-and-delius/deploy/values-prod.yml b/projects/cas2-and-delius/deploy/values-prod.yml index 0623eee9a2..db5a47c695 100644 --- a/projects/cas2-and-delius/deploy/values-prod.yml +++ b/projects/cas2-and-delius/deploy/values-prod.yml @@ -5,3 +5,4 @@ generic-service: env: SENTRY_ENVIRONMENT: prod SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/oauth/token + MESSAGING_CONSUMER_DETAIL_URLS: https://approved-premises-api.hmpps.service.justice.gov.uk diff --git a/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/client/approvedpremises/EventDetailsClient.kt b/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/client/approvedpremises/EventDetailsClient.kt deleted file mode 100644 index ae1a63e96e..0000000000 --- a/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/client/approvedpremises/EventDetailsClient.kt +++ /dev/null @@ -1,15 +0,0 @@ -package uk.gov.justice.digital.hmpps.client.approvedpremises - -import org.springframework.web.service.annotation.GetExchange -import uk.gov.justice.digital.hmpps.client.approvedpremises.model.ApplicationStatusUpdated -import uk.gov.justice.digital.hmpps.client.approvedpremises.model.ApplicationSubmitted -import uk.gov.justice.digital.hmpps.client.approvedpremises.model.EventDetails -import java.net.URI - -interface EventDetailsClient { - @GetExchange - fun getApplicationSubmittedDetails(uri: URI): EventDetails - - @GetExchange - fun getApplicationStatusUpdatedDetails(uri: URI): EventDetails -} diff --git a/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt b/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt deleted file mode 100644 index d5d77a0b39..0000000000 --- a/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt +++ /dev/null @@ -1,13 +0,0 @@ -package uk.gov.justice.digital.hmpps.config - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.client.RestClient -import uk.gov.justice.digital.hmpps.client.approvedpremises.EventDetailsClient -import uk.gov.justice.digital.hmpps.config.security.createClient - -@Configuration -class RestClientConfig(private val oauth2Client: RestClient) { - @Bean - fun eventDetailsClient() = createClient(oauth2Client) -} diff --git a/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/HmppsDomainEventExtensions.kt b/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/HmppsDomainEventExtensions.kt index 87195d136f..1862ba3719 100644 --- a/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/HmppsDomainEventExtensions.kt +++ b/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/HmppsDomainEventExtensions.kt @@ -1,10 +1,8 @@ package uk.gov.justice.digital.hmpps.messaging import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent -import java.net.URI object HmppsDomainEventExtensions { val HmppsDomainEvent.crn get(): String = personReference.findCrn() ?: throw IllegalArgumentException("Missing CRN") - val HmppsDomainEvent.url get(): URI = URI.create(detailUrl ?: throw IllegalArgumentException("Missing detail url")) val HmppsDomainEvent.telemetryProperties get() = mapOf("crn" to crn, "detailUrl" to detailUrl.toString()) } \ No newline at end of file diff --git a/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas2Service.kt b/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas2Service.kt index 2e23b7290a..abe4c16c22 100644 --- a/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas2Service.kt +++ b/projects/cas2-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas2Service.kt @@ -2,24 +2,26 @@ package uk.gov.justice.digital.hmpps.service import jakarta.transaction.Transactional import org.springframework.stereotype.Service -import uk.gov.justice.digital.hmpps.client.approvedpremises.EventDetailsClient +import uk.gov.justice.digital.hmpps.client.approvedpremises.model.ApplicationStatusUpdated +import uk.gov.justice.digital.hmpps.client.approvedpremises.model.ApplicationSubmitted +import uk.gov.justice.digital.hmpps.client.approvedpremises.model.EventDetails +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.entity.ContactType import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.messaging.HmppsDomainEventExtensions.crn import uk.gov.justice.digital.hmpps.messaging.HmppsDomainEventExtensions.telemetryProperties -import uk.gov.justice.digital.hmpps.messaging.HmppsDomainEventExtensions.url import uk.gov.justice.digital.hmpps.telemetry.TelemetryService @Service @Transactional class Cas2Service( - private val eventDetailsClient: EventDetailsClient, + private val detailService: DomainEventDetailService, private val contactService: ContactService, private val telemetryService: TelemetryService, ) { fun applicationSubmitted(event: HmppsDomainEvent) { - val details = eventDetailsClient.getApplicationSubmittedDetails(event.url) + val details = detailService.getDetail>(event) val success = contactService.createContact( crn = event.crn, type = ContactType.REFERRAL_SUBMITTED, @@ -32,7 +34,7 @@ class Cas2Service( } fun applicationStatusUpdated(event: HmppsDomainEvent) { - val details = eventDetailsClient.getApplicationStatusUpdatedDetails(event.url) + val details = detailService.getDetail>(event) val statusDetailsList = details.eventDetails.newStatus.statusDetails ?.joinToString("${System.lineSeparator()}|* ", "${System.lineSeparator()}|* ") { it.label } ?: "" val success = contactService.createContact( diff --git a/projects/cas2-and-delius/src/main/resources/application.yml b/projects/cas2-and-delius/src/main/resources/application.yml index 8420a9e1f4..5ffd21e7a3 100644 --- a/projects/cas2-and-delius/src/main/resources/application.yml +++ b/projects/cas2-and-delius/src/main/resources/application.yml @@ -50,6 +50,7 @@ seed.database: true wiremock.enabled: true messaging.consumer.queue: message-queue +messaging.consumer.detail.urls: http://localhost:${wiremock.port} integrations: example: diff --git a/projects/cas3-and-delius/deploy/values-dev.yml b/projects/cas3-and-delius/deploy/values-dev.yml index c108b9a841..af159b2832 100644 --- a/projects/cas3-and-delius/deploy/values-dev.yml +++ b/projects/cas3-and-delius/deploy/values-dev.yml @@ -12,6 +12,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://approved-premises-api-dev.hmpps.service.justice.gov.uk EVENT_EXCEPTION_THROWNOTFOUND: false generic-prometheus-alerts: diff --git a/projects/cas3-and-delius/deploy/values-preprod.yml b/projects/cas3-and-delius/deploy/values-preprod.yml index a5630b9986..7439340d33 100644 --- a/projects/cas3-and-delius/deploy/values-preprod.yml +++ b/projects/cas3-and-delius/deploy/values-preprod.yml @@ -10,6 +10,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://approved-premises-api-preprod.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/cas3-and-delius/deploy/values-prod.yml b/projects/cas3-and-delius/deploy/values-prod.yml index 2950692b46..842a40eb14 100644 --- a/projects/cas3-and-delius/deploy/values-prod.yml +++ b/projects/cas3-and-delius/deploy/values-prod.yml @@ -7,3 +7,4 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://approved-premises-api.hmpps.service.justice.gov.uk 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 af758fd7a4..12a1778178 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 @@ -14,7 +14,6 @@ import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.service.Cas3Service import uk.gov.justice.digital.hmpps.telemetry.TelemetryMessagingExtensions.notificationReceived import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI @Component @Channel("cas3-and-delius-queue") @@ -136,5 +135,3 @@ class Handler( } fun HmppsDomainEvent.crn(): String = requireNotNull(personReference.findCrn()) { "Missing CRN" } - -fun HmppsDomainEvent.url(): URI = URI.create(requireNotNull(detailUrl) { "Missing detail url" }) diff --git a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas3Service.kt b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas3Service.kt index 372e756910..842a167f4f 100644 --- a/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas3Service.kt +++ b/projects/cas3-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/Cas3Service.kt @@ -3,63 +3,63 @@ package uk.gov.justice.digital.hmpps.service import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import uk.gov.justice.digital.hmpps.datetime.DeliusDateTimeFormatter -import uk.gov.justice.digital.hmpps.integrations.approvedpremises.Cas3ApiClient +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService +import uk.gov.justice.digital.hmpps.integrations.approvedpremises.* import uk.gov.justice.digital.hmpps.integrations.delius.entity.PersonAddress 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 @Service @Transactional class Cas3Service( private val contactService: ContactService, private val addressService: AddressService, - private val cas3ApiClient: Cas3ApiClient, + private val detailService: DomainEventDetailService, private val personRepository: PersonRepository ) { fun referralSubmitted(event: HmppsDomainEvent) { contactService.createOrUpdateContact(event.crn()) { - cas3ApiClient.getApplicationSubmittedDetails(event.url()) + detailService.getDetail>(event) } } fun bookingCancelled(event: HmppsDomainEvent) { contactService.createOrUpdateContact(event.crn()) { - cas3ApiClient.getBookingCancelledDetails(event.url()) + detailService.getDetail>(event) } } fun bookingConfirmed(event: HmppsDomainEvent) { contactService.createOrUpdateContact(event.crn()) { - cas3ApiClient.getBookingConfirmedDetails(event.url()) + detailService.getDetail>(event) } } fun bookingProvisionallyMade(event: HmppsDomainEvent) { contactService.createOrUpdateContact(event.crn()) { - cas3ApiClient.getBookingProvisionallyMade(event.url()) + detailService.getDetail>(event) } } fun personArrived(event: HmppsDomainEvent): Pair { val person = personRepository.getByCrn(event.crn()) - val detail = cas3ApiClient.getPersonArrived(event.url()) + val detail = detailService.getDetail>(event) contactService.createOrUpdateContact(event.crn(), person) { detail } return addressService.updateMainAddress(person, detail.eventDetails) } fun personDeparted(event: HmppsDomainEvent): PersonAddress? { val person = personRepository.getByCrn(event.crn()) - val detail = cas3ApiClient.getPersonDeparted(event.url()) + val detail = detailService.getDetail>(event) contactService.createOrUpdateContact(event.crn(), person) { detail } return addressService.endMainCAS3Address(person, detail.eventDetails.departedAt.toLocalDate()) } fun personArrivedUpdated(event: HmppsDomainEvent): PersonAddress? { val person = personRepository.getByCrn(event.crn()) - val detail = cas3ApiClient.getPersonArrived(event.url()) + val detail = detailService.getDetail>(event) contactService.createOrUpdateContact( event.crn(), replaceNotes = false, @@ -70,13 +70,13 @@ class Cas3Service( fun personDepartedUpdated(event: HmppsDomainEvent) { contactService.createOrUpdateContact(event.crn(), replaceNotes = false) { - cas3ApiClient.getPersonDeparted(event.url()) + detailService.getDetail>(event) } } fun bookingCancelledUpdated(event: HmppsDomainEvent) { contactService.createOrUpdateContact(event.crn(), replaceNotes = false) { - cas3ApiClient.getBookingCancelledDetails(event.url()) + detailService.getDetail>(event) } } } \ No newline at end of file diff --git a/projects/cas3-and-delius/src/main/resources/application.yml b/projects/cas3-and-delius/src/main/resources/application.yml index 8e5dce7357..3aaddccfc2 100644 --- a/projects/cas3-and-delius/src/main/resources/application.yml +++ b/projects/cas3-and-delius/src/main/resources/application.yml @@ -49,8 +49,9 @@ spring: seed.database: true wiremock.enabled: true -messaging.consumer.queue: message-queue messaging.producer.topic: domain-events +messaging.consumer.queue: message-queue +messaging.consumer.detail.urls: http://localhost:${wiremock.port} integrations: cas3-api: diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index cb644affc4..18b85fbee8 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -6,24 +6,22 @@ import com.asyncapi.kotlinasyncapi.annotation.channel.Message import com.asyncapi.kotlinasyncapi.annotation.channel.Publish import org.slf4j.Logger import org.slf4j.LoggerFactory -import org.springframework.http.HttpStatus import org.springframework.stereotype.Component -import org.springframework.web.client.HttpStatusCodeException +import uk.gov.justice.digital.hmpps.config.security.nullIfNotFound import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exception.NotFoundException -import uk.gov.justice.digital.hmpps.integrations.courtcase.CourtCaseClient import uk.gov.justice.digital.hmpps.integrations.courtcase.CourtCaseNote import uk.gov.justice.digital.hmpps.integrations.delius.service.DeliusIntegrationService import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.telemetry.TelemetryMessagingExtensions.notificationReceived import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI @Component @Channel("court-case-and-delius-queue") class Handler( - val courtCaseClient: CourtCaseClient, + val detailService: DomainEventDetailService, val deliusIntegrationService: DeliusIntegrationService, val telemetryService: TelemetryService, override val converter: NotificationConverter @@ -39,31 +37,18 @@ class Handler( val event = notification.message val crn = event.personReference.findCrn() - val courtCaseNote = try { - courtCaseClient.getCourtCaseNote(URI.create(event.detailUrl!!)) - } catch (ex: HttpStatusCodeException) { - when (ex.statusCode) { - HttpStatus.NOT_FOUND -> { - telemetryService.trackEvent("CourtCaseNoteNotFound", mapOf("detailUrl" to event.detailUrl!!)) - return - } + val courtCaseNote = nullIfNotFound { detailService.getDetail(event) } + ?: return telemetryService.trackEvent("CourtCaseNoteNotFound", mapOf("detailUrl" to event.detailUrl!!)) - else -> throw ex - } - } - - log.debug( - "Found court case note in court case service for crn {}, now pushing to delius", - crn - ) + log.debug("Found court case note in court case service for crn {}, now pushing to delius", crn) try { - deliusIntegrationService.mergeCourtCaseNote(crn!!, courtCaseNote!!, notification.message.occurredAt) + deliusIntegrationService.mergeCourtCaseNote(crn!!, courtCaseNote, notification.message.occurredAt) telemetryService.trackEvent("CourtCaseNoteMerged", courtCaseNote.properties()) } catch (e: Exception) { telemetryService.trackEvent( "CourtCaseNoteMergeFailed", - courtCaseNote!!.properties() + ("exception" to (e.message ?: "")) + courtCaseNote.properties() + ("exception" to (e.message ?: "")) ) if (e !is NotFoundException) throw e } diff --git a/projects/court-case-and-delius/src/main/resources/application.yml b/projects/court-case-and-delius/src/main/resources/application.yml index 86075cddd9..a690d740ee 100644 --- a/projects/court-case-and-delius/src/main/resources/application.yml +++ b/projects/court-case-and-delius/src/main/resources/application.yml @@ -67,6 +67,7 @@ seed.database: true wiremock.enabled: true messaging.consumer.queue: events +messaging.consumer.detail.urls: http://localhost:${wiremock.port} community-api.url: http://localhost:${wiremock.port} diff --git a/projects/create-and-vary-a-licence-and-delius/deploy/values-dev.yml b/projects/create-and-vary-a-licence-and-delius/deploy/values-dev.yml index 2882422da8..e3ad42d2b0 100644 --- a/projects/create-and-vary-a-licence-and-delius/deploy/values-dev.yml +++ b/projects/create-and-vary-a-licence-and-delius/deploy/values-dev.yml @@ -12,6 +12,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://create-and-vary-a-licence-api-dev.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true diff --git a/projects/create-and-vary-a-licence-and-delius/deploy/values-preprod.yml b/projects/create-and-vary-a-licence-and-delius/deploy/values-preprod.yml index 0772c5c8f0..d3fe401ed0 100644 --- a/projects/create-and-vary-a-licence-and-delius/deploy/values-preprod.yml +++ b/projects/create-and-vary-a-licence-and-delius/deploy/values-preprod.yml @@ -10,6 +10,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://create-and-vary-a-licence-api-preprod.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/create-and-vary-a-licence-and-delius/deploy/values-prod.yml b/projects/create-and-vary-a-licence-and-delius/deploy/values-prod.yml index 88feae4e42..2f6e873f82 100644 --- a/projects/create-and-vary-a-licence-and-delius/deploy/values-prod.yml +++ b/projects/create-and-vary-a-licence-and-delius/deploy/values-prod.yml @@ -7,3 +7,4 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://create-and-vary-a-licence-api.hmpps.service.justice.gov.uk diff --git a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt b/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt deleted file mode 100644 index d87cde2a96..0000000000 --- a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt +++ /dev/null @@ -1,14 +0,0 @@ -package uk.gov.justice.digital.hmpps.config - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.client.RestClient -import uk.gov.justice.digital.hmpps.config.security.createClient -import uk.gov.justice.digital.hmpps.integrations.cvl.CvlClient - -@Configuration -class RestClientConfig(private val oauth2Client: RestClient) { - - @Bean - fun cvlClient() = createClient(oauth2Client) -} diff --git a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/cvl/CvlClient.kt b/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/cvl/ActivatedLicence.kt similarity index 89% rename from projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/cvl/CvlClient.kt rename to projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/cvl/ActivatedLicence.kt index 44ac6ec986..714810c156 100644 --- a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/cvl/CvlClient.kt +++ b/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/cvl/ActivatedLicence.kt @@ -1,16 +1,8 @@ package uk.gov.justice.digital.hmpps.integrations.cvl import com.fasterxml.jackson.annotation.JsonAlias -import org.hibernate.sql.Restriction -import org.springframework.web.service.annotation.GetExchange -import java.net.URI import java.time.LocalDate -interface CvlClient { - @GetExchange - fun getActivatedLicence(uri: URI): ActivatedLicence -} - data class ActivatedLicence( val crn: String, @JsonAlias("licenceStartDate") diff --git a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceActivatedHandler.kt b/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceActivatedHandler.kt index 0601eea3b0..7af9801422 100644 --- a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceActivatedHandler.kt +++ b/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceActivatedHandler.kt @@ -2,13 +2,13 @@ package uk.gov.justice.digital.hmpps.service import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.config.security.nullIfNotFound -import uk.gov.justice.digital.hmpps.integrations.cvl.CvlClient +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService +import uk.gov.justice.digital.hmpps.integrations.cvl.ActivatedLicence import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent -import java.net.URI @Component class LicenceActivatedHandler( - private val cvlClient: CvlClient, + private val detailService: DomainEventDetailService, private val lca: LicenceConditionApplier ) { fun licenceActivated(domainEvent: HmppsDomainEvent): List { @@ -16,18 +16,12 @@ class LicenceActivatedHandler( domainEvent.personReference.findCrn()?.let { "crn" to it }, domainEvent.detailUrl?.let { "url" to it }).toMap() return try { - val (crn, url) = validateEvent(domainEvent) - val activatedLicence = nullIfNotFound { cvlClient.getActivatedLicence(url) } + val crn = requireNotNull(domainEvent.personReference.findCrn()) { "No CRN Provided" } + val activatedLicence: ActivatedLicence = nullIfNotFound { detailService.getDetail(domainEvent) } ?: return listOf(ActionResult.Ignored("Licence not found", properties)) lca.applyLicenceConditions(crn, activatedLicence, domainEvent.occurredAt) } catch (e: Exception) { listOf(ActionResult.Failure(e, properties)) } } - - private fun validateEvent(domainEvent: HmppsDomainEvent): Pair { - val crn = domainEvent.personReference.findCrn() ?: throw IllegalArgumentException("No CRN Provided") - val url = domainEvent.detailUrl ?: throw IllegalArgumentException("No Detail Url Provided") - return crn to URI.create(url) - } } diff --git a/projects/create-and-vary-a-licence-and-delius/src/main/resources/application.yml b/projects/create-and-vary-a-licence-and-delius/src/main/resources/application.yml index 7e25887055..7413c261a9 100644 --- a/projects/create-and-vary-a-licence-and-delius/src/main/resources/application.yml +++ b/projects/create-and-vary-a-licence-and-delius/src/main/resources/application.yml @@ -75,6 +75,7 @@ spring.config.activate.on-profile: integration-test spring.datasource.url: jdbc:h2:mem:./test;MODE=Oracle;DEFAULT_NULL_ORDERING=HIGH messaging.consumer.queue: message-queue +messaging.consumer.detail.urls: http://localhost:${wiremock.port} --- spring.config.activate.on-profile: oracle diff --git a/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/LicenceActivatedHandlerTest.kt b/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/LicenceActivatedHandlerTest.kt index af0e43bbac..e110769ec6 100644 --- a/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/LicenceActivatedHandlerTest.kt +++ b/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/LicenceActivatedHandlerTest.kt @@ -9,10 +9,10 @@ import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.Mockito.mock import org.mockito.junit.jupiter.MockitoExtension -import org.mockito.kotlin.any +import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.whenever import org.springframework.web.client.HttpClientErrorException.NotFound -import uk.gov.justice.digital.hmpps.integrations.cvl.CvlClient +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.PersonIdentifier import uk.gov.justice.digital.hmpps.message.PersonReference @@ -20,7 +20,7 @@ import uk.gov.justice.digital.hmpps.message.PersonReference @ExtendWith(MockitoExtension::class) internal class LicenceActivatedHandlerTest { @Mock - internal lateinit var cvlClient: CvlClient + internal lateinit var detailService: DomainEventDetailService @Mock internal lateinit var lca: LicenceConditionApplier @@ -38,20 +38,6 @@ internal class LicenceActivatedHandlerTest { assertThat(fail.exception.message, equalTo("No CRN Provided")) } - @Test - fun `exception returned when detail url not found in message`() { - val event = HmppsDomainEvent( - DomainEventType.LicenceActivated.name, - 1, - personReference = PersonReference(listOf(PersonIdentifier("CRN", "X123456"))) - ) - val res = lah.licenceActivated(event).first() - assertThat(res, instanceOf(ActionResult.Failure::class.java)) - val fail = res as ActionResult.Failure - assertThat(fail.exception, instanceOf(IllegalArgumentException::class.java)) - assertThat(fail.exception.message, equalTo("No Detail Url Provided")) - } - @Test fun `ignore when activated licence not found`() { val event = HmppsDomainEvent( @@ -60,7 +46,7 @@ internal class LicenceActivatedHandlerTest { detailUrl = "https://cvl.service.co.uk/licence-activated/58eb2a20-6b0e-416b-b91d-5b98b0c1be7f", personReference = PersonReference(listOf(PersonIdentifier("CRN", "X123456"))) ) - whenever(cvlClient.getActivatedLicence(any())).thenThrow(mock(NotFound::class.java)) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenThrow(mock(NotFound::class.java)) val res = lah.licenceActivated(event).first() assertThat(res, instanceOf(ActionResult.Ignored::class.java)) diff --git a/projects/make-recall-decisions-and-delius/deploy/values-dev.yml b/projects/make-recall-decisions-and-delius/deploy/values-dev.yml index f3c167b353..a0115f4a61 100644 --- a/projects/make-recall-decisions-and-delius/deploy/values-dev.yml +++ b/projects/make-recall-decisions-and-delius/deploy/values-dev.yml @@ -13,6 +13,7 @@ generic-service: SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer INTEGRATIONS_ALFRESCO_URL: https://hmpps-delius-alfresco-test.apps.live.cloud-platform.service.justice.gov.uk/alfresco/service/noms-spg/ + MESSAGING_CONSUMER_DETAIL_URLS: https://make-recall-decision-api-dev.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/make-recall-decisions-and-delius/deploy/values-preprod.yml b/projects/make-recall-decisions-and-delius/deploy/values-preprod.yml index a6c0227b87..ff7777c9d1 100644 --- a/projects/make-recall-decisions-and-delius/deploy/values-preprod.yml +++ b/projects/make-recall-decisions-and-delius/deploy/values-preprod.yml @@ -11,6 +11,7 @@ generic-service: SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer INTEGRATIONS_ALFRESCO_URL: https://alfresco.pre-prod.delius.probation.hmpps.dsd.io/alfresco/service/noms-spg/ + MESSAGING_CONSUMER_DETAIL_URLS: https://make-recall-decision-api-preprod.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/make-recall-decisions-and-delius/deploy/values-prod.yml b/projects/make-recall-decisions-and-delius/deploy/values-prod.yml index 7033d1a033..ab78720923 100644 --- a/projects/make-recall-decisions-and-delius/deploy/values-prod.yml +++ b/projects/make-recall-decisions-and-delius/deploy/values-prod.yml @@ -8,3 +8,4 @@ generic-service: SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer INTEGRATIONS_ALFRESCO_URL: https://alfresco.probation.service.justice.gov.uk/alfresco/service/noms-spg/ + MESSAGING_CONSUMER_DETAIL_URLS: https://make-recall-decision-api.hmpps.service.justice.gov.uk diff --git a/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt b/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt deleted file mode 100644 index 549ea2986a..0000000000 --- a/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt +++ /dev/null @@ -1,14 +0,0 @@ -package uk.gov.justice.digital.hmpps.config - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.client.RestClient -import uk.gov.justice.digital.hmpps.config.security.createClient -import uk.gov.justice.digital.hmpps.integrations.makerecalldecisions.MakeRecallDecisionsClient - -@Configuration -class RestClientConfig(private val oauth2Client: RestClient) { - - @Bean - fun makeRecallDecisionClient() = createClient(oauth2Client) -} diff --git a/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/makerecalldecisions/MakeRecallDecisionsClient.kt b/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/makerecalldecisions/MakeRecallDecisionsClient.kt deleted file mode 100644 index 0e99281f46..0000000000 --- a/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/makerecalldecisions/MakeRecallDecisionsClient.kt +++ /dev/null @@ -1,11 +0,0 @@ -package uk.gov.justice.digital.hmpps.integrations.makerecalldecisions - -import org.springframework.web.service.annotation.GetExchange -import java.net.URI - -interface MakeRecallDecisionsClient { - @GetExchange - fun getDetails(url: URI): RecommendationDetails - - data class RecommendationDetails(val notes: String, val sensitive: Boolean) -} diff --git a/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/makerecalldecisions/RecommendationDetails.kt b/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/makerecalldecisions/RecommendationDetails.kt new file mode 100644 index 0000000000..f22e1200f8 --- /dev/null +++ b/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/makerecalldecisions/RecommendationDetails.kt @@ -0,0 +1,3 @@ +package uk.gov.justice.digital.hmpps.integrations.makerecalldecisions + +data class RecommendationDetails(val notes: String, val sensitive: Boolean) \ No newline at end of file diff --git a/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index 65f1c27a61..d800e69766 100644 --- a/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -5,8 +5,9 @@ import com.asyncapi.kotlinasyncapi.annotation.channel.Message import com.asyncapi.kotlinasyncapi.annotation.channel.Publish import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException -import uk.gov.justice.digital.hmpps.integrations.makerecalldecisions.MakeRecallDecisionsClient +import uk.gov.justice.digital.hmpps.integrations.makerecalldecisions.RecommendationDetails import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.service.RecommendationService @@ -19,7 +20,7 @@ import java.net.URI class Handler( override val converter: NotificationConverter, private val recommendationService: RecommendationService, - private val makeRecallDecisionsClient: MakeRecallDecisionsClient, + private val detailService: DomainEventDetailService, private val telemetryService: TelemetryService ) : NotificationHandler { @Publish( @@ -62,7 +63,7 @@ class Handler( telemetryService.trackEvent(ime.message, ime.additionalProperties) } - private fun Notification.details() = makeRecallDecisionsClient.getDetails(detailUrl()) + private fun Notification.details(): RecommendationDetails = detailService.getDetail(this.message) } private fun Notification.detailUrl() = diff --git a/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/RecommendationService.kt b/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/RecommendationService.kt index 5cd7f26dc1..90d8445adc 100644 --- a/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/RecommendationService.kt +++ b/projects/make-recall-decisions-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/RecommendationService.kt @@ -14,7 +14,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.recommendation.person.ge import uk.gov.justice.digital.hmpps.integrations.delius.user.staff.StaffRepository import uk.gov.justice.digital.hmpps.integrations.delius.user.staff.entity.Staff import uk.gov.justice.digital.hmpps.integrations.delius.user.staff.getStaff -import uk.gov.justice.digital.hmpps.integrations.makerecalldecisions.MakeRecallDecisionsClient.RecommendationDetails +import uk.gov.justice.digital.hmpps.integrations.makerecalldecisions.RecommendationDetails import uk.gov.justice.digital.hmpps.messaging.ManagementDecision import uk.gov.justice.digital.hmpps.telemetry.TelemetryService import java.time.ZonedDateTime diff --git a/projects/make-recall-decisions-and-delius/src/main/resources/application.yml b/projects/make-recall-decisions-and-delius/src/main/resources/application.yml index bc5b955aa9..9b5dc1cd99 100644 --- a/projects/make-recall-decisions-and-delius/src/main/resources/application.yml +++ b/projects/make-recall-decisions-and-delius/src/main/resources/application.yml @@ -63,6 +63,7 @@ seed.database: true wiremock.enabled: true messaging.consumer.queue: message-queue +messaging.consumer.detail.urls: http://localhost:${wiremock.port} logging.level: uk.gov.justice.digital.hmpps: DEBUG diff --git a/projects/make-recall-decisions-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt b/projects/make-recall-decisions-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt index f8a870ea16..55acbd2799 100644 --- a/projects/make-recall-decisions-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt +++ b/projects/make-recall-decisions-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt @@ -8,10 +8,11 @@ import org.junit.jupiter.api.extension.ExtendWith import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.verify import uk.gov.justice.digital.hmpps.converter.NotificationConverter import uk.gov.justice.digital.hmpps.data.generator.MessageGenerator -import uk.gov.justice.digital.hmpps.integrations.makerecalldecisions.MakeRecallDecisionsClient +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.MessageAttributes import uk.gov.justice.digital.hmpps.message.Notification @@ -19,7 +20,6 @@ import uk.gov.justice.digital.hmpps.message.PersonReference import uk.gov.justice.digital.hmpps.service.RecommendationService import uk.gov.justice.digital.hmpps.telemetry.TelemetryMessagingExtensions.notificationReceived import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI @ExtendWith(MockitoExtension::class) internal class HandlerTest { @@ -33,7 +33,7 @@ internal class HandlerTest { lateinit var recommendationService: RecommendationService @Mock - lateinit var makeRecallDecisionsClient: MakeRecallDecisionsClient + lateinit var detailService: DomainEventDetailService @InjectMocks lateinit var handler: Handler @@ -65,24 +65,6 @@ internal class HandlerTest { assertThat(exception.message, equalTo("CRN not found in message")) } - @Test - fun `decision message without detail url throws exception`() { - val message = MessageGenerator.DECISION_NOT_TO_RECALL.copy(detailUrl = null) - val notification = Notification(message, MessageAttributes(message.eventType)) - - val exception = assertThrows { handler.handle(notification) } - assertThat(exception.message, equalTo("No detail url provided")) - } - - @Test - fun `decision message with blank detail url throws exception`() { - val message = MessageGenerator.DECISION_NOT_TO_RECALL.copy(detailUrl = "") - val notification = Notification(message, MessageAttributes(message.eventType)) - - val exception = assertThrows { handler.handle(notification) } - assertThat(exception.message, equalTo("No detail url provided")) - } - @Test fun `calls detail url`() { val message = MessageGenerator.DECISION_TO_RECALL @@ -90,6 +72,6 @@ internal class HandlerTest { handler.handle(notification) - verify(makeRecallDecisionsClient).getDetails(URI(message.detailUrl!!)) + verify(detailService).getDetail(anyOrNull(), anyOrNull()) } } diff --git a/projects/manage-pom-cases-and-delius/deploy/values-dev.yml b/projects/manage-pom-cases-and-delius/deploy/values-dev.yml index cbaef3cd3f..33d6f9c48c 100644 --- a/projects/manage-pom-cases-and-delius/deploy/values-dev.yml +++ b/projects/manage-pom-cases-and-delius/deploy/values-dev.yml @@ -12,6 +12,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://dev.moic.service.justice.gov.uk MPC_HANDOVER_URL: https://dev.moic.service.justice.gov.uk bulk-update: diff --git a/projects/manage-pom-cases-and-delius/deploy/values-preprod.yml b/projects/manage-pom-cases-and-delius/deploy/values-preprod.yml index 0c5f01a2e3..25677dc614 100644 --- a/projects/manage-pom-cases-and-delius/deploy/values-preprod.yml +++ b/projects/manage-pom-cases-and-delius/deploy/values-preprod.yml @@ -10,6 +10,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://preprod.moic.service.justice.gov.uk MPC_HANDOVER_URL: https://preprod.moic.service.justice.gov.uk bulk-update: diff --git a/projects/manage-pom-cases-and-delius/deploy/values-prod.yml b/projects/manage-pom-cases-and-delius/deploy/values-prod.yml index 52baee68f5..c84a6389e9 100644 --- a/projects/manage-pom-cases-and-delius/deploy/values-prod.yml +++ b/projects/manage-pom-cases-and-delius/deploy/values-prod.yml @@ -7,6 +7,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://moic.service.justice.gov.uk MPC_HANDOVER_URL: https://moic.service.justice.gov.uk bulk-update: diff --git a/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PomCaseMessageHandler.kt b/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PomCaseMessageHandler.kt index 32e34a908a..35e2c3ef55 100644 --- a/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PomCaseMessageHandler.kt +++ b/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PomCaseMessageHandler.kt @@ -8,7 +8,6 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Primary -import org.springframework.http.HttpStatus import org.springframework.stereotype.Component import org.springframework.web.client.HttpClientErrorException import uk.gov.justice.digital.hmpps.converter.NotificationConverter @@ -52,37 +51,26 @@ class PomCaseMessageHandler( try { when (val message = notification.message) { is HmppsDomainEvent -> when (notification.eventType) { - "offender-management.handover.changed", BULK_HANDOVER_DATE_UPDATE -> handoverDatesChanged.process( - HandoverMessage( - message.personReference, - message.detailUrl - ), - message.dryRun - ) + "offender-management.handover.changed", BULK_HANDOVER_DATE_UPDATE -> + handoverDatesChanged.process(message.personReference, message.detailUrl, message.dryRun) "offender-management.allocation.changed" -> pomAllocated.process(message) + else -> throw NotImplementedError("Unhandled message type received: ${notification.eventType}") } is ProbationOffenderEvent -> when (notification.eventType) { - "SENTENCE_CHANGED", - -> personRepository.findNomsSingleCustodial(message.crn)?.let { + "SENTENCE_CHANGED" -> personRepository.findNomsSingleCustodial(message.crn)?.let { try { handoverDatesChanged.process( - HandoverMessage( - PersonReference(listOf(PersonIdentifier("NOMS", it))), - "$mpcHandoverUrl/api/handovers/$it" - ) + PersonReference(listOf(PersonIdentifier("NOMS", it))), + "$mpcHandoverUrl/api/handovers/$it" + ) + } catch (e: HttpClientErrorException.NotFound) { + throw IgnorableMessageException( + "Handovers api returned not found for sentence changed event", + mapOf("detailUrl" to "$mpcHandoverUrl/api/handovers/$it") ) - } catch (e: HttpClientErrorException) { - if (e.statusCode == HttpStatus.NOT_FOUND) { - throw IgnorableMessageException( - "Handovers api returned not found for sentence changed event", - mapOf("detailUrl" to "$mpcHandoverUrl/api/handovers/$it") - ) - } else { - throw e - } } } @@ -90,21 +78,13 @@ class PomCaseMessageHandler( } } } catch (ime: IgnorableMessageException) { - telemetryService.trackEvent( - ime.message, - ime.additionalProperties - ) + telemetryService.trackEvent(ime.message, ime.additionalProperties) } } val HmppsDomainEvent.dryRun get() = additionalInformation["dryRun"] == true } -data class HandoverMessage( - val personReference: PersonReference, - val detailUrl: String? -) - @Message data class ProbationOffenderEvent(val crn: String) diff --git a/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/HandoverDatesChanged.kt b/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/HandoverDatesChanged.kt index 6ecd08dd22..466a8fc0f0 100644 --- a/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/HandoverDatesChanged.kt +++ b/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/HandoverDatesChanged.kt @@ -1,30 +1,25 @@ package uk.gov.justice.digital.hmpps.services import org.springframework.stereotype.Service +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException +import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException.Companion.orIgnore import uk.gov.justice.digital.hmpps.integrations.delius.allocation.entity.event.keydate.KeyDate import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PersonRepository import uk.gov.justice.digital.hmpps.integrations.managepomcases.Handover -import uk.gov.justice.digital.hmpps.integrations.managepomcases.ManagePomCasesClient -import uk.gov.justice.digital.hmpps.messaging.HandoverMessage +import uk.gov.justice.digital.hmpps.message.PersonReference import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI @Service class HandoverDatesChanged( - private val pomCasesClient: ManagePomCasesClient, + private val detailService: DomainEventDetailService, private val personRepository: PersonRepository, private val keyDateService: KeyDateService, private val telemetryService: TelemetryService ) { - fun process(event: HandoverMessage, dryRun: Boolean = false) = try { - val handOver = event.detailUrl?.let { pomCasesClient.getDetails(URI.create(it)) } - ?: throw IgnorableMessageException( - "No handover data available", - mapOf("detailUrl" to event.detailUrl.orNotProvided()) - ) - val personId = personRepository.findIdFromNomsId(handOver.nomsId) - ?: throw IgnorableMessageException("PersonNotFound", handOver.properties()) + fun process(personReference: PersonReference, detailUrl: String?, dryRun: Boolean = false) = try { + val handOver = detailService.getDetail(detailUrl) + val personId = personRepository.findIdFromNomsId(handOver.nomsId).orIgnore { "PersonNotFound" } val (result, existingDates) = keyDateService .mergeHandoverDates(personId, handOver.date, handOver.startDate, dryRun) @@ -32,7 +27,7 @@ class HandoverDatesChanged( } catch (ime: IgnorableMessageException) { telemetryService.trackEvent( ime.message, - mapOf("nomsId" to event.personReference.findNomsNumber().orNotProvided()) + ime.additionalProperties + mapOf("nomsId" to personReference.findNomsNumber().orNotProvided()) + ime.additionalProperties ) } diff --git a/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/PomAllocated.kt b/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/PomAllocated.kt index a9aa8c8cd5..5e939bd3eb 100644 --- a/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/PomAllocated.kt +++ b/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/PomAllocated.kt @@ -1,45 +1,33 @@ package uk.gov.justice.digital.hmpps.services -import org.springframework.http.HttpStatus import org.springframework.stereotype.Service -import org.springframework.web.client.HttpStatusCodeException +import org.springframework.web.client.HttpClientErrorException import uk.gov.justice.digital.hmpps.datetime.DeliusDateTimeFormatter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PersonRepository -import uk.gov.justice.digital.hmpps.integrations.managepomcases.ManagePomCasesClient import uk.gov.justice.digital.hmpps.integrations.managepomcases.PomAllocation import uk.gov.justice.digital.hmpps.integrations.managepomcases.PomDeallocated import uk.gov.justice.digital.hmpps.integrations.managepomcases.PomNotAllocated import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI import java.time.ZonedDateTime @Service class PomAllocated( - private val pomCasesClient: ManagePomCasesClient, + private val detailService: DomainEventDetailService, private val personRepository: PersonRepository, private val prisonManagerService: PrisonManagerService, private val telemetryService: TelemetryService ) { fun process(event: HmppsDomainEvent) = try { val pomAllocation = try { - event.detailUrl?.let { pomCasesClient.getPomAllocation(URI.create(it)) } - ?: throw IgnorableMessageException( - "No POM Allocation data available", - mapOf("detailUrl" to event.detailUrl.orNotProvided()) - ) - } catch (e: HttpStatusCodeException) { - when (e.statusCode) { - HttpStatus.NOT_FOUND -> { - val error = e.getResponseBodyAs(ErrorResponse::class.java) - when (error?.message) { - "Not allocated" -> PomDeallocated - else -> PomNotAllocated - } - } - - else -> throw e + detailService.getDetail(event) + } catch (e: HttpClientErrorException.NotFound) { + val error = e.getResponseBodyAs(ErrorResponse::class.java) + when (error?.message) { + "Not allocated" -> PomDeallocated + else -> PomNotAllocated } } diff --git a/projects/manage-pom-cases-and-delius/src/main/resources/application.yml b/projects/manage-pom-cases-and-delius/src/main/resources/application.yml index 4faf99dc02..a72074dd87 100644 --- a/projects/manage-pom-cases-and-delius/src/main/resources/application.yml +++ b/projects/manage-pom-cases-and-delius/src/main/resources/application.yml @@ -60,6 +60,7 @@ wiremock.enabled: true messaging: consumer.queue: message-queue + consumer.detail.urls: http://localhost:${wiremock.port} producer.queue: message-queue mpc.handover.url: http://localhost:${wiremock.port} diff --git a/projects/manage-pom-cases-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/services/messaging/HandlerTest.kt b/projects/manage-pom-cases-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/services/messaging/HandlerTest.kt index cd91e71dcf..a8395f519f 100644 --- a/projects/manage-pom-cases-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/services/messaging/HandlerTest.kt +++ b/projects/manage-pom-cases-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/services/messaging/HandlerTest.kt @@ -66,7 +66,7 @@ internal class HandlerTest { @Test fun `handles internal event type`() { - doNothing().whenever(handoverDatesChanged).process(any(), any()) + doNothing().whenever(handoverDatesChanged).process(anyOrNull(), anyOrNull(), anyOrNull()) handler.handle( Notification( message = HmppsDomainEvent( @@ -77,7 +77,7 @@ internal class HandlerTest { ) ) - verify(handoverDatesChanged, times(1)).process(any(), any()) + verify(handoverDatesChanged, times(1)).process(anyOrNull(), anyOrNull(), anyOrNull()) verifyNoMoreInteractions(handoverDatesChanged) } } diff --git a/projects/prison-case-notes-to-probation/deploy/values-dev.yml b/projects/prison-case-notes-to-probation/deploy/values-dev.yml index db46aad5ea..e7d54cd60e 100644 --- a/projects/prison-case-notes-to-probation/deploy/values-dev.yml +++ b/projects/prison-case-notes-to-probation/deploy/values-dev.yml @@ -13,6 +13,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/oauth/token INTEGRATIONS_PRISON_CASE_NOTES_BASE_URL: https://dev.offender-case-notes.service.justice.gov.uk INTEGRATIONS_PRISONER_ALERTS_BASE_URL: https://alerts-api-dev.hmpps.service.justice.gov.uk + MESSAGING_CONSUMER_DETAIL_URLS: https://dev.offender-case-notes.service.justice.gov.uk,https://alerts-api-dev.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/prison-case-notes-to-probation/deploy/values-preprod.yml b/projects/prison-case-notes-to-probation/deploy/values-preprod.yml index bf007566be..a67f988b08 100644 --- a/projects/prison-case-notes-to-probation/deploy/values-preprod.yml +++ b/projects/prison-case-notes-to-probation/deploy/values-preprod.yml @@ -10,6 +10,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/oauth/token INTEGRATIONS_PRISON_CASE_NOTES_BASE_URL: https://preprod.offender-case-notes.service.justice.gov.uk INTEGRATIONS_PRISONER_ALERTS_BASE_URL: https://alerts-api-preprod.hmpps.service.justice.gov.uk + MESSAGING_CONSUMER_DETAIL_URLS: https://preprod.offender-case-notes.service.justice.gov.uk,https://alerts-api-preprod.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/prison-case-notes-to-probation/deploy/values-prod.yml b/projects/prison-case-notes-to-probation/deploy/values-prod.yml index 9941583767..aaf85b5ddc 100644 --- a/projects/prison-case-notes-to-probation/deploy/values-prod.yml +++ b/projects/prison-case-notes-to-probation/deploy/values-prod.yml @@ -7,3 +7,4 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/oauth/token INTEGRATIONS_PRISON_CASE_NOTES_BASE_URL: https://offender-case-notes.service.justice.gov.uk INTEGRATIONS_PRISONER_ALERTS_BASE_URL: https://alerts-api.hmpps.service.justice.gov.uk + MESSAGING_CONSUMER_DETAIL_URLS: https://offender-case-notes.service.justice.gov.uk,https://alerts-api.hmpps.service.justice.gov.uk diff --git a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonCaseNotesClient.kt b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonCaseNotesClient.kt index 2cff90855f..a7b8c91ced 100644 --- a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonCaseNotesClient.kt +++ b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonCaseNotesClient.kt @@ -1,15 +1,11 @@ package uk.gov.justice.digital.hmpps.integrations.prison import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.service.annotation.GetExchange import org.springframework.web.service.annotation.PostExchange import java.net.URI import java.time.LocalDateTime interface PrisonCaseNotesClient { - @GetExchange - fun getCaseNote(baseUrl: URI): PrisonCaseNote - @PostExchange fun searchCaseNotes( uri: URI, diff --git a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonerAlertClient.kt b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonerAlertClient.kt index 7444def72b..15c69ac086 100644 --- a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonerAlertClient.kt +++ b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonerAlertClient.kt @@ -15,9 +15,6 @@ import java.time.ZonedDateTime import java.util.* interface PrisonerAlertClient { - @GetExchange - fun getAlert(baseUrl: URI): Alert - @GetExchange fun getActiveAlerts(uri: URI): Alerts } diff --git a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNote.kt b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNote.kt index 84fd328893..3fb5b793ee 100644 --- a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNote.kt +++ b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNote.kt @@ -1,38 +1,29 @@ package uk.gov.justice.digital.hmpps.messaging -import org.springframework.http.HttpStatus import org.springframework.stereotype.Service -import org.springframework.web.client.HttpStatusCodeException +import org.springframework.web.client.HttpClientErrorException import uk.gov.justice.digital.hmpps.datetime.DeliusDateTimeFormatter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exceptions.OffenderNotFoundException import uk.gov.justice.digital.hmpps.integrations.delius.model.properties import uk.gov.justice.digital.hmpps.integrations.delius.service.DeliusService import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNote import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNoteFilters.filters -import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNotesClient import uk.gov.justice.digital.hmpps.integrations.prison.toDeliusCaseNote import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI @Service class PersonCaseNote( - private val prisonCaseNotesClient: PrisonCaseNotesClient, + private val detailService: DomainEventDetailService, private val deliusService: DeliusService, private val telemetryService: TelemetryService, ) { fun handle(event: HmppsDomainEvent) { val prisonCaseNote: PrisonCaseNote = try { - prisonCaseNotesClient.getCaseNote(URI.create(event.detailUrl!!)) - } catch (ex: HttpStatusCodeException) { - when (ex.statusCode) { - HttpStatus.NOT_FOUND -> { - telemetryService.trackEvent("CaseNoteNotFound", mapOf("detailUrl" to event.detailUrl!!)) - return - } - - else -> throw ex - } + detailService.getDetail(event) + } catch (e: HttpClientErrorException.NotFound) { + return telemetryService.trackEvent("CaseNoteNotFound", mapOf("detailUrl" to event.detailUrl!!)) } filters.firstOrNull { it.predicate.invoke(prisonCaseNote) }?.reason?.also { diff --git a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonerAlert.kt b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonerAlert.kt index 14eb0648d8..a9dc6b6f88 100644 --- a/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonerAlert.kt +++ b/projects/prison-case-notes-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonerAlert.kt @@ -1,38 +1,29 @@ package uk.gov.justice.digital.hmpps.messaging -import org.springframework.http.HttpStatus import org.springframework.stereotype.Service -import org.springframework.web.client.HttpStatusCodeException +import org.springframework.web.client.HttpClientErrorException import uk.gov.justice.digital.hmpps.datetime.DeliusDateFormatter import uk.gov.justice.digital.hmpps.datetime.DeliusDateTimeFormatter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exceptions.OffenderNotFoundException import uk.gov.justice.digital.hmpps.integrations.delius.model.properties import uk.gov.justice.digital.hmpps.integrations.delius.service.DeliusService import uk.gov.justice.digital.hmpps.integrations.prison.Alert -import uk.gov.justice.digital.hmpps.integrations.prison.PrisonerAlertClient import uk.gov.justice.digital.hmpps.integrations.prison.toDeliusCaseNote import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI @Service class PrisonerAlert( - private val alertsClient: PrisonerAlertClient, + private val detailService: DomainEventDetailService, private val deliusService: DeliusService, private val telemetryService: TelemetryService, ) { fun handle(event: HmppsDomainEvent) { val alert: Alert = try { - alertsClient.getAlert(URI.create(event.detailUrl!!)) - } catch (ex: HttpStatusCodeException) { - when (ex.statusCode) { - HttpStatus.NOT_FOUND -> { - telemetryService.trackEvent("AlertNotFound", mapOf("detailUrl" to event.detailUrl!!)) - return - } - - else -> throw ex - } + detailService.getDetail(event) + } catch (e: HttpClientErrorException.NotFound) { + return telemetryService.trackEvent("AlertNotFound", mapOf("detailUrl" to event.detailUrl!!)) } try { diff --git a/projects/prison-case-notes-to-probation/src/main/resources/application.yml b/projects/prison-case-notes-to-probation/src/main/resources/application.yml index 123f830e08..cc56c7e0d4 100644 --- a/projects/prison-case-notes-to-probation/src/main/resources/application.yml +++ b/projects/prison-case-notes-to-probation/src/main/resources/application.yml @@ -58,6 +58,7 @@ seed.database: true wiremock.enabled: true messaging.consumer.queue: events +messaging.consumer.detail.urls: http://localhost:${wiremock.port},http://localhost:${wiremock.port} integrations: prison-case-notes: diff --git a/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNoteTest.kt b/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNoteTest.kt index 29fc03a6b3..dc4961a771 100644 --- a/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNoteTest.kt +++ b/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PersonCaseNoteTest.kt @@ -8,23 +8,22 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource import org.mockito.InjectMocks import org.mockito.Mock +import org.mockito.Mockito.mock import org.mockito.junit.jupiter.MockitoExtension import org.mockito.kotlin.* -import org.springframework.http.HttpStatus -import org.springframework.web.client.HttpClientErrorException +import org.springframework.web.client.HttpClientErrorException.NotFound import uk.gov.justice.digital.hmpps.audit.service.AuditedInteractionService import uk.gov.justice.digital.hmpps.data.generator.CaseNoteMessageGenerator +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exceptions.OffenderNotFoundException import uk.gov.justice.digital.hmpps.exceptions.StaffCodeExhaustedException import uk.gov.justice.digital.hmpps.integrations.delius.service.DeliusService import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNote -import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNotesClient import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.prepNotification import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI import java.time.ZonedDateTime -import java.util.UUID +import java.util.* @ExtendWith(MockitoExtension::class) internal class PersonCaseNoteTest { @@ -33,7 +32,7 @@ internal class PersonCaseNoteTest { private lateinit var auditedInteractionService: AuditedInteractionService @Mock - private lateinit var prisonCaseNotesClient: PrisonCaseNotesClient + private lateinit var detailService: DomainEventDetailService @Mock private lateinit var deliusService: DeliusService @@ -47,8 +46,7 @@ internal class PersonCaseNoteTest { @Test fun `when case note not found - noop`() { val message = prepNotification(CaseNoteMessageGenerator.NOT_FOUND).message - whenever(prisonCaseNotesClient.getCaseNote(URI.create(message.detailUrl!!))) - .thenThrow(HttpClientErrorException(HttpStatus.NOT_FOUND)) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenThrow(mock(NotFound::class.java)) assertDoesNotThrow { handler.handle(message) } verify(telemetryService, never()).trackEvent(eq("CaseNoteMerged"), any(), any()) @@ -70,7 +68,7 @@ internal class PersonCaseNoteTest { amendments = listOf() ) val message = prepNotification(CaseNoteMessageGenerator.EXISTS_IN_DELIUS).message - whenever(prisonCaseNotesClient.getCaseNote(URI.create(message.detailUrl!!))).thenReturn(prisonCaseNote) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(prisonCaseNote) handler.handle(message) verify(deliusService, times(0)).mergeCaseNote(any()) } @@ -91,7 +89,7 @@ internal class PersonCaseNoteTest { amendments = listOf() ) val message = prepNotification(CaseNoteMessageGenerator.EXISTS_IN_DELIUS).message - whenever(prisonCaseNotesClient.getCaseNote(URI.create(message.detailUrl!!))).thenReturn(prisonCaseNote) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(prisonCaseNote) handler.handle(message) verify(deliusService, never()).mergeCaseNote(any()) @@ -117,7 +115,7 @@ internal class PersonCaseNoteTest { amendments = listOf() ) val message = prepNotification(CaseNoteMessageGenerator.EXISTS_IN_DELIUS).message - whenever(prisonCaseNotesClient.getCaseNote(URI.create(message.detailUrl!!))).thenReturn(prisonCaseNote) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(prisonCaseNote) handler.handle(message) verify(deliusService, never()).mergeCaseNote(any()) @@ -141,7 +139,7 @@ internal class PersonCaseNoteTest { amendments = listOf() ) val poe = Notification(prepNotification(CaseNoteMessageGenerator.NEW_TO_DELIUS).message) - whenever(prisonCaseNotesClient.getCaseNote(URI.create(poe.message.detailUrl!!))).thenReturn(prisonCaseNote) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(prisonCaseNote) whenever(deliusService.mergeCaseNote(any())).thenThrow(OffenderNotFoundException("A001")) handler.handle(poe.message) @@ -164,7 +162,7 @@ internal class PersonCaseNoteTest { amendments = listOf() ) val poe = Notification(prepNotification(CaseNoteMessageGenerator.NEW_TO_DELIUS).message) - whenever(prisonCaseNotesClient.getCaseNote(URI.create(poe.message.detailUrl!!))).thenReturn(prisonCaseNote) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(prisonCaseNote) whenever(deliusService.mergeCaseNote(any())).thenThrow(StaffCodeExhaustedException("A999")) assertThrows { handler.handle(poe.message) } diff --git a/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonerAlertTest.kt b/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonerAlertTest.kt index 2d2ca2a253..0353844dbf 100644 --- a/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonerAlertTest.kt +++ b/projects/prison-case-notes-to-probation/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/PrisonerAlertTest.kt @@ -7,27 +7,24 @@ import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.extension.ExtendWith import org.mockito.InjectMocks import org.mockito.Mock +import org.mockito.Mockito.mock import org.mockito.junit.jupiter.MockitoExtension -import org.mockito.kotlin.any -import org.mockito.kotlin.eq -import org.mockito.kotlin.never -import org.mockito.kotlin.verify -import org.mockito.kotlin.whenever +import org.mockito.kotlin.* import org.springframework.http.HttpStatus +import org.springframework.web.client.HttpClientErrorException.NotFound import org.springframework.web.client.HttpServerErrorException import org.springframework.web.client.HttpStatusCodeException import uk.gov.justice.digital.hmpps.data.generator.AlertMessageGenerator.ALERT_CREATED import uk.gov.justice.digital.hmpps.data.generator.PrisonCaseNoteGenerator +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exceptions.OffenderNotFoundException -import uk.gov.justice.digital.hmpps.flags.FeatureFlags import uk.gov.justice.digital.hmpps.integrations.delius.service.DeliusService -import uk.gov.justice.digital.hmpps.integrations.prison.PrisonerAlertClient import uk.gov.justice.digital.hmpps.telemetry.TelemetryService @ExtendWith(MockitoExtension::class) internal class PrisonerAlertTest { @Mock - private lateinit var alertApi: PrisonerAlertClient + private lateinit var detailService: DomainEventDetailService @Mock private lateinit var deliusService: DeliusService @@ -40,7 +37,7 @@ internal class PrisonerAlertTest { @Test fun `Exception logged but not thrown when alert not found`() { - whenever(alertApi.getAlert(any())).thenThrow(HttpServerErrorException(HttpStatus.NOT_FOUND)) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenThrow(mock(NotFound::class.java)) val domainEvent = ALERT_CREATED.message.copy(detailUrl = "http://localhost:8080/test") prisonerAlert.handle(domainEvent) @@ -49,7 +46,12 @@ internal class PrisonerAlertTest { @Test fun `Exception other than not found thrown`() { - whenever(alertApi.getAlert(any())).thenThrow(HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)) + whenever( + detailService.getDetail( + anyOrNull(), + anyOrNull() + ) + ).thenThrow(HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)) val domainEvent = ALERT_CREATED.message.copy(detailUrl = "http://localhost:8080/test") val exception = assertThrows { prisonerAlert.handle(domainEvent) } assertThat(exception.statusCode, equalTo(HttpStatus.INTERNAL_SERVER_ERROR)) @@ -58,7 +60,12 @@ internal class PrisonerAlertTest { @Test fun `Delius service exception thrown`() { whenever(deliusService.mergeCaseNote(any())).thenThrow(IllegalStateException("Something went wrong")) - whenever(alertApi.getAlert(any())).thenReturn(PrisonCaseNoteGenerator.CREATED_ALERT) + whenever( + detailService.getDetail( + anyOrNull(), + anyOrNull() + ) + ).thenReturn(PrisonCaseNoteGenerator.CREATED_ALERT) val domainEvent = ALERT_CREATED.message.copy(detailUrl = "http://localhost:8080/test") val exception = assertThrows { prisonerAlert.handle(domainEvent) } assertThat(exception.message, equalTo("Something went wrong")) @@ -67,7 +74,12 @@ internal class PrisonerAlertTest { @Test fun `Message ignored if offender not found`() { whenever(deliusService.mergeCaseNote(any())).thenThrow(OffenderNotFoundException("Offender not found")) - whenever(alertApi.getAlert(any())).thenReturn(PrisonCaseNoteGenerator.CREATED_ALERT) + whenever( + detailService.getDetail( + anyOrNull(), + anyOrNull() + ) + ).thenReturn(PrisonCaseNoteGenerator.CREATED_ALERT) val domainEvent = ALERT_CREATED.message.copy(detailUrl = "http://localhost:8080/test") prisonerAlert.handle(domainEvent) diff --git a/projects/refer-and-monitor-and-delius/deploy/values-dev.yml b/projects/refer-and-monitor-and-delius/deploy/values-dev.yml index ae1815294d..2aef0ab743 100644 --- a/projects/refer-and-monitor-and-delius/deploy/values-dev.yml +++ b/projects/refer-and-monitor-and-delius/deploy/values-dev.yml @@ -12,6 +12,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://hmpps-interventions-service-dev.apps.live-1.cloud-platform.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true diff --git a/projects/refer-and-monitor-and-delius/deploy/values-preprod.yml b/projects/refer-and-monitor-and-delius/deploy/values-preprod.yml index 6fc9744be5..6d4e6d42ff 100644 --- a/projects/refer-and-monitor-and-delius/deploy/values-preprod.yml +++ b/projects/refer-and-monitor-and-delius/deploy/values-preprod.yml @@ -10,6 +10,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://hmpps-interventions-service-preprod.apps.live-1.cloud-platform.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/refer-and-monitor-and-delius/deploy/values-prod.yml b/projects/refer-and-monitor-and-delius/deploy/values-prod.yml index 56f8c895e6..c91b682b2c 100644 --- a/projects/refer-and-monitor-and-delius/deploy/values-prod.yml +++ b/projects/refer-and-monitor-and-delius/deploy/values-prod.yml @@ -6,4 +6,5 @@ generic-service: SENTRY_ENVIRONMENT: prod SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: https://sign-in.hmpps.service.justice.gov.uk/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json - SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer \ No newline at end of file + SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://hmpps-interventions-service.apps.live-1.cloud-platform.service.justice.gov.uk diff --git a/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt b/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt deleted file mode 100644 index 17df492ac3..0000000000 --- a/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt +++ /dev/null @@ -1,14 +0,0 @@ -package uk.gov.justice.digital.hmpps.config - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.client.RestClient -import uk.gov.justice.digital.hmpps.config.security.createClient -import uk.gov.justice.digital.hmpps.integrations.randm.ReferAndMonitorClient - -@Configuration -class RestClientConfig(private val oauth2Client: RestClient) { - - @Bean - fun referAndMonitorClient() = createClient(oauth2Client) -} diff --git a/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/randm/ReferAndMonitorClient.kt b/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/randm/ReferAndMonitorClient.kt deleted file mode 100644 index 80a3548ba8..0000000000 --- a/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/randm/ReferAndMonitorClient.kt +++ /dev/null @@ -1,17 +0,0 @@ -package uk.gov.justice.digital.hmpps.integrations.randm - -import org.springframework.web.service.annotation.GetExchange -import uk.gov.justice.digital.hmpps.messaging.SentReferral -import java.net.URI - -interface ReferAndMonitorClient { - - @GetExchange - fun getReferral(uri: URI): SentReferral? - - @GetExchange - fun getSession(uri: URI): ReferralSession? - - @GetExchange - fun getSupplierAssessment(uri: URI): SupplierAssessment? -} diff --git a/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/FeedbackSubmitted.kt b/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/FeedbackSubmitted.kt index 691f87563a..9030084033 100644 --- a/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/FeedbackSubmitted.kt +++ b/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/FeedbackSubmitted.kt @@ -1,7 +1,8 @@ package uk.gov.justice.digital.hmpps.messaging import org.springframework.stereotype.Component -import uk.gov.justice.digital.hmpps.integrations.randm.ReferAndMonitorClient +import uk.gov.justice.digital.hmpps.config.security.nullIfNotFound +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.integrations.randm.ReferralSession import uk.gov.justice.digital.hmpps.integrations.randm.SupplierAssessment import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent @@ -10,11 +11,10 @@ import uk.gov.justice.digital.hmpps.service.AppointmentService import uk.gov.justice.digital.hmpps.service.Attended import uk.gov.justice.digital.hmpps.service.Outcome import uk.gov.justice.digital.hmpps.service.UpdateAppointmentOutcome -import java.net.URI @Component class FeedbackSubmitted( - private val ramClient: ReferAndMonitorClient, + private val detailService: DomainEventDetailService, private val appointmentService: AppointmentService ) : DomainEventHandler { override val handledEvents = mapOf( @@ -23,7 +23,7 @@ class FeedbackSubmitted( ) fun initialAppointmentSubmitted(event: HmppsDomainEvent): EventProcessingResult = handle(event) { - val appointment = ramClient.getSupplierAssessment(URI(event.detailUrl!!))?.appointmentOutcome( + val appointment = nullIfNotFound { detailService.getDetail(event) }?.appointmentOutcome( event.personReference.findCrn()!!, event.referralReference(), event.contractType(), @@ -35,7 +35,7 @@ class FeedbackSubmitted( } fun sessionAppointmentSubmitted(event: HmppsDomainEvent): EventProcessingResult = handle(event) { - val appointment = ramClient.getSession(URI(event.detailUrl!!))?.appointmentOutcome( + val appointment = nullIfNotFound { detailService.getDetail(event) }?.appointmentOutcome( event.personReference.findCrn()!!, event.referralId(), event.referralReference(), diff --git a/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/ReferralEndSubmitted.kt b/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/ReferralEndSubmitted.kt index 1d4597a6f9..ada852b569 100644 --- a/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/ReferralEndSubmitted.kt +++ b/projects/refer-and-monitor-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/ReferralEndSubmitted.kt @@ -2,20 +2,20 @@ package uk.gov.justice.digital.hmpps.messaging import com.fasterxml.jackson.annotation.JsonAlias import org.springframework.stereotype.Component +import uk.gov.justice.digital.hmpps.config.security.nullIfNotFound +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exception.NotFoundException -import uk.gov.justice.digital.hmpps.integrations.randm.ReferAndMonitorClient import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.messaging.DomainEventType.ReferralEnded import uk.gov.justice.digital.hmpps.messaging.EventProcessingResult.Success import uk.gov.justice.digital.hmpps.messaging.ReferralWithdrawalNsiOutcome.* import uk.gov.justice.digital.hmpps.messaging.ReferralWithdrawalState.PRE_ICA_WITHDRAWAL import uk.gov.justice.digital.hmpps.service.NsiService -import java.net.URI import java.time.ZonedDateTime @Component class ReferralEndSubmitted( - private val ramClient: ReferAndMonitorClient, + private val detailService: DomainEventDetailService, private val nsiService: NsiService ) : DomainEventHandler { override val handledEvents = mapOf( @@ -23,7 +23,7 @@ class ReferralEndSubmitted( ) fun referralEnded(event: HmppsDomainEvent): EventProcessingResult = handle(event) { - val sentReferral = ramClient.getReferral(URI(event.detailUrl!!)) + val sentReferral = nullIfNotFound { detailService.getDetail(event) } ?: throw NotFoundException("Unable to retrieve session: ${event.detailUrl}") val termination = NsiTermination( diff --git a/projects/refer-and-monitor-and-delius/src/main/resources/application.yml b/projects/refer-and-monitor-and-delius/src/main/resources/application.yml index 54a4ccfff9..356d0443ca 100644 --- a/projects/refer-and-monitor-and-delius/src/main/resources/application.yml +++ b/projects/refer-and-monitor-and-delius/src/main/resources/application.yml @@ -60,6 +60,7 @@ seed.database: true wiremock.enabled: true messaging.consumer.queue: message-queue +messaging.consumer.detail.urls: http://localhost:${wiremock.port} oauth2: client-id: refer-and-monitor-and-delius diff --git a/projects/refer-and-monitor-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/FeedbackSubmittedTest.kt b/projects/refer-and-monitor-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/FeedbackSubmittedTest.kt index dd4dbb25ac..9f1b0c6feb 100644 --- a/projects/refer-and-monitor-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/FeedbackSubmittedTest.kt +++ b/projects/refer-and-monitor-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/FeedbackSubmittedTest.kt @@ -8,9 +8,11 @@ import org.junit.jupiter.api.extension.ExtendWith import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.argumentCaptor import org.mockito.kotlin.verify import org.mockito.kotlin.whenever +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.integrations.randm.* import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.PersonIdentifier @@ -18,14 +20,13 @@ import uk.gov.justice.digital.hmpps.message.PersonReference import uk.gov.justice.digital.hmpps.service.AppointmentService import uk.gov.justice.digital.hmpps.service.Attended import uk.gov.justice.digital.hmpps.service.UpdateAppointmentOutcome -import java.net.URI import java.time.ZonedDateTime import java.util.* @ExtendWith(MockitoExtension::class) internal class FeedbackSubmittedTest { @Mock - lateinit var ramClient: ReferAndMonitorClient + lateinit var detailService: DomainEventDetailService @Mock lateinit var appointmentService: AppointmentService @@ -67,7 +68,8 @@ internal class FeedbackSubmittedTest { @Test fun `if appointment not found in supplier assessment, process fails`() { val supplierAssessment = SupplierAssessment(UUID.randomUUID(), listOf(), referralId) - whenever(ramClient.getSupplierAssessment(URI(domainEvent.detailUrl!!))).thenReturn(supplierAssessment) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())) + .thenReturn(supplierAssessment) val result = feedbackSubmitted.initialAppointmentSubmitted(domainEvent) assertThat(result, instanceOf(EventProcessingResult.Failure::class.java)) @@ -89,14 +91,13 @@ internal class FeedbackSubmittedTest { SessionFeedback(null, false) ) ) - whenever(ramClient.getSupplierAssessment(URI(domainEvent.detailUrl!!))) - .thenReturn( - SupplierAssessment( - UUID.randomUUID(), - listOf(appointment), - referralId - ) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenReturn( + SupplierAssessment( + UUID.randomUUID(), + listOf(appointment), + referralId ) + ) val result = feedbackSubmitted.initialAppointmentSubmitted(domainEvent) assertThat(result, instanceOf(EventProcessingResult.Success::class.java)) diff --git a/projects/refer-and-monitor-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/ReferralEndSubmittedTest.kt b/projects/refer-and-monitor-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/ReferralEndSubmittedTest.kt index cbfba4e2f8..93149ada22 100644 --- a/projects/refer-and-monitor-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/ReferralEndSubmittedTest.kt +++ b/projects/refer-and-monitor-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/ReferralEndSubmittedTest.kt @@ -11,11 +11,8 @@ import org.junit.jupiter.params.provider.MethodSource import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.junit.jupiter.MockitoExtension -import org.mockito.kotlin.any -import org.mockito.kotlin.never -import org.mockito.kotlin.verify -import org.mockito.kotlin.whenever -import uk.gov.justice.digital.hmpps.integrations.randm.ReferAndMonitorClient +import org.mockito.kotlin.* +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.PersonIdentifier import uk.gov.justice.digital.hmpps.message.PersonReference @@ -27,7 +24,7 @@ import java.util.* internal class ReferralEndSubmittedTest { @Mock - lateinit var ramClient: ReferAndMonitorClient + lateinit var detailService: DomainEventDetailService @Mock lateinit var nsiService: NsiService @@ -79,7 +76,7 @@ internal class ReferralEndSubmittedTest { ) ) val referral = sentReferral.copy(endRequestedAt = null, concludedAt = null) - whenever(ramClient.getReferral(any())).thenReturn(referral) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(referral) val res = referralEnd.referralEnded(event) assertThat(res, IsInstanceOf(EventProcessingResult.Failure::class.java)) diff --git a/projects/tier-to-delius/deploy/values-dev.yml b/projects/tier-to-delius/deploy/values-dev.yml index c7c61350a3..4774702ad9 100644 --- a/projects/tier-to-delius/deploy/values-dev.yml +++ b/projects/tier-to-delius/deploy/values-dev.yml @@ -11,9 +11,9 @@ generic-service: SENTRY_ENVIRONMENT: dev LOGGING_LEVEL_UK_GOV_DIGITAL_JUSTICE_HMPPS: DEBUG SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/oauth/token - INTEGRATIONS_TIER_URL: http://hmpps-tier.hmpps-tier-dev.svc.cluster.local SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://hmpps-tier-dev.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true diff --git a/projects/tier-to-delius/deploy/values-preprod.yml b/projects/tier-to-delius/deploy/values-preprod.yml index 11c5b4d150..3f722a10ce 100644 --- a/projects/tier-to-delius/deploy/values-preprod.yml +++ b/projects/tier-to-delius/deploy/values-preprod.yml @@ -8,9 +8,9 @@ generic-service: env: SENTRY_ENVIRONMENT: preprod SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/oauth/token - INTEGRATIONS_TIER_URL: http://hmpps-tier.hmpps-tier-preprod.svc.cluster.local SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://hmpps-tier-preprod.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/tier-to-delius/deploy/values-prod.yml b/projects/tier-to-delius/deploy/values-prod.yml index f3100d768e..31db9c0ea0 100644 --- a/projects/tier-to-delius/deploy/values-prod.yml +++ b/projects/tier-to-delius/deploy/values-prod.yml @@ -5,6 +5,6 @@ generic-service: env: SENTRY_ENVIRONMENT: prod SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/oauth/token - INTEGRATIONS_TIER_URL: http://hmpps-tier.hmpps-tier-prod.svc.cluster.local SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/.well-known/jwks.json - SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer \ No newline at end of file + SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer + MESSAGING_CONSUMER_DETAIL_URLS: https://hmpps-tier.hmpps.service.justice.gov.uk diff --git a/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt b/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt deleted file mode 100644 index f879eaeb61..0000000000 --- a/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt +++ /dev/null @@ -1,14 +0,0 @@ -package uk.gov.justice.digital.hmpps.config - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.client.RestClient -import uk.gov.justice.digital.hmpps.config.security.createClient -import uk.gov.justice.digital.hmpps.integrations.tier.TierClient - -@Configuration -class RestClientConfig(private val oauth2Client: RestClient) { - - @Bean - fun tierClient() = createClient(oauth2Client) -} diff --git a/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/tier/TierClient.kt b/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/tier/TierClient.kt deleted file mode 100644 index d13d891b43..0000000000 --- a/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/tier/TierClient.kt +++ /dev/null @@ -1,9 +0,0 @@ -package uk.gov.justice.digital.hmpps.integrations.tier - -import org.springframework.web.service.annotation.GetExchange -import java.net.URI - -interface TierClient { - @GetExchange - fun getTierCalculation(baseUrl: URI): TierCalculation -} diff --git a/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index 2d664ac065..6af5b1e58e 100644 --- a/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -6,20 +6,19 @@ import com.asyncapi.kotlinasyncapi.annotation.channel.Publish import org.springframework.stereotype.Component import org.springframework.web.client.HttpClientErrorException import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.integrations.tier.TierCalculation -import uk.gov.justice.digital.hmpps.integrations.tier.TierClient import uk.gov.justice.digital.hmpps.integrations.tier.TierService import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.telemetry.TelemetryMessagingExtensions.notificationReceived import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI @Component @Channel("tier-to-delius-queue") class Handler( private val telemetryService: TelemetryService, - private val tierClient: TierClient, + private val detailService: DomainEventDetailService, private val tierService: TierService, override val converter: NotificationConverter ) : NotificationHandler { @@ -29,7 +28,7 @@ class Handler( val crn = requireNotNull(notification.message.personReference.findCrn()) val detailUrl = requireNotNull(notification.message.detailUrl) val tierCalculation = try { - tierClient.getTierCalculation(URI.create(detailUrl)) + detailService.getDetail(notification.message) } catch (e: HttpClientErrorException.NotFound) { telemetryService.trackEvent("TierCalculationNotFound", mapOf("crn" to crn, "detailUrl" to detailUrl)) return diff --git a/projects/tier-to-delius/src/main/resources/application.yml b/projects/tier-to-delius/src/main/resources/application.yml index e95a7a502a..8ccf582a7d 100644 --- a/projects/tier-to-delius/src/main/resources/application.yml +++ b/projects/tier-to-delius/src/main/resources/application.yml @@ -56,7 +56,7 @@ seed.database: true wiremock.enabled: true messaging.consumer.queue: message-queue -integrations.tier.url: http://localhost:${wiremock.port}/hmpps-tier +messaging.consumer.detail.urls: http://localhost:${wiremock.port} oauth2: client-id: tier-to-delius diff --git a/projects/tier-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt b/projects/tier-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt index 72edcda053..6bbdd071e6 100644 --- a/projects/tier-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt +++ b/projects/tier-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt @@ -5,17 +5,17 @@ import org.junit.jupiter.api.extension.ExtendWith import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.integrations.tier.TierCalculation -import uk.gov.justice.digital.hmpps.integrations.tier.TierClient import uk.gov.justice.digital.hmpps.integrations.tier.TierService import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.prepMessage import uk.gov.justice.digital.hmpps.telemetry.TelemetryMessagingExtensions.notificationReceived import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI import java.time.ZonedDateTime.now @ExtendWith(MockitoExtension::class) @@ -24,7 +24,7 @@ internal class HandlerTest { lateinit var telemetryService: TelemetryService @Mock - lateinit var tierClient: TierClient + lateinit var detailService: DomainEventDetailService @Mock lateinit var tierService: TierService @@ -41,16 +41,14 @@ internal class HandlerTest { val message = prepMessage("tier-calculation", 1234) // And a calculation val calculation = TierCalculation("someScore", "calculationId", now()) - whenever(tierClient.getTierCalculation(URI.create("http://localhost:1234/hmpps-tier/crn/A000001/tier/123e4567-e89b-12d3-a456-426614174000"))).thenReturn( - calculation - ) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(calculation) // When the message is received handler.handle(message) // Then it is updated in Delius and logged to Telemetry verify(telemetryService).notificationReceived(message) - verify(tierClient).getTierCalculation(URI.create("http://localhost:1234/hmpps-tier/crn/A000001/tier/123e4567-e89b-12d3-a456-426614174000")) + verify(detailService).getDetail(anyOrNull(), anyOrNull()) verify(tierService).updateTier("A000001", calculation) verify(telemetryService).trackEvent("TierUpdateSuccess", calculation.telemetryProperties("A000001")) } diff --git a/projects/unpaid-work-and-delius/deploy/values-dev.yml b/projects/unpaid-work-and-delius/deploy/values-dev.yml index ea9cd445a7..3842747dd4 100644 --- a/projects/unpaid-work-and-delius/deploy/values-dev.yml +++ b/projects/unpaid-work-and-delius/deploy/values-dev.yml @@ -13,6 +13,7 @@ generic-service: SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer INTEGRATIONS_ALFRESCO_URL: https://hmpps-delius-alfresco-test.apps.live.cloud-platform.service.justice.gov.uk/alfresco/service/noms-spg/ + MESSAGING_CONSUMER_DETAIL_URLS: https://dev.hmpps-assessments.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true diff --git a/projects/unpaid-work-and-delius/deploy/values-preprod.yml b/projects/unpaid-work-and-delius/deploy/values-preprod.yml index e4e42b1201..491892f21f 100644 --- a/projects/unpaid-work-and-delius/deploy/values-preprod.yml +++ b/projects/unpaid-work-and-delius/deploy/values-preprod.yml @@ -12,6 +12,7 @@ generic-service: SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer INTEGRATIONS_ALFRESCO_URL: https://alfresco.pre-prod.delius.probation.hmpps.dsd.io/alfresco/service/noms-spg/ + MESSAGING_CONSUMER_DETAIL_URLS: https://preprod.hmpps-assessments.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/unpaid-work-and-delius/deploy/values-prod.yml b/projects/unpaid-work-and-delius/deploy/values-prod.yml index 85c93c69d6..4df32a7417 100644 --- a/projects/unpaid-work-and-delius/deploy/values-prod.yml +++ b/projects/unpaid-work-and-delius/deploy/values-prod.yml @@ -9,3 +9,4 @@ generic-service: SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer INTEGRATIONS_ALFRESCO_URL: https://alfresco.probation.service.justice.gov.uk/alfresco/service/noms-spg/ + MESSAGING_CONSUMER_DETAIL_URLS: https://hmpps-assessments.service.justice.gov.uk diff --git a/projects/unpaid-work-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt b/projects/unpaid-work-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt index df316f8cef..c59c2a8541 100644 --- a/projects/unpaid-work-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt +++ b/projects/unpaid-work-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt @@ -5,14 +5,9 @@ import org.springframework.context.annotation.Configuration import org.springframework.web.client.RestClient import uk.gov.justice.digital.hmpps.config.security.createClient import uk.gov.justice.digital.hmpps.integrations.alfresco.AlfrescoUploadClient -import uk.gov.justice.digital.hmpps.integrations.arn.ArnClient @Configuration -class RestClientConfig(private val oauth2Client: RestClient) { - - @Bean - fun arnClient() = createClient(oauth2Client) - +class RestClientConfig { @Bean fun alfrescoUploadClient(alfrescoRestClient: RestClient) = createClient(alfrescoRestClient) } diff --git a/projects/unpaid-work-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/arn/ArnClient.kt b/projects/unpaid-work-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/arn/ArnClient.kt deleted file mode 100644 index a8e2c01781..0000000000 --- a/projects/unpaid-work-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/arn/ArnClient.kt +++ /dev/null @@ -1,10 +0,0 @@ -package uk.gov.justice.digital.hmpps.integrations.arn - -import org.springframework.http.ResponseEntity -import org.springframework.web.service.annotation.GetExchange -import java.net.URI - -interface ArnClient { - @GetExchange - fun getUPWAssessment(baseUrl: URI): ResponseEntity -} diff --git a/projects/unpaid-work-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/upwassessment/UPWAssessmentService.kt b/projects/unpaid-work-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/upwassessment/UPWAssessmentService.kt index 690e0a7bfa..f8d33c4ca5 100644 --- a/projects/unpaid-work-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/upwassessment/UPWAssessmentService.kt +++ b/projects/unpaid-work-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/upwassessment/UPWAssessmentService.kt @@ -4,15 +4,14 @@ import org.springframework.dao.DataIntegrityViolationException import org.springframework.http.HttpStatus import org.springframework.stereotype.Service import uk.gov.justice.digital.hmpps.controller.casedetails.entity.EventRepository +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exception.NotFoundException -import uk.gov.justice.digital.hmpps.integrations.arn.ArnClient import uk.gov.justice.digital.hmpps.integrations.common.entity.person.PersonWithManager import uk.gov.justice.digital.hmpps.integrations.common.entity.person.PersonWithManagerRepository import uk.gov.justice.digital.hmpps.integrations.document.DocumentService import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI @Service class UPWAssessmentService( @@ -20,7 +19,7 @@ class UPWAssessmentService( private val documentService: DocumentService, private val personWithManagerRepository: PersonWithManagerRepository, private val eventRepository: EventRepository, - private val arnClient: ArnClient + private val domainEventDetailService: DomainEventDetailService, ) { fun HmppsDomainEvent.episodeId() = additionalInformation["episodeId"] as String @@ -37,7 +36,7 @@ class UPWAssessmentService( private fun uploadDocument(notification: Notification, person: PersonWithManager, eventId: Long) { // get the episode id from the message then get the document content from the UPW/ARN Service val episodeId = notification.message.episodeId() - val response = arnClient.getUPWAssessment(URI(notification.message.detailUrl!!)) + val response = domainEventDetailService.getDetailResponse(notification.message) val reg = Regex("[^A-Za-z0-9-. ]") val filename = "${person.forename}-${person.surname}-${person.crn}-UPW.pdf".replace(reg, "") val fileData = response.body @@ -47,7 +46,7 @@ class UPWAssessmentService( try { documentService.createDeliusDocument( notification.message, - fileData!!, + fileData, filename, episodeId, person, diff --git a/projects/unpaid-work-and-delius/src/main/resources/application.yml b/projects/unpaid-work-and-delius/src/main/resources/application.yml index 2c8ec41af0..7be188c996 100644 --- a/projects/unpaid-work-and-delius/src/main/resources/application.yml +++ b/projects/unpaid-work-and-delius/src/main/resources/application.yml @@ -55,6 +55,7 @@ seed.database: true wiremock.enabled: true messaging.consumer.queue: message-queue +messaging.consumer.detail.urls: http://localhost:${wiremock.port} integrations: alfresco: diff --git a/projects/unpaid-work-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/UPWAssessmentServiceTest.kt b/projects/unpaid-work-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/UPWAssessmentServiceTest.kt index 218ca74798..7574b22777 100644 --- a/projects/unpaid-work-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/UPWAssessmentServiceTest.kt +++ b/projects/unpaid-work-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/UPWAssessmentServiceTest.kt @@ -8,6 +8,7 @@ import org.junit.jupiter.api.extension.ExtendWith import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import org.springframework.http.HttpHeaders @@ -16,8 +17,8 @@ import org.springframework.http.ResponseEntity import uk.gov.justice.digital.hmpps.controller.casedetails.entity.EventRepository import uk.gov.justice.digital.hmpps.data.generator.CaseGenerator import uk.gov.justice.digital.hmpps.data.generator.EventGenerator +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exception.NotFoundException -import uk.gov.justice.digital.hmpps.integrations.arn.ArnClient import uk.gov.justice.digital.hmpps.integrations.common.entity.contact.ContactRepository import uk.gov.justice.digital.hmpps.integrations.common.entity.contact.type.ContactTypeRepository import uk.gov.justice.digital.hmpps.integrations.common.entity.person.PersonManager @@ -29,7 +30,6 @@ import uk.gov.justice.digital.hmpps.integrations.document.DocumentService import uk.gov.justice.digital.hmpps.integrations.upwassessment.UPWAssessmentService import uk.gov.justice.digital.hmpps.prepEvent import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI @ExtendWith(MockitoExtension::class) internal class UPWAssessmentServiceTest { @@ -56,7 +56,7 @@ internal class UPWAssessmentServiceTest { private lateinit var documentService: DocumentService @Mock - private lateinit var arnClient: ArnClient + private lateinit var detailService: DomainEventDetailService @Mock private lateinit var staff: Staff @@ -103,7 +103,7 @@ internal class UPWAssessmentServiceTest { whenever(eventRepository.existsById(EventGenerator.DEFAULT.id)).thenReturn(true) val notification = prepEvent("upw-assessment-complete", 1234) - whenever(arnClient.getUPWAssessment(URI(notification.message.detailUrl!!))).thenReturn( + whenever(detailService.getDetailResponse(anyOrNull(), anyOrNull())).thenReturn( ResponseEntity.status(HttpStatus.OK) .headers { it[HttpHeaders.CONTENT_DISPOSITION] = listOf("filename=upw-assessment.pdf") } .body( diff --git a/projects/workforce-allocations-to-delius/deploy/values-dev.yml b/projects/workforce-allocations-to-delius/deploy/values-dev.yml index 3e97bf124a..ed1928a3e4 100644 --- a/projects/workforce-allocations-to-delius/deploy/values-dev.yml +++ b/projects/workforce-allocations-to-delius/deploy/values-dev.yml @@ -12,6 +12,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/.well-known/jwks.json INTEGRATIONS_ALFRESCO_URL: https://hmpps-delius-alfresco-test.apps.live.cloud-platform.service.justice.gov.uk/alfresco/service/noms-spg/ + MESSAGING_CONSUMER_DETAIL_URLS: https://hmpps-workload-dev.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true diff --git a/projects/workforce-allocations-to-delius/deploy/values-preprod.yml b/projects/workforce-allocations-to-delius/deploy/values-preprod.yml index 060868a141..948468721f 100644 --- a/projects/workforce-allocations-to-delius/deploy/values-preprod.yml +++ b/projects/workforce-allocations-to-delius/deploy/values-preprod.yml @@ -10,6 +10,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/.well-known/jwks.json INTEGRATIONS_ALFRESCO_URL: https://alfresco.pre-prod.delius.probation.hmpps.dsd.io/alfresco/service/noms-spg/ + MESSAGING_CONSUMER_DETAIL_URLS: https://hmpps-workload-preprod.hmpps.service.justice.gov.uk generic-prometheus-alerts: businessHoursOnly: true diff --git a/projects/workforce-allocations-to-delius/deploy/values-prod.yml b/projects/workforce-allocations-to-delius/deploy/values-prod.yml index e3a95af427..490bc89ec3 100644 --- a/projects/workforce-allocations-to-delius/deploy/values-prod.yml +++ b/projects/workforce-allocations-to-delius/deploy/values-prod.yml @@ -13,6 +13,7 @@ generic-service: SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/oauth/token SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/.well-known/jwks.json INTEGRATIONS_ALFRESCO_URL: https://alfresco.probation.service.justice.gov.uk/alfresco/service/noms-spg/ + MESSAGING_CONSUMER_DETAIL_URLS: https://hmpps-workload.hmpps.service.justice.gov.uk initial-allocations-report: enabled: true diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt deleted file mode 100644 index 60fb981188..0000000000 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt +++ /dev/null @@ -1,14 +0,0 @@ -package uk.gov.justice.digital.hmpps.config - -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.client.RestClient -import uk.gov.justice.digital.hmpps.config.security.createClient -import uk.gov.justice.digital.hmpps.integrations.workforceallocations.WorkforceAllocationsClient - -@Configuration -class RestClientConfig(private val oauth2Client: RestClient) { - - @Bean - fun workforceAllocationsClient() = createClient(oauth2Client) -} diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/workforceallocations/WorkforceAllocationsClient.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/workforceallocations/WorkforceAllocationsClient.kt deleted file mode 100644 index 55fdbc230d..0000000000 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/workforceallocations/WorkforceAllocationsClient.kt +++ /dev/null @@ -1,9 +0,0 @@ -package uk.gov.justice.digital.hmpps.integrations.workforceallocations - -import org.springframework.web.service.annotation.GetExchange -import java.net.URI - -interface WorkforceAllocationsClient { - @GetExchange - fun getAllocationDetail(baseUrl: URI): AllocationDetail -} diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index 7b01ba7974..d039baa0fa 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -5,21 +5,21 @@ import com.asyncapi.kotlinasyncapi.annotation.channel.Message import com.asyncapi.kotlinasyncapi.annotation.channel.Publish import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException +import uk.gov.justice.digital.hmpps.integrations.workforceallocations.AllocationDetail import uk.gov.justice.digital.hmpps.integrations.workforceallocations.AllocationDetail.* -import uk.gov.justice.digital.hmpps.integrations.workforceallocations.WorkforceAllocationsClient import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.service.AllocateEventService import uk.gov.justice.digital.hmpps.service.AllocatePersonService import uk.gov.justice.digital.hmpps.service.AllocateRequirementService import uk.gov.justice.digital.hmpps.telemetry.TelemetryService -import java.net.URI.create @Component @Channel("workforce-allocations-to-delius-queue") class Handler( - private val allocationsClient: WorkforceAllocationsClient, + private val detailService: DomainEventDetailService, private val allocatePersonService: AllocatePersonService, private val allocateEventService: AllocateEventService, private val allocateRequirementService: AllocateRequirementService, @@ -35,8 +35,7 @@ class Handler( ) override fun handle(notification: Notification) { val allocationEvent = notification.message - val detailUrl = allocationEvent.detailUrl ?: return - val allocationDetail = allocationsClient.getAllocationDetail(create(detailUrl)) + val allocationDetail: AllocationDetail = detailService.getDetail(allocationEvent) try { when (allocationDetail) { is PersonAllocation -> allocatePersonService.createPersonAllocation(allocationDetail) @@ -52,7 +51,7 @@ class Handler( } telemetryService.trackEvent( allocationDetail::class.simpleName!!, - mapOf("crn" to allocationEvent.findCrn(), "detailUrl" to detailUrl) + mapOf("crn" to allocationEvent.findCrn(), "detailUrl" to allocationEvent.detailUrl!!) ) } catch (ex: IgnorableMessageException) { telemetryService.trackEvent( diff --git a/projects/workforce-allocations-to-delius/src/main/resources/application.yml b/projects/workforce-allocations-to-delius/src/main/resources/application.yml index 03c0963012..9e6eeb4811 100644 --- a/projects/workforce-allocations-to-delius/src/main/resources/application.yml +++ b/projects/workforce-allocations-to-delius/src/main/resources/application.yml @@ -63,6 +63,7 @@ seed.database: true wiremock.enabled: true messaging.consumer.queue: workforce-allocations-events +messaging.consumer.detail.urls: http://localhost:${wiremock.port} integrations: workforce-allocations: diff --git a/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt b/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt index d7bd1dac7e..b07a4b0caa 100644 --- a/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt +++ b/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt @@ -6,14 +6,11 @@ import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.Mockito.mock import org.mockito.junit.jupiter.MockitoExtension -import org.mockito.kotlin.any -import org.mockito.kotlin.eq -import org.mockito.kotlin.verify -import org.mockito.kotlin.whenever +import org.mockito.kotlin.* import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException import uk.gov.justice.digital.hmpps.integrations.workforceallocations.AllocationDetail -import uk.gov.justice.digital.hmpps.integrations.workforceallocations.WorkforceAllocationsClient import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.message.PersonIdentifier @@ -27,7 +24,7 @@ import uk.gov.justice.digital.hmpps.telemetry.TelemetryService internal class HandlerTest { @Mock - internal lateinit var allocationsClient: WorkforceAllocationsClient + internal lateinit var detailService: DomainEventDetailService @Mock internal lateinit var allocatePersonService: AllocatePersonService @@ -55,7 +52,7 @@ internal class HandlerTest { val allocationDetail = mock() whenever(allocationEvent.personReference).thenReturn(PersonReference(listOf(PersonIdentifier("CRN", crn)))) whenever(allocationEvent.detailUrl).thenReturn("https://some-url") - whenever(allocationsClient.getAllocationDetail(any())).thenReturn(allocationDetail) + whenever(detailService.getDetail(anyOrNull(), anyOrNull())).thenReturn(allocationDetail) whenever( allocateEventService.createEventAllocation( crn, diff --git a/templates/projects/message-listener-with-api-client-and-server/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt b/templates/projects/message-listener-with-api-client-and-server/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt index d81e4461ed..278ffdcd8a 100644 --- a/templates/projects/message-listener-with-api-client-and-server/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt +++ b/templates/projects/message-listener-with-api-client-and-server/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt @@ -11,11 +11,6 @@ import uk.gov.justice.digital.hmpps.integrations.example.ExampleClient class RestClientConfig(private val oauth2Client: RestClient) { @Bean - fun exampleClient(@Value("\${integrations.example.url}") apiBaseUrl: String): ExampleClient { - return createClient( - oauth2Client.mutate() - .baseUrl(apiBaseUrl) - .build() - ) - } + fun exampleClient(@Value("\${integrations.example.url}") apiBaseUrl: String) = + createClient(oauth2Client.mutate().baseUrl(apiBaseUrl).build()) } diff --git a/templates/projects/message-listener-with-api-client-and-server/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/templates/projects/message-listener-with-api-client-and-server/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index 200d8a08f2..7f42a0532f 100644 --- a/templates/projects/message-listener-with-api-client-and-server/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/templates/projects/message-listener-with-api-client-and-server/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -4,6 +4,7 @@ import com.asyncapi.kotlinasyncapi.annotation.channel.Channel import com.asyncapi.kotlinasyncapi.annotation.channel.Publish import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.telemetry.TelemetryService diff --git a/templates/projects/message-listener-with-api-client-and-server/src/main/resources/application.yml b/templates/projects/message-listener-with-api-client-and-server/src/main/resources/application.yml index 9fe9f886cc..2588cf7a06 100644 --- a/templates/projects/message-listener-with-api-client-and-server/src/main/resources/application.yml +++ b/templates/projects/message-listener-with-api-client-and-server/src/main/resources/application.yml @@ -55,6 +55,7 @@ seed.database: true wiremock.enabled: true messaging.consumer.queue: message-queue +messaging.consumer.detail.urls: http://localhost:${wiremock.port} integrations: example: diff --git a/templates/projects/message-listener-with-api-client/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt b/templates/projects/message-listener-with-api-client/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt index d81e4461ed..278ffdcd8a 100644 --- a/templates/projects/message-listener-with-api-client/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt +++ b/templates/projects/message-listener-with-api-client/src/main/kotlin/uk/gov/justice/digital/hmpps/config/RestClientConfig.kt @@ -11,11 +11,6 @@ import uk.gov.justice.digital.hmpps.integrations.example.ExampleClient class RestClientConfig(private val oauth2Client: RestClient) { @Bean - fun exampleClient(@Value("\${integrations.example.url}") apiBaseUrl: String): ExampleClient { - return createClient( - oauth2Client.mutate() - .baseUrl(apiBaseUrl) - .build() - ) - } + fun exampleClient(@Value("\${integrations.example.url}") apiBaseUrl: String) = + createClient(oauth2Client.mutate().baseUrl(apiBaseUrl).build()) } diff --git a/templates/projects/message-listener-with-api-client/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/templates/projects/message-listener-with-api-client/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index 53d91011c0..5742a1f4e6 100644 --- a/templates/projects/message-listener-with-api-client/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/templates/projects/message-listener-with-api-client/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -4,6 +4,7 @@ import com.asyncapi.kotlinasyncapi.annotation.channel.Channel import com.asyncapi.kotlinasyncapi.annotation.channel.Publish import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.detail.DomainEventDetailService import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.telemetry.TelemetryService @@ -13,6 +14,7 @@ import uk.gov.justice.digital.hmpps.telemetry.TelemetryMessagingExtensions.notif @Channel("$SERVICE_NAME-queue") class Handler( override val converter: NotificationConverter, + private val domainEventDetailService: DomainEventDetailService, private val telemetryService: TelemetryService ) : NotificationHandler { @Publish( diff --git a/templates/projects/message-listener-with-api-client/src/main/resources/application.yml b/templates/projects/message-listener-with-api-client/src/main/resources/application.yml index 53b104452f..7f5cbaea33 100644 --- a/templates/projects/message-listener-with-api-client/src/main/resources/application.yml +++ b/templates/projects/message-listener-with-api-client/src/main/resources/application.yml @@ -50,6 +50,7 @@ seed.database: true wiremock.enabled: true messaging.consumer.queue: message-queue +messaging.consumer.detail.urls: http://localhost:${wiremock.port} integrations: example: