Skip to content

Commit

Permalink
refactor: Hashset changes (#49)
Browse files Browse the repository at this point in the history
* fix: IN PROGRESS Ordering of template metadata rules

* IN PROGRESS: Rules sizes logs

* chore: Be specific with the type to help reference inference.

* fix: Prevent the owner of the rule being bound to

This prevents a circular binding issue where the owner is bound again
causing collections to have all the current bound elements added again.
When the collection is a set, we won't see duplicates but in lists this
can lead to element duplication

* revert: List changes

* feat: hasMany Changes

* chore: Cleanup

---------

Co-authored-by: Steve Osguthorpe <steve.osguthorpe@k-int.com>
Jack-Golding and sosguthorpe authored Jan 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7aa3c30 commit e3b0697
Showing 4 changed files with 38 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -9,10 +9,9 @@ import java.time.LocalDate

import grails.rest.*
import grails.converters.*
import org.grails.web.json.JSONObject
import org.json.JSONObject
import grails.gorm.transactions.Transactional
import grails.gorm.multitenancy.CurrentTenant
import groovy.json.JsonOutput
import groovy.util.logging.Slf4j

import java.util.regex.Pattern
@@ -25,15 +24,14 @@ class PredictedPiecesController {
// PredictedPiecesController(){
// super()
// }

// This takes in a JSON shape and outputs predicted pieces without saving domain objects
@Transactional
@Transactional
def generatePredictedPiecesTransient() {
final data = request.JSON
// Do not save this -- Is casting this all in one go ok?
// FIXME DO NOT SAVE
// SerialRuleset ruleset = new SerialRuleset(data).save(flush: true, failOnError: true)
SerialRuleset ruleset = new SerialRuleset(data)
JSONObject data = request.JSON
// SerialRuleset ruleset = new SerialRuleset(data.toMap()).save(flush: true, failOnError: true)
SerialRuleset ruleset = new SerialRuleset(data.toMap())

// TODO Should we validate this?
ArrayList<InternalPiece> result = pieceGenerationService.createPiecesTransient(ruleset, LocalDate.parse(data.startDate))
respond result
Original file line number Diff line number Diff line change
@@ -13,17 +13,16 @@ public class TemplateConfig implements MultiTenant<TemplateConfig> {
String id
SerialRuleset owner
String templateString
// TODO Mayeb seprate into two seperate lists for enumeration and chronology
ArrayList<TemplateMetadataRule> rules
// TODO Maybe seprate into two seperate lists for enumeration and chronology

static hasMany = [
rules: TemplateMetadataRule
]

static belongsTo = [
owner: SerialRuleset
]

static hasMany = [
rules : TemplateMetadataRule
]

static mapping = {
id column: 'tc_id', generator: 'uuid2', length: 36
owner column: 'tc_owner_fk'
32 changes: 22 additions & 10 deletions service/grails-app/migrations/create-mod-serials-management.groovy
Original file line number Diff line number Diff line change
@@ -1230,14 +1230,14 @@ databaseChangeLog = {

changeSet(author: "Jack-Golding (manual)", id: "20231001-1230-004"){
createTable(tableName: "chronology_template_metadata_rule") {
column(name: "ctmr_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "tmrt_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "ctmr_template_metadata_rule_format_fk", type: "VARCHAR(36)") { constraints(nullable: "false") }
}
}

changeSet(author: "Jack-Golding (manual)", id: "20231001-1230-005"){
createTable(tableName: "enumeration_template_metadata_rule") {
column(name: "etmr_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "tmrt_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "etmr_template_metadata_rule_format_fk", type: "VARCHAR(36)") { constraints(nullable: "false") }
}
}
@@ -1251,8 +1251,8 @@ databaseChangeLog = {
}

changeSet(author: "Jack-Golding (manual)", id: "20231001-1230-007"){
createTable(tableName: "chronology_date_tmrf") {
column(name: "cdtmrf_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
createTable(tableName: "chronology_datetmrf") {
column(name: "tmrf_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "cdtmrf_weekday_format_fk", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "cdtmrf_month_day_format_fk", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "cdtmrf_month_format_fk", type: "VARCHAR(36)") { constraints(nullable: "false") }
@@ -1261,22 +1261,22 @@ databaseChangeLog = {
}

changeSet(author: "Jack-Golding (manual)", id: "20231001-1230-008"){
createTable(tableName: "chronology_month_tmrf") {
column(name: "cmtmrf_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
createTable(tableName: "chronology_monthtmrf") {
column(name: "tmrf_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "cmtmrf_month_format_fk", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "cmtmrf_year_format_fk", type: "VARCHAR(36)") { constraints(nullable: "false") }
}
}

changeSet(author: "Jack-Golding (manual)", id: "20231001-1230-009"){
createTable(tableName: "chronology_year_tmrf") {
column(name: "cytmrf_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
createTable(tableName: "chronology_yeartmrf") {
column(name: "tmrf_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "cytmrf_year_format_fk", type: "VARCHAR(36)") { constraints(nullable: "false") }
}
}

changeSet(author: "Jack-Golding (manual)", id: "20231001-1230-010"){
createTable(tableName: "enumeration_numeric_level_tmrf") {
createTable(tableName: "enumeration_numeric_leveltmrf") {
column(name: "enltmrf_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "enltmrf_owner_fk", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "enltmrf_version", type: "BIGINT") { constraints(nullable: "false") }
@@ -1288,7 +1288,7 @@ databaseChangeLog = {
}

changeSet(author: "Jack-Golding (manual)", id: "20231001-1230-011"){
createTable(tableName: "enumeration_textual_level_tmrf") {
createTable(tableName: "enumeration_textual_leveltmrf") {
column(name: "etltmrf_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "etltmrf_owner_fk", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "etltmrf_version", type: "BIGINT") { constraints(nullable: "false") }
@@ -1304,4 +1304,16 @@ databaseChangeLog = {
column(name: "ip_label", type: "TEXT") { constraints(nullable: "true") }
}
}

changeSet(author: "Jack-Golding (manual)", id: "20231207-1230-001"){
createTable(tableName: "enumeration_numerictmrf") {
column(name: "tmrf_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
}
}

changeSet(author: "Jack-Golding (manual)", id: "20231207-1230-002"){
createTable(tableName: "enumeration_textualtmrf") {
column(name: "tmrf_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
}
}
}
Original file line number Diff line number Diff line change
@@ -139,9 +139,9 @@ public class PieceLabellingService {

}

public ArrayList<ChronologyTemplateMetadata> generateChronologyMetadata(StandardTemplateMetadata standardTM, ArrayList<TemplateMetadataRule> templateMetadataRules) {
public ArrayList<ChronologyTemplateMetadata> generateChronologyMetadata(StandardTemplateMetadata standardTM, Set<TemplateMetadataRule> templateMetadataRules) {
ArrayList<ChronologyTemplateMetadata> chronologyTemplateMetadataArray = []
ListIterator<TemplateMetadataRule> iterator = templateMetadataRules?.listIterator()
Iterator<TemplateMetadataRule> iterator = templateMetadataRules?.iterator()
while(iterator?.hasNext()){
TemplateMetadataRule currentMetadataRule = iterator.next()
String templateMetadataType = RGX_METADATA_RULE_TYPE.matcher(currentMetadataRule?.templateMetadataRuleType?.value).replaceAll { match -> match.group(1).toUpperCase() }
@@ -154,9 +154,9 @@ public class PieceLabellingService {
return chronologyTemplateMetadataArray
}

public ArrayList<EnumerationTemplateMetadata> generateEnumerationMetadata(StandardTemplateMetadata standardTM, ArrayList<TemplateMetadataRule> templateMetadataRules) {
public ArrayList<EnumerationTemplateMetadata> generateEnumerationMetadata(StandardTemplateMetadata standardTM, Set<TemplateMetadataRule> templateMetadataRules) {
ArrayList<EnumerationTemplateMetadata> enumerationTemplateMetadataArray = []
ListIterator<TemplateMetadataRule> iterator = templateMetadataRules?.listIterator()
Iterator<TemplateMetadataRule> iterator = templateMetadataRules?.iterator()
while(iterator?.hasNext()){
TemplateMetadataRule currentMetadataRule = iterator.next()
String templateMetadataType = RGX_METADATA_RULE_TYPE.matcher(currentMetadataRule?.templateMetadataRuleType?.value).replaceAll { match -> match.group(1).toUpperCase() }

0 comments on commit e3b0697

Please sign in to comment.