Changeset 1358 for trunk/grails-app
- Timestamp:
- Jan 11, 2011, 12:46:56 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy
r1332 r1358 10 10 import grails.converters.JSON 11 11 import cr.co.arquetipos.crypto.Blowfish 12 13 import org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib 12 14 13 15 /** … … 31 33 def fileService 32 34 def ImporterService 35 def validationTagLib = new ValidationTagLib() 33 36 34 37 /** … … 121 124 } 122 125 on("next") { 123 if (fileImportPage(flow, params)) { 124 success() 125 } else { 126 println "field is missing" 127 error() 128 } 126 // Study selected? 127 flow.importer_study = (params.study) ? Study.get(params.study.id.toInteger()) : null 128 129 // Trying to import a new study? 130 if (flow.importer_study) 131 if (flow.importer_study.canWrite(AuthenticationService.getLoggedInUser())) { 132 if (fileImportPage(flow, params)) { 133 success() 134 } else { 135 error.log ".importer wizard not all fields are filled in" 136 error() 137 } 138 } else 139 { 140 error.log ".importer wizard wrong permissions" 141 } 142 else { 143 if (fileImportPage(flow, params)) { 144 success() 145 } else { 146 error.log ".importer wizard not all fields are filled in" 147 error() 148 } 149 } 150 151 152 129 153 // put your bussiness logic (if applicable) in here 130 154 }.to "pageTwo" … … 156 180 } 157 181 on("next") { 158 if (propertiesPage(flow, params)) { 159 println "HIER" 182 if (propertiesPage(flow, params)) { 160 183 success() 161 184 } else { … … 188 211 }.to "pageThree" 189 212 on("next") { 190 if (mappingsPage(flow, params)) {213 if (mappingsPage(flow, flash, params)) { 191 214 success() 192 215 } else { 193 log.error ".import wizard mapping error, could not validate all entities" 194 error() 216 log.error ".import wizard mapping error, could not validate all entities" 217 error() 195 218 } 196 219 }.to "pageFour" … … 242 265 if (pluginManager.getGrailsPlugin('grom')) ".persisting instances to the database...".grom() 243 266 244 if (saveEntities(flow, params)) { 245 println "succes" 267 if (saveEntities(flow, params)) { 246 268 success() 247 269 } else { … … 263 285 // render errors 264 286 error { 287 //println "error?" 265 288 render(view: "_error") 266 289 onRender { … … 342 365 343 366 // Initialize some session variables 344 //flow.importer_workbook = wb // workbook object must be serialized for this to work 345 flow.importer_study = Study.get(params.study.id.toInteger()) 346 347 // Is the current logged in user allowed to write to this study? 348 if (flow.importer_study.canWrite(AuthenticationService.getLoggedInUser())) { 367 //flow.importer_workbook = wb // workbook object must be serialized for this to work 368 349 369 flow.importer_template_id = params.template_id 350 370 flow.importer_sheetindex = params.sheetindex.toInteger() -1 // 0 == first sheet … … 373 393 374 394 flow.importer_templates = Template.get(flow.importer_template_id) 375 flow.importer_allfieldtypes = "true" 376 } // end of if 395 flow.importer_allfieldtypes = "true" 377 396 /*else { 378 397 render (template:"common/error", … … 435 454 * @returns boolean true if correctly validated, otherwise false 436 455 */ 437 boolean mappingsPage(flow,params) { 456 boolean mappingsPage(flow, flash, params) { 457 flash.wizardErrors = [:] 438 458 flow.importer_invalidentities = 0 439 459 … … 461 481 if (!entity.validate() || invalidontologies) { 462 482 flow.importer_invalidentities++ 483 484 // add errors to map 485 this.appendErrors(entity, flash.wizardErrors, 'subject_' + entity.getIdentifier() + '_') 463 486 464 487 entity.errors.getAllErrors().each() { … … 505 528 return true 506 529 } 530 531 /** 532 * append errors of a particular object to a map 533 * @param object 534 * @param map linkedHashMap 535 * @void 536 */ 537 def appendErrors(object, map) { 538 this.appendErrorMap(getHumanReadableErrors(object), map) 539 } 540 541 def appendErrors(object, map, prepend) { 542 this.appendErrorMap(getHumanReadableErrors(object), map, prepend) 543 } 544 545 /** 546 * append errors of one map to another map 547 * @param map linkedHashMap 548 * @param map linkedHashMap 549 * @void 550 */ 551 def appendErrorMap(map, mapToExtend) { 552 map.each() {key, value -> 553 mapToExtend[key] = ['key': key, 'value': value, 'dynamic': false] 554 } 555 } 556 557 def appendErrorMap(map, mapToExtend, prepend) { 558 map.each() {key, value -> 559 mapToExtend[prepend + key] = ['key': key, 'value': value, 'dynamic': true] 560 } 561 } 562 563 /** 564 * transform domain class validation errors into a human readable 565 * linked hash map 566 * @param object validated domain class 567 * @return object linkedHashMap 568 */ 569 def getHumanReadableErrors(object) { 570 def errors = [:] 571 object.errors.getAllErrors().each() { error -> 572 // error.codes.each() { code -> println code } 573 574 // generally speaking g.message(...) should work, 575 // however it fails in some steps of the wizard 576 // (add event, add assay, etc) so g is not always 577 // availably. Using our own instance of the 578 // validationTagLib instead so it is always 579 // available to us 580 errors[ error.getArguments()[0] ] = validationTagLib.message(error: error) 581 } 582 583 return errors 584 } 507 585 }
Note: See TracChangeset
for help on using the changeset viewer.