187. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 7/9/2017 11:01:33 PM 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.

187.1 Files compared

# Location File Last Modified
1 PPS_N_3.0_Iter2_Build_360.zip\Unredacted\PS_PPS_srv\src\main\java\gov\va\med\pharmacy\peps\service\common\capability\impl NdfUpdateCapabilityImpl.java Fri Jun 30 19:12:26 2017 UTC
2 PPS_N_3.0_Iter2_Build_360.zip\Unredacted\PS_PPS_srv\src\main\java\gov\va\med\pharmacy\peps\service\common\capability\impl NdfUpdateCapabilityImpl.java Sun Jul 2 20:39:54 2017 UTC

187.2 Comparison summary

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

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

187.4 Active regular expressions

No regular expressions were active.

187.5 Comparison detail

  1   /*
  2    * 
  3    */
  4   package go v.va.med.p harmacy.pe ps.service .common.ca pability.i mpl;
  5  
  6   import gov .va.med.ph armacy.pep s.common.e mail.Email ;
  7   import gov .va.med.ph armacy.pep s.common.e mail.Email Service;
  8   import gov .va.med.ph armacy.pep s.common.e xception.V alidationE xception;
  9   import gov .va.med.ph armacy.pep s.common.e xception.V alueObject Validation Exception;
  10   import gov .va.med.ph armacy.pep s.common.e xception.W rappedIOEx ception;
  11   import gov .va.med.ph armacy.pep s.common.u tility.sec urity.Untr ustedLogPa ram;
  12   import gov .va.med.ph armacy.pep s.common.v o.FieldKey ;
  13   import gov .va.med.ph armacy.pep s.common.v o.NdfUpdat eFileVo;
  14   import gov .va.med.ph armacy.pep s.common.v o.Paginate dList;
  15   import gov .va.med.ph armacy.pep s.common.v o.StatusVo ;
  16   import gov .va.med.ph armacy.pep s.common.v o.UpdateSe archCriter ia;
  17   import gov .va.med.ph armacy.pep s.common.v o.UserVo;
  18   import gov .va.med.ph armacy.pep s.common.v o.validato r.ErrorKey ;
  19   import gov .va.med.ph armacy.pep s.common.v o.validato r.Errors;
  20   import gov .va.med.ph armacy.pep s.domain.c ommon.capa bility.Ndf UpdateFile MgtDomainC apability;
  21   import gov .va.med.ph armacy.pep s.domain.c ommon.capa bility.Ndf UpdateFile StatusDoma inCapabili ty;
  22   import gov .va.med.ph armacy.pep s.service. common.cap ability.Nd fUpdateCap ability;
  23   import gov .va.med.ph armacy.pep s.service. common.cap ability.Nd fUpdatePro cessCapabi lity;
  24   import gov .va.med.ph armacy.pep s.service. common.uti lity.NdfUp dateProces sFile;
  25  
  26   import jav a.io.IOExc eption;
  27   import jav a.util.Cal endar;
  28   import jav a.util.Gre gorianCale ndar;
  29   import jav a.util.Lis t;
  30   import jav a.util.Opt ional;
  31  
  32   import jav ax.annotat ion.Resour ce;
  33  
  34   import org .apache.co mmons.lang 3.StringUt ils;
  35   import org .apache.lo gging.log4 j.LogManag er;
  36   import org .apache.lo gging.log4 j.Logger;
  37   import org .springfra mework.con text.annot ation.Conf iguration;
  38   import org .springfra mework.con text.annot ation.Prop ertySource ;
  39   import org .springfra mework.cor e.env.Envi ronment;
  40   import org .springfra mework.tra nsaction.P latformTra nsactionMa nager;
  41   import org .springfra mework.tra nsaction.T ransaction Status;
  42   import org .springfra mework.tra nsaction.s upport.Tra nsactionCa llback;
  43   import org .springfra mework.tra nsaction.s upport.Tra nsactionCa llbackWith outResult;
  44   import org .springfra mework.tra nsaction.s upport.Tra nsactionTe mplate;
  45  
  46   /**
  47    * Contain s the main  logic to  create the  NDF Updat e File and  send emai l notifica tions. Thi s class is  not compl etely
  48    * thread- safe but s ee the {@l ink NdfUpd ateCapabil ity} class  documenta tion for w hat is thr ead-safe.
  49    */
  50   @Configura tion
  51   @PropertyS ource("cla sspath:gov .va.med.ph armacy.pep s.emailser vice.prope rties")
  52   public cla ss NdfUpda teCapabili tyImpl imp lements Nd fUpdateCap ability {
  53     
  54     private  static fin al String  THREAD_NAM E = "On-de mand Updat e File Thr ead";
  55  
  56     /**
  57      * The p roperty na me of the  email addr ess list t o send fil e rejected  emails to .
  58      */
  59     static f inal Strin g FILE_REJ ECTED_TO_E MAIL_PROPE RTY = "upd ate_file_r ejected_to _email";
  60  
  61     /**
  62      * The p roperty na me of the  email addr ess list t o send fil e approved  emails to .
  63      */
  64     static f inal Strin g FILE_APP ROVED_TO_E MAIL_PROPE RTY = "upd ate_file_a pproved_to _email";
  65  
  66     /**
  67      * The p roperty na me of the  email addr ess list t o send fil e ready fo r testing  emails to.
  68      */
  69     static f inal Strin g FILE_REA DY_FOR_TES TING_TO_EM AIL_PROPER TY = "upda te_file_on _test_site _to_email" ;
  70  
  71       /** Th e Logger.  */
  72       privat e static f inal Logge r LOG = Lo gManager
  73                .getLogg er(NdfUpda teCapabili tyImpl.cla ss);
  74       
  75       /** Th e NdfUpdat eProcessCa pability.  */
  76       privat e NdfUpdat eProcessCa pability n dfUpdatePr ocessCapab ility;
  77       
  78       /** Th e NdfUpdat eFileMgtDo mainCapabi lity. */
  79       privat e NdfUpdat eFileMgtDo mainCapabi lity ndfUp dateFileMg tDomainCap ability;
  80       
  81       /** Th e NdfUpdat eFileStatu sDomainCap ability. * /
  82       privat e NdfUpdat eFileStatu sDomainCap ability nd fUpdateFil eStatusDom ainCapabil ity;
  83       
  84       /** Th e NdfUpdat eProcessFi le. */
  85       privat e NdfUpdat eProcessFi le ndfUpda teProcessF ile;
  86  
  87       /** Th e transact ion manage r. */
  88       privat e Platform Transactio nManager t ransaction Manager;
  89  
  90       /** Th e email se rvice. */
  91       privat e EmailSer vice email Service;
  92  
  93       /** Th e environm ent. */
  94       privat e Environm ent enviro nment;
  95       
  96     // This  method is  synchroniz ed because  this proc ess should  only be e xecuted by  one threa d at a tim e. This cl ass
  97     // shoul d also be  a singleto n.
  98     @Overrid e
  99     public s ynchronize d NdfUpdat eFileVo cr eateOnDema ndFileAsyn c(UserVo u ser) throw s Validati onExceptio n {
  100  
  101       final  Optional<N dfUpdateFi leVo> opti onalFileTo Generate =  getFileRe cordForGen eration(us er);
  102       // If  a file was  already i n process,  throw the  exception  per the m ethod cont ract.
  103       if (!o ptionalFil eToGenerat e.isPresen t()) {
  104         thro w new Vali dationExce ption(Vali dationExce ption.NON_ FINAL_STAT E_FILE_IN_ PROCESS);
  105       }
  106       
  107       final  NdfUpdateF ileVo file ToGenerate  = optiona lFileToGen erate.get( );
  108  
  109       // It  would be b etter to u se a pre-e xisting th read for p erformance  here, but  we don't  have a com mon
  110       // Exe cutorServi ce availab le and per formance i s not a ma jor concer n for this  operation .
  111       new Th read(new R unnable()  {
  112         @Ove rride
  113         publ ic void ru n() {
  114           tr y {
  115              LOG.info(" Executing  on-demand  file gener ation.");
  116              // generat eAndTransm itFile() i s also syn chronized  so this ne w thread w ill not ex ecute it u ntil the
  117              // kicking -off metho d returns.
  118              generateAn dTransmitF ile(fileTo Generate,  user);
  119           }  catch (fin al IOExcep tion e) {
  120              handleExce ptionDurin gCreateAnd SendToTest Process(us er, fileTo Generate,  e);
  121              cleanupFro mException DuringCrea teAndSendT oTestProce ss(fileToG enerate);
  122             
  123              // Don't r e-throw an  exception  because w e're on a  separate t hread. We  have alrea dy updated  the file  metadata
  124              // to repo rt the err or.
  125           }
  126         }
  127       }, THR EAD_NAME). start();
  128  
  129       return  fileToGen erate;
  130     }
  131  
  132       @Overr ide
  133       // Thi s method i s synchron ized becau se this pr ocess shou ld only be  executed  by one thr ead at a t ime. This  class
  134       // sho uld also b e a single ton.
  135       public  synchroni zed void c reateSched uledFile(U serVo user ) throws I OException  {
  136  
  137         // G et the fil e record i n a separa te transac tion becau se we want  to commit  it before  we start  the transa ction for
  138         // g enerateAnd TransmitFi le().
  139         fina l Transact ionTemplat e txTempla te = new T ransaction Template(t ransaction Manager);
  140         txTe mplate.set Propagatio nBehavior( Transactio nTemplate. PROPAGATIO N_REQUIRES _NEW);
  141         fina l Optional <NdfUpdate FileVo> op tionalNewF ile = txTe mplate.exe cute(
  142              new Transa ctionCallb ack<Option al<NdfUpda teFileVo>> () {
  143                @Overrid e
  144                public O ptional<Nd fUpdateFil eVo> doInT ransaction (Transacti onStatus s tatus) {
  145                  return  getFileRe cordForGen eration(us er);
  146                }
  147              });
  148  
  149         if ( optionalNe wFile.isPr esent()) {
  150           fi nal NdfUpd ateFileVo  newFileVo  = optional NewFile.ge t(); // Ne ver return s null.
  151  
  152           tr y {
  153              // This me thod execu tes in its  own trans action.
  154              generateAn dTransmitF ile(newFil eVo, user) ;
  155           }  catch (Exc eption e)  {
  156              handleExce ptionDurin gCreateAnd SendToTest Process(us er, newFil eVo, e);
  157              cleanupFro mException DuringCrea teAndSendT oTestProce ss(newFile Vo);
  158  
  159              // Still t hrow the e xception p er the met hod contra ct.
  160              throw e;
  161           }
  162  
  163         }
  164       }
  165  
  166       /**
  167        * Ret urns the { @link NdfU pdateFileV o} to use  for genera ting a new  update fi le. Create s one or r esets an e xisting
  168        * one  as approp riate.
  169        * 
  170        * @re turn an "e mpty" opti onal if no  appropria te record  could be r eturned an d the file  should no t be gener ated now.
  171        * Oth erwise, a  "present"  optional c ontaining  the record  to use. N ever null.
  172        */
  173       privat e synchron ized Optio nal<NdfUpd ateFileVo>  getFileRe cordForGen eration(Us erVo user)  {
  174         fina l NdfUpdat eFileVo la testFileVo  = retriev eCurrentSt atus();
  175         if ( latestFile Vo == null ) {
  176           //  very firs t time cre ating a fi le
  177           re turn Optio nal.of(cre ateInitiat edFile(use r));
  178  
  179         } el se if (Sta tusVo.NON_ FINAL_STAT E_STATUSES .contains( latestFile Vo.getStat us().getSt atusId()))  {
  180           LO G.info("Ca nnot creat e new file , as the p revious fi le is not  in a final  state.");
  181           re turn Optio nal.empty( );
  182  
  183         } el se if (Sta tusVo.PPSN _ERROR ==  latestFile Vo.getStat us().getSt atusId())  {
  184           //  reuse the  NdfUpdate FileVo
  185           la testFileVo .setCommen ts(null);
  186           la testFileVo .setDirect oryPath(nu ll);
  187           la testFileVo .setFileNa me(null);
  188           la testFileVo .getStatus ().setStat usId(Statu sVo.INITIA TED);
  189           //  Go ahead  and update  the recor d in the d atabase to  prevent a nyone from  trying to  kick off  another pr ocess.
  190           up dateNdfUpd ateFile(la testFileVo , user);
  191           re turn Optio nal.of(lat estFileVo) ;
  192  
  193         } el se {
  194           re turn Optio nal.of(cre ateInitiat edFile(use r));
  195         }
  196       }
  197  
  198       /**
  199        * Gen erates an  update fil e, transmi ts it to t he test fo lder, and  updates it s metadata  in the da tabase, al l in its
  200        * own  transacti on.
  201        * 
  202        * @pa ram newFil eVo the as sociated { @link NdfU pdateFileV o}. Must b e in {@lin k StatusVo #INITIATED } status.
  203        * @pa ram user t he user ge nerating t he file
  204        * @th rows IOExc eption if  there is a n error ge nerating o r transfer ring the u pdate file .
  205        */
  206       // Thi s method i s mainly p rotected j ust to all ow automat ed testing , but theo retically  a subclass  could use  it.
  207       protec ted synchr onized voi d generate AndTransmi tFile(NdfU pdateFileV o newFileV o, UserVo  user) thro ws IOExcep tion {
  208         
  209         // P reconditio n check.
  210         if ( StatusVo.I NITIATED ! = newFileV o.getStatu s().getSta tusId()) {
  211           th row new Il legalArgum entExcepti on("The gi ven update  file is n ot ready t o generate .");
  212         }
  213  
  214         // U se Transac tionTempla te because  @Transact ional does  not work  when calli ng methods  on 'this' .
  215         fina l Transact ionTemplat e txTempla te = new T ransaction Template(t ransaction Manager);
  216         txTe mplate.set Propagatio nBehavior( Transactio nTemplate. PROPAGATIO N_REQUIRES _NEW);
  217         try  {
  218           tx Template.e xecute(new  Transacti onCallback WithoutRes ult() {
  219              @Override
  220              protected  void doInT ransaction WithoutRes ult(Transa ctionStatu s status)  {
  221                try {
  222                  create AndAttachP hysicalFil e(user, ne wFileVo);
  223           
  224                  ndfUpd ateProcess Capability .addDataTo File(newFi leVo, ndfU pdateProce ssFile);
  225             
  226                  transm itUpdateFi leToTest(n ewFileVo,  user);
  227                } catch  (IOExcepti on ex) {
  228                  throw  new Wrappe dIOExcepti on(ex);
  229                }
  230  
  231                updateNd fUpdateFil e(newFileV o, user);
  232         
  233                LOG.info ("Generate d and tran smitted up date file  {}.", newF ileVo.getF ileName()) ;
  234              }
  235           }) ;
  236         } ca tch (final  WrappedIO Exception  ex) {
  237           LO G.debug("C aught Wrap pedIOExcep tion. Tran slating ba ck to a no rmal IOExc eption.",  ex);
  238           th row new IO Exception( "Failed to  generate  update fil e.", ex.ge tWrappedEx ception()) ;
  239         }
  240       }
  241  
  242       /**
  243        * Cre ate the lo cal physic al file an d attach i t to speci fied NdfUp dateFileVo .
  244        * @pa ram user U ser
  245        * @pa ram newFil eVo NdfUpd ateFileVo  to associa te to the  new physic al file
  246        * @th rows IOExc eption Thr own if err ors encoun tered duri ng physica l file cre ation
  247        */ 
  248       privat e void cre ateAndAtta chPhysical File(UserV o user, Nd fUpdateFil eVo newFil eVo) throw s IOExcept ion {
  249  
  250           nd fUpdatePro cessFile.c reateFile( newFileVo. getFileId( ));
  251      
  252           ne wFileVo.se tFileName( ndfUpdateP rocessFile .getFileNa me());
  253           ne wFileVo.se tDirectory Path(ndfUp dateProces sFile.getP ath().toSt ring());
  254           ne wFileVo.se tStatus(ne w StatusVo (StatusVo. CREATED));
  255           up dateNdfUpd ateFile(ne wFileVo, u ser);
  256       }
  257  
  258       /**
  259        * Han dles an ex ception du ring the f ile creati on process .
  260        * @pa ram user U ser who in voked the  file creat ion
  261        * @pa ram newFil eVo the Nd fUpdateFil eVo being  processed.  Must not  be null.
  262        * @pa ram e the  exception  encountere d
  263        */
  264       privat e void han dleExcepti onDuringCr eateAndSen dToTestPro cess(UserV o user, Nd fUpdateFil eVo newFil eVo, Excep tion e) {
  265           tr y{
  266                LOG.erro r(
  267                    "Exc eption in  NdfUpdateC apabilityI mpl.proces s() - " +  new Untrus tedLogPara m(e.getMes sage()), e );
  268                newFileV o.setStatu s(new Stat usVo(Statu sVo.PPSN_E RROR));
  269                newFileV o.setComme nts("PPS-N /NDF Updat e Test Fil e Creation  Failed. L og a CA ti cket");
  270                updateNd fUpdateFil eInSeparat eTxn(newFi leVo, user );
  271           }
  272           ca tch (Excep tion e1){
  273                LOG.erro r("Seconda ry excepti on encount ered durin g cleanup  after a pr imary exce ption.", e 1);
  274           }
  275       }
  276       
  277       /**
  278        * Cre ates an Nd fUpdateFil eVo with i nitiated s tatus. 
  279        * @pa ram user U ser initia ting the f ile
  280        * @re turn NdfUp dateFileVo  with init iated stat us
  281        */
  282       privat e NdfUpdat eFileVo cr eateInitia tedFile(Us erVo user)  {
  283           Nd fUpdateFil eVo initia tedFile =  new NdfUpd ateFileVo( );
  284           in itiatedFil e.setStatu s(new Stat usVo(Statu sVo.INITIA TED));
  285           in itiatedFil e.setFileN ame("");
  286           Nd fUpdateFil eVo update File = ins ertNdfUpda teFile(ini tiatedFile , user);
  287           re turn updat eFile;
  288       }
  289  
  290     @Overrid e
  291     public s ynchronize d void app rove(NdfUp dateFileVo  toUpdate,  UserVo us er) throws  Validatio nException  {
  292       try {
  293         tran smitUpdate FileToProd (toUpdate,  user);
  294       } catc h (Excepti on e) {
  295         LOG. error("Err or while t ransmittin g file to  production .", e);
  296         thro w new Vali dationExce ption(Vali dationExce ption.FILE _APPROVAL_ FAILED);
  297       }
  298     }
  299       
  300       @Overr ide
  301       public  synchroni zed void r eject(NdfU pdateFileV o toUpdate , UserVo u ser)
  302                throws V alidationE xception {
  303           
  304         if ( StringUtil s.isBlank( toUpdate.g etComments ())) {
  305           Er rors error s = new Er rors();
  306           er rors.addEr ror(FieldK ey.UPDATE_ FILE, Erro rKey.FILE_ REJECTION_ COMMENTS_R EQUIRED);
  307           th row new Va lueObjectV alidationE xception(e rrors);
  308         }
  309  
  310         try  {
  311           tr ansmitUpda teFileToRe ject(toUpd ate, user) ;
  312         } ca tch (Excep tion e) {
  313           LO G.error("E rror while  transmitt ing file t o reject." , e);
  314           th row new Va lidationEx ception(Va lidationEx ception.FI LE_REJECTI ON_FAILED) ;
  315         }
  316       }        
  317       
  318       /**
  319        * Tra nsmit upda te file to  productio n - Moves  the file t o the prod uction fol der, sends  an email  notificati on, and st ores 
  320        * the  NdfUpdate FileVo wit h an updat ed status.   
  321        *
  322        * @pa ram update File the u pdate file
  323        * @pa ram user t he user
  324        * @th rows IOExc eption if  the file c ould not b e moved
  325        */
  326       privat e void tra nsmitUpdat eFileToPro d(NdfUpdat eFileVo up dateFile,  UserVo use r) throws  IOExceptio n {
  327         LOG. info("Prep aring to t ransmit "  + updateFi le.getFile Name() + "  file to P rod.");
  328  
  329         if ( ndfUpdateP rocessFile .getFileNa me() == nu ll) {
  330           nd fUpdatePro cessFile.s etFileName (updateFil e.getFileN ame());
  331         }
  332  
  333         ndfU pdateProce ssFile.tra nsmitFileT oProd();
  334  
  335         Cale ndar gc =  GregorianC alendar.ge tInstance( );
  336         upda teFile.set ProdTransm issionDtm( gc.getTime ());
  337         upda teFile.set Status(new  StatusVo( StatusVo.T RANSMITTED _TO_PRODUC TION));
  338  
  339         try  {
  340           se ndEmailNot ification( updateFile .getStatus (), update File.getFi leName(),
  341                ndfUpdat eProcessFi le.getProd uctionFile Size());
  342         } ca tch (final  Exception  ex) {
  343           //  The file  was sent,  but the em ail failed . We don't  want to f ail the wh ole proces s for this .
  344           up dateFile.s etComments (
  345                "PPS-N/N DF Update  Production  File Tran smission S uccessful,  but subse quent erro rs encount ered sendi ng "
  346                    + "e mail. Log  a CA ticke t.");
  347           LO G.error("F ile was se nt, but su bsequent e rror occur red sendin g email.",  ex);
  348         }
  349  
  350         upda teNdfUpdat eFile(upda teFile, us er);
  351       }
  352       
  353       /**
  354        * Tra nsmit upda te file to  test - Mo ves the fi le to the  test folde r and send s an email  notificat ion. If th e transmit
  355        * is  successful , this met hod will u pdate the  status of  the passed  {@link Nd fUpdateFil eVo} but w ill not pe rsist the
  356        * upd ate to the  database.
  357        *
  358        * @pa ram update File the u pdate file
  359        * @pa ram user t he user
  360        * @th rows IOExc eption if  file trans mission fa iled
  361        */     
  362       protec ted void t ransmitUpd ateFileToT est(NdfUpd ateFileVo  updateFile , UserVo u ser) throw s IOExcept ion {
  363           LO G.info("Pr eparing to  transmit  " + update File.getFi leName() +  " file to  Test.");
  364  
  365           tr y {
  366                if(ndfUp dateProces sFile.getF ileName()  == null){
  367                    ndfU pdateProce ssFile.set FileName(u pdateFile. getFileNam e());
  368                }
  369  
  370                ndfUpdat eProcessFi le.transmi tFileToTes t();
  371                Calendar  gc = Greg orianCalen dar.getIns tance();
  372                updateFi le.setTest Transmissi onDtm(gc.g etTime());
  373                updateFi le.setStat us(new Sta tusVo(Stat usVo.READY _FOR_TESTI NG));
  374                try {
  375                    send EmailNotif ication(up dateFile.g etStatus() , updateFi le.getFile Name(), 
  376                             ndfUpd ateProcess File.getPe ndingFileS ize());
  377                }
  378                catch (E xception e ) {
  379                    //th e file was  sent, but  the email  or status  updates f ailed.
  380                    LOG. error("Fil e was sent , but subs equent err or occurre d sending  email.", e );
  381                    upda teFile.set Comments(
  382                             "PPS-N /NDF Updat e Test Fil e Transmis sion Succe ssful, but  subsequen t errors e ncountered  sending e mail. "
  383                                      + "Log a  CA ticket .");                 
  384                }
  385           } 
  386           ca tch (final  IOExcepti on e) {
  387              // Don't u pdate the  file statu s or anyth ing, just  re-wrap in  a new IOE xception w ith an err or message  at the
  388              // appropr iate level  of detail . We'll re ly on the  calling me thod to up date the f ile status .
  389              throw new  IOExceptio n("Failed  to transmi t file to  test folde r.", e);
  390           } 
  391       }    
  392       
  393       /**
  394        * Tra nsmit upda te file to  reject -  Renames an d moves th e file to  the reject  folder, s ends an em ail notifi cation, 
  395        * and  stores th e NdfUpdat eFileVo wi th an upda ted status .  
  396        *
  397        * @pa ram update File the u pdate file
  398        * @pa ram user t he user
  399        * @th rows IOExc eption if  the file c ould not b e moved
  400        */
  401       privat e void tra nsmitUpdat eFileToRej ect(NdfUpd ateFileVo  updateFile , UserVo u ser) throw s IOExcept ion {
  402           LO G.info("Pr eparing to  rename an d transmit  " + updat eFile.getF ileName()  + " file t o the Reje cted folde r.");
  403  
  404           if (ndfUpdate ProcessFil e.getFileN ame() == n ull){
  405                ndfUpdat eProcessFi le.setFile Name(updat eFile.getF ileName()) ;
  406           }
  407           
  408           nd fUpdatePro cessFile.t ransmitFil eToReject( );
  409           
  410           nd fUpdatePro cessCapabi lity.remov eAllFileAs sociations (Long.valu eOf(update File.getFi leId()));
  411           
  412           // If the cal ler specif ied VISTA_ ERROR, sto re VISTA_E RROR, othe rwise, set  the statu s to REJEC TED_BY_QA 
  413           if  (updateFi le.getStat us().getSt atusId() ! = StatusVo .VISTA_ERR OR)
  414           {
  415                updateFi le.setStat us(new Sta tusVo(Stat usVo.REJEC TED_BY_QA) );
  416           }
  417           
  418           //  we rename  the file  name in th e database  also
  419           up dateFile.s etFileName (ndfUpdate ProcessFil e.getRejec tedFileNam e());
  420           
  421           tr y {
  422              sendEmailN otificatio n(updateFi le.getStat us(), upda teFile.get FileName()
  423                      nd fUpdatePro cessFile.g etRejected FileSize() );
  424           }  catch (fin al Excepti on ex) {
  425              // The fil e was sent , but the  email fail ed. We don 't want to  fail the  whole proc ess for th is.
  426              updateFile .setCommen ts(
  427                  "PPS-N /NDF Updat e Reject F ile Rename /Move Succ essful, bu t subseque nt errors  encountere d sending  email. "
  428                      +  "Log a CA  ticket.");
  429              LOG.error( "File was  sent, but  subsequent  error occ urred send ing email. ", ex);
  430           }
  431  
  432           up dateNdfUpd ateFile(up dateFile,  user);       
  433       }        
  434       
  435       /**
  436        * Upd ate the gi ven NdfUpd ateFileVo  in the dat abase.
  437        * 
  438        * @pa ram update dFile
  439        *             Ma nagedItemV o to updat e
  440        * @pa ram user
  441        *             Us erVo updat ing item
  442        */
  443       protec ted void u pdateNdfUp dateFile(N dfUpdateFi leVo updat edFile, Us erVo user)  {
  444           LO G.debug("U pdating ND FUpdateFil e Info.");
  445           Ca lendar gc  = Gregoria nCalendar. getInstanc e();
  446  
  447           up datedFile. setModifie dDate(gc.g etTime());
  448           up datedFile. setStatusM odifiedDtm (gc.getTim e());
  449           up datedFile. setModifie dBy(user.g etUsername ());
  450  
  451           nd fUpdateFil eMgtDomain Capability .update(up datedFile,  user);
  452       }
  453  
  454       /**
  455        * Upd ate the gi ven NdfUpd ateFileVo  in the dat abase, in  a separate  transacti on.  Usefu l for upda ting statu s and comm ents 
  456        * dur ing error  scenarios.
  457        * 
  458        * @pa ram update dFile
  459        *             Ma nagedItemV o to updat e
  460        * @pa ram user
  461        *             Us erVo updat ing item
  462        */   
  463       protec ted void u pdateNdfUp dateFileIn SeparateTx n(final Nd fUpdateFil eVo update dFile, fin al UserVo  user)
  464       {
  465         // U se Transac tionTempla te because  @Transact ional does  not work  when calli ng methods  on 'this' .
  466         fina l Transact ionTemplat e txTempla te = new T ransaction Template(t ransaction Manager);
  467         txTe mplate.set Propagatio nBehavior( Transactio nTemplate. PROPAGATIO N_REQUIRES _NEW);
  468         txTe mplate.exe cute(new T ransaction CallbackWi thoutResul t() {
  469  
  470           @O verride
  471           pr otected vo id doInTra nsactionWi thoutResul t(final Tr ansactionS tatus txSt atus) {
  472              updateNdfU pdateFile( updatedFil e, user);        
  473           }
  474         });
  475       }
  476  
  477       /**
  478        * Ins ert the gi ven NdfUpd ateFileVo  in the dat abase.
  479        *
  480        * @pa ram insert File the i nsert file
  481        * @pa ram user              UserVo upd ating item
  482        * @re turn the n df update  file vo
  483        */
  484       privat e NdfUpdat eFileVo in sertNdfUpd ateFile(Nd fUpdateFil eVo insert File, User Vo user) {
  485           Nd fUpdateFil eVo insert edFile = n ull;
  486           Ca lendar gc  = Gregoria nCalendar. getInstanc e();
  487  
  488           in sertFile.s etModified By(user.ge tUsername( ));
  489           in sertFile.s etModified Date(gc.ge tTime());
  490           in sertFile.s etStatusMo difiedDtm( gc.getTime ());
  491  
  492           in sertedFile  = ndfUpda teFileMgtD omainCapab ility.inse rt(insertF ile,
  493                    user );
  494           re turn inser tedFile;
  495       }
  496  
  497       /**
  498        * Ret rieve all  NdfUpdateF ileVo.
  499        * @re turn List< FileUpdate Vo> update Files
  500        */
  501       @Overr ide
  502       public  List<NdfU pdateFileV o> retriev eFileUpdat es() {
  503           re turn ndfUp dateFileMg tDomainCap ability.re trieveAll( );
  504       }
  505  
  506       /**
  507        * Ret rieve page d NdfUpdat eFileVo.
  508        *
  509        * @pa ram search Criteria
  510        *             th e search c riteria
  511        * @re turn List< FileUpdate Vo> update Files
  512        */
  513       @Overr ide
  514       public  Paginated List<NdfUp dateFileVo > retrieve PagedFileU pdates(
  515                UpdateSe archCriter ia searchC riteria) {
  516           re turn ndfUp dateFileMg tDomainCap ability.re trievePage d(searchCr iteria);
  517       }
  518  
  519       /**
  520        * Ret rieve all  the status  values (E PL_STATUS) .
  521        * @re turn List< StatusVo>  all update  file stat uses
  522        */
  523       @Overr ide
  524       public  List<Stat usVo> retr ieveAllFil eStatuses( ) {
  525           re turn ndfUp dateFileSt atusDomain Capability .retrieveA ll();
  526       }
  527  
  528       /**
  529        * Ret rieve NdfU pdateFileV o ready fo r approval /rejection .
  530        * @re turn List< NdfUpdateF ileVo> pen dingUpdate Files
  531        */
  532       @Overr ide
  533       public  List<NdfU pdateFileV o> retriev ePendingUp date() {
  534           re turn ndfUp dateFileMg tDomainCap ability.re trievePend ing();
  535       }
  536  
  537       @Overr ide
  538       public  NdfUpdate FileVo ret rieveById( Long id) {
  539           re turn ndfUp dateFileMg tDomainCap ability.re trieveById (id);
  540       }
  541  
  542       @Overr ide
  543       public  NdfUpdate FileVo ret rieveCurre ntStatus()  {
  544           re turn ndfUp dateFileMg tDomainCap ability.re trieveCurr entStatus( );
  545       }
  546  
  547       /**
  548        * Ret rieve a li st of File UpdateVo w ith initia ted status .  Realist ically, th ere should  only ever  be one.
  549        *
  550        * @re turn List< FileUpdate Vo> initia tedUpdateF iles
  551        */
  552       @Overr ide
  553       public  List<NdfU pdateFileV o> retriev eInitiated Update() {
  554           re turn ndfUp dateFileMg tDomainCap ability.re trieveInit iated();
  555       }
  556  
  557       /**
  558        * get s the Tran sactionMan ager for N dfUpdateCa pabilityIm pl.
  559        * 
  560        * @re turn the t ransaction Manager
  561        */
  562       public  PlatformT ransaction Manager ge tTransacti onManager( ) {
  563           re turn trans actionMana ger;
  564       }
  565  
  566       /**
  567        * set s the Tran sactionMan ager for N dfUpdateCa pabilityIm pl.
  568        * 
  569        * @pa ram transa ctionManag er
  570        *             th e transact ionManager  to set
  571        */
  572       @Resou rce
  573       public  void setT ransaction Manager(
  574                Platform Transactio nManager t ransaction Manager) {
  575           th is.transac tionManage r = transa ctionManag er;
  576       }
  577  
  578       /**
  579        * set NdfUpdateP rocessCapa bility in  NdfUpdateP rocessCapa bilityImpl .
  580        *
  581        * @pa ram ndfUpd ateProcess Capability  the new N dfUpdatePr ocessCapab ility
  582        */
  583       public  void setN dfUpdatePr ocessCapab ility(NdfU pdateProce ssCapabili ty ndfUpda teProcessC apability)  {
  584           th is.ndfUpda teProcessC apability  = ndfUpdat eProcessCa pability;
  585       }
  586  
  587       /**
  588        * Get s the NdfU pdateFileM gtDomainCa pability.
  589        *
  590        * @re turn the N dfUpdateFi leMgtDomai nCapabilit y
  591        */
  592       public  NdfUpdate FileMgtDom ainCapabil ity getNdf UpdateFile MgtDomainC apability( ) {
  593           re turn ndfUp dateFileMg tDomainCap ability;
  594       }
  595  
  596       /**
  597        * Set s the NdfU pdateFileM gtDomainCa pability.
  598        *
  599        * @pa ram ndfUpd ateFileMgt DomainCapa bility the  new NdfUp dateFileMg tDomainCap ability
  600        */
  601       public  void setN dfUpdateFi leMgtDomai nCapabilit y(
  602                NdfUpdat eFileMgtDo mainCapabi lity ndfUp dateFileMg tDomainCap ability) {
  603           th is.ndfUpda teFileMgtD omainCapab ility = nd fUpdateFil eMgtDomain Capability ;
  604       }
  605  
  606       /**
  607        * Get  the refer ence to th e NdfUpdat eProcessFi le, which  represents  a physica l file and  its actio ns.
  608        *
  609        * @re turn the N dfUpdatePr ocessFile
  610        */
  611       public  NdfUpdate ProcessFil e getNdfUp dateProces sFile() {
  612           re turn ndfUp dateProces sFile;
  613       }
  614  
  615       /**
  616        * Set  the refer ence to th e NdfUpdat eProcessFi le, which  represents  a physica l file and  its actio ns.
  617        *
  618        * @pa ram ndfUpd ateProcess File the n ew NdfUpda teProcessF ile
  619        */
  620       public  void setN dfUpdatePr ocessFile( NdfUpdateP rocessFile  ndfUpdate ProcessFil e) {
  621           th is.ndfUpda teProcessF ile = ndfU pdateProce ssFile;
  622       }
  623  
  624       /**
  625        * Get s the emai l service.
  626        *
  627        * @re turn the e mailServic e
  628        */
  629       public  EmailServ ice getEma ilService( ) {
  630           re turn email Service;
  631       }
  632  
  633       /**
  634        * Set s the emai l service.
  635        *
  636        * @pa ram emailS ervice the  emailServ ice to set
  637        */
  638       @Resou rce
  639       public  void setE mailServic e(EmailSer vice email Service) {
  640           th is.emailSe rvice = em ailService ;
  641       }
  642  
  643       /**
  644        * Sen ds text em ail notifi cation.
  645        *
  646        * @pa ram status  the statu s
  647        * @pa ram filena me the fil ename
  648        * @pa ram fileSi ze the fil e size
  649        */
  650       privat e void sen dEmailNoti fication(S tatusVo st atus, Stri ng filenam e, String  fileSize)
  651       {
  652           St ring toEma ilIds = nu ll;  
  653           St ring email Subject =  null;
  654           St ring email Message =  null;
  655           
  656                    
  657           if (status.is ReadyForTe sting()){                         
  658                // File  ready for  SQA             
  659                emailSub ject="PPS- N/NDF File  ["+ filen ame +"] CR EATED FOR  QA";
  660                emailMes sage="\n\n The PPS-N/ NDF File "  + filenam e + " (Siz e " + file Size  + "  bytes) "
  661                         + "has bee n CREATED  and TRANSM ITTED to t he test sF TP.  It is  now ready  to "
  662                         + "be DOWN LOADED and  INSTALLED .";
  663                toEmailI ds = envir onment.get RequiredPr operty(FIL E_READY_FO R_TESTING_ TO_EMAIL_P ROPERTY);
  664            }   // File  has been A pproved/Re leased       
  665           el se if(stat us.isTrans mittedToPr oduction() ){
  666                emailSub ject="PPS- N/NDF File  " + filen ame + " RE LEASED NAT IONALLY";
  667                emailMes sage="\n\n The PPS-N/ NDF Update  File " +  filename +  " (Size "  + fileSiz e  + " byt es) "
  668                         + "has bee n National ly Release d to the P roduct sFT P and is a vailable t o be "
  669                         + "DOWNLOA DED and IN STALLED at  the local  sites.";
  670                toEmailI ds = envir onment.get RequiredPr operty(FIL E_APPROVED _TO_EMAIL_ PROPERTY);
  671           }   // File h as been Re jected
  672           el se if (sta tus.isReje ctedByQA() ){
  673                emailSub ject="PPS- N/NDF File  " + filen ame + " RE JECTED";
  674                emailMes sage="\n\n The PPS-N/ NDF Update  Test File  " + filen ame + " (S ize " + fi leSize  +  " bytes) "
  675                         + "has bee n REJECTED  by the PP S-N Manage r.";
  676                toEmailI ds = envir onment.get RequiredPr operty(FIL E_REJECTED _TO_EMAIL_ PROPERTY);
  677           }  else if (  status.isV istaError( )) {
  678                emailSub ject="PPS- N/NDF File  " + filen ame + " AU TO REJECTE D";
  679                emailMes sage="\n\n The PPS-N/ NDF File "  + filenam e + " (Siz e " + file Size + " b ytes) has  been "
  680                         + "AUTO RE JECTED by  QA.";
  681               toEmailId s = enviro nment.getR equiredPro perty(FILE _REJECTED_ TO_EMAIL_P ROPERTY);
  682           }
  683  
  684           Em ail emailB ean = new  Email();
  685  
  686           /*
  687            *  Need to s et to in a nother way  by conver ting to an  array as
  688              * setting  addresses  like  PII                 PII                  Gives
  689            *  error by  javax mail  Address P arser.
  690            * /
  691           St ring[] toE mailId = n ew String[ ] { "" };
  692  
  693           //  if toEmai lIdStr str ing is a c omma separ ated strin g then spl it it.
  694           if  (null !=  toEmailIds  && toEmai lIds.lengt h() > 0) {
  695                toEmailI d = toEmai lIds.split (",");
  696           }
  697  
  698           em ailBean.se tTo(toEmai lId);
  699           em ailBean.se tSubject(e mailSubjec t);
  700           em ailBean.se tEmailMess age(emailM essage);
  701  
  702           em ailService .sendEmail MutlipleTi mes(emailB ean);
  703       }  
  704       
  705       /**
  706        * Cle anup from  a PPSN err or during  file creat ion or sen ding to te st.
  707        *
  708        * @pa ram ndfUpd ateFileVo  the NdfUpd ateFileVo  with {@cod e StatusVo .PPSN_ERRO R} status.  Must not  be null.
  709        * @re turn true,  if succes sful
  710        */   
  711       privat e boolean  cleanupFro mException DuringCrea teAndSendT oTestProce ss(NdfUpda teFileVo n dfUpdateFi leVo) {
  712           tr y{             
  713                //cleanu p the phys ical file  on the loc al drive,  if it exis ts.
  714                NdfUpdat eProcessFi le.deleteF ile(ndfUpd ateFileVo) ;
  715           }
  716           ca tch (Excep tion e1){
  717                LOG.erro r("Seconda ry excepti on encount ered durin g cleanup  after a pr imary exce ption.", e 1);
  718           }         
  719           re turn true;
  720       }  
  721       
  722       /**
  723        * Get s the ndf  update fil e status d omain capa bility.
  724        *
  725        * @re turn the n df update  file statu s domain c apability
  726        */
  727       public  NdfUpdate FileStatus DomainCapa bility get NdfUpdateF ileStatusD omainCapab ility() {
  728           re turn ndfUp dateFileSt atusDomain Capability ;
  729       }
  730  
  731       /**
  732        * Set s the ndf  update fil e status d omain capa bility.
  733        *
  734        * @pa ram ndfUpd ateFileSta tusDomainC apability  the new nd f update f ile status  domain ca pability
  735        */
  736       public  void setN dfUpdateFi leStatusDo mainCapabi lity(
  737                NdfUpdat eFileStatu sDomainCap ability nd fUpdateFil eStatusDom ainCapabil ity) {
  738           th is.ndfUpda teFileStat usDomainCa pability =  ndfUpdate FileStatus DomainCapa bility;
  739       }
  740  
  741  
  742       /**
  743        * Set s the {@li nk Environ ment} inst ance to us e.
  744        * @pa ram enviro nment inst ance to us e
  745        */
  746       @Resou rce
  747       public  void setE nvironment (Environme nt environ ment) {
  748         this .environme nt = envir onment;
  749       }
  750   }