Skip to content

Commit ebcb1fe

Browse files
authored
PI-1284 Migrate prison-to-probation-update listener to prison-identifier-and-delius (#3478)
1 parent c85cfc5 commit ebcb1fe

File tree

61 files changed

+1729
-580
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1729
-580
lines changed

libs/dev-tools/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/HmppsDevQueue.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import uk.gov.justice.digital.hmpps.publisher.NotificationPublisher
1212
import java.time.Duration
1313
import java.time.LocalDateTime
1414
import java.time.LocalTime
15-
import java.util.LinkedList
16-
import java.util.Queue
17-
import java.util.UUID
15+
import java.util.*
1816
import java.util.concurrent.TimeUnit
1917
import java.util.concurrent.TimeoutException
2018
import java.util.concurrent.locks.ReentrantLock
@@ -139,7 +137,7 @@ class HmppsNotificationListener(
139137

140138
@Component
141139
@ConditionalOnProperty("messaging.producer.topic")
142-
class HmppsNotificationPublisher(
140+
class TopicPublisher(
143141
@Value("\${messaging.producer.topic}") private val topicName: String,
144142
private val channelManager: HmppsChannelManager
145143
) : NotificationPublisher {
@@ -150,7 +148,7 @@ class HmppsNotificationPublisher(
150148

151149
@Component
152150
@ConditionalOnProperty("messaging.producer.queue")
153-
class HmppsQueuePublisher(
151+
class QueuePublisher(
154152
@Value("\${messaging.producer.queue}") private val queueName: String,
155153
private val channelManager: HmppsChannelManager
156154
) : NotificationPublisher {

libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/publisher/AwsQueuePublisher.kt renamed to libs/messaging/src/main/kotlin/uk/gov/justice/digital/hmpps/publisher/QueuePublisher.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import java.util.concurrent.Semaphore
1515
@Component
1616
@Conditional(AwsCondition::class)
1717
@ConditionalOnProperty("messaging.producer.queue")
18-
class AwsQueuePublisher(
18+
class QueuePublisher(
1919
private val sqsTemplate: SqsTemplate,
2020
private val objectMapper: ObjectMapper,
2121
@Value("\${messaging.producer.queue}") private val queue: String,
+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import uk.gov.justice.digital.hmpps.message.Notification
1515
@Component
1616
@Conditional(AwsCondition::class)
1717
@ConditionalOnProperty("messaging.producer.topic")
18-
class AwsNotificationPublisher(
18+
class TopicPublisher(
1919
private val notificationTemplate: SnsTemplate,
2020
@Value("\${messaging.producer.topic}") private val topic: String
2121
) : NotificationPublisher {
+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import uk.gov.justice.digital.hmpps.message.MessageAttributes
2020
import uk.gov.justice.digital.hmpps.message.Notification
2121

2222
@ExtendWith(MockitoExtension::class)
23-
class AwsNotificationPublisherTest {
23+
class TopicPublisherTest {
2424

2525
@Mock
2626
lateinit var notificationTemplate: SnsTemplate
@@ -29,7 +29,7 @@ class AwsNotificationPublisherTest {
2929

3030
@BeforeEach
3131
fun setup() {
32-
publisher = AwsNotificationPublisher(notificationTemplate, "my-topic")
32+
publisher = TopicPublisher(notificationTemplate, "my-topic")
3333
}
3434

3535
@Test

projects/prison-identifier-and-delius/README.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,22 @@ HMPPS has a number of systems each holding information about a person's interact
1414

1515
The matching process can be triggered by a request to the integration service API endpoint
1616

17-
| Business Event | API Endpoint |
18-
|-----------------------|------------------------------|
19-
| List of CRNs to Match | /person/populate-noms-number |
17+
| Business Event | API Endpoint |
18+
|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
19+
| List of CRNs to Match | [/person/match-by-crn](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/prison-identifier-and-delius/api-reference.html#person-match-by-crn) |
20+
| List of NOMIS IDs to Match | [/person/match-by-noms](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/prison-identifier-and-delius/api-reference.html#person-match-by-noms) |
2021

21-
### Domain Event Processing (Not Yet Implemented)
22+
### Domain Event Processing
2223

2324
The matching process will be triggered by domain events raised by Delius, once these events are implemented
2425

25-
| Business Event | Message Event Type / Filter |
26-
|------------------------------------|---------------------------------|
27-
| New Sentence Added to Delius | probation-case.sentence.created |
28-
| Sentence Changed in Delius | probation-case.sentence.amended |
29-
| Sentence Moved to New Delius Event | probation-case.sentence.move |
26+
| Business Event | Message Event Type / Filter | Status |
27+
|------------------------------------|------------------------------------------|---------------------|
28+
| New Sentence Added to Delius | probation-case.sentence.created | Not yet implemented |
29+
| Sentence Changed in Delius | probation-case.sentence.amended | Not yet implemented |
30+
| Sentence Moved to New Delius Event | probation-case.sentence.move | Not yet implemented |
31+
| Prisoner received into NOMIS | prison-offender-events.prisoner.received | Active |
32+
| Prisoner merged in NOMIS | prison-offender-events.prisoner.merged | Active |
3033

3134
## Workflows
3235

@@ -41,8 +44,8 @@ The matching process will be triggered by domain events raised by Delius, once t
4144
API endpoints are secured by roles supplied by the HMPPS Auth client used in
4245
the requests
4346

44-
| API Endpoint | Required Role |
45-
|--------------|-------------------------------------------------|
47+
| API Endpoint | Required Role |
48+
|--------------|--------------------------------------------------|
4649
| All | ROLE\_PROBATION\_API_\_PRISON_IDENTIFIER__UPDATE |
4750

4851
## Concepts

projects/prison-identifier-and-delius/deploy/database/access.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ database:
33
username_key: /prison-identifier-and-delius/db-username
44
password_key: /prison-identifier-and-delius/db-password
55
tables:
6-
- offender
6+
- additional_identifier
77
- custody
8+
- offender
9+
- offender_prisoner
810

911
audit:
1012
username: PrisonIdentifierAndDelius

projects/prison-identifier-and-delius/deploy/templates/update-noms-numbers.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
args:
2121
- /bin/sh
2222
- -c
23-
- 'curl -fsSL -X POST "https://$BASE_URL/person/populate-noms-number?dryRun=$DRY_RUN" --header "Authorization: Bearer $(curl -fsSL --request POST "$AUTH_URL?grant_type=client_credentials" --user "$CLIENT_ID:$CLIENT_SECRET" | jq -r .access_token)" --header "Content-Type: application/json"'
23+
- 'curl -fsSL -X POST "https://$BASE_URL/person/match-by-crn?dryRun=$DRY_RUN" --header "Authorization: Bearer $(curl -fsSL --request POST "$AUTH_URL?grant_type=client_credentials" --user "$CLIENT_ID:$CLIENT_SECRET" | jq -r .access_token)" --header "Content-Type: application/json"'
2424
env:
2525
- name: AUTH_URL
2626
value: {{ index .Values "generic-service" "env" "SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI" }}

projects/prison-identifier-and-delius/deploy/values-dev.yml

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ generic-service:
1010
SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/oauth/token
1111
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-dev.svc.cluster.local/auth/.well-known/jwks.json
1212

13+
INTEGRATIONS_PRISON-API_URL: https://prison-api-dev.prison.service.justice.gov.uk
1314
INTEGRATIONS_PRISONER-SEARCH_URL: https://prisoner-search-dev.prison.service.justice.gov.uk
15+
INTEGRATIONS_PROBATION-SEARCH_URL: https://probation-offender-search-dev.hmpps.service.justice.gov.uk
1416

1517
SPRING_DATASOURCE_HIKARI_MAXIMUMPOOLSIZE: 5
1618
SPRING_DATASOURCE_HIKARI_MINIMUMIDLE: 0

projects/prison-identifier-and-delius/deploy/values-preprod.yml

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ generic-service:
1010
SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/oauth/token
1111
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-preprod.svc.cluster.local/auth/.well-known/jwks.json
1212

13+
INTEGRATIONS_PRISON-API_URL: https://prison-api-preprod.prison.service.justice.gov.uk
1314
INTEGRATIONS_PRISONER-SEARCH_URL: https://prisoner-search-preprod.prison.service.justice.gov.uk
15+
INTEGRATIONS_PROBATION-SEARCH_URL: https://probation-offender-search-preprod.hmpps.service.justice.gov.uk
1416

1517
generic-prometheus-alerts:
1618
businessHoursOnly: true

projects/prison-identifier-and-delius/deploy/values-prod.yml

+2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ generic-service:
77
SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_HMPPS-AUTH_TOKEN-URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/oauth/token
88
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: http://hmpps-auth.hmpps-auth-prod.svc.cluster.local/auth/.well-known/jwks.json
99

10+
INTEGRATIONS_PRISON-API_URL: https://api.prison.service.justice.gov.uk
1011
INTEGRATIONS_PRISONER-SEARCH_URL: https://prisoner-search.prison.service.justice.gov.uk
12+
INTEGRATIONS_PROBATION-SEARCH_URL: https://probation-offender-search.hmpps.service.justice.gov.uk
1113

1214
noms:
1315
update:

projects/prison-identifier-and-delius/deploy/values.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ generic-service:
2626
prison-identifier-and-delius-queue:
2727
MESSAGING_CONSUMER_QUEUE: QUEUE_NAME
2828
MESSAGING_PRODUCER_QUEUE: QUEUE_NAME
29+
hmpps-domain-events-topic:
30+
MESSAGING_PRODUCER_TOPIC: topic_arn
2931

3032
generic-prometheus-alerts:
3133
targetApplication: prison-identifier-and-delius

projects/prison-identifier-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt

+15-19
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
1111
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.generateCustody
1212
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.generateDisposal
1313
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.generateEvent
14+
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator
1415
import uk.gov.justice.digital.hmpps.data.generator.UserGenerator
1516
import uk.gov.justice.digital.hmpps.user.AuditUserRepository
1617
import java.time.LocalDate
17-
import java.time.format.DateTimeFormatter
1818

1919
@Component
2020
@ConditionalOnProperty("seed.database")
@@ -31,44 +31,40 @@ class DataLoader(
3131
@Transactional
3232
override fun onApplicationEvent(are: ApplicationReadyEvent) {
3333
val personWithNomsEvent = generateEvent(PersonGenerator.PERSON_WITH_NOMS)
34-
val personWithNomsDisposal = generateDisposal(LocalDate.now(), personWithNomsEvent)
34+
val personWithNomsDisposal = generateDisposal(LocalDate.of(2022, 11, 11), personWithNomsEvent)
3535
val personWithNomsCustody = generateCustody(personWithNomsDisposal)
3636

3737
val personWithNoNomsNumberEvent = generateEvent(PersonGenerator.PERSON_WITH_NO_NOMS)
38-
val personWithNoNomsNumberDisposal = generateDisposal(
39-
LocalDate.parse("12/12/2022", DateTimeFormatter.ofPattern("MM/dd/yyyy")),
40-
personWithNoNomsNumberEvent
41-
)
38+
val personWithNoNomsNumberDisposal = generateDisposal(LocalDate.of(2022, 12, 12), personWithNoNomsNumberEvent)
4239
val personWithNoNomsNumberCustody = generateCustody(personWithNoNomsNumberDisposal)
4340

4441
val personWithMultiMatchEvent = generateEvent(PersonGenerator.PERSON_WITH_MULTI_MATCH)
45-
val personWithMultiMatchDisposal = generateDisposal(
46-
LocalDate.parse("12/12/2022", DateTimeFormatter.ofPattern("MM/dd/yyyy")),
47-
personWithMultiMatchEvent
48-
)
42+
val personWithMultiMatchDisposal = generateDisposal(LocalDate.of(2022, 12, 12), personWithMultiMatchEvent)
4943
val personWithMultiMatchCustody = generateCustody(personWithMultiMatchDisposal)
5044

5145
val personWithNoMatchEvent = generateEvent(PersonGenerator.PERSON_WITH_NO_MATCH)
52-
val personWithNoMatchDisposal = generateDisposal(
53-
LocalDate.parse("12/12/2022", DateTimeFormatter.ofPattern("MM/dd/yyyy")),
54-
personWithNoMatchEvent
55-
)
46+
val personWithNoMatchDisposal = generateDisposal(LocalDate.of(2022, 12, 12), personWithNoMatchEvent)
5647
val personWithNoMatchCustody = generateCustody(personWithNoMatchDisposal)
5748

5849
val personWithNomsInDeliusEvent = generateEvent(PersonGenerator.PERSON_WITH_NOMS_IN_DELIUS)
59-
val personWithNomsInDeliusDisposal = generateDisposal(
60-
LocalDate.parse("12/12/2022", DateTimeFormatter.ofPattern("MM/dd/yyyy")),
61-
personWithNomsInDeliusEvent
62-
)
50+
val personWithNomsInDeliusDisposal = generateDisposal(LocalDate.of(2022, 12, 12), personWithNomsInDeliusEvent)
6351
val personWithNomsInDeliusCustody = generateCustody(personWithNomsInDeliusDisposal)
6452

6553
em.saveAll(
66-
PersonGenerator.MALE,
54+
ReferenceDataGenerator.GENDER_SET,
55+
ReferenceDataGenerator.MALE,
56+
ReferenceDataGenerator.CUSTODY_STATUS_SET,
57+
ReferenceDataGenerator.CUSTODY_STATUS,
58+
ReferenceDataGenerator.ADDITIONAL_IDENTIFIER_TYPE_SET,
59+
ReferenceDataGenerator.DUPLICATE_NOMS,
60+
ReferenceDataGenerator.FORMER_NOMS,
6761
PersonGenerator.PERSON_WITH_NOMS,
6862
PersonGenerator.PERSON_WITH_NO_NOMS,
6963
PersonGenerator.PERSON_WITH_MULTI_MATCH,
7064
PersonGenerator.PERSON_WITH_NO_MATCH,
7165
PersonGenerator.PERSON_WITH_NOMS_IN_DELIUS,
66+
PersonGenerator.PERSON_WITH_DUPLICATE_NOMS,
67+
PersonGenerator.PERSON_WITH_EXISTING_NOMS,
7268
personWithNomsEvent,
7369
personWithNomsDisposal,
7470
personWithNomsCustody,

projects/prison-identifier-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
package uk.gov.justice.digital.hmpps.data.generator
22

3-
import uk.gov.justice.digital.hmpps.integrations.delius.entity.*
3+
import uk.gov.justice.digital.hmpps.entity.*
44
import java.time.LocalDate
55
import java.time.format.DateTimeFormatter
66

77
object PersonGenerator {
8-
val MALE = generateGender("M")
98
val PERSON_WITH_NOMS = generate("A000001", "E1234XS")
109
val PERSON_WITH_NO_NOMS = generate("A000002", pncNumber = "07/220000004Q")
11-
val PERSON_WITH_NOMS_IN_DELIUS = generate("A000005", pncNumber = "07/220000004Q")
1210
val PERSON_WITH_MULTI_MATCH = generate("A000003", forename = "Jack", surname = "Jones")
1311
val PERSON_WITH_NO_MATCH = generate("A000004", forename = "Fred", surname = "Jones", dobString = "12/12/2001")
12+
val PERSON_WITH_NOMS_IN_DELIUS = generate("A000005", pncNumber = "07/220000004Q")
13+
val PERSON_WITH_DUPLICATE_NOMS = generate("A000006", "G5541UN")
14+
val PERSON_WITH_EXISTING_NOMS = generate("A000007", "A0007AA")
1415

1516
fun generate(
1617
crn: String,
1718
noms: String? = null,
1819
pncNumber: String? = null,
19-
gender: ReferenceData = MALE,
20+
gender: ReferenceData = ReferenceDataGenerator.MALE,
2021
forename: String = "bob",
2122
surname: String = "smith",
2223
softDeleted: Boolean = false,
@@ -32,6 +33,7 @@ object PersonGenerator {
3233
surname,
3334
noms,
3435
null,
36+
null,
3537
pncNumber,
3638
gender,
3739
listOf(),
@@ -45,7 +47,6 @@ object PersonGenerator {
4547
Disposal(id, startDate, event, active = true, softDeleted = false)
4648

4749
fun generateCustody(disposal: Disposal, id: Long = IdGenerator.getAndIncrement()) =
48-
Custody(id, null, disposal = disposal)
49-
50-
fun generateGender(code: String, id: Long = IdGenerator.getAndIncrement()) = ReferenceData(id, code)
50+
Custody(id, null, status = ReferenceDataGenerator.CUSTODY_STATUS, disposal = disposal)
5151
}
52+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package uk.gov.justice.digital.hmpps.data.generator
2+
3+
import uk.gov.justice.digital.hmpps.entity.ReferenceData
4+
import uk.gov.justice.digital.hmpps.entity.ReferenceDataSet
5+
6+
object ReferenceDataGenerator {
7+
val GENDER_SET = generateReferenceDataSet("GENDER")
8+
val MALE = generateGender("M")
9+
10+
val CUSTODY_STATUS_SET = generateReferenceDataSet("THROUGHCARE STATUS")
11+
val CUSTODY_STATUS = generateCustodyStatus("A")
12+
13+
val ADDITIONAL_IDENTIFIER_TYPE_SET = generateReferenceDataSet("ADDITIONAL IDENTIFIER TYPE")
14+
val DUPLICATE_NOMS = generateIdentifierType("DNOMS")
15+
val FORMER_NOMS = generateIdentifierType("XNOMS")
16+
17+
fun generateGender(code: String, id: Long = IdGenerator.getAndIncrement()) = ReferenceData(id, code, GENDER_SET)
18+
fun generateCustodyStatus(code: String, id: Long = IdGenerator.getAndIncrement()) =
19+
ReferenceData(id, code, CUSTODY_STATUS_SET)
20+
21+
fun generateIdentifierType(code: String, id: Long = IdGenerator.getAndIncrement()) =
22+
ReferenceData(id, code, ADDITIONAL_IDENTIFIER_TYPE_SET)
23+
24+
fun generateReferenceDataSet(name: String, id: Long = IdGenerator.getAndIncrement()) = ReferenceDataSet(id, name)
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"version": 1,
3+
"eventType": "prison-offender-events.prisoner.merged",
4+
"description": "A prisoner has been merged from A0001AA to B0001BB",
5+
"occurredAt": "2024-03-14T16:14:47Z",
6+
"publishedAt": "2024-03-14T16:14:48.060048501Z",
7+
"additionalInformation": {
8+
"nomsNumber": "B0007BB",
9+
"removedNomsNumber": "A0007AA",
10+
"reason": "MERGE"
11+
},
12+
"personReference": {
13+
"identifiers": [
14+
{
15+
"type": "NOMS",
16+
"value": "A0007AA"
17+
}
18+
]
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": 1,
3+
"eventType": "prison-offender-events.prisoner.received",
4+
"description": "A prisoner has been received into prison",
5+
"occurredAt": "2023-08-04T08:09:36.649098+01:00",
6+
"publishedAt": "2023-08-04T09:06:46.65281576+01:00",
7+
"additionalInformation": {
8+
"nomsNumber": "A0002AA",
9+
"reason": "ADMISSION",
10+
"probableCause": "RECALL",
11+
"source": "PRISON",
12+
"nomisMovementReasonCode": "N",
13+
"details": "ACTIVE IN:ADM-N",
14+
"currentLocation": "IN_PRISON",
15+
"prisonId": "WSI",
16+
"currentPrisonStatus": "UNDER_PRISON_CARE"
17+
},
18+
"personReference": {
19+
"identifiers": [
20+
{
21+
"type": "NOMS",
22+
"value": "A0002AA"
23+
}
24+
]
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": 1,
3+
"eventType": "prison-offender-events.prisoner.received",
4+
"description": "A prisoner has been received into prison",
5+
"occurredAt": "2023-08-04T08:09:36.649098+01:00",
6+
"publishedAt": "2023-08-04T09:06:46.65281576+01:00",
7+
"additionalInformation": {
8+
"nomsNumber": "A0001AA",
9+
"reason": "ADMISSION",
10+
"probableCause": "RECALL",
11+
"source": "PRISON",
12+
"nomisMovementReasonCode": "N",
13+
"details": "ACTIVE IN:ADM-N",
14+
"currentLocation": "IN_PRISON",
15+
"prisonId": "WSI",
16+
"currentPrisonStatus": "UNDER_PRISON_CARE"
17+
},
18+
"personReference": {
19+
"identifiers": [
20+
{
21+
"type": "NOMS",
22+
"value": "A0001AA"
23+
}
24+
]
25+
}
26+
}

0 commit comments

Comments
 (0)