Produced by Araxis Merge on 2/7/2017 12:14:08 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\service | FpsService.java | Wed Feb 1 21:07:26 2017 UTC |
2 | cpss.zip\cpss\src\main\java\gov\va\cpss\service | FpsService.java | Mon Feb 6 15:17:35 2017 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 712 |
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. service; | |
2 | ||
3 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _FAILURE_K EY; | |
4 | import sta tic gov.va .cpss.job. fps.FpsPro cessingCon stants.TOT AL_SITE_CO UNT_KEY; | |
5 | import sta tic gov.va .cpss.job. fps.FpsPro cessingCon stants.TOT AL_STATEME NT_COUNT_K EY; | |
6 | ||
7 | import jav a.sql.Time stamp; | |
8 | import jav a.util.Arr ayList; | |
9 | import jav a.util.Cal endar; | |
10 | import jav a.util.Lis t; | |
11 | import jav a.util.Map ; | |
12 | import jav a.util.str eam.Collec tors; | |
13 | ||
14 | import org .apache.lo g4j.Logger ; | |
15 | import org .springfra mework.bat ch.core.Ex itStatus; | |
16 | import org .springfra mework.bat ch.core.Jo bExecution ; | |
17 | import org .springfra mework.ste reotype.Se rvice; | |
18 | ||
19 | import gov .va.cpss.d ao.PSDetai lsDAO; | |
20 | import gov .va.cpss.d ao.PSPatie ntDAO; | |
21 | import gov .va.cpss.d ao.PSRecei vedDAO; | |
22 | import gov .va.cpss.d ao.PSSiteD AO; | |
23 | import gov .va.cpss.d ao.Process StatusDAO; | |
24 | import gov .va.cpss.m odel.Proce ssStatus; | |
25 | import gov .va.cpss.m odel.fps.P SDetails; | |
26 | import gov .va.cpss.m odel.fps.P SPatient; | |
27 | import gov .va.cpss.m odel.fps.P SReceived; | |
28 | import gov .va.cpss.m odel.fps.P SSite; | |
29 | ||
30 | /** | |
31 | * Service class for handling activities relating to process ing FPS Da ta. | |
32 | * | |
33 | * @author DN S D N S | |
34 | */ | |
35 | @Service | |
36 | public cla ss FpsServ ice { | |
37 | ||
38 | pr ivate stat ic final L ogger logg er = Logge r.getLogge r(FpsServi ce.class.g etCanonica lName()); | |
39 | ||
40 | pr ivate Proc essStatusD AO process StatusDAO; | |
41 | pr ivate PSRe ceivedDAO psReceived DAO; | |
42 | pr ivate PSSi teDAO psSi teDAO; | |
43 | pr ivate PSPa tientDAO p sPatientDA O; | |
44 | pr ivate PSDe tailsDAO p sDetailsDA O; | |
45 | ||
46 | pu blic FpsSe rvice() { | |
47 | } | |
48 | ||
49 | pu blic Proce ssStatusDA O getProce ssStatusDA O() { | |
50 | retu rn process StatusDAO; | |
51 | } | |
52 | ||
53 | pu blic void setProcess StatusDAO( ProcessSta tusDAO pro cessStatus DAO) { | |
54 | this .processSt atusDAO = processSta tusDAO; | |
55 | } | |
56 | ||
57 | pu blic PSRec eivedDAO g etPsReceiv edDAO() { | |
58 | retu rn psRecei vedDAO; | |
59 | } | |
60 | ||
61 | pu blic void setPsRecei vedDAO(PSR eceivedDAO psReceive dDAO) { | |
62 | this .psReceive dDAO = psR eceivedDAO ; | |
63 | } | |
64 | ||
65 | pu blic PSSit eDAO getPs SiteDAO() { | |
66 | retu rn psSiteD AO; | |
67 | } | |
68 | ||
69 | pu blic void setPsSiteD AO(PSSiteD AO psSiteD AO) { | |
70 | this .psSiteDAO = psSiteD AO; | |
71 | } | |
72 | ||
73 | pu blic PSPat ientDAO ge tPsPatient DAO() { | |
74 | retu rn psPatie ntDAO; | |
75 | } | |
76 | ||
77 | pu blic void setPsPatie ntDAO(PSPa tientDAO p sPatientDA O) { | |
78 | this .psPatient DAO = psPa tientDAO; | |
79 | } | |
80 | ||
81 | pu blic PSDet ailsDAO ge tPsDetails DAO() { | |
82 | retu rn psDetai lsDAO; | |
83 | } | |
84 | ||
85 | pu blic void setPsDetai lsDAO(PSDe tailsDAO p sDetailsDA O) { | |
86 | this .psDetails DAO = psDe tailsDAO; | |
87 | } | |
88 | ||
89 | pu blic PSRec eived star tProcessFp sDataJob(f inal int b atchRunId, final Str ing fileNa me) { | |
90 | ||
91 | logg er.info("S tarting Pr ocess FPS Data Job") ; | |
92 | ||
93 | PSRe ceived pR = null; | |
94 | ||
95 | Inte ger proces sStatus = processSta tusDAO.get StatusFrom Enum(Proce ssStatus.S tatus.INIT IAL); | |
96 | ||
97 | if ( processSta tus != nul l) { | |
98 | Timest amp receiv edDate = n ew Timesta mp(Calenda r.getInsta nce().getT ime().getT ime()); | |
99 | ||
100 | pR = n ew PSRecei ved(batchR unId, proc essStatus, receivedD ate, fileN ame); | |
101 | ||
102 | long r eceivedId = psReceiv edDAO.save (pR); | |
103 | pR.set Id(receive dId); | |
104 | } el se { | |
105 | logger .error("Un able to ob tain statu s mapping for: " + P rocessStat us.Status. INITIAL); | |
106 | } | |
107 | ||
108 | retu rn pR; | |
109 | } | |
110 | ||
111 | pu blic boole an endProc essFpsData Job(JobExe cution exe cution, PS Received p sReceived) { | |
112 | ||
113 | bool ean jobSuc cess = fal se; | |
114 | ||
115 | if ( execution == null) { | |
116 | ||
117 | logger .error("Jo b ended wi th null ex ecution"); | |
118 | errorP rocessFpsD ataJob(psR eceived); | |
119 | ||
120 | } el se if (exe cution.get ExitStatus () != Exit Status.COM PLETED) { | |
121 | ||
122 | if (ex ecution.ge tExecution Context(). containsKe y(JOB_FAIL URE_KEY)) { | |
123 | logger.e rror("Job ended with failure: " + execut ion.getExe cutionCont ext().getS tring(JOB_ FAILURE_KE Y)); | |
124 | } else { | |
125 | logger.e rror("Job ended with unknown e rror: " + execution. getExitSta tus()); | |
126 | } | |
127 | errorP rocessFpsD ataJob(psR eceived); | |
128 | } el se { | |
129 | ||
130 | jobSuc cess = suc cessProces sFpsDataJo b(executio n, psRecei ved); | |
131 | ||
132 | // If unable to successful ly save th en treat a s an error . | |
133 | if (!j obSuccess) { | |
134 | errorPro cessFpsDat aJob(psRec eived); | |
135 | } | |
136 | } | |
137 | ||
138 | logg er.info("E nd Process FPS Data Job"); | |
139 | ||
140 | retu rn jobSucc ess; | |
141 | } | |
142 | ||
143 | pr ivate void errorProc essFpsData Job(PSRece ived psRec eived) { | |
144 | ||
145 | // B e sure to delete any partial p rocessed d ata. | |
146 | // D eleting th e site ent ries will cascade de lete throu gh the chi ld | |
147 | // t ables. | |
148 | psSi teDAO.dele teByReceiv edId(psRec eived.getI d()); | |
149 | ||
150 | Inte ger proces sStatus = processSta tusDAO.get StatusFrom Enum(Proce ssStatus.S tatus.ERRO R); | |
151 | ||
152 | if ( processSta tus != nul l) { | |
153 | psRece ived.setSt atusId(pro cessStatus ); | |
154 | ||
155 | psRece ivedDAO.up dateStatus (psReceive d); | |
156 | } el se { | |
157 | logger .error("Un able to ob tain statu s mapping for: " + P rocessStat us.Status. ERROR); | |
158 | } | |
159 | } | |
160 | ||
161 | pr ivate bool ean succes sProcessFp sDataJob(J obExecutio n executio n, PSRecei ved psRece ived) { | |
162 | ||
163 | bool ean comple teSuccess = true; | |
164 | ||
165 | if ( execution. getExecuti onContext( ).contains Key(TOTAL_ SITE_COUNT _KEY)) { | |
166 | psRece ived.setNu mOfSite(ex ecution.ge tExecution Context(). getLong(TO TAL_SITE_C OUNT_KEY)) ; | |
167 | } el se { | |
168 | logger .error("Un able to ob tain total site coun t from pro cess resul ts"); | |
169 | comple teSuccess = false; | |
170 | } | |
171 | ||
172 | if ( execution. getExecuti onContext( ).contains Key(TOTAL_ STATEMENT_ COUNT_KEY) ) { | |
173 | psRece ived.setNu mOfStateme nt(executi on.getExec utionConte xt().getLo ng(TOTAL_S TATEMENT_C OUNT_KEY)) ; | |
174 | } el se { | |
175 | logger .error("Un able to ob tain total statement count fro m process results"); | |
176 | comple teSuccess = false; | |
177 | } | |
178 | ||
179 | if ( completeSu ccess) { | |
180 | ||
181 | // If successful ly process ed set the status to NEW to in dicate rea dy | |
182 | // for processin g. | |
183 | Intege r processS tatus = pr ocessStatu sDAO.getSt atusFromEn um(Process Status.Sta tus.NEW); | |
184 | ||
185 | if (pr ocessStatu s != null) { | |
186 | ||
187 | psReceiv ed.setStat usId(proce ssStatus); | |
188 | psReceiv edDAO.upda teResults( psReceived ); | |
189 | ||
190 | } else { | |
191 | ||
192 | logger.e rror("Unab le to obta in status mapping fo r: " + Pro cessStatus .Status.NE W); | |
193 | complete Success = false; | |
194 | } | |
195 | } | |
196 | ||
197 | retu rn complet eSuccess; | |
198 | } | |
199 | ||
200 | pu blic Long getLastSit eIndex() { | |
201 | retu rn psSiteD AO.getLast Index(); | |
202 | } | |
203 | ||
204 | pu blic Long getLastPat ientIndex( ) { | |
205 | retu rn psPatie ntDAO.getL astIndex() ; | |
206 | } | |
207 | ||
208 | pu blic Long getLastDet ailsIndex( ) { | |
209 | retu rn psDetai lsDAO.getL astIndex() ; | |
210 | } | |
211 | ||
212 | pu blic PSSit e getPSSit eById(fina l long id) { | |
213 | retu rn psSiteD AO.getById (id); | |
214 | } | |
215 | ||
216 | /* * | |
217 | * Returns a List of a ll PSSite records fo r NEW PSRe ceived rec ords. | |
218 | * | |
219 | * @return | |
220 | * / | |
221 | pu blic List< PSSite> ge tPSSitesFo rNewPSRece ived() { | |
222 | List <PSSite> p sSites = n ew ArrayLi st<>(); | |
223 | ||
224 | Inte ger newSta tus = proc essStatusD AO.getStat usFromEnum (ProcessSt atus.Statu s.NEW); | |
225 | ||
226 | if ( newStatus != null) { | |
227 | psSite s = psSite DAO.getAll ForPSRecei vedStatusI d(newStatu s); | |
228 | } el se { | |
229 | ||
230 | logger .error("Un able to ob tain statu s mapping for: " + P rocessStat us.Status. NEW); | |
231 | } | |
232 | ||
233 | retu rn psSites ; | |
234 | } | |
235 | ||
236 | pu blic List< PSSite> ge tPSSiteFor PSReceived ID(final l ong id) { | |
237 | retu rn psSiteD AO.getAllB yPSReceive dID(id); | |
238 | } | |
239 | ||
240 | pu blic List< Long> getP SSiteIDLis tForPSRece ivedID(fin al long id ) { | |
241 | retu rn psSiteD AO.getAllI DByPSRecei vedID(id); | |
242 | } | |
243 | ||
244 | pu blic List< PSPatient> getPSPati entListFor PSSiteID(f inal long id) { | |
245 | ||
246 | // F irst get t he PSSite from datab ase. | |
247 | PSSi te psSite = psSiteDA O.getById( id); | |
248 | ||
249 | retu rn getPSPa tientListF orPSSite(p sSite); | |
250 | } | |
251 | ||
252 | pu blic List< PSPatient> getPSPati entListFor PSSite(fin al PSSite psSite) { | |
253 | ||
254 | List <PSPatient > psPatien tL = null; | |
255 | ||
256 | if ( psSite != null) { | |
257 | ||
258 | // The n get all PSPatient from datab ase. | |
259 | psPati entL = psP atientDAO. getAllByPS SiteID(psS ite); | |
260 | ||
261 | // The n get all PSDetails from datab ase. | |
262 | if (ps PatientL ! = null) { | |
263 | ||
264 | List<PSD etails> ps DetailsL = psDetails DAO.getAll ByPSSiteID (psSite); | |
265 | ||
266 | // Sort into a map (PSPatien t.ID to Li st<PSDetai ls>) for t he | |
267 | // list of PSDetai ls. | |
268 | Map<Long , List<PSD etails>> d etailsQuer yM = psDet ailsL.stre am() | |
269 | .c ollect(Col lectors.gr oupingBy(w -> w.getP sPatientId ())); | |
270 | ||
271 | // Set t he appropr iate detai ls list in the PSPat ient. | |
272 | for (PSP atient psP atient : p sPatientL) { | |
273 | List<PSDet ails> psDe tailsMapEn try = deta ilsQueryM. get(psPati ent.getId( )); | |
274 | // If no l ist then c reate an e mpty list. | |
275 | if (psDeta ilsMapEntr y != null) { | |
276 | ps Patient.se tPsDetails L(psDetail sMapEntry) ; | |
277 | } else { | |
278 | lo gger.error ("Unrecove rable data error, de tails map is null fo r patient" ); | |
279 | re turn null; | |
280 | } | |
281 | } | |
282 | } | |
283 | ||
284 | } | |
285 | ||
286 | retu rn psPatie ntL; | |
287 | } | |
288 | ||
289 | /* * | |
290 | * Get the N EW receive d data. | |
291 | * | |
292 | * @return L ist of PSR eceived ID associate d with the NEW data records. | |
293 | * / | |
294 | pu blic List< Long> getN ewPSReceiv edIDList() { | |
295 | ||
296 | List <Long> idL = new Arr ayList<>() ; | |
297 | ||
298 | Inte ger newSta tus = proc essStatusD AO.getStat usFromEnum (ProcessSt atus.Statu s.NEW); | |
299 | ||
300 | if ( newStatus != null) { | |
301 | idL = psReceived DAO.getPSR eceivedIDL istByStatu sID(newSta tus); | |
302 | } el se { | |
303 | ||
304 | logger .error("Un able to ob tain statu s mapping for: " + P rocessStat us.Status. NEW); | |
305 | } | |
306 | ||
307 | retu rn idL; | |
308 | } | |
309 | ||
310 | /* * | |
311 | * Publish t he NEW rec eived data to PROCES SED status . | |
312 | * | |
313 | * @return T he number of receive d rows tha t were upd ated. | |
314 | * / | |
315 | pu blic int p rocessPSRe ceivedList (final Lis t<Long> ps ReceivedL) { | |
316 | ||
317 | int updateCoun t = 0; | |
318 | ||
319 | Inte ger proces sedStatus = processS tatusDAO.g etStatusFr omEnum(Pro cessStatus .Status.PR OCESSED); | |
320 | ||
321 | if ( processedS tatus != n ull) { | |
322 | ||
323 | for (L ong id : p sReceivedL ) { | |
324 | updateCo unt += psR eceivedDAO .updateSta tusById(id , processe dStatus); | |
325 | } | |
326 | } el se { | |
327 | ||
328 | logger .error("Un able to ob tain statu s mapping for: " + P rocessStat us.Status. PROCESSED) ; | |
329 | } | |
330 | ||
331 | retu rn updateC ount; | |
332 | } | |
333 | ||
334 | /* * | |
335 | * Save an P SSite and update the database auto gener ated ID. | |
336 | * | |
337 | * @param si te | |
338 | * The site record. | |
339 | * @return T he updated site popu lated with the auto generated ID. | |
340 | * / | |
341 | pu blic void saveSite(P SSite site ) { | |
342 | ||
343 | psSi teDAO.save (site); | |
344 | } | |
345 | ||
346 | /* * | |
347 | * Save an P SPatient a nd update the databa se auto ge nerated ID . | |
348 | * | |
349 | * @param pa tient | |
350 | * The pati ent record . | |
351 | * @return T he updated patient p opulated w ith the au to generat ed ID. | |
352 | * / | |
353 | pu blic void savePatien t(PSPatien t patient) { | |
354 | ||
355 | psPa tientDAO.s ave(patien t); | |
356 | } | |
357 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.