Changeset 1051
- Timestamp:
- Nov 3, 2010, 8:48:39 AM (13 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/exporter/ExporterController.groovy
r1035 r1051 74 74 */ 75 75 def export = { 76 def studyInstance 76 //def studyInstance 77 def studies = [] 77 78 78 79 // the attributes list for the SimpleTox format … … 83 84 for ( j in dbnp.studycapturing.Study.list() ){ 84 85 if (params.containsKey(j.title)){ 85 studyInstance = j 86 } 87 } 86 // studyInstance = j 87 studies.add(j) 88 } 89 } 90 91 // def studies = params*.key.collect{ Study.findByTitle(it) } 92 93 println "STUDIES : "+studies 94 95 for (studyInstance in studies) { 96 97 98 if (studyInstance!=null){ 99 100 println "StudyInstance :" +studyInstance 88 101 89 102 HSSFWorkbook wb = new HSSFWorkbook() 90 //FileOutputStream fileOut = new FileOutputStream(studyInstance.title+"_SimpleTox.xls") 91 // HSSFCellStyle style = wb.createCellStyle() 92 // style.setFillForegroundColor((short) HSSFColor.RED.index) 93 94 103 println " WORKBOOK : "+wb 95 104 // The first row contains the attributes names 96 105 HSSFSheet sheet = wb.createSheet() 97 106 HSSFRow row = sheet.createRow((short)0) 98 107 for (i in 0..attributes_list.size()){ 99 // HSSFCell cell = row.createCell((short)i)100 // cell.setCellValue(attributes_list[i])101 // cell.setCellStyle(style)102 108 row.createCell((short)i).setCellValue(attributes_list[i]) 103 109 } … … 105 111 // Adding the next lines 106 112 for (s in 1..studyInstance.samples.size()){ 113 try { 107 114 // creating new line for every sample 108 115 HSSFRow sub = sheet.createRow((short)s) 109 // adding subject name in row 1 110 sub.createCell((short)0).setCellValue(studyInstance.samples.getAt(s-1).parentSubject.name) 111 // adding sample in row 4 112 sub.createCell((short)3).setCellValue(studyInstance.samples.getAt(s-1).name) 113 // adding label (EventGroup) in row 6 114 for (ev in EventGroup.list()){ 115 if (ev.subjects.name.contains(studyInstance.samples.getAt(s-1).parentSubject.name)) { 116 sub.createCell((short)5).setCellValue(ev.name) 117 break 118 } 119 else { 120 sub.createCell((short)5).setCellValue(" ") 121 } 122 } 123 // adding study title in row 7 124 sub.createCell((short)6).setCellValue(studyInstance.title) 125 // Species row 9 126 sub.createCell((short)8).setCellValue(studyInstance.samples.getAt(s-1).parentSubject.species.name) 116 def sample = studyInstance.samples.getAt(s-1) 117 118 writeMandatoryFields(sub,sample,studyInstance) 127 119 128 120 // adding the subject domain + template properties 129 for (u in 0..studyInstance.samples.getAt(s-1).parentSubject.giveFields().unique().size()-1){ 130 TemplateField tf = studyInstance.samples.getAt(s-1).parentSubject.giveFields().getAt(u) 131 row.createCell((short)9+u).setCellValue(tf.name) 132 studyInstance.samples.getAt(s-1).parentSubject.getFieldValue(tf.name) ? sub.createCell((short)9+u).setCellValue(studyInstance.samples.getAt(s-1).parentSubject.getFieldValue(tf.name).toString()) : "not define" 133 } 121 writeSubjectProperties(sub,sample,row) 134 122 135 123 // adding the samplingEvent domain + template properties 136 for (t in 0..studyInstance.samples.getAt(s-1).parentEvent.giveFields().unique().size()-1){ 137 TemplateField tf = studyInstance.samples.getAt(s-1).parentEvent.giveFields().getAt(t) 138 row.createCell((short)9+studyInstance.samples.getAt(s-1).parentSubject.giveFields().unique().size()+t).setCellValue(tf.name) 139 studyInstance.samples.getAt(s-1).parentEvent.getFieldValue(tf.name) ? sub.createCell((short)9+studyInstance.samples.getAt(s-1).parentSubject.giveFields().unique().size()+t).setCellValue(studyInstance.samples.getAt(s-1).parentEvent.getFieldValue(tf.name).toString()) : "not define" 140 } 141 124 writeSamplingEventProperties(sub,sample,row) 125 142 126 // adding samples domain + template properties 143 TemplateField sf = s tudyInstance.samples.getAt(s-1).giveFields().getAt(s)127 TemplateField sf = sample.giveFields().getAt(s) 144 128 //println studyInstance.samples.getAt(s-1).getFieldValue(sf.name) 145 129 146 130 // adding Event domaine + template properties 147 131 148 149 }150 //println "DOMAINS " +studyInstance.samples.getAt(s-1).parentSubject.giveFields()151 152 //wb.write(fileOut)153 //fileOut.close() 154 132 } 133 catch (Exception e){ 134 println "Error creating file" 135 } 136 } 137 138 // Make the file downloadable 155 139 response.setHeader("Content-disposition", "attachment;filename=\"${studyInstance.title}_SimpleTox.xls\"") 156 140 response.setContentType("application/octet-stream") 157 141 wb.write(response.outputStream) 158 142 response.outputStream.close() 159 160 161 } 162 143 } 144 } 145 } 146 147 def writeMandatoryFields(sub,sample,study) { 148 149 try { 150 // adding subject name in row 1 151 sub.createCell((short)0).setCellValue(sample.parentSubject.name) 152 // adding sample in row 4 153 sub.createCell((short)3).setCellValue(sample.name) 154 // adding label (EventGroup) in row 6 155 for (ev in EventGroup.list()){ 156 if (ev.subjects.name.contains(sample.parentSubject.name)) { 157 sub.createCell((short)5).setCellValue(ev.name) 158 break 159 } 160 else { 161 sub.createCell((short)5).setCellValue(" ") 162 } 163 } 164 // adding study title in row 7 165 sub.createCell((short)6).setCellValue(study.title) 166 // Species row 9 167 sub.createCell((short)8).setCellValue(sample.parentSubject.species.name) 168 } 169 catct (Exception e){ 170 println "Error during Mandatory Fields" 171 } 172 } 173 174 // writing subject properties 175 def writeSubjectProperties(sub,sample,row) { 176 try { 177 for (u in 0..sample.parentSubject.giveFields().unique().size()-1){ 178 TemplateField tf = sample.parentSubject.giveFields().getAt(u) 179 row.createCell((short)9+u).setCellValue(tf.name) 180 sample.parentSubject.getFieldValue(tf.name) ? sub.createCell((short)9+u).setCellValue(sample.parentSubject.getFieldValue(tf.name).toString()) : "not define" 181 } 182 } 183 catch (Exception e){ 184 println "Error during Subject Properties" 185 } 186 } 187 188 // writing samplingEvent properties 189 def writeSamplingEventProperties(sub,sample,row){ 190 try { 191 for (t in 0..sample.parentEvent.giveFields().unique().size()-1){ 192 TemplateField tf =sample.parentEvent.giveFields().getAt(t) 193 row.createCell((short)9+sample.parentSubject.giveFields().unique().size()+t).setCellValue(tf.name) 194 sample.parentEvent.getFieldValue(tf.name) ? sub.createCell((short)9+sample.parentSubject.giveFields().unique().size()+t).setCellValue(sample.parentEvent.getFieldValue(tf.name).toString()) : "not define" 195 } 196 } 197 catch (Exception e) { 198 println "Error during Sampling Event properties" 199 } 200 } 163 201 164 202 } -
trunk/grails-app/views/exporter/index.gsp
r1035 r1051 81 81 <div class="paginateButtons" id="button"> 82 82 </div> 83 84 <!-- <g:submitToRemote action="test" update="result" />--> 85 86 <!-- <g:submitToRemote action="export" update="[success:'message',failure:'error']" />--> 87 83 88 84 <INPUT TYPE=submit name=submit Value="Export"> 89 85 90 86 </div> 91 92 87 <div id="result"> </div> 93 88
Note: See TracChangeset
for help on using the changeset viewer.