Ignore:
Timestamp:
May 4, 2010, 5:03:21 PM (9 years ago)
Author:
keesvb
Message:

switched back from the fancy 'integrate domain fields as system fields directly into the Template object at the time of creation' method to the plain 'implement getFieldValue, setFieldValue and giveFields to work for both domain and template fields'. NB: this might affect Events, since until now startTime and endTime were moved directly into template! Switch any Event.template.fields to Event.giveFields()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy

    r390 r392  
    1414abstract class TemplateEntity implements Serializable {
    1515        Template template
    16         static List systemFields
    1716        Map templateStringFields = [:]
    1817        Map templateTextFields = [:]
     
    253252
    254253        /**
    255          * Find a template field by its name and return its value for this entity
    256          * @param fieldName The name of the template field
     254         * Find a domain or template field by its name and return its value for this entity
     255         * @param fieldName The name of the domain or template field
    257256         * @return the value of the field (class depends on the field type)
    258257         * @throws NoSuchFieldException If the field is not found or the field type is not supported
    259258         */
    260259        def getFieldValue(String fieldName) {
    261                 TemplateFieldType fieldType = template.getFieldType(fieldName)
    262                 if (!fieldType) throw new NoSuchFieldException("Field name ${fieldName} not recognized")
    263                 getStore(fieldType)[fieldName]
     260                if (this.properties.containsKey(fieldName)) {
     261                        return this[fieldName]
     262                }
     263                else {
     264                        TemplateFieldType fieldType = template.getFieldType(fieldName)
     265                        if (!fieldType) throw new NoSuchFieldException("Field name ${fieldName} not recognized")
     266                        return getStore(fieldType)[fieldName]
     267                }
    264268        }
    265269
     
    375379
    376380        /**
     381        * Return all fields defined in the underlying template and the built-in
     382        * domain fields of this entity
     383        */
     384        def List<TemplateField> giveFields() {
     385                return this.giveDomainFields() + this.giveTemplateFields();
     386        }
     387
     388        /**
    377389        * Return all templated fields defined in the underlying template of this entity
    378390        */
    379         def List<TemplateField> giveFields() {
     391        def List<TemplateField> giveTemplateFields() {
    380392                return this.template.fields;
    381393        }
    382394
    383         def List<TemplateField> giveSystemFields() {
    384                 return systemFields;
    385         }
    386        
    387 
    388395        /**
    389396         * Return all relevant 'built-in' domain fields of the super class
    390          * @return key-value pairs describing the built-in fields, with the names as keys and type (as TemplateFieldType) as values
     397         * @return List with DomainTemplateFields
     398         * @see TemplateField
    391399         */
    392         abstract Map giveDomainFields()
     400        abstract List<TemplateField> giveDomainFields()
     401
    393402        /*def giveDomainFields() {
    394403                def fieldSet = [:];
Note: See TracChangeset for help on using the changeset viewer.