From 2e4a4a98ee3bfd329e4100f4d5bc18fd5adbf146 Mon Sep 17 00:00:00 2001 From: Michael Willis Date: Thu, 18 Jul 2024 15:38:58 +0100 Subject: [PATCH] MAP-365 Remove legacy non-associations code (#321) This change removes the legacy non-associations code that was previously used to handle Prison API formats. Given the updates to the system and the adoption of modern roles and reasons formats, this code is no longer necessary. Also, the associated tests have been removed. --- .../dto/LegacyPrisonerNonAssociations.kt | 73 ----- .../dto/LegacyRestrictionType.kt | 15 - .../resource/LegacyResource.kt | 47 ---- .../service/NonAssociationsService.kt | 48 ---- .../resource/NonAssociationsResourceTest.kt | 264 ------------------ .../service/RoleAndReasonTranslation.kt | 37 --- 6 files changed, 484 deletions(-) delete mode 100644 src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/dto/LegacyPrisonerNonAssociations.kt diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/dto/LegacyPrisonerNonAssociations.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/dto/LegacyPrisonerNonAssociations.kt deleted file mode 100644 index aec6b351..00000000 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/dto/LegacyPrisonerNonAssociations.kt +++ /dev/null @@ -1,73 +0,0 @@ -package uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto - -import io.swagger.v3.oas.annotations.media.Schema -import java.time.LocalDateTime - -/** - * A list of non-associations for a given prisoner (in NOMIS/Prison API format) - */ -@Schema(description = "List of non-associations for a given prisoner in NOMIS/Prison API format") -data class LegacyPrisonerNonAssociations( - @Schema(description = "Prisoner number", required = true, example = "A1234BC") - val offenderNo: String, - @Schema(description = "First name", required = true, example = "James") - val firstName: String, - @Schema(description = "Last name", required = true, example = "Hall") - val lastName: String, - @Schema(description = "Prison ID where prisoner resides or OUT for released", required = false, example = "MDI") - val agencyId: String?, - @Schema(description = "Description of the agency (e.g. prison) the offender is assigned to", required = false, example = "Moorland (HMP & YOI)") - val agencyDescription: String?, - @Schema(description = "Description of living unit (e.g. cell) the offender is assigned to.", required = false, example = "MDI-1-1-3") - val assignedLivingUnitDescription: String?, - @Schema(description = "Non-associations with other prisoners", required = true) - val nonAssociations: List, -) - -/** - * Details about a single non-association in a list and link to the other prisoner involved (in NOMIS/Prison API format) - */ -@Schema(description = "An item in a list of non-associations for a given prisoner in NOMIS/Prison API format") -data class LegacyPrisonerNonAssociation( - @Schema(description = "Reason code for the non-association", required = true, example = "VIC") - val reasonCode: LegacyReason, - @Schema(description = "Reason for the non-association", required = true, example = "Victim") - val reasonDescription: String, - @Schema(description = "The non-association type code", required = true, example = "WING") - val typeCode: LegacyRestrictionType, - @Schema(description = "The non-association type description", required = true, example = "Do Not Locate on Same Wing") - val typeDescription: String, - @Schema(description = "Date and time the non-association is effective from. In Europe/London (ISO 8601) format without timezone offset e.g. YYYY-MM-DDTHH:MM:SS.", required = true, example = "2021-07-05T00:00:00") - val effectiveDate: LocalDateTime, - @Schema(description = "Date and time the non-association expires. In Europe/London (ISO 8601) format without timezone offset e.g. YYYY-MM-DDTHH:MM:SS.", required = false, example = "2021-07-05T00:00:00") - val expiryDate: LocalDateTime?, - @Schema(description = "The person who authorised the non-association (free text).", required = false, example = "Officer Alice B.") - val authorisedBy: String?, - @Schema(description = "Additional free text comments related to the non-association.", required = false, example = "Mr. Bloggs assaulted Mr. Hall") - val comments: String?, - @Schema(description = "Details about the other non-association person.", required = true) - val offenderNonAssociation: LegacyOtherPrisonerDetails, -) - -/** - * Details about the other prisoner to non-associate with (in NOMIS/Prison API format) - */ -@Schema(description = "Other prisoner’s details for an item in a list of non-associations in NOMIS/Prison API format") -data class LegacyOtherPrisonerDetails( - @Schema(description = "Prisoner number", required = true, example = "B1234CD") - val offenderNo: String, - @Schema(description = "First name", required = true, example = "Joseph") - val firstName: String, - @Schema(description = "Last name", required = true, example = "Bloggs") - val lastName: String, - @Schema(description = "Reason code for the non-association", required = true, example = "PER") - val reasonCode: LegacyReason, - @Schema(description = "Reason for the non-association", required = true, example = "Perpetrator") - val reasonDescription: String, - @Schema(description = "Prison ID where prisoner resides or OUT for released", required = false, example = "MDI") - val agencyId: String?, - @Schema(description = "Description of the agency (e.g. prison) the offender is assigned to", required = false, example = "Moorland (HMP & YOI)") - val agencyDescription: String?, - @Schema(description = "Description of living unit (e.g. cell) the offender is assigned to.", required = false, example = "MDI-2-3-4") - val assignedLivingUnitDescription: String?, -) diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/dto/LegacyRestrictionType.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/dto/LegacyRestrictionType.kt index 8753b031..4ac57d8e 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/dto/LegacyRestrictionType.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/dto/LegacyRestrictionType.kt @@ -8,20 +8,5 @@ package uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto enum class LegacyRestrictionType(val description: String) { CELL("Do Not Locate in Same Cell"), LAND("Do Not Locate on Same Landing"), - NONEX("Do Not Exercise Together"), - - // following legacy restriction types do not have "modern" counterpart - TNA("Total Non Association"), WING("Do Not Locate on Same Wing"), - ; - - fun toRestrictionType(): RestrictionType = when (this) { - CELL -> RestrictionType.CELL - LAND -> RestrictionType.LANDING - WING -> RestrictionType.WING - - // following legacy restriction types do not map clearly - NONEX -> RestrictionType.WING - TNA -> RestrictionType.WING - } } diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/resource/LegacyResource.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/resource/LegacyResource.kt index 548d3901..c0bb1891 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/resource/LegacyResource.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/resource/LegacyResource.kt @@ -12,13 +12,11 @@ import org.springframework.validation.annotation.Validated import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.bind.annotation.RestController import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.config.ErrorResponse import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.config.NonAssociationNotFoundException import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.LegacyNonAssociation -import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.LegacyPrisonerNonAssociations import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.service.NonAssociationsService @RestController @@ -31,51 +29,6 @@ import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.service.NonAssociati class LegacyResource( val nonAssociationsService: NonAssociationsService, ) { - @GetMapping("/offenders/{prisonerNumber}/non-association-details") - @ResponseStatus(HttpStatus.OK) - @Operation( - summary = "Get non-associations by prisoner number in NOMIS/Prison API format", - description = "Currently this is a façade that calls Prison API, but will in future use the non-associations database and yet maintain the Prison API contract.", - responses = [ - ApiResponse( - responseCode = "200", - description = "Returns non-association details for this prisoner", - ), - ApiResponse( - responseCode = "401", - description = "Unauthorized to access this endpoint", - content = [Content(mediaType = "application/json", schema = Schema(implementation = ErrorResponse::class))], - ), - ApiResponse( - responseCode = "404", - description = "Prisoner number not found (and possibly when no non-associations exist)", - content = [Content(mediaType = "application/json", schema = Schema(implementation = ErrorResponse::class))], - ), - ], - ) - fun getDetailsFromPrisonApiByPrisonerNumber( - @Schema(description = "The offender prisoner number", example = "A1234BC", required = true) - @PathVariable - prisonerNumber: String, - @Schema( - description = "Returns only non-association details for this prisoner in the same prison", - required = false, - defaultValue = "false", - example = "true", - ) - @RequestParam(value = "currentPrisonOnly", required = false, defaultValue = "false") - currentPrisonOnly: Boolean, - @Schema( - description = "Returns only active non-association details for this prisoner", - required = false, - defaultValue = "false", - example = "true", - ) - @RequestParam(value = "excludeInactive", required = false, defaultValue = "false") - excludeInactive: Boolean, - ): LegacyPrisonerNonAssociations { - return nonAssociationsService.getLegacyDetails(prisonerNumber, currentPrisonOnly, excludeInactive) - } @GetMapping("/non-associations/{id}") @PreAuthorize("hasRole('ROLE_NON_ASSOCIATIONS_SYNC')") diff --git a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/service/NonAssociationsService.kt b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/service/NonAssociationsService.kt index a83597b9..9e573b0d 100644 --- a/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/service/NonAssociationsService.kt +++ b/src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/service/NonAssociationsService.kt @@ -20,9 +20,6 @@ import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.CreateNonAssocia import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.DeleteNonAssociationRequest import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.LegacyNonAssociation import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.LegacyNonAssociationOtherPrisonerDetails -import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.LegacyOtherPrisonerDetails -import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.LegacyPrisonerNonAssociation -import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.LegacyPrisonerNonAssociations import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.NonAssociationListInclusion import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.NonAssociationListOptions import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.PatchNonAssociationRequest @@ -270,18 +267,6 @@ class NonAssociationsService( return nonAssociationsRepository.findById(id).getOrNull()?.toLegacy() } - fun getLegacyDetails( - prisonerNumber: String, - currentPrisonOnly: Boolean = true, - excludeInactive: Boolean = true, - ): LegacyPrisonerNonAssociations { - val inclusion = if (excludeInactive) NonAssociationListInclusion.OPEN_ONLY else NonAssociationListInclusion.ALL - return getPrisonerNonAssociations( - prisonerNumber, - NonAssociationListOptions(inclusion = inclusion, includeOtherPrisons = !currentPrisonOnly), - ).toLegacy() - } - private fun filterByPrisonId(nonAssociations: List, prisonId: String): List { val prisonerNumbers = nonAssociations.flatMap { nonna -> listOf(nonna.firstPrisonerNumber, nonna.secondPrisonerNumber) @@ -320,36 +305,3 @@ private fun NonAssociationJPA.toLegacy(): LegacyNonAssociation { ), ) } - -private fun PrisonerNonAssociations.toLegacy() = - LegacyPrisonerNonAssociations( - offenderNo = this.prisonerNumber, - firstName = this.firstName, - lastName = this.lastName, - agencyId = this.prisonId, - agencyDescription = this.prisonName, - assignedLivingUnitDescription = this.cellLocation, - nonAssociations = this.nonAssociations.map { - val (reason, otherReason) = translateFromRolesAndReason(it.role, it.otherPrisonerDetails.role, it.reason) - LegacyPrisonerNonAssociation( - reasonCode = reason, - reasonDescription = reason.description, - typeCode = it.restrictionType.toLegacyRestrictionType(), - typeDescription = it.restrictionType.toLegacyRestrictionType().description, - effectiveDate = it.whenCreated, - expiryDate = it.closedAt, - authorisedBy = it.authorisedBy, - comments = it.comment, - offenderNonAssociation = LegacyOtherPrisonerDetails( - offenderNo = it.otherPrisonerDetails.prisonerNumber, - firstName = it.otherPrisonerDetails.firstName, - lastName = it.otherPrisonerDetails.lastName, - reasonCode = otherReason, - reasonDescription = otherReason.description, - agencyId = it.otherPrisonerDetails.prisonId, - agencyDescription = it.otherPrisonerDetails.prisonName, - assignedLivingUnitDescription = it.otherPrisonerDetails.cellLocation, - ), - ) - }, - ) diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/resource/NonAssociationsResourceTest.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/resource/NonAssociationsResourceTest.kt index 214b3212..84e00fe3 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/resource/NonAssociationsResourceTest.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/resource/NonAssociationsResourceTest.kt @@ -746,270 +746,6 @@ class NonAssociationsResourceTest : SqsIntegrationTestBase() { prisoners, ) } - - @Test - fun `a non-association that exists is returned in the legacy format for all NAs`() { - webTestClient.get() - .uri("/legacy/api/offenders/${prisonerMerlin.prisonerNumber}/non-association-details?currentPrisonOnly=false&excludeInactive=false") - .headers( - setAuthorisation(), - ) - .header("Content-Type", "application/json") - .exchange() - .expectStatus() - .isOk - .expectBody().json( - // language=json - """ - { - "offenderNo": "${prisonerMerlin.prisonerNumber}", - "firstName": "${prisonerMerlin.firstName}", - "lastName": "${prisonerMerlin.lastName}", - "agencyDescription": "${prisonerMerlin.prisonName}", - "assignedLivingUnitDescription": "${prisonerMerlin.cellLocation}", - "nonAssociations": [ - { - "reasonCode": "${otherPrisonNaLegacyReasons.second}", - "reasonDescription": "${otherPrisonNaLegacyReasons.second.description}", - "typeCode": "${otherPrisonNa.restrictionType.toLegacyRestrictionType()}", - "typeDescription": "${otherPrisonNa.restrictionType.toLegacyRestrictionType().description}", - "effectiveDate": "${otherPrisonNa.whenCreated.format(dtFormat)}", - "expiryDate": null, - "authorisedBy": "${otherPrisonNa.authorisedBy}", - "comments": "${otherPrisonNa.comment}", - "offenderNonAssociation": { - "offenderNo": "${prisonerEdward.prisonerNumber}", - "firstName": "${prisonerEdward.firstName}", - "lastName": "${prisonerEdward.lastName}", - "reasonCode": "${otherPrisonNaLegacyReasons.first}", - "reasonDescription": "${otherPrisonNaLegacyReasons.first.description}", - "agencyDescription": "${prisonerEdward.prisonName}", - "assignedLivingUnitDescription": "${prisonerEdward.cellLocation}" - } - }, - { - "reasonCode": "${closedNaLegacyReasons.first}", - "reasonDescription": "${closedNaLegacyReasons.first.description}", - "typeCode": "${closedNa.restrictionType.toLegacyRestrictionType()}", - "typeDescription": "${closedNa.restrictionType.toLegacyRestrictionType().description}", - "effectiveDate": "${closedNa.whenCreated.format(dtFormat)}", - "expiryDate": "${closedNa.closedAt?.format(dtFormat)}", - "authorisedBy": "${closedNa.authorisedBy}", - "comments": "${closedNa.comment}", - "offenderNonAssociation": { - "offenderNo": "${prisonerJosh.prisonerNumber}", - "firstName": "${prisonerJosh.firstName}", - "lastName": "${prisonerJosh.lastName}", - "reasonCode": "${closedNaLegacyReasons.second}", - "reasonDescription": "${closedNaLegacyReasons.second.description}", - "agencyDescription": "${prisonerJosh.prisonName}", - "assignedLivingUnitDescription": "${prisonerJosh.cellLocation}" - } - }, - { - "reasonCode": "${openNonAssociationLegacyReasons.second}", - "reasonDescription": "${openNonAssociationLegacyReasons.second.description}", - "typeCode": "${openNonAssociation.restrictionType.toLegacyRestrictionType()}", - "typeDescription": "${openNonAssociation.restrictionType.toLegacyRestrictionType().description}", - "effectiveDate": "${openNonAssociation.whenCreated.format(dtFormat)}", - "expiryDate": null, - "authorisedBy": "${openNonAssociation.authorisedBy}", - "comments": "${openNonAssociation.comment}", - "offenderNonAssociation": { - "offenderNo": "${prisonerJohn.prisonerNumber}", - "firstName": "${prisonerJohn.firstName}", - "lastName": "${prisonerJohn.lastName}", - "reasonCode": "${openNonAssociationLegacyReasons.first}", - "reasonDescription": "${openNonAssociationLegacyReasons.first.description}", - "agencyDescription": "${prisonerJohn.prisonName}", - "assignedLivingUnitDescription": "${prisonerJohn.cellLocation}" - } - } - ] - } - """, - false, - ) - } - - @Test - fun `a non-association that exists is returned in the legacy format for active only NAs`() { - webTestClient.get() - .uri("/legacy/api/offenders/${prisonerMerlin.prisonerNumber}/non-association-details?currentPrisonOnly=false&excludeInactive=true") - .headers( - setAuthorisation(), - ) - .header("Content-Type", "application/json") - .exchange() - .expectStatus() - .isOk - .expectBody().json( - // language=json - """ - { - "offenderNo": "${prisonerMerlin.prisonerNumber}", - "firstName": "${prisonerMerlin.firstName}", - "lastName": "${prisonerMerlin.lastName}", - "agencyDescription": "${prisonerMerlin.prisonName}", - "assignedLivingUnitDescription": "${prisonerMerlin.cellLocation}", - "nonAssociations": [ - { - "reasonCode": "${otherPrisonNaLegacyReasons.second}", - "reasonDescription": "${otherPrisonNaLegacyReasons.second.description}", - "typeCode": "${otherPrisonNa.restrictionType.toLegacyRestrictionType()}", - "typeDescription": "${otherPrisonNa.restrictionType.toLegacyRestrictionType().description}", - "effectiveDate": "${otherPrisonNa.whenCreated.format(dtFormat)}", - "expiryDate": null, - "authorisedBy": "${otherPrisonNa.authorisedBy}", - "comments": "${otherPrisonNa.comment}", - "offenderNonAssociation": { - "offenderNo": "${prisonerEdward.prisonerNumber}", - "firstName": "${prisonerEdward.firstName}", - "lastName": "${prisonerEdward.lastName}", - "reasonCode": "${otherPrisonNaLegacyReasons.first}", - "reasonDescription": "${otherPrisonNaLegacyReasons.first.description}", - "agencyDescription": "${prisonerEdward.prisonName}", - "assignedLivingUnitDescription": "${prisonerEdward.cellLocation}" - } - }, - { - "reasonCode": "${openNonAssociationLegacyReasons.second}", - "reasonDescription": "${openNonAssociationLegacyReasons.second.description}", - "typeCode": "${openNonAssociation.restrictionType.toLegacyRestrictionType()}", - "typeDescription": "${openNonAssociation.restrictionType.toLegacyRestrictionType().description}", - "effectiveDate": "${openNonAssociation.whenCreated.format(dtFormat)}", - "expiryDate": null, - "authorisedBy": "${openNonAssociation.authorisedBy}", - "comments": "${openNonAssociation.comment}", - "offenderNonAssociation": { - "offenderNo": "${prisonerJohn.prisonerNumber}", - "firstName": "${prisonerJohn.firstName}", - "lastName": "${prisonerJohn.lastName}", - "reasonCode": "${openNonAssociationLegacyReasons.first}", - "reasonDescription": "${openNonAssociationLegacyReasons.first.description}", - "agencyDescription": "${prisonerJohn.prisonName}", - "assignedLivingUnitDescription": "${prisonerJohn.cellLocation}" - } - } - ] - } - """, - false, - ) - } - - @Test - fun `a non-association that exists is returned in the legacy format for current active prison only`() { - webTestClient.get() - .uri("/legacy/api/offenders/${prisonerMerlin.prisonerNumber}/non-association-details?currentPrisonOnly=true&excludeInactive=true") - .headers( - setAuthorisation(), - ) - .header("Content-Type", "application/json") - .exchange() - .expectStatus() - .isOk - .expectBody().json( - // language=json - """ - { - "offenderNo": "${prisonerMerlin.prisonerNumber}", - "firstName": "${prisonerMerlin.firstName}", - "lastName": "${prisonerMerlin.lastName}", - "agencyDescription": "${prisonerMerlin.prisonName}", - "assignedLivingUnitDescription": "${prisonerMerlin.cellLocation}", - "nonAssociations": [ - { - "reasonCode": "${openNonAssociationLegacyReasons.second}", - "reasonDescription": "${openNonAssociationLegacyReasons.second.description}", - "typeCode": "${openNonAssociation.restrictionType.toLegacyRestrictionType()}", - "typeDescription": "${openNonAssociation.restrictionType.toLegacyRestrictionType().description}", - "effectiveDate": "${openNonAssociation.whenCreated.format(dtFormat)}", - "expiryDate": null, - "authorisedBy": "${openNonAssociation.authorisedBy}", - "comments": "${openNonAssociation.comment}", - "offenderNonAssociation": { - "offenderNo": "${prisonerJohn.prisonerNumber}", - "firstName": "${prisonerJohn.firstName}", - "lastName": "${prisonerJohn.lastName}", - "reasonCode": "${openNonAssociationLegacyReasons.first}", - "reasonDescription": "${openNonAssociationLegacyReasons.first.description}", - "agencyDescription": "${prisonerJohn.prisonName}", - "assignedLivingUnitDescription": "${prisonerJohn.cellLocation}" - } - } - ] - } - """, - false, - ) - } - - @Test - fun `a non-association that exists is returned in the legacy format for all active and inactive current prison only`() { - webTestClient.get() - .uri("/legacy/api/offenders/${prisonerMerlin.prisonerNumber}/non-association-details?currentPrisonOnly=true&excludeInactive=false") - .headers( - setAuthorisation(), - ) - .header("Content-Type", "application/json") - .exchange() - .expectStatus() - .isOk - .expectBody().json( - // language=json - """ - { - "offenderNo": "${prisonerMerlin.prisonerNumber}", - "firstName": "${prisonerMerlin.firstName}", - "lastName": "${prisonerMerlin.lastName}", - "agencyDescription": "${prisonerMerlin.prisonName}", - "assignedLivingUnitDescription": "${prisonerMerlin.cellLocation}", - "nonAssociations": [ - { - "reasonCode": "${closedNaLegacyReasons.first}", - "reasonDescription": "${closedNaLegacyReasons.first.description}", - "typeCode": "${closedNa.restrictionType.toLegacyRestrictionType()}", - "typeDescription": "${closedNa.restrictionType.toLegacyRestrictionType().description}", - "effectiveDate": "${closedNa.whenCreated.format(dtFormat)}", - "expiryDate": "${closedNa.closedAt?.format(dtFormat)}", - "authorisedBy": "${closedNa.authorisedBy}", - "comments": "${closedNa.comment}", - "offenderNonAssociation": { - "offenderNo": "${prisonerJosh.prisonerNumber}", - "firstName": "${prisonerJosh.firstName}", - "lastName": "${prisonerJosh.lastName}", - "reasonCode": "${closedNaLegacyReasons.second}", - "reasonDescription": "${closedNaLegacyReasons.second.description}", - "agencyDescription": "${prisonerJosh.prisonName}", - "assignedLivingUnitDescription": "${prisonerJosh.cellLocation}" - } - }, - { - "reasonCode": "${openNonAssociationLegacyReasons.second}", - "reasonDescription": "${openNonAssociationLegacyReasons.second.description}", - "typeCode": "${openNonAssociation.restrictionType.toLegacyRestrictionType()}", - "typeDescription": "${openNonAssociation.restrictionType.toLegacyRestrictionType().description}", - "effectiveDate": "${openNonAssociation.whenCreated.format(dtFormat)}", - "expiryDate": null, - "authorisedBy": "${openNonAssociation.authorisedBy}", - "comments": "${openNonAssociation.comment}", - "offenderNonAssociation": { - "offenderNo": "${prisonerJohn.prisonerNumber}", - "firstName": "${prisonerJohn.firstName}", - "lastName": "${prisonerJohn.lastName}", - "reasonCode": "${openNonAssociationLegacyReasons.first}", - "reasonDescription": "${openNonAssociationLegacyReasons.first.description}", - "agencyDescription": "${prisonerJohn.prisonName}", - "assignedLivingUnitDescription": "${prisonerJohn.cellLocation}" - } - } - ] - } - """, - false, - ) - } } @Nested diff --git a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/service/RoleAndReasonTranslation.kt b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/service/RoleAndReasonTranslation.kt index 208bea55..016cd4c4 100644 --- a/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/service/RoleAndReasonTranslation.kt +++ b/src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsnonassociationsapi/service/RoleAndReasonTranslation.kt @@ -9,43 +9,6 @@ import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.translateFromRol import uk.gov.justice.digital.hmpps.hmppsnonassociationsapi.dto.translateToRolesAndReason class RoleAndReasonTranslation { - @Test - fun `translating legacy reasons into modern roles and a reason`() { - fun assertThatLegacyReasons(firstPrisonerReason: LegacyReason, secondPrisonerReason: LegacyReason) = object { - fun translateInto(firstPrisonerRole: Role, secondPrisonerRole: Role, reason: Reason) { - assertThat(translateToRolesAndReason(firstPrisonerReason, secondPrisonerReason)).isEqualTo(Triple(firstPrisonerRole, secondPrisonerRole, reason)) - assertThat(translateToRolesAndReason(secondPrisonerReason, firstPrisonerReason)).isEqualTo(Triple(secondPrisonerRole, firstPrisonerRole, reason)) - } - } - - assertThatLegacyReasons(LegacyReason.BUL, LegacyReason.BUL).translateInto(Role.UNKNOWN, Role.UNKNOWN, Reason.BULLYING) - assertThatLegacyReasons(LegacyReason.BUL, LegacyReason.RIV).translateInto(Role.UNKNOWN, Role.NOT_RELEVANT, Reason.GANG_RELATED) - assertThatLegacyReasons(LegacyReason.BUL, LegacyReason.PER).translateInto(Role.UNKNOWN, Role.PERPETRATOR, Reason.BULLYING) - assertThatLegacyReasons(LegacyReason.BUL, LegacyReason.VIC).translateInto(Role.UNKNOWN, Role.VICTIM, Reason.BULLYING) - assertThatLegacyReasons(LegacyReason.BUL, LegacyReason.NOT_REL).translateInto(Role.UNKNOWN, Role.NOT_RELEVANT, Reason.BULLYING) - assertThatLegacyReasons(LegacyReason.BUL, LegacyReason.UNKNOWN).translateInto(Role.UNKNOWN, Role.UNKNOWN, Reason.BULLYING) - - assertThatLegacyReasons(LegacyReason.PER, LegacyReason.PER).translateInto(Role.PERPETRATOR, Role.PERPETRATOR, Reason.OTHER) - assertThatLegacyReasons(LegacyReason.PER, LegacyReason.RIV).translateInto(Role.PERPETRATOR, Role.NOT_RELEVANT, Reason.GANG_RELATED) - assertThatLegacyReasons(LegacyReason.PER, LegacyReason.VIC).translateInto(Role.PERPETRATOR, Role.VICTIM, Reason.OTHER) - assertThatLegacyReasons(LegacyReason.PER, LegacyReason.NOT_REL).translateInto(Role.PERPETRATOR, Role.NOT_RELEVANT, Reason.OTHER) - assertThatLegacyReasons(LegacyReason.PER, LegacyReason.UNKNOWN).translateInto(Role.PERPETRATOR, Role.UNKNOWN, Reason.OTHER) - - assertThatLegacyReasons(LegacyReason.RIV, LegacyReason.RIV).translateInto(Role.NOT_RELEVANT, Role.NOT_RELEVANT, Reason.GANG_RELATED) - assertThatLegacyReasons(LegacyReason.RIV, LegacyReason.VIC).translateInto(Role.NOT_RELEVANT, Role.VICTIM, Reason.GANG_RELATED) - assertThatLegacyReasons(LegacyReason.RIV, LegacyReason.NOT_REL).translateInto(Role.NOT_RELEVANT, Role.NOT_RELEVANT, Reason.GANG_RELATED) - assertThatLegacyReasons(LegacyReason.RIV, LegacyReason.UNKNOWN).translateInto(Role.NOT_RELEVANT, Role.UNKNOWN, Reason.GANG_RELATED) - - assertThatLegacyReasons(LegacyReason.VIC, LegacyReason.VIC).translateInto(Role.VICTIM, Role.VICTIM, Reason.OTHER) - assertThatLegacyReasons(LegacyReason.VIC, LegacyReason.NOT_REL).translateInto(Role.VICTIM, Role.NOT_RELEVANT, Reason.OTHER) - assertThatLegacyReasons(LegacyReason.VIC, LegacyReason.UNKNOWN).translateInto(Role.VICTIM, Role.UNKNOWN, Reason.OTHER) - - assertThatLegacyReasons(LegacyReason.NOT_REL, LegacyReason.NOT_REL).translateInto(Role.NOT_RELEVANT, Role.NOT_RELEVANT, Reason.OTHER) - assertThatLegacyReasons(LegacyReason.NOT_REL, LegacyReason.UNKNOWN).translateInto(Role.NOT_RELEVANT, Role.UNKNOWN, Reason.OTHER) - - assertThatLegacyReasons(LegacyReason.UNKNOWN, LegacyReason.UNKNOWN).translateInto(Role.UNKNOWN, Role.UNKNOWN, Reason.OTHER) - } - @Test fun `translating modern roles and a reason into legacy reasons`() { val allButBullyingAndGangRelatedReasons = Reason.entries.filter { it != Reason.BULLYING && it != Reason.GANG_RELATED }