- Timestamp:
- May 27, 2010, 1:13:50 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy
r450 r485 30 30 import dbnp.studycapturing.TemplateField 31 31 import grails.converters.JSON 32 import org.apache.poi.hssf.usermodel.HSSFWorkbook 32 33 33 34 class ImporterController { … … 53 54 * @param importfile uploaded file to import 54 55 */ 55 def upload = { 56 def downloadedfile = request.getFile('importfile'); 56 def upload_advanced = { 57 def wb = handleUpload('importfile') 58 59 session.importer_header = ImporterService.getHeader(wb, 0) 60 session.importer_template_id = params.template_id 61 session.importer_workbook = wb 62 63 render (view:"step1_advanced", model:[header:session.importer_header, datamatrix:ImporterService.getDatamatrix(wb, 0, 5)]) 64 } 65 66 /** 67 * This method will move the uploaded file to a temporary path and send the header 68 * and the rows to the postview 69 * 70 * @param importfile uploaded file to import 71 * @param entity string representation of the entity chosen 72 */ 73 def upload_simple = { 74 def wb = handleUpload('importfile') 75 def entity = grailsApplication.config.gscf.domain.importableEntities.get(params.entity).entity 76 def entityClass = Class.forName(entity, true, this.getClass().getClassLoader()) 77 78 session.importer_header = ImporterService.getHeader(wb, 0, entityClass) 79 session.importer_template_id = params.template_id 80 session.importer_workbook = wb 81 82 //import workbook 83 //session.importer_importeddata = ImporterService.importdata(session.importer_template_id, session.importer_workbook, 0, 1, session.importer_header) 84 85 //println "DAS" + session.importer_header 86 87 //render(view:"step2_simple", model:[datamatrix:session.importer_importeddata]) 88 def templates = Template.get(session.importer_template_id) 89 90 render(view:"step2", model:[entities:entities, header:session.importer_header, templates:templates]) 91 } 92 93 /** 94 * This method handles a file being uploaded and storing it in a temporary directory 95 * and returning a workbook 96 * 97 * @param formfilename name used for the file field in the form 98 * @return workbook object reference 99 */ 100 private HSSFWorkbook handleUpload(formfilename) { 101 102 def downloadedfile = request.getFile(formfilename); 57 103 def tempfile = new File(System.getProperty('java.io.tmpdir') + File.separatorChar + System.currentTimeMillis() + ".nmcdsp") 58 104 downloadedfile.transferTo(tempfile) 59 60 def wb = ImporterService.getWorkbook(new FileInputStream(tempfile)) 61 62 def header = ImporterService.getHeader(wb, 0) 63 def datamatrix= ImporterService.getDatamatrix(wb, 0, 5) 64 65 session.importer_header = header 66 session.importer_template_id = params.template_id 67 session.importer_workbook = wb 68 69 render (view:"step1", model:[header:header, datamatrix:datamatrix]) 105 106 return ImporterService.getWorkbook(new FileInputStream(tempfile)) 70 107 } 71 108 … … 74 111 * All information of the columns is stored in a session as MappingColumn object 75 112 * 76 * @param entit y list of entities and columns it has been assigned to (columnindex:entitytype format)113 * @param entities list of entities and columns it has been assigned to (columnindex.entitytype) 77 114 * @param templatefieldtype list of celltypes and columns it has been assigned to (columnindex:templatefieldtype format) 78 115 * @return properties page … … 83 120 def tft = null 84 121 def identifiercolumnindex = (params.identifier!=null) ? params.identifier.toInteger() : -1 122 def selectedentities = [] 123 124 // loop all entities and see which column has been assigned which entitytype 125 // and build an array containing the selected entities 126 params.entity.index.each { columnindex, entityname -> 127 def _entity = [name:entityname,columnindex:columnindex.toInteger()] 128 selectedentities.add(_entity) 129 } 85 130 86 131 params.templatefieldtype.index.each { columnindex, _templatefieldtype -> … … 108 153 } 109 154 110 params.entity.index.each { columnindex, entity type ->155 params.entity.index.each { columnindex, entityname -> 111 156 Class clazz 112 157 113 switch (entity type.toInteger()) {114 case 0: clazz = Study115 break 116 case 1: clazz = Subject117 break 118 case 2: clazz = Event119 break 120 case 3: clazz = Protocol121 break 122 case 4: clazz = Sample158 switch (entityname) { 159 case "Study" : clazz = Study 160 break 161 case "Subject" : clazz = Subject 162 break 163 case "Event" : clazz = Event 164 break 165 case "Protocol" : clazz = Protocol 166 break 167 case "Sample" : clazz = Sample 123 168 break 124 169 default: clazz = Object … … 136 181 def templates = Template.get(session.importer_template_id) 137 182 138 render(view:"step2", model:[entities: params.entity, header:session.importer_header, templates:templates])183 render(view:"step2", model:[entities:selectedentities, header:session.importer_header, templates:templates]) 139 184 } 140 185
Note: See TracChangeset
for help on using the changeset viewer.