Changeset 1153 for trunk/grails-app/domain
- Timestamp:
- Nov 17, 2010, 11:34:09 AM (10 years ago)
- Location:
- trunk/grails-app/domain/dbnp/studycapturing
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy
r1111 r1153 25 25 Map templateTextFields = [:] 26 26 Map templateStringListFields = [:] 27 Map templateIntegerFields = [:]28 Map templateFloatFields = [:]29 27 Map templateDoubleFields = [:] 30 28 Map templateDateFields = [:] … … 45 43 templateTextFields : String, 46 44 templateStringListFields: TemplateFieldListItem, 47 templateIntegerFields : int,48 templateFloatFields : float,49 45 templateDoubleFields : double, 50 46 templateDateFields : Date, … … 148 144 error = true 149 145 errors.rejectValue( 150 'template IntegerFields',146 'templateStringFields', 151 147 'templateEntity.typeMismatch.templateFieldListItem', 152 148 [key, value.class] as Object[], … … 158 154 return (!error) 159 155 }) 160 templateIntegerFields(validator: { fields, obj, errors ->161 def error = false162 fields.each { key, value ->163 if (value && value.class != Integer) {164 try {165 fields[key] = (value as Integer)166 } catch (Exception e) {167 error = true168 errors.rejectValue(169 'templateIntegerFields',170 'templateEntity.typeMismatch.integer',171 [key, value.class] as Object[],172 'Property {0} must be of type Integer and is currently of type {1}'173 )174 }175 }176 }177 return (!error)178 })179 templateFloatFields(validator: { fields, obj, errors ->180 def error = false181 fields.each { key, value ->182 if (value && value.class != Float) {183 try {184 fields[key] = (value as Float)185 } catch (Exception e) {186 error = true187 errors.rejectValue(188 'templateFloatFields',189 'templateEntity.typeMismatch.float',190 [key, value.class] as Object[],191 'Property {0} must be of type Float and is currently of type {1}'192 )193 }194 }195 }196 return (!error)197 })198 156 templateDoubleFields(validator: { fields, obj, errors -> 199 157 def error = false 200 158 fields.each { key, value -> 159 // Double field should accept Doubles and Floats 201 160 if (value && value.class != Double) { 202 try { 203 fields[key] = (value as Double) 204 } catch (Exception e) { 205 error = true 206 errors.rejectValue( 207 'templateDoubleFields', 208 'templateEntity.typeMismatch.double', 209 [key, value.class] as Object[], 210 'Property {0} must be of type Double and is currently of type {1}' 211 ) 161 if(value.class == Float) { 162 fields[key] = value.toDouble(); 163 } else { 164 try { 165 fields[key] = (value as Double) 166 } catch (Exception e) { 167 error = true 168 errors.rejectValue( 169 'templateDoubleFields', 170 'templateEntity.typeMismatch.double', 171 [key, value.class] as Object[], 172 'Property {0} must be of type Double and is currently of type {1}' 173 ) 174 } 212 175 } 213 176 } … … 370 333 def error = false 371 334 fields.each { key, value -> 372 if (value && value.class != Long) { 373 try { 374 fields[key] = Long.parseLong(value.trim()) 375 } catch (Exception e) { 376 error = true 377 errors.rejectValue( 378 'templateLongFields', 379 'templateEntity.typeMismatch.long', 380 [key, value.class] as Object[], 381 'Property {0} must be of type Long and is currently of type {1}' 382 ) 335 // Long field should accept Longs and Integers 336 if (value && value.class != Long ) { 337 if( value.class == Integer ) { 338 fields[key] = value.toLong(); 339 } else { 340 try { 341 fields[key] = Long.parseLong(value.trim()) 342 } catch (Exception e) { 343 error = true 344 errors.rejectValue( 345 'templateLongFields', 346 'templateEntity.typeMismatch.long', 347 [key, value.class] as Object[], 348 'Property {0} must be of type Long and is currently of type {1}' 349 ) 350 } 383 351 } 384 352 } … … 403 371 case TemplateFieldType.STRINGLIST: 404 372 return templateStringListFields 405 case TemplateFieldType.INTEGER:406 return templateIntegerFields407 373 case TemplateFieldType.DATE: 408 374 return templateDateFields … … 411 377 case TemplateFieldType.FILE: 412 378 return templateFileFields 413 case TemplateFieldType.FLOAT:414 return templateFloatFields415 379 case TemplateFieldType.DOUBLE: 416 380 return templateDoubleFields … … 645 609 // Magic setter for LONG fields 646 610 if (field.type == TemplateFieldType.LONG && value && value.class == String) { 647 // TODO, check for invalids? 648 value = Long.parseLong(value.trim()) 611 // A check for invalidity is done in the validator of these fields. For that 612 // reason, we just try to parse it here. If it fails, the validator will also 613 // fail. 614 try { 615 value = Long.parseLong(value.trim()) 616 } catch( Exception e ) {} 649 617 } 650 618 … … 661 629 // the value to 0, otherwise, setting it to NULL 662 630 switch (field.type.toString()) { 663 case [ 'INTEGER', 'FLOAT','DOUBLE', 'RELTIME', 'LONG']:631 case [ 'DOUBLE', 'RELTIME', 'LONG']: 664 632 this[field.name] = 0; 665 633 break; -
trunk/grails-app/domain/dbnp/studycapturing/TemplateFieldType.groovy
r1056 r1153 10 10 */ 11 11 public enum TemplateFieldType implements Serializable { 12 STRING('String','Text', ' '), // string13 TEXT('Long string', 'Text', ' '), // text14 INTEGER('Integer number', 'Numerical', '1'), // integer15 FLOAT('Floating-point number', 'Numerical', '1.0'), // float16 DOUBLE(' Double precision floating-point number', 'Numerical', '1.0'),// double12 STRING('String','Text', 'max 255 chars'), // string 13 TEXT('Long string', 'Text', 'unlimited'), // text 14 //INTEGER('Integer number', 'Numerical', '1'), // integer 15 //FLOAT('Floating-point number', 'Numerical', '1.0'), // float 16 DOUBLE('Floating point number', 'Numerical', '1.0'), // double 17 17 STRINGLIST('List of items', 'Text', ''), // string list 18 18 ONTOLOGYTERM('Ontology Reference', 'Other', ''), // ontology reference … … 23 23 TEMPLATE('Template', 'Other', ''), // template 24 24 MODULE('Module', 'Other', ''), // third party connected module, 25 LONG(' Long number', 'Numerical', '100')// long25 LONG('Integer number', 'Numerical', '100') // long 26 26 // TODO: add a timezone-aware date type to use for study start date 27 27 … … 40 40 41 41 static list() { 42 [STRING, TEXT, INTEGER, FLOAT,DOUBLE, STRINGLIST, ONTOLOGYTERM, DATE, RELTIME, FILE, BOOLEAN, TEMPLATE, MODULE, LONG]42 [STRING, TEXT, DOUBLE, STRINGLIST, ONTOLOGYTERM, DATE, RELTIME, FILE, BOOLEAN, TEMPLATE, MODULE, LONG] 43 43 } 44 44 … … 47 47 case [STRING, TEXT]: 48 48 return "" 49 case INTEGER:50 return Integer.MIN_VALUE51 case FLOAT:52 return Float.NaN53 49 case DOUBLE: 54 50 return Double.MIN_VALUE
Note: See TracChangeset
for help on using the changeset viewer.