Skip to content

Commit 0ca8cc7

Browse files
authored
Merge pull request #485 from AtlasOfLivingAustralia/470-use-namematching-ws
#470 use namematching-ws for some bie services
2 parents ece1e88 + be51748 commit 0ca8cc7

File tree

4 files changed

+80
-77
lines changed

4 files changed

+80
-77
lines changed

grails-app/assets/javascripts/spApp/controller/createSpeciesListCtrl.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,9 @@
129129
};
130130

131131
$scope.addQ = function (query) {
132-
BieService.guidLookup([query.q[0].replace('lsid:', '')]).then(function (list) {
133-
for (var i in list) {
134-
if (list.hasOwnProperty(i)) {
135-
$scope.getCount(list[i]);
136-
137-
$scope.matchedItems.push(list[i])
138-
}
139-
}
132+
BieService.guidLookup(query.q[0].replace('lsid:', '')).then(function (result) {
133+
$scope.getCount(result);
134+
$scope.matchedItems.push(result);
140135
});
141136
speciesAutoComplete.value = ''
142137
};

grails-app/assets/javascripts/spApp/service/bieService.js

+73-69
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
* @memberof spApp
55
* @ngdoc service
66
* @name BieService
7-
* @param {service} $http angular html service
87
* @description
9-
* Methods to interact with ALA BIE
8+
* Methods to interact with ALA BIE and Name Matching services
109
*/
1110
angular.module('bie-service', [])
12-
.factory("BieService", ["$http", function ($http) {
11+
.factory("BieService", ["$http", "$q", function ($http, $q) {
1312
var _httpDescription = function (method, httpconfig) {
1413
if (httpconfig === undefined) {
1514
httpconfig = {};
@@ -54,6 +53,10 @@
5453

5554
/**
5655
* Bulk LSID lookup using taxon names
56+
*
57+
* Uses name matching service's /api/getGuidsForTaxa and /api/getAllByTaxonID because
58+
* /api/searchAllByClassification failed to return results for some names.
59+
*
5760
* @memberof BieService
5861
* @param {List} names List of taxon names to search
5962
* @returns {Promise(List)} search results that will contain LSID if found
@@ -62,93 +65,94 @@
6265
* Input:
6366
* ["Macropus"]
6467
*
65-
* Output:
68+
* Output (may contain additional fields):
6669
* [{
6770
* "identifier": "urn:lsid:biodiversity.org.au:afd.taxon:b1d9bf29-648f-47e6-8544-2c2fbdf632b1",
68-
* "guid": "urn:lsid:biodiversity.org.au:afd.taxon:b1d9bf29-648f-47e6-8544-2c2fbdf632b1",
69-
* "parentGuid": "urn:lsid:biodiversity.org.au:afd.taxon:3281c966-5119-4146-89e5-3c874754f23a",
70-
* "name": "Macropus",
71-
* "nameComplete": "Macropus Shaw, 1790",
72-
* "commonName": null,
73-
* "commonNameSingle": null,
74-
* "rank": "genus",
75-
* "rankId": 6000,
71+
* "searchTerm": "Macropus",
7672
* "acceptedConceptGuid": "urn:lsid:biodiversity.org.au:afd.taxon:b1d9bf29-648f-47e6-8544-2c2fbdf632b1",
77-
* "acceptedConceptName": "Macropus",
78-
* "taxonomicStatus": "accepted",
79-
* "imageId": "274ed24e-481e-4532-bead-66fa479fb272",
80-
* "imageUrl": "https://images.ala.org.au/image/proxyImage?imageId=274ed24e-481e-4532-bead-66fa479fb272",
81-
* "thumbnailUrl": "https://images.ala.org.au/image/proxyImageThumbnail?imageId=274ed24e-481e-4532-bead-66fa479fb272",
82-
* "largeImageUrl": "https://images.ala.org.au/image/proxyImageThumbnailLarge?imageId=274ed24e-481e-4532-bead-66fa479fb272",
83-
* "smallImageUrl": "https://images.ala.org.au/image/proxyImageThumbnailLarge?imageId=274ed24e-481e-4532-bead-66fa479fb272",
84-
* "imageMetadataUrl": "https://images.ala.org.au/ws/image/274ed24e-481e-4532-bead-66fa479fb272",
73+
* "name": "Macropus",
8574
* "kingdom": "ANIMALIA",
86-
* "phylum": "CHORDATA",
87-
* "classs": "MAMMALIA",
88-
* "order": "DIPROTODONTIA",
89-
* "family": "MACROPODIDAE",
90-
* "genus": null,
91-
* "author": "Shaw, 1790",
92-
* "linkIdentifier": null,
93-
* "searchTerm": "Macropus"
75+
* "family": "MACROPODIDAE"
9476
* }]
9577
*/
9678
nameLookup: function (names) {
97-
return $http.post($SH.bieServiceUrl + "/species/lookup/bulk", {
98-
names: names,
99-
vernacular: true
100-
}, _httpDescription('nameLookup')).then(function (response) {
79+
return $http.post($SH.namematchingUrl + "/api/getGuidsForTaxa", names,
80+
_httpDescription('nameLookup2')).then(function (response) {
81+
10182
var list = response.data;
102-
for (var i in list) {
103-
if (list.hasOwnProperty(i)) {
104-
list[i].searchTerm = names[i]
105-
}
83+
84+
// URL encode list
85+
var encodedIds = list.map(function (item) {
86+
return encodeURIComponent(item, "UTF-8");
87+
})
88+
89+
// do batching because the URL gets too long
90+
var batchSize = 1;
91+
var promises = [];
92+
93+
for (let i = 0; i < encodedIds.length; i += batchSize) {
94+
var batch = encodedIds.slice(i, i + batchSize);
95+
var taxonParam = "&taxonIDs=" + batch.join("&taxonIDs=");
96+
var promise = $http.post($SH.namematchingUrl + "/api/getAllByTaxonID?follow=true" + taxonParam, {}, _httpDescription('nameLookup2'))
97+
.then(function (response2) {
98+
var list2 = response2.data;
99+
100+
for (var j in list2) {
101+
if (list2.hasOwnProperty(j)) {
102+
list2[j].name = list2[j].scientificName;
103+
list2[j].searchTerm = names[i + Number(j)];
104+
list2[j].acceptedConceptGuid = list[i + Number(j)];
105+
list2[j].identifier = list[i + Number(j)];
106+
}
107+
}
108+
return list2;
109+
});
110+
promises.push(promise);
106111
}
107-
return list
112+
113+
return $q.all(promises).then(function (results) {
114+
return [].concat.apply([], results); // Flatten the array of results
115+
});
108116
});
117+
109118
},
110119

111120
/**
112-
* Bulk taxon information lookup using LSIDs
121+
* Single taxon information lookup using LSIDs. Uses name matching service.
122+
*
113123
* @memberof BieService
114-
* @param {List} lsids List of LSIDs to search
115-
* @returns {Promise(List)} search results that will contain taxon information if found
124+
* @param {String} LSID to search
125+
* @returns {Promise} search results that will contain taxon information if found
116126
*
117127
* @example
118128
* Input:
119129
* ["http://id.biodiversity.org.au/instance/apni/852793"]
120130
*
121-
* Ouput:
122-
* [{
123-
* "guid": "http://id.biodiversity.org.au/instance/apni/852793",
124-
* "name": "Eucalyptus subcaerulea",
125-
* "scientificName": "Eucalyptus subcaerulea",
126-
* "author": "K.D.Hill",
127-
* "nameComplete": "Eucalyptus subcaerulea K.D.Hill",
128-
* "rank": "species",
129-
* "kingdom": null,
130-
* "phylum": null,
131-
* "classs": null,
132-
* "order": null,
133-
* "family": null,
134-
* "genus": null,
135-
* "datasetName": "APC",
136-
* "datasetID": "dr5214",
137-
* "acceptedConceptGuid": "http://id.biodiversity.org.au/instance/apni/852793",
138-
* "searchTerm": "http://id.biodiversity.org.au/instance/apni/852793"
139-
* }]
131+
* Output (may contain additional fields):
132+
* {
133+
* "identifier": "urn:lsid:biodiversity.org.au:afd.taxon:b1d9bf29-648f-47e6-8544-2c2fbdf632b1",
134+
* "searchTerm": "urn:lsid:biodiversity.org.au:afd.taxon:b1d9bf29-648f-47e6-8544-2c2fbdf632b1",
135+
* "acceptedConceptGuid": "urn:lsid:biodiversity.org.au:afd.taxon:b1d9bf29-648f-47e6-8544-2c2fbdf632b1",
136+
* "name": "Macropus",
137+
* "kingdom": "ANIMALIA",
138+
* "family": "MACROPODIDAE"
139+
* }
140140
*/
141-
guidLookup: function (guids) {
142-
return $http.post($SH.bieServiceUrl + "/species/guids/bulklookup", guids, _httpDescription('guidLookup')).then(function (response) {
143-
var list = response.data.searchDTOList;
144-
for (var i in list) {
145-
if (list.hasOwnProperty(i)) {
146-
list[i].searchTerm = guids[i];
147-
list[i].acceptedConceptGuid = list[i].guid
141+
guidLookup: function (lsid) {
142+
return $http.post($SH.namematchingUrl + "/api/getAllByTaxonID?follow=true&taxonIDs=" + encodeURIComponent(lsid), {}, _httpDescription('nameLookup2'))
143+
.then(function (response2) {
144+
var list2 = response2.data;
145+
146+
for (var j in list2) {
147+
if (list2.hasOwnProperty(j)) {
148+
list2[j].name = list2[j].scientificName;
149+
list2[j].searchTerm = lsid;
150+
list2[j].acceptedConceptGuid = list2[j].taxonConceptID;
151+
list2[j].identifier = list2[j].taxonConceptID;
152+
}
148153
}
149-
}
150-
return list
151-
});
154+
return list2[[0]];
155+
});
152156
}
153157
};
154158
}])

grails-app/conf/application.yml

+3
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ bie:
192192
bieService:
193193
baseURL: 'https://bie.ala.org.au/ws'
194194

195+
namematching:
196+
baseURL: 'https://namematching-ws.ala.org.au'
197+
195198
favicon:
196199
url: 'https://www.ala.org.au/wp-content/themes/ala2011/images/favicon.ico'
197200

grails-app/views/portal/index.gsp

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
custom_facets: ${(custom_facets as grails.converters.JSON).toString().encodeAsRaw()},
3838
bieUrl: '${config.bie.baseURL}',
3939
bieServiceUrl: '${config.bieService.baseURL}',
40+
namematchingUrl: '${config.namematching.baseURL}',
4041
layersServiceUrl: '${config.layersService.url}',
4142
samplingUrl: '${config.sampling.url}',
4243
listsUrl: '${config.lists.url}',

0 commit comments

Comments
 (0)