Skip to content

Commit

Permalink
Support form versions for table data upload/download AtlasOfLivingAus…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Dec 19, 2024
1 parent 5d7c632 commit d8ac6e8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 8 additions & 4 deletions grails-app/services/au/org/ala/merit/MetadataService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}

Expand Down
2 changes: 1 addition & 1 deletion grails-app/services/au/org/ala/merit/ProjectService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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,"<b> ${outputType}: </b> <br>");
type.each { field ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()

Expand Down

0 comments on commit d8ac6e8

Please sign in to comment.