Changeset 302 for trunk/grails-app/services
- Timestamp:
- Jan 27, 2010, 8:13:13 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/CsvService.groovy
r301 r302 111 111 112 112 if(!nextColumn()) { 113 nextLine() 114 continue 115 } 116 117 // Ignore comment lines. 118 if( column.name.startsWith("Comment") ) { 119 log.info "Comment line found." 120 nextLine() 121 continue 122 } 123 124 // Ignore example lines. 125 if( column.name.startsWith("Example") ) { 126 log.info "Example line found." 113 127 nextLine() 114 128 continue … … 223 237 224 238 // Success. 239 log.info "End of file." 225 240 reader.close() 226 241 return result … … 239 254 CSVWriter writer = new CSVWriter(sw) 240 255 256 writeTemplateLines(writer) 257 258 writer.close() 259 return sw.toString() 260 } 261 262 private writeTemplateLines(writer) { 241 263 writer.writeNext(templateHeaderLine1 as String[]) 242 264 writer.writeNext(templateHeaderLine2 as String[]) 243 265 writer.writeNext() 244 writer.writeNext("Note: the header lines are required, start by replacing this line.") 266 writer.writeNext(["Example: Site1", "", "Department 1", "", "Section 1", "", "Asset 1", ""] as String[]) 267 writer.writeNext() 268 writer.writeNext(["Example: Site1", "", "Department 1", "", "Section 1", "", "Asset 2", ""] as String[]) 269 writer.writeNext() 270 writer.writeNext("Comment: the first two header lines are required.") 271 writer.writeNext("Comment: leave a blank line between assets.") 272 writer.writeNext("Comment: names are required, descriptions are optional.") 273 writer.writeNext("Comment: identical names in each column will be considered as the same item.") 274 writer.writeNext("Comment: any line starting with 'Comment' will be ignored.") 275 writer.writeNext("Comment: any line starting with 'Example' will be ignored.") 276 writer.writeNext("Comment: example and comment lines may be deleted.") 277 writer.writeNext() 278 } 279 280 /** 281 * Build an asset tree test file. 282 * This test file can be imported to test the import and template methods. 283 * @returns The test file as a String in csv format. 284 */ 285 def buildAssetTreeTest() { 286 287 StringWriter sw = new StringWriter() 288 CSVWriter writer = new CSVWriter(sw) 289 290 writeTemplateLines(writer) 291 292 writer.writeNext(["Lake Press", "Lake Press Site", 293 "Print Department", "The printing department", 294 "Press Section", "Contains all printing units", 295 "Print Unit 1", "Printing Unit Number 1", 296 "Print Unit", "Print Unit (Common to all units)", 297 "Print Couple", "Includes blanket cylinder", 298 "Motor", "Main Drive Motor", 299 "NDS Bearing", "Non Drive Side Main Bearing" 300 ] as String[]) 301 302 writer.writeNext(["Lake Press", "Lake Press Site", 303 "Print Department", "The printing department", 304 "Press Section", "Contains all printing units", 305 "Print Unit 1", "Printing Unit Number 1", 306 "Print Unit", "Print Unit (Common to all units)", 307 "Print Couple", "Includes blanket cylinder", 308 "Motor", "Main Drive Motor", 309 "DS Bearing", "Drive Side Main Bearing" 310 ] as String[]) 245 311 246 312 writer.close() … … 259 325 260 326 //Header 261 def header = ["Site", "Section", "Asset", "Sub Asset", "Functional Assembly", "Sub Assembly Group"]262 writer.writeNext( headeras String[])327 writer.writeNext(templateHeaderLine1 as String[]) 328 writer.writeNext(templateHeaderLine2 as String[]) 263 329 264 330 //Rows
Note: See TracChangeset
for help on using the changeset viewer.