From 128d83f10c60d65171d492f6bb6054473440ec6e Mon Sep 17 00:00:00 2001 From: Jack-Golding <94838251+Jack-Golding@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:10:59 +0100 Subject: [PATCH] MODSER-53: Add fall back for publication pattern numbering (#115) * feat: Add fall back for publication pattern numbering Added sequence to be used as fallback for serial ruleset numbering and implemented into the rulesets beforeValidate function * fix: Incorrect class Fixed error with incorrect class being used --- .../domain/org/olf/SerialRuleset.groovy | 22 ++++++++++++++++++- .../update-mod-serials-management-1-1.groovy | 4 ++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/service/grails-app/domain/org/olf/SerialRuleset.groovy b/service/grails-app/domain/org/olf/SerialRuleset.groovy index 998d508..fa99662 100644 --- a/service/grails-app/domain/org/olf/SerialRuleset.groovy +++ b/service/grails-app/domain/org/olf/SerialRuleset.groovy @@ -76,5 +76,25 @@ class SerialRuleset implements MultiTenant { omission nullable: true combination nullable: true templateConfig nullable: true - } + } + + def beforeValidate() { + if ( rulesetNumber == null ) { + this.rulesetNumber = generateHrid() + } + } + + private String generateHrid() { + String result = null; + + // Use this to make sessionFactory.currentSession work as expected + SerialRuleset.withSession { SessionImpl session -> + log.debug("Generate hrid"); + def sql = new Sql(session.connection()) + def query_result = sql.rows("select nextval('serial_ruleset_hrid_seq')".toString()) + log.debug("Query result: ${query_result.toString()}") + result = query_result[0].get('nextval')?.toString() + } + return result; + } } diff --git a/service/grails-app/migrations/update-mod-serials-management-1-1.groovy b/service/grails-app/migrations/update-mod-serials-management-1-1.groovy index 30ded0e..84e0cc6 100644 --- a/service/grails-app/migrations/update-mod-serials-management-1-1.groovy +++ b/service/grails-app/migrations/update-mod-serials-management-1-1.groovy @@ -81,4 +81,8 @@ databaseChangeLog = { column(name: "eluctmt_value_format_fk", type: "VARCHAR(36)") { constraints(nullable: "true") } } } + + changeSet(author: "Jack-Golding (manual)", id: "20241015-1457-001") { + createSequence(sequenceName: "serial_ruleset_hrid_seq") + } } \ No newline at end of file