Changeset 798

Show
Ignore:
Timestamp:
01/23/09 16:41:54 (4 years ago)
Author:
anthony
Message:

i don't remember but it fixes something

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/mpdb-common/src/edu/rpi/metpetdb/client/model/properties/PropertyUtils.java

    r753 r798  
    2121                                return new Float(Float.parseFloat(o.toString())).intValue(); 
    2222                        } 
     23                } else if (o instanceof Float) { 
     24                        return ((Float) o).intValue(); 
    2325                } else 
    2426                        return null; 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewAnalysisParser.java

    r796 r798  
    3333        // Maps an oxide/element name to their precision unit 
    3434        private final Map<String, String> precisionUnits; 
    35         //Oxides/Elements that are in this bulk upload process 
     35        // Oxides/Elements that are in this bulk upload process 
    3636        private final Map<String, Element> uploadElements; 
    3737        private final Map<String, Oxide> uploadOxides; 
     
    7878         *  
    7979         * @param is 
    80          *              the input stream that points to a spreadsheet 
     80         *            the input stream that points to a spreadsheet 
    8181         * @throws MpDbException 
    8282         * @throws InvalidFormatException 
     
    9090                uploadOxides = new HashMap<String, Oxide>(); 
    9191        } 
    92          
     92 
    9393        public void parse() { 
    94                 //data starts on row 1 for chemical analyses 
     94                // data starts on row 1 for chemical analyses 
    9595                parse(1); 
    9696        } 
     
    177177        @Override 
    178178        protected boolean parseColumnSpecialCase(HSSFRow row, HSSFCell cell, 
    179                         PropertyConstraint pc, ChemicalAnalysis currentObject) 
    180                         throws IllegalArgumentException, IllegalAccessException, 
    181                         InvocationTargetException { 
     179                        PropertyConstraint pc, ChemicalAnalysis currentObject, 
     180                        Integer cellNum) throws IllegalArgumentException, 
     181                        IllegalAccessException, InvocationTargetException { 
    182182                final String headerText = headers.get(cell.getColumnIndex()) 
    183183                                .getHeaderText(); 
     
    185185                        final ChemicalAnalysisElement element = new ChemicalAnalysisElement(); 
    186186                        element.setElement(uploadElements.get(headerText)); 
    187                         element.setAmount(Float.parseFloat(sanitizeNumber(cell.toString()))); 
     187                        element 
     188                                        .setAmount(getFloatValue(cell.toString())); 
    188189                        element.setMeasurementUnit(measurementUnits.get(headerText)); 
    189190                        // see if our next column is our precision 
    190191                        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())); 
    193195                                element.setPrecisionUnit(precisionUnits.get(headers.get( 
    194196                                                cell.getColumnIndex()).getHeaderText())); 
     
    200202                        final ChemicalAnalysisOxide oxide = new ChemicalAnalysisOxide(); 
    201203                        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()); 
    204207                        // see if our next column is our precision 
    205208                        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()); 
    210215                        } 
    211216                        oxide.setMinMax(); 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewImageParser.java

    r787 r798  
    105105        @Override 
    106106        protected boolean parseColumnSpecialCase(HSSFRow row, HSSFCell cell, 
    107                         PropertyConstraint pc, BulkUploadImage currentObject) 
     107                        PropertyConstraint pc, BulkUploadImage currentObject, Integer cellNum) 
    108108                        throws IllegalArgumentException, IllegalAccessException, 
    109109                        InvocationTargetException { 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewParser.java

    r797 r798  
    230230 
    231231                for (Integer i = 0; i <= row.getLastCellNum(); ++i) { 
    232                         final HSSFCell cell = row.getCell(i.intValue()); 
     232                        HSSFCell cell = row.getCell(i.intValue()); 
    233233                        try { 
    234234                                // get the constraint for this cell 
     
    236236 
    237237                                if (pc != null && cell != null && !cell.toString().equals("") 
    238                                                 && !parseColumnSpecialCase(row, cell, pc, newObject)) { 
     238                                                && !parseColumnSpecialCase(row, cell, pc, newObject, i)) { 
    239239 
    240240                                        if (pc == doc.Subsample_subsampleType) { 
     
    278278                                                                                        .equals(("BulkUploadImage"))))) { 
    279279                                                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())); 
    283281                                                } else if (pc instanceof TimestampConstraint) { 
    284282                                                        // handle dates differently 
     
    341339                                                                .toString())); 
    342340                        } catch (Exception e) { 
     341                                e.printStackTrace(); 
    343342                                errors.put(rowindex + 1, new BulkUploadError(rowindex + 1, 
    344343                                                i + 1, new GenericDAOException(e.getMessage()), cell 
     
    355354 
    356355        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        } 
    357364 
    358365        /** 
     
    368375         * @throws InvocationTargetException 
    369376         */ 
    370         protected abstract boolean parseColumnSpecialCase(final HSSFRow row, 
    371                         final HSSFCell 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, 
    373380                        IllegalAccessException, InvocationTargetException; 
    374381 
  • trunk/mpdb-server/src/edu/rpi/metpetdb/server/bulk/upload/NewSampleParser.java

    r787 r798  
    107107        @Override 
    108108        protected boolean parseColumnSpecialCase(HSSFRow row, HSSFCell cell, 
    109                         PropertyConstraint pc, Sample currentObject) 
     109                        PropertyConstraint pc, Sample currentObject, Integer cellNum) 
    110110                        throws IllegalArgumentException, IllegalAccessException, 
    111111                        InvocationTargetException {