Skip to content

Commit

Permalink
[#4]
Browse files Browse the repository at this point in the history
allow horizontal/column/pivotted name configuration
  • Loading branch information
scalding committed Sep 16, 2013
1 parent 677457d commit eb50e0a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
10 changes: 9 additions & 1 deletion doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ Only one of `value` and `staticValue` can be used. `normalizer` is only used if
* gender: field: String: gender. Valid values are M, F and `null`
* ssn: field: String: social security number
* names (required): group: names configuration
* keyField (required): field: key field distinguishing each distinct name. Should be the type of the name.
* name: group: A horizontal/pivotted name configuration. If any of these exist, then the row based
configuration will not be used.
* type (required): field: name type
* given (required): field: given name
* middle: field: middle name or initial
* family: field: family name
* prefix: field: name prefix
* suffix: field: name suffix
* keyField: field: key field distinguishing each distinct name. Should be the type of the name.
* given (required): field: given name
* middle: field: middle name or initial
* family: field: family name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class NamesDatabaseViewSorConfiguration extends SorNamesConfiguration {
}
}

class NameDatabaseViewSorConfiguration extends SorNameConfiguration {
def keyField

def getType() {
super.@type ?: this.keyField
}
}

class RolesDatabaseViewSorConfiguration extends SorRolesConfiguration {
def keyField

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class DatabaseViewSorConfigurationFactoryBean implements FactoryBean<Map<String,
arg.delegate = c
arg.resolveStrategy = Closure.DELEGATE_ONLY
arg()
if (name == 'localAttribute') {
delegate.localAttributeConfigurations << c
if (name in ['localAttribute', 'name']) {
delegate."${name}Configurations" << c
} else {
delegate."${name}Configuration" = c
}
Expand Down Expand Up @@ -67,14 +67,19 @@ class DatabaseViewSorConfigurationFactoryBean implements FactoryBean<Map<String,
]
)

NamesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
NamesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(
[
'name': NameDatabaseViewSorConfiguration
]
)
EmailAddressesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
DisclosureSettingsConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
LocalAttributeDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
UrlsDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
AddressesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
LeavesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
PhonesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
NameDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)

FieldConfiguration.metaClass.methodMissing = { name, args ->
if (name in ['value', 'staticValue', 'normalizer']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,30 @@ class DatabaseViewSorPersonActionProcessor extends PersonActionProcessor impleme
def doneLeaves = [] as Set
def donePhones = [] as Set
item.rows.each { row ->
// do name
if (!doneNames.containsKey(getFieldValue(sorConfiguration.personConfiguration.namesConfiguration.keyField, row))) {
def type = getFieldValue(sorConfiguration.personConfiguration.namesConfiguration.type, row)
doneNames[getFieldValue(sorConfiguration.personConfiguration.namesConfiguration.keyField, row)] = item.sorPerson.addName(referenceRepository.findType(Type.DataTypes.NAME, type)).with { name ->
['given', 'middle', 'family', 'prefix', 'suffix'].each {
if (sorConfiguration.personConfiguration.namesConfiguration."${it}") {
name."${it}" = getFieldValue(sorConfiguration.personConfiguration.namesConfiguration."${it}", row)
// do names
def doName = {key, type, configuration ->
if (!doneNames.containsKey(key)) {
doneNames[key] = item.sorPerson.addName(referenceRepository.findType(Type.DataTypes.NAME, type)).with { name ->
['given', 'middle', 'family', 'prefix', 'suffix'].each {
if (configuration."${it}") {
name."${it}" = getFieldValue(configuration."${it}", row)
}
}
return name
}
return name
}
}
if (sorConfiguration.personConfiguration.namesConfiguration.nameConfigurations) {
// we are horizontal
sorConfiguration.personConfiguration.namesConfiguration.nameConfigurations.each { NameDatabaseViewSorConfiguration nameConfiguration ->
def type = getFieldValue(nameConfiguration.type, row)
doName type, type, nameConfiguration
}
} else {
def type = getFieldValue(sorConfiguration.personConfiguration.namesConfiguration.type, row)
def key = getFieldValue(sorConfiguration.personConfiguration.namesConfiguration.keyField, row)
doName key, type, sorConfiguration.personConfiguration.namesConfiguration
}

// do localAttributes
if (sorConfiguration.personConfiguration.localAttributeConfigurations) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/groovy/org/openregistry/loader/SorConfiguration.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ class SorNamesConfiguration {
def family
def prefix
def suffix

def nameConfigurations = [] as Set
}

class SorNameConfiguration{
def type
def given
def middle
def family
def prefix
def suffix
}

class SorRolesConfiguration {
Expand Down

0 comments on commit eb50e0a

Please sign in to comment.