Skip to content

Commit d8ac6e8

Browse files
committed
Support form versions for table data upload/download AtlasOfLivingAustralia/ecodata#1025
1 parent 5d7c632 commit d8ac6e8

File tree

6 files changed

+20
-17
lines changed

6 files changed

+20
-17
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ dependencies {
188188
providedCompile "io.methvin:directory-watcher:0.4.0"
189189

190190
if (!Boolean.valueOf(inplace)) {
191-
implementation "org.grails.plugins:ecodata-client-plugin:7.0"
191+
implementation "org.grails.plugins:ecodata-client-plugin:7.2-SNAPSHOT"
192192
}
193193
}
194194

grails-app/controllers/au/org/ala/merit/ActivityController.groovy

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,10 @@ class ActivityController {
507507

508508
def outputName = params.type
509509
def listName = params.listName
510+
String activityForm = params.activityForm
511+
Integer formVersion = params.getInt('formVersion', null)
510512

511-
def model = metadataService.annotatedOutputDataModel(outputName)
513+
def model = metadataService.annotatedOutputDataModel(activityForm, outputName, formVersion)
512514
if (listName) {
513515
model = metadataService.findByName(listName, model)?.columns
514516
}
@@ -617,14 +619,9 @@ class ActivityController {
617619

618620
String url = "${grailsApplication.config.getProperty('ecodata.baseUrl')}metadata/excelOutputTemplate"
619621

620-
if (params.data) {
621-
webService.proxyPostRequest(response, url,
622-
[listName:params.listName, type:params.type, data:params.data, editMode:params.editMode, allowExtraRows:params.allowExtraRows, autosizeColumns:false])
623-
}
624-
else {
625-
url += "?type=${params.type?.encodeAsURL()}&listName=${params.listName?.encodeAsURL()}"
626-
webService.proxyGetRequest(response, url, true, true)
627-
}
622+
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]
623+
624+
webService.proxyPostRequest(response, url, postParams)
628625

629626
return null
630627
}

grails-app/controllers/au/org/ala/merit/OrganisationController.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ class OrganisationController {
455455
return
456456
}
457457
def outputModels = activityModel.outputs.collect {
458-
[name:it, annotatedModel:metadataService.annotatedOutputDataModel(it), dataModel:metadataService.getDataModelFromOutputName(it)]
458+
[name:it, annotatedModel:metadataService.annotatedOutputDataModel(activityType, it, null), dataModel:metadataService.getDataModelFromOutputName(it)]
459459
}
460460

461461
def criteria = [type:activityType, projectId:organisation.projects.collect{it.projectId}, dateProperty:'plannedEndDate', startDate:params.plannedStartDate, endDate:params.plannedEndDate]

grails-app/services/au/org/ala/merit/MetadataService.groovy

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ class MetadataService {
2323
})
2424
}
2525

26-
def annotatedOutputDataModel(type) {
27-
return cacheService.get('annotated-output-model'+type,{
28-
Collections.unmodifiableList(webService.getJson(grailsApplication.config.getProperty('ecodata.baseUrl') +
29-
'metadata/annotatedOutputDataModel?type='+type.encodeAsURL()))
26+
def annotatedOutputDataModel(String activityForm, String formSection, Integer formVersion) {
27+
return cacheService.get('annotated-output-model'+activityForm+'_'+formSection,{
28+
String url = grailsApplication.config.getProperty('ecodata.baseUrl') +
29+
'metadata/annotatedOutputDataModel?type='+formSection.encodeAsURL()+"&activityForm="+activityForm.encodeAsURL()
30+
if (formVersion) {
31+
url += "&formVersion="+formVersion
32+
}
33+
Collections.unmodifiableList(webService.getJson(url))
3034
})
3135
}
3236

grails-app/services/au/org/ala/merit/ProjectService.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ class ProjectService {
13401340

13411341
stageReportActivityModel.outputs.each { outputType ->
13421342
def output = activity.outputs?.find { it.name == outputType }
1343-
def type = metadataService.annotatedOutputDataModel(outputType)
1343+
def type = metadataService.annotatedOutputDataModel(activity.type, outputType, activity.formVersion)
13441344

13451345
append(html,"<b> ${outputType}: </b> <br>");
13461346
type.each { field ->

src/test/groovy/au/org/ala/merit/ActivityControllerSpec.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,8 @@ class ActivityControllerSpec extends Specification implements ControllerUnitTest
539539

540540
params.type = 'RLP - Flora survey'
541541
params.listName = 'floraSurveyDetails'
542+
params.activityForm = 'Flora Survey'
543+
params.formVersion = 2
542544

543545
JSON.createNamedConfig("clientSideFormattedDates", { cfg ->
544546
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd-MM-yyyy")
@@ -550,7 +552,7 @@ class ActivityControllerSpec extends Specification implements ControllerUnitTest
550552
controller.ajaxUpload()
551553

552554
then:
553-
1 * metadataService.annotatedOutputDataModel('RLP - Flora survey') >> getListModel()
555+
1 * metadataService.annotatedOutputDataModel('Flora Survey', 'RLP - Flora survey', 2) >> getListModel()
554556
1 * metadataService.findByName('floraSurveyDetails', getListModel()) >> getMapModel()
555557
1 * speciesService.searchByScientificName(_) >> getScientificModel()
556558

0 commit comments

Comments
 (0)