Skip to content

Commit

Permalink
HMAI-286 Make LinkedPrisoner and PrisonerContactRestrictions models c…
Browse files Browse the repository at this point in the history
…onsistent with new naming (#727)

* change model names to adhere to naming convention

* update class names

* update class name

* fix tests

* refactor models
  • Loading branch information
BushraAbdullahi authored Mar 11, 2025
1 parent 3efd2a1 commit 265f394
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import org.springframework.web.bind.annotation.RestController
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.DataResponse
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonVisitRestriction
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestrictions
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestrictions
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.roleconfig.ConsumerFilters
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetVisitRestrictionsForPersonService
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetVisitorRestrictionsService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrap
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrapper.WebClientWrapperResponse
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.LinkedPrisoner
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRDetailedContact
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRLinkedPrisoner
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRPaginatedPrisonerContacts
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestrictionsResponse
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PRPrisonerContactRestrictions

@Component
class PersonalRelationshipsGateway(
Expand All @@ -25,9 +25,9 @@ class PersonalRelationshipsGateway(
@Autowired
lateinit var hmppsAuthGateway: HmppsAuthGateway

fun getLinkedPrisoner(contactId: Long): Response<List<LinkedPrisoner>> {
fun getLinkedPrisoner(contactId: Long): Response<List<PRLinkedPrisoner>> {
val result =
webClient.request<List<LinkedPrisoner>>(
webClient.request<List<PRLinkedPrisoner>>(
HttpMethod.GET,
"/contact/$contactId/linked-prisoners",
authenticationHeader(),
Expand All @@ -48,9 +48,9 @@ class PersonalRelationshipsGateway(
}
}

fun getPrisonerContactRestrictions(prisonerContactId: Long): Response<PrisonerContactRestrictionsResponse?> {
fun getPrisonerContactRestrictions(prisonerContactId: Long): Response<PRPrisonerContactRestrictions?> {
val result =
webClient.request<PrisonerContactRestrictionsResponse>(
webClient.request<PRPrisonerContactRestrictions>(
HttpMethod.GET,
"/prisoner-contact/$prisonerContactId/restriction",
authenticationHeader(),
Expand Down Expand Up @@ -129,8 +129,8 @@ class PersonalRelationshipsGateway(
}
}

fun mapToLinkedPrisoner(result: WebClientWrapper.WebClientWrapperResponse.Success<List<LinkedPrisoner>>): List<LinkedPrisoner> {
val mappedResult: List<LinkedPrisoner> = mapper.convertValue(result.data, object : TypeReference<List<LinkedPrisoner>>() {})
fun mapToLinkedPrisoner(result: WebClientWrapper.WebClientWrapperResponse.Success<List<PRLinkedPrisoner>>): List<PRLinkedPrisoner> {
val mappedResult: List<PRLinkedPrisoner> = mapper.convertValue(result.data, object : TypeReference<List<PRLinkedPrisoner>>() {})
return mappedResult
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps

import com.fasterxml.jackson.annotation.JsonProperty

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelation
import com.fasterxml.jackson.annotation.JsonProperty
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.interfaces.IRelationship

data class LinkedPrisoner(
data class PRLinkedPrisoner(
@JsonProperty("prisonerNumber")
val prisonerNumber: String,
@JsonProperty("lastName")
Expand All @@ -13,10 +13,10 @@ data class LinkedPrisoner(
@JsonProperty("middleNames")
val middleNames: String?,
@JsonProperty("relationships")
val relationships: List<LinkedPrisonerRelationship>?,
val relationships: List<PRLinkedPrisonerRelationship>?,
)

data class LinkedPrisonerRelationship(
data class PRLinkedPrisonerRelationship(
@JsonProperty("relationshipTypeCode")
override val relationshipTypeCode: String?,
@JsonProperty("relationshipTypeDescription")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships

import com.fasterxml.jackson.annotation.JsonProperty
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ContactGlobalRestriction
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestriction

data class PRPrisonerContactRestrictions(
var prisonerContactRestrictions: MutableList<PRPrisonerContactRestriction>? = mutableListOf(),
var contactGlobalRestrictions: List<PRContactGlobalRestriction>? = listOf(),
)

data class PRPrisonerContactRestriction(
val prisonerContactRestrictionId: Long,
val prisonerContactId: Long,
val contactId: Long,
val prisonerNumber: String,
val restrictionType: String,
val restrictionTypeDescription: String,
val startDate: String,
val expiryDate: String,
val comments: String,
val enteredByUsername: String,
val enteredByDisplayName: String,
val createdBy: String,
val createdTime: String,
val updatedBy: String,
val updatedTime: String,
) {
fun toPrisonerContactRestriction() =
PrisonerContactRestriction(
prisonerContactRestrictionId = this.prisonerContactRestrictionId,
prisonerContactId = this.prisonerContactId,
contactId = this.contactId,
prisonerNumber = this.prisonerNumber,
restrictionType = this.restrictionType,
restrictionTypeDescription = this.restrictionTypeDescription,
startDate = this.startDate,
expiryDate = this.expiryDate,
comments = this.comments,
enteredByUsername = this.enteredByUsername,
enteredByDisplayName = this.enteredByDisplayName,
createdBy = this.createdBy,
createdTime = this.createdTime,
updatedBy = this.updatedBy,
updatedTime = this.updatedTime,
)
}

data class PRContactGlobalRestriction(
@JsonProperty("contactRestrictionId")
val contactRestrictionId: Long,
@JsonProperty("contactId")
val contactId: Long,
@JsonProperty("restrictionType")
val restrictionType: String,
@JsonProperty("restrictionTypeDescription")
val restrictionTypeDescription: String,
@JsonProperty("startDate")
val startDate: String,
@JsonProperty("expiryDate")
val expiryDate: String,
@JsonProperty("comments")
val comments: String,
@JsonProperty("enteredByUsername")
val enteredByUsername: String,
@JsonProperty("enteredByDisplayName")
val enteredByDisplayName: String,
@JsonProperty("createdBy")
val createdBy: String,
@JsonProperty("createdTime")
val createdTime: String,
@JsonProperty("updatedBy")
val updatedBy: String,
@JsonProperty("updatedTime")
val updatedTime: String,
) {
fun toContactGlobalRestriction() =
ContactGlobalRestriction(
contactRestrictionId = this.contactRestrictionId,
contactId = this.contactId,
restrictionType = this.restrictionType,
restrictionTypeDescription = this.restrictionTypeDescription,
startDate = this.startDate,
expiryDate = this.expiryDate,
comments = this.comments,
enteredByUsername = this.enteredByUsername,
enteredByDisplayName = this.enteredByDisplayName,
createdBy = this.createdBy,
createdTime = this.createdTime,
updatedBy = this.updatedBy,
updatedTime = this.updatedTime,
)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.common.ConsumerPrisonAccessService
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.PersonalRelationshipsGateway
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestrictions
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestrictions
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.roleconfig.ConsumerFilters

@Service
Expand Down Expand Up @@ -52,9 +52,12 @@ class GetVisitorRestrictionsService(
for (prisonerContactId in linkedPrisonerIds) {
val gatewayResult = personalRelationshipsGateway.getPrisonerContactRestrictions(prisonerContactId!!)
if (gatewayResult.errors.isEmpty() && gatewayResult.data != null) {
gatewayResult.data.prisonerContactRestrictions?.let { restrictionsResult.prisonerContactRestrictions?.addAll(it) }
gatewayResult.data.prisonerContactRestrictions?.let { it -> restrictionsResult.prisonerContactRestrictions?.addAll(it.map { it.toPrisonerContactRestriction() }) }
if (prisonerContactId == linkedPrisonerIds.first()) {
restrictionsResult.contactGlobalRestrictions = gatewayResult.data.contactGlobalRestrictions?.first()
restrictionsResult.contactGlobalRestrictions =
gatewayResult.data.contactGlobalRestrictions
?.first()
?.toContactGlobalRestriction()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import org.springframework.test.web.servlet.MockMvc
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.common.ConsumerPrisonAccessService
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.removeWhitespaceAndNewlines
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.helpers.IntegrationAPIMockMvc
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ContactGlobalRestriction
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonVisitRestriction
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestriction
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonerContactRestrictions
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.ContactGlobalRestriction
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestriction
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.personalRelationships.PrisonerContactRestrictions
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.roleconfig.ConsumerFilters
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetVisitRestrictionsForPersonService
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetVisitorRestrictionsService
Expand Down
Loading

0 comments on commit 265f394

Please sign in to comment.