Changeset 1945
- Timestamp:
- Jun 29, 2011, 10:10:48 AM (12 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/SimpleWizardController.groovy
r1944 r1945 45 45 flow.study = getStudyFromRequest( params ) 46 46 if (!flow.study) retrievalError() 47 47 48 // Save number of samples in flow 49 flow.numExistingSamples = 0 50 if( flow.study.id ) { 51 flow.numExistingSamples = Sample.countByParent( flow.study ); 52 } 53 48 54 // Search for studies 49 55 flow.studies = Study.giveWritableStudies( authenticationService.getLoggedInUser(), 100 ) … … 823 829 // loop through all entities to validate them and add them to failedcells if an error occurs 824 830 def numInvalidEntities = 0; 825 def e rrors = [];831 def entityErrors = []; 826 832 827 833 // Add all samples 828 834 table.each { record -> 829 835 record.each { entity -> 836 830 837 if( entity ) { 831 838 // Determine entity class and add a parent. Add the entity to the study … … 838 845 switch( entity.class ) { 839 846 case Sample: // instantiate a sample 840 def newSample = new Sample(841 parentSubject : subject,842 parentEvent : samplingEvent,843 parentEventGroup: eventGroup,844 name : sampleName,845 template : (samplingEvent.sampleTemplate) ? samplingEvent.sampleTemplate : ''846 )847 848 flow.study.addToSamples(newSample)849 847 if( !study.samples?.find( equalClosure ) ) { 850 848 study.addToSamples( entity ); 851 849 } 852 850 853 851 // If an eventgroup is created, add it to the study 854 852 // The eventgroup must have a unique name, but the user shouldn't be bothered with it … … 863 861 } 864 862 } 865 863 866 864 break; 867 865 case Subject: 868 if( !study.samples?.find( equalClosure ) ) {869 866 if( !study.subjects?.find( equalClosure ) ) { 867 870 868 if( preferredIdentifier ) { 871 869 // Subjects without a name should just be called 'subject' … … 884 882 885 883 study.addToSubjects( entity ); 886 887 } 884 } 888 885 889 886 break; … … 905 902 break; 906 903 } 907 904 908 905 if (!entity.validate()) { 909 906 numInvalidEntities++; … … 916 913 if( currentErrors ) { 917 914 currentErrors.each { 918 e rrors += "(" + entityName + ") " + it.value;915 entityErrors += "(" + entityName + ") " + it.value; 919 916 } 920 917 } … … 925 922 926 923 flow.imported.numInvalidEntities = numInvalidEntities + failedcells?.size(); 927 flow.imported.errors = e rrors;924 flow.imported.errors = entityErrors; 928 925 929 926 return true … … 941 938 def handleMissingFields( study, params, flow ) { 942 939 def numInvalidEntities = 0; 943 def e rrors = [];940 def entityErrors = []; 944 941 945 942 // Check which fields failed previously … … 989 986 if( currentErrors ) { 990 987 currentErrors.each { 991 e rrors += "(" + entityName + ") " + it.value;988 entityErrors += "(" + entityName + ") " + it.value; 992 989 } 993 990 } … … 1002 999 flow.imported.failedCells = newFailedCells 1003 1000 flow.imported.numInvalidEntities = numInvalidEntities; 1004 flow.imported.errors = e rrors;1001 flow.imported.errors = entityErrors; 1005 1002 1006 1003 return numInvalidEntities == 0 -
trunk/grails-app/domain/dbnp/studycapturing/Sample.groovy
r1922 r1945 142 142 Sample s = (Sample) o; 143 143 144 return this.i d == s.id144 return this.is(s) || this.id == s.id 145 145 } 146 146 -
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r1684 r1945 22 22 class ImporterService { 23 23 def authenticationService 24 def sessionFactory 24 25 25 26 static transactional = false … … 258 259 if( !mcmap ) 259 260 return; 261 262 def hibernateSession = sessionFactory.getCurrentSession() 260 263 261 264 // Check whether the rows should be imported in one or more entities … … 269 272 def sheet = wb.getSheetAt(sheetindex) 270 273 def table = [] 274 def samples = [] 271 275 def failedcells = [] // list of cells that have failed to import 272 276 … … 287 291 if( row && !rowIsEmpty( row ) ) { 288 292 // Create an entity record based on a row read from Excel and store the cells which failed to be mapped 289 def (record, failed) = importOrUpdateRecord( templates, entities, row, mcmap, parent, table, existingEntities[i] );290 293 def (record, failed) = importOrUpdateRecord( templates, entities, row, mcmap, parent, samples, existingEntities[i] ); 294 291 295 // Setup the relationships between the imported entities 292 296 relateEntities( record ); 293 297 294 298 // Add record with entities and its values to the table 295 299 table.add(record) 296 300 297 301 // If failed cells have been found, add them to the failed cells list 298 302 if (failed?.importcells?.size() > 0) failedcells.add(failed) 303 304 // Add a sample to the list of samples if possible 305 def sample = record.find { it instanceof dbnp.studycapturing.Sample } 306 if( sample && !samples.contains( sample ) ) 307 samples << sample 299 308 } 300 309 } … … 357 366 * @param mcmap Hashmap of mappingcolumns, with the first entry in the hashmap containing information about the first column, etc. 358 367 * @param parent Study to import all data into. Is used for determining which sample/event/subject/assay to update 359 * @param imported Rows Rows that have been imported before this row. These rows might contain the same entities as are360 * imported in this row. These entities should be used again,to avoid importing duplicates.368 * @param importedSamples Samples that have been imported before this row. These entities should be used again if possible, 369 * to avoid importing duplicates. 361 370 * @return List List with two entries: 362 371 * 0 List with ImportRecords, one for each row in the excelsheet … … 364 373 * (because the value in the excelsheet can't be entered into the template field) 365 374 */ 366 def importOrUpdateRecord(def templates, def entities, Row excelRow, mcmap, Study parent = null, List imported Rows, Map existingEntities ) {375 def importOrUpdateRecord(def templates, def entities, Row excelRow, mcmap, Study parent = null, List importedSamples, Map existingEntities ) { 367 376 DataFormatter df = new DataFormatter(); 368 377 def record = [] // list of entities and the read values 369 378 def failed = new ImportRecord() // map with entity identifier and failed mappingcolumn 370 379 380 def currentTime = System.currentTimeMillis(); 381 371 382 // Check whether this record mentions a sample that has been imported before. In that case, 372 383 // we update that record, in order to prevent importing the same sample multiple times 373 384 def importedEntities = []; 374 if( imported Rows )375 importedEntities = imported Rows.flatten().findAll { it.class == dbnp.studycapturing.Sample }.unique();385 if( importedSamples ) 386 importedEntities = importedSamples 376 387 377 388 def importedSample = findEntityInImportedEntities( dbnp.studycapturing.Sample, excelRow, mcmap, importedEntities, df ) -
trunk/grails-app/views/simpleWizard/simpleWizard/columns.gsp
r1944 r1945 33 33 Please match the columns from the excel file with the fields in the database. 34 34 </span> 35 <g:if test="${excel.numDataRows > 200}">35 <g:if test="${excel.numDataRows > 300}"> 36 36 <span class="info"> 37 <span class="error" style="background-position: 0 50%;"> Too many samples in excel file</span>38 Your uploaded excel file contains more than 200 samples. This wizard might become very slow when importing that many samples.<br />39 The best you can do is to save your study (go back to the first page of the wizard and click save), and use the <i>Import</i> ->40 <i>A part or a study design</i> menu option.37 <span class="error" style="background-position: 0 50%;">Many samples in excel file</span> 38 Your uploaded excel file contains more than 300 samples. This wizard might become less responsive when importing that many samples, but 39 will still be working properly.<br /> 40 Please be patient when importing the data and saving your study. 41 41 </span> 42 42 </g:if> -
trunk/grails-app/views/simpleWizard/simpleWizard/study.gsp
r1686 r1945 34 34 filled out, the more valuable the system will be. 35 35 </span> 36 37 <g:if test="${numExistingSamples > 300}"> 38 <span class="info"> 39 <span class="error" style="background-position: 0 50%;">Many samples in study</span> 40 Your study contains more than 300 samples. This wizard might become less responsive when editing that many samples, but will still function properly.<br /> 41 Please be patient when editing samples and saving your study. 42 </span> 43 </g:if> 44 36 45 37 46 <g:if test="${flash.validationErrors}">
Note: See TracChangeset
for help on using the changeset viewer.