Changeset 1611
- Timestamp:
- Mar 9, 2011, 10:24:41 PM (11 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/SimpleWizardController.groovy
r1610 r1611 69 69 'SamplingEvent': Template.findAllByEntity( SamplingEvent.class ) 70 70 ]; 71 71 72 flow.encodedEntity = [ 72 73 'Sample': gdtService.encryptEntity( Sample.class.name ), … … 74 75 'Event': gdtService.encryptEntity( Event.class.name ), 75 76 'SamplingEvent': gdtService.encryptEntity( SamplingEvent.class.name ) 76 77 ] 77 78 78 79 if (flow.study.samples) … … 272 273 flow.study.addToAssays( flow.assay ); 273 274 } 274 275 println "Events: " + flow.study.events276 println "Samples: " + flow.study.samples277 println "Eventgroups" + flow.study.eventGroups278 275 279 276 if( flow.study.save( flush: true ) ) { … … 746 743 break; 747 744 case Subject: 748 if( !preferredIdentifier || !study.subjects?.find( equalClosure ) ) { 749 study.addToSubjects( entity ); 745 // Subjects should have unique names; if the user has entered the same name multiple times, 746 // the subject will be renamed 747 def subjectFound = study.subjects?.find( equalClosure ) ; 748 if( preferredIdentifier && subjectFound ) { 749 def baseName = entity.getFieldValue( preferredIdentifier.name ) 750 def counter = 1; 751 752 while( study.subjects?.find { it.getFieldValue( preferredIdentifier.name ) == entity.getFieldValue( preferredIdentifier.name ) } ) { 753 entity.setFieldValue( preferredIdentifier.name, baseName + " (" + counter++ + ")" ) 754 } 750 755 } 756 study.addToSubjects( entity ); 757 751 758 break; 752 759 case Event: -
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r1610 r1611 282 282 // walk through all rows and fill the table with records 283 283 for( int i = rowindex; i <= sheet.getLastRowNum(); i++ ) { 284 // Create an entity record based on a row read from Excel and store the cells which failed to be mapped 285 def (record, failed) = importOrUpdateRecord( templates, entities, sheet.getRow(i), mcmap, parent, table, existingEntities[i] ); 286 287 // Setup the relationships between the imported entities 288 relateEntities( record ); 289 290 // Add record with entities and its values to the table 291 table.add(record) 292 293 // If failed cells have been found, add them to the failed cells list 294 if (failed?.importcells?.size() > 0) failedcells.add(failed) 284 def row = sheet.getRow(i); 285 286 if( row && !rowIsEmpty( row ) ) { 287 // Create an entity record based on a row read from Excel and store the cells which failed to be mapped 288 def (record, failed) = importOrUpdateRecord( templates, entities, row, mcmap, parent, table, existingEntities[i] ); 289 290 // Setup the relationships between the imported entities 291 relateEntities( record ); 292 293 // Add record with entities and its values to the table 294 table.add(record) 295 296 // If failed cells have been found, add them to the failed cells list 297 if (failed?.importcells?.size() > 0) failedcells.add(failed) 298 } 295 299 } 296 300 297 301 return [ "table": table, "failedCells": failedcells ] 302 } 303 304 /** 305 * Checks whether an excel row is empty 306 * @param row Row from the excel sheet 307 * @return True if all cells in this row are empty or the given row is null. False otherwise 308 */ 309 def rowIsEmpty( Row excelRow ) { 310 if( !excelRow ) 311 return true; 312 313 def df = new DataFormatter(); 314 for( int i = excelRow.getFirstCellNum(); i < excelRow.getLastCellNum(); i++ ) { 315 Cell cell = excelRow.getCell( i ); 316 317 try { 318 def value = df.formatCellValue(cell) 319 if( value ) 320 return false 321 } catch (NumberFormatException nfe) { 322 // If the number can't be formatted, the row isn't empty 323 return false; 324 } 325 } 326 327 return true; 298 328 } 299 329 … … 344 374 importedEntities = importedRows.flatten().findAll { it.class == dbnp.studycapturing.Sample }.unique(); 345 375 346 def importedSample = null // findEntityInImportedEntities( dbnp.studycapturing.Sample, excelRow, mcmap, importedEntities, df ) 347 def imported = [] // retrieveEntitiesBySample( importedSample ); 376 def importedSample = findEntityInImportedEntities( dbnp.studycapturing.Sample, excelRow, mcmap, importedEntities, df ) 377 def imported = retrieveEntitiesBySample( importedSample ); 378 348 379 for( entity in entities ) { 349 380 // Check whether this entity should be added or updated … … 372 403 373 404 // Go through the Excel row cell by cell 374 for (Cell cell: excelRow) { 405 for( int i = excelRow.getFirstCellNum(); i < excelRow.getLastCellNum(); i++ ) { 406 Cell cell = excelRow.getCell( i ); 407 375 408 // get the MappingColumn information of the current cell 376 409 def mc = mcmap[cell.getColumnIndex()] … … 426 459 */ 427 460 def findEntityByRow( Class entity, Row excelRow, def mcmap, Study parent = null, List importedEntities = [], DataFormatter df = null ) { 461 if( !excelRow ) 462 return 463 428 464 if( df == null ) 429 465 df = new DataFormatter(); -
trunk/grails-app/views/simpleWizard/simpleWizard/finish.gsp
r1608 r1611 25 25 <g:link class="view" controller="study" action="show" id="${study.id}">View study</g:link> 26 26 <g:link class="edit" controller="simpleWizard" action="index" id="${study.id}">Edit study</g:link> 27 <g:link class="restart" controller="simpleWizard" action=" study">Add another study</g:link>27 <g:link class="restart" controller="simpleWizard" action="index">Add another study</g:link> 28 28 </p> 29 29 </div>
Note: See TracChangeset
for help on using the changeset viewer.