Produced by Araxis Merge on 2/7/2017 12:14:06 PM Eastern 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 | cpss.zip\cpss\src\main\java\gov\va\cpss\job\fps | FpsItemProcessor.java | Wed Feb 1 21:07:30 2017 UTC |
2 | cpss.zip\cpss\src\main\java\gov\va\cpss\job\fps | FpsItemProcessor.java | Fri Feb 3 20:44:19 2017 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 998 |
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.cpss. job.fps; | |
2 | ||
3 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.EMP TY_FILE_ER ROR_STATUS ; | |
4 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.INC OMPLETE_FI LE_ERROR_S TATUS; | |
5 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _FAILURE_K EY; | |
6 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _FAILURE_M ESSAGE_KEY ; | |
7 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.PRO CESSING_FA ILURE_STAT US; | |
8 | import sta tic gov.va .cpss.job. fps.FpsPro cessingCon stants.REC EIVED_ID_K EY; | |
9 | import sta tic gov.va .cpss.job. fps.FpsPro cessingCon stants.TOT AL_SITE_CO UNT_KEY; | |
10 | import sta tic gov.va .cpss.job. fps.FpsPro cessingCon stants.TOT AL_STATEME NT_COUNT_K EY; | |
11 | ||
12 | import org .apache.lo g4j.Logger ; | |
13 | import org .springfra mework.bat ch.core.Jo bExecution ; | |
14 | import org .springfra mework.bat ch.core.St epExecutio n; | |
15 | import org .springfra mework.bat ch.core.an notation.A fterStep; | |
16 | import org .springfra mework.bat ch.core.an notation.B eforeStep; | |
17 | import org .springfra mework.bat ch.item.It emProcesso r; | |
18 | ||
19 | import gov .va.cpss.m odel.fps.P SDetails; | |
20 | import gov .va.cpss.m odel.fps.P SPatient; | |
21 | import gov .va.cpss.m odel.fps.P SRecord; | |
22 | import gov .va.cpss.m odel.fps.P SSite; | |
23 | ||
24 | /** | |
25 | * Custom ItemProces sor used b y the Proc ess FPS Da ta batch j ob to proc ess | |
26 | * records parsed fr om the inp ut flat fi le prior t o writing the record s to the | |
27 | * databas e. | |
28 | * | |
29 | * @author DN S P II | |
30 | */ | |
31 | public cla ss FpsItem Processor implements ItemProce ssor<PSRec ord, PSRec ord> { | |
32 | ||
33 | pr ivate stat ic final L ogger proc essorLogge r = Logger .getLogger (FpsItemPr ocessor.cl ass.getCan onicalName ()); | |
34 | ||
35 | pr ivate JobE xecution j obExecutio n; | |
36 | ||
37 | pr ivate Long receivedI d; | |
38 | ||
39 | // PS contai ns a seque nce number . | |
40 | // These are used to v erify the sequence a nd number of PS is c orrect dur ing | |
41 | // processin g. | |
42 | pr ivate int nextExpect edSeqNum = 1; | |
43 | pr ivate int savedSeqNu m; | |
44 | pr ivate int savedTotSe qNum; | |
45 | ||
46 | // PS contai ns number of PH. | |
47 | // These are used to v erify the number of PH. | |
48 | pr ivate int nextExpect edStatemen tCount = 1 ; | |
49 | pr ivate int savedState mentCount; | |
50 | pr ivate int savedTotSt atementCou nt; | |
51 | ||
52 | pr ivate Stri ng savedFa cilityNum; | |
53 | ||
54 | // PH contai ns number of PD. | |
55 | // These are used to v erify the number of PD. | |
56 | pr ivate int nextExpect edDetailsC ount = 1; | |
57 | pr ivate int savedDetai lsCount; | |
58 | pr ivate int savedTotDe tailsCount ; | |
59 | ||
60 | @O verride | |
61 | pu blic PSRec ord proces s(PSRecord pojo) thr ows Except ion { | |
62 | ||
63 | // I f job has already fa iled then just retur n null. | |
64 | if ( jobExecuti on.getExec utionConte xt().conta insKey(JOB _FAILURE_K EY)) { | |
65 | return null; | |
66 | } | |
67 | ||
68 | // T he data is processed as: | |
69 | // P S, then su bsequent 1 -* PH. | |
70 | // P H, then su bsequent 1 -* PD. | |
71 | ||
72 | if ( pojo insta nceof PSSi te) { | |
73 | ||
74 | // Ver ify the pr evious PS was proper ly process ed. | |
75 | if (!l astPatient Completed( )) { | |
76 | return s topJob(PRO CESSING_FA ILURE_STAT US); | |
77 | } | |
78 | ||
79 | // If a PSSite r ow then re set the ch ild keys t o null to prevent | |
80 | // err oneous for eign key r eferences. | |
81 | resetS ite(); | |
82 | savedF acilityNum = (((PSSi te) pojo). getFacilit yNum() == null) ? "" : ((PSSit e) pojo).g etFacility Num().trim (); | |
83 | ||
84 | // At this point receivedI d FK shoul d not be n ull. | |
85 | if (re ceivedId ! = null) { | |
86 | ||
87 | if (!pro cessSiteRe cord((PSSi te) pojo)) { | |
88 | return sto pJob(PROCE SSING_FAIL URE_STATUS ); | |
89 | } | |
90 | ||
91 | } else { | |
92 | ||
93 | // Unrec overable e rror so st op the job . | |
94 | return s topJob(PRO CESSING_FA ILURE_STAT US, "Attem pted to pr ocess PS r ow with a null Recei ved FK"); | |
95 | } | |
96 | ||
97 | } el se if (poj o instance of PSPatie nt) { | |
98 | ||
99 | // Ver ify the pr evious PH was proper ly process ed. | |
100 | if (!l astDetails Completed( )) { | |
101 | return s topJob(PRO CESSING_FA ILURE_STAT US); | |
102 | } | |
103 | ||
104 | // If a PSPatien t row then reset the child key s to null to prevent | |
105 | // err oneous for eign key r eferences. | |
106 | resetP atient(); | |
107 | ||
108 | if (!p rocessPati entRecord( (PSPatient ) pojo)) { | |
109 | return s topJob(PRO CESSING_FA ILURE_STAT US); | |
110 | } | |
111 | ||
112 | } el se if (poj o instance of PSDetai ls) { | |
113 | ||
114 | if (!p rocessDeta ilsRecord( (PSDetails ) pojo)) { | |
115 | return s topJob(PRO CESSING_FA ILURE_STAT US); | |
116 | } | |
117 | ||
118 | } el se { | |
119 | ||
120 | // Unr ecoverable error so stop the j ob. | |
121 | return stopJob(P ROCESSING_ FAILURE_ST ATUS, "Att empted to process un known row" ); | |
122 | } | |
123 | ||
124 | retu rn pojo; | |
125 | } | |
126 | ||
127 | /* * | |
128 | * Before pr ocessing c apture the job execu tion and t he receive d id for d ata | |
129 | * processin g. | |
130 | * | |
131 | * @param st epExecutio n | |
132 | * / | |
133 | @B eforeStep | |
134 | pu blic void beforeStep (StepExecu tion stepE xecution) { | |
135 | proc essorLogge r.info("Be fore Step Execution" ); | |
136 | ||
137 | // S ave the jo b executio n at the b eginning o f the step . | |
138 | // T he executi on context will be u sed to set foreign k ey values as rows | |
139 | // a re process ed. | |
140 | jobE xecution = stepExecu tion.getJo bExecution (); | |
141 | ||
142 | // S ave the re ceivedId a t the begi nning of t he step. | |
143 | // I t is obtai ned by the batch pri or to the job and pa ssed as a job | |
144 | // p arameter w hen the jo b starts. | |
145 | rece ivedId = j obExecutio n.getJobPa rameters() .getLong(R ECEIVED_ID _KEY); | |
146 | ||
147 | // I nitialize the proces sing count s. | |
148 | jobE xecution.g etExecutio nContext() .putLong(T OTAL_SITE_ COUNT_KEY, 0); | |
149 | jobE xecution.g etExecutio nContext() .putLong(T OTAL_STATE MENT_COUNT _KEY, 0); | |
150 | ||
151 | // I nitialize the proces sing verif ication da ta. | |
152 | // P S processi ng | |
153 | next ExpectedSe qNum = 1; | |
154 | save dSeqNum = 0; | |
155 | save dTotSeqNum = 0; | |
156 | // P H processi ng | |
157 | next ExpectedSt atementCou nt = 1; | |
158 | save dStatement Count = 0; | |
159 | save dTotStatem entCount = 0; | |
160 | // P D processi ng | |
161 | next ExpectedDe tailsCount = 1; | |
162 | save dDetailsCo unt = 0; | |
163 | save dTotDetail sCount = 0 ; | |
164 | } | |
165 | ||
166 | /* * | |
167 | * After pro cessing ch eck for un expected c onditions that sugge st an erro r. | |
168 | * | |
169 | * @param st epExecutio n | |
170 | * / | |
171 | @A fterStep | |
172 | pu blic void afterStep( StepExecut ion stepEx ecution) { | |
173 | ||
174 | // I f no other error det ected then check for other pos sible erro r | |
175 | // c onditions. | |
176 | if ( !jobExecut ion.getExe cutionCont ext().cont ainsKey(JO B_FAILURE_ KEY)) { | |
177 | ||
178 | // If read count is zero t hen report a job fai lure. | |
179 | if (st epExecutio n.getReadC ount() == 0) { | |
180 | setFailu reStatusAn dMessage(E MPTY_FILE_ ERROR_STAT US, "Input file is e mpty"); | |
181 | } else if (!last DetailsCom pleted() | | !lastPat ientComple ted() || ! lastSiteCo mpleted()) { | |
182 | setFailu reStatus(I NCOMPLETE_ FILE_ERROR _STATUS); | |
183 | } | |
184 | ||
185 | } | |
186 | ||
187 | proc essorLogge r.info("Af ter Step E xecution") ; | |
188 | } | |
189 | ||
190 | /* * | |
191 | * Verify th e last sit e processi ng was com pleted. | |
192 | * | |
193 | * @return B oolean ind icating if processin g complete d. | |
194 | * / | |
195 | pr ivate bool ean lastSi teComplete d() { | |
196 | ||
197 | bool ean succes sful = tru e; | |
198 | ||
199 | if ( savedTotSe qNum != sa vedSeqNum) { | |
200 | succes sful = fal se; | |
201 | setFai lureMessag e( | |
202 | "PS count (" + saved SeqNum + " ) of (" + savedTotSe qNum + ") indicates incomplete sequence" ); | |
203 | } el se { | |
204 | succes sful = las tPatientCo mpleted(); | |
205 | } | |
206 | ||
207 | retu rn success ful; | |
208 | } | |
209 | ||
210 | /* * | |
211 | * Verify th e last pat ient proce ssing was completed. | |
212 | * | |
213 | * @return B oolean ind icating if processin g complete d. | |
214 | * / | |
215 | pr ivate bool ean lastPa tientCompl eted() { | |
216 | ||
217 | bool ean succes sful = tru e; | |
218 | ||
219 | if ( savedState mentCount != savedTo tStatement Count) { | |
220 | succes sful = fal se; | |
221 | setFai lureMessag e("PH coun t (" + sav edStatemen tCount + " ) of (" + savedTotSt atementCou nt | |
222 | + ") indic ates incom plete stat ement"); | |
223 | } el se { | |
224 | succes sful = las tDetailsCo mpleted(); | |
225 | } | |
226 | ||
227 | retu rn success ful; | |
228 | } | |
229 | ||
230 | /* * | |
231 | * Verify th e last det ails proce ssing was completed. | |
232 | * | |
233 | * @return B oolean ind icating if processin g complete d. | |
234 | * / | |
235 | pr ivate bool ean lastDe tailsCompl eted() { | |
236 | ||
237 | bool ean succes sful = tru e; | |
238 | ||
239 | if ( savedDetai lsCount != savedTotD etailsCoun t) { | |
240 | succes sful = fal se; | |
241 | setFai lureMessag e("PD coun t (" + sav edDetailsC ount + ") of (" + sa vedTotDeta ilsCount | |
242 | + ") indic ates incom plete deta ils"); | |
243 | } | |
244 | ||
245 | retu rn success ful; | |
246 | } | |
247 | ||
248 | pr ivate bool ean validP atientAcco unt(String patientAc count) { | |
249 | fina l String t rimmedPati entAccount = (patien tAccount = = null) ? "" : patie ntAccount. trim(); | |
250 | if ( trimmedPat ientAccoun t.length() < 11) { | |
251 | // Min imum lengt h (1 (fac- num) + 9 ( ssn) + 1 ( last name) == 11) | |
252 | setFai lureMessag e("Invalid PatientAc count: Doe s not meet minimum l ength requ irement.") ; | |
253 | return false; | |
254 | } | |
255 | ||
256 | if ( (savedFaci lityNum == null) || (savedFaci lityNum.le ngth() < 1 ) | |
257 | || !trim medPatient Account.st artsWith(s avedFacili tyNum)) { | |
258 | setFai lureMessag e("Invalid PatientAc count: Fac ility numb er does no t match PS record.") ; | |
259 | return false; | |
260 | } | |
261 | ||
262 | retu rn true; | |
263 | } | |
264 | ||
265 | /* * | |
266 | * Process s ite record . | |
267 | * / | |
268 | pr ivate bool ean proces sSiteRecor d(PSSite s ite) { | |
269 | bool ean succes sful = tru e; | |
270 | ||
271 | site .setPsRece ivedId(rec eivedId); | |
272 | ||
273 | // V erify the sequence n umber is t he expecte d value. | |
274 | if ( site.getSe qNum() == nextExpect edSeqNum) { | |
275 | ||
276 | // If the sequen ce number is 1 then save the e xpected to tal sequen ce | |
277 | // num ber or ver ify the to tal sequen ce number. | |
278 | if (si te.getSeqN um() == 1) { | |
279 | savedTot SeqNum = s ite.getTot SeqNum(); | |
280 | ||
281 | } else if (site. getTotSeqN um() != sa vedTotSeqN um) { | |
282 | successf ul = false ; | |
283 | setFailu reMessage( "Attempted to proces s PS with invalid to tal seq nu m (" + sit e.getTotSe qNum() | |
284 | + ") but exp ected (" + savedTotS eqNum + ") "); | |
285 | } | |
286 | ||
287 | // Ver ify the se quence num ber is val id. | |
288 | if (si te.getSeqN um() <= si te.getTotS eqNum()) { | |
289 | ||
290 | // Set t he next ex pected seq uence numb er. | |
291 | if (site .getSeqNum () < site. getTotSeqN um()) { | |
292 | ++nextExpe ctedSeqNum ; | |
293 | } else { | |
294 | nextExpect edSeqNum = 1; | |
295 | } | |
296 | ||
297 | // Final ly, save d ata. | |
298 | // The s equence nu mber. | |
299 | savedSeq Num = site .getSeqNum (); // Thi s PS seque nce | |
300 | savedTot StatementC ount = sit e.getTotSt atement(); // The nu mber | |
301 | // o f | |
302 | // e xpected | |
303 | // P H | |
304 | if (save dTotStatem entCount = = 0) { | |
305 | successful = false; | |
306 | setFailure Message("A ttempted t o process PS with in valid tota l statemen t count (0 )"); | |
307 | } | |
308 | ||
309 | } else { | |
310 | successf ul = false ; | |
311 | setFailu reMessage( "Attempted to proces s PS with invalid se q num (" + site.getS eqNum() + ") of (" | |
312 | + site.getTo tSeqNum() + ")"); | |
313 | } | |
314 | ||
315 | } el se { | |
316 | succes sful = fal se; | |
317 | setFai lureMessag e("Attempt ed to proc ess PS wit h invalid seq num (" + site.ge tSeqNum() + ") but e xpected (" | |
318 | + nextExpe ctedSeqNum + ")"); | |
319 | } | |
320 | ||
321 | retu rn success ful; | |
322 | } | |
323 | ||
324 | /* * | |
325 | * Process p atient rec ord. | |
326 | * / | |
327 | pr ivate bool ean proces sPatientRe cord(PSPat ient patie nt) { | |
328 | ||
329 | bool ean succes sful = tru e; | |
330 | ||
331 | // I ncrement t he count o f patient. | |
332 | ++sa vedStateme ntCount; | |
333 | ||
334 | // V erify the statement count is t he expecte d value. | |
335 | if ( savedState mentCount == nextExp ectedState mentCount) { | |
336 | ||
337 | // Ver ify the st atement co unt is val id. | |
338 | if (sa vedStateme ntCount <= savedTotS tatementCo unt) { | |
339 | ||
340 | // Set t he next ex pected sta tement cou nt. | |
341 | if (save dStatement Count < sa vedTotStat ementCount ) { | |
342 | ++nextExpe ctedStatem entCount; | |
343 | } else { | |
344 | nextExpect edStatemen tCount = 1 ; | |
345 | } | |
346 | ||
347 | // Final ly, save d ata. | |
348 | savedTot DetailsCou nt = patie nt.getNumO fLines(); // The num ber of | |
349 | // expected PD | |
350 | ||
351 | if (save dTotDetail sCount == 0) { | |
352 | successful = false; | |
353 | setFailure Message("A ttempted t o process PH with in valid tota l details count (0)" ); | |
354 | } else { | |
355 | successful = validPa tientAccou nt(patient .getPatien tAccount() ); | |
356 | } | |
357 | } else { | |
358 | successf ul = false ; | |
359 | setFailu reMessage( "Attempted to proces s PH with invalid co unt (" + s avedStatem entCount + ") of (" | |
360 | + savedTotSt atementCou nt + ")"); | |
361 | } | |
362 | ||
363 | } el se { | |
364 | succes sful = fal se; | |
365 | setFai lureMessag e("Attempt ed to proc ess PH wit h unexpect ed count ( " + savedS tatementCo unt | |
366 | + ") but e xpected (" + nextExp ectedState mentCount + ")"); | |
367 | } | |
368 | ||
369 | retu rn success ful; | |
370 | } | |
371 | ||
372 | /* * | |
373 | * Process d etails rec ord. | |
374 | * / | |
375 | pr ivate bool ean proces sDetailsRe cord(PSDet ails detai ls) { | |
376 | ||
377 | bool ean succes sful = tru e; | |
378 | ||
379 | // I ncrement t he count o f details. | |
380 | ++sa vedDetails Count; | |
381 | ||
382 | // V erify the details co unt is the expected value. | |
383 | if ( savedDetai lsCount == nextExpec tedDetails Count) { | |
384 | ||
385 | // Ver ify the de tails coun t is valid . | |
386 | if (sa vedDetails Count <= s avedTotDet ailsCount) { | |
387 | ||
388 | // Set t he next ex pected det ails count . | |
389 | if (save dDetailsCo unt < save dTotDetail sCount) { | |
390 | ++nextExpe ctedDetail sCount; | |
391 | } else { | |
392 | nextExpect edDetailsC ount = 1; | |
393 | } | |
394 | ||
395 | } else { | |
396 | successf ul = false ; | |
397 | setFailu reMessage( "Attempted to proces s PD with invalid co unt (" + s avedDetail sCount + " ) of (" | |
398 | + savedTotDe tailsCount + ")"); | |
399 | } | |
400 | ||
401 | } el se { | |
402 | succes sful = fal se; | |
403 | setFai lureMessag e("Attempt ed to proc ess PD wit h unexpect ed count ( " + savedD etailsCoun t + ") but expected (" | |
404 | + nextExpe ctedDetail sCount + " )"); | |
405 | } | |
406 | ||
407 | retu rn success ful; | |
408 | } | |
409 | ||
410 | /* * | |
411 | * Reset the site valu es from th e job exec ution to p repare to process ne xt | |
412 | * site. | |
413 | * / | |
414 | pr ivate void resetSite () { | |
415 | ||
416 | // R eset PH co unts. | |
417 | next ExpectedSt atementCou nt = 1; | |
418 | save dStatement Count = 0; | |
419 | save dTotStatem entCount = 0; | |
420 | ||
421 | rese tPatient() ; | |
422 | } | |
423 | ||
424 | /* * | |
425 | * Reset the patient v alues from the job e xecution t o prepare to process | |
426 | * next pati ent. | |
427 | * / | |
428 | pr ivate void resetPati ent() { | |
429 | ||
430 | // R eset PD co unts. | |
431 | next ExpectedDe tailsCount = 1; | |
432 | save dDetailsCo unt = 0; | |
433 | save dTotDetail sCount = 0 ; | |
434 | } | |
435 | ||
436 | /* * | |
437 | * Forcefull y stop the job proce ssing beca use an err or was det ected. | |
438 | * | |
439 | * @return R eturn a nu ll record to stop st ep process ing. | |
440 | * / | |
441 | pr ivate PSRe cord stopJ ob(final S tring stat us) { | |
442 | // L og message . | |
443 | proc essorLogge r.error("P rocessor e xecution e ncountered unrecover able error and force d stop"); | |
444 | // S et failure and messa ge. | |
445 | setF ailureStat us(status) ; | |
446 | // S top job. | |
447 | jobE xecution.s top(); | |
448 | ||
449 | retu rn null; | |
450 | } | |
451 | ||
452 | /* * | |
453 | * Forcefull y stop the job proce ssing beca use an err or was det ected. | |
454 | * | |
455 | * @return R eturn a nu ll record to stop st ep process ing. | |
456 | * / | |
457 | pr ivate PSRe cord stopJ ob(final S tring stat us, final String mes sage) { | |
458 | ||
459 | // S et failure . | |
460 | stop Job(status ); | |
461 | ||
462 | // S et failure message. | |
463 | setF ailureMess age(messag e); | |
464 | ||
465 | retu rn null; | |
466 | } | |
467 | ||
468 | /* * | |
469 | * Set the f ailure and message i n the job execution context. | |
470 | * / | |
471 | pr ivate void setFailur eStatusAnd Message(fi nal String status, f inal Strin g message) { | |
472 | // S et job fai lure. | |
473 | setF ailureStat us(status) ; | |
474 | // S et job fai lure messa ge. | |
475 | setF ailureMess age(messag e); | |
476 | } | |
477 | ||
478 | /* * | |
479 | * Set the f ailure in the job ex ecution co ntext. | |
480 | * / | |
481 | pr ivate void setFailur eStatus(fi nal String status) { | |
482 | // L og job fai lure statu s. | |
483 | proc essorLogge r.error("J ob failed with statu s: " + sta tus); | |
484 | ||
485 | // S et job fai lure. | |
486 | jobE xecution.g etExecutio nContext() .putString (JOB_FAILU RE_KEY, st atus); | |
487 | } | |
488 | ||
489 | /* * | |
490 | * Set the f ailure mes sage in th e job exec ution cont ext. | |
491 | * / | |
492 | pr ivate void setFailur eMessage(f inal Strin g message) { | |
493 | // L og job fai lure messa ge. | |
494 | proc essorLogge r.error("J ob failure message: " + messag e); | |
495 | ||
496 | // S et job fai lure messa ge. | |
497 | jobE xecution.g etExecutio nContext() .putString (JOB_FAILU RE_MESSAGE _KEY, mess age); | |
498 | } | |
499 | ||
500 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.