Changeset 302 for trunk


Ignore:
Timestamp:
Jan 27, 2010, 8:13:13 PM (15 years ago)
Author:
gav
Message:

Add exportAssetTreeTest function, add and ignore comment and example lines.

Location:
trunk/grails-app
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/AssetDetailedController.groovy

    r298 r302  
    4444        response.setHeader("Content-disposition", "attachment; filename=AssetTreeTemplate.csv")
    4545        def s = csvService.buildAssetTreeTemplate()
     46        render s
     47    }
     48
     49    def exportAssetTreeTest = {
     50        response.contentType = ConfigurationHolder.config.grails.mime.types["csv"]
     51        response.setHeader("Content-disposition", "attachment; filename=AssetTreeTestFile.csv")
     52        def s = csvService.buildAssetTreeTest()
    4653        render s
    4754    }
  • trunk/grails-app/services/CsvService.groovy

    r301 r302  
    111111
    112112                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."
    113127                    nextLine()
    114128                    continue
     
    223237
    224238            // Success.
     239            log.info "End of file."
    225240            reader.close()
    226241            return result
     
    239254        CSVWriter writer = new CSVWriter(sw)
    240255
     256        writeTemplateLines(writer)
     257
     258        writer.close()
     259        return sw.toString()
     260    }
     261
     262    private writeTemplateLines(writer) {
    241263        writer.writeNext(templateHeaderLine1 as String[])
    242264        writer.writeNext(templateHeaderLine2 as String[])
    243265        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[])
    245311
    246312        writer.close()
     
    259325
    260326        //Header
    261         def header = ["Site", "Section", "Asset", "Sub Asset", "Functional Assembly", "Sub Assembly Group"]
    262         writer.writeNext(header as String[])
     327        writer.writeNext(templateHeaderLine1 as String[])
     328        writer.writeNext(templateHeaderLine2 as String[])
    263329
    264330        //Rows
Note: See TracChangeset for help on using the changeset viewer.