Changeset 1553


Ignore:
Timestamp:
Feb 23, 2011, 4:32:09 PM (12 years ago)
Author:
robert@…
Message:

First version of a simple wizard

Location:
trunk
Files:
15 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/dbnp/importer/ImporterService.groovy

    r1536 r1553  
    6161                        switch (datamatrix_celltype) {
    6262                                case Cell.CELL_TYPE_STRING:
    63                                         //parse cell value as double
     63                                //parse cell value as double
    6464                                        def doubleBoolean = true
    6565                                        def fieldtype = TemplateFieldType.STRING
    6666
    67                                         // is this string perhaps a double?
     67                                // is this string perhaps a double?
    6868                                        try {
    6969                                                formatValue(datamatrix_celldata, TemplateFieldType.DOUBLE)
     
    7474
    7575                                        header[columnindex] = new dbnp.importer.MappingColumn(name: df.formatCellValue(headercell),
    76                                                 templatefieldtype: fieldtype,
    77                                                 index: columnindex,
    78                                                 entityclass: theEntity,
    79                                                 property: property);
     76                                                        templatefieldtype: fieldtype,
     77                                                        index: columnindex,
     78                                                        entityclass: theEntity,
     79                                                        property: property);
    8080
    8181                                        break
     
    8585                                        def longBoolean = true
    8686
    87                                         // is this cell really an integer?
     87                                // is this cell really an integer?
    8888                                        try {
    8989                                                Long.valueOf(datamatrix_celldata)
     
    9393                                        }
    9494
    95                                         // it's not an long, perhaps a double?
     95                                // it's not an long, perhaps a double?
    9696                                        if (!longBoolean)
    9797                                                try {
     
    105105
    106106                                        header[columnindex] = new dbnp.importer.MappingColumn(name: df.formatCellValue(headercell),
    107                                                 templatefieldtype: fieldtype,
    108                                                 index: columnindex,
    109                                                 entityclass: theEntity,
    110                                                 property: property);
     107                                                        templatefieldtype: fieldtype,
     108                                                        index: columnindex,
     109                                                        entityclass: theEntity,
     110                                                        property: property);
    111111                                        break
    112112                                case Cell.CELL_TYPE_BLANK:
    113113                                        header[columnindex] = new dbnp.importer.MappingColumn(name: df.formatCellValue(headercell),
    114                                                 templatefieldtype: TemplateFieldType.STRING,
    115                                                 index: columnindex,
    116                                                 entityclass: theEntity,
    117                                                 property: property);
     114                                        templatefieldtype: TemplateFieldType.STRING,
     115                                        index: columnindex,
     116                                        entityclass: theEntity,
     117                                        property: property);
    118118                                        break
    119119                                default:
    120120                                        header[columnindex] = new dbnp.importer.MappingColumn(name: df.formatCellValue(headercell),
    121                                                 templatefieldtype: TemplateFieldType.STRING,
    122                                                 index: columnindex,
    123                                                 entityclass: theEntity,
    124                                                 property: property);
     121                                        templatefieldtype: TemplateFieldType.STRING,
     122                                        index: columnindex,
     123                                        entityclass: theEntity,
     124                                        property: property);
    125125                                        break
    126126                        } // end of switch
     
    150150
    151151                        (0..header.size() - 1).each { columnindex ->
    152                 if (sheet.getRow(rowindex))
    153                     row.add( sheet.getRow(rowindex).getCell(columnindex, Row.CREATE_NULL_AS_BLANK) )
     152                                if (sheet.getRow(rowindex))
     153                                        row.add( sheet.getRow(rowindex).getCell(columnindex, Row.CREATE_NULL_AS_BLANK) )
    154154                        }
    155155
     
    204204                def table = []
    205205                def failedcells = [] // list of records
    206 
     206               
    207207                // walk through all rows and fill the table with records
    208208                (rowindex..sheet.getLastRowNum()).each { i ->
     
    218218
    219219                return [table, failedcells]
     220        }
     221
     222        /**
     223         * Removes a cell from the failedCells list, based on the entity and field. If the entity and field didn't fail before
     224         * the method doesn't do anything.
     225         *
     226         * @param failedcell    list of cells that have failed previously
     227         * @param entity                entity to remove from the failedcells list
     228         * @param field                 field to remove the failed cell for. If no field is given, all cells for this entity will be removed
     229         * @return List                 Updated list of cells that have failed
     230         */
     231        def removeFailedCell(failedcells, entity, field = null ) {
     232                if( !entity )
     233                        return failedcells;
     234
     235                def filterClosure
     236                if( field ) {
     237                        def entityIdField = "entity_" + entity.getIdentifier() + "_" + field.name.toLowerCase()
     238                        filterClosure = { cell -> cell.entityidentifier != entityIdField }
     239                } else {
     240                        def entityIdField = "entity_" + entity.getIdentifier() + "_"
     241                        filterClosure = { cell -> !cell.entityidentifier.startsWith( entityIdField ) }
     242                }
     243
     244                failedcells.each { record ->
     245                        record.importcells = record.importcells.findAll( filterClosure )
     246                }
     247
     248                return failedcells;
     249        }
     250
     251        /**
     252         * Returns the name of an input field as it is used for a specific entity in HTML.
     253         *
     254         * @param entity                entity to retrieve the field name for
     255         * @param field                 field to retrieve the field name for
     256         * @return String               Name of the HTML field for the given entity and field. Can also be used in the map
     257         *                                              of request parameters
     258         */
     259        def getFieldNameInTableEditor(entity, field) {
     260                if( field instanceof TemplateField )
     261                        field = field.escapedName();
     262
     263                return "entity_" + entity.getIdentifier() + "_" + field
     264        }
     265
     266        /**
     267         * Retrieves a mapping column from a list based on the given fieldname
     268         * @param mappingColumns                List of mapping columns
     269         * @param fieldName                     Field name to find
     270         * @return                                      Mapping column if a column is found, null otherwise
     271         */
     272        def findMappingColumn( mappingColumns, String fieldName ) {
     273                return mappingColumns.find { it.property == fieldName.toLowerCase() }
    220274        }
    221275
     
    278332                                        case Study: log.info ".importer wizard, persisting Study `" + entity + "`: "
    279333                                                entity.owner = authenticationService.getLoggedInUser()
    280                        
    281                         if (study.validate()) {
    282                             if (!entity.save(flush:true)) {
    283                                 log.error ".importer wizard, study could not be saved: " + entity
    284                                 throw new Exception('.importer wizard, study could not be saved: ' + entity)
    285                             }
    286                         } else {
    287                             log.error ".importer wizard, study could not be validated: " + entity
    288                             throw new Exception('.importer wizard, study could not be validated: ' + entity)
    289                         }
    290 
    291                         break
     334
     335                                                if (study.validate()) {
     336                                                        if (!entity.save(flush:true)) {
     337                                                                log.error ".importer wizard, study could not be saved: " + entity
     338                                                                throw new Exception('.importer wizard, study could not be saved: ' + entity)
     339                                                        }
     340                                                } else {
     341                                                        log.error ".importer wizard, study could not be validated: " + entity
     342                                                        throw new Exception('.importer wizard, study could not be validated: ' + entity)
     343                                                }
     344
     345                                                break
    292346                                        case Subject: log.info ".importer wizard, persisting Subject `" + entity + "`: "
    293347
    294                                                 // is the current entity not already in the database?
    295                                                 //entitystored = isEntityStored(entity)
    296 
    297                                                 // this entity is new, so add it to the study
    298                                                 //if (entitystored==null)
     348                                        // is the current entity not already in the database?
     349                                        //entitystored = isEntityStored(entity)
     350
     351                                        // this entity is new, so add it to the study
     352                                        //if (entitystored==null)
    299353
    300354                                                study.addToSubjects(entity)
     
    306360                                        case Sample: log.info ".importer wizard, persisting Sample `" + entity + "`: "
    307361
    308                                                 // is this sample validatable (sample name unique for example?)
     362                                        // is this sample validatable (sample name unique for example?)
    309363                                                study.addToSamples(entity)
    310364
     
    391445        boolean persistEntity(entity) {
    392446                /*log.info ".import wizard persisting ${entity}"
    393 
    394                 try {           
    395                         entity.save(flush: true)
    396                         return true
    397 
    398                 } catch (Exception e) {
    399                         def session = sessionFactory.currentSession
    400                         session.setFlushMode(org.hibernate.FlushMode.MANUAL)
    401                         log.error ".import wizard, failed to save entity:\n" + org.apache.commons.lang.exception.ExceptionUtils.getRootCauseMessage(e)
    402                 }
    403 
    404                 return true*/
    405         //println "persistEntity"
     447                 try {           
     448                 entity.save(flush: true)
     449                 return true
     450                 } catch (Exception e) {
     451                 def session = sessionFactory.currentSession
     452                 session.setFlushMode(org.hibernate.FlushMode.MANUAL)
     453                 log.error ".import wizard, failed to save entity:\n" + org.apache.commons.lang.exception.ExceptionUtils.getRootCauseMessage(e)
     454                 }
     455                 return true*/
     456                //println "persistEntity"
    406457        }
    407458
     
    441492                                }
    442493
    443                                 try {                   
     494                                try {
    444495                                        // which entity does the current cell (field) belong to?
    445496                                        switch (mc.entityclass) {
     
    466517                                        log.error ".import wizard error could not set property `" + mc.property + "` to value `" + value + "`"
    467518                                        // store the mapping column and value which failed
    468                     def identifier
     519                                        def identifier
    469520
    470521                                        switch (mc.entityclass) {
     
    503554                        case TemplateFieldType.TEXT: return value.trim()
    504555                        case TemplateFieldType.LONG: return (long) Double.valueOf(value)
    505                 //case TemplateFieldType.FLOAT      :   return Float.valueOf(value.replace(",","."));
     556                        //case TemplateFieldType.FLOAT      :   return Float.valueOf(value.replace(",","."));
    506557                        case TemplateFieldType.DOUBLE: return Double.valueOf(value.replace(",", "."));
    507558                        case TemplateFieldType.STRINGLIST: return value.trim()
     
    520571
    521572                dotProduct(l_histo, r_histo) /
    522                         Math.sqrt(dotProduct(l_histo, l_histo) *
     573                                Math.sqrt(dotProduct(l_histo, l_histo) *
    523574                                dotProduct(r_histo, r_histo))
    524575        }
     
    546597
    547598                similarity(l_str.toString().toLowerCase().toCharArray(),
    548                         r_str.toString().toLowerCase().toCharArray(),
    549                         degree)
     599                                r_str.toString().toLowerCase().toCharArray(),
     600                                degree)
    550601        }
    551602
  • trunk/web-app/css/buttons.css

    r1548 r1553  
    2424}
    2525
     26.options a.save {
     27        background-image: url(../plugins/famfamfam-1.0.1/images/icons/page_save.png);
     28}
     29.options a.skip {
     30        background-image: url(../plugins/famfamfam-1.0.1/images/icons/control_end_blue.png);
     31}
     32.options a.view {
     33        background-image: url(../plugins/famfamfam-1.0.1/images/icons/application_form_magnify.png);
     34}
     35.options a.restart {
     36        background-image: url(../plugins/famfamfam-1.0.1/images/icons/arrow_redo.png);
     37}
     38.options a.edit {
     39        background-image: url(../plugins/famfamfam-1.0.1/images/icons/application_form_edit.png);
     40}
     41
    2642.options a.performAction {
    2743        background-image: url(../plugins/famfamfam-1.0.1/images/icons/brick_go.png);
  • trunk/web-app/js/studywizard.js

    r1508 r1553  
    148148function handleWizardTable() {
    149149        var that = this;
    150         var wizardTables = $(".ajaxFlow").find('div.tableEditor');
     150        var wizardTables = $('div.tableEditor');
    151151
    152152        wizardTables.each(function() {
Note: See TracChangeset for help on using the changeset viewer.