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

Last change on this file since 392 was 392, checked in by keesvb, 11 years ago

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()

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