From 2aff0512cdf6c5d04629ec284f1c140776f3f616 Mon Sep 17 00:00:00 2001 From: joseph-bcl <41573782+joseph-bcl@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:37:45 +0000 Subject: [PATCH] PI-2660 Fix stored procedure call (#4458) * PI-2660 bugfix * PI-2660 bugfix --- .../src/dev/resources/db/h2.sql | 8 -------- .../src/dev/resources/db/oracle.sql | 13 ------------- .../hmpps/integrations/delius/entity/Person.kt | 3 +++ .../justice/digital/hmpps/service/PersonService.kt | 9 +-------- .../src/main/resources/application.yml | 2 -- 5 files changed, 4 insertions(+), 31 deletions(-) delete mode 100644 projects/common-platform-and-delius/src/dev/resources/db/h2.sql delete mode 100644 projects/common-platform-and-delius/src/dev/resources/db/oracle.sql diff --git a/projects/common-platform-and-delius/src/dev/resources/db/h2.sql b/projects/common-platform-and-delius/src/dev/resources/db/h2.sql deleted file mode 100644 index 89bdf0a265..0000000000 --- a/projects/common-platform-and-delius/src/dev/resources/db/h2.sql +++ /dev/null @@ -1,8 +0,0 @@ -DROP SCHEMA IF EXISTS offender_support_api CASCADE; - -CREATE SCHEMA offender_support_api; - -CREATE ALIAS offender_support_api.getNextCRN AS -'String getNextCRN() { - return "A111111"; -}'; \ No newline at end of file diff --git a/projects/common-platform-and-delius/src/dev/resources/db/oracle.sql b/projects/common-platform-and-delius/src/dev/resources/db/oracle.sql deleted file mode 100644 index 5f651dd9cc..0000000000 --- a/projects/common-platform-and-delius/src/dev/resources/db/oracle.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE OR REPLACE PACKAGE offender_support_api AS - FUNCTION getNextCRN RETURN VARCHAR2; -END offender_support_api; - -GRANT EXECUTE ON offender_support_api TO delius_app_schema; - -CREATE OR REPLACE PACKAGE BODY offender_support_api AS - FUNCTION getNextCRN RETURN VARCHAR2 IS - BEGIN - RETURN 'A111111'; - END getNextCRN; -END offender_support_api; -/ \ No newline at end of file diff --git a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt index a67d7cb702..e7ceabe2bb 100644 --- a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt +++ b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/entity/Person.kt @@ -104,4 +104,7 @@ class Person( interface PersonRepository : JpaRepository { @Query("SELECT SOUNDEX(:name) FROM DUAL", nativeQuery = true) fun getSoundex(name: String): String + + @Query(value = "SELECT offender_support_api.getNextCRN FROM DUAL", nativeQuery = true) + fun getNextCrn(): String } \ No newline at end of file diff --git a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonService.kt b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonService.kt index a5ecc16b7b..c28a0aa9a8 100644 --- a/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonService.kt +++ b/projects/common-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonService.kt @@ -1,7 +1,5 @@ package uk.gov.justice.digital.hmpps.service -import org.springframework.jdbc.core.JdbcTemplate -import org.springframework.jdbc.core.simple.SimpleJdbcCall import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import uk.gov.justice.digital.hmpps.audit.service.AuditableService @@ -18,7 +16,6 @@ import java.time.Period @Service class PersonService( - jdbcTemplate: JdbcTemplate, auditedInteractionService: AuditedInteractionService, private val personRepository: PersonRepository, private val courtRepository: CourtRepository, @@ -30,10 +27,6 @@ class PersonService( private val personAddressRepository: PersonAddressRepository ) : AuditableService(auditedInteractionService) { - private val generateCrn = SimpleJdbcCall(jdbcTemplate) - .withCatalogName("offender_support_api") - .withFunctionName("getNextCRN") - @Transactional fun insertPerson(defendant: Defendant, courtCode: String): InsertPersonResult = audit(BusinessInteractionCode.INSERT_PERSON) { audit -> @@ -108,7 +101,7 @@ class PersonService( } fun generateCrn(): String { - return generateCrn.executeFunction(String::class.java) + return personRepository.getNextCrn() } fun String.toDeliusGender() = ReferenceData.GenderCode.entries.find { it.commonPlatformValue == this }?.deliusValue diff --git a/projects/common-platform-and-delius/src/main/resources/application.yml b/projects/common-platform-and-delius/src/main/resources/application.yml index d3c0873bb6..400dd58880 100644 --- a/projects/common-platform-and-delius/src/main/resources/application.yml +++ b/projects/common-platform-and-delius/src/main/resources/application.yml @@ -46,8 +46,6 @@ server.shutdown: immediate spring: datasource.url: jdbc:h2:file:./dev;MODE=Oracle;DEFAULT_NULL_ORDERING=HIGH;AUTO_SERVER=true;AUTO_SERVER_PORT=9092 - sql.init.mode: always - sql.init.data-locations: classpath:db/h2.sql jpa: hibernate.ddl-auto: create-drop