Produced by Araxis Merge on 6/9/2017 3:51:30 PM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | Fri Jun 9 19:51:30 2017 UTC | ||
| 2 | eHealth_Exch (eHealth Exchange Enhancements) Build 3 docs & code_May_2017.zip\VAP_CIF_CODE0502.zip\VAP_CIF_CODE0502\VAP_CIF_CODE0502\nvap-web\src\main\java\gov\va\nvap\web\util\file | FileUploader.java | Fri Apr 21 20:03:30 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 1 | 218 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | package go v.va.nvap. web.util.f ile; | |||||
| 2 | ||||||
| 3 | import jav a.io.Buffe redReader; | |||||
| 4 | import jav a.io.FileN otFoundExc eption; | |||||
| 5 | import jav a.io.IOExc eption; | |||||
| 6 | import jav a.io.Input Stream; | |||||
| 7 | import jav a.io.Input StreamRead er; | |||||
| 8 | import jav a.util.Arr ayList; | |||||
| 9 | import jav a.util.Has hMap; | |||||
| 10 | import jav a.util.Ite rator; | |||||
| 11 | import jav a.util.Lis t; | |||||
| 12 | import jav a.util.Map ; | |||||
| 13 | ||||||
| 14 | import org .apache.co mmons.file upload.Fil eItem; | |||||
| 15 | import org .apache.co mmons.logg ing.Log; | |||||
| 16 | import org .apache.co mmons.logg ing.LogFac tory; | |||||
| 17 | import org .apache.po i.ss.userm odel.Cell; | |||||
| 18 | import org .apache.po i.ss.userm odel.DataF ormatter; | |||||
| 19 | import org .apache.po i.ss.userm odel.Formu laEvaluato r; | |||||
| 20 | import org .apache.po i.ss.userm odel.RichT extString; | |||||
| 21 | import org .apache.po i.ss.userm odel.Row; | |||||
| 22 | import org .apache.po i.xssf.use rmodel.XSS FFormulaEv aluator; | |||||
| 23 | import org .apache.po i.xssf.use rmodel.XSS FSheet; | |||||
| 24 | import org .apache.po i.xssf.use rmodel.XSS FWorkbook; | |||||
| 25 | ||||||
| 26 | /** | |||||
| 27 | * @author Nusrath M ohammed | |||||
| 28 | * | |||||
| 29 | * Helper class to i mport Exce l and CSV files cont aining pat ients. | |||||
| 30 | * | |||||
| 31 | */ | |||||
| 32 | public cla ss FileUpl oader { | |||||
| 33 | ||||||
| 34 | static private f inal Log L OG = LogFa ctory.getL og(FileUpl oader.clas s); | |||||
| 35 | ||||||
| 36 | /** | |||||
| 37 | * Thi s method p arses CSV file with extension .csv | |||||
| 38 | * | |||||
| 39 | * @pa ram csvFil e | |||||
| 40 | * @re turn List of Map Obj ects | |||||
| 41 | * @th rows Runti meExceptio n | |||||
| 42 | */ | |||||
| 43 | public static Li st<Map<Str ing, Strin g>> readCS V(FileItem fileItem) { | |||||
| 44 | ||||||
| 45 | Bu fferedRead er br = nu ll; | |||||
| 46 | St ring line = ""; | |||||
| 47 | St ring cvsSp litBy = ", "; | |||||
| 48 | ||||||
| 49 | Li st<Map<Str ing, Strin g>> mapLis t = new Ar rayList<Ma p<String, String>>() ; | |||||
| 50 | Li st<String> headers = new Array List<Strin g>(); | |||||
| 51 | ||||||
| 52 | tr y { | |||||
| 53 | int rowN um = 0; | |||||
| 54 | br = new BufferedR eader(new InputStrea mReader(fi leItem.get InputStrea m())); | |||||
| 55 | while (( line = br. readLine() ) != null) { | |||||
| 56 | Map< String, St ring> pati entInfo = new HashMa p<String, String>(); | |||||
| 57 | // u se comma a s separato r | |||||
| 58 | Stri ng[] cells = line.sp lit(cvsSpl itBy); | |||||
| 59 | ||||||
| 60 | if ( rowNum == 0) { | |||||
| 61 | for (Strin g pd : cel ls) { | |||||
| 62 | header s.add(pd); | |||||
| 63 | } | |||||
| 64 | ||||||
| 65 | rowNum++; | |||||
| 66 | continue; | |||||
| 67 | } | |||||
| 68 | ||||||
| 69 | // Get t he map con taining po sitions of the three columns ( SSN, first name, and last name ) | |||||
| 70 | Map< String, In teger> col umnPositio ns = getCo lumnPositi ons(header s); | |||||
| 71 | ||||||
| 72 | Iter ator<Strin g> columns Iterator = columnPos itions.key Set() | |||||
| 73 | .itera tor(); | |||||
| 74 | whil e (columns Iterator.h asNext()) { | |||||
| 75 | String nam e = column sIterator. next(); | |||||
| 76 | String val ue = cells [columnPos itions.get (name)]; | |||||
| 77 | ||||||
| 78 | patientInf o.put(name , value); | |||||
| 79 | } | |||||
| 80 | ||||||
| 81 | mapL ist.add(ne w HashMap< String, St ring>(pati entInfo)); | |||||
| 82 | } | |||||
| 83 | } catch (Fil eNotFoundE xception e 1) { | |||||
| 84 | throw ne w RuntimeE xception(" File you a re trying to upload could not be found. Please try again."); | |||||
| 85 | } catch (IOE xception e 2) { | |||||
| 86 | throw ne w RuntimeE xception(" File you a re trying to upload could not be read. P lease try again."); | |||||
| 87 | } finally { | |||||
| 88 | if (br ! = null) { | |||||
| 89 | try { | |||||
| 90 | br.close() ; | |||||
| 91 | } ca tch (IOExc eption e3) { | |||||
| 92 | throw new RuntimeExc eption("Th ere was an error pro cessing th e file you are tryin g to uploa d. Please try again. "); | |||||
| 93 | } | |||||
| 94 | } | |||||
| 95 | } | |||||
| 96 | ||||||
| 97 | re turn mapLi st; | |||||
| 98 | } | |||||
| 99 | ||||||
| 100 | /** | |||||
| 101 | * Thi s method p arse Excel file with extension s xls and xlsx | |||||
| 102 | * | |||||
| 103 | * @pa ram String fileName | |||||
| 104 | * @th rows Runti meExceptio n | |||||
| 105 | */ | |||||
| 106 | public static Li st<Map<Str ing, Strin g>> readEx cel(FileIt em fileIte m) { | |||||
| 107 | ||||||
| 108 | XS SFWorkbook workbook = null; | |||||
| 109 | // a ll key val ue pair ma pping ( ho lding colu mn name an d its resp ective val ue per row . | |||||
| 110 | Li st<Map<Str ing, Strin g>> mapLis t = new Ar rayList<Ma p<String, String>>() ; | |||||
| 111 | In putStream in = null; | |||||
| 112 | tr y { | |||||
| 113 | // Get t he workboo k instance for XLS f ile | |||||
| 114 | in = fileItem. getInputSt ream(); | |||||
| 115 | workbook = new XSS FWorkbook( in); | |||||
| 116 | ||||||
| 117 | DataForm atter objD efaultForm at = new D ataFormatt er(); | |||||
| 118 | FormulaE valuator o bjFormulaE valuator = new XSSFF ormulaEval uator((XSS FWorkbook) workbook) ; | |||||
| 119 | ||||||
| 120 | // Get f irst sheet from the workbook | |||||
| 121 | XSSFShee t sheet = workbook.g etSheetAt( 0); | |||||
| 122 | ||||||
| 123 | // GET t he header row | |||||
| 124 | Row head erRow = sh eet.getRow (0); | |||||
| 125 | ||||||
| 126 | // LIst of headers from exce l | |||||
| 127 | List<Str ing> heade rs = new A rrayList<S tring>(); | |||||
| 128 | Iterator <Cell> cel ls = heade rRow.cellI terator(); | |||||
| 129 | while (c ells.hasNe xt()) { | |||||
| 130 | Cell cell = (C ell) cells .next(); | |||||
| 131 | Rich TextString value = c ell.getRic hStringCel lValue(); | |||||
| 132 | head ers.add(va lue.getStr ing()); | |||||
| 133 | } | |||||
| 134 | ||||||
| 135 | // There must be a t least 3 headers. | |||||
| 136 | if (head ers.size() < 3) { | |||||
| 137 | mapL ist = null ; | |||||
| 138 | retu rn mapList ; | |||||
| 139 | } | |||||
| 140 | ||||||
| 141 | // Get t he map con taining po sitions of the three columns ( SSN, first name, and last name ) | |||||
| 142 | Map<Stri ng, Intege r> columnP ositions = getColumn Positions( headers); | |||||
| 143 | ||||||
| 144 | // Get i terator to all the r ows in cur rent sheet | |||||
| 145 | int rowN umber = 0; | |||||
| 146 | Iterator <Row> rowI terator = sheet.iter ator(); | |||||
| 147 | while (r owIterator .hasNext() ) { | |||||
| 148 | Row row = (Row ) rowItera tor.next() ; | |||||
| 149 | if ( rowNumber == 0) { | |||||
| 150 | rowNumber+ +; | |||||
| 151 | continue; | |||||
| 152 | } | |||||
| 153 | ||||||
| 154 | Map< String, St ring> pati entInfo = new HashMa p<String, String>(); | |||||
| 155 | ||||||
| 156 | Iter ator<Strin g> columns Iterator = columnPos itions.key Set().iter ator(); | |||||
| 157 | whil e (columns Iterator.h asNext()) { | |||||
| 158 | String nam e = column sIterator. next(); | |||||
| 159 | Cell cellV alue = row .getCell(c olumnPosit ions.get(n ame)); | |||||
| 160 | // This wi ll evaluat e the cell , And any type of ce ll will re turn strin g value | |||||
| 161 | objFormula Evaluator. evaluate(c ellValue); | |||||
| 162 | ||||||
| 163 | String cel lValueStr = objDefau ltFormat.f ormatCellV alue(cellV alue, objF ormulaEval uator); | |||||
| 164 | ||||||
| 165 | patientInf o.put(name , cellValu eStr); | |||||
| 166 | } | |||||
| 167 | mapL ist.add(pa tientInfo) ; | |||||
| 168 | } | |||||
| 169 | ||||||
| 170 | } catch (Fil eNotFoundE xception e 1) { | |||||
| 171 | throw ne w RuntimeE xception(" File you a re trying to upload could not be found. Please try again."); | |||||
| 172 | } catch (IOE xception e 2) { | |||||
| 173 | throw ne w RuntimeE xception(" File you a re trying to upload could not be read. P lease try again."); | |||||
| 174 | } finally { | |||||
| 175 | if (work book != nu ll) { | |||||
| 176 | try { | |||||
| 177 | workbook.c lose(); | |||||
| 178 | } ca tch (Excep tion e3) { | |||||
| 179 | throw new RuntimeExc eption("Th ere was an error pro cessing th e file you are tryin g to uploa d. Please try again. "); | |||||
| 180 | } | |||||
| 181 | } | |||||
| 182 | if (in ! = null) { | |||||
| 183 | try { | |||||
| 184 | in.close() ; | |||||
| 185 | } ca tch (Excep tion e3) { | |||||
| 186 | throw new RuntimeExc eption("Th ere was an error pro cessing th e file you are tryin g to uploa d. Please try again. "); | |||||
| 187 | } | |||||
| 188 | } | |||||
| 189 | } | |||||
| 190 | ||||||
| 191 | re turn mapLi st; | |||||
| 192 | } | |||||
| 193 | ||||||
| 194 | /** | |||||
| 195 | * Get s the map containing positions of the th ree column s (SSN, fi rst name, and last n ame) | |||||
| 196 | * | |||||
| 197 | * @pa ram header s | |||||
| 198 | * @re turn Map | |||||
| 199 | */ | |||||
| 200 | privat e static M ap<String, Integer> getColumnP ositions(L ist<String > headers) { | |||||
| 201 | Ma p<String, Integer> p ositions = new HashM ap<String, Integer>( ); | |||||
| 202 | in t i = 0; | |||||
| 203 | ||||||
| 204 | fo r (String columnName : headers ) { | |||||
| 205 | ||||||
| 206 | if (colu mnName.toL owerCase() .contains( "ssn")) { | |||||
| 207 | posi tions.put( "ssn", i); | |||||
| 208 | } else i f (columnN ame.toLowe rCase().co ntains("fi rst")) { | |||||
| 209 | posi tions.put( "firstname ", i); | |||||
| 210 | } else i f (columnN ame.toLowe rCase().co ntains("la st")) { | |||||
| 211 | posi tions.put( "lastname" , i); | |||||
| 212 | } | |||||
| 213 | i++; | |||||
| 214 | } | |||||
| 215 | ||||||
| 216 | re turn posit ions; | |||||
| 217 | } | |||||
| 218 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.