Produced by Araxis Merge on 6/11/2019 10:54:09 AM Eastern 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 | HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\ccht\service\common\impl | AbstractBusinessService.java | Wed May 29 15:26:30 2019 UTC |
| 2 | HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\ccht\service\common\impl | AbstractBusinessService.java | Mon Jun 10 19:19:21 2019 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 506 |
| 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 | /** | |
| 2 | * | |
| 3 | */ | |
| 4 | package go v.va.med.c cht.servic e.common.i mpl; | |
| 5 | ||
| 6 | import jav a.awt.imag e.Buffered Image; | |
| 7 | import jav a.io.ByteA rrayOutput Stream; | |
| 8 | import jav a.io.IOExc eption; | |
| 9 | import jav a.util.Arr ayList; | |
| 10 | import jav a.util.Has hMap; | |
| 11 | import jav a.util.Lis t; | |
| 12 | import jav a.util.Map ; | |
| 13 | import jav a.util.Map .Entry; | |
| 14 | ||
| 15 | import jav ax.imageio .ImageIO; | |
| 16 | import jav ax.mail.in ternet.Mim eMessage; | |
| 17 | ||
| 18 | import org .apache.ve locity.app .VelocityE ngine; | |
| 19 | import org .apache.ve locity.exc eption.Vel ocityExcep tion; | |
| 20 | import org .slf4j.Log ger; | |
| 21 | import org .slf4j.Log gerFactory ; | |
| 22 | import org .springfra mework.bea ns.factory .annotatio n.Autowire d; | |
| 23 | import org .springfra mework.bea ns.factory .annotatio n.Qualifie r; | |
| 24 | import org .springfra mework.bea ns.factory .annotatio n.Value; | |
| 25 | import org .springfra mework.cor e.io.ByteA rrayResour ce; | |
| 26 | import org .springfra mework.mai l.SimpleMa ilMessage; | |
| 27 | import org .springfra mework.mai l.javamail .JavaMailS ender; | |
| 28 | import org .springfra mework.mai l.javamail .MimeMessa geHelper; | |
| 29 | import org .springfra mework.ste reotype.Se rvice; | |
| 30 | import org .springfra mework.ui. velocity.V elocityEng ineFactory ; | |
| 31 | import org .springfra mework.ui. velocity.V elocityEng ineUtils; | |
| 32 | ||
| 33 | import gov .va.med.cc ht.model.U ser; | |
| 34 | import gov .va.med.cc ht.service .common.Me rgeService ; | |
| 35 | import gov .va.med.cc ht.service .common.Te mplateLoad erService; | |
| 36 | import gov .va.med.cc ht.util.ES APIValidat ionType; | |
| 37 | import gov .va.med.cc ht.util.ES APIValidat or; | |
| 38 | import gov .va.med.fw .security. SecurityCo ntext; | |
| 39 | import gov .va.med.fw .security. SecurityCo ntextHelpe r; | |
| 40 | import gov .va.med.fw .security. UserPrinci pal; | |
| 41 | import gov .va.med.fw .service.A bstractCom ponent; | |
| 42 | import gov .va.med.fw .service.S erviceExce ption; | |
| 43 | import gov .va.med.fw .util.Stri ngUtils; | |
| 44 | ||
| 45 | /** | |
| 46 | * @author DNS | |
| 47 | * | |
| 48 | */ | |
| 49 | @Service | |
| 50 | public cla ss Abstrac tBusinessS ervice ext ends Abstr actCompone nt { | |
| 51 | pr ivate stat ic final L ogger log = LoggerFa ctory.getL ogger(Abst ractBusine ssService. class); | |
| 52 | ||
| 53 | pr ivate bool ean emailE nabled = t rue; | |
| 54 | ||
| 55 | pu blic stati c enum Pri ority { | |
| 56 | HIGH (1), NORMA L(3), LOW( 5); | |
| 57 | ||
| 58 | int priority = 3; | |
| 59 | ||
| 60 | priv ate Priori ty(int val ue) { | |
| 61 | this.p riority = value; | |
| 62 | } | |
| 63 | ||
| 64 | publ ic int get Priority() { | |
| 65 | return this.prio rity; | |
| 66 | } | |
| 67 | } | |
| 68 | ||
| 69 | pu blic stati c final St ring IMAGE _TYPE = "p ng"; | |
| 70 | ||
| 71 | /* * | |
| 72 | * send mail | |
| 73 | * | |
| 74 | * @param te mplate | |
| 75 | * / | |
| 76 | pu blic void send(Simpl eMailMessa ge templat e) { | |
| 77 | send (template, null); | |
| 78 | } | |
| 79 | ||
| 80 | pu blic final void send (SimpleMai lMessage t emplate, M ap<String, Object> a ttachments ) { | |
| 81 | this .send(temp late, atta chments, A bstractBus inessServi ce.Priorit y.NORMAL); | |
| 82 | } | |
| 83 | ||
| 84 | pu blic final void send (SimpleMai lMessage t emplate, M ap<String, Object> a ttachments , | |
| 85 | Abstra ctBusiness Service.Pr iority pri ority) { | |
| 86 | ||
| 87 | try { | |
| 88 | MimeMe ssage mess age = java MailSender .createMim eMessage() ; | |
| 89 | ||
| 90 | // use the false flag to i ndicate it is not a multi-part message | |
| 91 | boolea n multiPar t = (attac hments != null && at tachments. size() > 0 ) ? true : false; | |
| 92 | MimeMe ssageHelpe r helper = new MimeM essageHelp er(message , multiPar t); | |
| 93 | // Whe n multiple e-mail ad dress are specified by separat ing them | |
| 94 | // wit h , in the spring co nfiguratio n, they ar e not pars ed. | |
| 95 | List<S tring> toL ist = new ArrayList< String>(); | |
| 96 | for (S tring toAd dress : te mplate.get To()) { | |
| 97 | if (toAd dress.inde xOf(",") > 0) { | |
| 98 | String[] l ist = toAd dress.spli t(","); | |
| 99 | for (Strin g address : list) { | |
| 100 | to List.add(a ddress); | |
| 101 | } | |
| 102 | } else i f (toAddre ss.indexOf (";") > 0) { | |
| 103 | String[] l ist = toAd dress.spli t(";"); | |
| 104 | for (Strin g address : list) { | |
| 105 | to List.add(a ddress); | |
| 106 | } | |
| 107 | } else { | |
| 108 | toList.add (toAddress ); | |
| 109 | } | |
| 110 | } | |
| 111 | helper .setTo((St ring[]) to List.toArr ay(new Str ing[toList .size()])) ; | |
| 112 | helper .setFrom(t emplate.ge tFrom()); | |
| 113 | ||
| 114 | //Fix Fortify Is sues | |
| 115 | ESAPIV alidator.v alidateStr ingInput(t emplate.ge tSubject() , ESAPIVal idationTyp e.EmailSub ject_White list); | |
| 116 | ||
| 117 | helper .setSubjec t(template .getSubjec t()); | |
| 118 | // use the true flag to in dicate the text incl uded is HT ML | |
| 119 | helper .setText(t emplate.ge tText(), t rue); | |
| 120 | ||
| 121 | // Set priority | |
| 122 | helper .setPriori ty(priorit y.getPrior ity()); | |
| 123 | ||
| 124 | // att ach in lin e resource s | |
| 125 | if (mu ltiPart) { | |
| 126 | for (Ent ry<String, Object> e ntry : att achments.e ntrySet()) { | |
| 127 | String att achmentNam e = entry. getKey(); | |
| 128 | Object obj = entry.g etValue(); | |
| 129 | if (obj in stanceof B ufferedIma ge) { | |
| 130 | By teArrayOut putStream os = new B yteArrayOu tputStream (); | |
| 131 | Im ageIO.writ e((Buffere dImage) ob j, IMAGE_T YPE, os); | |
| 132 | he lper.addAt tachment(a ttachmentN ame, new B yteArrayRe source(os. toByteArra y())); | |
| 133 | } | |
| 134 | // add oth ers as nee ded (excel , pdf etc) | |
| 135 | if (obj in stanceof b yte[]) { | |
| 136 | he lper.addAt tachment(a ttachmentN ame, new B yteArrayRe source((by te[]) obj) ); | |
| 137 | } | |
| 138 | } | |
| 139 | } | |
| 140 | javaMa ilSender.s end(messag e); | |
| 141 | } ca tch (Excep tion e) { | |
| 142 | // ign ore mail d elivery er rors | |
| 143 | logger .error("Se nd Mail Fa iled", e); | |
| 144 | } | |
| 145 | } | |
| 146 | ||
| 147 | /* * | |
| 148 | * Process s ubject and body of m ail templa te | |
| 149 | * | |
| 150 | * @param da ta | |
| 151 | * @param me ssageTempl ate | |
| 152 | * @return | |
| 153 | * / | |
| 154 | pu blic final SimpleMai lMessage p rocessMail Template(M ap<String, Object> d ata, Simpl eMailMessa ge message Template) | |
| 155 | throws ServiceEx ception { | |
| 156 | Simp leMailMess age templa te = new S impleMailM essage(mes sageTempla te); | |
| 157 | // s ubject | |
| 158 | temp late.setSu bject(merg e(template .getSubjec t(), data) ); | |
| 159 | // b ody | |
| 160 | temp late.setTe xt(merge(t emplate.ge tText(), d ata)); | |
| 161 | retu rn templat e; | |
| 162 | } | |
| 163 | ||
| 164 | pu blic final String me rge(String template, Map<Strin g, Object> data) thr ows Servic eException { | |
| 165 | try { | |
| 166 | final TemplateLo aderServic e template Loader = n ew Templat eLoaderSer vice(); | |
| 167 | final VelocityEn gineFactor y fact = n ew Velocit yEngineFac tory(); | |
| 168 | final Map<String , Object> propMap = new HashMa p<String,O bject>(); | |
| 169 | propMa p.put("res ource.load er", "ds") ; | |
| 170 | propMa p.put("ds. resource.l oader.clas s", "gov.v a.med.ccht .service.c ommon.Temp lateLoader Service"); | |
| 171 | propMa p.put("ds. resource.l oader.inst ance", tem plateLoade r); | |
| 172 | fact.s etVelocity Properties Map(propMa p); | |
| 173 | ||
| 174 | return VelocityE ngineUtils .mergeTemp lateIntoSt ring(fact. createVelo cityEngine (), templa te, data); | |
| 175 | } ca tch (Veloc ityExcepti on ve) { | |
| 176 | throw new Servic eException ("Velocity Template merge fail ed", ve); | |
| 177 | } ca tch (IOExc eption e) { | |
| 178 | throw new Servic eException ("Velocity Template merge fail ed. " | |
| 179 | + "Creatio n of Veloc ity Engine failed.", e); | |
| 180 | } | |
| 181 | } | |
| 182 | ||
| 183 | pu blic List< String> ge tEmailList (List<User > users) { | |
| 184 | List <String> e mailList = new Array List<Strin g>(); | |
| 185 | for (User u : users) { | |
| 186 | if (u. isInactive () || Stri ngUtils.is Empty(u.ge tEmail())) { | |
| 187 | continue ; | |
| 188 | } else { | |
| 189 | emailLis t.add(u.ge tEmail()); | |
| 190 | } | |
| 191 | } | |
| 192 | retu rn emailLi st; | |
| 193 | } | |
| 194 | ||
| 195 | @A utowired | |
| 196 | @Q ualifier(" configurab leMailServ ice") | |
| 197 | pr ivate Java MailSender javaMailS ender = nu ll; | |
| 198 | @A utowired | |
| 199 | pr ivate Velo cityEngine velocityT emplateEng ine; | |
| 200 | @V alue("${cc ht.web.url }") | |
| 201 | pr ivate Stri ng webAppU rl; | |
| 202 | @A utowired | |
| 203 | pr ivate Merg eService m ergeServic e = null; | |
| 204 | ||
| 205 | pu blic JavaM ailSender getJavaMai lSender() { | |
| 206 | retu rn javaMai lSender; | |
| 207 | } | |
| 208 | ||
| 209 | pu blic void setJavaMai lSender(Ja vaMailSend er javaMai lSender) { | |
| 210 | this .javaMailS ender = ja vaMailSend er; | |
| 211 | } | |
| 212 | ||
| 213 | pu blic Veloc ityEngine getVelocit yTemplateE ngine() { | |
| 214 | retu rn velocit yTemplateE ngine; | |
| 215 | } | |
| 216 | ||
| 217 | pu blic void setVelocit yTemplateE ngine(Velo cityEngine velocityT emplateEng ine) { | |
| 218 | this .velocityT emplateEng ine = velo cityTempla teEngine; | |
| 219 | } | |
| 220 | ||
| 221 | pu blic Strin g getWebAp pUrl() { | |
| 222 | retu rn webAppU rl; | |
| 223 | } | |
| 224 | ||
| 225 | pu blic void setWebAppU rl(String webAppUrl) { | |
| 226 | this .webAppUrl = webAppU rl; | |
| 227 | } | |
| 228 | ||
| 229 | pu blic boole an isEmail Enabled() { | |
| 230 | retu rn emailEn abled; | |
| 231 | } | |
| 232 | ||
| 233 | pu blic void setEmailEn abled(bool ean emailE nabled) { | |
| 234 | this .emailEnab led = emai lEnabled; | |
| 235 | } | |
| 236 | ||
| 237 | pu blic Merge Service ge tMergeServ ice() { | |
| 238 | retu rn mergeSe rvice; | |
| 239 | } | |
| 240 | ||
| 241 | pu blic void setMergeSe rvice(Merg eService m ergeServic e) { | |
| 242 | this .mergeServ ice = merg eService; | |
| 243 | } | |
| 244 | ||
| 245 | pr otected Us er getCurr entUser() { | |
| 246 | Secu rityContex t sc = Sec urityConte xtHelper.g etSecurity Context(); | |
| 247 | User Principal p = sc.get UserPrinci pal(); | |
| 248 | if ( p == null) | |
| 249 | return null; | |
| 250 | if ( p instance of User) | |
| 251 | return (User) p; | |
| 252 | thro w new Ille galStateEx ception("U nsupported type of u ser in sec urity cont ext: " + p .getClass( )); | |
| 253 | } | |
| 254 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.