diff --git a/grails-app/conf/application.groovy b/grails-app/conf/application.groovy index d610a3105..da139f946 100644 --- a/grails-app/conf/application.groovy +++ b/grails-app/conf/application.groovy @@ -504,6 +504,7 @@ if (!ala.baseURL) { bie.ws.url = "https://bie-ws.ala.org.au/" bie.url = "https://bie.ala.org.au/" namesmatching.url = "https://namematching-ws-test.ala.org.au/" +namematching.strategy = ["exactMatch", "vernacularMatch"] if (!collectory.baseURL) { //collectory.baseURL = "https://collectory-dev.ala.org.au/" diff --git a/grails-app/services/au/org/ala/ecodata/ParatooService.groovy b/grails-app/services/au/org/ala/ecodata/ParatooService.groovy index d35a2a46e..577fb5df5 100644 --- a/grails-app/services/au/org/ala/ecodata/ParatooService.groovy +++ b/grails-app/services/au/org/ala/ecodata/ParatooService.groovy @@ -2084,7 +2084,7 @@ class ParatooService { } // try again with common name if ((result.guid == null) && commonName) { - resp = speciesReMatchService.searchByName(commonName) + resp = speciesReMatchService.searchByName(commonName, false, true) if (resp) { result.putAll(resp) result.commonName = commonName diff --git a/grails-app/services/au/org/ala/ecodata/SpeciesReMatchService.groovy b/grails-app/services/au/org/ala/ecodata/SpeciesReMatchService.groovy index a88af4a85..b7fb38aad 100644 --- a/grails-app/services/au/org/ala/ecodata/SpeciesReMatchService.groovy +++ b/grails-app/services/au/org/ala/ecodata/SpeciesReMatchService.groovy @@ -91,9 +91,14 @@ class SpeciesReMatchService { }) } - Map searchByName (String name, boolean addDetails = false) { - Map result = searchNameMatchingServer(name) - if (result) { + Map searchByName (String name, boolean addDetails = false, boolean useVernacularSearch = false ) { + Map result + if (useVernacularSearch) + result = searchNameMatchingServer(name) + else + result = searchByVernacularNameOnNameMatchingServer(name) + List strategy = grailsApplication.config.getProperty('namematching.strategy', List) + if (strategy.contains(result?.matchType)) { Map resp = [ scientificName: result.scientificName, commonName: result.vernacularName, @@ -122,4 +127,18 @@ class SpeciesReMatchService { resp }) } + + Map searchByVernacularNameOnNameMatchingServer (String name) { + name = name?.toLowerCase() ?: "" + cacheService.get('name-matching-server-vernacular-name' + name, { + def encodedQuery = URLEncoder.encode(name ?: '', "UTF-8") + def url = "${grailsApplication.config.getProperty('namesmatching.url')}api/searchByVernacularName?vernacularName=${encodedQuery}" + def resp = webService.getJson(url) + if (!resp.success) { + return null + } + + resp + }) + } } diff --git a/src/test/groovy/au/org/ala/ecodata/SpeciesReMatchServiceSpec.groovy b/src/test/groovy/au/org/ala/ecodata/SpeciesReMatchServiceSpec.groovy index c848689b5..09dbddcde 100644 --- a/src/test/groovy/au/org/ala/ecodata/SpeciesReMatchServiceSpec.groovy +++ b/src/test/groovy/au/org/ala/ecodata/SpeciesReMatchServiceSpec.groovy @@ -67,4 +67,69 @@ class SpeciesReMatchServiceSpec extends Specification implements ServiceUnitTest result2 == resp2 } + void "search name server by name" () { + setup: + grailsApplication.config.namesmatching.url = "http://localhost:8080/" + grailsApplication.config.namesmatching.strategy = ["exactMatch", "vernacularMatch"] + def resp = [ + "success": true, + "scientificName": "Red", + "taxonConceptID": "ALA_DR22913_1168_0", + "rank": "genus", + "rankID": 6000, + "lft": 24693, + "rgt": 24693, + "matchType": "higherMatch", + "nameType": "SCIENTIFIC", + "kingdom": "Bamfordvirae", + "kingdomID": "https://www.catalogueoflife.org/data/taxon/8TRHY", + "phylum": "Nucleocytoviricota", + "phylumID": "https://www.catalogueoflife.org/data/taxon/5G", + "classs": "Megaviricetes", + "classID": "https://www.catalogueoflife.org/data/taxon/6224M", + "order": "Pimascovirales", + "orderID": "https://www.catalogueoflife.org/data/taxon/623FC", + "family": "Iridoviridae", + "familyID": "https://www.catalogueoflife.org/data/taxon/BFM", + "genus": "Red", + "genusID": "ALA_DR22913_1168_0", + "issues": [ + "noIssue" + ] + ] + service.webService.getJson(_) >> resp + when: + def result = service.searchByName("name") + + then: + result == null + + when: + resp.matchType = "exactMatch" + def result2 = service.searchByName("name") + + then: + service.webService.getJson(_) >> resp + result2 == [ + scientificName: "Red", + commonName: null, + guid: "ALA_DR22913_1168_0", + taxonRank: "genus" + ] + + when: + resp.matchType = "vernacularMatch" + def result3 = service.searchByName("name", false, true) + + then: + service.webService.getJson(_) >> resp + result3 == [ + scientificName: "Red", + commonName: null, + guid: "ALA_DR22913_1168_0", + taxonRank: "genus" + ] + + } + }