From 701b4599b411ea93351119b27a45d7a09b118b27 Mon Sep 17 00:00:00 2001 From: Adam Collins Date: Fri, 1 Mar 2024 17:25:54 +1000 Subject: [PATCH] #468 incremental species-list support --- gradle.properties | 2 +- .../spApp/controller/areaReportCtrl.js | 4 +- .../spApp/controller/createSpeciesListCtrl.js | 11 +---- .../javascripts/spApp/directive/listsList.js | 7 +--- grails-app/conf/application.yml | 30 +++++++++++++ .../spatial/portal/PortalController.groovy | 42 +++++++++++++------ grails-app/views/portal/index.gsp | 3 +- 7 files changed, 66 insertions(+), 33 deletions(-) diff --git a/gradle.properties b/gradle.properties index 00c1447..d2f7dbe 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,4 +10,4 @@ webdriverBinariesVersion=2.6 #chromeDriverVersion=2.45.0 geckodriverVersion=0.24.0 seleniumSafariDriverVersion=3.14.0 -alaSecurityLibsVersion=6.2.0 +alaSecurityLibsVersion=6.3.0-SNAPSHOT diff --git a/grails-app/assets/javascripts/spApp/controller/areaReportCtrl.js b/grails-app/assets/javascripts/spApp/controller/areaReportCtrl.js index c46d392..1ab17ee 100644 --- a/grails-app/assets/javascripts/spApp/controller/areaReportCtrl.js +++ b/grails-app/assets/javascripts/spApp/controller/areaReportCtrl.js @@ -349,7 +349,7 @@ { name: $i18n(372, "Migratory species - EPBC"), query: {q: areaQ.q, bs: areaQ.bs, ws: areaQ.ws, wkt: areaQ.wkt, qid: areaQ.qid}, - link: ListsService.url() + '/speciesListItem/list/' + $SH.migratoryDR, + link: ListsService.urlUi() + $SH.migratoryDR, linkName: $i18n(373, "Full list"), extraQ: ["species_list_uid:" + $SH.migratoryDR], ignore: $SH.listsUrl === '' || $SH.migratoryDR === '' @@ -357,7 +357,7 @@ { name: $i18n(374, "Australian iconic species"), query: {q: areaQ.q, bs: areaQ.bs, ws: areaQ.ws, wkt: areaQ.wkt, qid: areaQ.qid}, - link: ListsService.url() + '/speciesListItem/list/' + $SH.iconicSpeciesDR, + link: ListsService.urlUi() + $SH.iconicSpeciesDR, linkName: $i18n(373, "Full list"), extraQ: ["species_list_uid:" + $SH.iconicSpeciesDR], ignore: $SH.listsUrl === '' || $SH.iconicSpeciesDR === '' diff --git a/grails-app/assets/javascripts/spApp/controller/createSpeciesListCtrl.js b/grails-app/assets/javascripts/spApp/controller/createSpeciesListCtrl.js index a93c476..8ebc450 100644 --- a/grails-app/assets/javascripts/spApp/controller/createSpeciesListCtrl.js +++ b/grails-app/assets/javascripts/spApp/controller/createSpeciesListCtrl.js @@ -33,16 +33,7 @@ $scope.maxFileSize = $SH.maxUploadSize; - $scope.listTypes = [ - {id: 'OTHER', label: "Other"}, - {id: 'SPECIES_CHARACTERS', label: "Species characters list"}, - {id: 'CONSERVATION_LIST', label: "Conservation list"}, - {id: 'SENSITIVE_LIST', label: "Sensitive list of species"}, - {id: 'LOCAL_LIST', label: "Local checklist"}, - {id: 'COMMON_TRAIT', label: "Common trait of species"}, - {id: 'COMMON_HABITAT', label: "Common habitat of species"}, - {id: 'TEST', label: "Test list"} - ] + $scope.listTypes = $SH.listTypes; $scope.newListName = $i18n(375, "My species list"); $scope.newListDescription = ''; diff --git a/grails-app/assets/javascripts/spApp/directive/listsList.js b/grails-app/assets/javascripts/spApp/directive/listsList.js index d2ead5e..c4eba9d 100644 --- a/grails-app/assets/javascripts/spApp/directive/listsList.js +++ b/grails-app/assets/javascripts/spApp/directive/listsList.js @@ -70,12 +70,7 @@ }; scope.itemUrl = function (item) { - if (ListsService.urlUi()) { - // new species-lists as urlUi defined - return ListsService.urlUi() + '/#/list/' + item.dataResourceUid - } else { - return ListsService.url() + '/speciesListItem/list/' + item.dataResourceUid - } + return ListsService.urlUi() + item.dataResourceUid }; scope.add = function (item) { diff --git a/grails-app/conf/application.yml b/grails-app/conf/application.yml index 2fd0e71..c91e63a 100644 --- a/grails-app/conf/application.yml +++ b/grails-app/conf/application.yml @@ -212,6 +212,23 @@ lists: facets: true migratoryDR: 'dr1005' iconicSpeciesDR: 'dr781' + listTypes: + - id: 'OTHER' + label: "Other" + - id: 'SPECIES_CHARACTERS' + label: "Species characters list" + - id: 'CONSERVATION_LIST' + label: "Conservation list" + - id: 'SENSITIVE_LIST' + label: "Sensitive list of species" + - id: 'LOCAL_LIST' + label: "Local checklist" + - id: 'COMMON_TRAIT' + label: "Common trait of species" + - id: 'COMMON_HABITAT' + label: "Common habitat of species" + - id: 'TEST' + label: "Test list" #lists: # useListWs: true # url: 'http://localhost:8080' @@ -221,6 +238,19 @@ lists: # facets: true # migratoryDR: 'dr1005' # iconicSpeciesDR: 'dr781' +# listTypes: +# - id: 'CONSERVATION_LIST' +# label: "Conservation species list" +# - id: 'SENSITIVE_LIST' +# label: "Sensitive list" +# - id: 'INVASIVE' +# label: "Invasive species list" +# - id: 'COMMON_TRAIT' +# label: "Traits" +# - id: 'LOCAL_LIST' +# label: "Local checklist" +# - id: 'SPECIES_CHARACTERS' +# label: "Species characters" journalmap: url: 'https://www.journalmap.org' diff --git a/grails-app/controllers/au/org/ala/spatial/portal/PortalController.groovy b/grails-app/controllers/au/org/ala/spatial/portal/PortalController.groovy index 5cd43df..e7ae57d 100644 --- a/grails-app/controllers/au/org/ala/spatial/portal/PortalController.groovy +++ b/grails-app/controllers/au/org/ala/spatial/portal/PortalController.groovy @@ -9,7 +9,6 @@ import org.apache.commons.lang.StringUtils import org.apache.http.client.methods.HttpGet import org.apache.http.client.methods.HttpPost import org.apache.http.entity.ContentType -import org.jasig.cas.client.util.CommonUtils import org.springframework.web.multipart.MultipartFile import org.springframework.web.multipart.MultipartHttpServletRequest @@ -378,19 +377,36 @@ class PortalController { def r if (grailsApplication.config.lists.useListWs) { - // format input - /* - { - "listName": name, - "listItems": items, - "description": description, - "isPrivate": makePrivate, - "listType": listType - } - */ - r = webService.post("${url}/upload", json, null, ContentType.APPLICATION_JSON, false, true) + // create tmp file + File tmpFile = File.createTempFile("spatial-species-list-",".csv") + BufferedWriter fw = new BufferedWriter(new FileWriter(tmpFile)) + fw.writeLine("taxonID") + for (String item : json.listItems.split(",")) { + fw.writeLine(item) + } + fw.flush() + fw.close() + + r = webService.postMultipart("${url}/upload", null, null, [file: tmpFile], ContentType.APPLICATION_JSON, false, true) + + tmpFile.delete() - r = webService.post("${url}/ingest/${speciesListID}", json, null, ContentType.APPLICATION_JSON, false, true) + if (r.statusCode == 200) { + def metadata = [ + file : r.resp.localFile, + title : json.listName, + description: json.description ?: json.listName, + listType : json.listType, + region : "AUS", // TODO: replicate species-lists behaviour, depends on species-lists issue #83 + licence : "CC-BY", // TODO: replicate species-lists behaviour, depends on species-lists issue #83 + isPrivate : json.isPrivate + ] + + r = webService.post("${url}/ingest", metadata, [file: r.resp.localFile], ContentType.APPLICATION_JSON, false, true) + + // backward compatible id field + r.resp.druid = r.resp.id + } } else { r = webService.post("${url}/ws/speciesList/", json) } diff --git a/grails-app/views/portal/index.gsp b/grails-app/views/portal/index.gsp index 4d07900..f6b6caa 100644 --- a/grails-app/views/portal/index.gsp +++ b/grails-app/views/portal/index.gsp @@ -40,8 +40,9 @@ layersServiceUrl: '${config.layersService.url}', samplingUrl: '${config.sampling.url}', listsUrl: '${config.lists.url}', - listsUrlUi: '${config.lists.urlUi}', + listsUrlUi: '${config.lists.urlUi + (config.lists.useListWs ? "/#/list/" : "/speciesListItem/list/")}', listsFacets: ${config.lists.facets}, + listTypes: ${(config.lists.listTypes as grails.converters.JSON).toString().encodeAsRaw()}, sandboxUrl: '${config.sandbox.url}', sandboxServiceUrl: '${config.sandboxService.url}', sandboxUiUrl: '${config.sandbox.uiUrl}',