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

Last change on this file since 359 was 359, checked in by duh, 11 years ago
  • set keyword expansion
  • Property svn:keywords set to Date Author Rev
File size: 1.9 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: 359 $
10 * $Author: duh $
11 * $Date: 2010-04-20 12:42:20 +0000 (di, 20 apr 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         * overloading the findAllByEntity method to make it function as expected
61         * @param       Class           entity (for example: dbnp.studycapturing.Subject)
62         * @return      ArrayList
63         */
64        public static findAllByEntity(java.lang.Class entity) {
65                def results = []
66                // 'this' should not work in static context, however it does so I'll keep
67                // this in for now :)
68                this.findAll().each() {
69                        if (entity.equals(it.entity)) {
70                                results[ results.size() ] = it
71                        }
72                }
73
74                return results
75        }
76}
Note: See TracBrowser for help on using the repository browser.