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

Last change on this file since 203 was 203, checked in by tabma, 10 years ago
  • rewrote to HashMap? based columns (columns are always unique, storing in array tricky/redundancy)
  • entities can be chosen in the preview
  • properties page shows columns grouped per entity
  • properties page allows mapping of column to property (TODO: get all fields per entity)
  • Property svn:keywords set to
    Date
    Author
    Rev
File size: 1.7 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: 203 $
17 * $Author: tabma $
18 * $Date: 2010-02-18 07:10:35 +0000 (do, 18 feb 2010) $
19 */
20
21package dbnp.importer
22import org.apache.poi.hssf.usermodel.HSSFCell
23import org.apache.poi.ss.usermodel.DataFormatter
24
25class ImporterController {
26    def ImporterService
27
28    /**
29     * Default page
30     **/
31    def index = { }
32
33    /**
34    * This method will move the uploaded file to a temporary path and send the header
35    * and the first n rows to the preview
36    * @param importfile uploaded file to import
37    */
38    def upload = {
39        def downloadedfile = request.getFile('importfile');
40        def tempfile = new File(System.getProperty('java.io.tmpdir') + File.separatorChar + System.currentTimeMillis() + ".nmcdsp")
41        downloadedfile.transferTo(tempfile)
42       
43        def wb = ImporterService.getWorkbook(new FileInputStream(tempfile))
44       
45        def header = ImporterService.getHeader(wb, 0)
46        def datamatrix= ImporterService.getDatamatrix(wb, 0, 5)
47
48        session.header = header
49
50        render (view:"step1", model:[header:header, datamatrix:datamatrix])
51
52    }
53
54    def savepreview = { 
55        def entities  = request.getParameterValues("entity")
56
57        render(view:"step2", model:[entities:entities, header:session.header])
58    }
59}
Note: See TracBrowser for help on using the repository browser.