Skip to content

Commit

Permalink
PI-2469: Added static phone type reference data (#4230)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcphee77 authored Sep 13, 2024
1 parent f638c17 commit de3de53
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import uk.gov.justice.digital.hmpps.data.generator.RegistrationGenerator.REFDATA
import uk.gov.justice.digital.hmpps.model.PersonIdentifier
import uk.gov.justice.digital.hmpps.model.ProbationReferenceData
import uk.gov.justice.digital.hmpps.model.RefData
import uk.gov.justice.digital.hmpps.service.PhoneTypes
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken
import java.time.LocalDate
Expand Down Expand Up @@ -152,11 +153,18 @@ internal class IntegrationTest {
.andExpect(status().is2xxSuccessful)
.andReturn().response.contentAsJson<ProbationReferenceData>()
Assertions.assertEquals(
response.probationReferenceData.get("GENDER"),
response.probationReferenceData["GENDER"],
listOf(
RefData(REFDATA_FEMALE.code, REFDATA_FEMALE.description),
RefData(REFDATA_MALE.code, REFDATA_MALE.description)
)
)
Assertions.assertEquals(
response.probationReferenceData["PHONE_TYPE"],
listOf(
RefData(PhoneTypes.TELEPHONE.name, PhoneTypes.TELEPHONE.description),
RefData(PhoneTypes.MOBILE.name, PhoneTypes.MOBILE.description)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ interface RegistrationRepository : JpaRepository<RegistrationEntity, Long> {
on rdm.reference_data_master_id = rdl.reference_data_master_id
where rdm.code_set_name in ('GENDER','ETHNICITY')
union
select 'REGISTER_TYPES' as set_name, rt.code, rt.description
select 'REGISTER_TYPE' as set_name, rt.code, rt.description
from r_register_type rt
order by codeSet, code
""", nativeQuery = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ import uk.gov.justice.digital.hmpps.model.RefData
class ReferenceDataService(
private val registrationRepository: RegistrationRepository,
) {
fun getReferenceData(): ProbationReferenceData =
ProbationReferenceData(
fun getReferenceData(): ProbationReferenceData {

val refData = LinkedHashMap<String, MutableList<RefData>>()
refData["PHONE_TYPE"] = PhoneTypes.entries.map { RefData(it.name, it.description) }.toMutableList()
refData.putAll(
registrationRepository.getReferenceData()
.groupByTo(LinkedHashMap(), { it.codeSet.trim() }, { RefData(it.code.trim(), it.description) })
)
}
return ProbationReferenceData(refData)
}
}

enum class PhoneTypes(val description: String) {
TELEPHONE("Home"),
MOBILE("Mobile")
}

0 comments on commit de3de53

Please sign in to comment.