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

Last change on this file since 247 was 247, checked in by duh, 13 years ago
  • set keyword expansion
  • Property svn:keywords set to Author Rev Date
File size: 1.7 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: 247 $
10 * $Author: duh $
11 * $Date: 2010-03-08 17:29:14 +0000 (ma, 08 mrt 2010) $
12 */
13class Template implements Serializable {
14        String name
15        Class entity
16        //nimble.User owner
17
18        static hasMany = [fields: TemplateField]
19
20        static constraints = {
21                name(unique:['entity'])
22        }
23
24        /**
25         * overloaded toString method
26         * @return String
27         */
28        def String toString() {
29                return this.name;
30        }
31
32        /**
33         * Look up the type of a certain template subject field
34         * @param       String  fieldName The name of the template field
35         * @return      String  The type (static member of TemplateFieldType) of the field, or null of the field does not exist
36         */
37        def TemplateFieldType getFieldType(String fieldName) {
38                def field = fields.find {
39                        it.name == fieldName   
40                }
41                field?.type
42        }
43
44        /**
45         * get all field of a particular type
46         * @param       Class   fieldType
47         * @return      Set<TemplateField>
48         */
49        def getFieldsByType(TemplateFieldType fieldType) {
50                def result = fields.findAll {
51                        it.type == fieldType
52                }
53                return result;
54        }
55
56        /**
57         * overloading the findAllByEntity method to make it function as expected
58         * @param       Class           entity (for example: dbnp.studycapturing.Subject)
59         * @return      ArrayList
60         */
61        public static findAllByEntity(java.lang.Class entity) {
62                def results = []
63
64                // 'this' should not work in static context, however it does so I'll keep
65                // this in for now :)
66                this.findAll().each() {
67                        if (entity.equals(it.entity)) {
68                                results[ results.size() ] = it
69                        }
70                }
71
72                return results
73        }
74}
Note: See TracBrowser for help on using the repository browser.