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-2109: Added registrations endpoint
- Loading branch information
Showing
13 changed files
with
572 additions
and
2 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
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
91 changes: 91 additions & 0 deletions
91
...lius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/RegistrationsGenerator.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,91 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.CURRENTLY_MANAGED | ||
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.REG_CATEGORY | ||
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.REG_FLAG | ||
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.REG_LEVEL | ||
import uk.gov.justice.digital.hmpps.integration.delius.registration.entity.DeRegistration | ||
import uk.gov.justice.digital.hmpps.integration.delius.registration.entity.RegisterType | ||
import uk.gov.justice.digital.hmpps.integration.delius.registration.entity.Registration | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.ReferenceData | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Person | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
object RegistrationsGenerator { | ||
|
||
val REG_TYPE = RegisterType( | ||
"T1", "Register Type 1", REG_FLAG, | ||
true, 6L, "Red", IdGenerator.getAndIncrement() | ||
) | ||
|
||
val ACTIVE_REG = generateRegistrations(CURRENTLY_MANAGED, false) | ||
val INACTIVE_REG = generateRegistrations(CURRENTLY_MANAGED, true) | ||
|
||
val REG_NO_DEREG = generateRegistrations(CURRENTLY_MANAGED, false, level = null, category = null) | ||
|
||
val DEREG_1 = generateDeregistration( | ||
ACTIVE_REG, | ||
date = LocalDate.now().minusDays(1), | ||
createdDateTime = LocalDate.now().minusDays(1).atTime(13, 0) | ||
) | ||
|
||
val DEREG_2 = generateDeregistration( | ||
ACTIVE_REG, | ||
date = LocalDate.now().minusDays(1), | ||
createdDateTime = LocalDate.now().minusDays(1).atTime(14, 0) | ||
) | ||
|
||
val DEREG_3 = generateDeregistration( | ||
ACTIVE_REG, | ||
date = LocalDate.now().minusDays(2), | ||
createdDateTime = LocalDate.now().minusDays(2).atTime(18, 0) | ||
) | ||
|
||
val DEREG_4 = generateDeregistration( | ||
INACTIVE_REG, | ||
date = LocalDate.now().minusDays(1), | ||
createdDateTime = LocalDate.now().minusDays(1).atTime(13, 0) | ||
) | ||
|
||
val DEREG_5 = generateDeregistration( | ||
INACTIVE_REG, | ||
date = LocalDate.now().minusDays(1), | ||
createdDateTime = LocalDate.now().minusDays(1).atTime(14, 0) | ||
) | ||
|
||
fun generateRegistrations( | ||
person: Person, | ||
deRegistered: Boolean, | ||
category: ReferenceData? = REG_CATEGORY, | ||
level: ReferenceData? = REG_LEVEL | ||
) = Registration( | ||
id = IdGenerator.getAndIncrement(), | ||
person = person, | ||
category = category, | ||
level = level, | ||
type = REG_TYPE, | ||
date = LocalDate.now().minusDays(2), | ||
reviewDate = LocalDate.now().minusDays(1), | ||
notes = "Notes", | ||
team = TeamGenerator.DEFAULT, | ||
staff = StaffGenerator.ALLOCATED, | ||
deRegistrations = emptyList(), | ||
deRegistered = deRegistered, | ||
softDeleted = false, | ||
createdDateTime = LocalDateTime.now() | ||
|
||
) | ||
|
||
fun generateDeregistration(registration: Registration, date: LocalDate, createdDateTime: LocalDateTime) = | ||
DeRegistration( | ||
id = IdGenerator.getAndIncrement(), | ||
registration = registration, | ||
deRegistrationDate = date, | ||
team = TeamGenerator.DEFAULT, | ||
staff = StaffGenerator.ALLOCATED, | ||
notes = "Deregistration notes", | ||
createdDateTime = createdDateTime, | ||
softDeleted = false | ||
) | ||
} |
104 changes: 104 additions & 0 deletions
104
...ourt-case-and-delius/src/dev/resources/simulations/__files/get_registrations_C123456.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,104 @@ | ||
{ | ||
"registrations": [ | ||
{ | ||
"offenderId": 68, | ||
"register": { | ||
"code": "F1", | ||
"description": "Registration Flag" | ||
}, | ||
"type": { | ||
"code": "T1", | ||
"description": "Register Type 1" | ||
}, | ||
"riskColour": "Red", | ||
"startDate": "2024-08-07", | ||
"nextReviewDate": "2024-08-08", | ||
"reviewPeriodMonths": 6, | ||
"notes": "Notes", | ||
"registeringTeam": { | ||
"code": "T1 ", | ||
"description": "Team1" | ||
}, | ||
"registeringOfficer": { | ||
"code": "N01ABBA", | ||
"forenames": "Bob Micheal", | ||
"surname": "Smith", | ||
"unallocated": false | ||
}, | ||
"registeringProbationArea": { | ||
"code": "LN1", | ||
"description": "London" | ||
}, | ||
"registerLevel": { | ||
"code": "L1", | ||
"description": "Registration Level" | ||
}, | ||
"registerCategory": { | ||
"code": "RC1", | ||
"description": "Registration Category" | ||
}, | ||
"warnUser": true, | ||
"active": true, | ||
"endDate": "2024-08-08", | ||
"deregisteringNotes": "Deregistration notes", | ||
"numberOfPreviousDeregistrations": 3 | ||
}, | ||
{ | ||
"offenderId": 68, | ||
"register": { | ||
"code": "F1", | ||
"description": "Registration Flag" | ||
}, | ||
"type": { | ||
"code": "T1", | ||
"description": "Register Type 1" | ||
}, | ||
"riskColour": "Red", | ||
"startDate": "2024-08-07", | ||
"nextReviewDate": "2024-08-08", | ||
"reviewPeriodMonths": 6, | ||
"notes": "Notes", | ||
"registeringTeam": { | ||
"code": "T1 ", | ||
"description": "Team1" | ||
}, | ||
"registeringOfficer": { | ||
"code": "N01ABBA", | ||
"forenames": "Bob Micheal", | ||
"surname": "Smith", | ||
"unallocated": false | ||
}, | ||
"registeringProbationArea": { | ||
"code": "LN1", | ||
"description": "London" | ||
}, | ||
"registerLevel": { | ||
"code": "L1", | ||
"description": "Registration Level" | ||
}, | ||
"registerCategory": { | ||
"code": "RC1", | ||
"description": "Registration Category" | ||
}, | ||
"warnUser": true, | ||
"active": false, | ||
"endDate": "2024-08-08", | ||
"deregisteringTeam": { | ||
"code": "T1 ", | ||
"description": "Team1" | ||
}, | ||
"deregisteringOfficer": { | ||
"code": "N01ABBA", | ||
"forenames": "Bob Micheal", | ||
"surname": "Smith", | ||
"unallocated": false | ||
}, | ||
"deregisteringProbationArea": { | ||
"code": "LN1", | ||
"description": "London" | ||
}, | ||
"deregisteringNotes": "Deregistration notes", | ||
"numberOfPreviousDeregistrations": 2 | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
projects/court-case-and-delius/src/dev/resources/simulations/mappings/get-registrations.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,17 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"urlPathTemplate": "/secure/offenders/crn/{crn}/registrations" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"bodyFileName": "get_registrations_C123456.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
52 changes: 52 additions & 0 deletions
52
...s/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/RegistrationsIntegrationTest.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,52 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import uk.gov.justice.digital.hmpps.api.model.Registrations | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.RegistrationsGenerator.DEREG_2 | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
internal class RegistrationsIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun `get registrations by CRN with active only set to false`() { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
|
||
val response = mockMvc | ||
.perform(get("/probation-case/$crn/registrations?activeOnly=false").withToken()) | ||
.andExpect(status().isOk) | ||
.andReturn().response.contentAsJson<Registrations>() | ||
|
||
assertThat(response.registrations.size, equalTo(3)) | ||
assertThat(response.registrations[0].active, equalTo(true)) | ||
assertThat(response.registrations[1].active, equalTo(false)) | ||
assertThat(response.registrations[0].endDate, equalTo(DEREG_2.deRegistrationDate)) | ||
} | ||
|
||
@Test | ||
fun `get registrations by CRN with active only set to true`() { | ||
val crn = PersonGenerator.CURRENTLY_MANAGED.crn | ||
|
||
val response = mockMvc | ||
.perform(get("/probation-case/$crn/registrations?activeOnly=true").withToken()) | ||
.andExpect(status().isOk) | ||
.andReturn().response.contentAsJson<Registrations>() | ||
|
||
assertThat(response.registrations.size, equalTo(2)) | ||
assertThat(response.registrations[0].active, equalTo(true)) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...t-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/Registrations.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,31 @@ | ||
package uk.gov.justice.digital.hmpps.api.model | ||
|
||
import java.time.LocalDate | ||
|
||
data class Registrations( | ||
val registrations: List<Registration> = emptyList() | ||
) | ||
|
||
data class Registration( | ||
val offenderId: Long? = null, | ||
val register: KeyValue? = null, | ||
val type: KeyValue? = null, | ||
val riskColour: String? = null, | ||
val startDate: LocalDate? = null, | ||
val nextReviewDate: LocalDate? = null, | ||
val reviewPeriodMonths: Long? = null, | ||
val notes: String? = null, | ||
val registeringTeam: KeyValue? = null, | ||
val registeringOfficer: StaffHuman? = null, | ||
val registeringProbationArea: KeyValue? = null, | ||
val registerLevel: KeyValue? = null, | ||
val registerCategory: KeyValue? = null, | ||
val warnUser: Boolean = false, | ||
val active: Boolean = false, | ||
val endDate: LocalDate? = null, | ||
val deregisteringTeam: KeyValue? = null, | ||
val deregisteringOfficer: StaffHuman? = null, | ||
val deregisteringProbationArea: KeyValue? = null, | ||
val deregisteringNotes: String? = null, | ||
val numberOfPreviousDeregistrations: Int = 0 | ||
) |
Oops, something went wrong.