17. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 3/1/2018 12:13:14 PM 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.

17.1 Files compared

# Location File Last Modified
1 ehealth_xchange_cif.zip\NHIN_adapter\AdapterDataQualityServices\AdapterDataQualityServicesEJB\src\main\java\gov\va\med\nhin\adapter\dataquality\common Emailer.java Thu Feb 22 14:19:38 2018 UTC
2 ehealth_xchange_cif.zip\NHIN_adapter\AdapterDataQualityServices\AdapterDataQualityServicesEJB\src\main\java\gov\va\med\nhin\adapter\dataquality\common Emailer.java Tue Feb 27 14:23:34 2018 UTC

17.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 512
Changed 1 2
Inserted 0 0
Removed 0 0

17.3 Comparison options

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

17.4 Active regular expressions

No regular expressions were active.

17.5 Comparison detail

  1   /**
  2    * SMPT em ail client  to create  and send  email mess ages 
  3    * using t he email.p roperties  values loa ded in Ema ilBean. 
  4    * Copied  from VAP a nd modifie d. 
  5    * 
  6    */
  7   package go v.va.med.n hin.adapte r.dataqual ity.common ;
  8  
  9  
  10   import jav a.util.Dat e;
  11   import jav a.util.Ite rator;
  12   import jav a.util.Lis t;
  13   import jav a.util.Map ;
  14   import jav a.util.Pro perties;
  15   import jav ax.mail.Bo dyPart;
  16  
  17   import jav ax.mail.Me ssage;
  18   import jav ax.mail.Me ssagingExc eption;
  19   import jav ax.mail.Mu ltipart;
  20   import jav ax.mail.Pa sswordAuth entication ;
  21   import jav ax.mail.Se ssion;
  22   import jav ax.mail.Tr ansport;
  23   import jav ax.mail.in ternet.Int ernetAddre ss;
  24   import jav ax.mail.in ternet.Int ernetHeade rs;
  25   import jav ax.mail.in ternet.Mim eBodyPart;
  26   import jav ax.mail.in ternet.Mim eMultipart ;
  27   import jav ax.mail.in ternet.Mim eMessage;
  28  
  29   import org .slf4j.Log ger;
  30   import org .slf4j.Log gerFactory ;
  31  
  32  
  33   public cla ss Emailer  {
  34       
  35       privat e static f inal Logge r LOG = Lo ggerFactor y.getLogge r(Emailer. class.getN ame());
  36        
  37       
  38       privat e final st atic Strin g SMTP_AUT H = "mail. smtp.auth" ;
  39       privat e final st atic Strin g SMTP_STA RTTLS = "m ail.smtp.s tarttls.en able";
  40       privat e final st atic Strin g SMTP_HOS T = "mail. smtp.host" ;
  41       privat e final st atic Strin g SMTP_POR T = "mail. smtp.port" ;
  42  
  43       privat e final st atic Strin g SUBJECT  = "subject ";
  44       privat e final st atic Strin g BODY = " body";
  45       privat e final st atic Strin g REPORT_P ATTERN = " %report%";
  46       
  47  
  48       /**
  49        * @pa ram distri butionList  List of e mail addre sses and/o r contact  groups sep arated by  semicolon
  50        * @pa ram messag eAttribute s Map of m essage att ributes, k eyed by at tribute na me. Curren tly suppor ted keys a re:
  51        *                             "subject "
  52        *                             "body" 
  53        * @pa ram report  List of i tems in th e report.  If "body"  attribute  contains " %report%"  stub, gene rated tabu lar repres entation
  54        *                  of the r eport will  substitut e the stub ; otherwis e, it will  be append ed at the  end of the  "body" at tribute.
  55        * @re turn true,  if email  messages a re sent co rrectly;
  56        *           fals e, if at l east one s end operat ion fails
  57        */
  58       final  public boo lean email Report(Str ing distri butionList , Map<Stri ng, String > messageA ttributes,
  59                    List <Map<Strin g, Object> > report)  {
  60           bo olean retV alue = tru e;
  61           Em ailBean em ailBean =  EmailBean. getInstanc e();
  62           fi nal String  username  = emailBea n.getFrom( );
  63           fi nal String  password  = emailBea n.getPassw ord();
  64           fi nal String  reportLin k = emailB ean.getLin k();
  65  
  66           Pr operties p rops = new  Propertie s();
  67           pr ops.put(SM TP_AUTH, " true");
  68           pr ops.put(SM TP_STARTTL S, "true") ;
  69           pr ops.put(SM TP_HOST, e mailBean.g etHost());
  70           pr ops.put(SM TP_PORT, e mailBean.g etPort());
  71  
  72           Se ssion sess ion = Sess ion.getIns tance(prop s,
  73                new java x.mail.Aut henticator () {
  74                    @Ove rride
  75                    prot ected Pass wordAuthen tication g etPassword Authentica tion() {
  76                            return  new Passwo rdAuthenti cation(use rname, pas sword);
  77                    }
  78           }) ;
  79    
  80           tr y {
  81                MimeMess age messag e = new Mi meMessage( session);
  82                message. setFrom(ne w Internet Address(em ailBean.ge tFrom()));                                   
  83                addRecip ients(mess age, distr ibutionLis t);                                      
  84                message. setSubject (messageAt tributes.g et(SUBJECT ));                 
  85                MimeBody Part bodyT ext = new  MimeBodyPa rt();              
  86                Internet Headers he aders = ne w Internet Headers();
  87                headers. addHeader( "Content-t ype", "tex t/html; ch arset=UTF- 8");
  88                bodyText .setText(m essageAttr ibutes.get (BODY) + r eportLink) ;
  89                MimeMult ipart body  = new Mim eMultipart ();
  90                body.add BodyPart(b odyText);                                                    
  91                message. setContent (body);
  92                Transpor t.send(mes sage);
  93           }  catch (Mes sagingExce ption e) {
  94                LOG.erro r("emailRe port Messa gingExcept ion: ",e);
  95                //e.prin tStackTrac e(System.o ut);
  96                retValue  = false;
  97           }
  98           re turn retVa lue;
  99       }
  100       
  101       /**
  102        * Sen ds an noti fication e mail to ta rget email  addresses  separated  by semico lon in dis tributionL ist String
  103        * whe re message Attributes  Map conta ins "subje ct" and "b ody" keys.  Uses info rmation fr om email.p roperties 
  104        * alo ng with th e above in put parame ters.
  105        * 
  106        * Exa mple:
  107        *        String  bodyString  = "VAP Bu lk Data Up load Failu re!" 
  108        *        Map<Str ing, Strin g> message Attributes  = new Has hMap<Strin g, String> ();
  109        *        message Attributes .put("subj ect", "VAP  Data Bulk  Upload Fa ilure Noti ce");
  110        *        message Attributes .put("body ", bodyStr ing);
  111        *
  112        *        Emailer  emailer =  new Email er();
  113                 emailer.em ailNotific ation(" PII                   PII                   ",
  114        *        message Attributes );
  115        *
  116        * 
  117        * @pa ram distri butionList  List of e mail addre sses and/o r contact  groups sep arated by  semicolon
  118        * @pa ram messag eAttribute s Map of m essage att ributes, k eyed by at tribute na me. Curren tly suppor ted keys a re:
  119        *                             "subject "
  120        *                             "body"
  121        * @re turn true,  if email  messages a re sent co rrectly;
  122        *           fals e, if at l east one s end operat ion fails
  123        */
  124       final  public boo lean email Notificati on(String  distributi onList, Ma p<String,  String> me ssageAttri butes) {
  125           bo olean retV alue = tru e;
  126           // System.out .println(" in emailNo tification () ...");
  127           Em ailBean em ailBean =  EmailBean. getInstanc e();
  128           fi nal String  username  = emailBea n.getUsern ame();
  129           fi nal String  password  = emailBea n.getPassw ord();
  130           
  131           Se ssion sess ion = null ;
  132                    
  133           // try {
  134           //  attempt t o retrieve  session f rom JNDI:
  135           // InitialCon text ic =  new Initia lContext() ;
  136           // session =  (Session)  ic.lookup( "myMailSes sion");         
  137           // } catch(Na mingExcept ion e) {
  138                // TODO:  Log excep tion as WA RN?             
  139           // }
  140           
  141   //         if(null ==  session)  {
  142                // creat e a sessio n from the  EmailBean /email.pro perties fi le
  143                Properti es props =  new Prope rties();
  144                props.pu t(SMTP_AUT H, "true") ;
  145                props.pu t(SMTP_STA RTTLS, "tr ue");
  146                //props. put("mail. transport. protocol",  "smtp");
  147                props.pu t(SMTP_HOS T, emailBe an.getHost ());
  148                props.pu t(SMTP_POR T, emailBe an.getPort ());
  149                //props. put("mail. from", ema ilBean.get From());
  150                //TODO:  should thi s also be  an empty c heck?
  151                if(null  != usernam e && null  != passwor d) {
  152                    sess ion = Sess ion.getIns tance(prop s,
  153                    new  javax.mail .Authentic ator() {
  154                           @Overrid e
  155                           protecte d Password Authentica tion getPa sswordAuth entication () {
  156                                  r eturn new  PasswordAu thenticati on(usernam e, passwor d);
  157                           }
  158                    });
  159                } else {              
  160                    sess ion = Sess ion.getIns tance(prop s);             
  161                }
  162   //         }        
  163         
  164           tr y {             
  165                // creat e message
  166                Message  message =  new MimeMe ssage(sess ion);
  167                // set m essage pro perties
  168                message. setFrom(ne w Internet Address(em ailBean.ge tFrom()));                             
  169                addRecip ients(mess age, distr ibutionLis t); 
  170                message. setSentDat e(new Date ()); 
  171                message. setSubject (messageAt tributes.g et(SUBJECT ));                                   
  172                // set t he body
  173                BodyPart  bodyText  = new Mime BodyPart()
  174                bodyText .setText(m essageAttr ibutes.get (BODY));
  175                bodyText .addHeader ("Content- type", "te xt/plain;  charset=UT F-8");
  176                //bodyTe xt.addHead er("Conten t-type", " text/html;  charset=U TF-8");                           
  177                Multipar t body = n ew MimeMul tipart();
  178                body.add BodyPart(b odyText);                          
  179                message. setContent (body);             
  180                //System .out.print ln("about  to send th e message. ..");
  181                LOG.debu g(" about  to send th e message. ..");
  182                // send  the messag e             
  183                Transpor t.send(mes sage); 
  184                //System .out.print ln("... me ssage sent .");
  185                LOG.debu g("... mes sage sent. ");
  186           }  catch (Mes sagingExce ption e) {              
  187                LOG.erro r("emailNo tification  Messaging Exception:  ",e);
  188                //e.prin tStackTrac e(System.o ut);
  189                retValue  = false;
  190           }         
  191           re turn retVa lue;
  192       }
  193       
  194       /**
  195        * Sen ds an emai l containi ng the Dat a Quality  health doc ument dail y upload s ummary inf ormation 
  196        * to  the email. toList dis tribution  list in em ail.proper ties. The  only messa geAttribut es map 
  197        * val ue which n eeds to be  set progr ammaticall y is the " body" key/ value item
  198        * whi ch contain s the cont ents of th e email. T he subject  from the  properties  
  199        * fil e is used  instead.
  200        * 
  201        * Exa mple:
  202        *        String  bodyString  = "Diamet er Health  bulk data  upload dai ly summary  contents  here"; 
  203        *        Map<Str ing, Strin g> message Attributes  = new Has hMap<>();        
  204        *        message Attributes .put("body ", bodyStr ing);
  205        *
  206        *        Emailer  emailer =  new Email er();
  207        *        boolean  success =  emailer.e mailNotifi cationDQUp load(messa geAttribut es);
  208        * 
  209        * @pa ram messag eAttribute s Map of m essage att ributes, k eyed by at tribute na me. Curren tly suppor ted keys a re:
  210        *                             "body"
  211        * @re turn true,  if email  messages a re sent co rrectly;
  212        *           fals e, if at l east one s end operat ion fails
  213        */
  214       final  public boo lean email Notificati onDQUpload (Map<Strin g, String>  messageAt tributes)  {                 
  215           Em ailBean em ailBean =  EmailBean. getInstanc e();
  216           St ring distr ibutionLis t = emailB ean.getToL ist();
  217           St ring subje ct = email Bean.getSu bject();
  218           me ssageAttri butes.put( "subject",  subject);         
  219           //  call the  wrapped me thod 
  220           bo olean retV alue = thi s.emailNot ification( distributi onList, me ssageAttri butes);         
  221           re turn retVa lue;         
  222       }
  223  
  224       /**
  225        * @pa ram distri butionList  List of e mail addre sses and/o r contact  groups sep arated by  semicolon
  226        * @pa ram messag eAttribute s Map of m essage att ributes, k eyed by at tribute na me. Curren tly suppor ted keys a re:
  227        *                             "subject "
  228        *                             "body" 
  229        */
  230       privat e void add Recipients (Message m essage, St ring distr ibutionLis t)
  231                    thro ws Messagi ngExceptio n{      
  232           St ring[] lis t = distri butionList .split(";" );
  233           fo r (int i=0 ; i<list.l ength; i++ ){
  234                     mes sage.addRe cipient(Me ssage.Reci pientType. TO,
  235                          new Inter netAddress (list[i])) ;
  236           }
  237       }
  238  
  239       /**
  240        * @pa ram report List List  of items i n the repo rt. If "bo dy" attrib ute contai ns "%repor t%" stub,  generated  tabular re presentati on
  241        *                  of the r eport will  substitut e the stub ; otherwis e, it will  be append ed at the  end of the  "body" at tribute.
  242        * @re turn The r eport;
  243        */
  244       /*
  245       privat e String g etTabRepor t(List<Map <String, O bject>> re portList){
  246           It erator<Map <String, O bject>> it er = repor tList.iter ator();
  247                    Stri ngBuilder  report = n ew StringB uilder();
  248           wh ile(iter.h asNext()){
  249                             Map<St ring, Obje ct> map =  iter.next( );
  250                             for(Ma p.Entry<St ring, Obje ct> entry  : map.entr ySet()){
  251                                      report.a ppend(entr y.getValue ().toStrin g()).appen d("\n");
  252                             }
  253                    }
  254           re turn repor t.toString ();
  255       }
  256       */
  257   }