|
4 | 4 | * @memberof spApp
|
5 | 5 | * @ngdoc service
|
6 | 6 | * @name BieService
|
7 |
| - * @param {service} $http angular html service |
8 | 7 | * @description
|
9 |
| - * Methods to interact with ALA BIE |
| 8 | + * Methods to interact with ALA BIE and Name Matching services |
10 | 9 | */
|
11 | 10 | angular.module('bie-service', [])
|
12 |
| - .factory("BieService", ["$http", function ($http) { |
| 11 | + .factory("BieService", ["$http", "$q", function ($http, $q) { |
13 | 12 | var _httpDescription = function (method, httpconfig) {
|
14 | 13 | if (httpconfig === undefined) {
|
15 | 14 | httpconfig = {};
|
|
54 | 53 |
|
55 | 54 | /**
|
56 | 55 | * 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 | + * |
57 | 60 | * @memberof BieService
|
58 | 61 | * @param {List} names List of taxon names to search
|
59 | 62 | * @returns {Promise(List)} search results that will contain LSID if found
|
|
62 | 65 | * Input:
|
63 | 66 | * ["Macropus"]
|
64 | 67 | *
|
65 |
| - * Output: |
| 68 | + * Output (may contain additional fields): |
66 | 69 | * [{
|
67 | 70 | * "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", |
76 | 72 | * "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", |
85 | 74 | * "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" |
94 | 76 | * }]
|
95 | 77 | */
|
96 | 78 | 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 | + |
101 | 82 | 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); |
106 | 111 | }
|
107 |
| - return list |
| 112 | + |
| 113 | + return $q.all(promises).then(function (results) { |
| 114 | + return [].concat.apply([], results); // Flatten the array of results |
| 115 | + }); |
108 | 116 | });
|
| 117 | + |
109 | 118 | },
|
110 | 119 |
|
111 | 120 | /**
|
112 |
| - * Bulk taxon information lookup using LSIDs |
| 121 | + * Single taxon information lookup using LSIDs. Uses name matching service. |
| 122 | + * |
113 | 123 | * @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 |
116 | 126 | *
|
117 | 127 | * @example
|
118 | 128 | * Input:
|
119 | 129 | * ["http://id.biodiversity.org.au/instance/apni/852793"]
|
120 | 130 | *
|
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 | + * } |
140 | 140 | */
|
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 | + } |
148 | 153 | }
|
149 |
| - } |
150 |
| - return list |
151 |
| - }); |
| 154 | + return list2[[0]]; |
| 155 | + }); |
152 | 156 | }
|
153 | 157 | };
|
154 | 158 | }])
|
|
0 commit comments