Changeset 825 for trunk/grails-app/domain
- Timestamp:
- Aug 17, 2010, 6:22:24 PM (10 years ago)
- Location:
- trunk/grails-app/domain/dbnp/studycapturing
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/Assay.groovy
r784 r825 6 6 * this data can be found. 7 7 */ 8 class Assay extends Identity { 9 10 /** The name of the assay, which should indicate the measurements represented in this assay to the user. */ 8 class Assay extends TemplateEntity { 9 // The name of the assay, which should indicate the measurements represented in this assay to the user. 11 10 String name 12 11 13 / **The dbNP module in which the assay omics data can be found. */12 // The dbNP module in which the assay omics data can be found. */ 14 13 AssayModule module 15 14 15 // The assay ID which is used in the dbNP submodule which contains the actual omics data of this assay. 16 // This ID is generated in GSCF, but is used in the submodules to refer to this particular Assay. 17 long externalAssayID 18 16 19 /** 17 The assay ID which is used in the dbNP submodule which contains the actual omics data of this assay.18 This ID is generated in GSCF, but is used in the submodules to refer to this particular Assay.20 * return the domain fields for this domain class 21 * @return List 19 22 */ 20 long externalAssayID 23 static List<TemplateField> giveDomainFields() { return Assay.domainFields } 24 static List<TemplateField> domainFields = [ 25 new TemplateField( 26 name: 'name', 27 type: TemplateFieldType.STRING, 28 preferredIdentifier: true, 29 required: true 30 ), 31 new TemplateField( 32 name: 'module', 33 type: TemplateFieldType.MODULE 34 35 ), 36 new TemplateField( 37 name: 'externalAssayID', 38 type: TemplateFieldType.LONG 39 ) 40 ] 21 41 22 42 // An Assay always belongs to one study. -
trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy
r803 r825 31 31 Map templateBooleanFields = [:] 32 32 Map templateTemplateFields = [:] 33 Map templateModuleFields = [:] 34 Map templateLongFields = [:] 33 35 34 36 // N.B. If you try to set Long.MIN_VALUE for a reltime field, an error will occur … … 40 42 // define relationships 41 43 static hasMany = [ 42 templateStringFields : String,43 templateTextFields : String,44 templateStringFields : String, 45 templateTextFields : String, 44 46 templateStringListFields: TemplateFieldListItem, 45 templateIntegerFields: int, 46 templateFloatFields: float, 47 templateDoubleFields: double, 48 templateDateFields: Date, 49 templateTermFields: Term, 50 templateRelTimeFields: long, 51 templateFileFields: String, 52 templateBooleanFields: boolean, 53 templateTemplateFields: Template, 54 systemFields: TemplateField 47 templateIntegerFields : int, 48 templateFloatFields : float, 49 templateDoubleFields : double, 50 templateDateFields : Date, 51 templateTermFields : Term, 52 templateRelTimeFields : long, 53 templateFileFields : String, 54 templateBooleanFields : boolean, 55 templateTemplateFields : Template, 56 templateModuleFields : AssayModule, 57 templateLongFields : long, 58 systemFields : TemplateField 55 59 ] 56 60 … … 314 318 return (!error) 315 319 }) 316 templateTemplateFields(validator: { fields, obj, errors ->317 def error = false318 fields.each { key, value ->319 if (value && value.class != Template) {320 try {321 fields[key] = (value as Template)322 323 } catch (Exception e) {324 error = true325 errors.rejectValue(326 'templateTemplateFields',327 'templateEntity.typeMismatch.template',328 [key, value.class] as Object[],329 'Property {0} must be of type Template and is currently of type {1}'330 )331 }332 }333 }334 return (!error)335 })336 320 templateBooleanFields(validator: { fields, obj, errors -> 337 321 def error = false … … 341 325 } else { 342 326 fields[key] = false; 327 } 328 } 329 return (!error) 330 }) 331 templateTemplateFields(validator: { fields, obj, errors -> 332 def error = false 333 fields.each { key, value -> 334 if (value && value.class != Template) { 335 try { 336 fields[key] = (value as Template) 337 } catch (Exception e) { 338 error = true 339 errors.rejectValue( 340 'templateTemplateFields', 341 'templateEntity.typeMismatch.template', 342 [key, value.class] as Object[], 343 'Property {0} must be of type Template and is currently of type {1}' 344 ) 345 } 346 } 347 } 348 return (!error) 349 }) 350 templateModuleFields(validator: { fields, obj, errors -> 351 def error = false 352 fields.each { key, value -> 353 if (value && value.class != AssayModule) { 354 try { 355 fields[key] = (value as AssayModule) 356 } catch (Exception e) { 357 error = true 358 errors.rejectValue( 359 'templateModuleFields', 360 'templateEntity.typeMismatch.module', 361 [key, value.class] as Object[], 362 'Property {0} must be of type AssayModule and is currently of type {1}' 363 ) 364 } 365 } 366 } 367 return (!error) 368 }) 369 templateLongFields(validator: { fields, obj, errors -> 370 def error = false 371 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 ) 383 } 343 384 } 344 385 } … … 380 421 case TemplateFieldType.TEMPLATE: 381 422 return templateTemplateFields 423 case TemplateFieldType.MODULE: 424 return templateModuleFields 425 case TemplateFieldType.LONG: 426 return templateLongFields 382 427 default: 383 428 throw new NoSuchFieldException("Field type ${fieldType} not recognized") … … 583 628 } 584 629 585 // Magic setter for templatefields630 // Magic setter for TEMPLATE fields 586 631 if (field.type == TemplateFieldType.TEMPLATE && value && value.class == String) { 587 632 value = Template.findByName(value) 633 } 634 635 // Magic setter for MODULE fields 636 if (field.type == TemplateFieldType.MODULE && value && value.class == String) { 637 value = AssayModule.findByName(value) 638 } 639 640 // Magic setter for LONG fields 641 if (field.type == TemplateFieldType.LONG && value && value.class == String) { 642 // TODO, check for invalids? 643 value = Long.parseLong(value.trim()) 588 644 } 589 645 … … 600 656 // the value to 0, otherwise, setting it to NULL 601 657 switch (field.type.toString()) { 602 case ['INTEGER', 'FLOAT', 'DOUBLE', 'RELTIME' ]:658 case ['INTEGER', 'FLOAT', 'DOUBLE', 'RELTIME', 'LONG']: 603 659 this[field.name] = 0; 604 660 break; -
trunk/grails-app/domain/dbnp/studycapturing/TemplateFieldType.groovy
r803 r825 3 3 /** 4 4 * Enum describing the type of a TemplateField. 5 * 5 6 * Revision information: 6 7 * $Rev$ … … 9 10 */ 10 11 public enum TemplateFieldType implements Serializable { 11 STRING('String'), 12 TEXT('Long string'), 13 INTEGER('Integer number'), 14 FLOAT('Floating-point number'), 15 DOUBLE('Double precision floating-point number'), 16 STRINGLIST('List of items'), 17 ONTOLOGYTERM('Ontology Reference'), 18 DATE('Date'), 19 RELTIME('Relative time'), // relative date, e.g. days since start of study 20 FILE('File'), 21 BOOLEAN('Boolean'), 22 TEMPLATE('Template') 12 STRING('String'), // string 13 TEXT('Long string'), // text 14 INTEGER('Integer number'), // integer 15 FLOAT('Floating-point number'), // float 16 DOUBLE('Double precision floating-point number'), // double 17 STRINGLIST('List of items'), // string list 18 ONTOLOGYTERM('Ontology Reference'), // ontology reference 19 DATE('Date'), // date 20 RELTIME('Relative time'), // relative date, e.g. days since start of study 21 FILE('File'), // file 22 BOOLEAN('Boolean'), // boolean 23 TEMPLATE('Template'), // template 24 MODULE('Module'), // third party connected module, 25 LONG('Long number') // long 23 26 // TODO: add a timezone-aware date type to use for study start date 24 27 … … 30 33 31 34 static list() { 32 [STRING, TEXT, INTEGER, FLOAT, DOUBLE, STRINGLIST, ONTOLOGYTERM, DATE, RELTIME, FILE, BOOLEAN, TEMPLATE ]35 [STRING, TEXT, INTEGER, FLOAT, DOUBLE, STRINGLIST, ONTOLOGYTERM, DATE, RELTIME, FILE, BOOLEAN, TEMPLATE, MODULE, LONG] 33 36 } 34 37 … … 54 57 return "" 55 58 case BOOLEAN: 56 return false ;59 return false 57 60 case TEMPLATE: 58 return null; 61 return null 62 case MODULE: 63 return null 64 case LONG: 65 return Long.MIN_VALUE 59 66 default: 60 67 throw new NoSuchFieldException("Field type ${fieldType} not recognized")
Note: See TracChangeset
for help on using the changeset viewer.