Produced by Araxis Merge on 4/2/2019 1:06:56 PM 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 | C:\AraxisMergeCompare\Pri_un\ARS_Backend\ars_app\src\main\java\gov\va\med\ewv\service\impl | EwvPdfReferenceServiceImpl.java | Wed Mar 27 19:22:49 2019 UTC |
2 | C:\AraxisMergeCompare\Pri_re\ARS_Backend\ars_app\src\main\java\gov\va\med\ewv\service\impl | EwvPdfReferenceServiceImpl.java | Fri Mar 29 17:37:19 2019 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 10 | 728 |
Changed | 9 | 18 |
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.med.e wv.service .impl; | |
2 | ||
3 | import jav a.io.File; | |
4 | import jav a.math.Big Decimal; | |
5 | import jav a.nio.file .Files; | |
6 | import jav a.nio.file .Path; | |
7 | import jav a.nio.file .Paths; | |
8 | import jav a.util.Arr ayList; | |
9 | import jav a.util.Dat e; | |
10 | import jav a.util.Lis t; | |
11 | ||
12 | import org .apache.co mmons.lang .StringUti ls; | |
13 | import org .apache.lo gging.log4 j.LogManag er; | |
14 | import org .apache.lo gging.log4 j.Logger; | |
15 | import org .springfra mework.bea ns.factory .annotatio n.Autowire d; | |
16 | import org .springfra mework.cor e.env.Envi ronment; | |
17 | import org .springfra mework.htt p.HttpStat us; | |
18 | import org .springfra mework.ste reotype.Se rvice; | |
19 | import org .springfra mework.web .multipart .Multipart File; | |
20 | ||
21 | import gov .va.med.ar s.constant s.ErrorMes sages; | |
22 | import gov .va.med.ar s.dao.ewv. IEwvPdfRef erenceRepo sitory; | |
23 | import gov .va.med.ar s.exceptio ns.Generic Exception; | |
24 | import gov .va.med.do main.ewv.E wvReferenc es; | |
25 | import gov .va.med.ew v.bean.Arc hivedPdfRe ference; | |
26 | import gov .va.med.ew v.model.re sponse.Ewd PdfReferen cesFileArc hiveRespon se; | |
27 | import gov .va.med.ew v.model.re sponse.Ewd PdfReferen cesFileUpl oadRespons e; | |
28 | import gov .va.med.ew v.model.re sponse.Ewv PdfReferen cesRespons e; | |
29 | import gov .va.med.ew v.service. IEwvPdfRef erenceServ ice; | |
30 | import gov .va.med.ew v.util.Pdf Reference; | |
31 | ||
32 | /** | |
33 | * Impleme nts all th e methods needed to get, creat e, update, and delet e the PDF References | |
34 | * in the database. | |
35 | * | |
36 | * @author DN S PEREZF | |
37 | * | |
38 | */ | |
39 | @Service | |
40 | public cla ss EwvPdfR eferenceSe rviceImpl implements IEwvPdfRe ferenceSer vice { | |
41 | ||
42 | /* * | |
43 | * Contains informatio n about th e server e nvironment . It's use d in this Controller to get th e | |
44 | * Destinati on Directo ry where F ile conten ts will be saved. | |
45 | * / | |
46 | @A utowired | |
47 | En vironment env; | |
48 | ||
49 | /* * | |
50 | * JPA Repos itory sub- interface used to ge t, update, and add i nformation in the | |
51 | * EWV_REFER ENCES tabl e of the E WV databas e. | |
52 | * / | |
53 | /* @Autowired | |
54 | IE wvPdfRefer enceReposi tory ewvPd fReference Repository ;*/ | |
55 | ||
56 | @A utowired | |
57 | IE wvPdfRefer enceReposi tory ewvPd fReference Repository ; | |
58 | ||
59 | pr ivate stat ic final L ogger logg er = LogMa nager.getL ogger(EwvP dfReferenc eServiceIm pl.class); | |
60 | ||
61 | /* * | |
62 | * Gets all the PDF Re ferences t hat are in the datab ase. | |
63 | * | |
64 | * @return - the Web S ervice Res ponse for all the PD F Referenc es that ar e in the d atabase | |
65 | * @throws G enericExce ption - th rown if an y type of Exception occurs | |
66 | * / | |
67 | @O verride | |
68 | pu blic EwvPd fReference sResponse getAllPdfR eferences( ) throws G enericExce ption { | |
69 | EwvP dfReferenc esResponse pdfRefere ncesRespon se = new E wvPdfRefer encesRespo nse(); | |
70 | ||
71 | logg er.info("I nside of \ "getAllPdf References \" method" ); | |
72 | ||
73 | try { | |
74 | List < PdfReferen ce> pdfRef erencesLis t = getRea lAllPdfRef erences(); | |
75 | pdfRef erencesRes ponse.setP dfReferenc esList(pdf References List); | |
76 | } ca tch (Throw able e) { | |
77 | String errorDesc ription = "Getting o f all the PDF Refere nces faile d with exc eption : " + e; | |
78 | logg er.error(e rrorDescri ption); | |
79 | thro w new Gene ricExcepti on("ERROR" , errorDes cription, HttpStatus .BAD_REQUE ST); | |
80 | } | |
81 | ||
82 | logg er.info("R eturning t he EwvPdfR eferencesR esponse: " + pdfRefe rencesResp onse); | |
83 | retu rn pdfRefe rencesResp onse; | |
84 | } | |
85 | ||
86 | /* * | |
87 | * Inserts a PDF Refer ence into the databa se having the inform ation as i n the give n | |
88 | * "ewvRefer ences" inp ut paramet er. | |
89 | * | |
90 | * The metho d will do the follow ing: | |
91 | * 1) Check for valid inputs. Th e followin g constitu tes invali d inputs a nd an Exce ption will be thrown | |
92 | * for an y of the f ollowing i nvalid inp uts: | |
93 | * a) "ew vReference s" is null | |
94 | * b) Ref erence Nam e of "ewvR eferences" is null | |
95 | * c) Ref erence Nam e of "ewvR eferences" is an emp ty string or is comp osed of sp aces | |
96 | * d) Ref erence Fil e Name of "ewvRefere nces" is n ull | |
97 | * e) Ref erence Fil e Name of "ewvRefere nces" is a n empty st ring or is composed of spaces | |
98 | * f) An un-archive d PDF Refe rence exis ts in the database t hat has th e same Ref erence Nam e (Trimmed ) | |
99 | * val ue of "ewv References " | |
100 | * g) An un-archive d PDF Refe rence exis ts in the database t hat has th e same Ref erence Fil e Name (Tr immed) | |
101 | * val ue of "ewv References " input | |
102 | * 2) Sets t he "guid" value of " ewvReferen ces" to nu ll | |
103 | * 3) Sets t he "archiv e" value t o "false", since onl y un-archi ved PDF Re ferences w ill be per mitted to be | |
104 | * insert ed into th e database | |
105 | * 4) Trims the Refere nce Name a nd Referen ce File Na me values of the "ew vReference s" input | |
106 | * 5) Insert s a PDF Re ference in to the dat abase from the infor mation in the "ewvRe ference" i nput param eter | |
107 | * | |
108 | * @param ew vReference s - the in put parame ter that c ontains th e PDF Refe rences inf ormation t o be inser ted | |
109 | * into t he databas e | |
110 | * @param co mmitToData base - boo lean flag to indicat e if the i nsert shou ld be comm itted to t he databas e; | |
111 | * boo lean "true " means to commit to the datab ase; | |
112 | * boo lean "fals e" means t o NOT comm it to the database | |
113 | * | |
114 | * @return - a referen ce to the EwvRefernc es object inserted i nto the da tabase; it will have the infor mation tha t | |
115 | * was store d in the d atabase in cluding th e unique n on-null "g uid" value . | |
116 | * | |
117 | * @throws E xception - an Except ion is thr ows in one of the fo llowing sc enarios: | |
118 | * 1) The "e wvReferenc es" input parameter has invali d input va lue(s) | |
119 | * 2) Insert of PDF Re ference in to the dat abase was not succes sful | |
120 | * / | |
121 | pr ivate EwvR eferences insertPdfR eference(E wvReferenc es ewvRefe rences) th rows Excep tion { | |
122 | EwvR eferences insertedEw vReference s = null; | |
123 | ||
124 | if ( ewvReferen ces == nul l) { | |
125 | throw new Except ion("Null argument f ed into \" EwvPdfRefe renceServi ceImpl.ins ertPdfRefe rence\" me thod!"); | |
126 | } | |
127 | ||
128 | if ( ewvReferen ces.getRef erenceName () == null ) { | |
129 | throw new Except ion("Null Reference Name fed i nto \"EwvP dfReferenc eServiceIm pl.insertP dfReferenc e\" method !"); | |
130 | } | |
131 | ||
132 | if ( ewvReferen ces.getRef erenceName ().trim(). isEmpty()) { | |
133 | throw new Except ion("Refer ence Name fed into \ "EwvPdfRef erenceServ iceImpl.in sertPdfRef erence\" m ethod has only empty spaces or is an emp ty string! "); | |
134 | } | |
135 | ||
136 | if ( ewvReferen ces.getRef erenceFile Name() == null) { | |
137 | throw new Except ion("Null Reference File Name fed into \ "EwvPdfRef erenceServ iceImpl.in sertPdfRef erence\" m ethod!"); | |
138 | } | |
139 | ||
140 | if ( ewvReferen ces.getRef erenceFile Name().tri m().isEmpt y()) { | |
141 | throw new Except ion("Refer ence File Name fed i nto \"EwvP dfReferenc eServiceIm pl.insertP dfReferenc e\" method has only empty spac es or is a n empty st ring!"); | |
142 | } | |
143 | ||
144 | logg er.info("c alling ewv PdfReferen ceReposito ry.findByR eferenceNa meAndArchi ve()"); | |
145 | List <EwvRefere nces> ewvR eferencesL ist = ewvP dfReferenc eRepositor y.findByRe ferenceNam eAndArchiv e( | |
146 | ewvRef erences.ge tReference Name(), ew vReference s.getArchi ve()); | |
147 | if ( ewvReferen cesList != null && ! ewvReferen cesList.is Empty()) { | |
148 | throw new Except ion("Attem pt to inse rt already existing PDF Refere nce that h as the sam e Referenc e Name!"); | |
149 | } | |
150 | ||
151 | logg er.info("c alling ewv PdfReferen ceReposito ry.findByR eferenceFi leNameAndA rchive()") ; | |
152 | ewvR eferencesL ist = ewvP dfReferenc eRepositor y.findByRe ferenceFil eNameAndAr chive( | |
153 | ewvRefer ences.getR eferenceFi leName(), ewvReferen ces.getArc hive()); | |
154 | if ( ewvReferen cesList != null && ! ewvReferen cesList.is Empty()) { | |
155 | throw new Except ion("Attem pt to inse rt already existing PDF Refere nce that h as the sam e Referenc e File Nam e!"); | |
156 | } | |
157 | ||
158 | logg er.info("c alling ewv PdfReferen ceReposito ry.saveAnd Flush()"); | |
159 | inse rtedEwvRef erences = ewvPdfRefe renceRepos itory.save AndFlush(e wvReferenc es); | |
160 | if ( insertedEw vReference s == null) { | |
161 | throw new Except ion("Attem p to inser t the give n PDF Refe rence was not succes sful due t o NULL ref erence " + | |
162 | "returne d when att empting to do insert operation !"); | |
163 | } | |
164 | ||
165 | logg er.info("V alue for i nsertedEwv References : "+insert edEwvRefer ences.getR eferenceFi leName()); | |
166 | retu rn inserte dEwvRefere nces; | |
167 | } | |
168 | ||
169 | /* * | |
170 | * Gets all the PDF Re ferences t hat are in the datab ase. | |
171 | * | |
172 | * @return - List of P dfReferenc e objects | |
173 | * / | |
174 | pr ivate List <PdfRefer ence> getR ealAllPdfR eferences( ) { | |
175 | List <PdfRefer ence> pdfR eferencesL ist = new ArrayList< PdfReferen ce>(); | |
176 | ||
177 | logg er.info("A bout to ca ll \"ewvPd fReference Repository .findAll\" method"); | |
178 | List <EwvRefer ences> ewv References List = ewv PdfReferen ceReposito ry.findByA rchive("fa lse"); | |
179 | logg er.info("J ust finish ed calling \"ewvPdfR eferenceRe pository.f indAll\" m ethod"); | |
180 | for (int i = 0 ; i < ewvR eferencesL ist.size() ; i++) { | |
181 | PdfRef erence pdf Reference = new PdfR eference() ; | |
182 | pdfRef erence.set Guid(ewvRe ferencesLi st.get(i). getGuid(). toPlainStr ing()); | |
183 | pdfRef erence.set Alt(ewvRef erencesLis t.get(i).g etReferenc eName()); | |
184 | pdfRef erencesLis t.add(pdfR eference); | |
185 | } | |
186 | ||
187 | retu rn pdfRefe rencesList ; | |
188 | } | |
189 | ||
190 | /* * | |
191 | * Stub meth od used ON LY for tes t purposes that retu rns back | |
192 | * a list of hard-code d PDF Refe rences. | |
193 | * | |
194 | * @return - List of P dfReferenc e objects | |
195 | * / | |
196 | pr ivate List <PdfRefer ence> getS tubAllPdfR eferences( ) { | |
197 | List <PdfRefer ence> pdfR eferencesL ist = new ArrayList< PdfReferen ce>(); | |
198 | ||
199 | PdfR eference p dfReferenc e = new Pd fReference (); | |
200 | // pdfRefe rence.setH ref("https :// SERVER . DOMAIN/POR T /help/CARC .pdf"); | |
201 | pdfR eference.s etAlt("Cod eset: Clai m Adjustme nt Reason Codes"); | |
202 | pdfR eferencesL ist.add(pd fReference ); | |
203 | ||
204 | pdfR eference = new PdfRe ference(); | |
205 | // pdfRefe rence.setH ref("https :// SERVER . DOMAIN/POR T /help/RARC .pdf"); | |
206 | pdfR eference.s etAlt("Cod eset: Remi ttance Rem ark Codes" ); | |
207 | pdfR eferencesL ist.add(pd fReference ); | |
208 | ||
209 | pdfR eference = new PdfRe ference(); | |
210 | // pdfRefe rence.setH ref("https :// SERVER . DOMAIN/POR T /help/POA- Indicators .pdf"); | |
211 | pdfR eference.s etAlt("POA Indicator s"); | |
212 | pdfR eferencesL ist.add(pd fReference ); | |
213 | ||
214 | pdfR eference = new PdfRe ference(); | |
215 | // pdfRefe rence.setH ref("https :// SERVER . DOMAIN/POR T /help/OHI- Type-Cover age.pdf"); | |
216 | pdfR eference.s etAlt("OHI Type of C overage Gu ide"); | |
217 | pdfR eferencesL ist.add(pd fReference ); | |
218 | ||
219 | pdfR eference = new PdfRe ference(); | |
220 | // pdfRefe rence.setH ref("https :// SERVER . DOMAIN/POR T /help/GUI- POA-Indica tors-Inpat ient.pdf") ; | |
221 | pdfR eference.s etAlt("OHI Payment S equence In dicators") ; | |
222 | pdfR eferencesL ist.add(pd fReference ); | |
223 | ||
224 | pdfR eference = new PdfRe ference(); | |
225 | // pdfRefe rence.setH ref("https :// SERVER . DOMAIN/POR T /help/Medi care-Payer -IDs.pdf") ; | |
226 | pdfR eference.s etAlt("Med icare Cont ractor Pay er IDs"); | |
227 | pdfR eferencesL ist.add(pd fReference ); | |
228 | ||
229 | pdfR eference = new PdfRe ference(); | |
230 | // pdfRefe rence.setH ref("https :// SERVER . DOMAIN/POR T /help/X-Jo b-Code.pdf "); | |
231 | pdfR eference.s etAlt("X-C odes"); | |
232 | pdfR eferencesL ist.add(pd fReference ); | |
233 | ||
234 | pdfR eference = new PdfRe ference(); | |
235 | // pdfRefe rence.setH ref("https :// SERVER . DOMAIN/POR T /help/ASC- Job-Code-A id.pdf"); | |
236 | pdfR eference.s etAlt("ASC Rev Codes "); | |
237 | pdfR eferencesL ist.add(pd fReference ); | |
238 | ||
239 | retu rn pdfRefe rencesList ; | |
240 | } | |
241 | ||
242 | /** | |
243 | * Upl oads (i.e. , saves th e contents into the server fil e system) a list of "files" in to the ser ver file s ystem as | |
244 | * wel l as inser t PDF Refe rences of those file s into the database. | |
245 | * | |
246 | * @pa ram files - a list o f Multipar tFile obje cts; each such objec t contains the appro priate inf ormation f or one | |
247 | * file tha t will be used to sa ve its con tents into the serve r file sys tem as wel l as its P DF | |
248 | * Referenc e informat ion in the database | |
249 | * | |
250 | * @re turn - ins tance of E wdPdfRefer encesFileU ploadRespo nse Java c lass; it w ill show w hich Files | |
251 | * have had their cont ents store d successf ully into the server file syst em as well as their PDF Refere nce | |
252 | * informati on in the database a nd which h ave not. I n those in stances th at are uns uccessful, the reaso n | |
253 | * for not b eing succe ssful will be includ ed in the response | |
254 | */ | |
255 | @O verride | |
256 | public EwdPdfRef erencesFil eUploadRes ponse save UploadedFi les(List<M ultipartFi le> files) { | |
257 | ||
258 | St ring refer enceName = ""; | |
259 | // Make sure directory exists! | |
260 | Fi le uploadD ir = new F ile(env.ge tProperty( "destinati on_folder" )); | |
261 | up loadDir.mk dirs(); | |
262 | ||
263 | // StringBui lder sb = new String Builder(); | |
264 | Ew dPdfRefere ncesFileUp loadRespon se respons e = new Ew dPdfRefere ncesFileUp loadRespon se(); | |
265 | ||
266 | fo r (Multipa rtFile fil e : files) { | |
267 | EwvR eferences ewvReferen ces = new EwvReferen ces(); | |
268 | ||
269 | try { | |
270 | if ( file.isEmp ty()) { | |
271 | continue; | |
272 | } | |
273 | ||
274 | Stri ng uploadF ilePath = env.getPro perty("des tination_f older") + File.sepa rator + fi le.getOrig inalFilena me(); | |
275 | ||
276 | byte [] bytes = file.getB ytes(); | |
277 | Path path = Pa ths.get(up loadFilePa th); | |
278 | File s.write(pa th, bytes) ; | |
279 | // i nsert a re cord to th e database | |
280 | //ew vReference s.setGuid( null); | |
281 | ewvR eferences. setArchive ("false"); | |
282 | ewvR eferences. setReferen ceFileName (uploadFil ePath.trim ()); | |
283 | if(f ile.getOri ginalFilen ame().cont ains(".")) { | |
284 | refere nceName = file.getOr iginalFile name().sub string(0, file.getOr iginalFile name().las tIndexOf(' .')) ; | |
285 | } | |
286 | else { | |
287 | refere nceName = file.getOr iginalFile name(); | |
288 | } | |
289 | ||
290 | ewvR eferences. setReferen ceName(ref erenceName .trim()); | |
291 | ewvR eferences. setDateCre ated(new D ate()); | |
292 | EwvR eferences returnedEw vReference s = insert PdfReferen ce(ewvRefe rences); | |
293 | logg er.info("A dding the object to the respon se"+return edEwvRefer ences.getR eferenceFi leName()+" with refe renece nam e: "+retur nedEwvRefe rences.get ReferenceN ame()); | |
294 | resp onse.addSu ccessfulFi leUpload(f ile); | |
295 | resp onse.addEw vReference s(returned EwvReferen ces); | |
296 | ||
297 | } ca tch (Excep tion ex) { | |
298 | respon se.addUnSu ccessfulFi leUploadsL ist(file); | |
299 | respon se.addErro rMessage(e x.getMessa ge()); | |
300 | } | |
301 | ||
302 | } | |
303 | ||
304 | re turn respo nse; | |
305 | } | |
306 | ||
307 | ||
308 | /** | |
309 | * Mar ks one or more PDF R eferences to the Arc hived stat e. | |
310 | * | |
311 | * @pa ram archiv edPdfRefer ences - a list of Ar chivedPdfR eference o bjects; ea ch such ob ject conta ins the ap propriate | |
312 | * informat ion to ide ntify whic h PDF Refe rence in t he databas e will be marked as archived | |
313 | * | |
314 | * @re turn - Ewv ClaimDetai lResponse Java class instance; it will s how which PDF Refere nces have been place d | |
315 | * successfu lly in the Archived state and which have not. In t hose insta nces that are unsucc essful, th e | |
316 | * reason fo r not bein g successf ul will be included in the res ponse | |
317 | */ | |
318 | @O verride | |
319 | public EwdPdfRef erencesFil eArchiveRe sponse upd ateUploade dFiles(Lis t<Archived PdfReferen ce> archiv edPdfRefer ences) { | |
320 | ||
321 | Ew dPdfRefere ncesFileAr chiveRespo nse respon se = new E wdPdfRefer encesFileA rchiveResp onse(); | |
322 | ||
323 | fo r (Archive dPdfRefere nce archiv edPdfRefer ence : arc hivedPdfRe ferences) { | |
324 | ||
325 | try { | |
326 | EwvRef erences ew vReference = ewvPdfR eferenceRe pository.f indOne(new BigDecima l(archived PdfReferen ce.getGuid ())); | |
327 | ||
328 | if (ew vReference == null) { | |
329 | throw ne w Exceptio n("PDF Ref erence wit h GUID \"" + archive dPdfRefere nce.getGui d() + "\" does not e xist!"); | |
330 | } | |
331 | ewvRef erence.set Archive("t rue"); | |
332 | ewvRef erence.set ReferenceN ame(archiv edPdfRefer ence.getAl t()); | |
333 | ewvRef erence.set DateArchiv ed(new Dat e()); | |
334 | ewvRef erence = e wvPdfRefer enceReposi tory.saveA ndFlush(ew vReference ); | |
335 | ||
336 | respon se.addSucc essfulFile Archive(ar chivedPdfR eference); | |
337 | respon se.addEwvR eferences( ewvReferen ce); | |
338 | ||
339 | } ca tch (Excep tion ex) { | |
340 | respon se.addUnSu ccessfulFi leArchive( archivedPd fReference ); | |
341 | respon se.addErro rMessage(e x.getMessa ge()); | |
342 | } | |
343 | } | |
344 | ||
345 | re turn respo nse; | |
346 | } | |
347 | ||
348 | /* * | |
349 | * Gets the Reference File Name of an EWV_ REFERENCE record giv en it's GU ID Id. | |
350 | * | |
351 | * @param fi leId - the GUID that uniquely identifies a record in the EWV _REFERENCE S table | |
352 | * | |
353 | * @return - the Refer ence File Name assoc iated with the EWV_R EFERENCE t able recor d | |
354 | * | |
355 | * @throws G enericExce ption - th rown if so me error o ccurs | |
356 | * / | |
357 | @O verride | |
358 | pu blic Strin g getPathF orTheAttac hment(Stri ng fileId) throws Ge nericExcep tion { | |
359 | Stri ng filePat h = null; | |
360 | if(! StringUtil s.isEmpty( fileId)) { | |
361 | EwvRef erences ew vReference s = ewvPdf ReferenceR epository. findByGuid (new BigDe cimal(file Id)); | |
362 | if(ewv References != null) { | |
363 | filePath = ewvRefe rences.get ReferenceF ileName(); | |
364 | return f ilePath; | |
365 | } else { | |
366 | throw ne w GenericE xception(E rrorMessag es.NOT_FOU ND, "File not found for a give n uniqueId ", HttpSta tus.NOT_FO UND); | |
367 | } | |
368 | } el se { | |
369 | throw new Generi cException (ErrorMess ages.INVAL ID_REQUEST , "Unique Id should not be emp ty/null", HttpStatus .BAD_REQUE ST); | |
370 | } | |
371 | } | |
372 | ||
373 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.