source: trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy @ 215

Last change on this file since 215 was 215, checked in by tabma, 10 years ago
  • added Template chooser, used in the properties page
  • Property svn:keywords set to
    Date
    Author
    Rev
File size: 2.2 KB
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: 215 $
17 * $Author: tabma $
18 * $Date: 2010-02-26 11:26:29 +0000 (vr, 26 feb 2010) $
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 to the columns and continues to the next step (assigning properties to columns)
60    *
61    * @param entity list of entities
62    * @return properties page
63    */
64    def savepreview = { 
65        def entities  = request.getParameterValues("entity")
66
67        // currently only one template is used for all entities
68        // TODO: show template fields per entity
69       
70        def templates = Template.get(session.importtemplate_id)
71
72        render(view:"step2", model:[entities:entities, header:session.header, templates:templates])
73    }
74}
Note: See TracBrowser for help on using the repository browser.