Changeset 1083

Show
Ignore:
Timestamp:
04-11-10 16:49:53 (3 years ago)
Author:
t.w.abma@…
Message:

- added logic for cleaning up 'failed cells' in the imported datamatrix

Location:
trunk/grails-app
Files:
4 modified

Legend:

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

    r1059 r1083  
    153153    } 
    154154 
     155    /* 
     156     * Store the corrected cells back into the datamatrix. Be sure to check 
     157     * if the corrected ontology is not blank. If so, it should keep 
     158     * the original value which was read from the Excel file. 
     159     * 
     160     * @param cell array of cells with updated ontologies 
     161     *  
     162    */ 
     163    def saveCorrectedCells = { 
     164        def correctedcells = [:] 
     165 
     166        // Loop through the form with cell fields and values 
     167        params.cell.index.each { cellhashcode, value -> 
     168            correctedcells.put(cellhashcode, value) 
     169        } 
     170 
     171        // Store the corrected cells back into the datamatrix 
     172        ImporterService.saveCorrectedCells( 
     173                    session.importer_importeddata, 
     174                    session.imported_failedcells, 
     175                    correctedcells) 
     176 
     177        //render("failed cells saved") 
     178      
     179        render(view:"step3_simple", model:[datamatrix:session.importer_importeddata]) 
     180 
     181    } 
     182 
    155183    /** 
    156184    * User has assigned all entities and templatefieldtypes to the columns and continues to the next step (assigning properties to columns) 
     
    270298 
    271299        // First handle the "failed cells" 
    272         //render(view:"step2a_simple", model:[failedcells:ImporterService.getFailedCells(session.importer_importeddata)]) 
     300        session.imported_failedcells = ImporterService.getFailedCells(session.importer_importeddata) 
     301 
     302        //render(view:"step2a_simple", model:[failedcells:session.imported_failedcells]) 
    273303 
    274304        if (params.layout=="horizontal") 
  • trunk/grails-app/services/dbnp/importer/ImporterService.groovy

    r1058 r1083  
    237237     * 
    238238     * @param datamatrix two dimensional array containing entities and possibly also failed cells 
    239      * @return array of failed cells in [rownum:n, value:xxx] format 
     239     * @return array of failed cells in [mappingcolumn, hssfcell] format 
    240240     * */ 
    241241    def getFailedCells(datamatrix) { 
     
    244244       datamatrix.each { record -> 
    245245            record.each { column -> 
    246                 column.each { 
     246                column.each {                     
    247247                    if (it.getClass().getName().equals('java.util.LinkedHashMap$Entry')) {                         
    248248                        failedcells.add(it) 
     
    253253 
    254254        return failedcells 
     255    } 
     256 
     257    /** Method to put failed cells back into the datamatrix. Failed cells are cell values 
     258     * which could not be stored in an entity (e.g. Humu Supiuns in an ontology field). 
     259     * 
     260     * @param datamatrix two dimensional array containing entities and possibly also failed cells 
     261     * @param failedcells map of failed cells in [mappingcolumn, hssfcell] format 
     262     * @param correctedcells map of corrected cells 
     263     **/ 
     264    def saveCorrectedCells(datamatrix, failedcells, correctedcells) { 
     265        /*failedcells.each { 
     266            println it 
     267        }*/ 
     268        def newdatamatrix = [] 
     269 
     270        // Remove failed cells 'entity' / clean up datamatrix 
     271        datamatrix.each { record -> 
     272            def newrecord = [] 
     273 
     274            record.each { entity -> 
     275              // LinkedHashMap means a "mappingcolumn:hssfcell" object is inside the record (= failed to map to entity) 
     276              if (!entity.getClass().getName().equals('java.util.LinkedHashMap')) 
     277              newrecord.add(entity) 
     278            } 
     279 
     280            newdatamatrix.add(newrecord) 
     281        } 
     282 
     283        newdatamatrix.each { record -> 
     284            record.each { entity -> 
     285                entity.giveFields().each { field -> 
     286                    println "das"+ field 
     287                } 
     288            } 
     289        } 
     290 
     291        println "-----" 
     292        correctedcells.each { 
     293            println it.dump() 
     294        } 
    255295    } 
    256296    
     
    446486                                    } // end switch 
    447487                                } catch (IllegalArgumentException iae) { 
    448                                     // leave the field empty and let the user choose the ontology manually in a later step 
    449                                     failed.put(mc, [rownum:excelrow.getRowNum(), value:value]) 
     488                                    // store the mapping column and the cell in an array 
     489                                    failed.put(mc, cell) 
    450490                                    //println "failed ("+mc.templatefieldtype+"`" + value + "`" 
    451491                                } 
  • trunk/grails-app/views/importer/common/_failedcells.gsp

    r1070 r1083  
    2828<table> 
    2929  <tr> 
    30     <td>Column</td><td>Row</td><td>Ontology unknown</td><td>Corrected ontology</td> 
     30    <th>Column</th><th>Row</th><th>Unknown ontology found</th><th>Corrected ontology</th> 
    3131  </tr> 
    32 <g:form> 
     32<g:form name="failedcellsform" action="saveCorrectedCells"> 
    3333        <g:each var="record" in="${failedcells}"> 
    3434          <tr> 
    3535            <td>${record.key.name}</td> 
    36             <td>${record.value.rownum}</td> 
    37             <td>${record.value.value}</td> 
     36            <td>${record.value.getRowIndex()}</td> 
     37            <td>${record.value}</td> 
    3838            <td> 
    39                 <input type="text" name="cell${record.value.rownum}" rel="ontology-all-name"/><br/> 
    40                 <input type="hidden" name="cell${record.value.rownum}-concept_id" /><br/> 
    41                 <input type="hidden" name="cell${record.value.rownum}-ontology_id" /><br/> 
    42                 <input type="hidden" name="cell${record.value.rownum}-full_id" /><br/> 
     39                <input type="text" name="cell.index.${record.value.hashCode()}" rel="ontology-all-name"/> 
     40                <!-- <input type="hidden" name="cell.index.${record.value}-concept_id"/> 
     41                <input type="hidden" name="cell.index.${record.value}-ontology_id"/> 
     42                <input type="hidden" name="cell.index.${record.value}-full_id"/> --> 
    4343            </td> 
    4444          </tr> 
  • trunk/grails-app/views/importer/step2a_simple.gsp

    r1058 r1083  
    2020    <meta name="layout" content="main"/> 
    2121    <link rel="stylesheet" href="${resource(dir: 'css', file: 'importer.css')}"/> 
    22     <title>Step 2a: values which could not be determined</title> 
     22    <title>Step 2a: ontologies which could not be determined</title> 
    2323  </head> 
    2424  <body> 
    25     <h1>Step 2a: values which could not be determined</h1> 
    26     <p>The next step is to adjust values which could not be determined.</p> 
     25    <h1>Step 2a: ontologies which could not be determined</h1> 
     26    <p>The next step is to correct ontologies which could not be determined.</p> 
    2727  <importer:failedCells failedcells="${failedcells}" /> 
    2828  </body>