From d8ac6e8ee547bbe2f259e073fae409e7ec2ed946 Mon Sep 17 00:00:00 2001 From: chrisala Date: Thu, 19 Dec 2024 13:16:15 +1100 Subject: [PATCH] Support form versions for table data upload/download AtlasOfLivingAustralia/ecodata#1025 --- build.gradle | 2 +- .../au/org/ala/merit/ActivityController.groovy | 15 ++++++--------- .../org/ala/merit/OrganisationController.groovy | 2 +- .../au/org/ala/merit/MetadataService.groovy | 12 ++++++++---- .../au/org/ala/merit/ProjectService.groovy | 2 +- .../org/ala/merit/ActivityControllerSpec.groovy | 4 +++- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index b0c783dc1..b4353bb3a 100644 --- a/build.gradle +++ b/build.gradle @@ -188,7 +188,7 @@ dependencies { providedCompile "io.methvin:directory-watcher:0.4.0" if (!Boolean.valueOf(inplace)) { - implementation "org.grails.plugins:ecodata-client-plugin:7.0" + implementation "org.grails.plugins:ecodata-client-plugin:7.2-SNAPSHOT" } } diff --git a/grails-app/controllers/au/org/ala/merit/ActivityController.groovy b/grails-app/controllers/au/org/ala/merit/ActivityController.groovy index f78f9e0ca..7006424bd 100644 --- a/grails-app/controllers/au/org/ala/merit/ActivityController.groovy +++ b/grails-app/controllers/au/org/ala/merit/ActivityController.groovy @@ -507,8 +507,10 @@ class ActivityController { def outputName = params.type def listName = params.listName + String activityForm = params.activityForm + Integer formVersion = params.getInt('formVersion', null) - def model = metadataService.annotatedOutputDataModel(outputName) + def model = metadataService.annotatedOutputDataModel(activityForm, outputName, formVersion) if (listName) { model = metadataService.findByName(listName, model)?.columns } @@ -617,14 +619,9 @@ class ActivityController { String url = "${grailsApplication.config.getProperty('ecodata.baseUrl')}metadata/excelOutputTemplate" - if (params.data) { - webService.proxyPostRequest(response, url, - [listName:params.listName, type:params.type, data:params.data, editMode:params.editMode, allowExtraRows:params.allowExtraRows, autosizeColumns:false]) - } - else { - url += "?type=${params.type?.encodeAsURL()}&listName=${params.listName?.encodeAsURL()}" - webService.proxyGetRequest(response, url, true, true) - } + Map postParams = [listName:params.listName, type:params.type, data:params.data, editMode:params.editMode, allowExtraRows:params.allowExtraRows, autosizeColumns:false, formVersion:params.getInt('formVersion'), activityForm:params.activityForm] + + webService.proxyPostRequest(response, url, postParams) return null } diff --git a/grails-app/controllers/au/org/ala/merit/OrganisationController.groovy b/grails-app/controllers/au/org/ala/merit/OrganisationController.groovy index 4ab021f5b..13b5fb36a 100644 --- a/grails-app/controllers/au/org/ala/merit/OrganisationController.groovy +++ b/grails-app/controllers/au/org/ala/merit/OrganisationController.groovy @@ -455,7 +455,7 @@ class OrganisationController { return } def outputModels = activityModel.outputs.collect { - [name:it, annotatedModel:metadataService.annotatedOutputDataModel(it), dataModel:metadataService.getDataModelFromOutputName(it)] + [name:it, annotatedModel:metadataService.annotatedOutputDataModel(activityType, it, null), dataModel:metadataService.getDataModelFromOutputName(it)] } def criteria = [type:activityType, projectId:organisation.projects.collect{it.projectId}, dateProperty:'plannedEndDate', startDate:params.plannedStartDate, endDate:params.plannedEndDate] diff --git a/grails-app/services/au/org/ala/merit/MetadataService.groovy b/grails-app/services/au/org/ala/merit/MetadataService.groovy index 10603bce4..62e29e34c 100644 --- a/grails-app/services/au/org/ala/merit/MetadataService.groovy +++ b/grails-app/services/au/org/ala/merit/MetadataService.groovy @@ -23,10 +23,14 @@ class MetadataService { }) } - def annotatedOutputDataModel(type) { - return cacheService.get('annotated-output-model'+type,{ - Collections.unmodifiableList(webService.getJson(grailsApplication.config.getProperty('ecodata.baseUrl') + - 'metadata/annotatedOutputDataModel?type='+type.encodeAsURL())) + def annotatedOutputDataModel(String activityForm, String formSection, Integer formVersion) { + return cacheService.get('annotated-output-model'+activityForm+'_'+formSection,{ + String url = grailsApplication.config.getProperty('ecodata.baseUrl') + + 'metadata/annotatedOutputDataModel?type='+formSection.encodeAsURL()+"&activityForm="+activityForm.encodeAsURL() + if (formVersion) { + url += "&formVersion="+formVersion + } + Collections.unmodifiableList(webService.getJson(url)) }) } diff --git a/grails-app/services/au/org/ala/merit/ProjectService.groovy b/grails-app/services/au/org/ala/merit/ProjectService.groovy index 761357552..206f93c6b 100644 --- a/grails-app/services/au/org/ala/merit/ProjectService.groovy +++ b/grails-app/services/au/org/ala/merit/ProjectService.groovy @@ -1340,7 +1340,7 @@ class ProjectService { stageReportActivityModel.outputs.each { outputType -> def output = activity.outputs?.find { it.name == outputType } - def type = metadataService.annotatedOutputDataModel(outputType) + def type = metadataService.annotatedOutputDataModel(activity.type, outputType, activity.formVersion) append(html," ${outputType}:
"); type.each { field -> diff --git a/src/test/groovy/au/org/ala/merit/ActivityControllerSpec.groovy b/src/test/groovy/au/org/ala/merit/ActivityControllerSpec.groovy index 44551475a..7dc8bcee0 100644 --- a/src/test/groovy/au/org/ala/merit/ActivityControllerSpec.groovy +++ b/src/test/groovy/au/org/ala/merit/ActivityControllerSpec.groovy @@ -539,6 +539,8 @@ class ActivityControllerSpec extends Specification implements ControllerUnitTest params.type = 'RLP - Flora survey' params.listName = 'floraSurveyDetails' + params.activityForm = 'Flora Survey' + params.formVersion = 2 JSON.createNamedConfig("clientSideFormattedDates", { cfg -> DateTimeFormatter formatter = DateTimeFormat.forPattern("dd-MM-yyyy") @@ -550,7 +552,7 @@ class ActivityControllerSpec extends Specification implements ControllerUnitTest controller.ajaxUpload() then: - 1 * metadataService.annotatedOutputDataModel('RLP - Flora survey') >> getListModel() + 1 * metadataService.annotatedOutputDataModel('Flora Survey', 'RLP - Flora survey', 2) >> getListModel() 1 * metadataService.findByName('floraSurveyDetails', getListModel()) >> getMapModel() 1 * speciesService.searchByScientificName(_) >> getScientificModel()