Skip to content

Commit

Permalink
PI-2215 Remove MapStruct dependency (#3840)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl authored Jun 3, 2024
1 parent f8f6681 commit 9c8537e
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 219 deletions.
2 changes: 0 additions & 2 deletions projects/unpaid-work-and-delius/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation(libs.springdoc)
implementation(libs.mapstruct)
kapt(libs.mapstructprocessor)

dev(project(":libs:dev-tools"))
dev("com.h2database:h2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,120 @@ import uk.gov.justice.digital.hmpps.controller.casedetails.entity.CaseRepository
import uk.gov.justice.digital.hmpps.controller.casedetails.entity.EventRepository
import uk.gov.justice.digital.hmpps.controller.casedetails.entity.getCase
import uk.gov.justice.digital.hmpps.controller.casedetails.entity.getEvent
import uk.gov.justice.digital.hmpps.controller.casedetails.model.CaseDetails
import uk.gov.justice.digital.hmpps.controller.casedetails.model.*
import uk.gov.justice.digital.hmpps.integrations.common.model.*

@Service
class CaseDetailsService(
val caseRepository: CaseRepository,
val eventRepository: EventRepository,
val caseMapper: CaseMapper
val eventRepository: EventRepository
) {
fun getCaseDetails(crn: String, eventId: Long): CaseDetails {
val case = caseRepository.getCase(crn)
val event = eventRepository.getEvent(eventId)
return caseMapper.withAdditionalMappings(case, event)
return CaseDetails(
crn = case.crn,
name = Name(
forename = case.forename,
middleName = case.secondName,
surname = case.surname
),
dateOfBirth = case.dateOfBirth,
gender = case.gender?.description,
genderIdentity = case.genderIdentity?.description,
croNumber = case.croNumber,
pncNumber = case.pncNumber,
aliases = case.aliases.map { Alias(it.name(), it.dateOfBirth) },
emailAddress = case.emailAddress,
phoneNumbers = listOfNotNull(
case.mobileNumber?.let { PhoneNumber("MOBILE", it) },
case.telephoneNumber?.let { PhoneNumber("TELEPHONE", it) }
),
mainAddress = case.addresses.firstOrNull()?.let {
Address(it.buildingName, it.addressNumber, it.streetName, it.district, it.town, it.county, it.postcode)
},
ethnicity = case.ethnicity?.description,
disabilities = case.disabilities.map {
Disability(
type = Type(it.type.code, it.type.description),
condition = it.condition?.let { c -> Type(c.code, c.description) },
notes = it.notes
)
},
provisions = case.provisions.map {
Provision(
type = Type(it.type.code, it.type.description),
category = it.category?.let { c -> Type(c.code, c.description) },
notes = it.notes
)
},
language = case.primaryLanguage?.description?.let {
Language(
requiresInterpreter = case.requiresInterpreter ?: false,
primaryLanguage = it
)
},
personalCircumstances = case.personalCircumstances.map {
PersonalCircumstance(
type = Type(it.type.code, it.type.description),
subType = it.subType?.let { t -> Type(t.code, t.description) },
notes = it.notes,
evidenced = it.evidenced ?: false
)
},
personalContacts = case.personalContacts.map {
PersonalContact(
relationship = it.relationship,
relationshipType = Type(it.relationshipType.code, it.relationshipType.description),
name = it.name(),
mobileNumber = it.mobileNumber,
telephoneNumber = it.address?.telephoneNumber,
address = it.address?.let { address ->
Address(
buildingName = address.buildingName,
addressNumber = address.addressNumber,
streetName = address.streetName,
district = address.district,
town = address.town,
county = address.county,
postcode = address.postcode
)
}
)
},
mappaRegistration = case.registrations.filter { it.type.code == "MAPPA" }.maxByOrNull { it.startDate }
?.let {
MappaRegistration(
startDate = it.startDate,
level = Type(it.level.code, it.level.description),
category = Type(it.category.code, it.category.description)
)
},
registerFlags = case.registrations.map {
RegisterFlag(
code = it.type.code,
description = it.type.description,
riskColour = it.type.riskColour
)
},
sentence = if (event.mainOffence != null && event.disposal != null) {
Sentence(
startDate = event.disposal.disposalDate,
mainOffence = MainOffence(
Type(
event.mainOffence.offence.mainCategoryCode,
event.mainOffence.offence.mainCategoryDescription
),
Type(
event.mainOffence.offence.subCategoryCode,
event.mainOffence.offence.subCategoryDescription
)
)
)
} else {
null
}

)
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,45 @@ import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.controller.personaldetails.entity.PersonRepository
import uk.gov.justice.digital.hmpps.controller.personaldetails.entity.getPerson
import uk.gov.justice.digital.hmpps.controller.personaldetails.model.PersonalDetails
import uk.gov.justice.digital.hmpps.controller.personaldetails.model.name
import uk.gov.justice.digital.hmpps.integrations.common.model.Address
import uk.gov.justice.digital.hmpps.integrations.common.model.PersonalCircumstance
import uk.gov.justice.digital.hmpps.integrations.common.model.PersonalContact
import uk.gov.justice.digital.hmpps.integrations.common.model.Type

@Service
class PersonalDetailsService(val personRepository: PersonRepository, val personMapper: PersonMapper) {
fun getPersonalDetails(crn: String): PersonalDetails {
val person = personRepository.getPerson(crn)
return personMapper.convertToModel(person)
class PersonalDetailsService(val personRepository: PersonRepository) {
fun getPersonalDetails(crn: String) = with(personRepository.getPerson(crn)) {
PersonalDetails(
crn = crn,
personalCircumstances = personalCircumstances.map {
PersonalCircumstance(
type = Type(it.type.code, it.type.description),
subType = it.subType?.let { t -> Type(t.code, t.description) },
notes = it.notes,
evidenced = it.evidenced ?: false
)
},
personalContacts = personalContacts.map {
PersonalContact(
relationship = it.relationship,
relationshipType = Type(it.relationshipType.code, it.relationshipType.description),
name = it.name(),
telephoneNumber = it.address?.telephoneNumber,
mobileNumber = it.mobileNumber,
address = it.address?.let { address ->
Address(
buildingName = address.buildingName,
addressNumber = address.addressNumber,
streetName = address.streetName,
district = address.district,
town = address.town,
county = address.county,
postcode = address.postcode
)
}
)
}
)
}
}

This file was deleted.

Loading

0 comments on commit 9c8537e

Please sign in to comment.