- Timestamp:
- May 27, 2010, 1:13:50 PM (11 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 deleted
- 8 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/Config.groovy
r444 r485 7 7 * Revision information: 8 8 * $Rev$ 9 * $Author :$9 * $Author$ 10 10 * $Date$ 11 11 */ … … 143 143 // @see ImporterController 144 144 importableEntities: [ 145 study : [name: 'Study', entity: 'dbnp.studycapturing.Study'], 146 subject : [name: 'Subject', entity: 'dbnp.studycapturing.Subject'], 147 sample : [name: 'Sample', entity: 'dbnp.studycapturing.Sample'] 145 none : [name: 'None', entity:'', type:-1], 146 event : [name: 'Event', entity:'dbnp.studycapturing.Event', type:2], 147 protocol: [name: 'Protocol', entity:'dbnp.studycapturing.Protocol', type:3], 148 sample : [name: 'Sample', entity: 'dbnp.studycapturing.Sample', type:4], 149 study : [name: 'Study', entity: 'dbnp.studycapturing.Study', type:0], 150 subject : [name: 'Subject', entity: 'dbnp.studycapturing.Subject', type:1] 151 148 152 ] 149 153 ] -
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 -
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r415 r485 46 46 /** 47 47 * @param wb high level representation of the workbook 48 * @param sheetindex sheet to use within the workbook 48 49 * @return header representation as a MappingColumn hashmap 49 50 */ 50 def getHeader(HSSFWorkbook wb, int sheetindex ){51 def getHeader(HSSFWorkbook wb, int sheetindex, theEntity=0){ 51 52 52 53 def sheet = wb.getSheetAt(sheetindex) … … 55 56 def header = [:] 56 57 def df = new DataFormatter() 57 58 def property = new dbnp.studycapturing.TemplateField() 58 59 59 60 for (HSSFCell c: sheet.getRow(datamatrix_start)) { … … 67 68 switch (datamatrix_celltype) { 68 69 case HSSFCell.CELL_TYPE_STRING: 69 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING, index:index );70 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING, index:index, entity:theEntity, property:property); 70 71 break 71 72 case HSSFCell.CELL_TYPE_NUMERIC: 72 73 if (HSSFDateUtil.isCellDateFormatted(c)) { 73 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.DATE, index:index )74 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.DATE, index:index, entity:theEntity, property:property) 74 75 } 75 76 else 76 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.INTEGER,index:index );77 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.INTEGER,index:index, entity:theEntity, property:property); 77 78 break 78 79 case HSSFCell.CELL_TYPE_BLANK: 79 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING, index:index );80 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING, index:index, entity:theEntity, property:property); 80 81 break 81 82 default: 82 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING,index:index );83 header[index] = new dbnp.importer.MappingColumn(name:df.formatCellValue(headercell), templatefieldtype:TemplateFieldType.STRING,index:index, entity:theEntity, property:property); 83 84 break 84 85 } … … 160 161 def sheet = wb.getSheetAt(sheetindex) 161 162 def table = [] 163 162 164 163 165 // walk through all rows 164 166 (rowindex..sheet.getLastRowNum()).each { i -> 165 table.add(createRecord(template_id, sheet.getRow(i), mcmap)) 167 table.add(createRecord(template_id, sheet.getRow(i), mcmap)) 166 168 } 167 169 … … 263 265 def sample = new Sample(name:"New sample", template:template) 264 266 265 for (HSSFCell cell: excelrow) { 267 for (HSSFCell cell: excelrow) { 266 268 def mc = mcmap[cell.getColumnIndex()] 267 def value = formatValue(df.formatCellValue(cell), mc.templatefieldtype) 269 def value = formatValue(df.formatCellValue(cell), mc.templatefieldtype) 268 270 269 271 switch(mc.entity) { -
trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy
r415 r485 22 22 class ImporterTagLib { 23 23 static namespace = 'importer' 24 def standardentities = [[type:-1, name:"Don't import"], [type:0, name:"Study"], [type:1, name:"Subject"], [type:2, name:"Event"],25 [type:3, name:"Protocol"], [type:4, name:"Sample"]]26 24 27 25 /** … … 53 51 54 52 /** 55 * @param entities array 53 * @param entities array containing selected entities 56 54 */ 57 55 def properties = { attrs -> 58 def selectedentities = []59 56 def header = attrs['header'] 57 def entities = attrs['entities'] 60 58 61 attrs['entities'].index.each { columnindex, entitytype -> 62 def entity = [type:entitytype,columnindex:columnindex.toInteger()] 63 selectedentities.add(entity) 64 } 65 66 out << render (template:"common/properties", model:[selectedentities:selectedentities, standardentities:standardentities, header:header]) 59 out << render ( template:"common/properties", 60 model:[selectedentities:entities, 61 standardentities:grailsApplication.config.gscf.domain.importableEntities, 62 header:header]) 67 63 } 68 64 … … 124 120 def res = "<select style=\"font-size:10px\" name=\"${name}.index.${custval}\">" 125 121 126 standardentities.each { e ->127 res += "<option value=\"${e. type}\""128 res += (e. type == sel) ? " selected" : ""129 res += ">${e. name}</option>"122 grailsApplication.config.gscf.domain.importableEntities.each { e -> 123 res += "<option value=\"${e.value.name}\"" 124 res += (e.value.type == sel) ? " selected" : "" 125 res += ">${e.value.name}</option>" 130 126 } 131 127 -
trunk/grails-app/views/importer/common/_properties.gsp
r359 r485 17 17 <table> 18 18 <g:each var="stdentity" in ="${standardentities}"> 19 <% if (selectedentities.any { it. type.toInteger() ==stdentity.type.toInteger()} && stdentity.type.toInteger()!=-1) { %>20 <tr><td colspan="2"><h4>${stdentity. name}</h4></td></tr>19 <% if (selectedentities.any { it.name == stdentity.value.name } && stdentity.value.name!="") { %> 20 <tr><td colspan="2"><h4>${stdentity.value.name}</h4></td></tr> 21 21 <tr> 22 22 <td>Columnname:</td> … … 24 24 </tr> 25 25 <g:each var="selentity" in="${selectedentities}"> 26 <g:if test="${selentity. type.toLong()==stdentity.type}">26 <g:if test="${selentity.name==stdentity.value.name}"> 27 27 <tr> 28 28 <td class="header" width="200px"> -
trunk/grails-app/views/importer/index_advanced.gsp
r417 r485 14 14 <h1>Importer wizard (advanced)</h1> 15 15 <p>You can import your Excel data to the server by choosing a file from your local harddisk in the form below.</p> 16 <g:form controller="importer" method="post" action="upload " enctype="multipart/form-data">16 <g:form controller="importer" method="post" action="upload_advanced" enctype="multipart/form-data"> 17 17 <table border="0"> 18 18 <tr> -
trunk/grails-app/views/importer/index_simple.gsp
r449 r485 57 57 <h1>Importer wizard (simple)</h1> 58 58 <p>You can import your Excel data to the server by choosing a file from your local harddisk in the form below.</p> 59 <g:form controller="importer" method="post" action="upload " enctype="multipart/form-data">59 <g:form controller="importer" method="post" action="upload_simple" enctype="multipart/form-data"> 60 60 <table border="0"> 61 61 <tr> -
trunk/grails-app/views/importer/step2_simple.gsp
r417 r485 21 21 <meta name="layout" content="main"/> 22 22 <link rel="stylesheet" href="${resource(dir: 'css', file: 'importer.css')}"/> 23 <title>Step 2: import wizard entities/properties</title>23 <title>Step 2: import wizard properties/columns</title> 24 24 </head> 25 25 <body> 26 <h1>Step 2: import wizard entities/properties</h1>27 <p> First select the study you want to add the data to. The next step is to assign properties to the columns. Below you see the entities and columns, please make your28 selections.</p>26 <h1>Step 2: import wizard properties/columns</h1> 27 <p>The next step is to assign properties to the columns. Below you see the columns, please assign every column to 28 a property.</p> 29 29 <importer:properties entities="${entities}" header="${header}" templates="${templates}"/> 30 30 </body>
Note: See TracChangeset
for help on using the changeset viewer.