Skip to content

Commit 051b805

Browse files
authored
Merge pull request #955 from AtlasOfLivingAustralia/feature/issues951
#951
2 parents 1984f24 + 2c69988 commit 051b805

File tree

5 files changed

+94
-7
lines changed

5 files changed

+94
-7
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
@@ -2085,7 +2085,7 @@ class ParatooService {
20852085
}
20862086
// try again with common name
20872087
if ((result.guid == null) && commonName) {
2088-
resp = speciesReMatchService.searchByName(commonName)
2088+
resp = speciesReMatchService.searchByName(commonName, false, true)
20892089
if (resp) {
20902090
result.putAll(resp)
20912091
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/ParatooServiceSpec.groovy

+5-3
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
713713
then:
714714
outputSpeciesId != null
715715
result == [name: "Acacia glauca Willd. (Acacia glauca)", scientificName: "Acacia glauca Willd.", guid: "A_GUID", commonName: "Acacia glauca", taxonRank: "Species"]
716-
2 * speciesReMatchService.searchByName(_) >> null
716+
1 * speciesReMatchService.searchByName(_) >> null
717+
1 * speciesReMatchService.searchByName(_, false, true) >> null
717718

718719
when: // no scientific name
719720
result = service.transformSpeciesName("Frogs [Class] (scientific: )")
@@ -722,7 +723,8 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
722723
then:
723724
outputSpeciesId != null
724725
result == [name: "Frogs", scientificName: "", guid: "A_GUID", commonName: "Frogs", taxonRank: "Class"]
725-
2 * speciesReMatchService.searchByName(_) >> null
726+
1 * speciesReMatchService.searchByName(_) >> null
727+
1 * speciesReMatchService.searchByName(_, false, true) >> null
726728
}
727729

728730
void "buildTreeFromParentChildRelationships should build tree correctly"() {
@@ -1431,7 +1433,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
14311433
result.lut.remove('outputSpeciesId')
14321434
then:
14331435
1 * speciesReMatchService.searchByName("Felis catus") >> null
1434-
1 * speciesReMatchService.searchByName("Cats") >> [
1436+
1 * speciesReMatchService.searchByName("Cats", false, true) >> [
14351437
commonName: "Cat",
14361438
scientificName: "Felis catus",
14371439
guid: "TAXON_ID",

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({it.contains("search?q=")}) >> 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({it.contains("search?q=")}) >> 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({it.contains("searchByVernacularName")}) >> 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)