Ignore:
Timestamp:
Mar 2, 2010, 6:10:52 PM (13 years ago)
Author:
keesvb
Message:

revised templating system: templates are now per entity rather than per study, moved samples to Study

Location:
trunk/grails-app/domain/dbnp/studycapturing
Files:
2 deleted
6 edited

Legend:

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

    r190 r224  
    99        static searchable = true
    1010
    11     // TODO: should Sample also carry a reference to its parent study,
    12     // or should this be inferred via the parent SamplingEvent?
     11
    1312
    1413    String name      // should be unique with respect to the parent study (which can be inferred)
    1514    Term material
    16     // don't we need a member that describes the quantity of the sample?
     15    // don't we need a member that describes the quantity of the sample? --> should be in the templates
    1716
    1817    static constraints = {
  • trunk/grails-app/domain/dbnp/studycapturing/Study.groovy

    r212 r224  
    2020        Date lastUpdated
    2121        Date startDate
    22         Template template
    2322
    2423        static hasMany = [
     
    2928                events: Event,
    3029                samplingEvents: SamplingEvent,
     30                samples: Sample,
    3131                assays: Assay,
    3232                persons: StudyPerson,
     
    5050        }
    5151
    52         def giveAllFields() {
    53                 return template.studyFields;
    54         }
    55 
    56         def giveSamples() {
    57                 return samplingEvents*.samples;
    58         }
    5952}
  • trunk/grails-app/domain/dbnp/studycapturing/Subject.groovy

    r212 r224  
    1313class Subject extends TemplateEntity implements Serializable {
    1414        static searchable = true
    15         Template template
    1615        String name
    1716        Term species
  • trunk/grails-app/domain/dbnp/studycapturing/Template.groovy

    r212 r224  
    1212 */
    1313class Template implements Serializable {
     14
    1415        String name
     16        Class entity
    1517        //nimble.User owner
    1618
    17         static hasMany = [studyFields: TemplateStudyField, subjectFields: TemplateSubjectField]
     19        static hasMany = [fields: TemplateField]
    1820
    1921        static constraints = {
    20                 name(unique: true)
     22                name(unique:['entity'])
     23
    2124        }
    2225
     
    3033         * @return The type (static member of TemplateFieldType) of the field, or null of the field does not exist
    3134         */
    32         def TemplateFieldType getSubjectFieldType(String fieldName) {
    33                 def field = subjectFields.find {
     35        def TemplateFieldType getFieldType(String fieldName) {
     36                def field = fields.find {
    3437                        it.name == fieldName   
    3538                }
    3639                field?.type
    3740        }
     41
     42        def getFieldsByType(TemplateFieldType fieldType) {
     43                def result = fields.findAll {
     44                        it.type == fieldType
     45                }
     46                return result;
     47        }
    3848}
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy

    r212 r224  
    22
    33import dbnp.data.Term
     4import org.codehaus.groovy.runtime.NullObject
    45
    56class TemplateEntity {
    67
     8        Template template
     9
    710        Map templateStringFields
     11        Map templateStringListFields
    812        Map templateIntegerFields
    913        Map templateFloatFields
     
    1317
    1418        static hasMany = [
    15                 templateStringFields: String, // stores both STRING and STRINGLIST items (latter should be checked against the list)
     19                templateStringFields: String,
     20                templateStringListFields: TemplateFieldListItem,
    1621                templateIntegerFields: int,
    1722                templateFloatFields: float,
     
    3136         */
    3237        def getFieldValue(String fieldName) {
    33                 TemplateFieldType fieldType = template.getSubjectFieldType(fieldName)
     38                TemplateFieldType fieldType = template.getFieldType(fieldName)
    3439                if (!fieldType) throw new NoSuchFieldException("Field name ${fieldName} not recognized")
    3540                switch(fieldType) {
    3641                        case [TemplateFieldType.STRING, TemplateFieldType.STRINGLIST]:
    3742                                return templateStringFields[fieldName]
     43                        case [TemplateFieldType.STRINGLIST]:
     44                                return templateStringListFields[fieldName]
    3845                        case TemplateFieldType.INTEGER:
    3946                                return templateIntegerFields[fieldName]
     
    5259
    5360        def setFieldValue(String fieldName, value) {
    54                 this.properties.each { println it}
    5561                if (this.properties.containsKey(fieldName)) {
    5662                        this[fieldName] = value
    5763                }
    58                 else if (templateStringFields.containsKey(fieldName) && value.class == String) {
    59                         this.templateStringFields[fieldName] = value
    60                 }
    61                 else if (templateIntegerFields.containsKey(fieldName) && value.class == Integer) {
    62                         this.templateIntegerFields[fieldName] = value
    63                 }
    64                 else if (templateFloatFields.containsKey(fieldName) && value.class == Float) {
    65                         this.templateFloatFields[fieldName] = value
    66                 }
    67                 else if (templateDoubleFields.containsKey(fieldName) && value.class == Double) {
    68                         this.templateDoubleFields[fieldName] = value
    69                 }
    70                 else if (templateDateFields.containsKey(fieldName) && value.class == Date) {
    71                         this.templateDateFields[fieldName] = value
    72                 }
    73                 else if (templateTermFields.containsKey(fieldName) && value.class == Term) {
    74                         this.templateTermFields[fieldName] = value
     64                else
     65                if (template == null) {
     66                        throw new NoSuchFieldException("Field ${fieldName} not found in class properties")
    7567                }
    7668                else {
    77                         println "Field ${fieldName} not found"
     69                        if (templateStringFields.containsKey(fieldName) && value.class == String) {
     70                                this.templateStringFields[fieldName] = value
     71                        }
     72                        if (templateStringListFields.containsKey(fieldName) && value.class == TemplateFieldListItem) {
     73                                this.templateStringFields[fieldName] = value
     74                        }
     75                        else if (templateIntegerFields.containsKey(fieldName) && value.class == Integer) {
     76                                this.templateIntegerFields[fieldName] = value
     77                        }
     78                        else if (templateFloatFields.containsKey(fieldName) && value.class == Float) {
     79                                this.templateFloatFields[fieldName] = value
     80                        }
     81                        else if (templateDoubleFields.containsKey(fieldName) && value.class == Double) {
     82                                this.templateDoubleFields[fieldName] = value
     83                        }
     84                        else if (templateDateFields.containsKey(fieldName) && value.class == Date) {
     85                                this.templateDateFields[fieldName] = value
     86                        }
     87                        else if (templateTermFields.containsKey(fieldName) && value.class == Term) {
     88                                this.templateTermFields[fieldName] = value
     89                        }
     90                        else {
     91                                throw new NoSuchFieldException("Field ${fieldName} not found in class properties or template fields")
     92                        }
    7893                }
    7994        }
    8095
     96        def Set<TemplateField> giveFields() {
     97                return this.template.fields;
     98        }
     99
     100        @Override
     101        void setTemplate(Template newTemplate) {
     102
     103                // Contrary to expectation, this method does not cause an infinite loop but calls the super method
     104                // whereas super.setTemplate(newTemplate) leads to errors concerning NullObject values
     105                this.template = newTemplate
     106
     107                // TODO: initialize all template fields with the necessary keys and null values
     108
     109                println "Setting template " + newTemplate
     110                /*if (template == null || template instanceof NullObject) {} else{ // negation doesn't seem to work well
     111                        def stringFields = template.getFieldsByType(TemplateFieldType.STRINGLIST)
     112                        println stringFields*.name
     113                        if (stringFields.size() > 0) {
     114                                templateStringFields = new HashMap<String,String>()
     115                                templateStringFields.keyset.add stringFields*.name;
     116                                println templateStringFields
     117                        }
     118                }*/
     119        }
     120
    81121}
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateField.groovy

    r190 r224  
    99 * $Date$
    1010 */
    11 abstract class TemplateField implements Serializable {
     11class TemplateField implements Serializable {
    1212        String name
    1313        TemplateFieldType type
     
    1515
    1616    static hasMany = [listEntries : String] // to store the entries to choose from when the type is 'item from predefined list'
     17        //TODO: make TemplateFieldListItem and make a convenience setter for a string array
    1718
    1819        static constraints = {
Note: See TracChangeset for help on using the changeset viewer.