generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* PI-2235: Process SENTENCE_CHANGED events with crn
- Loading branch information
Showing
15 changed files
with
225 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/MessageGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.messaging.CustodyDateChanged | ||
import uk.gov.justice.digital.hmpps.messaging.ProbationOffenderEvent | ||
import uk.gov.justice.digital.hmpps.resourceloader.ResourceLoader | ||
|
||
object MessageGenerator { | ||
val SENTENCE_DATE_CHANGED = ResourceLoader.message<CustodyDateChanged>("sentence-date-changed") | ||
val SENTENCE_CHANGED = ResourceLoader.message<ProbationOffenderEvent>("sentence-changed") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
projects/custody-key-dates-and-delius/src/dev/resources/messages/sentence-changed.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"Type": "Notification", | ||
"MessageId": "20e13002-d1be-56e7-be8c-66cdd7e23341", | ||
"TopicArn": "arn:aws:sns:eu-west-2:754256621582:cloud-platform-Digital-Prison-Services-f221e27fcfcf78f6ab4f4c3cc165eee7", | ||
"Message": "{\"eventType\":\"SENTENCE_CHANGED\",\"eventDatetime\":\"2020-02-25T11:24:32.935401\",\"offenderId\":1,\"crn\":\"A000002\",\"sourceId\":\"2500974056\"}", | ||
"Timestamp": "2020-02-25T11:25:16.169Z", | ||
"SignatureVersion": "1", | ||
"Signature": "h5p3FnnbsSHxj53RFePh8HR40cbVvgEZa6XUVTlYs/yuqfDsi17MPA+bX4ijKmmTT2l6xG2xYhcmRAbJWQ4wrwncTBm2azgiwSO5keRNWYVdiC0rI484KLZboP1SDsE+Y7hOU/R0dz49q7+0yd+QIocPteKB/8xG7/6kjGStAZKf3cEdlxOwLhN+7RU1Yk2ENuwAJjVRtvlAa76yKB3xvL2hId7P7ZLmHGlzZDNZNYxbg9C8HGxteOzZ9ZeeQsWDf9jmZ+5+7dKXQoW9LeqwHxEAq2vuwSZ8uwM5JljXbtS5w1P0psXPYNoin2gU1F5MDK8RPzjUtIvjINx08rmEOA==", | ||
"SigningCertURL": "https://sns.eu-west-2.amazonaws.com/SimpleNotificationService-a86cb10b4e1f29c941702d737128f7b6.pem", | ||
"UnsubscribeURL": "https://sns.eu-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-2:754256621582:cloud-platform-Digital-Prison-Services-f221e27fcfcf78f6ab4f4c3cc165eee7:92545cfe-de5d-43e1-8339-c366bf0172aa", | ||
"MessageAttributes": { | ||
"eventType": { | ||
"Type": "String", | ||
"Value": "SENTENCE_CHANGED" | ||
}, | ||
"id": { | ||
"Type": "String", | ||
"Value": "cb4645f2-d0c1-4677-806a-8036ed54bf69" | ||
}, | ||
"contentType": { | ||
"Type": "String", | ||
"Value": "text/plain;charset=UTF-8" | ||
}, | ||
"timestamp": { | ||
"Type": "Number.java.lang.Long", | ||
"Value": "1582629916147" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...s/custody-key-dates-and-delius/src/dev/resources/simulations/__files/booking_1200837.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"bookingId": 1200837, | ||
"bookingNo": "48340A", | ||
"offenderNo": "A0002DY", | ||
"firstName": "Jim", | ||
"lastName": "Smith", | ||
"agencyId": "MDI", | ||
"activeFlag": true, | ||
"dateOfBirth": "1970-01-01" | ||
} |
6 changes: 6 additions & 0 deletions
6
...tody-key-dates-and-delius/src/dev/resources/simulations/__files/booking_noms_A0002DY.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"bookingId": 1200837, | ||
"bookingNo": "48340A", | ||
"offenderNo": "A0002DY", | ||
"active": true | ||
} |
10 changes: 10 additions & 0 deletions
10
...y-key-dates-and-delius/src/dev/resources/simulations/__files/sentence_detail_1200837.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"bookingId": 1200837, | ||
"sentenceExpiryDate": "2025-09-10", | ||
"conditionalReleaseDate": "2022-11-25", | ||
"conditionalReleaseOverrideDate": "2022-11-26", | ||
"licenceExpiryDate": "2025-09-11", | ||
"releaseDate": "2022-11-26", | ||
"confirmedReleaseDate": "2022-11-27", | ||
"homeDetentionCurfewEligibilityDate": "2022-10-28" | ||
} |
30 changes: 30 additions & 0 deletions
30
...stody-key-dates-and-delius/src/dev/resources/simulations/mappings/getBooking_1200837.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"urlPath": "/api/bookings/1200837" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"bodyFileName": "booking_1200837.json" | ||
} | ||
}, | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"urlPath": "/api/bookings/offenderNo/A0002DY" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"bodyFileName": "booking_noms_A0002DY.json" | ||
} | ||
} | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
...ey-dates-and-delius/src/dev/resources/simulations/mappings/getSentenceDetail_1200837.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"urlPath": "/api/bookings/1200837/sentenceDetail" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"bodyFileName": "sentence_detail_1200837.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...c/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/PersonRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.delius.person | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
|
||
interface PersonRepository : JpaRepository<Person, Long> { | ||
fun findByNomsIdIgnoreCaseAndSoftDeletedIsFalse(nomsId: String): Person? | ||
|
||
@Query("select p.nomsId from Person p where p.crn = :crn and p.softDeleted = false") | ||
fun findNomsIdByCrn(crn: String): String? | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ey-dates-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package uk.gov.justice.digital.hmpps.messaging | ||
|
||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import uk.gov.justice.digital.hmpps.data.generator.MessageGenerator | ||
import uk.gov.justice.digital.hmpps.integrations.delius.custody.date.CustodyDateUpdateService | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.PersonRepository | ||
import uk.gov.justice.digital.hmpps.message.MessageAttributes | ||
import uk.gov.justice.digital.hmpps.message.Notification | ||
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
internal class HandlerTest { | ||
|
||
@Mock | ||
lateinit var converter: KeyDateChangedEventConverter | ||
|
||
@Mock | ||
lateinit var telemetryService: TelemetryService | ||
|
||
@Mock | ||
lateinit var personRepository: PersonRepository | ||
|
||
@Mock | ||
lateinit var cduService: CustodyDateUpdateService | ||
|
||
lateinit var handler: Handler | ||
|
||
@Test | ||
fun `handles unexpected event type`() { | ||
handler = Handler(converter, cduService, telemetryService, personRepository) | ||
val exception = assertThrows<IllegalArgumentException> { | ||
handler.handle( | ||
Notification( | ||
message = MessageGenerator.SENTENCE_CHANGED, | ||
attributes = MessageAttributes(eventType = "UNKNOWN") | ||
) | ||
) | ||
} | ||
assertThat(exception.message, equalTo("Unexpected offender event type: UNKNOWN")) | ||
} | ||
} |