Ignore:
Timestamp:
Mar 3, 2010, 12:17:06 PM (13 years ago)
Author:
keesvb
Message:

study template convenience methods

Location:
trunk/grails-app/domain/dbnp/studycapturing
Files:
3 edited

Legend:

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

    r224 r228  
    5050        }
    5151
     52        /**
     53         * Returns the template of all subjects in the study
     54         * Throws an error if there are no or multiple subject templates
     55         */
     56        def Template giveSubjectTemplate() {
     57                TemplateEntity.giveTemplate(subjects);
     58        }
     59
     60        /**
     61         * Returns the template of all samples in the study
     62         * Throws an error if there are no or multiple sample templates
     63         */
     64        def Template giveSampleTemplate() {
     65                TemplateEntity.giveTemplate(samples);
     66        }
     67        /**
     68         * Returns the template of the study
     69         */
     70        def Template giveStudyTemplate() {
     71                return this.template;
     72        }
    5273}
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy

    r224 r228  
    2727
    2828        static constraints = {
     29                template(nullable: true)
    2930        }
    3031
     
    7172                        }
    7273                        if (templateStringListFields.containsKey(fieldName) && value.class == TemplateFieldListItem) {
     74                                // TODO: check if item really belongs to the list under fieldName
    7375                                this.templateStringFields[fieldName] = value
    7476                        }
     
    119121        }
    120122
     123        /**
     124         * Convenience method. Returns all unique templates within a collection of TemplateEntities.
     125         */
     126        static List<Template> giveTemplates(Set<TemplateEntity> entityCollection) {
     127                return entityCollection*.template.unique();
     128        }
     129
     130        static Template giveTemplate(Set<TemplateEntity> entityCollection) {
     131                def templates = giveTemplates(entityCollection);
     132                if (templates.size() == 0) {
     133                        throw new NoSuchFieldException("No templates found in collection!")
     134                }
     135                else if (templates.size() == 1) {
     136                        return templates[0];
     137                }
     138                else {
     139                        throw new NoSuchFieldException("Multiple templates found in collection!")
     140                }
     141        }
     142
    121143}
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateFieldListItem.groovy

    r225 r228  
    77        static constraints = {
    88        }
     9
     10        String toString() {
     11                return name;
     12        }
    913}
Note: See TracChangeset for help on using the changeset viewer.