From 9890bd8bb3f499bff744f3b2cd2bb1015817c4eb Mon Sep 17 00:00:00 2001 From: Dave Martin Date: Mon, 7 Aug 2023 09:21:30 +0100 Subject: [PATCH] fix for #162 --- .../collectory/DataProviderController.groovy | 36 +++++++++++++++++++ grails-app/views/dataProvider/show.gsp | 4 +-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/grails-app/controllers/au/org/ala/collectory/DataProviderController.groovy b/grails-app/controllers/au/org/ala/collectory/DataProviderController.groovy index 1f871711..360f2eb7 100644 --- a/grails-app/controllers/au/org/ala/collectory/DataProviderController.groovy +++ b/grails-app/controllers/au/org/ala/collectory/DataProviderController.groovy @@ -1,9 +1,14 @@ package au.org.ala.collectory +import grails.converters.JSON +import grails.converters.XML +import grails.web.http.HttpHeaders + class DataProviderController extends ProviderGroupController { def gbifRegistryService def authService + def iptService DataProviderController() { entityName = "DataProvider" @@ -89,6 +94,37 @@ class DataProviderController extends ProviderGroupController { ) } + def iptScan = { + def create = params.create != null && params.create.equalsIgnoreCase("true") + def check = params.check == null || !params.check.equalsIgnoreCase("false") + def keyName = params.key ?: 'catalogNumber' + def isShareableWithGBIF = params.isShareableWithGBIF ? params.isShareableWithGBIF.toBoolean(): true + def provider = providerGroupService._get(params.uid) + + def username = collectoryAuthService.username() + def admin = collectoryAuthService.userInRole(grailsApplication.config.ROLE_ADMIN) + try { + def updates = provider == null ? null : iptService.scan(provider, create, check, keyName, username, admin, isShareableWithGBIF) + log.info "${updates.size()} data resources to update for ${params.uid}" + response.addHeader HttpHeaders.VARY, HttpHeaders.ACCEPT + withFormat { + text { + render updates.findAll({ dr -> dr.uid != null }).collect({ dr -> dr.uid }).join("\n") + } + xml { + render updates as XML + } + json { + render updates as JSON + } + } + } catch (Exception e){ + log.error("Problem scanning IPT endpoint: " + e.getMessage(), e) + render (status: 500, text: "Problem scanning data provider " + params.uid) + return + } + } + /** * Create a single data provider for a selected GBIF organization */ diff --git a/grails-app/views/dataProvider/show.gsp b/grails-app/views/dataProvider/show.gsp index 82425ebc..b5bf9f9a 100644 --- a/grails-app/views/dataProvider/show.gsp +++ b/grails-app/views/dataProvider/show.gsp @@ -181,7 +181,7 @@ function checkIptInstance(){ $('.iptCheck .spinner').removeClass('hide'); $('.iptBtn').attr('disabled','disabled'); - var checkUrl = "${raw(createLink(controller: "ipt", action: "scan", params:[format:"json", uid: instance?.uid, check:true, create: false]))}"; + var checkUrl = "${raw(createLink(controller: "dataProvider", action: "iptScan", params:[format:"json", uid: instance?.uid, check:true, create: false]))}"; var jqxhr = $.get(checkUrl, function(data) { $('.iptStatus').html("Success! IPT instance has " + data.length + " resources available." ); $('.iptStatus').removeClass('hide') @@ -198,7 +198,7 @@ function updateResourcesFromIpt(){ $('.iptUpdate .spinner').removeClass('hide'); $('.iptBtn').attr('disabled','disabled'); - var updateUrl = "${raw(createLink(controller: "ipt", action: "scan", params:[format:"json", uid: instance?.uid, create:true, check: false]))}"; + var updateUrl = "${raw(createLink(controller: "dataProvider", action: "iptScan", params:[format:"json", uid: instance?.uid, create:true, check: false]))}"; var jqxhr = $.get(updateUrl, function(data) { console.log(data) var updateText = "Success!

" + data.length + " resources have been added or updated from this IPT instance."