Changeset 146 for trunk/grails-app/domain
- Timestamp:
- Jan 28, 2010, 6:42:30 PM (13 years ago)
- Location:
- trunk/grails-app/domain/dbnp/studycapturing
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/Subject.groovy
r145 r146 13 13 class Subject implements Serializable { 14 14 static searchable = true 15 Template template 15 16 String name 16 17 Term species … … 29 30 static constraints = { 30 31 } 32 33 /** 34 * Find a template field by its name and return its value for this subject 35 * @param fieldName The name of the template subject field 36 * @return the value of the field (class depends on the field type) 37 * @throws NoSuchFieldException If the field is not found or the field type is not supported 38 */ 39 def getFieldValue(String fieldName) { 40 TemplateFieldType fieldType = template.getSubjectFieldType(fieldName) 41 if (!fieldType) throw new NoSuchFieldException("Field name ${fieldName} not recognized") 42 switch(fieldType) { 43 case [TemplateFieldType.STRING, TemplateFieldType.STRINGLIST]: 44 return templateStringFields[fieldName] 45 case TemplateFieldType.INTEGER: 46 return templateIntegerFields[fieldName] 47 case TemplateFieldType.FLOAT: 48 return templateFloatFields[fieldName] 49 case TemplateFieldType.ONTOLOGYTERM: 50 return templateTermFields[fieldName] 51 default: 52 throw new NoSuchFieldException("Field type ${fieldType} not recognized") 53 } 54 } 31 55 } -
trunk/grails-app/domain/dbnp/studycapturing/Template.groovy
r140 r146 12 12 */ 13 13 class Template implements Serializable { 14 15 14 String name 15 //nimble.User owner 16 16 17 static hasMany = [subjectFields : TemplateSubjectField] 18 19 static constraints = { 20 name(unique:true) 21 } 17 static hasMany = [subjectFields: TemplateSubjectField] 22 18 23 def String toString() { 24 return this.name; 25 } 19 static constraints = { 20 name(unique: true) 21 } 22 23 def String toString() { 24 return this.name; 25 } 26 27 /** 28 * Look up the type of a certain template subject field 29 * @param fieldName The name of the template field 30 * @return The type (static member of TemplateFieldType) of the field, or null of the field does not exist 31 */ 32 def TemplateFieldType getSubjectFieldType(String fieldName) { 33 def field = subjectFields.find { 34 it.name == fieldName 35 } 36 field?.type 37 } 26 38 }
Note: See TracChangeset
for help on using the changeset viewer.