Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- adds vernacular name search
  • Loading branch information
temi committed May 19, 2024
1 parent f803982 commit 62ad615
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 4 deletions.
1 change: 1 addition & 0 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]

}

}

0 comments on commit 62ad615

Please sign in to comment.