root/trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy @ 245

Revision 245, 3.3 KB (checked in by tabma, 4 years ago)

- columnmapping added

  • Property svn:keywords set to
    Date
    Author
    Rev
Line 
1/**
2 * Importer controller
3 *
4 * The importer controller handles the uploading of tabular, comma delimited and Excel format
5 * based files. When uploaded a preview is shown of the data and the user can adjust the column
6 * type. Data in cells which don't correspond to the specified column type will be represented as "#error".
7 *
8 * The importer controller catches the actions and consecutively performs the
9 * logic behind it.
10 *
11 * @package     importer
12 * @author      t.w.abma@umcutrecht.nl
13 * @since       20100126
14 *
15 * Revision information:
16 * $Rev$
17 * $Author$
18 * $Date$
19 */
20
21package dbnp.importer
22import org.apache.poi.hssf.usermodel.HSSFCell
23import org.apache.poi.ss.usermodel.DataFormatter
24import dbnp.studycapturing.Template
25
26class ImporterController {
27    def ImporterService
28
29    /**
30     * Default page
31     **/
32    def index = {
33        [templates:Template.list()]
34    }
35
36    /**
37    * This method will move the uploaded file to a temporary path and send the header
38    * and the first n rows to the preview
39    * @param importfile uploaded file to import
40    */
41    def upload = {
42        def downloadedfile = request.getFile('importfile');
43        def tempfile = new File(System.getProperty('java.io.tmpdir') + File.separatorChar + System.currentTimeMillis() + ".nmcdsp")
44        downloadedfile.transferTo(tempfile)
45       
46        def wb = ImporterService.getWorkbook(new FileInputStream(tempfile))
47       
48        def header = ImporterService.getHeader(wb, 0)
49        def datamatrix= ImporterService.getDatamatrix(wb, 0, 5)
50
51        session.header = header
52        session.importtemplate_id = params.template_id
53
54        render (view:"step1", model:[header:header, datamatrix:datamatrix])
55
56    }
57
58    /**
59    * User has assigned all entities and celltypes to the columns and continues to the next step (assigning properties to columns)
60    *
61    * @param entity list of entities and columns it has been assigned to (columnindex:entitytype format)
62    * @param celltype list of celltypes and columns it has been assigned to (columnindex:celltype format)
63    * @return properties page
64    */
65    def savepreview = {
66        def entities  = request.getParameterValues("entity")
67        def celltypes = request.getParameterValues("celltype")
68
69        celltypes.each { c ->
70            def temp = c.split(":")
71           
72            session.header[temp[0].toInteger()].celltype =  temp[1].toInteger()
73        }
74
75        entities.each { e ->
76            def temp = e.split(":")
77            Class clazz
78            switch (temp[1]) {
79                case 0: clazz = Study
80                        break
81                case 1: clazz = Subject
82                        break
83                case 2: clazz = Event
84                        break
85                case 3: clazz = Protocol
86                        break
87                case 4: clazz = Sample
88                        break
89                default: clazz = String
90            }
91            session.header[temp[0].toInteger()].entity = clazz
92        }
93
94        // currently only one template is used for all entities
95        // TODO: show template fields per entity
96       
97        def templates = Template.get(session.importtemplate_id)
98
99        render(view:"step2", model:[entities:entities, header:session.header, templates:templates])
100    }
101
102    /**
103    * @param columnproperty array of columns and the assigned property in `column:property_id` format
104    *
105    */
106    def saveproperties = {
107
108        /*def columnproperties  = request.getParameterValues("columnproperty")
109        columnproperties.each { cp ->
110                def temp = cp.split(":")
111                session.header[temp[0]]
112        }*/
113        for (e in session.header) {
114            println e
115        }
116        render ("properties saved")
117    }
118}
Note: See TracBrowser for help on using the browser.