Changeset 803 for trunk/grails-app/domain
- Timestamp:
- Aug 12, 2010, 12:41:10 PM (11 years ago)
- Location:
- trunk/grails-app/domain/dbnp/studycapturing
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/SamplingEvent.groovy
r784 r803 9 9 */ 10 10 class SamplingEvent extends TemplateEntity { 11 12 11 // A SamplingEvent always belongs to one study. 13 12 // Although this is technically inherited from Event, we have to specify it here again. … … 15 14 // where it is actually referenced in Study.samplingEvents 16 15 static belongsTo = [parent : Study] 17 18 16 static hasMany = [samples : Sample] 19 17 … … 24 22 long duration 25 23 24 // define what template samples should have 25 Template sampleTemplate 26 27 // define domain constraints 26 28 static constraints = { 27 29 duration(default: 0L) 30 sampleTemplate(nullable: false, blank: false) 28 31 } 29 32 … … 43 46 name: 'duration', 44 47 type: TemplateFieldType.RELTIME, 45 comment: "Please enter the duration of the sampling action, if applicable. "+RelTime.getHelpText()) 48 comment: "Please enter the duration of the sampling action, if applicable. "+RelTime.getHelpText()), 49 new TemplateField( 50 name: 'sampleTemplate', 51 type: TemplateFieldType.TEMPLATE, 52 entity: dbnp.studycapturing.Sample, 53 comment: "Please select the template of the resulting samples") 46 54 ] 47 48 /**49 * Get the duration of the event as RelTime50 * @return RelTime51 */52 /*RelTime getDuration() {53 return new RelTime(duration)54 }*/55 55 56 56 /** … … 60 60 def getStartTimeString() { 61 61 return new RelTime(startTime).toPrettyString(); 62 }63 64 /**65 * Get extended, human readable string representing the duration between startTime and endTime66 *67 * @return String68 */69 def getDurationString() {70 return new RelTime(duration).toPrettyString();71 62 } 72 63 … … 90 81 /** 91 82 * Get all samples that have this sampling event as a parent 83 * @return Map 92 84 */ 93 85 def getSamples() { 94 95 86 def samples = Sample.findAll("from Sample as s where s.parentEvent.id = ${this.id}") 96 87 samples.collect { it.class == SamplingEvent.class } … … 98 89 return samples == null ? [] : samples 99 90 } 100 101 91 } -
trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy
r785 r803 22 22 23 23 // Maps for storing the different template field values 24 Map templateStringFields = [:] 25 Map templateTextFields = [:] 26 Map templateStringListFields = [:] 27 Map templateIntegerFields = [:] 28 Map templateFloatFields = [:] 29 Map templateDoubleFields = [:] 30 Map templateDateFields = [:] 31 Map templateBooleanFields = [:] 24 Map templateStringFields = [:] 25 Map templateTextFields = [:] 26 Map templateStringListFields= [:] 27 Map templateIntegerFields = [:] 28 Map templateFloatFields = [:] 29 Map templateDoubleFields = [:] 30 Map templateDateFields = [:] 31 Map templateBooleanFields = [:] 32 Map templateTemplateFields = [:] 32 33 33 34 // N.B. If you try to set Long.MIN_VALUE for a reltime field, an error will occur 34 35 // However, this will never occur in practice: this value represents 3 bilion centuries 35 Map templateRelTimeFields 36 Map templateFileFields 37 Map templateTermFields 36 Map templateRelTimeFields = [:] // Contains relative times in seconds 37 Map templateFileFields = [:] // Contains filenames 38 Map templateTermFields = [:] 38 39 39 40 // define relationships … … 50 51 templateFileFields: String, 51 52 templateBooleanFields: boolean, 53 templateTemplateFields: Template, 52 54 systemFields: TemplateField 53 55 ] … … 301 303 errors.rejectValue( 302 304 'templateFileFields', 303 'templateEntity.typeMismatch. string',305 'templateEntity.typeMismatch.file', 304 306 [key, value.class] as Object[], 305 307 'Property {0} must be of type String and is currently of type {1}' … … 310 312 311 313 // got an error, or not? 314 return (!error) 315 }) 316 templateTemplateFields(validator: { fields, obj, errors -> 317 def error = false 318 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 = true 325 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 } 312 334 return (!error) 313 335 }) … … 356 378 case TemplateFieldType.BOOLEAN: 357 379 return templateBooleanFields 380 case TemplateFieldType.TEMPLATE: 381 return templateTemplateFields 358 382 default: 359 383 throw new NoSuchFieldException("Field type ${fieldType} not recognized") … … 559 583 } 560 584 585 // Magic setter for template fields 586 if (field.type == TemplateFieldType.TEMPLATE && value && value.class == String) { 587 value = Template.findByName(value) 588 } 589 561 590 // Set the field value 562 591 if (isDomainField(field)) { 563 592 // got a value? 564 593 if (value) { 565 //debug message: println ".setting [" + ((super) ? super.class : '??') + "] domain field: [" + fieldName + "] ([" + value.toString() + "] of type [" + value.class + "])" 566 567 // set value 594 println ".setting [" + ((super) ? super.class : '??') + "] ("+getIdentifier()+") domain field: [" + fieldName + "] ([" + value.toString() + "] of type [" + value.class + "])" 568 595 this[field.name] = value 569 596 } else { 570 //debug message: println ".unsetting [" + ((super) ? super.class : '??') + "]domain field: [" + fieldName + "]"597 println ".unsetting [" + ((super) ? super.class : '??') + "] ("+getIdentifier()+") domain field: [" + fieldName + "]" 571 598 572 599 // remove value. For numbers, this is done by setting … … 688 715 } 689 716 } 690 691 717 } -
trunk/grails-app/domain/dbnp/studycapturing/TemplateField.groovy
r784 r803 53 53 54 54 static constraints = { 55 56 55 // outcommented for now due to bug in Grails / Hibernate 57 56 // see http://jira.codehaus.org/browse/GRAILS-6020 … … 129 128 return elements.size(); 130 129 } 131 132 133 130 } -
trunk/grails-app/domain/dbnp/studycapturing/TemplateFieldType.groovy
r784 r803 19 19 RELTIME('Relative time'), // relative date, e.g. days since start of study 20 20 FILE('File'), 21 BOOLEAN('Boolean') 21 BOOLEAN('Boolean'), 22 TEMPLATE('Template') 22 23 // TODO: add a timezone-aware date type to use for study start date 23 24 … … 29 30 30 31 static list() { 31 [STRING, TEXT, INTEGER, FLOAT, DOUBLE, STRINGLIST, ONTOLOGYTERM, DATE, RELTIME, FILE, BOOLEAN ]32 [STRING, TEXT, INTEGER, FLOAT, DOUBLE, STRINGLIST, ONTOLOGYTERM, DATE, RELTIME, FILE, BOOLEAN, TEMPLATE] 32 33 } 33 34 … … 54 55 case BOOLEAN: 55 56 return false; 57 case TEMPLATE: 58 return null; 56 59 default: 57 60 throw new NoSuchFieldException("Field type ${fieldType} not recognized")
Note: See TracChangeset
for help on using the changeset viewer.