Changeset 1121


Ignore:
Timestamp:
Nov 11, 2010, 2:29:16 PM (13 years ago)
Author:
t.w.abma@…
Message:
  • rewrote part of the importer and added a ImportRecord? and ImportCell? domain
  • ontologies should now always be shown individually
Location:
trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy

    r1103 r1121  
    170170
    171171        // Loop through the form with cell fields and values
    172         params.cell.index.each { mappingcolumnhash, value ->
    173             correctedcells.put(mappingcolumnhash, value)
     172        params.cell.index.each { cellhash, value ->
     173            correctedcells.put(cellhash, value)
    174174        }
    175175
  • trunk/grails-app/domain/dbnp/importer/MappingColumn.groovy

    r1103 r1121  
    11package dbnp.importer
    22import dbnp.studycapturing.TemplateField
     3import dbnp.studycapturing.Identity
    34
    45/**
  • trunk/grails-app/services/dbnp/importer/ImporterService.groovy

    r1103 r1121  
    219219        def sheet = wb.getSheetAt(sheetindex)
    220220        def table = []
    221         def failedcells = [:] // map [recordhash, [mappingcolumnlist]] values
     221        def failedcells = [:] // map [recordhash, importrecord] values
    222222       
    223223        // walk through all rows and fill the table with records
    224         (rowindex..sheet.getLastRowNum()).each { i ->
    225             //table.add(createRecord(template_id, sheet.getRow(i), mcmap))
     224        (rowindex..sheet.getLastRowNum()).each { i ->       
    226225            // Create an entity record based on a row read from Excel and store the cells which failed to be mapped
    227226            def (record, failed) = createRecord(template_id, sheet.getRow(i), mcmap)
     
    232231            // If failed cells have been found, add them to the failed cells map
    233232            // the record hashcode is later on used to put the failed data back
    234             // in the data matrix
    235             if (failed.size()!=0) failedcells.put(record.hashCode(), failed)
     233            // in the data matrix           
     234            if (failed.importcells.size()>0) failedcells.put(record.hashCode(), failed)
    236235        }
    237 
    238         failedcells.each { record ->
    239            record.each { cell ->
    240                cell.each {
    241                    println it.value.dump()
    242                }
    243             }
    244         }
    245 
    246236
    247237        return [table,failedcells]
     
    257247     **/
    258248    def saveCorrectedCells(datamatrix, failedcells, correctedcells) {       
    259         // Loop through all failed cells
    260 
    261         failedcells.each { mcrecord ->
    262             mcrecord.each { mappingcolumn ->
     249       
     250        // Loop through all failed cells (stored as
     251        failedcells.each { record ->
     252            record.value.importcells.each { cell ->
     253
    263254                  // Get the corrected value
    264                   def correctedvalue = correctedcells.find { it.key.toInteger() == mappingcolumn.hashCode()}.value
     255                  def correctedvalue = correctedcells.find { it.key.toInteger() == cell.getIdentifier()}.value
    265256
    266257                  // Find the record in the table which the mappingcolumn belongs to
    267                   def tablerecord = datamatrix.find { it.hashCode() == mcrecord.key }
    268 
    269                   // Loop through all entities in the record
     258                  def tablerecord = datamatrix.find { it.hashCode() == record.key }
     259
     260                  // Loop through all entities in the record and correct them if necessary
    270261                  tablerecord.each { rec ->
    271262                      rec.each { entity ->
    272263                            try {
    273264                                // Update the entity field
    274                                 entity.setFieldValue(mappingcolumn.value.property[0], correctedvalue)
    275                                 println "Adjusted " + mappingcolumn.value.property[0] + " to " + correctedvalue
     265                                entity.setFieldValue(cell.mappingcolumn.property, correctedvalue)
     266                                //println "Adjusted " + cell.mappingcolumn.property + " to " + correctedvalue
    276267                            }
    277268                            catch (Exception e) {
    278                                 println "Could not map corrected ontology"
     269                                //println "Could not map corrected ontology: " + cell.mappingcolumn.property + " to " + correctedvalue
    279270                            }
    280271                      }
    281272                  } // end of table record
    282             } // end of mapping record
    283         } // end of failed cells loop     
     273               } // end of cell record
     274            } // end of failedlist
    284275    }
    285276   
     
    428419                def tft = TemplateFieldType
    429420                def record = [] // list of entities and the read values
    430                 def failed = [] // list of failed columns [mappingcolumn] with the value which couldn't be mapped into the entity
     421                def failed = new ImportRecord() // list of failed cells with the value which couldn't be mapped into the entity
    431422
    432423                // Initialize all possible entities with the chosen template
     
    460451                                    temp.value = "undefined"
    461452                                    failed.add(temp)
    462                                 }*/
     453                                }*/                               
    463454                             
    464455
    465456                                try {
    466                                     /*if ((mc.templatefieldtype == TemplateFieldType.ONTOLOGYTERM) && (value == ""))
    467                                         {
    468                                             def temp = new MappingColumn()
    469                                             temp.properties = mc.properties
    470                                             temp.value="unknown"
    471                                             failed.add(temp)
    472                                         }*/
    473 
    474457                                // which entity does the current cell (field) belong to?
    475458                                    switch (mc.entity) {
     
    495478                                } catch (IllegalArgumentException iae) {
    496479                                    // store the mapping column and value which failed
    497                                     def temp = new MappingColumn()
    498                                     temp.properties = mc.properties
    499                                     temp.value = value
    500                                     failed.add(temp)
     480                                    def mcInstance = new MappingColumn()
     481                                    mcInstance.properties = mc.properties
     482                                    failed.addToImportcells(
     483                                        new ImportCell(mappingcolumn:mcInstance,
     484                                            value:value)
     485                                        )
    501486                                }
    502487                        } // end
    503488                } // end for
    504        
    505489        // a failed column means that using the entity.setFieldValue() threw an exception       
    506490        return [record, failed]       
  • trunk/grails-app/views/importer/common/_failedcells.gsp

    r1103 r1121  
    3131  </tr>
    3232<g:form name="failedcellsform" action="saveCorrectedCells">
    33         <g:each var="record" in="${failedcells}">
    34           <g:each var="list" in="${record}">
    35             <g:each var="cell" in="${list}">
     33        <g:each var="item" in="${failedcells}"> <!-- [recordhash, importrecord] -->
     34          <g:each var="cell" in="${item.value.importcells}">
    3635            <tr>
    37               <td>${cell.value.name}</td>
     36              <td>${cell.mappingcolumn.name}</td>
    3837              <td>-</td>
    39               <td>${cell.value.value}</td>
     38              <td>${cell}</td>
    4039              <td>
    41                   <input type="text" name="cell.index.${cell.hashCode()}" rel="ontology-all-name"/>
    42                   <!-- <input type="hidden" name="cell.index.${cell.value}-concept_id"/>
    43                   <input type="hidden" name="cell.index.${cell.value}-ontology_id"/>
    44                   <input type="hidden" name="cell.index.${cell.value}-full_id"/> -->
     40                  <input type="text" name="cell.index.${cell.getIdentifier()}" rel="ontology-all-name"/>
     41                  <!-- <input type="hidden" name="cell.index.${cell}-concept_id"/>
     42                  <input type="hidden" name="cell.index.${cell}-ontology_id"/>
     43                  <input type="hidden" name="cell.index.${cell}-full_id"/> -->
    4544              </td>
    46             </tr>
    47             </g:each>
     45            </tr>           
    4846          </g:each>
    4947        </g:each>
  • trunk/grails-app/views/importer/common/_missingproperties.gsp

    r1103 r1121  
    2525        <g:set var="showHeader" value="${true}"/>
    2626            <g:each status="index" var="table" in="${datamatrix}">
    27                 <g:each status="i" var="entity" in="${table}">                 
     27                <g:each status="i" var="entity" in="${table}">
    2828                    <g:if test="${showHeader}">
    2929                        <g:set var="showHeader" value="${false}"/>
Note: See TracChangeset for help on using the changeset viewer.