Produced by Araxis Merge on 8/31/2017 11:16:53 AM Central 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 | JLV_2.6.zip\JLV_2.6\JLV_2.6\Joint Legacy Viewer\VistaDataService\src\main\java\gov\va\med\rpc\client | RPCClient.java | Thu Aug 31 12:13:24 2017 UTC |
2 | JLV_2.6.zip\JLV_2.6\JLV_2.6\Joint Legacy Viewer\VistaDataService\src\main\java\gov\va\med\rpc\client | RPCClient.java | Thu Aug 31 14:22:39 2017 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 648 |
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 | * Janus 4 .0 (c) | |
3 | * Copyrig ht (c) 201 3 Hawaii R esource Gr oup LLC. A ll Rights Reserved. | |
4 | * Develop ed for the Pacific T elehealth & Technolo gy Hui and the Pacif ic Joint I nformation Technolog y Center | |
5 | * Contrib utors: | |
6 | * Ho norable Se nator Dani el K. Inou ye | |
7 | * VA Pacific I slands Hea lth Care S ystem | |
8 | * Tr ipler Army Medical C enter | |
9 | */ | |
10 | ||
11 | ||
12 | package go v.va.med.r pc.client; | |
13 | ||
14 | import gov .va.med.rp c.RPCConne ction; | |
15 | import gov .va.med.rp c.RPCExcep tion; | |
16 | import gov .va.med.rp c.StringUt ils; | |
17 | import gov .va.med.rp c.VistaQue ry; | |
18 | import gov .va.med.rp c.VistaQue ryFactory; | |
19 | import gov .va.med.rp c.VistaQue ryFactoryU til; | |
20 | import gov .va.med.rp c.VistaRes ponse; | |
21 | import gov .va.med.vd s.vistabea ns.Site; | |
22 | ||
23 | /** | |
24 | * RPCClie nt is a he lper class which is designed t o ease the use of ta lking | |
25 | * RPC's w ith a Vist A system. | |
26 | * | |
27 | * An RPC client doe s not need to authen ticate in order to p erform cer tain | |
28 | * queries ; ie RPC " XUS INTRO MSG". Othe r RPCs whi ch write d ata to the VistA | |
29 | * system require th e RPC Clie nt to logi n. | |
30 | * | |
31 | * By defa ult, when the RPC cl ient execu tes a sing le query u sing the | |
32 | * execute Query meth od, the RP C client w ill perfor m the quer y, get the result | |
33 | * and imm ediately d isconnect. | |
34 | * | |
35 | * To perf orm a quer y in seque nce while keeping th e state of the under lying | |
36 | * M stack alive, us e the exec uteMultiQu ery method . In contr ast to exe cuteQuery, | |
37 | * execute MultiQuery will keep the RPC c onnection open UNTIL TOLD to l ogout. | |
38 | * | |
39 | * Example usage can be found in the JUn it tests. | |
40 | * | |
41 | * @author REDACTED | |
42 | */ | |
43 | public cla ss RPCClie nt { | |
44 | public final sta tic String CAPRI_CON TEXT = "DV BA CAPRI G UI"; | |
45 | public final sta tic String CPRS_CONT EXT = "OR CPRS GUI C HART"; | |
46 | public final sta tic String BCMA_CONT EXT = "PSB GUI CONTE XT - USER" ; | |
47 | public final sta tic String VISTA_IMA GING_CONTE XT = "MAG WINDOWS"; | |
48 | ||
49 | privat e RPCConne ction rpcC onnection = null; | |
50 | privat e String e ncryptedAv Code = ""; | |
51 | privat e String b rokerConte xt = null; | |
52 | privat e boolean isAuthenti cated = fa lse; | |
53 | privat e boolean isLoggedIn = false; | |
54 | ||
55 | privat e VistaQue ryFactory vistaQuery Factory; | |
56 | ||
57 | /** | |
58 | * Ins tantiate a n RPC clie nt without credentia ls. Used f or queryin g a | |
59 | * Vis tA system without pr oviding cr edentials. This assu mes the us er knows | |
60 | * whe ther or no t the RPC requires l ogin in or der to exe cute succe ssfully. | |
61 | * @pa ram site t o connect with. | |
62 | * @th rows gov.v a.med.rpc. RPCExcepti on occurs when the g iven site code canno t be found | |
63 | */ | |
64 | public RPCClient (Site site ) throws R PCExceptio n { | |
65 | rp cConnectio n = new RP CConnectio n(site); | |
66 | ||
67 | vi staQueryFa ctory = Vi staQueryFa ctoryUtil. getVistaQu eryFactory (rpcConnec tion.getCo nnectionSt rategy()); | |
68 | } | |
69 | ||
70 | /** | |
71 | * Ins tantiates an RPC cli ent using the given credential s. Used fo r reading | |
72 | * and writing d ata via a VistA syst em's RPCs. | |
73 | * @pa ram encryp tedAvCode encrypted form of th e access a nd verify code | |
74 | * @pa ram broker Context th e context to login a s; such as | |
75 | * RPC Client.CPR S_CONTEXT | |
76 | * @pa ram site t o connect with. | |
77 | * @th rows gov.v a.med.rpc. RPCExcepti on occurs when the g iven site code canno t be found | |
78 | * or when the i mpl client fails to validate t he given a ccess / ve rify | |
79 | * cod e pair. | |
80 | */ | |
81 | public RPCClient (String en cryptedAvC ode, Strin g brokerCo ntext, Sit e site) th rows RPCEx ception | |
82 | { | |
83 | su per(); | |
84 | if (encrypte dAvCode == null || s ite == nul l || broke rContext = = null) { | |
85 | throw ne w IllegalA rgumentExc eption("RP CClient - constructo r " | |
86 | + "argumen ts cannot be null.") ; | |
87 | } | |
88 | ||
89 | th is.rpcConn ection = n ew RPCConn ection(sit e); | |
90 | ||
91 | co nnect(); | |
92 | lo gin(encryp tedAvCode, brokerCon text); | |
93 | di sconnect() ; | |
94 | } | |
95 | ||
96 | /** | |
97 | * Ins tantiates a RPC clie nt using t he given c redentials . Used for reading | |
98 | * and writing d ata via a VistA syst em's RPCs. | |
99 | * @pa ram access Code unenc rypted for m of the a ccess code | |
100 | * @pa ram verify Code unenc rypted for m of the v erify code | |
101 | * @pa ram broker Context th e context to login a s; such as | |
102 | * RPC Client.CPR S_CONTEXT | |
103 | * @pa ram site V istaSite t o connect with. | |
104 | * @th rows gov.v a.med.rpc. RPCExcepti on occurs when the i mpl client fails to validate t he | |
105 | * giv en access and verify code pair or when t he site co de doesn't exist | |
106 | * or the broker context i s invalid. | |
107 | */ | |
108 | public RPCClient (String ac cessCode, String ver ifyCode, S tring brok erContext, Site site ) throws R PCExceptio n | |
109 | { | |
110 | if (accessCo de == null || verify Code == nu ll || site == null | | brokerCo ntext == n ull) { | |
111 | throw ne w IllegalA rgumentExc eption("RP CClient - constructo r " + "arg uments can not be nul l."); | |
112 | } | |
113 | ||
114 | th is.rpcConn ection = n ew RPCConn ection(sit e); | |
115 | ||
116 | co nnect(); | |
117 | lo gin(access Code, veri fyCode, br okerContex t); | |
118 | di sconnect() ; | |
119 | } | |
120 | ||
121 | public RPCClient (RPCConnec tion rpcCo nnection) { | |
122 | th is.rpcConn ection = r pcConnecti on; | |
123 | } | |
124 | ||
125 | privat e void con nect() thr ows RPCExc eption { | |
126 | rp cConnectio n.connect( ); | |
127 | } | |
128 | ||
129 | privat e void dis connect() throws RPC Exception { | |
130 | is LoggedIn = false; | |
131 | rp cConnectio n.disconne ct(); | |
132 | } | |
133 | ||
134 | /** | |
135 | * Log in using t he supplie d access a nd verify code and b roker cont ext. | |
136 | * @pa ram access Code unenc rypted for m of the a ccess code | |
137 | * @pa ram verify Code unenc rypted for m of the v erify code | |
138 | * @pa ram broker Context xw b broker c ontext, ie - RPCClie nt.CPRS_CO NTEXT | |
139 | * @th rows gov.v a.med.rpc. RPCExcepti on occurs when the u ser is alr eady logge d in or | |
140 | * the supplied access and verify co de is wron g. | |
141 | */ | |
142 | public final voi d login(St ring acces sCode, Str ing verify Code, Stri ng brokerC ontext) th rows RPCEx ception { | |
143 | St ring encry ptedAvCode = vistaQu eryFactory .getVistaQ uery().enc rypt(acces sCode + "; " + verify Code); | |
144 | lo gin(encryp tedAvCode, brokerCon text); | |
145 | } | |
146 | ||
147 | /** | |
148 | * Log in using t he supplie d ENCRYPTE D access a nd verify code. By D EFAULT | |
149 | * thi s method w ill login using the CPRS conte xt. | |
150 | * @pa ram encryp tedAvCode encrypted form of th e access c ode + veri fy code | |
151 | * @th rows gov.v a.med.rpc. RPCExcepti on when th e given ac cess and v erify code are incor rect. | |
152 | */ | |
153 | public final voi d login(St ring encry ptedAvCode ) throws R PCExceptio n { | |
154 | lo gin(encryp tedAvCode, RPCClient .CPRS_CONT EXT); | |
155 | } | |
156 | ||
157 | /** | |
158 | * Log in using t he supplie d ENCRYPTE D access a nd verify code. The client | |
159 | * wil l login us ing the su pplied bro ker contex t. | |
160 | * @pa ram encryp tedAvCode encrypted form of th e access c ode + veri fy code | |
161 | * @pa ram broker Context th e xwb cont ext to log in as afte r authenti cating | |
162 | * @th rows gov.v a.med.rpc. RPCExcepti on when th e given ac cess and v erify code are incor rect | |
163 | * or the broker context i s invalid | |
164 | */ | |
165 | public final voi d login(St ring encry ptedAvCode , String b rokerConte xt) throws RPCExcept ion { | |
166 | if (isLogged In()) { | |
167 | throw ne w RPCExcep tion("RPCC lient is a lready log ged in."); | |
168 | } | |
169 | ||
170 | tr y { | |
171 | /* Recor d that the user is l ogging int o the syst em. */ | |
172 | isLogged In = true; | |
173 | authenti cate(encry ptedAvCode , brokerCo ntext); | |
174 | } catch (RPC Exception e) { | |
175 | /* Authe ntication failed: re cord that the user i s NOT logg ed in. */ | |
176 | isLogged In = false ; | |
177 | throw ne w RPCExcep tion(e); | |
178 | } | |
179 | } | |
180 | ||
181 | /** | |
182 | * Cal led when a n RPC clie nt has com pleted its sequence of queries . | |
183 | * @th rows gov.v a.med.rpc. RPCExcepti on | |
184 | */ | |
185 | public void logo ut() throw s RPCExcep tion { | |
186 | di sconnect() ; | |
187 | } | |
188 | ||
189 | public String ge tRPCServer () { | |
190 | re turn rpcCo nnection.g etRPCEndpo int().getH ost() + ": " + rpcCon nection.ge tRPCEndpoi nt().getPo rt(); | |
191 | } | |
192 | ||
193 | privat e final vo id authent icate(Stri ng inencry ptedAvCode , String b rokerConte xt) throws RPCExcept ion { | |
194 | St ring encry ptedAvCode = inencry ptedAvCode ; | |
195 | Vi staRespons e vresp = null; | |
196 | ||
197 | Vi staQuery v query = vi staQueryFa ctory.getV istaQuery( "XUS SIGNO N SETUP"); | |
198 | ex ecuteMulti Query(vque ry); | |
199 | ||
200 | vq uery = vis taQueryFac tory.getVi staQuery(" XUS AV COD E"); | |
201 | vq uery.addPa rameter(Vi staQuery.L ITERAL, en cryptedAvC ode); | |
202 | vr esp = exec uteMultiQu ery(vquery ); | |
203 | ||
204 | /* If the 7t h piece is null then authentic ation has failed. */ | |
205 | if (vresp.ge tPiece(Str ingUtils.C RLF, 7) == null) { | |
206 | encrypte dAvCode = ""; | |
207 | throw ne w RPCExcep tion(vresp .getPiece( StringUtil s.CRLF, 4) ); | |
208 | } | |
209 | ||
210 | vq uery = vis taQueryFac tory.getVi staQuery(" XWB CREATE CONTEXT") ; | |
211 | vq uery.addEn cryptedPar ameter(Vis taQuery.LI TERAL, bro kerContext ); | |
212 | vr esp = exec uteMultiQu ery(vquery ); | |
213 | ||
214 | /* If the RP C doesn't return 1 t hen creati ng context has faile d. */ | |
215 | if (!"1".equ als(vresp. getRawResp onse())) { | |
216 | throw ne w RPCExcep tion("Fail ed to crea te XWB con text: " + brokerCont ext); | |
217 | } | |
218 | ||
219 | /* If the co ntext chan ge is succ essful the n inform t he impl co nnection. */ | |
220 | rp cConnectio n.setConte xt(brokerC ontext); | |
221 | th is.brokerC ontext = b rokerConte xt; | |
222 | ||
223 | /* The clien t has succ essfully a uthenticat ed. */ | |
224 | th is.isAuthe nticated = true; | |
225 | ||
226 | /* Store the encrypted access/ve rify code. */ | |
227 | th is.encrypt edAvCode = encrypted AvCode; | |
228 | } | |
229 | ||
230 | privat e VistaRes ponse quer y(VistaQue ry vquery, boolean s ingleQuery ) throws R PCExceptio n { | |
231 | if (!isConne cted()) { | |
232 | connect( ); | |
233 | } | |
234 | ||
235 | if (isAuthen ticated() && !isLogg edIn()) { | |
236 | login(en cryptedAvC ode, broke rContext); | |
237 | } | |
238 | ||
239 | Vi staRespons e vresp = rpcConnect ion.query( vquery); | |
240 | ||
241 | if (isConnec ted() && s ingleQuery ) { | |
242 | disconne ct(); | |
243 | } | |
244 | ||
245 | re turn vresp ; | |
246 | } | |
247 | ||
248 | /** | |
249 | * Exe cutes a RP C query, i mmediately disconnec ts and ret urns the r esult | |
250 | * @pa ram vistaQ uery the R PC to exec ute | |
251 | * @re turn a Vis taResponse object wh ich encaps ulates the RPC respo nse | |
252 | * @th rows gov.v a.med.rpc. RPCExcepti on when th e query fa ils to exe cute | |
253 | */ | |
254 | public VistaResp onse execu teQuery(Vi staQuery v istaQuery) throws RP CException | |
255 | { | |
256 | re turn query (vistaQuer y, true); | |
257 | } | |
258 | ||
259 | /** | |
260 | * Exe cutes a RP C query, K EEPS the R PC client connection open and returns | |
261 | * the results. This metho d enables a programm er to reta in the M s tack | |
262 | * whi le issuing RPCs in a procedura l fashion. | |
263 | * @pa ram vistaQ uery the R PC to exec ute | |
264 | * @re turn a Vis taResponse object wh ich encaps ulates the RPC respo nse | |
265 | * @th rows gov.v a.med.rpc. RPCExcepti on when th e query fa ils to exe cute | |
266 | */ | |
267 | public VistaResp onse execu teMultiQue ry(VistaQu ery vistaQ uery) thro ws RPCExce ption { | |
268 | re turn query (vistaQuer y, false); | |
269 | } | |
270 | ||
271 | /** | |
272 | * Ret urns the s tatus of t he RPC cli ent at the socket le vel. | |
273 | * @re turn true if the imp l client i s still co nnected ot herwise fa lse. | |
274 | */ | |
275 | public boolean i sConnected () { | |
276 | re turn rpcCo nnection.i sConnected (); | |
277 | } | |
278 | ||
279 | /** | |
280 | * Ret urns wheth er or not the impl c lient has provided a ccess and verify | |
281 | * cod es which h ave been v alidated. | |
282 | * @re turn true if the imp l client h as validat ed the giv en access and verify | |
283 | * cod e; otherwi se false. | |
284 | */ | |
285 | public boolean i sAuthentic ated() { | |
286 | re turn isAut henticated ; | |
287 | } | |
288 | ||
289 | /** | |
290 | * Ret urns wheth er or not the curren t impl con nection ha s logged i n using | |
291 | * the supplied access and verify co des. Note: an impl c onnection does not | |
292 | * hav e to authe nticated i n order fo r queries to execute . | |
293 | * @re turn true if the imp l client i s currentl y connecte d and the connection | |
294 | * has logged in using the provided access and verify co des. | |
295 | */ | |
296 | public final boo lean isLog gedIn() { | |
297 | re turn isLog gedIn; | |
298 | } | |
299 | ||
300 | /** | |
301 | * Per forms an R PC select of the pat ient. RPC client mus t be authe nticated | |
302 | * bef ore callin g this met hod. | |
303 | * @pa ram patien tIen the v ista patie nt ien | |
304 | * @th rows gov.v a.med.rpc. RPCExcepti on when th e patient is not fou nd in vist a. | |
305 | */ | |
306 | public void sele ctPatient( String pat ientIen) t hrows RPCE xception { | |
307 | if (!isAuthe nticated() ) { | |
308 | throw ne w IllegalS tateExcept ion("RPC c lient requ ires " | |
309 | + "authent ication be fore calli ng this me thod."); | |
310 | } | |
311 | ||
312 | Vi staQuery v query = vi staQueryFa ctory.getV istaQuery( "ORWPT SEL ECT"); | |
313 | vq uery.addPa rameter(Vi staQuery.L ITERAL, pa tientIen); | |
314 | ||
315 | Vi staRespons e vresp = executeQue ry(vquery) ; | |
316 | if ("-1".equ alsIgnoreC ase(vresp. getPiece(1 ))) { | |
317 | throw ne w RPCExcep tion("Pati ent not fo und in Vis tA: " + pa tientIen); | |
318 | } | |
319 | if (!vresp.g etRawRespo nse().star tsWith("ZZ TEST")) { | |
320 | throw ne w RPCExcep tion("Writ e back is not permit ted to pat ient: " | |
321 | + vresp.ge tPiece(1)) ; | |
322 | } | |
323 | } | |
324 | ||
325 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.