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

Last change on this file since 182 was 182, checked in by keesvb, 9 years ago

small change to importer to avoid cross-platform issues (now works under Windows as well)

  • Property svn:keywords set to
    Date
    Author
    Rev
File size: 1.6 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: 182 $
17 * $Author: keesvb $
18 * $Date: 2010-02-09 15:21:01 +0000 (di, 09 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.pathSeparator + 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        render (view:"step1", model:[header:header, datamatrix:datamatrix])
49
50    }
51
52    def accept = {
53       
54    }
55}
Note: See TracBrowser for help on using the repository browser.