Skip to content

Commit

Permalink
MODSER-53: Add fall back for publication pattern numbering (#115)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Jack-Golding authored Oct 15, 2024
1 parent 29010bc commit 128d83f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 21 additions & 1 deletion service/grails-app/domain/org/olf/SerialRuleset.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,25 @@ class SerialRuleset implements MultiTenant<SerialRuleset> {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 128d83f

Please sign in to comment.