source: trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy @ 283

Last change on this file since 283 was 283, checked in by tabma, 11 years ago
  • final step in the wizard, implemented method in the ImporterService? to persist the entities into the database
  • Property svn:keywords set to Author Rev Date
File size: 4.7 KB
Line 
1/**
2 * Importer tag library
3 *
4 * The importer tag library gives support for automating several 'components'
5 *
6 * @package     importer
7 * @author      t.w.abma@umcutrecht.nl
8 * @since       20100202
9 *
10 * Revision information:
11 * $Rev: 283 $
12 * $Author: tabma $
13 * $Date: 2010-03-18 09:17:02 +0000 (do, 18 mrt 2010) $
14 */
15
16package dbnp.importer
17import dbnp.studycapturing.Template
18import dbnp.studycapturing.TemplateFieldType
19
20class ImporterTagLib {
21    static namespace = 'importer'
22    def standardentities = [[type:-1, name:"Don't import"], [type:0, name:"Study"], [type:1, name:"Subject"], [type:2, name:"Event"],
23                        [type:3, name:"Protocol"], [type:4, name:"Sample"]]
24
25    /**
26    * @param header string array containing header
27    * @param datamatrix two dimensional array containing actual data
28    * @return preview of the data with the ability to adjust the datatypes
29    */
30    def preview = { attrs ->
31       
32        def header = attrs['header']
33        def datamatrix = attrs['datamatrix']
34
35        out << render (template:"common/preview", model:[header:header, datamatrix:datamatrix])
36    }
37
38    /**
39     * @param datamatrix two dimensional array containing entities with read values
40     * @return postview of the imported data
41     */
42    def postview = { attrs ->
43        def datamatrix = attrs['datamatrix']
44
45        out << render (template:"common/postview", model:[datamatrix:datamatrix])
46    }
47
48    def entity = { attrs ->
49        out << entities[attrs['index']].name
50    }
51
52    /**
53     * @param entities array in the format of columnindex:entitytype format
54     */
55    def properties = { attrs ->
56        def selectedentities = []
57        def header = attrs['header']
58
59        attrs['entities'].each { se ->
60            def temp = se.split(":")
61            def entity = [type:temp[1],columnindex:temp[0]]
62            selectedentities.add(entity)
63        }
64
65        out << render (template:"common/properties", model:[selectedentities:selectedentities, standardentities:standardentities, header:header])
66    }
67
68    /**
69     * Possibly this will later on return an AJAX-like autocompletion chooser for the fields?
70     *
71     * @param importtemplate_id template identifier where fields are retrieved from
72     * @param columnindex column in the header we're talking about
73     * @return chooser object
74     * */
75    def propertyChooser = { attrs ->
76        // TODO: this should be changed to retrieving fields per entity
77        def t = Template.get(session.importtemplate_id)
78        def columnindex = attrs['columnindex']
79
80        switch (attrs['entitytype']) {
81            case 0  : createPropertySelect(attrs['name'], t.fields, columnindex)
82                      break
83            case 1  : break
84            case 2  : break
85            case 3  : break
86            default : out << createPropertySelect(attrs['name'], t.fields, columnindex)
87                     break
88        }
89    }
90
91    /**
92     * @param name name of the HTML select object
93     * @param options list of options to be used
94     * @param columnIndex column identifier (corresponding to position in header of the Excel sheet)
95     * @return HTML select object
96     */
97    def createPropertySelect(String name, options, String columnIndex)
98    {
99        def res = "<select style=\"font-size:10px\" name=\"${name}\">"
100
101        options.each { f ->
102            res += "<option value=\"${columnIndex}:${f.id}\""
103            //res += (e.type.toInteger() == selected) ? " selected" : ""
104            res += ">${f}</option>"
105        }
106
107        res += "</select>"
108        return res
109    }
110
111    /**
112    * @param selected selected TemplateFieldType
113    * @param custval custom value to be combined in the option(s) of the selector
114    * @param name name of the HTML select object
115    * @return HTML select object
116    *
117    * @see dbnp.studycapturing.TemplateFieldType
118    */
119
120     def entitySelect = { attrs ->
121        def sel = (attrs['selected']==null) ? -1 : attrs['selected']
122        def custval = (attrs['customvalue']==null) ? "" : attrs['customvalue']
123        def name = (attrs['name']==null) ? -1 : attrs['name']
124
125        def res = "<select style=\"font-size:10px\" name=\"${name}\">"
126
127        standardentities.each { e ->
128            res += "<option value=\"${custval}:${e.type}\""
129            res += (e.type == sel) ? " selected" : ""
130            res += ">${e.name}</option>"
131        }
132
133        res += "</select>"
134        out << res
135    }
136
137    /**
138    * @param selected selected TemplateFieldType
139    * @param customvalue custom value to be combined in the option(s) of the selector
140    * @param name name of the HTML select object
141    * @return HTML select object
142    *
143    * @see dbnp.studycapturing.TemplateFieldType
144    */
145    def templatefieldtypeSelect = { attrs ->
146        def selected = (attrs['selected']==null) ? -1 : attrs['selected']
147        def customvalue = (attrs['customvalue']==null) ? "" : attrs['customvalue']
148        def name = (attrs['name']==null) ? "" : attrs['name']   
149
150        def res = "<select style=\"font-size:10px\" name=\"${name}\">"
151
152        TemplateFieldType.list().each { e ->
153            res += "<option value=\"${customvalue}:${e}\""
154            res += (e == selected) ? " selected" : ""
155            res += ">${e}</option>"
156        }
157
158        res += "</select>"
159
160        out << res
161    }
162}
Note: See TracBrowser for help on using the repository browser.