Produced by Araxis Merge on 12/5/2017 12:06:49 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\TransactionContext\main\src\java\gov\va\med\imaging\transactioncontext | TransactionContextFactory.java | Mon Dec 4 21:34:48 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\TransactionContext\main\src\java\gov\va\med\imaging\transactioncontext | TransactionContextFactory.java | Mon Dec 4 22:06:03 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 592 |
| 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 | /** | |
| 2 | * | |
| 3 | */ | |
| 4 | package go v.va.med.i maging.tra nsactionco ntext; | |
| 5 | ||
| 6 | import gov .va.med.SE RIALIZATIO N_FORMAT; | |
| 7 | import gov .va.med.im aging.Imag eURN; | |
| 8 | import gov .va.med.im aging.tomc at.vistare alm.VistaR ealmPrinci pal; | |
| 9 | import gov .va.med.im aging.tomc at.vistare alm.VistaR ealmPrinci pal.Authen ticationCr edentialsT ype; | |
| 10 | ||
| 11 | import jav a.io.IOExc eption; | |
| 12 | import jav a.lang.ref lect.Proxy ; | |
| 13 | import jav a.text.Sim pleDateFor mat; | |
| 14 | import jav a.util.*; | |
| 15 | ||
| 16 | import org .apache.lo gging.log4 j.LogManag er; | |
| 17 | import org .apache.lo gging.log4 j.Logger; | |
| 18 | ||
| 19 | /** | |
| 20 | * @author
|
|
| 21 | * | |
| 22 | */ | |
| 23 | public cla ss Transac tionContex tFactory | |
| 24 | { | |
| 25 | pr ivate stat ic Logger logger = L ogManager. getLogger( Transactio nContextFa ctory.clas s); | |
| 26 | ||
| 27 | privat e static T hreadLocal <Stack<Tra nsactionCo ntextMemen to>> trans actionCont extMemento Stack = | |
| 28 | ne w ThreadLo cal<Stack< Transactio nContextMe mento>>(); | |
| 29 | ||
| 30 | /* * | |
| 31 | * Get a ref erence to the Transa ctionConte xt. The r eturned in stance is | |
| 32 | * unique to the call, but the u nderlying data store is a thre ad-local | |
| 33 | * instance. | |
| 34 | * | |
| 35 | * @return | |
| 36 | * / | |
| 37 | pu blic stati c Transact ionContext get() | |
| 38 | { | |
| 39 | Tran sactionCon text trans actionCont ext = | |
| 40 | (Trans actionCont ext) Proxy .newProxyI nstance(Tr ansactionC ontext.cla ss.getClas sLoader(), | |
| 41 | new Class[] { Transactio nContext.c lass }, | |
| 42 | new Transactio nContextPr oxyInvocat ionHandler () ); | |
| 43 | ||
| 44 | retu rn transac tionContex t; | |
| 45 | } | |
| 46 | ||
| 47 | /* * | |
| 48 | * Call this method on ly the fir st time th e Transact ionContext is needed on a | |
| 49 | * thread, e lse the Pr incipal in stance pas sed will b e ignored (a warning will be | |
| 50 | * logged). | |
| 51 | * | |
| 52 | * @param pr incipal | |
| 53 | * @return | |
| 54 | * / | |
| 55 | pu blic stati c Transact ionContext createCli entTransac tionContex t(ClientPr incipal pr incipal) | |
| 56 | { | |
| 57 | Tran sactionCon text trans actionCont ext = | |
| 58 | (Trans actionCont ext) Proxy .newProxyI nstance(Tr ansactionC ontext.cla ss.getClas sLoader(), | |
| 59 | new Class[] { Transactio nContext.c lass }, | |
| 60 | new Transactio nContextPr oxyInvocat ionHandler (principal ) ); | |
| 61 | ||
| 62 | retu rn transac tionContex t; | |
| 63 | } | |
| 64 | ||
| 65 | /* * | |
| 66 | * | |
| 67 | * @return | |
| 68 | * / | |
| 69 | pu blic stati c boolean isTransact ionContext Establishe d() | |
| 70 | { | |
| 71 | retu rn Transac tionContex tProxyInvo cationHand ler.isTran sactionCon textEstabl ished(); | |
| 72 | } | |
| 73 | ||
| 74 | /* * | |
| 75 | * Returns a n opaque r epresentat ion of the current t ransaction context. | |
| 76 | * The retur ned instan ce may be used in a pushTransa ctionConte xt() to | |
| 77 | * re-establ ish the tr ansaction context on a differe nt thread. | |
| 78 | * | |
| 79 | * @return | |
| 80 | * / | |
| 81 | pu blic stati c Transact ionContext Memento ge tTransacti onContextM emento() | |
| 82 | { | |
| 83 | Tran sactionCon text threa dTransacti onContext = get(); | |
| 84 | ||
| 85 | retu rn threadT ransaction Context.ge tMemento() ; | |
| 86 | } | |
| 87 | ||
| 88 | /* * | |
| 89 | * Store the current t ransaction context o n the stac k, creatin g the stac k if it do es not exi st. | |
| 90 | * Set the t ransaction context f or the cur rent threa d to that encapsulat ed in the | |
| 91 | * given tra nsaction c ontext mem ento. | |
| 92 | * | |
| 93 | * @param tr ansactionC ontextMeme nto | |
| 94 | * / | |
| 95 | pu blic stati c void pus hTransacti onContext( Transactio nContextMe mento tran sactionCon textMement o) | |
| 96 | th rows Inval idTransact ionContext MementoExc eption | |
| 97 | { | |
| 98 | Stac k<Transact ionContext Memento> t hreadConte xtMementoS tack = tra nsactionCo ntextMemen toStack.ge t(); | |
| 99 | if(t hreadConte xtMementoS tack == nu ll) | |
| 100 | { | |
| 101 | thread ContextMem entoStack = new Stac k<Transact ionContext Memento>() ; | |
| 102 | transa ctionConte xtMementoS tack.set(t hreadConte xtMementoS tack); | |
| 103 | } | |
| 104 | ||
| 105 | // I f there is an existi ng transac tion conte xt then th e values a re seriali zed (made into a mem ento) | |
| 106 | // a nd then pu shed onto the stack of memento . | |
| 107 | if(i sTransacti onContextE stablished ()) | |
| 108 | { | |
| 109 | Transa ctionConte xtMemento currentTra nsactionCo ntextMemen to = getTr ansactionC ontextMeme nto(); | |
| 110 | if(cur rentTransa ctionConte xtMemento != null) | |
| 111 | threadCo ntextMemen toStack.pu sh(current Transactio nContextMe mento); | |
| 112 | } | |
| 113 | ||
| 114 | setS ecurityCon text(trans actionCont extMemento ); | |
| 115 | } | |
| 116 | ||
| 117 | /* * | |
| 118 | * Restore t he previou s transact ion contex t, if one exists. | |
| 119 | * Otherwise , silently do nothin g. | |
| 120 | * / | |
| 121 | pu blic stati c void pop Transactio nContext() | |
| 122 | { | |
| 123 | Stac k<Transact ionContext Memento> t hreadConte xtMementoS tack = tra nsactionCo ntextMemen toStack.ge t(); | |
| 124 | if(t hreadConte xtMementoS tack == nu ll) | |
| 125 | return ; | |
| 126 | ||
| 127 | Tran sactionCon textMement o memento; | |
| 128 | try | |
| 129 | { | |
| 130 | mement o = thread ContextMem entoStack. pop(); | |
| 131 | if(mem ento == nu ll) | |
| 132 | return; | |
| 133 | } | |
| 134 | catc h (EmptySt ackExcepti on x) | |
| 135 | { | |
| 136 | // not really an error, ju st no pare nt transac tion conte xt | |
| 137 | return ; | |
| 138 | } | |
| 139 | ||
| 140 | setS ecurityCon text(memen to); | |
| 141 | } | |
| 142 | ||
| 143 | /* * | |
| 144 | * Clears th e current context on the main thread and restores an old one . | |
| 145 | * @param me mento | |
| 146 | * / | |
| 147 | pu blic stati c void res toreTransa ctionConte xt(Transac tionContex tMemento m emento) | |
| 148 | { | |
| 149 | // C lear out t he context on main t hread and push the o ld one | |
| 150 | Tr ansactionC ontextFact ory.get(). clear(); | |
| 151 | tr y | |
| 152 | { | |
| 153 | Transa ctionConte xtFactory. pushTransa ctionConte xt(memento ); | |
| 154 | } | |
| 155 | ca tch (Inval idTransact ionContext MementoExc eption itc mX) | |
| 156 | { | |
| 157 | logger .error("Er ror pushin g memento back onto context, " + itcmX.g etMessage( )); | |
| 158 | } | |
| 159 | } | |
| 160 | ||
| 161 | ||
| 162 | /* * | |
| 163 | * In genera l this is another me thod that nobody but the secur ity code s hould be c alling. | |
| 164 | * This allo ws code to change th e security (and tran saction co ntext) on the curren t thread. | |
| 165 | * This is u sually don e to provi de an asyn chronous t hread the same conte xt as an o riginating | |
| 166 | * thread, f or example in loggin g and in a synchrouno us proxies . | |
| 167 | * | |
| 168 | * Note that changing a security context i s not real ly a secur ity issue because th e new cont ext | |
| 169 | * must have privelige s to invok e an opera tion. | |
| 170 | * | |
| 171 | * @param se curityCont extMemento | |
| 172 | * / | |
| 173 | pu blic stati c void set SecurityCo ntext(Tran sactionCon textMement o security ContextMem ento) | |
| 174 | { | |
| 175 | get( ).setMemen to(securit yContextMe mento); | |
| 176 | } | |
| 177 | ||
| 178 | pr ivate stat ic int tes tTransacti onId = 0; | |
| 179 | /* * | |
| 180 | * Create a security/t ransaction context f or testing . | |
| 181 | * | |
| 182 | * realm = " test" | |
| 183 | * UID/Acces s = "testi ng_1" | |
| 184 | * PWD/Verif y = "testi ng_2" | |
| 185 | * duz = "13 5" | |
| 186 | * fullName = "IMAGPRO VIDERONETH REEFIVE,ON ETHREEFIVE " | |
| 187 | * siteName = "SALT LA KE CITY" | |
| 188 | * siteNumbe r = "660" | |
| 189 | * ssn = "98 7670909" | |
| 190 | * roles are "clinical -display-u ser", "vis ta-user", and "peer- vixs" | |
| 191 | * transacti on_id is a monotonic ally incre asing inte ger starti ng at 0 | |
| 192 | * @throws I OException | |
| 193 | * / | |
| 194 | pu blic stati c synchron ized void setTestSec urityConte xt() | |
| 195 | th rows IOExc eption | |
| 196 | { | |
| 197 | List <String> t estRoles = new Array List<Strin g>(); | |
| 198 | test Roles.add( "clinical- display-us er"); | |
| 199 | test Roles.add( "vista-use r"); | |
| 200 | test Roles.add( "peer-vixs "); | |
| 201 | ||
| 202 | Vist aRealmPrin cipal prin cipal = ne w VistaRea lmPrincipa l( | |
| 203 | "test", false, Aut henticatio nCredentia lsType.Pas sword, "te sting_1", "testing_2 ", | |
| 204 | "135", " IMAGPROVID ERONETHREE FIVE,ONETH REEFIVE", "987670909 ", | |
| 205 | "660", " SALT LAKE CITY", tes tRoles, nu ll); | |
| 206 | setS ecurityCon text( Tran sactionCon textMement o.create(p rincipal) ); | |
| 207 | get( ).setTrans actionId(I nteger.toS tring(test Transactio nId++)); | |
| 208 | } | |
| 209 | ||
| 210 | /* * | |
| 211 | * Set the T hread-Loca l security context f or client applicatio ns. | |
| 212 | * | |
| 213 | * @param ui d | |
| 214 | * @param pw d | |
| 215 | * @throws I OException | |
| 216 | * / | |
| 217 | pu blic stati c synchron ized void setClientS ecurityCon text(Strin g uid, Str ing pwd) | |
| 218 | th rows IOExc eption | |
| 219 | { | |
| 220 | List <String> c lientRoles = new Arr ayList<Str ing>(); | |
| 221 | ||
| 222 | Vist aRealmPrin cipal prin cipal = ne w ClientPr incipal( | |
| 223 | "client" , false, A uthenticat ionCredent ialsType.P assword, u id, pwd, | |
| 224 | null, nu ll, null, null, null , clientRo les, null) ; | |
| 225 | setS ecurityCon text( Tran sactionCon textMement o.create(p rincipal) ); | |
| 226 | } | |
| 227 | ||
| 228 | /* * | |
| 229 | * | |
| 230 | * @param im ageUrn | |
| 231 | * @return | |
| 232 | * / | |
| 233 | pu blic stati c String d ecodeUrnFo rLogging(I mageURN im ageUrn) | |
| 234 | { | |
| 235 | // J MW 12/7/20 10 P104 - now that t he URN doe s not cont ain Base32 encoded p ieces | |
| 236 | // n o reason f or this me thod to do anything but call t oString() | |
| 237 | //re turn image Urn.toStri ng(); | |
| 238 | retu rn imageUr n.toString (SERIALIZA TION_FORMA T.RAW); | |
| 239 | /* | |
| 240 | ||
| 241 | Stri ngBuilder sb = new S tringBuild er(); | |
| 242 | Stri ng []urnPi eces = ima geUrn.toSt ring().spl it(":"); | |
| 243 | sb.a ppend(urnP ieces[0] + ":" + urn Pieces[1] + ":"); | |
| 244 | sb.a ppend(imag eUrn.getOr iginatingS iteId()); | |
| 245 | sb.a ppend("-") ; | |
| 246 | // C TB 29Nov20 09 | |
| 247 | //sb .append(Ba se32Conver sionUtilit y.base32De code(image Urn.getIns tanceId()) ); | |
| 248 | sb.a ppend(imag eUrn.getIn stanceId() ); | |
| 249 | sb.a ppend("-") ; | |
| 250 | // C TB 29Nov20 09 | |
| 251 | //sb .append(Ba se32Conver sionUtilit y.base32De code(image Urn.getStu dyId())); | |
| 252 | sb.a ppend(imag eUrn.getSt udyId()); | |
| 253 | sb.a ppend("-") ; | |
| 254 | sb.a ppend(imag eUrn.getPa tientIcn() ); | |
| 255 | sb.a ppend("-") ; | |
| 256 | sb.a ppend(imag eUrn.getIm ageModalit y()); | |
| 257 | retu rn sb.toSt ring();*/ | |
| 258 | } | |
| 259 | ||
| 260 | /* * | |
| 261 | * Construct a date ra nge string suitable for inclus ion in the transacti on log. Th is informa tion usual ly origina tes | |
| 262 | * from a we b service filter obj ect. | |
| 263 | * @param fr omDate - l ower end o f the date range | |
| 264 | * @param to Date - upp er end on the date r ange | |
| 265 | * @return - the forma tted date range stri ng | |
| 266 | * / | |
| 267 | pu blic stati c String g etFilterDa teRange(Da te fromDat e, Date to Date) | |
| 268 | { | |
| 269 | Stri ng range = null; | |
| 270 | if ( fromDate = = null && toDate == null) | |
| 271 | { | |
| 272 | range = "all"; | |
| 273 | } | |
| 274 | else | |
| 275 | { | |
| 276 | range = getDateS tring(from Date) + " - " + getD ateString( toDate); | |
| 277 | } | |
| 278 | retu rn range; | |
| 279 | } | |
| 280 | ||
| 281 | /* * | |
| 282 | * Format a Date to a string sui table for inclusion in the tra nsaction l og | |
| 283 | * @param da te | |
| 284 | * @return | |
| 285 | * / | |
| 286 | pr ivate stat ic String getDateStr ing(Date d ate) | |
| 287 | { | |
| 288 | Stri ng dateStr ing=""; | |
| 289 | if ( date != nu ll) | |
| 290 | { | |
| 291 | Simple DateFormat df = new SimpleDate Format("MM /dd/yyyy") ; | |
| 292 | dateSt ring = df. format(dat e); | |
| 293 | } | |
| 294 | retu rn dateStr ing; | |
| 295 | } | |
| 296 | ||
| 297 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.