Changeset 1207
- Timestamp:
- Nov 26, 2010, 1:02:51 PM (12 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy
r1202 r1207 344 344 model:[error:"Data is already imported or you are calling the url directly without following the previous import steps."]) 345 345 } else { 346 session.validatedSuccesfully = ImporterService.saveDatamatrix(session.importer_study, session.importer_importeddata) 347 render(view:"step4", model:[validatedSuccesfully:session.validatedSuccesfully, totalrows:session.importer_importeddata.size, referer: session.import_referer]) 346 def (validatedSuccesfully, updatedEntities, failedtopersist) = ImporterService.saveDatamatrix(session.importer_study, session.importer_importeddata) 347 session.validatedSuccesfully = validatedSuccesfully 348 render(view:"step4", model:[validatedSuccesfully:session.validatedSuccesfully, failedtopersist:failedtopersist, updatedentities:updatedEntities, totalrows:session.importer_importeddata.size, referer: session.import_referer]) 348 349 session.import_wizard_init = false 350 351 println "failed:" 352 failedtopersist.each { 353 println it 354 } 349 355 } 350 356 } -
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r1202 r1207 281 281 def saveDatamatrix(Study study, datamatrix) { 282 282 def validatedSuccesfully = 0 283 def entitystored = null 284 study.refresh() 285 283 def entitystored = null 284 def failedtopersist = [] 285 def updatedentities = [] 286 study.refresh() 287 286 288 // go through the data matrix, read every record and validate the entity and try to persist it 287 289 datamatrix.each { record -> … … 290 292 case Study : print "Persisting Study `" + entity + "`: " 291 293 entity.owner = AuthenticationService.getLoggedInUser() 292 if (persistEntity(entity)) validatedSuccesfully++ 294 if (persistEntity(entity)) validatedSuccesfully++; 295 else failedtopersist.add(entity) 293 296 break 294 297 case Subject : print "Persisting Subject `" + entity + "`: " … … 300 303 // this entity is new, so add it to the study 301 304 if (entitystored==null) study.addToSubjects(entity) 302 else // existing entity, so update it305 else { // existing entity, so update it 303 306 updateEntity(entitystored, entity) 304 305 if (persistEntity(study)) validatedSuccesfully++ 307 updatedentities.add(entity) 308 } 309 310 if (persistEntity(study)) validatedSuccesfully++; 311 else failedtopersist.add(entity) 306 312 break 307 313 case Event : print "Persisting Event `" + entity + "`: " 308 314 entity.parent = study 309 315 study.addToEvents(entity) 310 if (persistEntity(entity)) validatedSuccesfully++ 316 if (persistEntity(entity)) validatedSuccesfully++; 317 else failedtopersist.add(entity) 311 318 break 312 319 case Sample : print "Persisting Sample `" + entity +"`: " … … 316 323 if (entity.validate()) { 317 324 study.addToSamples(entity) 318 if (persistEntity(study)) validatedSuccesfully++ 319 } 325 if (persistEntity(study)) validatedSuccesfully++; 326 } else failedtopersist.add(entity) 320 327 321 328 break … … 323 330 entity.parent = study 324 331 study.addToSamplingEvents(entity) 325 if (persistEntity(entity)) validatedSuccesfully++ 332 if (persistEntity(entity)) validatedSuccesfully++; 333 else failedtopersist.add(entity) 326 334 break 327 335 default : println "Skipping persisting of `" + entity.getclass() +"`" 336 failedtopersist.add(entity) 328 337 break 329 338 } // end switch 330 339 } // end record 331 340 } // end datamatrix 332 return validatedSuccesfully341 return [validatedSuccesfully, updatedentities, failedtopersist] 333 342 } 334 343 -
trunk/grails-app/views/importer/step4.gsp
r1142 r1207 25 25 <h1>Step 5: import wizard finished</h1> 26 26 <p>${validatedSuccesfully} of ${totalrows} rows were imported succesfully.</p> 27 28 29 30 <g:if test="${failedtopersist}"> 31 <p>The following entities could not be persisted:</p> 32 <table> 33 <g:each var="entity" in="${failedtopersist}"> 34 <tr> 35 <g:each var="field" in="${entity.giveFields()}"> 36 <td> 37 <g:if test="${entity.getFieldValue(field.name)!=null}"> 38 <b>${field.name}</b> ${entity.getFieldValue(field.name)} 39 </g:if> 40 <g:else><b>${field.name}</b> × 41 </g:else> 42 </td> 43 </g:each> 44 </tr> 45 </g:each> 46 </table> 47 </g:if> 48 49 27 50 <g:if test="${referer}"> 28 51 <p>Click <a href="${referer}">here</a> to return to the page you came from.</p>
Note: See TracChangeset
for help on using the changeset viewer.