Ignore:
Timestamp:
Feb 25, 2010, 3:06:16 PM (7 years ago)
Author:
keesvb
Message:

refactored template entity code into TemplateEntity?, added more template field types, updated BootStrap? with some more details on PPSH, changed code in study overview to get template field contents in a nicer way

File:
1 edited

Legend:

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

    r190 r212  
    1111 * $Date$
    1212 */
    13 class Subject implements Serializable {
     13class Subject extends TemplateEntity implements Serializable {
    1414        static searchable = true
    1515        Template template
    1616        String name
    1717        Term species
    18         Map templateStringFields
    19         Map templateIntegerFields
    20         Map templateFloatFields
    21         Map templateTermFields
    22 
    23         static hasMany = [
    24                 templateStringFields: String, // stores both STRING and STRINGLIST items (latter should be checked against the list)
    25                 templateIntegerFields: int,
    26                 templateFloatFields: float,
    27                 templateTermFields: Term
    28         ]
    29 
    30         static constraints = {
    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         }
    55 
    56         def setFieldValue(String fieldName, value) {
    57                 this.properties.each { println it}
    58                 if (this.properties.containsKey(fieldName)) {
    59                         this[fieldName] = value
    60                 }
    61                 else if (templateStringFields.containsKey(fieldName) && value.class == String) {
    62                         this.templateStringFields[fieldName] = value
    63                 }
    64                 else {
    65                         println "Field ${fieldName} not found"
    66                 }
    67         }
    6818}
Note: See TracChangeset for help on using the changeset viewer.