From 7354fe6a1feae079a79f2f657362dcb722672b5d Mon Sep 17 00:00:00 2001 From: temi Date: Fri, 10 Jan 2025 07:06:17 +1100 Subject: [PATCH] #1053 - support species manual entry --- .../au/org/ala/ecodata/ParatooService.groovy | 21 ++++++++++++------- .../org/ala/ecodata/ParatooServiceSpec.groovy | 17 ++++++++++++++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/grails-app/services/au/org/ala/ecodata/ParatooService.groovy b/grails-app/services/au/org/ala/ecodata/ParatooService.groovy index febfb3aff..4dceb8afa 100644 --- a/grails-app/services/au/org/ala/ecodata/ParatooService.groovy +++ b/grails-app/services/au/org/ala/ecodata/ParatooService.groovy @@ -2097,7 +2097,7 @@ class ParatooService { } String regex = "([^\\[\\(]*)(?:\\[(.*)\\])?\\s*(?:\\(scientific:\\s*(.*?)\\))?" - String commonName, scientificName = name + String commonName, scientificName, taxonRank Pattern pattern = Pattern.compile(regex) Matcher matcher = pattern.matcher(name) Map result = [scientificName: name, commonName: name, outputSpeciesId: UUID.randomUUID().toString()] @@ -2105,17 +2105,18 @@ class ParatooService { if (matcher.find()) { commonName = matcher.group(1)?.trim() scientificName = matcher.group(3)?.trim() - result.taxonRank = matcher.group(2)?.trim() - result.scientificName = scientificName - result.commonName = commonName + taxonRank = matcher.group(2)?.trim() + result.taxonRank = taxonRank + result.scientificName = scientificName == null ? result.scientificName : scientificName + result.commonName = commonName == null ? result.commonName : commonName } - Map resp = speciesReMatchService.searchByName(scientificName) + Map resp = speciesReMatchService.searchByName(result.scientificName) if (resp) { result.putAll(resp) } // try again with common name - if ((result.guid == null) && commonName) { + if ((result.guid == null) && result.commonName) { resp = speciesReMatchService.searchByName(commonName, false, true) if (resp) { result.putAll(resp) @@ -2123,7 +2124,13 @@ class ParatooService { } } - result.name = result.commonName ? result.scientificName ? "${result.scientificName} (${result.commonName})" : result.commonName : result.scientificName + if (result.commonName != result.scientificName) { + result.name = result.commonName ? result.scientificName ? "${result.scientificName} (${result.commonName})" : result.commonName : result.scientificName + } + else { + result.name = result.scientificName ?: result.commonName + } + List specialCases = grailsApplication.config.getProperty("paratoo.species.specialCases", List) // do not create record for special cases if (specialCases.contains(name)) { diff --git a/src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy b/src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy index eecefa9dc..1b4cb2cfc 100644 --- a/src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy +++ b/src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy @@ -800,13 +800,28 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest> null 1 * speciesReMatchService.searchByName(_, false, true) >> null + when: // user inputs scientific name to field + result = service.transformSpeciesName("Centipeda cunninghamii") + outputSpeciesId = result.remove("outputSpeciesId") + + then: + outputSpeciesId != null + result == [name: "Centipeda cunninghamii (Common Sneezeweed)", scientificName: "Centipeda cunninghamii", guid: "https://id.biodiversity.org.au/node/apni/2916674", commonName: "Common Sneezeweed", taxonRank: "species"] + 1 * speciesReMatchService.searchByName(_) >> [ + scientificName: "Centipeda cunninghamii", + commonName: "Common Sneezeweed", + guid: "https://id.biodiversity.org.au/node/apni/2916674", + taxonRank: "species" + ] + 0 * speciesReMatchService.searchByName(_, false, true) + when: // Do not create record when value equals special cases. Therefore, removes guid. result = service.transformSpeciesName("Other") outputSpeciesId = result.remove("outputSpeciesId") then: outputSpeciesId != null - result == [name: "Other", scientificName: null, commonName: "Other", taxonRank: null] + result == [name: "Other", scientificName: "Other", commonName: "Other", taxonRank: null] 1 * speciesReMatchService.searchByName(_) >> null 1 * speciesReMatchService.searchByName(_, false, true) >> null