From ee0babc95a89e66927f05ec97e270188bce0cec7 Mon Sep 17 00:00:00 2001 From: Michael Willis Date: Mon, 9 Dec 2024 18:35:57 +0000 Subject: [PATCH] IR-719 remove geographical region for now - due to mapping issues. (#2310) * IR-719 remove geographical region for now - due to mapping issues. * IR-719 remove geographical region for now - due to mapping issues. * IR-719 remove geographical region for now - due to mapping issues. * IR-719 remove geographical region for now - due to mapping issues. --- .../hmpps/prison/api/model/Agency.java | 7 +------ .../hmpps/prison/api/model/AgencyDto.kt | 1 - .../repository/jpa/model/AgencyLocation.java | 13 ++----------- .../repository/jpa/model/GeographicRegion.kt | 19 ------------------- .../jpa/repository/AgencyLocationFilter.java | 6 ------ .../transformers/AgencyTransformer.java | 3 +-- .../resource/impl/AgencyResourceIntTest.kt | 3 --- .../AgencyLocationRepositoryTest.kt | 10 ---------- 8 files changed, 4 insertions(+), 58 deletions(-) delete mode 100644 src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/model/GeographicRegion.kt diff --git a/src/main/java/uk/gov/justice/hmpps/prison/api/model/Agency.java b/src/main/java/uk/gov/justice/hmpps/prison/api/model/Agency.java index 7c7f8cd6f..a144e7276 100644 --- a/src/main/java/uk/gov/justice/hmpps/prison/api/model/Agency.java +++ b/src/main/java/uk/gov/justice/hmpps/prison/api/model/Agency.java @@ -5,7 +5,6 @@ import lombok.Builder; import lombok.Builder.Default; import lombok.Data; -import uk.gov.justice.hmpps.prison.api.model.v1.CodeDescription; import java.time.LocalDate; import java.util.List; @@ -57,10 +56,7 @@ public class Agency { @Schema(description = "Region of this agency") private RefCodeAndDescription region; - @Schema(description = "Geographical region for this agency") - private RefCodeAndDescription geographicalRegion; - - public Agency(String agencyId, String description, String longDescription, String agencyType, boolean active, String courtType, String courtTypeDescription, LocalDate deactivationDate, List addresses, List phones, List emails, RefCodeAndDescription area, RefCodeAndDescription region, RefCodeAndDescription geographicalRegion) { + public Agency(String agencyId, String description, String longDescription, String agencyType, boolean active, String courtType, String courtTypeDescription, LocalDate deactivationDate, List addresses, List phones, List emails, RefCodeAndDescription area, RefCodeAndDescription region) { this.agencyId = agencyId; this.description = description; this.longDescription = longDescription; @@ -74,7 +70,6 @@ public Agency(String agencyId, String description, String longDescription, Strin this.emails = emails; this.area = area; this.region = region; - this.geographicalRegion = geographicalRegion; } public Agency() { diff --git a/src/main/java/uk/gov/justice/hmpps/prison/api/model/AgencyDto.kt b/src/main/java/uk/gov/justice/hmpps/prison/api/model/AgencyDto.kt index ae135684d..2358efb40 100644 --- a/src/main/java/uk/gov/justice/hmpps/prison/api/model/AgencyDto.kt +++ b/src/main/java/uk/gov/justice/hmpps/prison/api/model/AgencyDto.kt @@ -24,6 +24,5 @@ data class AgencyDto( null, null, null, - null, ) } diff --git a/src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/model/AgencyLocation.java b/src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/model/AgencyLocation.java index b92e4f985..ffe523349 100644 --- a/src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/model/AgencyLocation.java +++ b/src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/model/AgencyLocation.java @@ -24,6 +24,8 @@ import org.hibernate.annotations.JoinColumnOrFormula; import org.hibernate.annotations.JoinColumnsOrFormulas; import org.hibernate.annotations.JoinFormula; +import org.hibernate.annotations.NotFound; +import org.hibernate.annotations.NotFoundAction; import org.hibernate.annotations.Where; import org.hibernate.type.YesNoConverter; @@ -37,7 +39,6 @@ import static uk.gov.justice.hmpps.prison.repository.jpa.model.AgencyLocationType.AGY_LOC_TYPE; import static uk.gov.justice.hmpps.prison.repository.jpa.model.CourtType.JURISDICTION; -import static uk.gov.justice.hmpps.prison.repository.jpa.model.GeographicRegion.GEOGRAPHIC; @Data @Entity @@ -71,9 +72,6 @@ @NamedAttributeNode(value = "courtType"), @NamedAttributeNode(value = "region"), @NamedAttributeNode(value = "area"), - @NamedAttributeNode(value = "geographicRegion"), - - } ) public class AgencyLocation extends AuditableEntity { @@ -144,13 +142,6 @@ public class AgencyLocation extends AuditableEntity { @JoinColumn(name = "NOMS_REGION_CODE") private Region region; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumnsOrFormulas(value = { - @JoinColumnOrFormula(formula = @JoinFormula(value = "'" + GEOGRAPHIC + "'", referencedColumnName = "domain")), - @JoinColumnOrFormula(column = @JoinColumn(name = "GEOGRAPHIC_REGION_CODE", referencedColumnName = "code")) - }) - private GeographicRegion geographicRegion; - public void removeAddress(final AgencyAddress address) { addresses.remove(address); } diff --git a/src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/model/GeographicRegion.kt b/src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/model/GeographicRegion.kt deleted file mode 100644 index 830847c80..000000000 --- a/src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/model/GeographicRegion.kt +++ /dev/null @@ -1,19 +0,0 @@ -package uk.gov.justice.hmpps.prison.repository.jpa.model - -import jakarta.persistence.DiscriminatorValue -import jakarta.persistence.Entity -import lombok.NoArgsConstructor - -@Entity -@DiscriminatorValue(GeographicRegion.GEOGRAPHIC) -@NoArgsConstructor -class GeographicRegion(code: String?, description: String?) : - ReferenceCode(GEOGRAPHIC, code, description) { - - companion object { - const val GEOGRAPHIC: String = "GEOGRAPHIC" - fun pk(code: String?): Pk { - return Pk(GEOGRAPHIC, code) - } - } -} diff --git a/src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/repository/AgencyLocationFilter.java b/src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/repository/AgencyLocationFilter.java index 4bd887323..38f079383 100644 --- a/src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/repository/AgencyLocationFilter.java +++ b/src/main/java/uk/gov/justice/hmpps/prison/repository/jpa/repository/AgencyLocationFilter.java @@ -37,8 +37,6 @@ public class AgencyLocationFilter implements Specification { private String region; - private String geographicRegion; - private String establishmentType; public Predicate toPredicate(final Root root, final CriteriaQuery query, final CriteriaBuilder cb) { @@ -72,10 +70,6 @@ public Predicate toPredicate(final Root root, final CriteriaQuer predicateBuilder.add(cb.equal(root.get("region").get("code"), region)); } - if (geographicRegion != null) { - predicateBuilder.add(cb.equal(root.get("geographicRegion").get("code"), geographicRegion)); - } - if (establishmentType != null) { predicateBuilder.add(cb.equal(root.get("establishmentTypes").get("establishmentType").get("code"), establishmentType)); } diff --git a/src/main/java/uk/gov/justice/hmpps/prison/service/transformers/AgencyTransformer.java b/src/main/java/uk/gov/justice/hmpps/prison/service/transformers/AgencyTransformer.java index 99d269e73..4f2c10e19 100644 --- a/src/main/java/uk/gov/justice/hmpps/prison/service/transformers/AgencyTransformer.java +++ b/src/main/java/uk/gov/justice/hmpps/prison/service/transformers/AgencyTransformer.java @@ -44,8 +44,7 @@ private static AgencyBuilder transformToBuilder(final AgencyLocation agency, fin .longDescription(agency.getLongDescription()) .deactivationDate(agency.getDeactivationDate()) .area(withAreas ? agency.getArea() != null ? agency.getArea().toDto() : null : null) - .region(withAreas ? agency.getRegion() != null ? agency.getRegion().toDto() : null : null) - .geographicalRegion(withAreas ? agency.getGeographicRegion() != null ? agency.getGeographicRegion().toDto() : null : null); + .region(withAreas ? agency.getRegion() != null ? agency.getRegion().toDto() : null : null); } static private String codeOrNull(final ReferenceCode referenceData) { diff --git a/src/test/java/uk/gov/justice/hmpps/prison/api/resource/impl/AgencyResourceIntTest.kt b/src/test/java/uk/gov/justice/hmpps/prison/api/resource/impl/AgencyResourceIntTest.kt index 5d1460f6b..147a5859d 100644 --- a/src/test/java/uk/gov/justice/hmpps/prison/api/resource/impl/AgencyResourceIntTest.kt +++ b/src/test/java/uk/gov/justice/hmpps/prison/api/resource/impl/AgencyResourceIntTest.kt @@ -291,10 +291,8 @@ class AgencyResourceIntTest : ResourceTest() { .jsonPath("$[?(@.agencyId=='BMI')].area.code").isEqualTo("WMID") .jsonPath("$[?(@.agencyId=='BMI')].area.description").isEqualTo("West Midlands") .jsonPath("$[?(@.agencyId=='BMI')].region.description").isEqualTo("West Midlands") - .jsonPath("$[?(@.agencyId=='BMI')].geographicalRegion.description").isEqualTo("West Midlands") .jsonPath("$[?(@.agencyId=='WAI')].area.description").isEqualTo("West Midlands") .jsonPath("$[?(@.agencyId=='WAI')].region.description").isEqualTo("West Midlands") - .jsonPath("$[?(@.agencyId=='WAI')].geographicalRegion.description").isEqualTo("West Midlands") } @Test @@ -308,7 +306,6 @@ class AgencyResourceIntTest : ResourceTest() { .jsonPath("$[?(@.agencyId=='BXI')].area.description").isEqualTo("London") .jsonPath("$[?(@.agencyId=='BXI')].region.code").isEqualTo("LON") .jsonPath("$[?(@.agencyId=='BXI')].region.description").isEqualTo("London") - .jsonPath("$[?(@.agencyId=='BXI')].geographicalRegion.description").isEqualTo("London") .jsonPath("$[?(@.agencyId=='BWI')]").doesNotExist() .jsonPath("$[?(@.agencyId=='MDI')]").doesNotExist() } diff --git a/src/test/java/uk/gov/justice/hmpps/prison/repository/jpa/repository/AgencyLocationRepositoryTest.kt b/src/test/java/uk/gov/justice/hmpps/prison/repository/jpa/repository/AgencyLocationRepositoryTest.kt index ef5665e13..030f3589e 100644 --- a/src/test/java/uk/gov/justice/hmpps/prison/repository/jpa/repository/AgencyLocationRepositoryTest.kt +++ b/src/test/java/uk/gov/justice/hmpps/prison/repository/jpa/repository/AgencyLocationRepositoryTest.kt @@ -93,16 +93,6 @@ class AgencyLocationRepositoryTest { assertThat(agencies).extracting("id").containsAnyOf("BMI", "WAI") } - @Test - fun findAgenciesWithGeographicCodes() { - val expected = AgencyLocationFilter.builder() - .active(true) - .geographicRegion("WMID") - .build() - val agencies = repository.findAll(expected) - assertThat(agencies).extracting("id").containsAnyOf("BMI", "WAI") - } - @Test fun findAgenciesWithEstablishmentType() { val expected = AgencyLocationFilter.builder()