Changeset 1425 for trunk/grails-app/controllers
- Timestamp:
- Jan 21, 2011, 4:37:54 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/AssayController.groovy
r1261 r1425 138 138 */ 139 139 def exportAssayAsExcel = { 140 Assay assay = Assay.get(params.id) 140 141 Assay assay = Assay.get(params.assayId) 141 142 142 143 if (!assay) { 143 flash.errorMessage = "No assay found with id: $params. id."144 flash.errorMessage = "No assay found with id: $params.assayId." 144 145 redirect action: 'selectAssay' 145 146 return 146 147 } 147 148 148 // TODO: refactor into service149 try { 149 150 150 // Gather sample meta data from GSCF 151 def samples = assay.samples 151 def assayData = assayService.collectAssayData(assay, grailsApplication.config.modules.metabolomics.url) 152 152 153 def collectUsedTemplateFields = { templateEntityList -> 153 def filename = 'export.xlsx' 154 response.setHeader("Content-disposition", "attachment;filename=\"${filename}\"") 155 response.setContentType("application/octet-stream") 154 156 155 def templateFields = templateEntityList*.giveFields().flatten().unique().findAll{it} 156 def usedTemplateFields = templateFields.findAll{ tf -> 157 assayService.exportColumnWiseDataToExcelFile(assayData, response.outputStream) 157 158 158 templateEntityList.any { it.fieldExists(tf.name) && it.getFieldValue(tf.name) } 159 } 159 } catch (Exception e) { 160 160 161 def m = [:] 162 usedTemplateFields.each { tf -> 163 m["${tf.name}"] = templateEntityList.collect{ it.fieldExists(tf.name) ? it.getFieldValue(tf.name) : '' } 164 } 165 m 166 } 161 flash.errorMessage = e.toString() 162 redirect action: 'selectAssay' 167 163 168 // get all sample related subjects169 def assayData = [170 'Subject Data': collectUsedTemplateFields(samples*.parentSubject.unique()),171 'Sampling Event Data': collectUsedTemplateFields(samples*.parentEvent.unique()),172 'Event Data': collectUsedTemplateFields(samples*.parentEventGroup.events.flatten().unique()),173 'Sample Data': collectUsedTemplateFields(samples)]174 175 // Gather sample meta data from the module176 177 // - sample metadata178 179 // Gather measurement data from the module180 181 // - measurements182 183 // Write to excel184 185 println assayData186 187 try {188 assayService.exportAssayDataAsExcelFile(assayData)189 } catch (Exception e) {190 flash.errorMessage = e.message191 redirect action: 'selectAssay'192 164 } 193 165 }
Note: See TracChangeset
for help on using the changeset viewer.