@@ -21,6 +21,7 @@ import com.opencsv.CSVWriterBuilder
21
21
import com.opencsv.RFC4180ParserBuilder
22
22
import org.springframework.beans.factory.annotation.Autowired
23
23
import org.springframework.beans.factory.annotation.Qualifier
24
+ import org.springframework.beans.factory.annotation.Value
24
25
import org.springframework.web.multipart.MultipartFile
25
26
import org.springframework.web.multipart.MultipartHttpServletRequest
26
27
@@ -33,6 +34,9 @@ class AdminController {
33
34
def profileService
34
35
def authorisedSystemService
35
36
37
+ @Value (' ${attributes.affiliations.attribute-name:affiliation}' )
38
+ String affiliationAttribute = ' affiliation'
39
+
36
40
@Autowired
37
41
@Qualifier (' userService' )
38
42
IUserService userService
@@ -153,13 +157,28 @@ class AdminController {
153
157
}
154
158
155
159
def surveyResults () {
156
- def results = userService. countByProfileAttribute(' affiliation' , null , request. locale)
160
+ def results = userService. countByProfileAttribute(affiliationAttribute, null , request. locale)
161
+ respondWithCsv(results, " user-survey-${ new Date()} .csv" )
162
+ }
163
+
164
+ def emailListForm () {
165
+
166
+ }
167
+
168
+ def emailList () {
169
+ def startDate = params. date(' start_date' )
170
+ def endDate = params. date(' end_date' )
171
+ def results = userService. emailList(startDate, endDate)
172
+ respondWithCsv(results, " email-list-$startDate -to-${ endDate} .csv" )
173
+ }
174
+
175
+ private def respondWithCsv (List<String []> results , String filename ) {
157
176
def csvWriter = new CSVWriterBuilder (response. writer)
158
177
.withParser(new RFC4180ParserBuilder (). build())
159
178
.build()
160
179
response. status = 200
161
180
response. contentType = ' text/csv'
162
- response. setHeader(' Content-Disposition' , " attachment; filename=user-survey- ${ new Date() } .csv " )
181
+ response. setHeader(' Content-Disposition' , " attachment; filename=$f ilename " )
163
182
csvWriter. writeAll(results)
164
183
csvWriter. flush()
165
184
}
0 commit comments