Skip to content

Commit

Permalink
Merge pull request #955 from AtlasOfLivingAustralia/feature/issues951
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala authored May 20, 2024
2 parents 1984f24 + 2c69988 commit 051b805
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 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 @@ -2085,7 +2085,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
})
}
}
8 changes: 5 additions & 3 deletions src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,8 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
then:
outputSpeciesId != null
result == [name: "Acacia glauca Willd. (Acacia glauca)", scientificName: "Acacia glauca Willd.", guid: "A_GUID", commonName: "Acacia glauca", taxonRank: "Species"]
2 * speciesReMatchService.searchByName(_) >> null
1 * speciesReMatchService.searchByName(_) >> null
1 * speciesReMatchService.searchByName(_, false, true) >> null

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

void "buildTreeFromParentChildRelationships should build tree correctly"() {
Expand Down Expand Up @@ -1431,7 +1433,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
result.lut.remove('outputSpeciesId')
then:
1 * speciesReMatchService.searchByName("Felis catus") >> null
1 * speciesReMatchService.searchByName("Cats") >> [
1 * speciesReMatchService.searchByName("Cats", false, true) >> [
commonName: "Cat",
scientificName: "Felis catus",
guid: "TAXON_ID",
Expand Down
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({it.contains("search?q=")}) >> resp
when:
def result = service.searchByName("name")

then:
result == null

when:
resp.matchType = "exactMatch"
def result2 = service.searchByName("name")

then:
service.webService.getJson({it.contains("search?q=")}) >> 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({it.contains("searchByVernacularName")}) >> resp
result3 == [
scientificName: "Red",
commonName: null,
guid: "ALA_DR22913_1168_0",
taxonRank: "genus"
]

}

}

0 comments on commit 051b805

Please sign in to comment.