41. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 2/7/2017 12:14:06 PM 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.

41.1 Files compared

# Location File Last Modified
1 cpss.zip\cpss\src\main\java\gov\va\cpss\job\sendbill SendBillProcessFileCompletionTasklet.java Wed Feb 1 21:07:30 2017 UTC
2 cpss.zip\cpss\src\main\java\gov\va\cpss\job\sendbill SendBillProcessFileCompletionTasklet.java Fri Feb 3 20:49:38 2017 UTC

41.2 Comparison summary

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

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

41.4 Active regular expressions

No regular expressions were active.

41.5 Comparison detail

  1   package go v.va.cpss. job.sendbi ll;
  2  
  3   import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.DAT A_ERROR_ST ATUS;
  4   import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _FAILURE_K EY;
  5   import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.WRI TE_FAILURE _STATUS;
  6   import sta tic gov.va .cpss.job. sendbill.S endBillDat aProcessin gConstants .SEND_BILL _ID_KEY;
  7   import sta tic gov.va .cpss.job. sendbill.S endBillDat aProcessin gConstants .SEND_BILL _OUTPUT_FI LE_NAME_KE Y;
  8   import sta tic gov.va .cpss.job. sendbill.S endBillDat aProcessin gConstants .SEND_BILL _OUTPUT_RE SOURCE_KEY ;
  9   //import s tatic gov. va.cpss.jo b.sendcbs. SendCBSPro cessingCon stants.CBS _TOTAL_PAT IENTS_INCL UDED_KEY;
  10   import sta tic gov.va .cpss.job. sendbill.S endBillDat aProcessin gConstants .TOTAL_BIL L_PATIENT_ DATA_PROCE SSED;
  11  
  12   import org .springfra mework.bat ch.core.Jo bExecution ;
  13   import org .springfra mework.bat ch.core.sc ope.contex t.ChunkCon text;
  14  
  15   import gov .va.cpss.j ob.CbssJob BaseTransa ctionTaskl et;
  16   import gov .va.cpss.m odel.Proce ssStatus;
  17   import gov .va.cpss.s ervice.Sen dBillDataS ervice;
  18   import gov .va.cpss.s ervice.Sft pService;
  19   import gov .va.cpss.t ime.TimeUt ils;
  20  
  21   /**
  22    * Complet e processi ng by tran sferring f ile to sft p server w ith tempor ary name,
  23    * setting  appropria te message  status an d statemen t status,  and renami ng
  24    * tempora ry file on  sftp serv er with co rrect name . If any e rrors occu r the
  25    * databas e updates  are rolled  back and  the batch  job status  is set to  error
  26    * conditi on.
  27    * 
  28    * @author   D N   
  29    */
  30   public cla ss SendBil lProcessFi leCompleti onTasklet  extends Cb ssJobBaseT ransaction Tasklet {
  31  
  32           pr ivate fina l String T IMESTAMP_F ORMAT = "H H_mm_ss";
  33  
  34           pr ivate Stri ng tempFil enamePostf ix;
  35  
  36           pr ivate Stri ng serverT argetDirec tory;
  37  
  38           pr ivate Sftp Service sf tpService;
  39  
  40           pr ivate Send BillDataSe rvice send BillDataSe rvice;
  41  
  42           pu blic Strin g getTempF ilenamePos tfix() {
  43                    retu rn tempFil enamePostf ix;
  44           }
  45  
  46           pu blic void  setTempFil enamePostf ix(String  tempFilena mePostfix)  {
  47                    this .tempFilen amePostfix  = tempFil enamePostf ix;
  48           }
  49  
  50           pu blic Strin g getServe rTargetDir ectory() {
  51                    retu rn serverT argetDirec tory;
  52           }
  53  
  54           pu blic void  setServerT argetDirec tory(Strin g serverTa rgetDirect ory) {
  55                    this .serverTar getDirecto ry = serve rTargetDir ectory;
  56           }
  57  
  58           pu blic SftpS ervice get SftpServic e() {
  59                    retu rn sftpSer vice;
  60           }
  61  
  62           pu blic void  setSftpSer vice(SftpS ervice sft pService)  {
  63                    this .sftpServi ce = sftpS ervice;
  64           }
  65  
  66           pu blic SendB illDataSer vice getSe ndBillData Service()  {
  67                    retu rn sendBil lDataServi ce;
  68           }
  69  
  70           pu blic void  setSendBil lDataServi ce(SendBil lDataServi ce sendBil lDataServi ce) {
  71                    this .sendBillD ataService  = sendBil lDataServi ce;
  72           }
  73  
  74           @O verride
  75           pr otected bo olean exec uteLogic(C hunkContex t chunkCon text) {
  76  
  77                    bool ean succes sful = tru e;
  78  
  79                    task letLogger. info("File  Completio n Tasklet  Running!") ;
  80  
  81                    // S ave the jo bExecution  for refer ence.
  82                    JobE xecution j obExecutio n = chunkC ontext.get StepContex t().getSte pExecution ().getJobE xecution() ;
  83  
  84                    // O btain the  temporary  local file  path as i t will be  needed reg ardless
  85                    // o f failure.
  86                    fina l String s endBillOut putResourc eLocalTemp FilePath =  jobExecut ion.getExe cutionCont ext()
  87                                      .getStri ng(SEND_BI LL_OUTPUT_ RESOURCE_K EY);
  88  
  89                    // I f an error  getting t he local f ile path t hen just r eturn.
  90                    if ( (sendBillO utputResou rceLocalTe mpFilePath  != null)  && !sendBi llOutputRe sourceLoca lTempFileP ath.isEmpt y()) {
  91  
  92                             taskle tLogger.in fo("cbsOut putResourc eLocalTemp FilePath:  " + sendBi llOutputRe sourceLoca lTempFileP ath);
  93  
  94                    } el se {
  95  
  96                             // Thi s is an un expected a nd unrecov erable err or.
  97                             final  String err or = "Coul d not obta in the pat h to the t emporary l ocal outpu t file";
  98                             setFai lureStatus (jobExecut ion, DATA_ ERROR_STAT US, error) ;
  99  
  100                             // Ret urn now!
  101                             return  false;
  102                    }
  103  
  104                    // I f the job  has been s uccessful  then trans fer file t o server a nd
  105                    // a ttempt to  set approp riate fina l statemen t and mess age status es.
  106                    if ( !jobExecut ion.getExe cutionCont ext().cont ainsKey(JO B_FAILURE_ KEY)) {
  107  
  108                             // Get  filename  values fro m the jobE xecution o r jobParam eters.
  109  
  110                             // The  output fi lename.
  111                             final  String sen dBillOutpu tFileName  = jobExecu tion.getJo bParameter s()
  112                                               .getString (SEND_BILL _OUTPUT_FI LE_NAME_KE Y);
  113                             if ((s endBillOut putFileNam e != null)  && !sendB illOutputF ileName.is Empty()) {
  114  
  115                                      taskletL ogger.info ("cbsOutpu tFileName:  " + sendB illOutputF ileName);
  116  
  117                             } else  {
  118  
  119                                      // This  is an unex pected and  unrecover able error .
  120                                      final St ring error  = "Rollba ck Trigger ed - Could  not obtai n the outp ut file na me";
  121                                      setFailu reStatus(j obExecutio n, DATA_ER ROR_STATUS , error);
  122  
  123                                      // Flag  to do roll back.
  124                                      successf ul = false ;
  125                             }
  126  
  127                             // The  temporary  filename  used to tr ansfer to  the sftp s erver.
  128                             final  String sen dBillTarge tTemporary FileName =  getTempor aryFilenam e(sendBill OutputFile Name);
  129                             if (su ccessful & & (sendBil lTargetTem poraryFile Name != nu ll)) {
  130  
  131                                      taskletL ogger.info ("cbsTarge tTemporary FileName:  " + sendBi llTargetTe mporaryFil eName);
  132                             } else  {
  133  
  134                                      // This  is an unex pected and  unrecover able error .
  135                                      final St ring error  = "Rollba ck Trigger ed - Could  not creat e a tempor ary server  filename" ;
  136                                      setFailu reStatus(j obExecutio n, DATA_ER ROR_STATUS , error);
  137  
  138                                      // Flag  to do roll back.
  139                                      successf ul = false ;
  140                             }
  141  
  142                             // Get  latest Pa tAcntBalMs g ID from  the jobExe cution con text.
  143                             if(suc cessful)
  144                             {
  145                                      final Lo ng msgId =  jobExecut ion.getJob Parameters ().getLong (SEND_BILL _ID_KEY);
  146                             
  147                                      if ((msg Id == null ) || (msgI d < 1)) {
  148           
  149                                               // This is  an unexpe cted and u nrecoverab le error.
  150                                               final Stri ng error =  "Rollback  Triggered  - Could n ot obtain  a valid me ssage ID:  " + msgId;
  151                                               setFailure Status(job Execution,  DATA_ERRO R_STATUS,  error);
  152           
  153                                               // Flag to  do rollba ck.
  154                                               successful  = false;
  155                                      } else {
  156                                               successful  = updateS tatusToCom plete(succ essful, jo bExecution , msgId);
  157                                               //Update P atAcntBalM sgID for S ITEBAL -
  158                                               sendBillDa taService. updateSite BalPatAcnt BalMsgId(m sgId);
  159                                               //Update t otal Numbe r of Patie nts
  160                                               taskletLog ger.info(" Number Of  Patients L ogged in c ompletion  Tasklet: " +jobExecut ion.getExe cutionCont ext().getL ong(TOTAL_ BILL_PATIE NT_DATA_PR OCESSED));
  161                                               sendBillDa taService. updateTota lPatientPr ocessed(jo bExecution .getExecut ionContext ().getLong (TOTAL_BIL L_PATIENT_ DATA_PROCE SSED), msg Id);
  162                                      }
  163                             }
  164                             
  165                             // Sen d file wit h temporar y filename  (with tim estamp ext ension).
  166                             // Exa mple:
  167                             // 'CB S-06022016 .txt' woul d be tempo rarily sen t as
  168                             // 'CB S-06022016 .txt.<time stamp>.sen dcbs'
  169                             if (su ccessful & & sftpServ ice.ftpFil eToServerW ithName(se ndBillOutp utResource LocalTempF ilePath,
  170                                               sendBillTa rgetTempor aryFileNam e, serverT argetDirec tory)) {
  171  
  172                                      taskletL ogger.info ("Sent fil e to serve r sucessfu lly: " + s endBillTar getTempora ryFileName );
  173                             } else  {
  174  
  175                                      // This  is an unex pected and  unrecover able error .
  176                                      final St ring error  = "Rollba ck Trigger ed - Unsuc cessful fi le transfe r: "
  177                                                       +  sendBillTa rgetTempor aryFileNam e;
  178                                      setFailu reStatus(j obExecutio n, WRITE_F AILURE_STA TUS, error );
  179  
  180                                      // Flag  to do roll back.
  181                                      successf ul = false ;
  182                             }
  183  
  184                             // Ren ame the fi le on the  server (by  removing  the tempor ary
  185                             // '.< timestamp> .sendbill'  extension ).
  186                             if (su ccessful & & sftpServ ice.ftpRen ameFileInD irectory(s endBillTar getTempora ryFileName ,
  187                                               sendBillOu tputFileNa me, server TargetDire ctory)) {
  188  
  189                                      taskletL ogger.info ("Renamed  file on se rver suces sfully: "  + sendBill OutputFile Name);
  190  
  191                             } else  {
  192  
  193                                      // This  is an unex pected and  unrecover able error .
  194                                      final St ring error  = "Rollba ck Trigger ed - Unsuc cessful fi le rename:  " + sendB illOutputF ileName;
  195                                      setFailu reStatus(j obExecutio n, WRITE_F AILURE_STA TUS, error );
  196  
  197                                      // Flag  to do roll back.
  198                                      successf ul = false ;
  199                             }
  200  
  201                             // Sen d a done f ile to the  server.
  202                             final  String sen dBillOutpu tDoneFileN ame = getD oneFilenam e(sendBill OutputFile Name);
  203                             if (su ccessful
  204                                               && sftpSer vice.ftpEm ptyFileToS erverWithN ame(sendBi llOutputDo neFileName , serverTa rgetDirect ory)) {
  205  
  206                                      taskletL ogger.info ("Transfer  done file  to server  sucessful ly: " + se ndBillOutp utDoneFile Name);
  207  
  208                             } else  {
  209  
  210                                      // This  is an unex pected and  unrecover able error .
  211                                      final St ring error  = "Rollba ck Trigger ed - Unsuc cessful do ne file tr ansfer: "
  212                                                       +  sendBillOu tputDoneFi leName;
  213                                      setFailu reStatus(j obExecutio n, WRITE_F AILURE_STA TUS, error );
  214  
  215                                      // Flag  to do roll back.
  216                                      successf ul = false ;
  217                             }
  218  
  219                             // If  successful  then save  final sta tistics.
  220                             if (su ccessful)  {
  221                                      taskletL ogger.info ("Successf ul SFTP!") ;
  222                                      // TODO?
  223                                      // // Sa ve batch j ob complet ion result s.
  224                                      
  225                             }
  226                    }
  227  
  228                    // R egardless  of failure  or succes sful batch  run, dele te local C BS file
  229                    // i f exists.
  230                    if ( sendBillDa taService. deleteBill DataOutput Resource(s endBillOut putResourc eLocalTemp FilePath))  {
  231  
  232                             taskle tLogger.in fo("Delete d temporar y local fi le sucessf ully: " +  sendBillOu tputResour ceLocalTem pFilePath) ;
  233                    } el se {
  234  
  235                             // Don 't make th is a failu re in case  transfer  had alread y been
  236                             // suc cessful.
  237                             taskle tLogger.wa rn("Unable  to delete  the tempo rary local  file: " +  sendBillO utputResou rceLocalTe mpFilePath );
  238                    }
  239  
  240                    retu rn success ful;
  241           }
  242  
  243           pr ivate bool ean update StatusToCo mplete(boo lean succe ssful, Job Execution  jobExecuti on, final  Long msgId ) {
  244                    if(s endBillDat aService.s etMessageS tatus(msgI d, Process Status.Sta tus.SUCCES S))
  245                    {
  246                             taskle tLogger.in fo("Update d message  status to  success fo r message  ID: " + ms gId);
  247                    }
  248                    else
  249                    {
  250                             // Thi s is an un expected a nd unrecov erable err or.
  251                             final  String err or = "Roll back Trigg ered - Uns uccessful  attempting  to update  message s tatus to s uccess for  message I D: "
  252                                               + msgId;
  253                             setFai lureStatus (jobExecut ion, DATA_ ERROR_STAT US, error) ;
  254  
  255                             // Fla g to do ro llback.
  256                             succes sful = fal se;
  257                    }
  258                    retu rn success ful;
  259           }
  260  
  261           /* *
  262            *  Build a t emporary f ilename fo r use on t he target  sftp serve r. The for mat
  263            *  of the te mporary fi lename: Gi ven filena me: 'CBS-0 6022016.tx t' would
  264            *  return te mporary fi lename: 'C BS-0602201 6.txt.<tim estamp>.se ndcbs'
  265            *  
  266            *  @param fi lename
  267            *              The base  filename.
  268            *  @return T he tempora ry filenam e.
  269            * /
  270           pr ivate Stri ng getTemp oraryFilen ame(final  String fil ename) {
  271                    if ( (filename  != null) & & !filenam e.isEmpty( )) {
  272                             String Builder te mpFilename  = new Str ingBuilder (filename) ;
  273                             tempFi lename.app end(".");
  274                             tempFi lename.app end(TimeUt ils.getTim estamp(TIM ESTAMP_FOR MAT));
  275                             tempFi lename.app end(".");
  276                             tempFi lename.app end(tempFi lenamePost fix);
  277                             return  tempFilen ame.toStri ng();
  278                    }
  279                    retu rn null;
  280           }
  281  
  282           /* *
  283            *  Get the d one filena me based o n the outp ut filenam e. The don e filename  is
  284            *  the same  base filen ame but wi th ".don"  extension  instead of  ".txt"
  285            *  
  286            *  @param fi lename
  287            *              The outp ut filenam e.
  288            *  @return T he done fi lename.
  289            * /
  290           pr ivate Stri ng getDone Filename(f inal Strin g filename ) {
  291  
  292                    retu rn filenam e.substrin g(0, filen ame.lastIn dexOf(".tx t")) + ".d on";
  293           }
  294  
  295   }