Skip to content

Commit 62ad615

Browse files
committed
- adds vernacular name search
1 parent f803982 commit 62ad615

File tree

4 files changed

+89
-4
lines changed

4 files changed

+89
-4
lines changed

grails-app/conf/application.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ if (!ala.baseURL) {
504504
bie.ws.url = "https://bie-ws.ala.org.au/"
505505
bie.url = "https://bie.ala.org.au/"
506506
namesmatching.url = "https://namematching-ws-test.ala.org.au/"
507+
namematching.strategy = ["exactMatch", "vernacularMatch"]
507508

508509
if (!collectory.baseURL) {
509510
//collectory.baseURL = "https://collectory-dev.ala.org.au/"

grails-app/services/au/org/ala/ecodata/ParatooService.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,7 @@ class ParatooService {
20842084
}
20852085
// try again with common name
20862086
if ((result.guid == null) && commonName) {
2087-
resp = speciesReMatchService.searchByName(commonName)
2087+
resp = speciesReMatchService.searchByName(commonName, false, true)
20882088
if (resp) {
20892089
result.putAll(resp)
20902090
result.commonName = commonName

grails-app/services/au/org/ala/ecodata/SpeciesReMatchService.groovy

+22-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,14 @@ class SpeciesReMatchService {
9191
})
9292
}
9393

94-
Map searchByName (String name, boolean addDetails = false) {
95-
Map result = searchNameMatchingServer(name)
96-
if (result) {
94+
Map searchByName (String name, boolean addDetails = false, boolean useVernacularSearch = false ) {
95+
Map result
96+
if (useVernacularSearch)
97+
result = searchNameMatchingServer(name)
98+
else
99+
result = searchByVernacularNameOnNameMatchingServer(name)
100+
List strategy = grailsApplication.config.getProperty('namematching.strategy', List)
101+
if (strategy.contains(result?.matchType)) {
97102
Map resp = [
98103
scientificName: result.scientificName,
99104
commonName: result.vernacularName,
@@ -122,4 +127,18 @@ class SpeciesReMatchService {
122127
resp
123128
})
124129
}
130+
131+
Map searchByVernacularNameOnNameMatchingServer (String name) {
132+
name = name?.toLowerCase() ?: ""
133+
cacheService.get('name-matching-server-vernacular-name' + name, {
134+
def encodedQuery = URLEncoder.encode(name ?: '', "UTF-8")
135+
def url = "${grailsApplication.config.getProperty('namesmatching.url')}api/searchByVernacularName?vernacularName=${encodedQuery}"
136+
def resp = webService.getJson(url)
137+
if (!resp.success) {
138+
return null
139+
}
140+
141+
resp
142+
})
143+
}
125144
}

src/test/groovy/au/org/ala/ecodata/SpeciesReMatchServiceSpec.groovy

+65
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,69 @@ class SpeciesReMatchServiceSpec extends Specification implements ServiceUnitTest
6767
result2 == resp2
6868
}
6969

70+
void "search name server by name" () {
71+
setup:
72+
grailsApplication.config.namesmatching.url = "http://localhost:8080/"
73+
grailsApplication.config.namesmatching.strategy = ["exactMatch", "vernacularMatch"]
74+
def resp = [
75+
"success": true,
76+
"scientificName": "Red",
77+
"taxonConceptID": "ALA_DR22913_1168_0",
78+
"rank": "genus",
79+
"rankID": 6000,
80+
"lft": 24693,
81+
"rgt": 24693,
82+
"matchType": "higherMatch",
83+
"nameType": "SCIENTIFIC",
84+
"kingdom": "Bamfordvirae",
85+
"kingdomID": "https://www.catalogueoflife.org/data/taxon/8TRHY",
86+
"phylum": "Nucleocytoviricota",
87+
"phylumID": "https://www.catalogueoflife.org/data/taxon/5G",
88+
"classs": "Megaviricetes",
89+
"classID": "https://www.catalogueoflife.org/data/taxon/6224M",
90+
"order": "Pimascovirales",
91+
"orderID": "https://www.catalogueoflife.org/data/taxon/623FC",
92+
"family": "Iridoviridae",
93+
"familyID": "https://www.catalogueoflife.org/data/taxon/BFM",
94+
"genus": "Red",
95+
"genusID": "ALA_DR22913_1168_0",
96+
"issues": [
97+
"noIssue"
98+
]
99+
]
100+
service.webService.getJson(_) >> resp
101+
when:
102+
def result = service.searchByName("name")
103+
104+
then:
105+
result == null
106+
107+
when:
108+
resp.matchType = "exactMatch"
109+
def result2 = service.searchByName("name")
110+
111+
then:
112+
service.webService.getJson(_) >> resp
113+
result2 == [
114+
scientificName: "Red",
115+
commonName: null,
116+
guid: "ALA_DR22913_1168_0",
117+
taxonRank: "genus"
118+
]
119+
120+
when:
121+
resp.matchType = "vernacularMatch"
122+
def result3 = service.searchByName("name", false, true)
123+
124+
then:
125+
service.webService.getJson(_) >> resp
126+
result3 == [
127+
scientificName: "Red",
128+
commonName: null,
129+
guid: "ALA_DR22913_1168_0",
130+
taxonRank: "genus"
131+
]
132+
133+
}
134+
70135
}

0 commit comments

Comments
 (0)