Changeset 725
- Timestamp:
- Jul 27, 2010, 12:07:32 PM (11 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy
r662 r725 420 420 // Convenience setter for boolean fields 421 421 if( field.type == TemplateFieldType.BOOLEAN && value && value.class == String ) { 422 if (value.equals("true") || value.equals("on")) { 422 def lower = value.toLowerCase() 423 if (lower.equals("true") || lower.equals("on") || lower.equals("x")) { 423 424 value = true 424 425 } 425 else if ( value.equals("false") || value.equals("off")) {426 else if (lower.equals("false") || lower.equals("off") || lower.equals("")) { 426 427 value = false 427 428 } -
trunk/grails-app/services/dbnp/importer/ImporterService.groovy
r724 r725 29 29 30 30 import dbnp.data.Term 31 import dbnp.studycapturing.SamplingEvent 31 32 32 33 class ImporterService { … … 303 304 } 304 305 305 /** 306 * This method creates a record (array) containing entities with values 307 * 308 * @param template_id template identifier 309 * @param excelrow POI based Excel row containing the cells 310 * @param mcmap map containing MappingColumn objects 311 */ 312 def createRecord(template_id, HSSFRow excelrow, mcmap) { 313 def df = new DataFormatter() 314 def template = Template.get(template_id) 315 def record = [] 316 317 def study = new Study(template:template) 318 def subject = new Subject(template:template) 319 def event = new Event(template:template) 320 def sample = new Sample(template:template) 321 322 for (HSSFCell cell: excelrow) { 323 def mc = mcmap[cell.getColumnIndex()] 324 def value 325 326 // Check if column must be imported 327 if (!mc.dontimport) { 328 try { 329 value = formatValue(df.formatCellValue(cell), mc.templatefieldtype) 330 } catch (NumberFormatException nfe) { 331 value = "" 332 } 333 334 switch(mc.entity) { 335 case Study : (record.any {it.getClass()==mc.entity}) ? 0 : record.add(study) 336 study.setFieldValue(mc.property, value) 337 break 338 case Subject : (record.any {it.getClass()==mc.entity}) ? 0 : record.add(subject) 339 subject.setFieldValue(mc.property, value) 340 break 341 case Event : (record.any {it.getClass()==mc.entity}) ? 0 : record.add(event) 342 event.setFieldValue(mc.property, value) 343 break 344 case Sample : (record.any {it.getClass()==mc.entity}) ? 0 : record.add(sample) 345 sample.setFieldValue(mc.property, value) 346 break 347 case Object : // don't import 348 break 349 } // end switch 350 } // end 351 } // end for 306 /** 307 * This method creates a record (array) containing entities with values 308 * 309 * @param template_id template identifier 310 * @param excelrow POI based Excel row containing the cells 311 * @param mcmap map containing MappingColumn objects 312 */ 313 def createRecord(template_id, HSSFRow excelrow, mcmap) { 314 def df = new DataFormatter() 315 def template = Template.get(template_id) 316 def record = [] 317 318 def study = new Study(template: template) 319 def subject = new Subject(template: template) 320 def samplingEvent = new SamplingEvent(template: template) 321 def event = new Event(template: template) 322 def sample = new Sample(template: template) 323 324 for (HSSFCell cell: excelrow) { 325 def mc = mcmap[cell.getColumnIndex()] 326 def value 327 328 // Check if column must be imported 329 if (!mc.dontimport) { 330 try { 331 value = formatValue(df.formatCellValue(cell), mc.templatefieldtype) 332 } catch (NumberFormatException nfe) { 333 value = "" 334 } 335 336 switch (mc.entity) { 337 case Study: (record.any {it.getClass() == mc.entity}) ? 0 : record.add(study) 338 study.setFieldValue(mc.property, value) 339 break 340 case Subject: (record.any {it.getClass() == mc.entity}) ? 0 : record.add(subject) 341 subject.setFieldValue(mc.property, value) 342 break 343 case SamplingEvent: (record.any {it.getClass() == mc.entity}) ? 0 : record.add(samplingEvent) 344 samplingEvent.setFieldValue(mc.property, value) 345 break 346 case Event: (record.any {it.getClass() == mc.entity}) ? 0 : record.add(event) 347 event.setFieldValue(mc.property, value) 348 break 349 case Sample: (record.any {it.getClass() == mc.entity}) ? 0 : record.add(sample) 350 sample.setFieldValue(mc.property, value) 351 break 352 case Object: // don't import 353 break 354 } // end switch 355 } // end 356 } // end for 352 357 353 358 return record
Note: See TracChangeset
for help on using the changeset viewer.