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