Skip to content

Commit

Permalink
#232 initial commit for new species-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Collins committed Feb 21, 2024
1 parent 6c66602 commit b4f09a3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
3 changes: 3 additions & 0 deletions grails-app/conf/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ records.url: 'https://archives.ala.org.au/archives/exports/lat_lon_taxon.zip'

api_key: ''
lists.url: 'https://lists.ala.org.au'
lists.useListWs: false
#lists.url: 'http://localhost:8080'
#lists.useListWs: true
collections.url: 'https://collections.ala.org.au'
sandboxHubUrl: 'https://sandbox.ala.org.au/ala-hub'
sandboxBiocacheServiceUrl: 'https://sandbox.ala.org.au/biocache-service'
Expand Down
8 changes: 7 additions & 1 deletion src/main/groovy/au/org/ala/spatial/SpatialConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SpatialConfig {
DotUrl namematching
DotUrl records
String api_key
DotUrl lists
DotList lists
DotUrl collections
DotGeoserver geoserver

Expand Down Expand Up @@ -96,6 +96,12 @@ class SpatialConfig {
String url
}

static
class DotList {
String url
Boolean useListWs
}

static
class DotBaseUrl {
String baseURL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class AreaReport extends SlaveProcess {
spatialConfig.biocacheUrl.toString(),
spatialConfig.bie.baseURL.toString(),
spatialConfig.lists.url.toString(),
spatialConfig.lists.useListWs,
q,
area[0].pid.toString(),
area[0].name.toString(),
Expand Down
38 changes: 25 additions & 13 deletions src/main/groovy/au/org/ala/spatial/util/AreaReportPDF.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class AreaReportPDF {
String biocacheServiceUrl
String biocacheHubUrl
String listsUrl
Boolean useListWs
String bieUrl

Map<String, String> distributions = new HashMap()
Expand Down Expand Up @@ -79,7 +80,7 @@ class AreaReportPDF {
AreaReportPDF(DistributionsService distributionsService, JournalMapService journalMapService,
TabulationService tabulationService, SpatialObjectsService spatialObjectsService,
String geoserverUrl, String openstreetmapUrl, String biocacheServiceUrl, String biocacheHubUrl,
String bieUrl, String listsUrl,
String bieUrl, String listsUrl, Boolean useListWs,
String q, String pid,
String areaName,
String area_km,
Expand All @@ -101,6 +102,7 @@ class AreaReportPDF {
this.biocacheHubUrl = biocacheHubUrl
this.bieUrl = bieUrl
this.listsUrl = listsUrl
this.useListWs = useListWs
this.pid = pid
this.query = q
this.area_km = area_km
Expand Down Expand Up @@ -665,11 +667,11 @@ class AreaReportPDF {

private String getSpeciesListName(String dr) {
try {
String txt = (String) Util.urlResponse("GET", listsUrl + "/ws/speciesList/" + dr).get("text")
String txt = (String) Util.urlResponse("GET", listsUrl + "/speciesList/" + dr).get("text")

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

return (String) jo.get("listName")
return (String) jo.get("listName", jo.get("title", null))
} catch (Exception e) {
e.printStackTrace()
}
Expand All @@ -686,9 +688,16 @@ class AreaReportPDF {
boolean hasAnotherPage = true
int max = 400
int offset = 0
int page = 1

while (hasAnotherPage) {
String txt = (String) Util.urlResponse("GET", listsUrl + "/speciesListItems/" + dr + "?includeKVP=true&max=" + max + "&offset=" + offset).get("text")
String txt
if (useListWs) {
txt = (String) Util.urlResponse("GET", listsUrl + "/speciesListItems/" + dr + "?pageSize=" + max + "&page=" + page).get("text")
page++
} else {
txt = (String) Util.urlResponse("GET", listsUrl + "/speciesListItems/" + dr + "?includeKVP=true&max=" + max + "&offset=" + offset).get("text")
}

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

for (Object o : values) {
JSONObject jo = (JSONObject) o
if (lsid.equalsIgnoreCase((String) jo.getOrDefault("lsid", null))) {
JSONArray kvp = (JSONArray) jo.get("kvpValues")
for (Object o2 : kvp) {
JSONObject jo2 = (JSONObject) o2
if (key == jo2.getOrDefault("key", null)) {
String s = (String) jo2.getOrDefault("value", null)

// keep initials only
return s.replaceAll("[a-z]", "")
String newId = ((JSONObject) jo.getOrDefault("classification", null))?.getOrDefault("taxonConceptID", null)
if (lsid.equalsIgnoreCase((String) jo.getOrDefault("lsid", newId))) {
JSONArray kvp = (JSONArray) jo.getOrDefault("kvpValues", jo.getOrDefault("properties", null))
if (kvp) {
for (Object o2 : kvp) {
JSONObject jo2 = (JSONObject) o2
if (key == jo2.getOrDefault("key", null)) {
String s = (String) jo2.getOrDefault("value", null)

// keep initials only
return s.replaceAll("[a-z]", "")
}
}
}
}
Expand Down

0 comments on commit b4f09a3

Please sign in to comment.