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

Last change on this file since 269 was 269, checked in by keesvb, 13 years ago

upgraded to webflow plugin 1.2.1, added templates to BootStrap?, changed some code to get list_extended back up but it's still not working

  • Property svn:keywords set to Author Rev Date
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: 269 $
10 * $Author: keesvb $
11 * $Date: 2010-03-15 21:40:37 +0000 (ma, 15 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
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                println "Searching for" + entity
67                // 'this' should not work in static context, however it does so I'll keep
68                // this in for now :)
69                this.findAll().each() {
70                        if (entity.equals(it.entity)) {
71                                results[ results.size() ] = it
72                        }
73                }
74
75                return results
76        }
77}
Note: See TracBrowser for help on using the repository browser.