Changeset 290 for trunk/grails-app/domain
- Timestamp:
- Mar 22, 2010, 11:38:25 AM (13 years ago)
- Location:
- trunk/grails-app/domain/dbnp/studycapturing
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy
r257 r290 70 70 71 71 /** 72 * Find a template field by its name and return its value for this subject73 * @param fieldName The name of the template subjectfield72 * Find a template field by its name and return its value for this entity 73 * @param fieldName The name of the template field 74 74 * @return the value of the field (class depends on the field type) 75 75 * @throws NoSuchFieldException If the field is not found or the field type is not supported … … 81 81 } 82 82 83 /** 84 * Set a template/entity field value 85 * @param fieldName The name of the template or entity field 86 * @param value The value to be set, this should align with the (template) field type, but there are some convenience setters 87 * 88 */ 83 89 def setFieldValue(String fieldName, value) { 90 91 // First, search if there is an entity property with the given name, and if so, set that 84 92 if (this.properties.containsKey(fieldName)) { 85 93 this[fieldName] = value 86 94 } 87 else88 if (template == null) {89 throw new NoSuchFieldException("Field ${fieldName} not found in class properties ")95 // If not the found, then it is a template field, so check if there is a template 96 else if (template == null) { 97 throw new NoSuchFieldException("Field ${fieldName} not found in class properties: template not set") 90 98 } 99 // If there is a template, check the template fields 91 100 else { 101 // Find the target template field, if not found, throw an error 92 102 TemplateField field = this.template.fields.find { it.name == fieldName} 93 103 if (field == null) { 94 104 throw new NoSuchFieldException("Field ${fieldName} not found in class properties or template fields") 95 105 } 106 // Set the value of the found template field 96 107 else { 108 // Convenience setter for template string list fields: find TemplateFieldListItem by name 97 109 if (field.type == TemplateFieldType.STRINGLIST && value.class == String) { 98 // Convenience setter: find template item by name99 110 value = field.listEntries.find { it.name == value } 100 111 } 101 112 102 // handle string values for date fields113 // Convenience setter for dates: handle string values for date fields 103 114 if (field.type == TemplateFieldType.DATE && value.class == String) { 104 115 // a string was given, attempt to transform it into a date instance … … 119 130 } 120 131 121 // Caution: this assumes that all template...Field Maps are already initialized 122 // Otherwise, the results are pretty much unpredictable! 132 // Set the field value 133 // Caution: this assumes that all template...Field Maps are already initialized (as is done now above as [:]) 134 // If that is ever changed, the results are pretty much unpredictable (random Java object pointers?)! 123 135 getStore(field.type)[fieldName] = value 124 136 return this -
trunk/grails-app/domain/dbnp/studycapturing/TemplateField.groovy
r247 r290 13 13 TemplateFieldType type 14 14 String unit 15 String comment // help string for the user interface 15 16 16 17 static hasMany = [listEntries : TemplateFieldListItem] // to store the entries to choose from when the type is 'item from predefined list' … … 19 20 name(unique: true) 20 21 unit(nullable: true, blank: true) 22 comment(nullable:true, blank: true) 23 } 24 25 static mapping = { 26 comment type: 'text' 21 27 } 22 28
Note: See TracChangeset
for help on using the changeset viewer.