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

Clarified error messages related to unreachable module; added functionality to export numbers using comma as decimal separator and made this the default for european csv style export

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/dbnp/studycapturing/AssayService.groovy

    r1828 r1830  
    1818import org.codehaus.groovy.grails.web.json.JSONObject 
    1919import org.dbnp.gdt.RelTime 
    20 import org.dbnp.gdt.TemplateFieldType; 
     20import org.dbnp.gdt.TemplateFieldType 
     21import java.text.DecimalFormat 
     22import java.text.NumberFormat 
    2123 
    2224class AssayService { 
     
    244246                def moduleUrl = assay.module.url 
    245247 
    246                 def path = moduleUrl + "/rest/getMeasurements/query?assayToken=$assay.assayUUID" 
    247  
    248                 def jsonArray = moduleCommunicationService.callModuleRestMethodJSON(moduleUrl, path) 
     248                def path = moduleUrl + "/rest/getMeasurements/query" 
     249        def query = "assayToken=$assay.assayUUID" 
     250        def jsonArray 
     251 
     252        try { 
     253            jsonArray = moduleCommunicationService.callModuleMethod(moduleUrl, path, query) 
     254        } catch (e) { 
     255            throw new Exception("An error occured while trying to get the measurement tokens from the $assay.module.name. \ 
     256             This means the module containing the measurement data is not available right now. Please try again \ 
     257             later or notify the system administrator if the problem persists. URL: $path?$query.") 
     258        } 
    249259 
    250260                jsonArray.collect { 
     
    275285                } 
    276286 
    277                 def path = moduleUrl + "/rest/getMeasurementData/query?assayToken=$assay.assayUUID" + tokenString 
    278  
    279                 def (sampleTokens, measurementTokens, moduleData) = moduleCommunicationService.callModuleRestMethodJSON(moduleUrl, path) 
     287                def path = moduleUrl + "/rest/getMeasurementData/query" 
     288 
     289        def query = "assayToken=$assay.assayUUID$tokenString" 
     290 
     291                def sampleTokens = [], measurementTokens = [], moduleData = [] 
     292 
     293        try { 
     294            (sampleTokens, measurementTokens, moduleData) = moduleCommunicationService.callModuleMethod(moduleUrl, path, query) 
     295        } catch (e) { 
     296            throw new Exception("An error occured while trying to get the measurement data from the $assay.module.name. \ 
     297             This means the module containing the measurement data is not available right now. Please try again \ 
     298             later or notify the system administrator if the problem persists. URL: $path?$query.") 
     299        } 
    280300 
    281301                if (!sampleTokens?.size()) return [] 
     
    307327                                                measurements << null 
    308328                                        }  else { 
    309                                                 measurements << ( moduleData[ valueIndex ] == JSONObject.NULL ? "" : moduleData[ valueIndex ].toString() ); 
     329                                                measurements << ( moduleData[ valueIndex ] == JSONObject.NULL ? "" : moduleData[ valueIndex ].toDouble() ); 
    310330                                        } 
    311331                                } else { 
     
    520540         * @return 
    521541         */ 
    522         def exportRowWiseDataToCSVFile(rowData, outputStream, outputDelimiter = '\t') { 
     542        def exportRowWiseDataToCSVFile(rowData, outputStream, outputDelimiter = '\t', locale = java.util.Locale.US) { 
     543 
     544        def formatter = NumberFormat.getNumberInstance(locale) 
     545        formatter.setGroupingUsed false // we don't want grouping (thousands) separators 
    523546 
    524547        outputStream << rowData.collect { row -> 
    525548          row.collect{ 
    526549 
    527               // omit quotes in case of numeric values 
    528               if (it instanceof Number) return it 
     550              // omit quotes in case of numeric values and format using chosen locale 
     551              if (it instanceof Number) return formatter.format(it) 
    529552 
    530553              def s = it?.toString() ?: ''