Produced by Araxis Merge on 12/5/2017 12:06:51 PM Central Standard 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 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\VixGuiWebApp\main\src\java\gov\va\med\imaging\exchange | ExcelTransactionLog.java | Mon Dec 4 21:34:30 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\VixGuiWebApp\main\src\java\gov\va\med\imaging\exchange | ExcelTransactionLog.java | Mon Dec 4 22:07:28 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 1652 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| 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.med.i maging.exc hange; | |
| 2 | ||
| 3 | import gov .va.med.im aging.Date Util; | |
| 4 | import gov .va.med.im aging.acce ss.Transac tionLogEnt ry; | |
| 5 | import gov .va.med.im aging.acce ss.Transac tionLogWri ter; | |
| 6 | import gov .va.med.im aging.core .FacadeRou terUtility ; | |
| 7 | import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception; | |
| 8 | //import g ov.va.med. imaging.ac cess.Trans actionLogE ntry; | |
| 9 | //import g ov.va.med. imaging.Ba seWebFacad eRouter; | |
| 10 | //import g ov.va.med. imaging.co re.FacadeR outerUtili ty; | |
| 11 | import gov .va.med.im aging.exch ange.enums .Datasourc eProtocol; | |
| 12 | import gov .va.med.im aging.exch ange.enums .ImageQual ity; | |
| 13 | ||
| 14 | import jav a.io.IOExc eption; | |
| 15 | import jav a.io.Outpu tStream; | |
| 16 | import jav a.io.Print Writer; | |
| 17 | import jav a.lang.ref lect.Metho d; | |
| 18 | import jav a.text.Dat eFormat; | |
| 19 | import jav a.text.Par seExceptio n; | |
| 20 | import jav a.text.Sim pleDateFor mat; | |
| 21 | import jav a.util.Dat e; | |
| 22 | ||
| 23 | import jav ax.servlet .ServletEx ception; | |
| 24 | import jav ax.servlet .http.Http Servlet; | |
| 25 | import jav ax.servlet .http.Http ServletReq uest; | |
| 26 | import jav ax.servlet .http.Http ServletRes ponse; | |
| 27 | ||
| 28 | import jxl .Workbook; | |
| 29 | import jxl .write.Lab el; | |
| 30 | import jxl .write.Wri tableSheet ; | |
| 31 | import jxl .write.Wri tableWorkb ook; | |
| 32 | import jxl .write.Wri teExceptio n; | |
| 33 | import jxl .write.bif f.RowsExce ededExcept ion; | |
| 34 | ||
| 35 | import org .apache.lo gging.log4 j.LogManag er; | |
| 36 | import org .apache.lo gging.log4 j.Logger; | |
| 37 | import org .springfra mework.con text.Appli cationCont ext; | |
| 38 | import org .springfra mework.web .context.s upport.Web Applicatio nContextUt ils; | |
| 39 | ||
| 40 | /** | |
| 41 | * | |
| 42 | * @author
|
|
| 43 | * | |
| 44 | */ | |
| 45 | public cla ss ExcelTr ansactionL og | |
| 46 | extends Ht tpServlet | |
| 47 | { | |
| 48 | pr ivate stat ic final l ong serial VersionUID = 1L; | |
| 49 | pr ivate Logg er logger = LogManag er.getLogg er(getClas s()); | |
| 50 | /* * | |
| 51 | * Construct or of the object. | |
| 52 | * / | |
| 53 | pu blic Excel Transactio nLog() | |
| 54 | { | |
| 55 | supe r(); | |
| 56 | } | |
| 57 | ||
| 58 | /* * | |
| 59 | * Initializ ation of t he servlet . <br> | |
| 60 | * | |
| 61 | * @throws S ervletExce ption if a n error oc curs | |
| 62 | * / | |
| 63 | pu blic void init() | |
| 64 | th rows Servl etExceptio n | |
| 65 | { | |
| 66 | // P ut your co de here | |
| 67 | } | |
| 68 | ||
| 69 | /* * | |
| 70 | * Returns i nformation about the servlet, such as | |
| 71 | * author, v ersion, an d copyrigh t. | |
| 72 | * | |
| 73 | * @return S tring info rmation ab out this s ervlet | |
| 74 | * / | |
| 75 | pu blic Strin g getServl etInfo() | |
| 76 | { | |
| 77 | retu rn "Transa ction Log CSV and XL S Generati on Servlet "; | |
| 78 | } | |
| 79 | ||
| 80 | // the first date form at in the array | |
| 81 | pr ivate Date Format[] d ateFormats = new Dat eFormat[] | |
| 82 | { | |
| 83 | new Si mpleDateFo rmat("MM/d d/yyyy"), | |
| 84 | new Si mpleDateFo rmat("ddMM yyyy") | |
| 85 | }; | |
| 86 | ||
| 87 | pr ivate Date parseDate (String st ringDate) | |
| 88 | { | |
| 89 | for( DateFormat df : date Formats) | |
| 90 | { | |
| 91 | try | |
| 92 | { | |
| 93 | Date dat e = df.par se(stringD ate); | |
| 94 | return d ate; | |
| 95 | } | |
| 96 | catch (ParseExce ption e) | |
| 97 | { | |
| 98 | } | |
| 99 | } | |
| 100 | retu rn null; | |
| 101 | } | |
| 102 | ||
| 103 | pr ivate Appl icationCon text getAp plicationC ontext() | |
| 104 | { | |
| 105 | retu rn WebAppl icationCon textUtils. getRequire dWebApplic ationConte xt(this.ge tServletCo ntext()); | |
| 106 | } | |
| 107 | ||
| 108 | /* * | |
| 109 | * The doGet method of the servl et. <br> | |
| 110 | * | |
| 111 | * This meth od is call ed when a form has i ts tag val ue method equals to get. | |
| 112 | * | |
| 113 | * @param re quest the request se nd by the client to the server | |
| 114 | * @param re sponse the response send by th e server t o the clie nt | |
| 115 | * @throws S ervletExce ption if a n error oc curred | |
| 116 | * @throws I OException if an err or occurre d | |
| 117 | * / | |
| 118 | pu blic void doGet(Http ServletReq uest reque st, HttpSe rvletRespo nse respon se) | |
| 119 | th rows Servl etExceptio n, IOExcep tion | |
| 120 | { | |
| 121 | Date Format dfD ateOnly = new Simple DateFormat ("MM/dd/yy yy"); | |
| 122 | ||
| 123 | Date fromDate = DateUtil .currentDa yStart(); | |
| 124 | Stri ng fromDat eParam = r equest.get Parameter( "fromDate" ); | |
| 125 | if(f romDatePar am != null ) | |
| 126 | try{fr omDate = d fDateOnly. parse( fro mDateParam );} | |
| 127 | catc h(ParseExc eption pX) {logger.er ror("Error parsing f romDate, u sing defau lt value o f today"); } | |
| 128 | from DateParam =dfDateOnl y.format(f romDate); | |
| 129 | ||
| 130 | Date toDate = DateUtil.c urrentDayE nd(); | |
| 131 | Stri ng toDateP aram = req uest.getPa rameter("t oDate"); | |
| 132 | if(t oDateParam != null) | |
| 133 | try{to Date = dfD ateOnly.pa rse( toDat eParam );} | |
| 134 | catc h(ParseExc eption pX) {logger.er ror("Error parsing t oDate, usi ng default value of today");} | |
| 135 | toDa te = DateU til.dayEnd (toDate); | |
| 136 | toDa teParam = dfDateOnly .format(to Date); | |
| 137 | ||
| 138 | Stri ng imageQu alityParam = request .getParame ter("image Quality"); | |
| 139 | Imag eQuality i mageQualit y = null; | |
| 140 | if(i mageQualit yParam != null) | |
| 141 | { | |
| 142 | try{im ageQuality = ImageQu ality.valu eOf(imageQ ualityPara m);} | |
| 143 | catch( IllegalArg umentExcep tion iaX){ imageQuali ty = null; } | |
| 144 | } | |
| 145 | Stri ng user = request.ge tParameter ("user"); | |
| 146 | Stri ng modalit y = reques t.getParam eter("moda lity"); | |
| 147 | ||
| 148 | Stri ng datasou rceProtoco lParam = r equest.get Parameter( "datasourc eProtocol" ); | |
| 149 | Data sourceProt ocol datas ourceProto col = null ; | |
| 150 | if(d atasourceP rotocolPar am != null ) | |
| 151 | { | |
| 152 | try{ d atasourceP rotocol = Datasource Protocol.v alueOf(dat asourcePro tocolParam ); } | |
| 153 | catch( IllegalArg umentExcep tion iaX){ datasource Protocol = null;} | |
| 154 | } | |
| 155 | ||
| 156 | Stri ng errorMe ssage = re quest.getP arameter(" errorMessa ge"); | |
| 157 | Stri ng transac tionId = r equest.get Parameter( "transacti onId"); | |
| 158 | Stri ng imageUr n = reques t.getParam eter("imag eUrn"); | |
| 159 | ||
| 160 | Stri ng transac tionIdOnly = request .getParame ter("trans actionIdOn ly"); | |
| 161 | if(t ransaction IdOnly != null && | |
| 162 | transact ionId != n ull && | |
| 163 | "true".e qualsIgnor eCase(tran sactionIdO nly)) | |
| 164 | { | |
| 165 | // onl y want to get this o ne transac tion so nu ll out eve rything el se | |
| 166 | fromDa te = null; | |
| 167 | toDate = null; | |
| 168 | imageQ uality = n ull; | |
| 169 | user = null; | |
| 170 | modali ty = null; | |
| 171 | dataso urceProtoc ol = null; | |
| 172 | errorM essage = n ull; | |
| 173 | imageU rn = null; | |
| 174 | } | |
| 175 | ||
| 176 | Stri ng acceptT ype = requ est.getHea der("accep t"); | |
| 177 | ||
| 178 | Cont entType co ntentType = request. getParamet er("format ") == null ? | |
| 179 | ContentT ype.getByA cceptHeade r(acceptTy pe) : | |
| 180 | ContentTyp e.getByAcc eptHeader( request.ge tParameter ("format") ); | |
| 181 | response .setConten tType(cont entType.ge tMimeType( )); | |
| 182 | ||
| 183 | try | |
| 184 | { | |
| 185 | if(content Type == Co ntentType. XLS) | |
| 186 | { | |
| 187 | re sponse.set Header("Co ntent-Disp osition", "attachmen t; filenam e=\"Transa ctionLogs. xls\""); | |
| 188 | st reamConten tAsXLS(res ponse.getO utputStrea m(), fromD ate, toDat e, | |
| 189 | imageQ uality, us er, modali ty, dataso urceProtoc ol, errorM essage, | |
| 190 | imageU rn, transa ctionId); | |
| 191 | re sponse.get OutputStre am().flush (); | |
| 192 | } | |
| 193 | else if(co ntentType == Content Type.CSV) | |
| 194 | { | |
| 195 | re sponse.set Header("Co ntent-Disp osition", "attachmen t; filenam e=\"Transa ctionLogs. csv\""); | |
| 196 | st reamConten tAsCSV(res ponse.getW riter(), f romDate, t oDate, ima geQuality, user, | |
| 197 | modali ty, dataso urceProtoc ol, errorM essage, im ageUrn, tr ansactionI d); | |
| 198 | re sponse.get Writer().f lush(); | |
| 199 | } | |
| 200 | else if(co ntentType == Content Type.TSV) | |
| 201 | { | |
| 202 | re sponse.set Header("Co ntent-Disp osition", "attachmen t; filenam e=\"Transa ctionLogs. tsv\""); | |
| 203 | st reamConten tAsTSV(res ponse.getW riter(), f romDate, t oDate, ima geQuality, user, | |
| 204 | modali ty, dataso urceProtoc ol, errorM essage, im ageUrn, tr ansactionI d); | |
| 205 | re sponse.get Writer().f lush(); | |
| 206 | } | |
| 207 | } | |
| 208 | catch (R owsExceede dException e) | |
| 209 | { | |
| 210 | throw new ServletExc eption(e); | |
| 211 | } | |
| 212 | catch (W riteExcept ion e) | |
| 213 | { | |
| 214 | throw new ServletExc eption(e); | |
| 215 | } | |
| 216 | catch (I OException iox) | |
| 217 | { | |
| 218 | throw new ServletExc eption(iox ); | |
| 219 | } | |
| 220 | } | |
| 221 | ||
| 222 | /* * | |
| 223 | * | |
| 224 | * @param ou t | |
| 225 | * @param co ntentType | |
| 226 | * @param st artDate | |
| 227 | * @param en dDate | |
| 228 | * @param im ageQuality | |
| 229 | * @param us er | |
| 230 | * @param mo dality | |
| 231 | * @param da tasourcePr otocol | |
| 232 | * @throws I OException | |
| 233 | * @throws W riteExcept ion | |
| 234 | * @throws R owsExceede dException | |
| 235 | * / | |
| 236 | pr ivate void streamCon tentAsXLS( | |
| 237 | Output Stream out , | |
| 238 | Date s tartDate, | |
| 239 | Date e ndDate, | |
| 240 | ImageQ uality ima geQuality, | |
| 241 | String user, | |
| 242 | String modality, | |
| 243 | Dataso urceProtoc ol datasou rceProtoco l, | |
| 244 | String errorMess age, | |
| 245 | String imageUrn, | |
| 246 | String transacti onId) | |
| 247 | th rows IOExc eption, Ro wsExceeded Exception, WriteExce ption | |
| 248 | { | |
| 249 | Writ ableWorkbo ok workboo k = Workbo ok.createW orkbook(ou t); | |
| 250 | ||
| 251 | Writ ableSheet sheet = wo rkbook.cre ateSheet(" Transactio n Log", 0) ; | |
| 252 | ||
| 253 | writ eTitleCell s(sheet); | |
| 254 | ||
| 255 | try | |
| 256 | { | |
| 257 | XlsTra nsactionLo gWriter xl sWriter = new XlsTra nsactionLo gWriter(sh eet); | |
| 258 | VixGui WebAppRout er router = FacadeRo uterUtilit y.getFacad eRouter (V ixGuiWebAp pRouter.cl ass); | |
| 259 | if(sta rtDate == null && | |
| 260 | endDate == null && | |
| 261 | imageQuali ty == null && | |
| 262 | user == nu ll && | |
| 263 | modality = = null && | |
| 264 | datasource Protocol = = null && | |
| 265 | errorMessa ge == null && | |
| 266 | imageUrn = = null && | |
| 267 | transactio nId != nul l) | |
| 268 | { | |
| 269 | router.g etTransact ionLogEntr iesByTrans actionId(x lsWriter, transactio nId); | |
| 270 | } | |
| 271 | else | |
| 272 | { | |
| 273 | router.g etTransact ionLogEntr ies(xlsWri ter, start Date, endD ate, image Quality, u ser, modal ity, | |
| 274 | da tasourcePr otocol, er rorMessage , imageUrn , transact ionId, new Boolean ( true), nul l, null); | |
| 275 | } | |
| 276 | } | |
| 277 | ||
| 278 | catc h (Excepti on x) | |
| 279 | { | |
| 280 | throw new IOExce ption (x); | |
| 281 | } | |
| 282 | ||
| 283 | work book.write (); | |
| 284 | work book.close (); | |
| 285 | } | |
| 286 | ||
| 287 | pr ivate void writeTitl eCells(Wri tableSheet sheet) | |
| 288 | th rows RowsE xceededExc eption, Wr iteExcepti on | |
| 289 | { | |
| 290 | for( Columns co lumn : Col umns.value s()) | |
| 291 | sheet. addCell( n ew Label(c olumn.ordi nal(), 0, column.get ColumnHead er()) ); | |
| 292 | } | |
| 293 | ||
| 294 | pr ivate void streamCon tentAsCSV( | |
| 295 | PrintW riter writ er, | |
| 296 | Date s tartDate, | |
| 297 | Date e ndDate, | |
| 298 | ImageQ uality ima geQuality, | |
| 299 | String user, | |
| 300 | String modality, | |
| 301 | Dataso urceProtoc ol datasou rceProtoco l, | |
| 302 | String errorMess age, | |
| 303 | String imageUrn, | |
| 304 | String transacti onId) | |
| 305 | th rows IOExc eption, Ro wsExceeded Exception, WriteExce ption | |
| 306 | { | |
| 307 | ||
| 308 | Stri ng fieldDe limiter = ","; | |
| 309 | Stri ng recordD elimiter = System.ge tProperty( "line.sepa rator"); | |
| 310 | writ eDelimited Headers(wr iter, fiel dDelimiter , recordDe limiter); | |
| 311 | ||
| 312 | try | |
| 313 | { | |
| 314 | VixGui WebAppRout er router = FacadeRo uterUtilit y.getFacad eRouter (V ixGuiWebAp pRouter.cl ass); | |
| 315 | Transa ctionLogWr iter trans actionLogW riter = ne w Delimite dTransacti onLogWrite r(writer, | |
| 316 | fieldDelim iter, reco rdDelimite r); | |
| 317 | if(sta rtDate == null && | |
| 318 | endDate == null && | |
| 319 | imageQuali ty == null && | |
| 320 | user == nu ll && | |
| 321 | modality = = null && | |
| 322 | datasource Protocol = = null && | |
| 323 | errorMessa ge == null && | |
| 324 | imageUrn = = null && | |
| 325 | transactio nId != nul l) | |
| 326 | { | |
| 327 | router.g etTransact ionLogEntr iesByTrans actionId(t ransaction LogWriter, transacti onId); | |
| 328 | } | |
| 329 | else | |
| 330 | { | |
| 331 | router.g etTransact ionLogEntr ies(transa ctionLogWr iter, star tDate, end Date, | |
| 332 | im ageQuality , user, mo dality, da tasourcePr otocol, er rorMessage , imageUrn , | |
| 333 | tr ansactionI d, new Boo lean (true ), null, n ull); | |
| 334 | } | |
| 335 | } | |
| 336 | ||
| 337 | catc h (Excepti on x) | |
| 338 | { | |
| 339 | throw new IOExce ption (x); | |
| 340 | } | |
| 341 | } | |
| 342 | ||
| 343 | pr ivate void streamCon tentAsTSV( | |
| 344 | PrintW riter writ er, | |
| 345 | Date s tartDate, | |
| 346 | Date e ndDate, | |
| 347 | ImageQ uality ima geQuality, | |
| 348 | String user, | |
| 349 | String modality, | |
| 350 | Dataso urceProtoc ol datasou rceProtoco l, | |
| 351 | String errorMess age, | |
| 352 | String imageUrn, | |
| 353 | String transacti onId) | |
| 354 | th rows IOExc eption, Ro wsExceeded Exception, WriteExce ption | |
| 355 | { | |
| 356 | ||
| 357 | Stri ng fieldDe limiter = "\t"; | |
| 358 | Stri ng recordD elimiter = System.ge tProperty( "line.sepa rator"); | |
| 359 | writ eDelimited Headers(wr iter, fiel dDelimiter , recordDe limiter); | |
| 360 | ||
| 361 | try | |
| 362 | { | |
| 363 | VixGui WebAppRout er router = FacadeRo uterUtilit y.getFacad eRouter (V ixGuiWebAp pRouter.cl ass); | |
| 364 | Transa ctionLogWr iter trans actionLogW riter = ne w Delimite dTransacti onLogWrite r(writer, | |
| 365 | fieldDelim iter, reco rdDelimite r); | |
| 366 | if(sta rtDate == null && | |
| 367 | endDate == null && | |
| 368 | imageQuali ty == null && | |
| 369 | user == nu ll && | |
| 370 | modality = = null && | |
| 371 | datasource Protocol = = null && | |
| 372 | errorMessa ge == null && | |
| 373 | imageUrn = = null && | |
| 374 | transactio nId != nul l) | |
| 375 | { | |
| 376 | router.g etTransact ionLogEntr iesByTrans actionId(t ransaction LogWriter, transacti onId); | |
| 377 | } | |
| 378 | else | |
| 379 | { | |
| 380 | router.g etTransact ionLogEntr ies(transa ctionLogWr iter, star tDate, end Date, | |
| 381 | im ageQuality , user, mo dality, da tasourcePr otocol, er rorMessage , imageUrn , | |
| 382 | tr ansactionI d, new Boo lean (true ), null, n ull); | |
| 383 | } | |
| 384 | } | |
| 385 | ||
| 386 | catc h (Excepti on x) | |
| 387 | { | |
| 388 | throw new IOExce ption (x); | |
| 389 | } | |
| 390 | } | |
| 391 | ||
| 392 | /* * | |
| 393 | * @param wr iter | |
| 394 | * @param fi eldDelimit er | |
| 395 | * @param re cordDelimi ter | |
| 396 | * @param el Enumeratio n | |
| 397 | * / | |
| 398 | /* | |
| 399 | pr ivate void writeDeli mitedConte nt( | |
| 400 | PrintW riter writ er, | |
| 401 | String fieldDeli miter, | |
| 402 | String recordDel imiter, | |
| 403 | Enumer ation<Tran sactionLog Entry> elE numeration ) | |
| 404 | { | |
| 405 | whil e( elEnume ration.has MoreElemen ts() ) | |
| 406 | { | |
| 407 | Transa ctionLogEn try logEnt ry = elEnu meration.n extElement (); | |
| 408 | writeD elimitedEn try(writer , fieldDel imiter, re cordDelimi ter, logEn try); | |
| 409 | } | |
| 410 | } | |
| 411 | ||
| 412 | pr ivate void writeDeli mitedEntry (PrintWrit er writer, String fi eldDelimit er, | |
| 413 | String recordDel imiter, Tr ansactionL ogEntry lo gEntry) | |
| 414 | { | |
| 415 | int columnInde x = 0; | |
| 416 | for( Columns co lumn : Col umns.value s()) | |
| 417 | { | |
| 418 | if(col umnIndex ! = 0) | |
| 419 | writer.w rite(field Delimiter) ; | |
| 420 | try | |
| 421 | { | |
| 422 | Method a ccessor = column.get AccessorMe thod(); | |
| 423 | if( acce ssor != nu ll) | |
| 424 | { | |
| 425 | Object val ue = acces sor.invoke (logEntry, (Object[] )null); | |
| 426 | ColumnForm atter form atter = co lumn.getCo lumnFormat ter(); | |
| 427 | // wrap fo rmatted an d unformat ted values in double quotes | |
| 428 | if(formatt er != null ) | |
| 429 | wr iter.write ( "\"" + f ormatter.f ormatColum nValue(val ue) + "\"" ); | |
| 430 | else | |
| 431 | wr iter.write ( value == null ? "" : "\"" + value.toSt ring() + " \"" ); | |
| 432 | } | |
| 433 | else | |
| 434 | writer.wri te(""); | |
| 435 | ||
| 436 | } | |
| 437 | catch( Exception e) | |
| 438 | { | |
| 439 | logger.w arn(e); | |
| 440 | e.printS tackTrace( ); | |
| 441 | writer.w rite( e == null ? | |
| 442 | "< ERROR>" : e.getMessa ge() == nu ll ? | |
| 443 | e.getC lass().get SimpleName () : e.get Message() ); | |
| 444 | } | |
| 445 | ++colu mnIndex; | |
| 446 | } | |
| 447 | writ er.write(r ecordDelim iter); | |
| 448 | }* / | |
| 449 | ||
| 450 | pr ivate void writeDeli mitedHeade rs( | |
| 451 | PrintW riter writ er, | |
| 452 | String fieldDeli miter, | |
| 453 | String recordDel imiter) | |
| 454 | { | |
| 455 | bool ean firstC olumn = tr ue; | |
| 456 | int columnCoun t = Column s.values() .length; | |
| 457 | int currentCol umn = 0; | |
| 458 | for( Columns co lumn : Col umns.value s()) | |
| 459 | { | |
| 460 | curren tColumn++; | |
| 461 | writer .write( co lumn.getCo lumnHeader () ); | |
| 462 | if(cur rentColumn < columnC ount) | |
| 463 | { | |
| 464 | writer.w rite(field Delimiter) ; | |
| 465 | } | |
| 466 | /* | |
| 467 | if(fir stColumn) | |
| 468 | { | |
| 469 | firstCol umn = fals e; | |
| 470 | writer.w rite(field Delimiter) ; | |
| 471 | } | |
| 472 | writer .write( co lumn.getCo lumnHeader () ); | |
| 473 | */ | |
| 474 | } | |
| 475 | writ er.write(r ecordDelim iter); | |
| 476 | } | |
| 477 | ||
| 478 | /* * | |
| 479 | * Destructi on of the servlet. < br> | |
| 480 | * / | |
| 481 | pu blic void destroy() | |
| 482 | { | |
| 483 | supe r.destroy( ); | |
| 484 | } | |
| 485 | ||
| 486 | pu blic enum ContentTyp e | |
| 487 | { | |
| 488 | XLS( "applicati on/vnd-ms- excel"), | |
| 489 | CSV( "text/csv" ), | |
| 490 | TSV( "text/tab- separated- values"); | |
| 491 | ||
| 492 | priv ate String mimeType; | |
| 493 | ||
| 494 | Cont entType(St ring mimeT ype) | |
| 495 | { | |
| 496 | this.m imeType = mimeType; | |
| 497 | } | |
| 498 | ||
| 499 | publ ic String getMimeTyp e() | |
| 500 | { | |
| 501 | return mimeType; | |
| 502 | } | |
| 503 | ||
| 504 | stat ic Content Type getBy AcceptHead er(String acceptHead er) | |
| 505 | { | |
| 506 | if(acc eptHeader == null) | |
| 507 | return C ontentType .XLS; | |
| 508 | ||
| 509 | accept Header = a cceptHeade r.toLowerC ase(); | |
| 510 | String [] acceptH eaderValue s = accept Header.spl it(","); | |
| 511 | ||
| 512 | for(St ring accep tHeaderVal ue : accep tHeaderVal ues) | |
| 513 | for( Con tentType c ontentType : Content Type.value s() ) | |
| 514 | if( accept HeaderValu e.indexOf( contentTyp e.getMimeT ype()) >= 0 ) | |
| 515 | re turn conte ntType; | |
| 516 | ||
| 517 | return ContentTy pe.XLS; | |
| 518 | } | |
| 519 | } | |
| 520 | ||
| 521 | /* * | |
| 522 | * An interf ace for cl asses that format in dividual c olumns of the | |
| 523 | * spreadshe et. These may be ge neric to t ype or spe cific to a column. | |
| 524 | * The forma tting is c alled when doing tex t (CSV, TS V) output. | |
| 525 | * @param <T > | |
| 526 | * / | |
| 527 | st atic inter face Colum nFormatter <T> | |
| 528 | { | |
| 529 | Stri ng formatC olumnValue (T columnV alue); | |
| 530 | } | |
| 531 | ||
| 532 | /* * | |
| 533 | * A definit ion for ge neric type conversio n. An ins tance of t his may be | |
| 534 | * assigned to each co lumn. The conversio n for each column wi ll be call ed | |
| 535 | * when buil ding an XL S output. | |
| 536 | * | |
| 537 | * @param <S > - source type | |
| 538 | * @param <D > - destin ation | |
| 539 | * / | |
| 540 | st atic inter face Colum nTypeConve rter<S, D> | |
| 541 | { | |
| 542 | D co nvert(S va lue); | |
| 543 | } | |
| 544 | ||
| 545 | /* * | |
| 546 | * A column formatter for date c olumns sto red as Lon g values | |
| 547 | * / | |
| 548 | st atic class DateAsLon gColumnFor matter | |
| 549 | im plements C olumnForma tter<Long> | |
| 550 | { | |
| 551 | // t he first d ate format in the ar ray | |
| 552 | priv ate DateFo rmat dateF ormat = ne w SimpleDa teFormat(" yyyy-MM-dd HH:mm:ss. SSS"); | |
| 553 | ||
| 554 | @Ove rride | |
| 555 | publ ic String formatColu mnValue(Lo ng columnV alue) | |
| 556 | { | |
| 557 | if(col umnValue = = null) | |
| 558 | return " "; | |
| 559 | Date d ate = new Date(colum nValue.lon gValue()); | |
| 560 | return dateForma t.format(d ate); | |
| 561 | } | |
| 562 | ||
| 563 | } | |
| 564 | ||
| 565 | st atic class RemoveTab AndNewline Formatter | |
| 566 | im plements C olumnForma tter<Strin g> | |
| 567 | { | |
| 568 | @Ove rride | |
| 569 | publ ic String formatColu mnValue(St ring value ) | |
| 570 | { | |
| 571 | String formatted Value = (v alue == nu ll ? "" : value); | |
| 572 | if (va lue != nul l) | |
| 573 | { | |
| 574 | formatte dValue = f ormattedVa lue.replac e('\n',' ' ); | |
| 575 | formatte dValue = f ormattedVa lue.replac e('\t',' ' ); | |
| 576 | } | |
| 577 | return formatted Value; | |
| 578 | } | |
| 579 | } | |
| 580 | ||
| 581 | st atic class LongToDat eConverter | |
| 582 | im plements C olumnTypeC onverter<L ong, Date> | |
| 583 | { | |
| 584 | @Ove rride | |
| 585 | publ ic Date co nvert(Long value) | |
| 586 | { | |
| 587 | return value == null ? nul l : new Da te(value.l ongValue() ); | |
| 588 | } | |
| 589 | ||
| 590 | } | |
| 591 | ||
| 592 | pu blic enum Columns | |
| 593 | { | |
| 594 | Tran sactionTim e("Date an d Time", " getStartTi me", new D ateAsLongC olumnForma tter(), ne w LongToDa teConverte r()), | |
| 595 | Dura tion("Time on ViX (m sec)", "ge tElapsedTi me", null, null), | |
| 596 | Pati entICN("Pa tient ICN" , "getPati entIcn", n ull, null) , | |
| 597 | Quer yType("Que ry Type", "getQueryT ype", null , null), | |
| 598 | Quer yFilter("Q uery Filte r", "getQu eryFilter" , null, nu ll), | |
| 599 | Asyn chronousCo mmand("Asy nchronous? ", "isAsyn chronousCo mmand", nu ll, null), | |
| 600 | Item sReturned( "Items (Si ze) Return ed", "getI temCount", null, nul l), | |
| 601 | Data SourceItem sReceived( "Data Sour ce Items R eceived", "getDataSo urceItemsR eceived", null, null ), | |
| 602 | Faca deBytesRet urned("Fac ade Bytes Returned", "getFacad eBytesSent ", null, n ull), | |
| 603 | Data SourceByte sReceived( "DataSourc e Bytes Re ceived", " getDataSou rceBytesRe ceived", n ull, null) , | |
| 604 | Imag eQuality(" Quality", "getQualit y", null, null), | |
| 605 | Comm andClassNa me("Comman d Class Na me", "getC ommandClas sName", nu ll, null), | |
| 606 | Orig inatingHos t("Origina ting IP Ad dress", "g etOriginat ingHost", null, null ), | |
| 607 | User ("User", " getUser", null, null ), | |
| 608 | Cach eHit("Item in cache? ", "isCach eHit", nul l, null), | |
| 609 | Erro rMessage(" Error Mess age", "get ErrorMessa ge", new R emoveTabAn dNewlineFo rmatter(), null), | |
| 610 | Moda lity("Moda lity", "ge tModality" , null, nu ll), | |
| 611 | Purp oseOfUse(" Purpose of Use", "ge tPurposeOf Use", null , null), | |
| 612 | Data sourceProt ocol("Data source Pro tocol", "g etDatasour ceProtocol ", null, n ull), | |
| 613 | Resp onseCode(" Response C ode", "get ResponseCo de", null, null), | |
| 614 | Real mSiteNumbe r("Realm S ite Number ", "getRea lmSiteNumb er", null, null), | |
| 615 | URN( "URN", "ge tUrn", nul l, null), | |
| 616 | Tran sactionNum ber("Trans action Num ber", "get Transactio nId", null , null), | |
| 617 | VixS oftwareVer sion("Vix Software V ersion", " getVixSoft wareVersio n", null, null), | |
| 618 | Remo teLoginMet hod("VistA Login Met hod", "get RemoteLogi nMethod", null, null ), | |
| 619 | Faca deBytesRec eived("Fac ade Bytes Received", "getFacad eBytesRece ived", nul l, null), | |
| 620 | Data SourceByte sReturned( "DataSourc e Bytes Re turned", " getDataSou rceBytesSe nt", null, null), | |
| 621 | Mach ineName("M achine Nam e", "getMa chineName" , null, nu ll), | |
| 622 | Requ estingSite ("Requesti ng Site", "getReques tingSite", null, nul l), | |
| 623 | Exce ptionClass Name("Exce ption Clas s Name", " getExcepti onClassNam e", null, null), | |
| 624 | Time ToFirstByt e("Time To First Byt e", "getTi meToFirstB yte", null , null), | |
| 625 | Resp ondingSite ("Respondi ng Site", "getRespon dingSite", null, nul l), | |
| 626 | Comm andId("Com mand ID", "getComman dId", null , null), | |
| 627 | Pare ntCommandI d("Parent Command ID ", "getPar entCommand Id", null, null), | |
| 628 | Faca deImageFor matSent("F acade Imag e Format S ent", "get FacadeImag eFormatSen t", null, null), | |
| 629 | Faca deImageQua litySent(" Facade Ima ge Quality Sent", "g etFacadeIm ageQuality Sent", nul l, null), | |
| 630 | Data SourceImag eFormatRec eived("Dat a Source I mage Forma t Received ", "getDat aSourceIma geFormatRe ceived", n ull, null) , | |
| 631 | Data SourceImag eQualityRe ceived("Da ta Source Image Qual ity Receiv ed", "getD ataSourceI mageQualit yReceived" , null, nu ll), | |
| 632 | Clie ntVersion( "Client Ve rsion", "g etClientVe rsion", nu ll, null), | |
| 633 | Data SourceMeth od("Data S ource Meth od", "getD ataSourceM ethod", nu ll, null), | |
| 634 | Data SourceVers ion("Data Source Ver sion", "ge tDataSourc eVersion", null, nul l), | |
| 635 | Debu gInformati on("Debug Informatio n", "getDe bugInforma tion", new RemoveTab AndNewline Formatter( ), null), | |
| 636 | Data SourceResp onseServer ("Data Sou rce Respon se Server" , "getData SourceResp onseServer ", null, n ull), | |
| 637 | Thre adId("Thre ad ID", "g etThreadId ", null, n ull), | |
| 638 | VixS iteNumber( "VIX Site Number", " getVixSite Number", n ull, null) , | |
| 639 | Requ estingVixS iteNumber( "Requestin g VIX Site Number", "getReques tingVixSit eNumber", null, null ); | |
| 640 | ||
| 641 | ||
| 642 | priv ate final String col umnHeader; | |
| 643 | priv ate Method accessorM ethod; | |
| 644 | priv ate final ColumnForm atter<?> c olumnForma tter; | |
| 645 | priv ate final ColumnType Converter< ?, ?> type Converter; | |
| 646 | ||
| 647 | Colu mns(String columnHea der, Strin g accessor MethodName , | |
| 648 | ColumnFo rmatter<?> columnFor matter, Co lumnTypeCo nverter<?, ?> typeCo nverter) | |
| 649 | { | |
| 650 | this.c olumnHeade r = column Header; | |
| 651 | try | |
| 652 | { | |
| 653 | this.acc essorMetho d = Transa ctionLogEn try.class. getMethod( accessorMe thodName, (Class<?>[ ])null); | |
| 654 | } | |
| 655 | catch (SecurityE xception e ) | |
| 656 | { | |
| 657 | this.acc essorMetho d = null; | |
| 658 | e.printS tackTrace( ); | |
| 659 | } | |
| 660 | catch (NoSuchMet hodExcepti on e) | |
| 661 | { | |
| 662 | this.acc essorMetho d = null; | |
| 663 | e.printS tackTrace( ); | |
| 664 | } | |
| 665 | this.c olumnForma tter = col umnFormatt er; | |
| 666 | this.t ypeConvert er = typeC onverter; | |
| 667 | } | |
| 668 | ||
| 669 | publ ic String getColumnH eader() | |
| 670 | { | |
| 671 | return columnHea der; | |
| 672 | } | |
| 673 | ||
| 674 | publ ic Method getAccesso rMethod() | |
| 675 | { | |
| 676 | return accessorM ethod; | |
| 677 | } | |
| 678 | ||
| 679 | publ ic ColumnF ormatter<? > getColum nFormatter () | |
| 680 | { | |
| 681 | return columnFor matter; | |
| 682 | } | |
| 683 | ||
| 684 | publ ic ColumnT ypeConvert er<?, ?> g etTypeConv erter() | |
| 685 | { | |
| 686 | return typeConve rter; | |
| 687 | } | |
| 688 | } | |
| 689 | ||
| 690 | cl ass XlsTra nsactionLo gWriter | |
| 691 | im plements T ransaction LogWriter | |
| 692 | { | |
| 693 | fina l Writable Sheet shee t; | |
| 694 | int row = 1; | |
| 695 | ||
| 696 | XlsT ransaction LogWriter( WritableSh eet sheet) | |
| 697 | { | |
| 698 | this.s heet = she et; | |
| 699 | } | |
| 700 | ||
| 701 | @Ove rride | |
| 702 | publ ic void wr iteTransac tionLogEnt ry(Transac tionLogEnt ry logEntr y) | |
| 703 | thro ws MethodE xception | |
| 704 | { | |
| 705 | for(Co lumns colu mn : Colum ns.values( )) | |
| 706 | { | |
| 707 | try | |
| 708 | { | |
| 709 | Method acc essor = co lumn.getAc cessorMeth od(); | |
| 710 | if( access or != null ) | |
| 711 | { | |
| 712 | // the retur n type of the getXXX method | |
| 713 | Cl ass<?> pro pertyType = accessor .getReturn Type(); | |
| 714 | // the value of the co lumn (the log entry property) | |
| 715 | Ob ject value = null; | |
| 716 | ||
| 717 | va lue = acce ssor.invok e(logEntry , (Object[ ])null); | |
| 718 | Co lumnTypeCo nverter ty peConverte r = column .getTypeCo nverter(); | |
| 719 | if (typeConve rter != nu ll) | |
| 720 | valu e = typeCo nverter.co nvert(valu e); | |
| 721 | ||
| 722 | if (value == null) | |
| 723 | shee t.addCell( new Label( column.ord inal(), ro w, "")); | |
| 724 | ||
| 725 | el se if( val ue instanc eof Boolea n ) | |
| 726 | shee t.addCell( new jxl.w rite.Boole an(column. ordinal(), row, ((ja va.lang.Bo olean)valu e).boolean Value()) ) ; | |
| 727 | ||
| 728 | el se if( val ue instanc eof Charac ter ) | |
| 729 | shee t.addCell( new jxl.w rite.Label (column.or dinal(), r ow, ((java .lang.Char acter)valu e).toStrin g()) ); | |
| 730 | ||
| 731 | el se if( val ue instanc eof Long ) | |
| 732 | shee t.addCell( new jxl.w rite.Numbe r(column.o rdinal(), row, ((jav a.lang.Lon g)value).l ongValue() ) ); | |
| 733 | ||
| 734 | el se if( val ue instanc eof Intege r ) | |
| 735 | shee t.addCell( new jxl.w rite.Numbe r(column.o rdinal(), row, ((jav a.lang.Int eger)value ).intValue ()) ); | |
| 736 | ||
| 737 | el se if( val ue instanc eof Float ) | |
| 738 | shee t.addCell( new jxl.w rite.Numbe r(column.o rdinal(), row, ((jav a.lang.Flo at)value). floatValue ()) ); | |
| 739 | ||
| 740 | el se if( val ue instanc eof Double ) | |
| 741 | shee t.addCell( new jxl.w rite.Numbe r(column.o rdinal(), row, ((jav a.lang.Dou ble)value) .doubleVal ue()) ); | |
| 742 | ||
| 743 | el se if( val ue instanc eof Date ) | |
| 744 | shee t.addCell( new jxl.w rite.DateT ime(column .ordinal() , row, (ja va.util.Da te)value) ); | |
| 745 | ||
| 746 | el se | |
| 747 | shee t.addCell( new Label (column.or dinal(), r ow, value. toString() ) ); | |
| 748 | } | |
| 749 | else | |
| 750 | sh eet.addCel l(new Labe l(column.o rdinal(), row, "")); | |
| 751 | ||
| 752 | } | |
| 753 | catch(Ex ception e) | |
| 754 | { | |
| 755 | try | |
| 756 | { | |
| 757 | sh eet.addCel l(new Labe l(column.o rdinal(), row, e.get Message()) ); | |
| 758 | } | |
| 759 | catch(Writ eException wX) | |
| 760 | { | |
| 761 | th row new Me thodExcept ion(wX); | |
| 762 | } | |
| 763 | } | |
| 764 | } | |
| 765 | ++row; | |
| 766 | } | |
| 767 | ||
| 768 | } | |
| 769 | ||
| 770 | cl ass Delimi tedTransac tionLogWri ter | |
| 771 | im plements T ransaction LogWriter | |
| 772 | { | |
| 773 | priv ate final PrintWrite r writer; | |
| 774 | priv ate final String fie ldDelimite r; | |
| 775 | priv ate final String rec ordDelimit er; | |
| 776 | ||
| 777 | publ ic Delimit edTransact ionLogWrit er(PrintWr iter write r, String fieldDelim iter, Stri ng recordD elimiter) | |
| 778 | { | |
| 779 | this.w riter = wr iter; | |
| 780 | this.f ieldDelimi ter = fiel dDelimiter ; | |
| 781 | this.r ecordDelim iter = rec ordDelimit er; | |
| 782 | } | |
| 783 | ||
| 784 | /* ( non-Javado c) | |
| 785 | * @ see gov.va .med.imagi ng.access. Transactio nLogWriter #writeTran sactionLog Entry(gov. va.med.ima ging.acces s.Transact ionLogEntr y) | |
| 786 | */ | |
| 787 | @Ove rride | |
| 788 | publ ic void wr iteTransac tionLogEnt ry(Transac tionLogEnt ry logEntr y) | |
| 789 | thro ws MethodE xception | |
| 790 | { | |
| 791 | int co lumnIndex = 0; | |
| 792 | for(Co lumns colu mn : Colum ns.values( )) | |
| 793 | { | |
| 794 | if(colum nIndex != 0) | |
| 795 | writer.wri te(fieldDe limiter); | |
| 796 | try | |
| 797 | { | |
| 798 | Method acc essor = co lumn.getAc cessorMeth od(); | |
| 799 | if( access or != null ) | |
| 800 | { | |
| 801 | Ob ject value = accesso r.invoke(l ogEntry, ( Object[])n ull); | |
| 802 | Co lumnFormat ter format ter = colu mn.getColu mnFormatte r(); | |
| 803 | // wrap form atted and unformatte d values i n double q uotes | |
| 804 | if (formatter != null) | |
| 805 | writ er.write( "\"" + for matter.for matColumnV alue(value ) + "\"" ) ; | |
| 806 | el se | |
| 807 | writ er.write( value == n ull ? "" : "\"" + va lue.toStri ng() + "\" " ); | |
| 808 | } | |
| 809 | else | |
| 810 | wr iter.write (""); | |
| 811 | ||
| 812 | } | |
| 813 | catch(Ex ception e) | |
| 814 | { | |
| 815 | logger.war n(e); | |
| 816 | e.printSta ckTrace(); | |
| 817 | writer.wri te( e == n ull ? | |
| 818 | "<ER ROR>" : e. getMessage () == null ? | |
| 819 | e.getCla ss().getSi mpleName() : e.getMe ssage() ); | |
| 820 | } | |
| 821 | ++column Index; | |
| 822 | } | |
| 823 | writer .write(rec ordDelimit er); | |
| 824 | } | |
| 825 | ||
| 826 | } | |
| 827 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.