Changeset 798
- Timestamp:
- 01/23/09 16:41:54 (4 years ago)
- Location:
- trunk
- Files:
-
- 5 modified
-
mpdb-common/src/edu/rpi/metpetdb/client/model/properties/PropertyUtils.java (modified) (1 diff)
-
mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewAnalysisParser.java (modified) (6 diffs)
-
mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewImageParser.java (modified) (1 diff)
-
mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewParser.java (modified) (6 diffs)
-
mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewSampleParser.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/mpdb-common/src/edu/rpi/metpetdb/client/model/properties/PropertyUtils.java
r753 r798 21 21 return new Float(Float.parseFloat(o.toString())).intValue(); 22 22 } 23 } else if (o instanceof Float) { 24 return ((Float) o).intValue(); 23 25 } else 24 26 return null; -
trunk/mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewAnalysisParser.java
r796 r798 33 33 // Maps an oxide/element name to their precision unit 34 34 private final Map<String, String> precisionUnits; 35 // Oxides/Elements that are in this bulk upload process35 // Oxides/Elements that are in this bulk upload process 36 36 private final Map<String, Element> uploadElements; 37 37 private final Map<String, Oxide> uploadOxides; … … 78 78 * 79 79 * @param is 80 * the input stream that points to a spreadsheet80 * the input stream that points to a spreadsheet 81 81 * @throws MpDbException 82 82 * @throws InvalidFormatException … … 90 90 uploadOxides = new HashMap<String, Oxide>(); 91 91 } 92 92 93 93 public void parse() { 94 // data starts on row 1 for chemical analyses94 // data starts on row 1 for chemical analyses 95 95 parse(1); 96 96 } … … 177 177 @Override 178 178 protected boolean parseColumnSpecialCase(HSSFRow row, HSSFCell cell, 179 PropertyConstraint pc, ChemicalAnalysis currentObject )180 throws IllegalArgumentException, IllegalAccessException,181 I nvocationTargetException {179 PropertyConstraint pc, ChemicalAnalysis currentObject, 180 Integer cellNum) throws IllegalArgumentException, 181 IllegalAccessException, InvocationTargetException { 182 182 final String headerText = headers.get(cell.getColumnIndex()) 183 183 .getHeaderText(); … … 185 185 final ChemicalAnalysisElement element = new ChemicalAnalysisElement(); 186 186 element.setElement(uploadElements.get(headerText)); 187 element.setAmount(Float.parseFloat(sanitizeNumber(cell.toString()))); 187 element 188 .setAmount(getFloatValue(cell.toString())); 188 189 element.setMeasurementUnit(measurementUnits.get(headerText)); 189 190 // see if our next column is our precision 190 191 if (spreadSheetColumnMapping.get(cell.getColumnIndex() + 1) == doc.ChemicalAnalysisElement_ChemicalAnalysis_elements_precision) { 191 element.setPrecision(Float.parseFloat(sanitizeNumber(row 192 .getCell(cell.getColumnIndex() + 1).toString()))); 192 cell = row.getCell(cell.getColumnIndex() + 1); 193 ++cellNum; 194 element.setPrecision(getFloatValue(cell.toString())); 193 195 element.setPrecisionUnit(precisionUnits.get(headers.get( 194 196 cell.getColumnIndex()).getHeaderText())); … … 200 202 final ChemicalAnalysisOxide oxide = new ChemicalAnalysisOxide(); 201 203 oxide.setOxide(uploadOxides.get(headerText)); 202 oxide.setAmount(Float.parseFloat(sanitizeNumber(cell.toString()))); 203 oxide.setMeasurementUnit(measurementUnits.get(headerText).toUpperCase()); 204 oxide.setAmount(getFloatValue(cell.toString())); 205 oxide.setMeasurementUnit(measurementUnits.get(headerText) 206 .toUpperCase()); 204 207 // see if our next column is our precision 205 208 if (spreadSheetColumnMapping.get(cell.getColumnIndex() + 1) == doc.ChemicalAnalysisOxide_ChemicalAnalysis_oxides_precision) { 206 oxide.setPrecision(Float.parseFloat(sanitizeNumber(row.getCell( 207 cell.getColumnIndex() + 1).toString()))); 208 oxide.setPrecisionUnit(precisionUnits.get(headers.get( 209 cell.getColumnIndex()).getHeaderText()).toUpperCase()); 209 cell = row.getCell(cell.getColumnIndex() + 1); 210 ++cellNum; 211 oxide.setPrecision(getFloatValue(cell.toString())); 212 oxide.setPrecisionUnit(precisionUnits.get( 213 headers.get(cell.getColumnIndex()).getHeaderText()) 214 .toUpperCase()); 210 215 } 211 216 oxide.setMinMax(); -
trunk/mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewImageParser.java
r787 r798 105 105 @Override 106 106 protected boolean parseColumnSpecialCase(HSSFRow row, HSSFCell cell, 107 PropertyConstraint pc, BulkUploadImage currentObject )107 PropertyConstraint pc, BulkUploadImage currentObject, Integer cellNum) 108 108 throws IllegalArgumentException, IllegalAccessException, 109 109 InvocationTargetException { -
trunk/mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewParser.java
r797 r798 230 230 231 231 for (Integer i = 0; i <= row.getLastCellNum(); ++i) { 232 finalHSSFCell cell = row.getCell(i.intValue());232 HSSFCell cell = row.getCell(i.intValue()); 233 233 try { 234 234 // get the constraint for this cell … … 236 236 237 237 if (pc != null && cell != null && !cell.toString().equals("") 238 && !parseColumnSpecialCase(row, cell, pc, newObject )) {238 && !parseColumnSpecialCase(row, cell, pc, newObject, i)) { 239 239 240 240 if (pc == doc.Subsample_subsampleType) { … … 278 278 .equals(("BulkUploadImage"))))) { 279 279 if (pc instanceof NumberConstraint<?>) { 280 // Santize numbers before setting them on the object 281 final String data = sanitizeNumber(cell.toString()); 282 newObject.mSet(pc.property, data); 280 newObject.mSet(pc.property, getFloatValue(cell.toString())); 283 281 } else if (pc instanceof TimestampConstraint) { 284 282 // handle dates differently … … 341 339 .toString())); 342 340 } catch (Exception e) { 341 e.printStackTrace(); 343 342 errors.put(rowindex + 1, new BulkUploadError(rowindex + 1, 344 343 i + 1, new GenericDAOException(e.getMessage()), cell … … 355 354 356 355 protected abstract T getNewObject(); 356 357 protected Float getFloatValue(final String number) { 358 final String data = sanitizeNumber(number); 359 if (data.equals("")) { 360 throw new NumberFormatException("Unable to convert '" + number + "' to a number"); 361 } 362 return Float.parseFloat(data); 363 } 357 364 358 365 /** … … 368 375 * @throws InvocationTargetException 369 376 */ 370 protected abstract boolean parseColumnSpecialCase( finalHSSFRow row,371 finalHSSFCell cell, final PropertyConstraint pc,372 final T currentObject ) throws IllegalArgumentException,377 protected abstract boolean parseColumnSpecialCase(HSSFRow row, 378 HSSFCell cell, final PropertyConstraint pc, 379 final T currentObject, Integer cellNum) throws IllegalArgumentException, 373 380 IllegalAccessException, InvocationTargetException; 374 381 -
trunk/mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewSampleParser.java
r787 r798 107 107 @Override 108 108 protected boolean parseColumnSpecialCase(HSSFRow row, HSSFCell cell, 109 PropertyConstraint pc, Sample currentObject )109 PropertyConstraint pc, Sample currentObject, Integer cellNum) 110 110 throws IllegalArgumentException, IllegalAccessException, 111 111 InvocationTargetException {
