Skip to content

Commit eb50e0a

Browse files
committed
[#4]
allow horizontal/column/pivotted name configuration
1 parent 677457d commit eb50e0a

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

doc/configuration.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ Only one of `value` and `staticValue` can be used. `normalizer` is only used if
4747
* gender: field: String: gender. Valid values are M, F and `null`
4848
* ssn: field: String: social security number
4949
* names (required): group: names configuration
50-
* keyField (required): field: key field distinguishing each distinct name. Should be the type of the name.
50+
* name: group: A horizontal/pivotted name configuration. If any of these exist, then the row based
51+
configuration will not be used.
52+
* type (required): field: name type
53+
* given (required): field: given name
54+
* middle: field: middle name or initial
55+
* family: field: family name
56+
* prefix: field: name prefix
57+
* suffix: field: name suffix
58+
* keyField: field: key field distinguishing each distinct name. Should be the type of the name.
5159
* given (required): field: given name
5260
* middle: field: middle name or initial
5361
* family: field: family name

src/main/groovy/org/openregistry/loader/DatabaseViewSorConfiguration.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class NamesDatabaseViewSorConfiguration extends SorNamesConfiguration {
2222
}
2323
}
2424

25+
class NameDatabaseViewSorConfiguration extends SorNameConfiguration {
26+
def keyField
27+
28+
def getType() {
29+
super.@type ?: this.keyField
30+
}
31+
}
32+
2533
class RolesDatabaseViewSorConfiguration extends SorRolesConfiguration {
2634
def keyField
2735

src/main/groovy/org/openregistry/loader/DatabaseViewSorConfigurationFactoryBean.groovy

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class DatabaseViewSorConfigurationFactoryBean implements FactoryBean<Map<String,
3737
arg.delegate = c
3838
arg.resolveStrategy = Closure.DELEGATE_ONLY
3939
arg()
40-
if (name == 'localAttribute') {
41-
delegate.localAttributeConfigurations << c
40+
if (name in ['localAttribute', 'name']) {
41+
delegate."${name}Configurations" << c
4242
} else {
4343
delegate."${name}Configuration" = c
4444
}
@@ -67,14 +67,19 @@ class DatabaseViewSorConfigurationFactoryBean implements FactoryBean<Map<String,
6767
]
6868
)
6969

70-
NamesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
70+
NamesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(
71+
[
72+
'name': NameDatabaseViewSorConfiguration
73+
]
74+
)
7175
EmailAddressesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
7276
DisclosureSettingsConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
7377
LocalAttributeDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
7478
UrlsDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
7579
AddressesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
7680
LeavesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
7781
PhonesDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
82+
NameDatabaseViewSorConfiguration.metaClass.methodMissing = notSoSimpleMethodMissing(null)
7883

7984
FieldConfiguration.metaClass.methodMissing = { name, args ->
8085
if (name in ['value', 'staticValue', 'normalizer']) {

src/main/groovy/org/openregistry/loader/DatabaseViewSorPersonActionProcessor.groovy

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,30 @@ class DatabaseViewSorPersonActionProcessor extends PersonActionProcessor impleme
7070
def doneLeaves = [] as Set
7171
def donePhones = [] as Set
7272
item.rows.each { row ->
73-
// do name
74-
if (!doneNames.containsKey(getFieldValue(sorConfiguration.personConfiguration.namesConfiguration.keyField, row))) {
75-
def type = getFieldValue(sorConfiguration.personConfiguration.namesConfiguration.type, row)
76-
doneNames[getFieldValue(sorConfiguration.personConfiguration.namesConfiguration.keyField, row)] = item.sorPerson.addName(referenceRepository.findType(Type.DataTypes.NAME, type)).with { name ->
77-
['given', 'middle', 'family', 'prefix', 'suffix'].each {
78-
if (sorConfiguration.personConfiguration.namesConfiguration."${it}") {
79-
name."${it}" = getFieldValue(sorConfiguration.personConfiguration.namesConfiguration."${it}", row)
73+
// do names
74+
def doName = {key, type, configuration ->
75+
if (!doneNames.containsKey(key)) {
76+
doneNames[key] = item.sorPerson.addName(referenceRepository.findType(Type.DataTypes.NAME, type)).with { name ->
77+
['given', 'middle', 'family', 'prefix', 'suffix'].each {
78+
if (configuration."${it}") {
79+
name."${it}" = getFieldValue(configuration."${it}", row)
80+
}
8081
}
82+
return name
8183
}
82-
return name
8384
}
8485
}
86+
if (sorConfiguration.personConfiguration.namesConfiguration.nameConfigurations) {
87+
// we are horizontal
88+
sorConfiguration.personConfiguration.namesConfiguration.nameConfigurations.each { NameDatabaseViewSorConfiguration nameConfiguration ->
89+
def type = getFieldValue(nameConfiguration.type, row)
90+
doName type, type, nameConfiguration
91+
}
92+
} else {
93+
def type = getFieldValue(sorConfiguration.personConfiguration.namesConfiguration.type, row)
94+
def key = getFieldValue(sorConfiguration.personConfiguration.namesConfiguration.keyField, row)
95+
doName key, type, sorConfiguration.personConfiguration.namesConfiguration
96+
}
8597

8698
// do localAttributes
8799
if (sorConfiguration.personConfiguration.localAttributeConfigurations) {

src/main/groovy/org/openregistry/loader/SorConfiguration.groovy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ class SorNamesConfiguration {
2525
def family
2626
def prefix
2727
def suffix
28+
29+
def nameConfigurations = [] as Set
30+
}
31+
32+
class SorNameConfiguration{
33+
def type
34+
def given
35+
def middle
36+
def family
37+
def prefix
38+
def suffix
2839
}
2940

3041
class SorRolesConfiguration {

0 commit comments

Comments
 (0)