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

Last change on this file since 397 was 397, checked in by duh, 9 years ago
  • reformatted source code
  • added mega huge big ASCII comments to UNDOCUMMENTED of not properly DOCUMENTED classess... we have agreed many many MANY times that everyone should document their code according to JavaDoc? style... but why does nobody do it, or just keep SLACKING! /annoyed modus
  • 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: 397 $
10 * $Author: duh $
11 * $Date: 2010-05-07 12:53:11 +0000 (vr, 07 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                // outcommented for now due to bug in Grails / Hibernate
22                // see http://jira.codehaus.org/browse/GRAILS-6020
23                //      name(unique:['entity'])
24        }
25
26        /**
27         * overloaded toString method
28         * @return String
29         */
30        def String toString() {
31                return this.name;
32        }
33
34        /**
35         * Look up the type of a certain template subject field
36         * @param       String  fieldName The name of the template field
37         * @return      String  The type (static member of TemplateFieldType) of the field, or null of the field does not exist
38         */
39        def TemplateFieldType getFieldType(String fieldName) {
40                def field = fields.find {
41                        it.name == fieldName   
42                }
43                field?.type
44        }
45
46        /**
47         * get all field of a particular type
48         * @param       Class   fieldType
49         * @return      Set<TemplateField>
50         */
51        def getFieldsByType(TemplateFieldType fieldType) {
52                def result = fields.findAll {
53                        it.type == fieldType
54                }
55                return result;
56        }
57
58        /**
59         * get all required fields
60         * @param       Class   fieldType
61         * @return      Set<TemplateField>
62         */
63        def getRequiredFields() {
64                def result = fields.findAll {
65                        it.required == true
66                }
67                return result;
68        }
69
70        /**
71         * overloading the findAllByEntity method to make it function as expected
72         * @param       Class           entity (for example: dbnp.studycapturing.Subject)
73         * @return      ArrayList
74         */
75        public static findAllByEntity(java.lang.Class entity) {
76                def results = []
77                // 'this' should not work in static context, so taking Template instead of this
78                Template.findAll().each() {
79                        if (entity.equals(it.entity)) {
80                                results[ results.size() ] = it
81                        }
82                }
83
84                return results
85        }
86}
Note: See TracBrowser for help on using the repository browser.