@@ -12,7 +12,7 @@ class MetadataController {
12
12
static responseFormats = [' json' ]
13
13
14
14
def metadataService, activityService, commonService, projectService, webService
15
-
15
+ ActivityFormService activityFormService
16
16
def activitiesModel () {
17
17
render metadataService. activitiesModel()
18
18
}
@@ -72,7 +72,21 @@ class MetadataController {
72
72
render result as JSON
73
73
return null
74
74
}
75
- def annotatedModel = metadataService. annotatedOutputDataModel(outputName)
75
+ String activityForm = params. activityForm
76
+ Integer formVersion = params. getInt(' formVersion' , null )
77
+ def annotatedModel
78
+ if (activityForm) {
79
+ ActivityForm form = activityFormService. findActivityForm(activityForm, formVersion)
80
+ if (! form) {
81
+ def result = [status :400 , error :' No form with name ' + activityForm+ ' and version ' + formVersion+ ' was found' ]
82
+ render result as JSON
83
+ return null
84
+ }
85
+ annotatedModel = form. getFormSection(outputName). annotatedTemplate()
86
+ }
87
+ else {
88
+ annotatedModel = metadataService. annotatedOutputDataModel(outputName)
89
+ }
76
90
77
91
if (! annotatedModel) {
78
92
def result = [status :404 , error :" No output of type ${ outputName} exists" ]
@@ -83,23 +97,48 @@ class MetadataController {
83
97
render annotatedModel as JSON
84
98
}
85
99
100
+ private Map getModelAndAnnotatedModel (String outputName , String activityFormName , Integer activityFormVersion , def expandList ) {
101
+ List annotatedModel
102
+ def model
103
+ if (activityFormName) {
104
+ ActivityForm form = activityFormService. findActivityForm(activityFormName, activityFormVersion)
105
+ model = form?. sections?. find{it. name == outputName}
106
+ OutputMetadata metadata = new OutputMetadata (model?. template)
107
+ annotatedModel = metadata. annotateDataModel()
108
+ }
109
+ else {
110
+ // Legacy support
111
+ model = metadataService. getOutputDataModel(outputName)
112
+ if (expandList && expandList == ' true' ) {
113
+ annotatedModel = metadataService. annotatedOutputDataModel(outputName, true )
114
+ } else {
115
+ annotatedModel = metadataService. annotatedOutputDataModel(outputName)
116
+ }
117
+ }
118
+ return [model :model, annotatedModel :annotatedModel]
119
+ }
120
+
86
121
/**
87
122
* Returns an Excel template that can be populated with output data and uploaded.
88
123
*/
89
124
def excelOutputTemplate () {
90
125
91
126
def outputName, listName, data, expandList
92
127
boolean editMode, allowExtraRows, autosizeColumns, includeDataPathHeader
128
+ String activityForm
129
+ Integer formVersion
93
130
def json = request. getJSON()
94
131
if (json) {
132
+ activityForm = json. activityForm
133
+ formVersion = json. formVersion
95
134
outputName = json. type
96
135
listName = json. listName
97
136
editMode = Boolean . valueOf(json. editMode)
98
137
allowExtraRows = Boolean . valueOf(json. allowExtraRows)
99
138
autosizeColumns = json. autosizeColumns != null ? Boolean . valueOf(json. autosizeColumns) : true
100
139
includeDataPathHeader = json. includeDataPathHeader != null ? Boolean . valueOf(json. includeDataPathHeader) : false
101
- data = JSON . parse(json. data)
102
-
140
+ data = json . data ? JSON . parse(json. data) : null
141
+ expandList = json . expandList
103
142
104
143
}
105
144
else {
@@ -110,6 +149,8 @@ class MetadataController {
110
149
allowExtraRows = params. getBoolean(' allowExtraRows' , false )
111
150
autosizeColumns = params. getBoolean(' autosizeColumns' , true )
112
151
includeDataPathHeader = params. getBoolean(' includeDataPathHeader' , false )
152
+ activityForm = params. activityForm
153
+ formVersion = params. getInt(' formVersion' , null )
113
154
}
114
155
115
156
@@ -119,13 +160,9 @@ class MetadataController {
119
160
return null
120
161
}
121
162
122
- Map model = metadataService. getOutputDataModelByName(outputName)
123
- def annotatedModel = null
124
- if (expandList && expandList == ' true' ) {
125
- annotatedModel = metadataService. annotatedOutputDataModel(outputName, true )
126
- } else {
127
- annotatedModel = metadataService. annotatedOutputDataModel(outputName)
128
- }
163
+ Map modelAndAnnotatedModel = getModelAndAnnotatedModel(outputName, activityForm, formVersion, expandList)
164
+ def model = modelAndAnnotatedModel. model
165
+ List annotatedModel = modelAndAnnotatedModel. annotatedModel
129
166
if (! annotatedModel) {
130
167
def result = [status :404 , error :" No output of type ${ outputName} exists" ]
131
168
render result as JSON
@@ -173,9 +210,6 @@ class MetadataController {
173
210
174
211
builder. save(response. outputStream)
175
212
176
- // response.getOutputStream().flush();
177
- // response.getOutputStream().close();
178
-
179
213
}
180
214
181
215
/**
0 commit comments