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\cbs | CbsPatientEntryItemProcessor.java | Wed Feb 1 21:07:30 2017 UTC |
2 | cpss.zip\cpss\src\main\java\gov\va\cpss\job\cbs | CbsPatientEntryItemProcessor.java | Fri Feb 3 20:40:27 2017 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 526 |
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.cbs; | |
2 | ||
3 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.BAT CH_RUN_ID_ KEY; | |
4 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.DAT A_ERROR_ST ATUS; | |
5 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _ERROR_KEY ; | |
6 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _ERROR_MES SAGE_KEY; | |
7 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _FAILURE_K EY; | |
8 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _FAILURE_M ESSAGE_KEY ; | |
9 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.PRO CESSING_FA ILURE_STAT US; | |
10 | ||
11 | import jav a.util.Lis t; | |
12 | import jav a.util.Map .Entry; | |
13 | ||
14 | import org .apache.lo g4j.Logger ; | |
15 | import org .springfra mework.bat ch.core.It emProcessL istener; | |
16 | import org .springfra mework.bat ch.core.Jo bExecution ; | |
17 | import org .springfra mework.bat ch.core.St epExecutio n; | |
18 | import org .springfra mework.bat ch.core.an notation.A fterStep; | |
19 | import org .springfra mework.bat ch.core.an notation.B eforeStep; | |
20 | import org .springfra mework.bat ch.item.It emProcesso r; | |
21 | ||
22 | import gov .va.cpss.m odel.cbs.C BSStmt; | |
23 | import gov .va.cpss.m odel.fps.P SPatient; | |
24 | import gov .va.cpss.s ervice.Cbs Service; | |
25 | ||
26 | /** | |
27 | * Custom ItemProces sor used b y the Gene rate CBS D ata batch job to con solidate s tatements | |
28 | * in a me mory map o f CBS Acco unt ID to list of as sociated P SPatient r ecords. | |
29 | * | |
30 | * @author DN S P II | |
31 | */ | |
32 | public cla ss CbsPati entEntryIt emProcesso r implemen ts ItemPro cessor<Ent ry<Long, L ist<PSPati ent>>, CBS Stmt>, | |
33 | Item ProcessLis tener<Entr y<Long, Li st<PSPatie nt>>, CBSS tmt> { | |
34 | ||
35 | /* | |
36 | * Flag to i ndicate th at the job has been forcefully stopped a nd should no | |
37 | * longer at tempt proc essing. | |
38 | * / | |
39 | pr ivate bool ean forceS top = fals e; | |
40 | ||
41 | pr ivate fina l Logger p rocessorLo gger; | |
42 | ||
43 | pr ivate JobE xecution j obExecutio n; | |
44 | ||
45 | pr ivate Long batchRunI d; | |
46 | ||
47 | pr ivate CbsS ervice cbs Service; | |
48 | ||
49 | pu blic CbsPa tientEntry ItemProces sor() { | |
50 | proc essorLogge r = Logger .getLogger (this.getC lass().get CanonicalN ame()); | |
51 | } | |
52 | ||
53 | pu blic CbsSe rvice getC bsService( ) { | |
54 | retu rn cbsServ ice; | |
55 | } | |
56 | ||
57 | pu blic void setCbsServ ice(CbsSer vice cbsSe rvice) { | |
58 | this .cbsServic e = cbsSer vice; | |
59 | } | |
60 | ||
61 | @O verride | |
62 | pu blic CBSSt mt process (Entry<Lon g, List<PS Patient>> pojo) thro ws Excepti on { | |
63 | ||
64 | proc essorLogge r.info("Be gin Proces s"); | |
65 | ||
66 | // D o not atte mpt to pro cess if fo rced stop. | |
67 | if ( forceStop) { | |
68 | return null; | |
69 | } | |
70 | ||
71 | fina l long cbs sAccount = pojo.getK ey(); | |
72 | ||
73 | proc essorLogge r.info("Pr ocessing p atient rec ord list f or CBS Acc ount: " + cbssAccoun t); | |
74 | ||
75 | CBSS tmt statem ent = null ; | |
76 | ||
77 | // A t this poi nt batchRu nId FK sho uld not be null. | |
78 | if ( batchRunId != null) { | |
79 | ||
80 | try { | |
81 | ||
82 | statemen t = cbsSer vice.build StatementF orPatientM ap(batchRu nId, pojo) ; | |
83 | ||
84 | // If th e statemen t is null then just continue p rocessing. | |
85 | if (stat ement == n ull) { | |
86 | ||
87 | setDataErr orAndMessa ge( | |
88 | "No statement can be gen erated for CBS Accou nt (" + cb ssAccount + ") but w ill contin ue process ing"); | |
89 | } | |
90 | ||
91 | } catc h (Excepti on e) { | |
92 | ||
93 | // Unrec overable e rror so st op the job . | |
94 | stopJob( PROCESSING _FAILURE_S TATUS, "Un recoverabl e processi ng error: " + e.getM essage()); | |
95 | } | |
96 | ||
97 | } el se { | |
98 | ||
99 | // Unr ecoverable error so stop the j ob. | |
100 | stopJo b(PROCESSI NG_FAILURE _STATUS, " Attempted to process with a nu ll Batch R un FK"); | |
101 | } | |
102 | ||
103 | proc essorLogge r.info("En d Process" ); | |
104 | ||
105 | // I f flagged to forcefu lly stop t hen return null whic h will eff ectively | |
106 | // s top proces sing. | |
107 | if ( forceStop) { | |
108 | return null; | |
109 | } | |
110 | ||
111 | // R eturn the statement. | |
112 | retu rn stateme nt; | |
113 | } | |
114 | ||
115 | /* * | |
116 | * Before pr ocessing c apture the job execu tion and t he receive d id for d ata | |
117 | * processin g. | |
118 | * | |
119 | * @param st epExecutio n | |
120 | * / | |
121 | @B eforeStep | |
122 | pu blic void beforeStep (StepExecu tion stepE xecution) { | |
123 | proc essorLogge r.info("Be fore Step Execution" ); | |
124 | ||
125 | // S ave the jo b executio n at the b eginning o f the step . | |
126 | // T he executi on context will be u sed to set key value s as data is | |
127 | // p rocessed. | |
128 | jobE xecution = stepExecu tion.getJo bExecution (); | |
129 | ||
130 | // S ave the ba tchRunId a t the begi nning of t he step. | |
131 | // I t is obtai ned by the batch pri or to the job and pa ssed as a job | |
132 | // p arameter w hen the jo b starts. | |
133 | batc hRunId = j obExecutio n.getJobPa rameters() .getLong(B ATCH_RUN_I D_KEY); | |
134 | } | |
135 | ||
136 | /* * | |
137 | * After pro cessing ch eck for un expected c onditions that sugge st an erro r. | |
138 | * | |
139 | * @param st epExecutio n | |
140 | * / | |
141 | @A fterStep | |
142 | pu blic void afterStep( StepExecut ion stepEx ecution) { | |
143 | ||
144 | proc essorLogge r.info("Af ter Step E xecution") ; | |
145 | } | |
146 | ||
147 | @O verride | |
148 | pu blic void beforeProc ess(Entry< Long, List <PSPatient >> item) { | |
149 | proc essorLogge r.info("Be fore Proce ss"); | |
150 | forc eStop = fa lse; | |
151 | if ( jobExecuti on.getExec utionConte xt().conta insKey(JOB _FAILURE_K EY)) { | |
152 | proces sorLogger. error("Sys tem failur e detected ."); | |
153 | forceS top = true ; | |
154 | } | |
155 | } | |
156 | ||
157 | @O verride | |
158 | pu blic void afterProce ss(Entry<L ong, List< PSPatient> > item, CB SStmt resu lt) { | |
159 | // D o not need to do any thing afte r process. | |
160 | } | |
161 | ||
162 | @O verride | |
163 | pu blic void onProcessE rror(Entry <Long, Lis t<PSPatien t>> item, Exception e) { | |
164 | proc essorLogge r.error("P rocessor e ncountered system er ror and fo rced stop" ); | |
165 | ||
166 | Stri ngBuilder error = ne w StringBu ilder(); | |
167 | erro r.append(" Unable to process it em because of "); | |
168 | erro r.append(e .getClass( ).getSimpl eName()); | |
169 | erro r.append(" \nMessage: "); | |
170 | erro r.append(e .getMessag e()); | |
171 | erro r.append(" \nCause: " ); | |
172 | erro r.append(e .getCause( ).getMessa ge().trim( )); | |
173 | ||
174 | // S et failure and messa ge. | |
175 | stop Job(PROCES SING_FAILU RE_STATUS, "Unrecove rable proc essor erro r"); | |
176 | } | |
177 | ||
178 | /* * | |
179 | * Forcefull y stop the job proce ssing beca use a fail ure was de tected. | |
180 | * | |
181 | * @return R eturn a nu ll record to stop st ep process ing. | |
182 | * / | |
183 | pr ivate void stopJob(f inal Strin g status, final Stri ng message ) { | |
184 | ||
185 | // S et the fla g to indic ate the jo b has been forcefull y stopped. | |
186 | forc eStop = tr ue; | |
187 | ||
188 | // L og message . | |
189 | proc essorLogge r.error("P rocessor e xecution e ncountered unrecover able error and force d stop"); | |
190 | ||
191 | // S et failure and messa ge. | |
192 | setF ailureStat us(status) ; | |
193 | ||
194 | // S et failure message. | |
195 | setF ailureMess age(messag e); | |
196 | } | |
197 | ||
198 | /* * | |
199 | * Set the d ata error and messag e in the j ob executi on context . This is an | |
200 | * error con dition tha t allows c ontinuing processing . | |
201 | * | |
202 | * @param me ssage | |
203 | * The mess age to ass ociate wit h the data error sta tus. | |
204 | * / | |
205 | pr ivate void setDataEr rorAndMess age(final String mes sage) { | |
206 | ||
207 | // L og job err or status. | |
208 | proc essorLogge r.error("J ob error w ith status : " + DATA _ERROR_STA TUS); | |
209 | ||
210 | // L og job err or message . | |
211 | proc essorLogge r.error("J ob error m essage: " + message) ; | |
212 | ||
213 | // S et job err or. | |
214 | jobE xecution.g etExecutio nContext() .putString (JOB_ERROR _KEY, DATA _ERROR_STA TUS); | |
215 | ||
216 | // A ppend mess age to job context i f already exists. | |
217 | Stri ng existin gErrorMess age = null ; | |
218 | Stri ngBuffer e rrorMessag eBuff = ne w StringBu ffer(); | |
219 | ||
220 | // A dd (append if necess ary) to th e job exec ution. | |
221 | if ( jobExecuti on.getExec utionConte xt().conta insKey(JOB _ERROR_MES SAGE_KEY)) { | |
222 | existi ngErrorMes sage = job Execution. getExecuti onContext( ).getStrin g(JOB_ERRO R_MESSAGE_ KEY); | |
223 | } | |
224 | if ( existingEr rorMessage != null) { | |
225 | errorM essageBuff .append(ex istingErro rMessage); | |
226 | } | |
227 | // M essage sho uld always be unique so always append. | |
228 | erro rMessageBu ff.append( message); | |
229 | ||
230 | // S et job err or message . | |
231 | jobE xecution.g etExecutio nContext() .putString (JOB_ERROR _MESSAGE_K EY, messag e); | |
232 | } | |
233 | ||
234 | /* * | |
235 | * Set the f ailure in the job ex ecution co ntext. | |
236 | * | |
237 | * @param st atus | |
238 | * The fail ure status . | |
239 | * / | |
240 | pr ivate void setFailur eStatus(fi nal String status) { | |
241 | ||
242 | // L og job fai lure statu s. | |
243 | proc essorLogge r.error("J ob failed with statu s: " + sta tus); | |
244 | ||
245 | // S et job fai lure. | |
246 | jobE xecution.g etExecutio nContext() .putString (JOB_FAILU RE_KEY, st atus); | |
247 | } | |
248 | ||
249 | /* * | |
250 | * Set the f ailure mes sage in th e job exec ution cont ext. | |
251 | * | |
252 | * @param me ssage | |
253 | * The mess age to ass ociate wit h the erro r status. | |
254 | * / | |
255 | pr ivate void setFailur eMessage(f inal Strin g message) { | |
256 | ||
257 | // L og job fai lure messa ge. | |
258 | proc essorLogge r.error("J ob failure message: " + messag e); | |
259 | ||
260 | // S et job fai lure messa ge. | |
261 | jobE xecution.g etExecutio nContext() .putString (JOB_FAILU RE_MESSAGE _KEY, mess age); | |
262 | } | |
263 | ||
264 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.