Produced by Araxis Merge on 11/14/2017 6:57:20 AM 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 | cbs.zip\cbs\cbs\src\main\java\gov\va\cpss\job\loadbill | LoadBillDelegateMultiItemWriter.java | Thu Nov 9 14:19:52 2017 UTC |
| 2 | cbs.zip\cbs\cbs\src\main\java\gov\va\cpss\job\loadbill | LoadBillDelegateMultiItemWriter.java | Tue Nov 14 12:26:23 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 476 |
| 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.loadbi ll; | |
| 2 | ||
| 3 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _FAILURE_K EY; | |
| 4 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _FAILURE_M ESSAGE_KEY ; | |
| 5 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.WRI TE_FAILURE _STATUS; | |
| 6 | ||
| 7 | import jav a.util.Arr ayList; | |
| 8 | import jav a.util.Lis t; | |
| 9 | ||
| 10 | import org .apache.lo g4j.Logger ; | |
| 11 | import org .springfra mework.bat ch.core.Ex itStatus; | |
| 12 | import org .springfra mework.bat ch.core.It emWriteLis tener; | |
| 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.St epExecutio nListener; | |
| 16 | import org .springfra mework.bat ch.item.Ex ecutionCon text; | |
| 17 | import org .springfra mework.bat ch.item.It emWriter; | |
| 18 | ||
| 19 | import gov .va.cpss.m odel.bal.S iteBalance ; | |
| 20 | import gov .va.cpss.s ervice.Loa dBillServi ce; | |
| 21 | ||
| 22 | /** | |
| 23 | * Impleme ntation of ItemWrite r used to handle wri ting of si te balance s when | |
| 24 | * process ing. | |
| 25 | * | |
| 26 | * @author DN S BROWNL | |
| 27 | */ | |
| 28 | public cla ss LoadBil lDelegateM ultiItemWr iter | |
| 29 | impl ements Ite mWriter<Li st<SiteBal ance>>, It emWriteLis tener<List <SiteBalan ce>>, Step ExecutionL istener { | |
| 30 | ||
| 31 | pr ivate fina l Logger w riterLogge r = Logger .getLogger (LoadBillD elegateMul tiItemWrit er.class.g etCanonica lName()); | |
| 32 | ||
| 33 | /* | |
| 34 | * Flag to i ndicate th at the job has been forcefully stopped a nd should no | |
| 35 | * longer at tempt writ es. | |
| 36 | * / | |
| 37 | pr ivate bool ean forceS top = fals e; | |
| 38 | ||
| 39 | pr ivate JobE xecution j obExecutio n; | |
| 40 | ||
| 41 | pr ivate Load BillServic e loadBill Service; | |
| 42 | ||
| 43 | /* | |
| 44 | * Delegate writer use d to take advantage of batch w riting sit e transact ion | |
| 45 | * records. Only write s new Site Balance r ecords. | |
| 46 | * / | |
| 47 | pr ivate Item Writer<Sit eBalance> newSiteBal DatabaseIt emWriter; | |
| 48 | ||
| 49 | /* | |
| 50 | * Delegate writer use d to take advantage of batch w riting sit e transact ion | |
| 51 | * records. Only updat es existin g Site Bal ance recod s. | |
| 52 | * / | |
| 53 | pr ivate Item Writer<Sit eBalance> existingSi teBalDatab aseItemWri ter; | |
| 54 | ||
| 55 | pu blic LoadB illService getLoadBi llService( ) { | |
| 56 | retu rn this.lo adBillServ ice; | |
| 57 | } | |
| 58 | ||
| 59 | pu blic void setLoadBil lService(L oadBillSer vice loadB illService ) { | |
| 60 | this .loadBillS ervice = l oadBillSer vice; | |
| 61 | } | |
| 62 | ||
| 63 | pu blic ItemW riter<Site Balance> g etNewSiteB alDatabase ItemWriter () { | |
| 64 | retu rn newSite BalDatabas eItemWrite r; | |
| 65 | } | |
| 66 | ||
| 67 | pu blic void setNewSite BalDatabas eItemWrite r(ItemWrit er<SiteBal ance> newS iteBalData baseItemWr iter) { | |
| 68 | this .newSiteBa lDatabaseI temWriter = newSiteB alDatabase ItemWriter ; | |
| 69 | } | |
| 70 | ||
| 71 | pu blic ItemW riter<Site Balance> g etExisting SiteBalDat abaseItemW riter() { | |
| 72 | retu rn existin gSiteBalDa tabaseItem Writer; | |
| 73 | } | |
| 74 | ||
| 75 | pu blic void setExistin gSiteBalDa tabaseItem Writer(Ite mWriter<Si teBalance> existingS iteBalData baseItemWr iter) { | |
| 76 | this .existingS iteBalData baseItemWr iter = exi stingSiteB alDatabase ItemWriter ; | |
| 77 | } | |
| 78 | ||
| 79 | @O verride | |
| 80 | pu blic void write(List <? extends List<Site Balance>> items) thr ows Except ion { | |
| 81 | ||
| 82 | writ erLogger.d ebug("Begi n Write"); | |
| 83 | ||
| 84 | // D o not atte mpt to wri te if forc ed stop. | |
| 85 | if ( forceStop) { | |
| 86 | return ; | |
| 87 | } | |
| 88 | ||
| 89 | try { | |
| 90 | // Com bined list of site b alance lis ts. | |
| 91 | List<S iteBalance > newSiteB alL = new ArrayList< >(); | |
| 92 | List<S iteBalance > existing SiteBalL = new Array List<>(); | |
| 93 | // Loo p through all of the statement s to write . | |
| 94 | ||
| 95 | for (L ist<SiteBa lance> sbL : items) { | |
| 96 | for(Site Balance si teBal: sbL ) { | |
| 97 | // If a re cord with the same s tation and account n umbers is present, u pdate that record wi th new inf ormation. | |
| 98 | if(loadBil lService.g etSiteBala nceByAcntN umAndStati onNum(site Bal.getPat ientDfn(), siteBal.g etStationN um()) == n ull) { | |
| 99 | ne wSiteBalL. add(siteBa l); | |
| 100 | } | |
| 101 | else { | |
| 102 | ex istingSite BalL.add(s iteBal); | |
| 103 | } | |
| 104 | } | |
| 105 | } | |
| 106 | ||
| 107 | // We can use ba tch to sav e the comb ined list. | |
| 108 | // Ens ure that a t least on e record i s being up dated or a dded. | |
| 109 | if (!n ewSiteBalL .isEmpty() || !exist ingSiteBal L.isEmpty( )) { | |
| 110 | writerLo gger.debug ("Writing new Site B alances"); | |
| 111 | newSiteB alDatabase ItemWriter .write(new SiteBalL); | |
| 112 | writerLo gger.debug ("Updating existing Site Balan ces"); | |
| 113 | existing SiteBalDat abaseItemW riter.writ e(existing SiteBalL); | |
| 114 | // Keep a running total of t he amount of facilit ies and pa tients | |
| 115 | Executio nContext e xecContext = jobExec ution.getE xecutionCo ntext(); | |
| 116 | int prev iousPatien tTotal = 0 ; | |
| 117 | if(execC ontext.con tainsKey(L oadBillPro cessingCon stants.TOT AL_PATIENT _COUNT_KEY )) { | |
| 118 | previousPa tientTotal = execCon text.getIn t(LoadBill Processing Constants. TOTAL_PATI ENT_COUNT_ KEY); | |
| 119 | } | |
| 120 | execCont ext.putInt (LoadBillP rocessingC onstants.T OTAL_PATIE NT_COUNT_K EY, | |
| 121 | ne wSiteBalL. size() + e xistingSit eBalL.size () + previ ousPatient Total); | |
| 122 | } | |
| 123 | } ca tch (Excep tion e) { | |
| 124 | ||
| 125 | String Builder er ror = new StringBuil der(); | |
| 126 | error. append("Er ror during write bec ause of ") ; | |
| 127 | error. append(e.g etClass(). getSimpleN ame()); | |
| 128 | error. append("\n Cause: "); | |
| 129 | error. append(e.g etCause(). getMessage ().trim()) ; | |
| 130 | ||
| 131 | // Unr ecoverable error so stop the j ob. | |
| 132 | stopJo b(WRITE_FA ILURE_STAT US, error. toString() ); | |
| 133 | } | |
| 134 | ||
| 135 | writ erLogger.d ebug("End Write"); | |
| 136 | } | |
| 137 | ||
| 138 | @O verride | |
| 139 | pu blic void beforeWrit e(List<? e xtends Lis t<SiteBala nce>> item s) { | |
| 140 | forc eStop = fa lse; | |
| 141 | if ( jobExecuti on.getExec utionConte xt().conta insKey(JOB _FAILURE_K EY)) { | |
| 142 | writer Logger.err or("System failure d etected.") ; | |
| 143 | forceS top = true ; | |
| 144 | } | |
| 145 | } | |
| 146 | ||
| 147 | @O verride | |
| 148 | pu blic void afterWrite (List<? ex tends List <SiteBalan ce>> items ) { | |
| 149 | } | |
| 150 | ||
| 151 | @O verride | |
| 152 | pu blic void onWriteErr or(Excepti on e, List <? extends List<Site Balance>> items) { | |
| 153 | ||
| 154 | writ erLogger.e rror("Writ er encount ered syste m error an d forced s top"); | |
| 155 | ||
| 156 | Stri ngBuilder error = ne w StringBu ilder(); | |
| 157 | erro r.append(" Unable to write item because o f "); | |
| 158 | erro r.append(e .getClass( ).getSimpl eName()); | |
| 159 | erro r.append(" \nMessage: "); | |
| 160 | erro r.append(e .getMessag e()); | |
| 161 | if ( (e.getCaus e() != nul l) && (e.g etCause(). getMessage () != null )) { | |
| 162 | error. append("\n Cause: "); | |
| 163 | error. append(e.g etCause(). getMessage ().trim()) ; | |
| 164 | } | |
| 165 | ||
| 166 | // S et failure and messa ge. | |
| 167 | stop Job(WRITE_ FAILURE_ST ATUS, "Unr ecoverable writer er ror"); | |
| 168 | } | |
| 169 | ||
| 170 | @O verride | |
| 171 | pu blic void beforeStep (StepExecu tion stepE xecution) { | |
| 172 | writ erLogger.i nfo("Befor e Step Exe cution"); | |
| 173 | // S ave the jo b executio n at the b eginning o f the step . | |
| 174 | // T he executi on context will be u sed to set key value s as data is | |
| 175 | // p rocessed. | |
| 176 | jobE xecution = stepExecu tion.getJo bExecution (); | |
| 177 | } | |
| 178 | ||
| 179 | @O verride | |
| 180 | pu blic ExitS tatus afte rStep(Step Execution stepExecut ion) { | |
| 181 | writ erLogger.i nfo("After Step Exec ution"); | |
| 182 | // D o not need to do any thing afte r step. | |
| 183 | retu rn null; | |
| 184 | } | |
| 185 | ||
| 186 | /* * | |
| 187 | * Forcefull y stop the job proce ssing beca use a fail ure was de tected. | |
| 188 | * | |
| 189 | * @param st atus | |
| 190 | * The stat us for the failure. | |
| 191 | * @param me ssage | |
| 192 | * The mess age associ ated with the status failure. | |
| 193 | * / | |
| 194 | pr ivate void stopJob(f inal Strin g status, final Stri ng message ) { | |
| 195 | ||
| 196 | // S et the fla g to indic ate the jo b has been forcefull y stopped. | |
| 197 | forc eStop = tr ue; | |
| 198 | ||
| 199 | // L og message . | |
| 200 | writ erLogger.e rror("Writ er executi on encount ered unrec overable e rror and f orced stop "); | |
| 201 | ||
| 202 | // S et failure and messa ge. | |
| 203 | setF ailureStat us(status) ; | |
| 204 | ||
| 205 | // S et failure message. | |
| 206 | setF ailureMess age(messag e); | |
| 207 | } | |
| 208 | ||
| 209 | /* * | |
| 210 | * Set the f ailure in the job ex ecution co ntext. | |
| 211 | * | |
| 212 | * @param st atus | |
| 213 | * The fail ure status . | |
| 214 | * / | |
| 215 | pr ivate void setFailur eStatus(fi nal String status) { | |
| 216 | ||
| 217 | // L og job fai lure statu s. | |
| 218 | writ erLogger.e rror("Job failed wit h status: " + status ); | |
| 219 | ||
| 220 | // S et job fai lure. | |
| 221 | jobE xecution.g etExecutio nContext() .putString (JOB_FAILU RE_KEY, st atus); | |
| 222 | } | |
| 223 | ||
| 224 | /* * | |
| 225 | * Set the f ailure mes sage in th e job exec ution cont ext. | |
| 226 | * | |
| 227 | * @param me ssage | |
| 228 | * The mess age to ass ociate wit h the erro r status. | |
| 229 | * / | |
| 230 | pr ivate void setFailur eMessage(f inal Strin g message) { | |
| 231 | ||
| 232 | // L og job fai lure messa ge. | |
| 233 | writ erLogger.e rror("Job failure me ssage: " + message); | |
| 234 | ||
| 235 | // S et job fai lure messa ge. | |
| 236 | jobE xecution.g etExecutio nContext() .putString (JOB_FAILU RE_MESSAGE _KEY, mess age); | |
| 237 | } | |
| 238 | ||
| 239 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.