Skip to content

Commit

Permalink
PI-2109: Added registrations endpoint (#4165)
Browse files Browse the repository at this point in the history
* PI-2109: Added registrations endpoint
  • Loading branch information
pmcphee77 authored Aug 9, 2024
1 parent e3bbf00 commit 76197df
Show file tree
Hide file tree
Showing 13 changed files with 572 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class DataLoader(
ReferenceDataGenerator.SED,
ReferenceDataGenerator.CRN,
ReferenceDataGenerator.TRIAL,
ReferenceDataGenerator.REG_CATEGORY,
ReferenceDataGenerator.REG_LEVEL,
ReferenceDataGenerator.REG_FLAG,
CourtGenerator.PROBATION_AREA,
CourtGenerator.BHAM,
PersonGenerator.NEW_TO_PROBATION,
Expand Down Expand Up @@ -258,6 +261,19 @@ class DataLoader(
ContactGenerator.ATTENDANCE_CONTACT_1,
ContactGenerator.ATTENDANCE_CONTACT_2
)

//Registrations
em.saveAll(
RegistrationsGenerator.REG_TYPE,
RegistrationsGenerator.ACTIVE_REG,
RegistrationsGenerator.INACTIVE_REG,
RegistrationsGenerator.REG_NO_DEREG,
RegistrationsGenerator.DEREG_1,
RegistrationsGenerator.DEREG_2,
RegistrationsGenerator.DEREG_3,
RegistrationsGenerator.DEREG_4,
RegistrationsGenerator.DEREG_5,
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,22 @@ object ReferenceDataGenerator {
"Trial/Adjournment",
IdGenerator.getAndIncrement()
)

val REG_CATEGORY = ReferenceData(
code = "RC1",
"Registration Category",
IdGenerator.getAndIncrement()
)

val REG_LEVEL = ReferenceData(
code = "L1",
"Registration Level",
IdGenerator.getAndIncrement()
)

val REG_FLAG = ReferenceData(
code = "F1",
"Registration Flag",
IdGenerator.getAndIncrement()
)
}
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
)
}
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
}
]
}
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"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ internal class ProxyIntegrationTest {
"DOCUMENTS_GROUPED": {
"type": null,
"subtype": null
},
"REGISTRATIONS": {
"activeOnly": false
}
}
}
Expand All @@ -273,7 +276,7 @@ internal class ProxyIntegrationTest {
.withToken()
).andExpect(status().is2xxSuccessful).andReturn().response.contentAsJson<CompareAllReport>()

assertThat(res.totalNumberOfRequests, equalTo(15))
assertThat(res.totalNumberOfRequests, equalTo(16))
assertThat(res.totalNumberOfCrns, equalTo(2))
assertThat(res.currentPageNumber, equalTo(1))
}
Expand Down
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))
}
}
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
)
Loading

0 comments on commit 76197df

Please sign in to comment.