source: trunk/grails-app/domain/dbnp/studycapturing/Template.groovy @ 421

Last change on this file since 421 was 421, checked in by keesvb, 9 years ago

cleaned up BootStrap? and re-added Samples, updated study/show to also show sampling events in EventGroups?, added description field for Templates

  • Property svn:keywords set to Date Author Rev
File size: 2.1 KB
Line 
1package dbnp.studycapturing
2
3/**
4 * The Template class describes a study template, which is basically an extension of the study capture entities
5 * in terms of extra fields (described by classes that extend the TemplateField class).
6 * At this moment, only extension of the study and subject entities is implemented.
7 *
8 * Revision information:
9 * $Rev: 421 $
10 * $Author: keesvb $
11 * $Date: 2010-05-17 13:26:48 +0000 (ma, 17 mei 2010) $
12 */
13class Template implements Serializable {
14        String name
15        String description
16        Class entity
17        //nimble.User owner
18        List fields
19        static hasMany = [fields: TemplateField]
20
21        static constraints = {
22                description(nullable: true, blank: true)
23                // outcommented for now due to bug in Grails / Hibernate
24                // see http://jira.codehaus.org/browse/GRAILS-6020
25                //      name(unique:['entity'])
26        }
27
28        /**
29         * overloaded toString method
30         * @return String
31         */
32        def String toString() {
33                return this.name;
34        }
35
36        /**
37         * Look up the type of a certain template subject field
38         * @param       String  fieldName The name of the template field
39         * @return      String  The type (static member of TemplateFieldType) of the field, or null of the field does not exist
40         */
41        def TemplateFieldType getFieldType(String fieldName) {
42                def field = fields.find {
43                        it.name == fieldName   
44                }
45                field?.type
46        }
47
48        /**
49         * get all field of a particular type
50         * @param       Class   fieldType
51         * @return      Set<TemplateField>
52         */
53        def getFieldsByType(TemplateFieldType fieldType) {
54                def result = fields.findAll {
55                        it.type == fieldType
56                }
57                return result;
58        }
59
60        /**
61         * get all required fields
62         * @param       Class   fieldType
63         * @return      Set<TemplateField>
64         */
65        def getRequiredFields() {
66                def result = fields.findAll {
67                        it.required == true
68                }
69                return result;
70        }
71
72        /**
73         * overloading the findAllByEntity method to make it function as expected
74         * @param       Class           entity (for example: dbnp.studycapturing.Subject)
75         * @return      ArrayList
76         */
77        public static findAllByEntity(java.lang.Class entity) {
78                def results = []
79                // 'this' should not work in static context, so taking Template instead of this
80                Template.findAll().each() {
81                        if (entity.equals(it.entity)) {
82                                results[ results.size() ] = it
83                        }
84                }
85
86                return results
87        }
88}
Note: See TracBrowser for help on using the repository browser.