Skip to content

Commit b4f09a3

Browse files
author
Adam Collins
committed
#232 initial commit for new species-lists
1 parent 6c66602 commit b4f09a3

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

grails-app/conf/application.yml

+3
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ records.url: 'https://archives.ala.org.au/archives/exports/lat_lon_taxon.zip'
266266

267267
api_key: ''
268268
lists.url: 'https://lists.ala.org.au'
269+
lists.useListWs: false
270+
#lists.url: 'http://localhost:8080'
271+
#lists.useListWs: true
269272
collections.url: 'https://collections.ala.org.au'
270273
sandboxHubUrl: 'https://sandbox.ala.org.au/ala-hub'
271274
sandboxBiocacheServiceUrl: 'https://sandbox.ala.org.au/biocache-service'

src/main/groovy/au/org/ala/spatial/SpatialConfig.groovy

+7-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class SpatialConfig {
6060
DotUrl namematching
6161
DotUrl records
6262
String api_key
63-
DotUrl lists
63+
DotList lists
6464
DotUrl collections
6565
DotGeoserver geoserver
6666

@@ -96,6 +96,12 @@ class SpatialConfig {
9696
String url
9797
}
9898

99+
static
100+
class DotList {
101+
String url
102+
Boolean useListWs
103+
}
104+
99105
static
100106
class DotBaseUrl {
101107
String baseURL

src/main/groovy/au/org/ala/spatial/process/AreaReport.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class AreaReport extends SlaveProcess {
113113
spatialConfig.biocacheUrl.toString(),
114114
spatialConfig.bie.baseURL.toString(),
115115
spatialConfig.lists.url.toString(),
116+
spatialConfig.lists.useListWs,
116117
q,
117118
area[0].pid.toString(),
118119
area[0].name.toString(),

src/main/groovy/au/org/ala/spatial/util/AreaReportPDF.groovy

+25-13
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class AreaReportPDF {
4949
String biocacheServiceUrl
5050
String biocacheHubUrl
5151
String listsUrl
52+
Boolean useListWs
5253
String bieUrl
5354

5455
Map<String, String> distributions = new HashMap()
@@ -79,7 +80,7 @@ class AreaReportPDF {
7980
AreaReportPDF(DistributionsService distributionsService, JournalMapService journalMapService,
8081
TabulationService tabulationService, SpatialObjectsService spatialObjectsService,
8182
String geoserverUrl, String openstreetmapUrl, String biocacheServiceUrl, String biocacheHubUrl,
82-
String bieUrl, String listsUrl,
83+
String bieUrl, String listsUrl, Boolean useListWs,
8384
String q, String pid,
8485
String areaName,
8586
String area_km,
@@ -101,6 +102,7 @@ class AreaReportPDF {
101102
this.biocacheHubUrl = biocacheHubUrl
102103
this.bieUrl = bieUrl
103104
this.listsUrl = listsUrl
105+
this.useListWs = useListWs
104106
this.pid = pid
105107
this.query = q
106108
this.area_km = area_km
@@ -665,11 +667,11 @@ class AreaReportPDF {
665667

666668
private String getSpeciesListName(String dr) {
667669
try {
668-
String txt = (String) Util.urlResponse("GET", listsUrl + "/ws/speciesList/" + dr).get("text")
670+
String txt = (String) Util.urlResponse("GET", listsUrl + "/speciesList/" + dr).get("text")
669671

670672
JSONObject jo = (JSONObject) JSON.parse(txt)
671673

672-
return (String) jo.get("listName")
674+
return (String) jo.get("listName", jo.get("title", null))
673675
} catch (Exception e) {
674676
e.printStackTrace()
675677
}
@@ -686,9 +688,16 @@ class AreaReportPDF {
686688
boolean hasAnotherPage = true
687689
int max = 400
688690
int offset = 0
691+
int page = 1
689692

690693
while (hasAnotherPage) {
691-
String txt = (String) Util.urlResponse("GET", listsUrl + "/speciesListItems/" + dr + "?includeKVP=true&max=" + max + "&offset=" + offset).get("text")
694+
String txt
695+
if (useListWs) {
696+
txt = (String) Util.urlResponse("GET", listsUrl + "/speciesListItems/" + dr + "?pageSize=" + max + "&page=" + page).get("text")
697+
page++
698+
} else {
699+
txt = (String) Util.urlResponse("GET", listsUrl + "/speciesListItems/" + dr + "?includeKVP=true&max=" + max + "&offset=" + offset).get("text")
700+
}
692701

693702
JSONArray newValues = (JSONArray) JSON.parse(txt)
694703
values.addAll(newValues)
@@ -705,15 +714,18 @@ class AreaReportPDF {
705714

706715
for (Object o : values) {
707716
JSONObject jo = (JSONObject) o
708-
if (lsid.equalsIgnoreCase((String) jo.getOrDefault("lsid", null))) {
709-
JSONArray kvp = (JSONArray) jo.get("kvpValues")
710-
for (Object o2 : kvp) {
711-
JSONObject jo2 = (JSONObject) o2
712-
if (key == jo2.getOrDefault("key", null)) {
713-
String s = (String) jo2.getOrDefault("value", null)
714-
715-
// keep initials only
716-
return s.replaceAll("[a-z]", "")
717+
String newId = ((JSONObject) jo.getOrDefault("classification", null))?.getOrDefault("taxonConceptID", null)
718+
if (lsid.equalsIgnoreCase((String) jo.getOrDefault("lsid", newId))) {
719+
JSONArray kvp = (JSONArray) jo.getOrDefault("kvpValues", jo.getOrDefault("properties", null))
720+
if (kvp) {
721+
for (Object o2 : kvp) {
722+
JSONObject jo2 = (JSONObject) o2
723+
if (key == jo2.getOrDefault("key", null)) {
724+
String s = (String) jo2.getOrDefault("value", null)
725+
726+
// keep initials only
727+
return s.replaceAll("[a-z]", "")
728+
}
717729
}
718730
}
719731
}

0 commit comments

Comments
 (0)