Changeset 20 for trunk/grails-app/services/nl
- Timestamp:
- Mar 22, 2011, 1:52:56 PM (12 years ago)
- Location:
- trunk/grails-app/services/nl/tno/metagenomics
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/nl/tno/metagenomics/files/ExcelService.groovy
r7 r20 79 79 80 80 for( def rowNum = startRow; rowNum <= endRow; rowNum++ ) { 81 ArrayList row = []82 81 Row excelRow = sheet.getRow( rowNum ); 83 82 84 for( def colNum = 0; colNum < excelRow.getLastCellNum(); colNum++ ) { 85 Cell c = excelRow.getCell( colNum ); 86 if( c ) { 87 if( c.getCellType() == Cell.CELL_TYPE_NUMERIC ) { 88 row << numberformat.format( c.getNumericCellValue() ); 83 if( !rowIsEmpty( excelRow ) ) { 84 ArrayList row = [] 85 86 for( def colNum = 0; colNum < excelRow.getLastCellNum(); colNum++ ) { 87 Cell c = excelRow.getCell( colNum ); 88 if( c ) { 89 if( c.getCellType() == Cell.CELL_TYPE_NUMERIC ) { 90 row << numberformat.format( c.getNumericCellValue() ); 91 } else { 92 row << df.formatCellValue( c ); 93 } 89 94 } else { 90 row << df.formatCellValue( c );95 row << "" 91 96 } 92 } else { 93 row << "" 97 94 98 } 95 99 100 data << row; 96 101 } 97 98 data << row;99 102 } 100 103 … … 200 203 } 201 204 205 206 /** 207 * Checks whether an excel row is empty 208 * @param row Row from the excel sheet 209 * @return True if all cells in this row are empty or the given row is null. False otherwise 210 */ 211 def rowIsEmpty( Row excelRow ) { 212 if( !excelRow ) 213 return true; 214 215 def df = new DataFormatter(); 216 for( int i = excelRow.getFirstCellNum(); i < excelRow.getLastCellNum(); i++ ) { 217 Cell cell = excelRow.getCell( i ); 218 219 try { 220 def value = df.formatCellValue(cell) 221 if( value ) 222 return false 223 } catch (NumberFormatException nfe) { 224 // If the number can't be formatted, the row isn't empty 225 return false; 226 } 227 } 228 229 return true; 230 } 231 232 202 233 /** 203 234 * Return the given workbook for download -
trunk/grails-app/services/nl/tno/metagenomics/files/FileService.groovy
r13 r20 110 110 def File get( String filename, File directory = null ) { 111 111 if( directory == null ) 112 directory = getUploadDir()112 directory = getUploadDir() 113 113 114 114 return new File( directory, filename ); … … 120 120 def boolean fileExists( String filename, File directory = null ) { 121 121 if( directory == null ) 122 directory = getUploadDir()122 directory = getUploadDir() 123 123 124 124 return new File( directory, filename ).exists(); … … 130 130 def boolean delete( String filename, File directory = null ) { 131 131 if( directory == null ) 132 directory = getUploadDir()132 directory = getUploadDir() 133 133 134 134 def f = new File( directory, filename ); … … 136 136 f.delete(); 137 137 } 138 139 return true; 140 } 141 142 def boolean copy( String filename, String newfilename, File directory = null ) { 143 if( directory == null ) 144 directory = getUploadDir() 145 146 def f = new File( directory, filename ); 147 def destination = new File( directory, newfilename ); 148 149 if( f.exists() && !destination.exists() ) { 150 def reader = f.newReader(); 151 destination.withWriter { writer -> 152 writer << reader 153 } 154 reader.close(); 155 } 156 157 return true; 138 158 } 139 159 -
trunk/grails-app/services/nl/tno/metagenomics/integration/TrashService.groovy
r9 r20 27 27 } 28 28 } 29 29 30 30 study.delete(flush:true); 31 31 } … … 185 185 // Move data from this assay sample to the trash version of it 186 186 assaySample.moveValuableDataTo( dummyAssaySample ); 187 188 // Remove the assaySample from its run, since otherwise the statistics of the run (#sequences for example) 189 // are not correct anymore and the assaySample will be resaved after delete 190 dummyAssaySample.run?.removeFromAssaySamples( dummyAssaySample ); 191 187 192 dummyAssaySample.save(); 193 } 194 } 195 196 // Remove all assaysamples from this assay from their run 197 assay.assaySamples?.each { assaySample -> 198 assaySample.run?.removeFromAssaySamples( assaySample ); 199 } 200 201 // Remove this assay from the runs, since otherwise the samples will be resaved upon delete 202 if( assay.runs ) { 203 def l = [] + assay.runs 204 l.each { 205 it.removeFromAssays( assay ); 188 206 } 189 207 } … … 232 250 // Move data from this assay sample to the trash version of it 233 251 assaySample.moveValuableDataTo( dummyAssaySample ); 252 253 // Remove the assaySample from its run, since otherwise the statistics of the run (#sequences for example) 254 // are not correct anymore 255 dummyAssaySample.run?.removeFromAssaySamples( dummyAssaySample ); 256 234 257 dummyAssaySample.save(); 235 258 } 259 } 260 261 // Remove all assaysamples from this assay from their run 262 sample.assaySamples?.each { assaySample -> 263 assaySample.run?.removeFromAssaySamples( assaySample ); 236 264 } 237 265 }
Note: See TracChangeset
for help on using the changeset viewer.