Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Separate out chronology and enumeration #127

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.olf.templateConfig

import org.olf.templateConfig.templateMetadataRule.TemplateMetadataRule
import org.olf.templateConfig.templateMetadataRule.ChronologyTemplateMetadataRule
import org.olf.templateConfig.templateMetadataRule.EnumerationTemplateMetadataRule

import org.olf.SerialRuleset

import grails.gorm.MultiTenant
Expand All @@ -13,10 +15,10 @@ public class TemplateConfig implements MultiTenant<TemplateConfig> {
String id
SerialRuleset owner
String templateString
// TODO Maybe seprate into two seperate lists for enumeration and chronology

static hasMany = [
rules: TemplateMetadataRule
chronologyRules: ChronologyTemplateMetadataRule,
enumerationRules: EnumerationTemplateMetadataRule
]

static belongsTo = [
Expand All @@ -28,12 +30,14 @@ public class TemplateConfig implements MultiTenant<TemplateConfig> {
owner column: 'tc_owner_fk'
version column: 'tc_version'
templateString column: 'tc_template_string'
rules cascade: 'all-delete-orphan', sort: 'index', order: 'asc'
chronologyRules cascade: 'all-delete-orphan', sort: 'index', order: 'asc'
enumerationRules cascade: 'all-delete-orphan', sort: 'index', order: 'asc'
}

static constraints = {
owner nullable: false
rules nullable: true
chronologyRules nullable: true
enumerationRules nullable: true
templateString nullable: false
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.olf.templateConfig.templateMetadataRule

import org.olf.templateConfig.templateMetadataRuleFormat.TemplateMetadataRuleFormat
import org.olf.templateConfig.TemplateConfig
import org.olf.templateConfig.templateMetadataRuleFormat.ChronologyTemplateMetadataRuleFormat
import org.olf.internalPiece.templateMetadata.ChronologyUCTMT

import java.util.regex.Pattern
Expand All @@ -16,7 +17,10 @@ import com.k_int.web.toolkit.refdata.CategoryId
import com.k_int.web.toolkit.refdata.Defaults
import com.k_int.web.toolkit.refdata.RefdataValue

public class ChronologyTemplateMetadataRule extends TemplateMetadataRuleType implements MultiTenant<ChronologyTemplateMetadataRule> {
public class ChronologyTemplateMetadataRule implements MultiTenant<ChronologyTemplateMetadataRule> {
String id
TemplateConfig owner
Integer index

@CategoryId(value="ChronologyTemplateMetadataRule.TemplateMetadataRuleFormat", defaultInternal=true)
// We setup these defaults within the HouseKeepingService in order to assign non-standard labels
Expand All @@ -25,32 +29,38 @@ public class ChronologyTemplateMetadataRule extends TemplateMetadataRuleType imp

String ruleLocale = 'en'

@BindUsing({ TemplateMetadataRuleType obj, SimpleMapDataBindingSource source ->
TemplateMetadataRuleTypeHelpers.doRuleFormatBinding(obj, source)
@BindUsing({ ChronologyTemplateMetadataRule obj, SimpleMapDataBindingSource source ->
ChronologyTemplateMetadataRuleHelpers.doRuleFormatBinding(obj, source)
})
TemplateMetadataRuleFormat ruleFormat
ChronologyTemplateMetadataRuleFormat ruleFormat

static hasOne = [
ruleFormat: TemplateMetadataRuleFormat
ruleFormat: ChronologyTemplateMetadataRuleFormat
]


static mapping = {
id column: 'ctmr_id', generator: 'uuid2', length: 36
owner column: 'ctmr_owner_fk'
index column: 'ctmr_index'
version column: 'ctmr_version'
templateMetadataRuleFormat column: 'ctmr_template_metadata_rule_format_fk'
ruleLocale column: 'ctmr_rule_locale'
ruleFormat cascade: 'all-delete-orphan'
}

static constraints = {
owner nullable: false
index nullable: false
templateMetadataRuleFormat nullable: false
ruleLocale nullable: false
ruleFormat nullable: false, validator: TemplateMetadataRuleTypeHelpers.ruleFormatValidator
ruleFormat nullable: false, validator: ChronologyTemplateMetadataRuleHelpers.ruleFormatValidator
}

public static ChronologyUCTMT handleType(TemplateMetadataRule rule, LocalDate date, int index) {
public static ChronologyUCTMT handleType(ChronologyTemplateMetadataRule rule, LocalDate date, int index) {
final Pattern RGX_RULE_FORMAT = Pattern.compile('_([a-z])')
String ruleFormatClassString = RGX_RULE_FORMAT.matcher(rule?.ruleType?.templateMetadataRuleFormat?.value).replaceAll { match -> match.group(1).toUpperCase() }
Class<? extends TemplateMetadataRuleFormat> rfc = Class.forName("org.olf.templateConfig.templateMetadataRuleFormat.${ruleFormatClassString.capitalize()}TMRF")
String ruleFormatClassString = RGX_RULE_FORMAT.matcher(rule?.templateMetadataRuleFormat?.value).replaceAll { match -> match.group(1).toUpperCase() }
Class<? extends ChronologyTemplateMetadataRuleFormat> rfc = Class.forName("org.olf.templateConfig.templateMetadataRuleFormat.${ruleFormatClassString.capitalize()}TMRF")
return rfc.handleFormat(rule, date, index)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.olf.templateConfig.templateMetadataRule

import org.olf.templateConfig.templateMetadataRuleFormat.TemplateMetadataRuleFormat
import org.olf.templateConfig.TemplateConfig
import org.olf.templateConfig.templateMetadataRuleFormat.EnumerationTemplateMetadataRuleFormat
import org.olf.internalPiece.templateMetadata.EnumerationUCTMT

import java.util.regex.Pattern
Expand All @@ -15,35 +16,45 @@ import com.k_int.web.toolkit.refdata.CategoryId
import com.k_int.web.toolkit.refdata.Defaults
import com.k_int.web.toolkit.refdata.RefdataValue

public class EnumerationTemplateMetadataRule extends TemplateMetadataRuleType implements MultiTenant<EnumerationTemplateMetadataRule> {
public class EnumerationTemplateMetadataRule implements MultiTenant<EnumerationTemplateMetadataRule> {
String id
TemplateConfig owner
Integer index

@CategoryId(value="EnumerationTemplateMetadataRule.TemplateMetadataRuleFormat", defaultInternal=true)
// We setup these defaults within the HouseKeepingService in order to assign non-standard labels
// @Defaults(['Enumeration Numeric', 'Enumeration Textual'])
RefdataValue templateMetadataRuleFormat

@BindUsing({ TemplateMetadataRuleType obj, SimpleMapDataBindingSource source ->
TemplateMetadataRuleTypeHelpers.doRuleFormatBinding(obj, source)
@BindUsing({ EnumerationTemplateMetadataRule obj, SimpleMapDataBindingSource source ->
EnumerationTemplateMetadataRuleHelpers.doRuleFormatBinding(obj, source)
})
TemplateMetadataRuleFormat ruleFormat
EnumerationTemplateMetadataRuleFormat ruleFormat

static hasOne = [
ruleFormat: TemplateMetadataRuleFormat
ruleFormat: EnumerationTemplateMetadataRuleFormat
]

static mapping = {
id column: 'etmr_id', generator: 'uuid2', length: 36
owner column: 'etmr_owner_fk'
index column: 'etmr_index'
version column: 'etmr_version'
templateMetadataRuleFormat column: 'etmr_template_metadata_rule_format_fk'
ruleFormat cascade: 'all-delete-orphan'
}

static constraints = {
owner nullable: false
index nullable: false
templateMetadataRuleFormat nullable: false
ruleFormat nullable: false, validator: TemplateMetadataRuleTypeHelpers.ruleFormatValidator
ruleFormat nullable: false, validator: EnumerationTemplateMetadataRuleHelpers.ruleFormatValidator
}

public static EnumerationUCTMT handleType(TemplateMetadataRule rule, LocalDate date, int index, EnumerationUCTMT startingValues) {
public static EnumerationUCTMT handleType(EnumerationTemplateMetadataRule rule, LocalDate date, int index, EnumerationUCTMT startingValues) {
final Pattern RGX_RULE_FORMAT = Pattern.compile('_([a-z])')
String ruleFormatClassString = RGX_RULE_FORMAT.matcher(rule?.ruleType?.templateMetadataRuleFormat?.value).replaceAll { match -> match.group(1).toUpperCase() }
Class<? extends TemplateMetadataRuleFormat> rfc = Class.forName("org.olf.templateConfig.templateMetadataRuleFormat.${ruleFormatClassString.capitalize()}TMRF")
String ruleFormatClassString = RGX_RULE_FORMAT.matcher(rule?.templateMetadataRuleFormat?.value).replaceAll { match -> match.group(1).toUpperCase() }
Class<? extends EnumerationTemplateMetadataRuleFormat> rfc = Class.forName("org.olf.templateConfig.templateMetadataRuleFormat.${ruleFormatClassString.capitalize()}TMRF")
return rfc.handleFormat(rule, date, index, startingValues)
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.olf.templateConfig.templateMetadataRuleFormat

import grails.gorm.MultiTenant

import org.olf.templateConfig.templateMetadataRule.TemplateMetadataRule
import org.olf.templateConfig.templateMetadataRule.ChronologyTemplateMetadataRule
import org.olf.internalPiece.templateMetadata.ChronologyUCTMT

import java.time.LocalDate
Expand All @@ -14,7 +14,7 @@ import com.k_int.web.toolkit.refdata.CategoryId
import com.k_int.web.toolkit.refdata.Defaults
import com.k_int.web.toolkit.refdata.RefdataValue

public class ChronologyDateTMRF extends TemplateMetadataRuleFormat implements MultiTenant<ChronologyDateTMRF> {
public class ChronologyDateTMRF extends ChronologyTemplateMetadataRuleFormat implements MultiTenant<ChronologyDateTMRF> {

@CategoryId(value="Global.WeekdayFormat", defaultInternal=true)
@Defaults(['Slice Lower', 'Slice Upper', 'Full Lower', 'Full Upper'])
Expand Down Expand Up @@ -76,9 +76,9 @@ public class ChronologyDateTMRF extends TemplateMetadataRuleFormat implements Mu
full_lower: 'EEEE',
]

public static ChronologyUCTMT handleFormat(TemplateMetadataRule rule, LocalDate date, int index) {
Locale locale = new Locale(rule?.ruleType?.ruleLocale)
ChronologyDateTMRF tmrf = rule?.ruleType?.ruleFormat
public static ChronologyUCTMT handleFormat(ChronologyTemplateMetadataRule rule, LocalDate date, int index) {
Locale locale = new Locale(rule?.ruleLocale)
ChronologyDateTMRF tmrf = rule?.ruleFormat
// TODO Dont handle if not a chronology rule
String weekday = date.format(DateTimeFormatter.ofPattern(weekdayFormatTransform.get(tmrf?.weekdayFormat?.value), locale))
if(tmrf?.weekdayFormat?.value.endsWith('upper')){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.olf.templateConfig.templateMetadataRuleFormat

import org.olf.templateConfig.templateMetadataRule.TemplateMetadataRule
import org.olf.templateConfig.templateMetadataRule.ChronologyTemplateMetadataRule
import org.olf.internalPiece.templateMetadata.ChronologyUCTMT

import grails.gorm.MultiTenant
Expand All @@ -14,7 +14,7 @@ import com.k_int.web.toolkit.refdata.CategoryId
import com.k_int.web.toolkit.refdata.Defaults
import com.k_int.web.toolkit.refdata.RefdataValue

public class ChronologyMonthTMRF extends TemplateMetadataRuleFormat implements MultiTenant<ChronologyMonthTMRF> {
public class ChronologyMonthTMRF extends ChronologyTemplateMetadataRuleFormat implements MultiTenant<ChronologyMonthTMRF> {

@CategoryId(value="Global.MonthFormat", defaultInternal=true)
@Defaults(['Full', 'Slice', 'Number'])
Expand All @@ -34,9 +34,9 @@ public class ChronologyMonthTMRF extends TemplateMetadataRuleFormat implements M
yearFormat nullable: false
}

public static ChronologyUCTMT handleFormat(TemplateMetadataRule rule, LocalDate date, int index) {
Locale locale = new Locale(rule?.ruleType?.ruleLocale)
ChronologyMonthTMRF tmrf = rule?.ruleType?.ruleFormat
public static ChronologyUCTMT handleFormat(ChronologyTemplateMetadataRule rule, LocalDate date, int index) {
Locale locale = new Locale(rule?.ruleLocale)
ChronologyMonthTMRF tmrf = rule?.ruleFormat
Map<String, String> getYearFormat = [
slice: 'yy',
full: 'yyyy',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.olf.templateConfig.templateMetadataRuleFormat

import org.olf.templateConfig.templateMetadataRule.ChronologyTemplateMetadataRule

import grails.gorm.MultiTenant

public abstract class ChronologyTemplateMetadataRuleFormat implements MultiTenant<ChronologyTemplateMetadataRuleFormat> {
String id
ChronologyTemplateMetadataRule owner

static mapping = {
id column: 'ctmrf_id', generator: 'uuid2', length: 36
owner column: 'ctmrf_owner_fk'
version column: 'ctmrf_version'

tablePerHierarchy false
}

static constraints = {
owner nullable: false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.olf.templateConfig.templateMetadataRuleFormat

import grails.gorm.MultiTenant

import org.olf.templateConfig.templateMetadataRule.TemplateMetadataRule
import org.olf.templateConfig.templateMetadataRule.ChronologyTemplateMetadataRule
import org.olf.internalPiece.templateMetadata.ChronologyUCTMT

import java.time.LocalDate
Expand All @@ -12,7 +12,7 @@ import com.k_int.web.toolkit.refdata.CategoryId
import com.k_int.web.toolkit.refdata.Defaults
import com.k_int.web.toolkit.refdata.RefdataValue

public class ChronologyYearTMRF extends TemplateMetadataRuleFormat implements MultiTenant<ChronologyYearTMRF> {
public class ChronologyYearTMRF extends ChronologyTemplateMetadataRuleFormat implements MultiTenant<ChronologyYearTMRF> {

@CategoryId(value="Global.YearFormat", defaultInternal=true)
@Defaults(['Full', 'Slice'])
Expand All @@ -26,9 +26,9 @@ public class ChronologyYearTMRF extends TemplateMetadataRuleFormat implements Mu
yearFormat nullable: false
}

public static ChronologyUCTMT handleFormat(TemplateMetadataRule rule, LocalDate date, int index) {
Locale locale = new Locale(rule?.ruleType?.ruleLocale)
ChronologyYearTMRF tmrf = rule?.ruleType?.ruleFormat
public static ChronologyUCTMT handleFormat(ChronologyTemplateMetadataRule rule, LocalDate date, int index) {
Locale locale = new Locale(rule?.ruleLocale)
ChronologyYearTMRF tmrf = rule?.ruleFormat
Map<String, String> getYearFormat = [
slice: 'yy',
full: 'yyyy',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.olf.templateConfig.templateMetadataRuleFormat

import org.olf.templateConfig.templateMetadataRule.TemplateMetadataRule
import org.olf.templateConfig.templateMetadataRule.EnumerationTemplateMetadataRule
import org.olf.internalPiece.templateMetadata.EnumerationUCTMT
import org.olf.internalPiece.templateMetadata.EnumerationLevelUCTMT

Expand All @@ -14,7 +14,7 @@ import com.k_int.web.toolkit.refdata.RefdataValue

import com.github.fracpete.romannumerals4j.RomanNumeralFormat;

public class EnumerationNumericTMRF extends TemplateMetadataRuleFormat implements MultiTenant<EnumerationNumericTMRF> {
public class EnumerationNumericTMRF extends EnumerationTemplateMetadataRuleFormat implements MultiTenant<EnumerationNumericTMRF> {
Set<EnumerationNumericLevelTMRF> levels

static hasMany = [
Expand All @@ -41,11 +41,11 @@ public class EnumerationNumericTMRF extends TemplateMetadataRuleFormat implement
}
}

public static EnumerationUCTMT handleFormat (TemplateMetadataRule rule, LocalDate date, int index, EnumerationUCTMT startingValues){
public static EnumerationUCTMT handleFormat (EnumerationTemplateMetadataRule rule, LocalDate date, int index, EnumerationUCTMT startingValues){
RomanNumeralFormat rnf = new RomanNumeralFormat();

// Array of EnumerationNumericLevels sorted by index
ArrayList<EnumerationNumericLevelTMRF> enltmrfArray = rule?.ruleType?.ruleFormat?.levels?.sort { it?.index }
ArrayList<EnumerationNumericLevelTMRF> enltmrfArray = rule?.ruleFormat?.levels?.sort { it?.index }
// Array of starting values sorted by index
ArrayList<EnumerationLevelUCTMT> levelStartingValueArray = startingValues?.levels?.sort { it?.index }
ArrayList<EnumerationLevelUCTMT> result = []
Expand Down
Loading
Loading