Changeset 1828

Show
Ignore:
Timestamp:
10-05-11 11:36:53 (3 years ago)
Author:
s.h.sikkema@…
Message:

Fixed only being able to export to tab delimited; fixed 'null' values in export; fixed extra period between filename and extension

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/studycapturing/AssayController.groovy

    r1827 r1828  
    220220 
    221221        switch(session.exportFileType) { 
    222             case 2: // Comma delimited csv 
     222            case '2': // Comma delimited csv 
    223223                outputDelimiter = ',' 
    224                 outputFileExtension = '.csv' 
     224                outputFileExtension = 'csv' 
    225225                break 
    226             case 3: // Semicolon delimited csv 
     226            case '3': // Semicolon delimited csv 
    227227                outputDelimiter = ';' 
    228                 outputFileExtension = '.csv' 
     228                outputFileExtension = 'csv' 
    229229                break 
    230230            default: // Tab delimited with .txt extension 
    231231                outputDelimiter = '\t' 
    232                 outputFileExtension = '.txt' 
     232                outputFileExtension = 'txt' 
    233233        } 
    234234 
  • trunk/grails-app/services/dbnp/studycapturing/AssayService.groovy

    r1827 r1828  
    528528              if (it instanceof Number) return it 
    529529 
    530               def s = it.toString() 
     530              def s = it?.toString() ?: '' 
    531531 
    532532              def addQuotes = false 
  • trunk/test/unit/dbnp/studycapturing/AssayServiceTests.groovy

    r1827 r1828  
    270270        // - other strings and numbers should remain 'quoteless' 
    271271        // - is the custom delimiter (e.g. tab, comma, semicolon) correctly handled 
     272        // - null values are exported as empty strings 
    272273 
    273274        def rowData = [["""a 
    274 b""","a,b","a\"b", "abc"],[1,2.0,"3,1"]] 
     275b""","a,b","a\"b", "abc"],[1,2.0,"3,1"],[null,2]] 
    275276 
    276277        def baos = new ByteArrayOutputStream() 
    277278 
    278279        service.exportRowWiseDataToCSVFile rowData, baos, '\t' 
    279         assertEquals 'CSV Output', '"a\nb"\t"a,b"\t"a""b"\tabc\n1\t2.0\t"3,1"', baos.toString() 
     280        assertEquals 'CSV Output', '"a\nb"\t"a,b"\t"a""b"\tabc\n1\t2.0\t"3,1"\n\t2', baos.toString() 
    280281 
    281282        baos.reset() 
    282283 
    283284        service.exportRowWiseDataToCSVFile rowData, baos, ',' 
    284         assertEquals 'CSV Output', '"a\nb","a,b","a""b",abc\n1,2.0,"3,1"', baos.toString() 
     285        assertEquals 'CSV Output', '"a\nb","a,b","a""b",abc\n1,2.0,"3,1"\n,2', baos.toString() 
    285286 
    286287        baos.reset() 
    287288 
    288289        service.exportRowWiseDataToCSVFile rowData, baos, ';' 
    289         assertEquals 'CSV Output', '"a\nb";"a,b";"a""b";abc\n1;2.0;"3,1"', baos.toString() 
     290        assertEquals 'CSV Output', '"a\nb";"a,b";"a""b";abc\n1;2.0;"3,1"\n;2', baos.toString() 
    290291 
    291292