Changeset 1527


Ignore:
Timestamp:
Feb 16, 2011, 2:22:09 PM (12 years ago)
Author:
t.w.abma@…
Message:
  • Importermappings can now be fully retrieved and stored in step 2 of the Importer Wizard
Location:
trunk/grails-app
Files:
4 edited

Legend:

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

    r1525 r1527  
    351351                        flow.importer_datamatrix_start = params.datamatrix_start.toInteger() - 1 // 0 == first row
    352352                        flow.importer_headerrow = params.headerrow.toInteger()
    353             flow.importer_entityclass = entityClass.getClass()
     353            flow.importer_entityclass = entityClass
    354354
    355355                        // Get the header from the Excel file using the arguments given in the first step of the wizard
     
    372372                }
    373373
     374
    374375        log.error ".importer wizard not all fields are filled in"
    375376        this.appendErrorMap(['error': "Not all fields are filled in, please fill in or select all fields"], flash.wizardErrors)
     
    386387    boolean propertiesLoadImportMappingPage(flow, flash, params) {
    387388        def im = ImportMapping.get(params.importmapping_id.toInteger())
    388 
    389         flow.importer_header.each {
    390             println "original=" + it.dump()
    391         }
     389        im.refresh()
    392390
    393391        im.mappingcolumns.each { mappingcolumn ->
    394             flow.importer_header[mappingcolumn.index.toInteger()] = mappingcolumn
    395             println "adjusted=" + mappingcolumn.dump()
     392            def mc = new MappingColumn()
     393            mc.properties = mappingcolumn.properties
     394
     395            flow.importer_header[mappingcolumn.index.toInteger()] = mc         
    396396        }
    397397    }
     
    418418                        // Create an actual class instance of the selected entity with the selected template
    419419                        // This should be inside the closure because in some cases in the advanced importer, the fields can have different target entities                     
    420                         def entityClass = GdtService.getInstanceByEntityName(flow.importer_header[columnindex.toInteger()].entity.getName())
    421             def entityObj = entityClass.newInstance(template:template)
     420                        //def entityClass = GdtService.getInstanceByEntityName(flow.importer_header[columnindex.toInteger()].entity.getName())           
     421            def entityObj = flow.importer_entityclass.newInstance(template:template)
    422422
    423423            def dontimport = (property == "dontimport") ? true : false
     
    432432                                        property:property,
    433433                                        index:columnindex,
    434                                         entity:flow.importer_header[columnindex.toInteger()].entity,
     434                                        entityclass:flow.importer_entityclass,
    435435                                        templatefieldtype:entityObj.giveFieldType(property),
    436436                                        dontimport: dontimport,
     
    439439            // Save mappingcolumn
    440440            if (mc.validate()) {
    441                 im.addToMappingcolumns(mc)
     441                im.addToMappingcolumns(mc)               
    442442            }
    443443            else {
     
    449449            // Save importmapping
    450450            if (im.validate()) {
    451                 im.save(flush:true)
     451                im.save(flush:true)               
    452452            }
    453453            else {
     
    488488                        // Create an actual class instance of the selected entity with the selected template
    489489                        // This should be inside the closure because in some cases in the advanced importer, the fields can have different target entities
    490                         def entityClass = Class.forName(flow.importer_header[columnindex.toInteger()].entity.getName(), true, this.getClass().getClassLoader())
     490                        def entityClass = Class.forName(flow.importer_header[columnindex.toInteger()].entityclass.getName(), true, this.getClass().getClassLoader())
    491491                        def entityObj = entityClass.newInstance(template: template)
    492492
     
    707707                return errors
    708708        }
     709
    709710}
  • trunk/grails-app/domain/dbnp/importer/MappingColumn.groovy

    r1525 r1527  
    1616        String name
    1717        TemplateFieldType templatefieldtype
    18         Class entity
     18        Class entityclass
    1919        String property
    2020        Integer index
     
    3636
    3737    String toString() {
    38         return "Name:" + name + "/TemplateFieldType:" + templatefieldtype + "/Entity:" + entity + "/Property:" + property + "/Index:" + index + "/Value:" + value + "/Identifier:" + identifier
     38        return "Name:" + name + "/TemplateFieldType:" + templatefieldtype + "/Entity:" + entityclass + "/Property:" + property + "/Index:" + index + "/Value:" + value + "/Identifier:" + identifier
    3939    }
    4040}
  • trunk/grails-app/services/dbnp/importer/ImporterService.groovy

    r1515 r1527  
    7676                                                templatefieldtype: fieldtype,
    7777                                                index: columnindex,
    78                                                 entity: theEntity,
     78                                                entityclass: theEntity,
    7979                                                property: property);
    8080
     
    107107                                                templatefieldtype: fieldtype,
    108108                                                index: columnindex,
    109                                                 entity: theEntity,
     109                                                entityclass: theEntity,
    110110                                                property: property);
    111111                                        break
     
    114114                                                templatefieldtype: TemplateFieldType.STRING,
    115115                                                index: columnindex,
    116                                                 entity: theEntity,
     116                                                entityclass: theEntity,
    117117                                                property: property);
    118118                                        break
     
    121121                                                templatefieldtype: TemplateFieldType.STRING,
    122122                                                index: columnindex,
    123                                                 entity: theEntity,
     123                                                entityclass: theEntity,
    124124                                                property: property);
    125125                                        break
     
    442442
    443443                                try {
     444                    println "importdata="+mc.entityclass
    444445                                        // which entity does the current cell (field) belong to?
    445                                         switch (mc.entity) {
     446                                        switch (mc.entityclass) {
    446447                                                case Study: // does the entity already exist in the record? If not make it so.
    447                                                         (record.any {it.getClass() == mc.entity}) ? 0 : record.add(study)
     448                                                        (record.any {it.getClass() == mc.entityclass}) ? 0 : record.add(study)
    448449                                                        study.setFieldValue(mc.property, value)
    449450                                                        break
    450                                                 case Subject: (record.any {it.getClass() == mc.entity}) ? 0 : record.add(subject)
     451                                                case Subject: (record.any {it.getClass() == mc.entityclass}) ? 0 : record.add(subject)
    451452                                                        subject.setFieldValue(mc.property, value)
    452453                                                        break
    453                                                 case SamplingEvent: (record.any {it.getClass() == mc.entity}) ? 0 : record.add(samplingEvent)
     454                                                case SamplingEvent: (record.any {it.getClass() == mc.entityclass}) ? 0 : record.add(samplingEvent)
    454455                                                        samplingEvent.setFieldValue(mc.property, value)
    455456                                                        break
    456                                                 case Event: (record.any {it.getClass() == mc.entity}) ? 0 : record.add(event)
     457                                                case Event: (record.any {it.getClass() == mc.entityclass}) ? 0 : record.add(event)
    457458                                                        event.setFieldValue(mc.property, value)
    458459                                                        break
    459                                                 case Sample: (record.any {it.getClass() == mc.entity}) ? 0 : record.add(sample)
     460                                                case Sample: (record.any {it.getClass() == mc.entityclass}) ? 0 : record.add(sample)
    460461                                                        sample.setFieldValue(mc.property, value)
    461462                                                        break
     
    468469                    def identifier
    469470
    470                                         switch (mc.entity) {
     471                                        switch (mc.entityclass) {
    471472                                                case Study: identifier = "entity_" + study.getIdentifier() + "_" + mc.property
    472473                                                        break
  • trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy

    r1515 r1527  
    111111        def selected = (attrs['selected']) ? attrs['selected'] : ""
    112112
    113         def domainfields = mc.entity.giveDomainFields().findAll { it.type == mc.templatefieldtype }
     113        def domainfields = mc.entityclass.giveDomainFields().findAll { it.type == mc.templatefieldtype }
    114114                domainfields = domainfields.findAll { it.preferredIdentifier != mc.identifier}
    115115
     
    118118                        t.fields + mc.entity.giveDomainFields() :
    119119                        t.fields.findAll { it.type == mc.templatefieldtype } + domainfields*/
    120         def templatefields = t.fields + mc.entity.giveDomainFields()
     120        def templatefields = t.fields + mc.entityclass.giveDomainFields()
    121121
    122122                // map identifier to preferred column
    123                 def prefcolumn = mc.entity.giveDomainFields().findAll { it.preferredIdentifier == true }
     123                def prefcolumn = mc.entityclass.giveDomainFields().findAll { it.preferredIdentifier == true }
    124124
    125125                /*(mc.identifier) ? out << createPropertySelect(attrs['name'], prefcolumn, matchvalue, mc.index) :
Note: See TracChangeset for help on using the changeset viewer.