Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- fixes species extraction from lut fields
  • Loading branch information
temi committed Apr 26, 2024
1 parent d0eca17 commit 12a1665
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
7 changes: 6 additions & 1 deletion grails-app/services/au/org/ala/ecodata/ParatooService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,12 @@ class ParatooService {
case "species":
String speciesName
try {
speciesName = getProperty(output, model.name)?.first()
if(model.containsKey(PARATOO_LUT_REF)) {
speciesName = getProperty(output, model.name)?.label?.first()
} else {
speciesName = getProperty(output, model.name)?.first()
}

output[model.name] = transformSpeciesName(speciesName)
} catch (Exception e) {
log.info("Error getting species name for ${model.name}: ${e.message}")
Expand Down
61 changes: 61 additions & 0 deletions src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,67 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
result == definition.output
}

def "recursivelyTransformData should transform species data"() {

def dataModel = [
[
"dataType" : "species",
"name" : "lut",
"x-lut-ref" : "lut1",
]
]
def output = [
lut: [
"id": 8,
"symbol": "Cat",
"label": "Cat",
"description": "",
"uri": "",
"createdAt": "2024-03-26T02:39:32.116Z",
"updatedAt": "2024-03-26T02:39:32.116Z"
]
]
String formName = "form name"

when:
def result = service.recursivelyTransformData(dataModel, output, formName, 1, null)
result.lut.remove('outputSpeciesId')

then:
result == [
lut: [
commonName: "Cat",
name: "Cat",
taxonRank: null,
scientificName: "Cat",
guid: "A_GUID"
]
]

when:
dataModel = [
[
"dataType" : "species",
"name" : "lut"
]
]
output = [
lut: "Cat"
]
result = service.recursivelyTransformData(dataModel, output, formName, 1, null)
result.lut.remove('outputSpeciesId')
then:
result == [
lut: [
commonName: "Cat",
name: "Cat",
taxonRank: null,
scientificName: "Cat",
guid: "A_GUID"
]
]
}

def "recursivelyTransformData should transform feature object based on provided protocol config"() {
given:
def dataModel = [
Expand Down

0 comments on commit 12a1665

Please sign in to comment.