Skip to content

Commit

Permalink
Merge pull request #1070 from AtlasOfLivingAustralia/feature/extended…
Browse files Browse the repository at this point in the history
…-data

#1047 individuals or groups
  • Loading branch information
chrisala authored Feb 16, 2025
2 parents e7c09fd + 2607af1 commit d5c9fa2
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 8 deletions.
26 changes: 23 additions & 3 deletions grails-app/services/au/org/ala/ecodata/ParatooService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,10 @@ class ParatooService {
cleanedDefinition << cleanSwaggerDefinition(value)
}
} else {
try {
cleanedDefinition = definition?.clone()
if (definition instanceof Cloneable) {
cleanedDefinition = definition.clone()
}
catch (CloneNotSupportedException e) {
else {
// if not cloneable, then it is a primitive type
cleanedDefinition = definition
}
Expand Down Expand Up @@ -1297,6 +1297,7 @@ class ParatooService {
}
}

addInsertions(template.dataModel, template.viewModel, "", config)
template
}

Expand Down Expand Up @@ -1521,6 +1522,7 @@ class ParatooService {
modelVisitStack.pop()
}

addInsertions(model.dataModel, model.viewModel, path, config)
model
}

Expand All @@ -1541,6 +1543,24 @@ class ParatooService {
}
}

void addInsertions(List dataModels, List viewModels, String path = "", ParatooProtocolConfig config) {
path = path ?: "<root>"
Map insertions = config.insertions
if (insertions?.dataModel?.containsKey(path)) {
List items = insertions?.dataModel[path] as List
if (items) {
dataModels.addAll(items)
}
}

if (insertions?.viewModel?.containsKey(path)) {
List items = insertions?.viewModel[path] as List
if (items) {
viewModels.addAll(items)
}
}
}

boolean isLocationObject(Map input) {
((input[PARATOO_COMPONENT] == PARATOO_LOCATION_COMPONENT) ||
input[PARATOO_COMPONENT]?.startsWith(PARATOO_LOCATION_COMPONENT_STARTS_WITH)) &&
Expand Down
7 changes: 3 additions & 4 deletions grails-app/services/au/org/ala/ecodata/RecordService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1384,8 +1384,8 @@ class RecordService {
}

Map getAttributeConfig(String dwcClass, String attribute) {
Map groups = grailsApplication.config.getProperty("darwinCore.termsGroupedByClass", Map)
groups[dwcClass].find { it.name == attribute }
List groups = grailsApplication.config.getProperty("darwinCore.termsGroupedByClass.$dwcClass", List<Map>)
groups.find { it.name == attribute }
}

Map darwinCoreTermsGroupedByClass() {
Expand Down Expand Up @@ -1535,8 +1535,7 @@ class RecordService {
*/
Map convertProjectActivityToEvent (pActivity, project) {
String dwcClass = DWC_EVENT
Map paDWC = grailsApplication.config.getProperty("darwinCore.projectActivityToDwC", Map)
List configs = paDWC[dwcClass]
List configs = grailsApplication.config.getProperty("darwinCore.projectActivityToDwC.${DWC_EVENT}", List<Map>)
Map<String, Map> result = [:].withDefault { [:] }
configs.each { config ->
transformToEventCoreTerm(config, pActivity, [project: project, pActivity: pActivity, recordService: this], result, dwcClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ trait RecordFieldConverter {
return value
}
catch (Exception ex) {
log.error(ex.message, ex)
log.error(ex.message)
data.remove('context')
return defaultValue == null ? expression : defaultValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ParatooProtocolConfig {
apiEndpoint ?: defaultEndpoint(surveyId)
}
Map overrides = [dataModel: [:], viewModel: [:]]
Map<String, Map<String,List>> insertions = [dataModel: new LinkedHashMap<String, List>(), viewModel: new LinkedHashMap<String, List>()]

ParatooCollectionId surveyId
TimeZone clientTimeZone
Expand Down
46 changes: 46 additions & 0 deletions src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,22 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
"usesPlotLayout": false,
"tags" : ["survey"],
"apiEndpoint" : "s1s",
"insertions": [
"dataModel": [
"<root>": [
[
"dataType": "text",
"name": "countTypeIndividual",
"dwcAttribute": "individualsOrGroups",
"dwcExpression": "'Individuals'",
"constraints": [
"Individuals",
"Groups"
]
]
]
]
],
"overrides" : [
"dataModel": null,
"viewModel": null
Expand All @@ -1375,6 +1391,16 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
"description" : "height",
"decimalPlaces": 0
]
result.dataModel[1] == [
"dataType": "text",
"name": "countTypeIndividual",
"dwcAttribute": "individualsOrGroups",
"dwcExpression": "'Individuals'",
"constraints": [
"Individuals",
"Groups"
]
]
result.viewModel[0] == [
"type" : "number",
"source" : "height",
Expand All @@ -1395,6 +1421,16 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
"description" : "height",
"decimalPlaces": 6
]
result.dataModel[1] == [
"dataType": "text",
"name": "countTypeIndividual",
"dwcAttribute": "individualsOrGroups",
"dwcExpression": "'Individuals'",
"constraints": [
"Individuals",
"Groups"
]
]
result.viewModel[0] == [
"type" : "number",
"source" : "height",
Expand Down Expand Up @@ -1454,6 +1490,16 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
],
"x-lut-ref":"lut1"
]
result.dataModel[1] == [
"dataType": "text",
"name": "countTypeIndividual",
"dwcAttribute": "individualsOrGroups",
"dwcExpression": "'Individuals'",
"constraints": [
"Individuals",
"Groups"
]
]
result.viewModel[0] == [
"type" : "selectOne",
"source" : "height",
Expand Down

0 comments on commit d5c9fa2

Please sign in to comment.