Skip to content

Commit

Permalink
fix: Final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Golding committed Jan 14, 2025
1 parent e6771c1 commit b9b1791
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,34 @@ class RulesetTemplateController extends OkapiTenantAwareController<RulesetTempla
super(RulesetTemplate)
}

@Transactional
// @Transactional
@Override
def save() {
RulesetTemplate.withTransaction {
def data = getObjectToBind()

SerialRuleset ruleset = new SerialRuleset(data?.serialRuleset).save(failOnError: true)

RulesetTemplate rulesetTemplate = new RulesetTemplate([
name: data?.name,
description: data?.description,
exampleLabel: data?.exampleLabel,
]).save()
rulesetTemplateStatus: data?.rulesetTemplateStatus
// serialRuleset: ruleset
])

SerialRuleset ruleset = new SerialRuleset(data?.serialRuleset)
ruleset.owner = rulesetTemplate.id
ruleset.save(failOnError: true)
rulesetTemplate.serialRuleset = ruleset

rulesetTemplate.setSerialRuleset(ruleset)
rulesetTemplate.save(failOnError: true)



// SerialRuleset ruleset = new SerialRuleset(data?.serialRuleset)
// ruleset.owner = rulesetTemplate.id
// ruleset.save(failOnError: true)
// rulesetTemplate.serialRuleset = ruleset

// rulesetTemplate.save(failOnError: true)

respond rulesetTemplate
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class SerialRulesetController extends OkapiTenantAwareController<SerialRuleset>
def save() {
SerialRuleset.withTransaction {
def data = getObjectToBind()

SerialRuleset ruleset = new SerialRuleset(data)
activeRulesetCheck(ruleset)

Expand Down
1 change: 1 addition & 0 deletions service/grails-app/domain/org/olf/RulesetOwner.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class RulesetOwner implements MultiTenant<RulesetOwner> {
lastUpdated column: 'ro_last_updated'
dateCreated column: 'ro_date_created'
version column: 'ro_version'
tablePerHierarchy false
}

static constraints = {
Expand Down
6 changes: 6 additions & 0 deletions service/grails-app/domain/org/olf/RulesetTemplate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ import org.springframework.validation.Errors
import groovy.sql.Sql


// ModelRuleset

@GrailsCompileStatic
class RulesetTemplate extends RulesetOwner implements MultiTenant<RulesetTemplate> {

String id
String name
String description
String exampleLabel

SerialRuleset serialRuleset

@CategoryId(defaultInternal=true)
@Defaults(['Active', 'Closed'])
RefdataValue rulesetTemplateStatus
Expand All @@ -35,6 +40,7 @@ class RulesetTemplate extends RulesetOwner implements MultiTenant<RulesetTemplat
]

static mapping = {
id column: 'rt_id', generator: 'uuid2', length: 36
name column: 'rt_name'
description column: 'rt_description'
exampleLabel column: 'rt_example_label'
Expand Down
7 changes: 4 additions & 3 deletions service/grails-app/domain/org/olf/Serial.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import groovy.sql.Sql
class Serial extends RulesetOwner implements MultiTenant<Serial> {

// TODO Remove commented properties before merging
// String id
String id
// Date lastUpdated
// Date dateCreated
String description
Expand All @@ -39,11 +39,12 @@ class Serial extends RulesetOwner implements MultiTenant<Serial> {

static mappedBy = [
orderLine: 'owner',
recurrence: 'owner'
recurrence: 'owner',
serialRulesets: 'owner'
]

static mapping = {
// id column: 's_id', generator: 'uuid2', length: 36
id column: 's_id', generator: 'uuid2', length: 36
// lastUpdated column: 's_last_updated'
// dateCreated column: 's_date_created'
serialStatus column: 's_serial_status'
Expand Down
7 changes: 2 additions & 5 deletions service/grails-app/domain/org/olf/SerialRuleset.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class SerialRuleset implements MultiTenant<SerialRuleset> {
String rulesetNumber
String description

RulesetOwner owner

@CategoryId(defaultInternal=true)
@Defaults(['Active', 'Draft', 'Deprecated'])
RefdataValue rulesetStatus
Expand All @@ -44,11 +46,6 @@ class SerialRuleset implements MultiTenant<SerialRuleset> {
templateConfig: 'owner'
]

static belongsTo = [
owner: RulesetOwner
// predictedPieceSet: PredictedPieceSet
]

static mapping = {
id column: 'sr_id', generator: 'uuid2', length: 36
lastUpdated column: 'sr_last_updated'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@ databaseChangeLog = {
}
}

changeSet(author: "Jack-Golding (manual)", id: "20250111-1201-002") {
changeSet(author: "Jack-Golding (manual)", id: "20250111-1201-003") {
dropColumn(columnName: "s_version", tableName: "serial")
}

changeSet(author: "Jack-Golding (manual)", id: "20250111-1201-004") {
createTable(tableName: "ruleset_template") {
column(name: "rt_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "rt_name", type: "TEXT") { constraints(nullable: "false") }
column(name: "rt_description", type: "TEXT") { constraints(nullable: "true") }
column(name: "rt_example_label", type: "TEXT") { constraints(nullable: "true") }
column(name: "rt_ruleset_template_status", type: "VARCHAR(36)") { constraints(nullable: "false") }
}
}

changeSet(author: "Jack-Golding (manual)", id: "20250111-1201-005") {
dropForeignKeyConstraint(baseTableName: "serial_ruleset", constraintName: "serial_ruleset_owner_fk")
}
// Add migrations for old serial data
// Add FK constraint to ruleset owner
}
12 changes: 12 additions & 0 deletions service/grails-app/views/rulesetOwner/_rulesetOwner.gson
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import groovy.transform.*
import org.olf.RulesetOwner
import groovy.transform.Field
import org.grails.orm.hibernate.cfg.GrailsHibernateUtil

def should_expand = []

@Field RulesetOwner rulesetOwner

rulesetOwner = GrailsHibernateUtil.unwrapIfProxy(rulesetOwner) as RulesetOwner

json g.render(rulesetOwner, [expand: should_expand])
12 changes: 12 additions & 0 deletions service/grails-app/views/rulesetTemplate/_rulesetTemplate.gson
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import groovy.transform.*
import org.olf.RulesetTemplate
import groovy.transform.Field

def should_expand = [
'rulesetTemplateStatus',
'serialRuleset',
]

@Field RulesetTemplate rulesetTemplate

json g.render(rulesetTemplate, [expand: should_expand])

0 comments on commit b9b1791

Please sign in to comment.