Skip to content

Commit

Permalink
PI-2498: Do not use non mappa types (#4211)
Browse files Browse the repository at this point in the history
* PI-2498: Do not use non mappa types

* Formatting changes

---------

Co-authored-by: probation-integration-bot[bot] <177347787+probation-integration-bot[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 579ada4 commit 09a114c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ class ProbationCaseDataLoader(
)
)

registrationRepository.save(
PersonGenerator.generateRegistration(
ProbationCaseGenerator.CASE_COMPLEX.asPerson(),
ReferenceDataGenerator.REGISTER_TYPES[RegisterType.Code.MAPPA.value]!!,
LocalDate.now().minusDays(7),
ReferenceDataGenerator.NON_MAPPA_CATEGORY,
ReferenceDataGenerator.REGISTER_LEVELS["M2"]
)
)

registrationRepository.save(
PersonGenerator.generateRegistration(
ProbationCaseGenerator.CASE_COMPLEX.asPerson(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ object ReferenceDataGenerator {
generate(it.name, REGISTER_LEVEL.id, "MAPPA Level ${it.name}")
}.associateBy { it.code }

val NON_MAPPA_CATEGORY = generate("RC07", REGISTER_CATEGORY.id, "Other category")

fun generate(
code: String,
datasetId: Long,
Expand Down Expand Up @@ -99,7 +101,8 @@ object ReferenceDataGenerator {
GENDER_MALE,
GENDER_IDENTITY_PNS,
NATIONALITY_BRITISH,
RELIGION_OTHER
RELIGION_OTHER,
NON_MAPPA_CATEGORY,
) + REGISTER_CATEGORIES.values + REGISTER_LEVELS.values + REFERRAL_CATEGORIES.values

fun generateReferralSource(code: String, id: Long = IdGenerator.getAndIncrement()) = ReferralSource(id, code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,8 @@ fun String.toMappaLevel() = Level.entries.find { it.name == this }?.number
fun String.toMappaCategory() = Category.entries.find { it.name == this }?.number
?: throw IllegalStateException("Unexpected MAPPA category: $this")

fun Map<Boolean, List<Registration>>.mappa() = get(true)?.firstOrNull()?.asMappa()
fun Map<Boolean, List<Registration>>.mappa() = get(true)?.firstOrNull {
it.category?.code != null && Category.entries.map(Category::name).contains(it.category.code)
}?.asMappa()

fun Map<Boolean, List<Registration>>.flags() = get(false)?.map { it.asRegistration() } ?: listOf()

0 comments on commit 09a114c

Please sign in to comment.