Changeset 340


Ignore:
Timestamp:
Feb 9, 2010, 10:28:15 PM (14 years ago)
Author:
gav
Message:

Small adjustment to CsvService asset tree import, to handle blank description on last column correctly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/CsvService.groovy

    r327 r340  
    4242
    4343            def columnIndex = 0
     44            def nameColumnIndex = 0
    4445            def numberOfColumns = 0
    4546            def maxNumberOfColumns = 20
     
    9192
    9293            def nextColumn = {
    93                 if( (columnIndex+2) > numberOfColumns ) {
     94                nameColumnIndex = columnIndex
     95
     96                if( (columnIndex+1) < numberOfColumns ) {
     97                    // Capitalise and assign the name and description columns.
     98                    use(WordUtils) {
     99                    column.name = line[columnIndex].trim().capitalize()
     100                    column.description = line[++columnIndex].trim().capitalize()
     101                    }
     102                }
     103                else if( columnIndex < numberOfColumns ) {
     104                    // Capitalise and assign the name column with a blank description.
     105                    use(WordUtils) {
     106                    column.name = line[columnIndex].trim().capitalize()
     107                    column.description = ''
     108                    }
     109                }
     110                else {
    94111                    log.info "No more columns on line: " + lineNumber
    95112                    return false
    96113                }
    97                 if(!line[columnIndex]) {
    98                     log.info "No name at " + "line: " + lineNumber + " col: " + columnIndex
     114
     115                if(!column.name) {
     116                    log.info "No name at " + "line: " + lineNumber + " col: " + nameColumnIndex
    99117                    return false
    100118                }
    101                 // Capitalise and assign the name and description columns.
    102                 use(WordUtils) {
    103                 column.name = line[columnIndex].trim().capitalize()
    104                 column.description = line[++columnIndex].trim().capitalize()
    105                 }
     119
    106120                columnIndex++
    107121                // Success.
Note: See TracChangeset for help on using the changeset viewer.