279. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 12/5/2017 12:06:45 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.

279.1 Files compared

# Location File Last Modified
1 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingDicomRouter\main\src\java\gov\va\med\imaging\core\router\commands ProcessEmailQueueCommandImpl.java Mon Dec 4 21:35:24 2017 UTC
2 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingDicomRouter\main\src\java\gov\va\med\imaging\core\router\commands ProcessEmailQueueCommandImpl.java Mon Dec 4 22:02:54 2017 UTC

279.2 Comparison summary

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

279.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

279.4 Active regular expressions

No regular expressions were active.

279.5 Comparison detail

  1   package go v.va.med.i maging.cor e.router.c ommands;
  2  
  3   import gov .va.med.Ro utingToken ;
  4   import gov .va.med.im aging.core .annotatio ns.routerf acade.Rout erCommandE xecution;
  5   import gov .va.med.im aging.core .interface s.exceptio ns.Connect ionExcepti on;
  6   import gov .va.med.im aging.core .interface s.exceptio ns.Invalid UserCreden tialsExcep tion;
  7   import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception;
  8   import gov .va.med.im aging.core .interface s.router.C ommand;
  9   import gov .va.med.im aging.core .router.Ab stractComm andImpl;
  10   import gov .va.med.im aging.core .router.fa cade.Inter nalContext ;
  11   import gov .va.med.im aging.exch ange.busin ess.Durabl eQueue;
  12   import gov .va.med.im aging.exch ange.busin ess.Durabl eQueueMess age;
  13   import gov .va.med.im aging.exch ange.busin ess.Queued EmailMessa ge;
  14   import gov .va.med.im aging.exch ange.busin ess.dicom. DicomServe rConfigura tion;
  15   import gov .va.med.im aging.noti fications. Notificati on;
  16   import gov .va.med.im aging.noti fications. Notificati onFacade;
  17   import gov .va.med.im aging.noti fications. Notificati onTypes;
  18   import gov .va.med.im aging.noti fications. email.Noti ficationEm ailConfigu ration;
  19   import gov .va.med.im aging.noti fications. email.Noti ficationEm ailProtoco l;
  20  
  21   import jav a.util.Arr ayList;
  22   import jav a.util.Cal endar;
  23   import jav a.util.Lis t;
  24  
  25   import jav ax.mail.in ternet.Add ressExcept ion;
  26   import jav ax.mail.in ternet.Int ernetAddre ss;
  27  
  28   import org .apache.lo gging.log4 j.LogManag er;
  29   import org .apache.lo gging.log4 j.Logger;
  30  
  31   import com .thoughtwo rks.xstrea m.XStream;
  32   import com .thoughtwo rks.xstrea m.XStreamE xception;
  33  
  34   /**
  35    * Checks  queued ema il message s stored i n VistA.   Finds like  email mes sages and  combined t hem into
  36    *  a sing le email m essage to  avoid gene rating too  much emai l traffic  for the re cipients.   Determine
  37    *  if an  email mess age is to  be sent im mediately  or sent la ter.  Erro r email me ssage are  sent immed iately.
  38    *  Warnin g messages  are sent  later.  Th ere is log ic to not  allow an e mail messa ge to sit  in the que ue for mor e
  39    *  than a  day.    
  40    * 
  41    * @author         
TITTOC and         
PETERB
  42    *
  43    */
  44   @RouterCom mandExecut ion(asynch ronous = t rue, distr ibutable =  false)
  45   public cla ss Process EmailQueue CommandImp l extends
  46                    Abst ractComman dImpl<Bool ean> {
  47  
  48           pr ivate stat ic final l ong serial VersionUID  = 4923784 727344L;
  49           pr ivate fina l static S tring EMAI L_QUEUE_NA ME = "E-Ma il Queue";
  50           pr ivate Logg er logger  = LogManag er
  51                             .getLo gger(Proce ssEmailQue ueCommandI mpl.class) ;
  52           pr ivate stat ic final D icomServer Configurat ion config  = getConf ig();
  53           pr ivate stat ic final N otificatio nEmailConf iguration  emailConfi g = getEma ilConfig() ;
  54  
  55       privat e DurableQ ueue email Queue;
  56  
  57           pu blic Proce ssEmailQue ueCommandI mpl() {
  58           }
  59  
  60           @O verride
  61           pu blic Boole an callSyn chronously InTransact ionContext ()
  62                             throws  MethodExc eption, Co nnectionEx ception {
  63                    logg er.info("C hecking "  + EMAIL_QU EUE_NAME +  " for E-m ail messag es to send ");
  64                    Proc essEmails( );
  65                    retu rn true;
  66           }
  67  
  68           @O verride
  69           pu blic boole an equals( Object obj ) {
  70                    retu rn false;
  71           }
  72  
  73           @O verride
  74           pu blic Comma nd<Boolean > getNewPe riodicInst ance() thr ows Method Exception  {
  75                    Proc essEmailQu eueCommand Impl comma nd = new P rocessEmai lQueueComm andImpl();
  76                    comm and.setPer iodic(true );
  77                    comm and.setPer iodicExecu tionDelay( this.getPe riodicExec utionDelay ());
  78                    retu rn command ;
  79           }
  80  
  81           pu blic List< Class<? ex tends Meth odExceptio n>> getFat alPeriodic ExceptionC lasses()
  82           {
  83                    List <Class<? e xtends Met hodExcepti on>> fatal Exceptions  = new Arr ayList<Cla ss<? exten ds MethodE xception>> ();
  84                    fata lException s.add(Inva lidUserCre dentialsEx ception.cl ass);
  85                    retu rn fatalEx ceptions;
  86           }
  87  
  88           /* *
  89            *  This meth od is call ed when a  periodic c ommand has  thrown a  fatal exce ption as d efined by  the list i n getFatal PeriodicEx ceptionCla sses(). At  the point  when this  method is  called
  90            *  the perio dic comman d has alre ady stoppe d executin g and will  not execu te again.   This meth od is mean t to allow  the comma nd to aler t someone  of the fai lure (such  as by sen ding 
  91            *  an email  message)
  92            *  @param t
  93            * /
  94           pu blic void  handleFata lPeriodicE xception(T hrowable t )
  95           {
  96                    Stri ng subject  = "Invali d HDIG ser vice accou nt credent ials";
  97                    Stri ng message  = "The Pr ocessEmail Queue peri odic comma nd has shu t down due  to invali d HDIG ser vice accou nt credent ials.";
  98                    Noti ficationFa cade.sendN otificatio n(Notifica tionTypes. InvalidSer viceAccoun tCredentia ls, subjec t, message );
  99           }
  100  
  101           /* *
  102            *  @return
  103            * /
  104           pr otected st atic Dicom ServerConf iguration  getConfig( ) {
  105                    retu rn DicomSe rverConfig uration.ge tConfigura tion();
  106           }
  107  
  108           pr otected st atic Notif icationEma ilConfigur ation getE mailConfig (){
  109                    retu rn Notific ationEmail Configurat ion.getCon figuration ();
  110           }
  111  
  112           @O verride
  113           pr otected St ring param eterToStri ng() {
  114                    retu rn "";
  115           }
  116  
  117           pr otected vo id Process Emails() t hrows Meth odExceptio n, Connect ionExcepti on
  118       {
  119            / /
  120            / / Get the  next queue d Email  m essage
  121            / /
  122            R outingToke n routingT oken = con fig.getRou tingToken( );
  123            D urableQueu e queue =  getEmailQu eue();
  124            S tring msgG roupID = c onfig.getH ostName();  // localh ost
  125            
  126            Q ueuedEmail Message qu euedEmail  = null;
  127            D urableQueu eMessage m essage = n ull;
  128            A rrayList<Q ueuedEmail Message> e mailMessag es = new A rrayList<Q ueuedEmail Message>() ;
  129            b oolean mor eMessages  = true;
  130            / / collect  messages u p to a MB
  131            w hile (more Messages){
  132                    //ge t the next  message f rom Durabl e Queue.
  133                    mess age = getQ ueueMessag e(routingT oken, queu e, msgGrou pID);
  134                    
  135                    if ( message !=  null){ //  new messa ge
  136                         //get the  message fr om the dur able queue  message a nd de-seri alize it i nto a
  137                         //  email  message ob ject.
  138                         try{
  139                                      queuedEm ail = dese rializeUsi ngXStream( message.ge tMessage() );
  140                                 
  141                                 // determine  if this em ail messag e matches  another em ail messag e already  in the lis t.
  142                                 //   Use the  Subject Li ne for mat ching.  Th is is beca use nothin g else mak es much se nse.
  143                                 in t emailInd ex = email Messages.i ndexOf(que uedEmail);  
  144                                 if (emailInde x < 0){
  145                                      //if the re is no m atch, add  this new e mail messa ge to the  list.
  146                                      emailMes sages.add( queuedEmai l);                  
  147                                 }
  148                                 el se{
  149                                      QueuedEm ailMessage  m = (Queu edEmailMes sage)email Messages.g et(emailIn dex);
  150                                      //if the re is a ma tch, add s ubject lin e and body  to existi ng email b ody.
  151                                      //       increment  message co unt.
  152                                      StringBu ffer buf =  new Strin gBuffer(m. getMessage Body());
  153                                      StringBu ffer addSt ring = new  StringBuf fer("\r\n- ---------- ---------- ---------- ---------- ---\r\n"+ 
  154                                                       "S ubject: "+ queuedEmai l.getSubje ctLine()+" \r\nMessag e:\r\n"+qu euedEmail. getMessage Body());
  155                                      buf.appe nd(addStri ng);
  156                                      m.setMes sageBody(b uf.toStrin g());
  157                                      m.setMes sageCount( m.getMessa geCount()  + queuedEm ail.getMes sageCount( ));
  158                                      m.setBod yByteSize( m.getBodyB yteSize()  + queuedEm ail.getBod yByteSize( ));
  159                                 }
  160                         }
  161                         catch(XStr eamExcepti on xsX){
  162                             logger .error(thi s.getClass ().getName ()+": Bad  Durable Qu eue Messag e. Will sk ip message  "
  163                                               +message.g etId());
  164                                      logger.e rror(xsX.g etMessage( ), xsX);
  165                         }
  166                    }
  167                    else {
  168                             logger .info("No  more entri es in " +  EMAIL_QUEU E_NAME + "  for " + m sgGroupID  + ".  Back  to sleep. ");
  169                             moreMe ssages = f alse;
  170                    }
  171           }
  172                    tran sverseQueu edEmailMes sageCollec tion(routi ngToken, q ueue, msgG roupID, em ailMessage s);
  173       }
  174  
  175  
  176           /* *
  177            *  Re-queue  email mess age back i nto VISA q ueue mecha nism.
  178            *  
  179            *  @param ro utingToken
  180            *  @param qu eue repres ents the D urableQueu e for emai ls.
  181            *  @param ms gGroupID r epresents  the hostna me of the  HDIG.
  182            *  @param qu euedEmail  represents  the email  message.
  183            *  @return
  184            *  @throws C onnectionE xception
  185            *  @throws M ethodExcep tion
  186            * /
  187           pr otected Bo olean requ eue(Routin gToken rou tingToken,  DurableQu eue queue,  String ms gGroupID,  QueuedEmai lMessage q ueuedEmail , Boolean  doCount) 
  188       throws  Connectio nException , MethodEx ception
  189       {
  190                    if(q ueuedEmail .getRetryC ount() < q ueue.getNu mRetries() ){
  191                             if (do Count) {
  192                                      queuedEm ail.increm entRetryCo unt();
  193                             }
  194                    Stri ng seriali zedEmail =  serialize UsingXStre am(queuedE mail);
  195                             Durabl eQueueMess age messag e = new Du rableQueue Message(qu eue, msgGr oupID, ser ializedEma il);
  196                             try {
  197                                      setQueue Message(ro utingToken , message) ;
  198                                      logger.d ebug(this. getClass() .getName() +": Email  job requeu ed with su bject, \n" +queuedEma il.getSubj ectLine()) ;
  199                             }
  200                             catch( Exception  X) {
  201                                      logger.e rror(this. getClass() .getName() +": Failed  to requeu e Email wi th subject , \n"
  202                                                       +  queuedEmai l.getSubje ctLine() + ". \nNo Em ail will b e sent.");
  203                             }
  204                             return  true;
  205                    }
  206                    else {
  207                             //fals e, log mes sage and t hrow away  the messag e.
  208                             logger .error(thi s.getClass ().getName ()+": Fail ed to send  Email aft er maximum  number of  retries w ith subjec t, \n" + q ueuedEmail .getSubjec tLine() + 
  209                                               " \nNo Ema il will be  sent.");
  210                             return  false;
  211                    }                 
  212       }
  213       
  214           /* *
  215            *  Send emai l message.
  216            *  
  217            *  @param em ailMessage
  218            * /
  219           pr otected vo id sendMai l(QueuedEm ailMessage  emailMess age)
  220           {
  221                Notifica tionEmailP rotocol nE mailProtoc ol= new No tification EmailProto col();
  222                List<Int ernetAddre ss> eMailT Os=new Arr ayList<Int ernetAddre ss>();
  223                ArrayLis t<String>  emailRecip ients = em ailMessage .getRecipi ents();
  224                    for  (String to s: emailRe cipients)
  225                             try{
  226                                      eMailTOs .add(new I nternetAdd ress(tos)) ;
  227                             } 
  228                             catch  (AddressEx ception ae
  229                             {
  230                                      logger.w arn(this.g etClass(). getName()+ ": Bad ema il address , "+tos);
  231                             }
  232                    Noti fication e MailMsg =  Notificati on.getGene ricNotific ation(emai lMessage.g etSubjectL ine(), ema ilMessage. getMessage Body());
  233                    nEma ilProtocol .sendTo(eM ailTOs, eM ailMsg);
  234           }
  235  
  236           /* *
  237            *  Get Durab leQueue co ntaining e mail messa ges.  This  was creat ed primari ly for uni t testing.
  238            *  
  239            *  @return
  240            *  @throws C onnectionE xception
  241            *  @throws M ethodExcep tion
  242            * /
  243           pr otected Du rableQueue  getEmailQ ueue() thr ows Connec tionExcept ion, Metho dException
  244           {
  245                    if ( emailQueue  == null){
  246                             emailQ ueue = Int ernalConte xt.getRout er().getDu rableQueue ByName(con fig.getRou tingToken( ), EMAIL_Q UEUE_NAME) ;
  247                    }
  248                    retu rn emailQu eue;
  249           }
  250  
  251           /* *
  252            *  Get the n ext email  message in  the queue .  This wa s created  primarily  for unit t esting.
  253            *  
  254            *  @param ro utingToken
  255            *  @param qu eue repres ents the D urableQueu e for emai ls.
  256            *  @param ms gGroupID r epresents  the hostna me of the  HDIG.
  257            *  @return
  258            *  @throws M ethodExcep tion
  259            *  @throws C onnectionE xception
  260            * /
  261           pr otected Du rableQueue Message ge tQueueMess age(Routin gToken rou tingToken,
  262                             Durabl eQueue que ue, String  msgGroupI D) throws  MethodExce ption,
  263                             Connec tionExcept ion {
  264                    retu rn Interna lContext.g etRouter() .dequeueDu rableQueue Message(ro utingToken , queue.ge tId(), msg GroupID);
  265           }
  266           
  267           pr otected Qu euedEmailM essage des erializeUs ingXStream (String se rializedXm l)throws X StreamExce ption{
  268                    XStr eam xstrea m = new XS tream();
  269                    retu rn (Queued EmailMessa ge)xstream .fromXML(s erializedX ml);
  270           }
  271  
  272           pr otected St ring seria lizeUsingX Stream(Que uedEmailMe ssage emai lMessage){
  273                    XStr eam xstrea m = new XS tream();
  274                    retu rn xstream .toXML(ema ilMessage) ;
  275           }
  276  
  277           /* *
  278            *  Re-queue  an email m essage in  the queue.   This was  created p rimarily f or unit te sting.
  279            *  
  280            *  @param ro utingToken
  281            *  @param me ssage repr esents the  email mes sage.
  282            *  @throws M ethodExcep tion
  283            *  @throws C onnectionE xception
  284            * /
  285           pr ivate void  setQueueM essage(Rou tingToken  routingTok en,
  286                             Durabl eQueueMess age messag e) throws  MethodExce ption,
  287                             Connec tionExcept ion {
  288                    Inte rnalContex t.getRoute r().enqueu eDurableQu eueMessage (routingTo ken, messa ge);
  289           }
  290  
  291           /* *
  292            *  A collect ion of ema il message s was buil t from the  queue.  T his method  now deter mines what  should ha ppen
  293            *       to t he email m essages.   Email mess ages could  be sent o ut immedia tely or it  could be  place back  into
  294            *   the queu e for late r transmis sion.  Bas ically, er ror messag es are sen t out imme diately an d warning
  295            *   warning  message ar e re-queue d for late r.
  296            *   
  297            *  @param ro utingToken
  298            *  @param qu eue repres ents the D urableQueu e for emai ls.
  299            *  @param ms gGroupID r epresents  the hostna me of the  HDIG.
  300            *  @param em ailMessage s represen ts the col lection of  email mes sages.
  301            *  @throws C onnectionE xception
  302            *  @throws M ethodExcep tion
  303            * /
  304       privat e void tra nsverseQue uedEmailMe ssageColle ction(Rout ingToken r outingToke n, Durable Queue queu e, String  msgGroupID ,
  305                                                       Ar rayList<Qu euedEmailM essage> em ailMessage s)throws C onnectionE xception,  MethodExce ption {
  306                    int  maxMessage sPerEmail  = emailCon fig.getMax imumMessag eCountPerE mail();
  307                    int  maxBytesPe rEmail = e mailConfig .getMaximu mByteSizeP erEmail();
  308           fo r(QueuedEm ailMessage  queuedEma il : email Messages){
  309                    if(( (queuedEma il.getSubj ectLine(). contains(" DUP/")) ||  (queuedEm ail.getSub jectLine() .contains( "IOD Viola tion")))){  
  310                             Calend ar now = C alendar.ge tInstance( );
  311                             int no wDay = now .get(Calen dar.DAY_OF _YEAR);
  312                             int po stDay = qu euedEmail. getDateTim ePosted(). get(Calend ar.DAY_OF_ YEAR);
  313                             if((qu euedEmail. getMessage Count() >=  maxMessag esPerEmail
  314                                               || (queued Email.getB odyByteSiz e() >= max BytesPerEm ail) 
  315                                               || (postDa y < nowDay )){
  316                                      sendQueu edEmailMes sage(routi ngToken, q ueue, msgG roupID, qu euedEmail) ;
  317                             }
  318                             else{
  319                                      requeue( routingTok en, queue,  msgGroupI D, queuedE mail, fals e); // do  not count  retry -- t his is a N OOP
  320                             }
  321                    }
  322                    else {
  323                         sendQueued EmailMessa ge(routing Token, que ue, msgGro upID, queu edEmail);
  324                    }
  325                    }
  326           }
  327  
  328           /* *
  329            *  Prepares  email mess age to be  sent out.
  330            *  
  331            *  @param ro utingToken
  332            *  @param qu eue repres ents the D urableQueu e for emai ls.
  333            *  @param ms gGroupID r epresents  the hostna me of the  HDIG.
  334            *  @param qu euedEmail  represents  an email  message.
  335            *  @throws C onnectionE xception
  336            *  @throws M ethodExcep tion
  337            * /
  338           pr ivate void  sendQueue dEmailMess age(Routin gToken rou tingToken,
  339                             Durabl eQueue que ue, String  msgGroupI D,
  340                             Queued EmailMessa ge queuedE mail) thro ws Connect ionExcepti on,
  341                             Method Exception  {
  342                    try  {
  343                             int ms gCount = q ueuedEmail .getMessag eCount();
  344                         if (msgCou nt > 1){ / / place co unter on e nd
  345                                      String t emp = queu edEmail.ge tSubjectLi ne(); 
  346                                      temp = t emp.concat ("(Qty: "  + String.v alueOf(msg Count) + " )");
  347                                      queuedEm ail.setSub jectLine(t emp);
  348                             }
  349                         sendMail(q ueuedEmail );
  350                    }
  351                    catc h (Excepti on X){
  352                             logger .error(X.g etMessage( ), X);
  353                             requeu e(routingT oken, queu e, msgGrou pID, queue dEmail, tr ue); // do  count ret ries
  354                    }
  355           }
  356   }