Skip to content

Commit

Permalink
MAP-365 Remove legacy non-associations code (#321)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mjwillis authored Jul 18, 2024
1 parent a9219e5 commit 2e4a4a9
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 484 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<NonAssociationJPA>, prisonId: String): List<NonAssociationJPA> {
val prisonerNumbers = nonAssociations.flatMap { nonna ->
listOf(nonna.firstPrisonerNumber, nonna.secondPrisonerNumber)
Expand Down Expand Up @@ -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,
),
)
},
)
Loading

0 comments on commit 2e4a4a9

Please sign in to comment.