Changeset 1311
- Timestamp:
- Dec 22, 2010, 1:39:29 PM (10 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy
r1277 r1311 1 1 package dbnp.importer 2 2 import dbnp.studycapturing.Study 3 import dbnp.studycapturing.Sample 4 import dbnp.studycapturing.Event 3 5 import dbnp.studycapturing.Template 4 6 … … 432 434 * @returns boolean true if correctly validated, otherwise false 433 435 */ 434 boolean mappingsPage(flow,params) { 435 def fielderrors = 0 436 flow.importer_invalidentities = 0 436 boolean mappingsPage(flow,params) { 437 flow.importer_invalidentities = 0 437 438 438 439 flow.importer_importeddata.each { table -> 439 440 table.each { entity -> 440 // a new entity is being traversed, if a field cannot be set, increase this counter441 fielderrors = 0 442 441 def invalidontologies = 0 442 443 // Set the fields for this entity by retrieving values from the params 443 444 entity.giveFields().each { field -> 444 try { 445 // try to set the value 446 entity.setFieldValue (field.toString(), params["entity_" + entity.getIdentifier() + "_" + field.escapedName()]) 447 } catch (Exception e) { 448 fielderrors++ 449 } 450 } 451 452 // a field could not be set in the entity, so the entity failed (is not validated) 453 if (fielderrors) flow.importer_invalidentities++ 454 455 // all fields in the entity could be set, no errors, so remove it from the failed cells 456 if (!fielderrors) { 445 // field of type ontology and value "#invalidterm"? 446 if (field.type == dbnp.studycapturing.TemplateFieldType.ONTOLOGYTERM && 447 params["entity_" + entity.getIdentifier() + "_" + field.escapedName()] == "#invalidterm" 448 ) { 449 invalidontologies++ 450 } else 451 entity.setFieldValue (field.toString(), params["entity_" + entity.getIdentifier() + "_" + field.escapedName()]) 452 } 453 454 // Determine entity class and add a parent (defined as Study in first step of wizard) 455 switch (entity.getClass()) { 456 case [Study, Sample, Event]: entity.parent = flow.importer_study 457 } 458 459 // Try to validate the entity now all fields have been set 460 if (!entity.validate() || invalidontologies) { 461 flow.importer_invalidentities++ 462 463 entity.errors.getAllErrors().each() { 464 log.error ".import wizard imported validation error:" + it 465 } 466 } else { 467 // Valid entity, remove it from failedcells 457 468 flow.importer_failedcells.each { record -> 458 469 record.importcells.each { cell -> 459 470 // remove the cell from the failed cells session 460 if (cell.entityidentifier == entity.getIdentifier()) {471 if (cell.entityidentifier == entity.getIdentifier()) { 461 472 record.removeFromImportcells(cell) 462 473 } 463 } 464 } 465 } // end of fielderrors 474 } // end of importcells 475 } // end of failedcells 476 } // end else if 477 466 478 } // end of record 467 479 } // end of table -
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r1277 r1311 297 297 break 298 298 case Subject : log.info "Persisting Subject `" + entity + "`: " 299 entity.parent = study300 299 301 300 // is the current entity not already in the database? … … 312 311 else failedtopersist.add(entity) 313 312 break 314 case Event : log.info "Persisting Event `" + entity + "`: " 315 entity.parent = study 313 case Event : log.info "Persisting Event `" + entity + "`: " 316 314 study.addToEvents(entity) 317 315 if (persistEntity(entity)) validatedSuccesfully++; 318 316 else failedtopersist.add(entity) 319 317 break 320 case Sample : log.info "Persisting Sample `" + entity +"`: " 321 entity.parent = study 318 case Sample : log.info "Persisting Sample `" + entity +"`: " 322 319 323 320 // is this sample validatable (sample name unique for example?) … … 329 326 } 330 327 break 331 case SamplingEvent: log.info "Persisting SamplingEvent `" + entity + "`: " 332 entity.parent = study 328 case SamplingEvent: log.info "Persisting SamplingEvent `" + entity + "`: " 333 329 study.addToSamplingEvents(entity) 334 330 if (persistEntity(entity)) validatedSuccesfully++;
Note: See TracChangeset
for help on using the changeset viewer.