108. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/11/2019 10:54:11 AM 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.

108.1 Files compared

# Location File Last Modified
1 HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\fw\batchprocess BatchProcessServiceImpl.java Wed May 29 15:26:02 2019 UTC
2 HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\fw\batchprocess BatchProcessServiceImpl.java Mon Jun 10 19:30:04 2019 UTC

108.2 Comparison summary

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

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

108.4 Active regular expressions

No regular expressions were active.

108.5 Comparison detail

  1   /********* ********** ********** ********** ********** ********** *********
  2    * Copyrii ght 2006 V HA. All ri ghts reser ved
  3    ********* ********** ********** ********** ********** ********** *********/
  4  
  5   package go v.va.med.f w.batchpro cess;
  6  
  7   import jav a.util.Arr ayList;
  8   import jav a.util.Dat e;
  9   import jav a.util.Lis t;
  10   import jav a.util.Map ;
  11  
  12   import org .apache.co mmons.lang .StringUti ls;
  13   import org .apache.co mmons.lang .Validate;
  14   import org .quartz.Sc hedulerExc eption;
  15   import org .springfra mework.bat ch.core.Ba tchStatus;
  16   import org .springfra mework.bat ch.core.Jo bParameter s;
  17   import org .springfra mework.bat ch.core.Jo bParameter sBuilder;
  18   import org .springfra mework.bat ch.core.co nfiguratio n.JobLocat or;
  19   import org .springfra mework.bat ch.core.la unch.JobLa uncher;
  20   import org .springfra mework.bea ns.factory .annotatio n.Autowire d;
  21   import org .springfra mework.sch eduling.qu artz.JobDe tailBean;
  22   import org .springfra mework.ste reotype.Se rvice;
  23  
  24   import gov .va.med.cc ht.persist ent.JobDAO ;
  25   import gov .va.med.fw .model.bat chprocess. BatchJobEx ecution;
  26   import gov .va.med.fw .model.bat chprocess. JobConfig;
  27   import gov .va.med.fw .model.bat chprocess. JobResult;
  28   import gov .va.med.fw .model.bat chprocess. JobStatus;
  29   import gov .va.med.fw .schedulin g.Auditabl eScheduled Process;
  30   import gov .va.med.fw .schedulin g.Schedule dProcessIn vocationCo ntext;
  31   import gov .va.med.fw .schedulin g.Schedule dProcessTr iggerEvent ;
  32   import gov .va.med.fw .schedulin g.Scheduli ngService;
  33   import gov .va.med.fw .security. LoginManag er;
  34   import gov .va.med.fw .security. SecurityCo ntextHelpe r;
  35   import gov .va.med.fw .service.A bstractCom ponent;
  36   import gov .va.med.fw .service.S erviceExce ption;
  37   import gov .va.med.fw .util.Refl ector;
  38   import gov .va.med.fw .util.Syst emUtils;
  39  
  40   /**
  41    * Initial  javadoc f or class B atchProces sServiceIm pl.
  42    * 
  43    * Created  Sep 29, 2 006 1:48:3 3 PM
  44    * 
  45    * @author   DNS     DN S
  46    */
  47   @Service 
  48   public cla ss BatchPr ocessServi ceImpl ext ends Abstr actCompone nt impleme nts BatchP rocessServ ice {
  49           
  50           pr ivate stat ic String  NAMED_QUER Y_GET_JOB_ RESULTS_BY _STATUS =  "jobResult Query_GetB yStatus";
  51           pr ivate stat ic String  NAMED_QUER Y_GET_JOB_ CONFIG_BY_ JOB_NAME =  "jobConfi gQuery_Get ByJobName" ;
  52           pr ivate stat ic String  NAMED_QUER Y_GET_JOB_ CONFIG_BY_ JOB_NAME_A ND_JOB_GRO UP = "jobC onfigQuery _GetByJobN ameAndJobG roup";
  53  
  54           pr ivate stat ic String  PARAM_STAT US = "stat us";
  55  
  56           pr ivate stat ic String  PARAM_JOB_ NAME = "jo bName";
  57  
  58           pr ivate stat ic String  PARAM_JOB_ GROUP = "j obGroup";
  59  
  60           pr ivate stat ic final S tring NO_O P = "NOOP" ;
  61  
  62           pr ivate stat ic final S tring TRAN SLATED_NO_ OP_STATUS  = "Job exe cuted; no  data to pr ocess";
  63  
  64           @A utowired
  65           pr ivate Logi nManager l oginManage r;
  66  
  67           @A utowired
  68           pr ivate Sche dulingServ ice schedu lingServic e;
  69           
  70           pr ivate JobL auncher jo bLauncher;
  71           pr ivate JobL ocator job Locator;
  72           
  73           @A utowired
  74           pr ivate JobD AO jobDao;
  75  
  76           /*
  77            *  (non-Java doc)
  78            *  
  79            *  @see
  80            *  gov.va.me d.fw.batch process.Ba tchProcess Service#sa veJobResul t(gov.va.m ed
  81            *  .fw.batch process.mo del.JobRes ult)
  82            * /
  83           pu blic void  saveJobRes ult(JobRes ult jr) {
  84                    jobD ao.saveJob Result(jr) ;
  85           }
  86  
  87           pu blic JobRe sult getJo bResult(fi nal long i d) {
  88                    retu rn jobDao. findJobRes ult(id);
  89           }
  90  
  91           @O verride
  92           pu blic JobRe sultData s aveAndOver layJobResu lt(long id , ProcessS tatistics  stats,
  93                             int to talDataCou nt) throws  ServiceEx ception {
  94                    JobR esult jr =  getAndLoc kJobResult (id);
  95                    // c reate new  ProcessSta tistics
  96                    Proc essStatist ics update dStats = n ull;
  97                    try  {
  98                             // cre ate new Pr ocessStati stics
  99                             update dStats = ( ProcessSta tistics) s tats.getCl ass().newI nstance();
  100  
  101                             update dStats.imp ortFromCSV (jr.getSta tistics()) ; // seed  it with db
  102                             // sta ts
  103                             // now  overlay w orker stat s
  104                             update dStats.ove rlayStats( stats);
  105  
  106                             // upd ate status
  107                             if (up datedStats .getNumber OfTotalRec ords() >=  totalDataC ount) {
  108                                      updatedS tats.setPr ocessingEn dDate(new  Date());
  109                                      jr.setEn dDate(upda tedStats.g etProcessi ngEndDate( ));
  110                                      if (upda tedStats.g etNumberOf ErrorRecor ds() > 0)
  111                                               jr.setStat us(JobStat us.COMPLET E_WITH_ERR OR);
  112                                      else
  113                                               jr.setStat us(JobStat us.COMPLET E);
  114                             }
  115                             jr.set Statistics (updatedSt ats.export AsCSV());
  116  
  117                             saveJo bResult(jr );
  118                    } ca tch (Excep tion e) {
  119                             throw  new Servic eException ("Unable t o saveAndO verlayJobR esult", e) ;
  120                    }
  121                    retu rn new Job ResultData (jr, updat edStats);
  122           }
  123  
  124           pr ivate JobR esult getA ndLockJobR esult(fina l long id)  {
  125                    // F IX TODO Lo ckMode.UPG RADE);
  126                    retu rn jobDao. findJobRes ult(id);
  127           }
  128  
  129           /*
  130            *  (non-Java doc)
  131            *  
  132            *  @see
  133            *  gov.va.me d.fw.batch process.Ba tchProcess Service#sa veJobConfi g(gov.va.m ed
  134            *  .fw.batch process.mo del.JobCon fig)
  135            * /
  136           pu blic void  saveJobCon fig(JobCon fig jc) {
  137                    jobD ao.saveJob Config(jc) ;
  138           }
  139  
  140           /*
  141            *  (non-Java doc)
  142            *  
  143            *  @see
  144            *  gov.va.me d.fw.batch process.Ba tchProcess Service#ge tJobConfig (java.lang
  145            *  .String)
  146            * /
  147           @S uppressWar nings("unc hecked")
  148           pu blic JobCo nfig getJo bConfig(St ring jobNa me, String  jobGroup)  {
  149                    
  150                    if ( StringUtil s.isEmpty( jobGroup))  { 
  151                             return  jobDao.fi ndJobConfi gs(jobName ).get(0);
  152                    } el se {
  153                             return  jobDao.fi ndJobConfi gs(jobName , jobGroup ).get(0);
  154                    }
  155                    
  156           }
  157  
  158           /*
  159            *  (non-Java doc)
  160            *  
  161            *  @see
  162            *  gov.va.me d.fw.batch process.Ba tchProcess Service#ge tJobResult s(gov.va.m ed
  163            *  .fw.batch process.mo del.JobSta tus)
  164            * /
  165           pu blic List< JobResult>  getJobRes ults(JobSt atus statu s) {
  166                    retu rn jobDao. findJobRes ultsByStat us(status. getCode()) ;
  167           }
  168  
  169           pu blic List< JobResult>  getJobRes ults(Batch Status sta tus) {
  170                    retu rn jobDao. findJobRes ultsByStat us(status. toString() );
  171           }
  172  
  173           /*
  174            *  i.job_nam e job_name , e.start_ time start _time, e.e nd_time en d_time,
  175            *  e.status  status, e. exit_code  exit_code,  e.exit_me ssage exit _message
  176            * /
  177           pu blic List< JobResult>  getFinish edJobResul ts(String  jobName, S tring jobG roup) {
  178                    retu rn jobDao. findFinish edJobResul ts(jobName , jobGroup );
  179           }
  180  
  181           pu blic void  executeJob (Scheduled ProcessTri ggerEvent  triggerEve nt) throws  ServiceEx ception {
  182                    exec uteJob((Sc heduledPro cessInvoca tionContex t) trigger Event.getP ayload());
  183           }
  184  
  185           /*
  186            *  (non-Java doc)
  187            *  
  188            *  @see
  189            *  gov.va.me d.fw.sched uling.Sche dulingServ ice#fireJo b(gov.va.m ed.fw.sche duling
  190            *  .Schedule dProcessIn vocationCo ntext)
  191            * /
  192           pu blic void  executeJob (Scheduled ProcessInv ocationCon text invoc ationConte xt)
  193                             throws  ServiceEx ception {
  194                    if ( logger.isI nfoEnabled ()) {
  195                             logger .info("Exe cuting job /process [ " + invoca tionContex t.getJobNa me()
  196                                               + "] for e xecutionCo ntext/user  [" + invo cationCont ext.getExe cutionCont ext()
  197                                               + "]");
  198                    }
  199  
  200                    Stri ng auditIn fo = null;
  201                    long  beforeUse dMemory =  SystemUtil s.getUsedM emory();
  202                    try  {
  203                             /*
  204                              * thi s implemen tation sup ports simp le invocat ion via a  Spring
  205                              * Job DetailName  or from t he actual  service na me and met hod name.
  206                              * The  point her e is we ne ed the ser viceName a nd methodN ame and
  207                              * the re is more  than one  way to get  it.
  208                              */
  209                             String  serviceNa me = null;
  210                             String  methodNam e = null;
  211                             if (in vocationCo ntext.getJ obDetailBe anName() ! = null) {
  212                                      JobDetai lBean job  = (JobDeta ilBean) th is.getAppl icationCon text().get Bean(
  213                                                       in vocationCo ntext.getJ obDetailBe anName(),  JobDetailB ean.class) ;
  214                                      serviceN ame = (Str ing) job.g etJobDataM ap().get(" serviceNam e");
  215                                      methodNa me = (Stri ng) job.ge tJobDataMa p().get("m ethodName" );
  216                             } else  {
  217                                      serviceN ame = invo cationCont ext.getSer viceName() ;
  218                                      methodNa me = invoc ationConte xt.getMeth odName();
  219                             }
  220                             Object  service =  this.getA pplication Context(). getBean(se rviceName) ;
  221  
  222                             auditI nfo = serv ice instan ceof Audit ableSchedu ledProcess  ? ((Audit ableSchedu ledProcess ) service)
  223                                               .getAuditI nfo(invoca tionContex t)
  224                                               : serviceN ame + "."  + methodNa me;
  225                             getLog inManager( ).loginAno nymous(aud itInfo);
  226  
  227                             // see  if servic e supports  invocatio n via a
  228                             // Sch eduledProc essInvocat ionContext
  229                             Object [] args =  new Object [] { invoc ationConte xt };
  230                             try {
  231                                      Reflecto r.findMeth od(service , methodNa me, args);
  232                             } catc h (NoSuchM ethodExcep tion e) {
  233                                      // no "s tandard" m ethod for  ScheduledP rocessInvo cationCont ext
  234                                      // ....j ust use wr apped argu ments
  235                                      Object o bj = invoc ationConte xt.getInvo cationArgu ments();
  236                                      args = o bj instanc eof Object [] ? (Obje ct[]) obj  : new Obje ct[] { obj  };
  237                             }
  238  
  239                             Reflec tor.invoke (service,  methodName , args);
  240                    } ca tch (Throw able e) {
  241                             throw  new Servic eException (
  242                                               "Unable to  execute j ob with Sc heduledPro cessInvoca tionContex t: "
  243                                                                + in vocationCo ntext, e);
  244                    } fi nally {
  245                             getLog inManager( ).logout() ;
  246  
  247                             System Utils.logM emory(true ); // note  this will  suggest G C
  248                             System Utils.logM emoryDelta (auditInfo , beforeUs edMemory);
  249                    }
  250           }
  251  
  252           pu blic void  afterPrope rtiesSet()  {
  253                    Vali date.notNu ll(schedul ingService , "A sched ulingServi ce is requ ired");
  254                    Vali date.notNu ll(loginMa nager, "A  loginManag er is requ ired");            
  255           }
  256  
  257           /* *
  258            *  @return R eturns the  loginMana ger.
  259            * /
  260           pu blic Login Manager ge tLoginMana ger() {
  261                    retu rn loginMa nager;
  262           }
  263  
  264           /* *
  265            *  @param lo ginManager
  266            *              The logi nManager t o set.
  267            * /
  268           pu blic void  setLoginMa nager(Logi nManager l oginManage r) {
  269                    this .loginMana ger = logi nManager;
  270           }
  271  
  272           /*
  273            *  (non-Java doc)
  274            *  
  275            *  @see
  276            *  gov.va.me d.fw.batch process.Ba tchProcess Service#ca ncelActive Job(gov.va
  277            *  .med.fw.m odel.Entit yKey)
  278            * /
  279           @O verride
  280           pu blic void  cancelActi veJob(fina l long id)  throws Se rviceExcep tion {
  281                    /*
  282                     * s ome jobs a re sync an d some are  async - t o cover th ese scenar ios,
  283                     * m ust cancel  the job i n 2 differ ent ways
  284                     */
  285  
  286                    JobR esult jobR esult = jo bDao.findJ obResult(i d);
  287                    
  288                    if ( JobStatus. IN_PROCESS .getCode() .equals(jo bResult.ge tStatus(). getCode()) ) {
  289                             // do  this first
  290                             jobRes ult.setSta tus(JobSta tus.CANCEL LED);
  291                             saveJo bResult(jo bResult);
  292  
  293                             // do  this secon d
  294                             try {
  295                                      scheduli ngService. interrupt( jobResult. getName(),  jobResult .getGroup( ));
  296                             } catc h (Schedul erExceptio n e) {
  297                                      throw ne w ServiceE xception(" Unable to  interrupt  the job du ring cance l", e);
  298                             }
  299                    }
  300           }
  301  
  302           /*
  303            *  (non-Java doc)
  304            *  
  305            *  @see
  306            *  gov.va.me d.fw.batch process.Ba tchProcess Service#er rActiveJob (gov.va.me d
  307            *  .fw.model .EntityKey )
  308            * /
  309           pu blic void  errActiveJ ob(final l ong id) {
  310                    JobR esult jobR esult = jo bDao.findJ obResult(i d);
  311                    if ( JobStatus. IN_PROCESS .getCode() .equals(jo bResult.ge tStatus(). getCode()) ) {
  312                             jobRes ult.setSta tus(JobSta tus.ERROR) ;
  313                             saveJo bResult(jo bResult);
  314                    }
  315           }
  316  
  317           @S uppressWar nings("unc hecked")
  318           pu blic void  executeJob (Map jobDe tails) thr ows Servic eException  {
  319                    Stri ng jobName  = (String ) jobDetai ls.get("jo bName");
  320                    JobP arametersB uilder job Parameters Builder  =  new JobPa rametersBu ilder() ;
  321                    Stri ng runBy =  (String)  jobDetails .get("user Id");
  322                    jobP arametersB uilder.add String("ru nBy", runB y == null  ? Security ContextHel per.getUse rName() :  runBy);
  323                    jobP arametersB uilder.add Date("Date ", new Dat e());
  324                                      
  325                    JobP arameters  jobParamet ers = jobP arametersB uilder.toJ obParamete rs();
  326                    try  {
  327                             jobLau ncher.run( jobLocator .getJob(jo bName), jo bParameter s);
  328                    } ca tch (Excep tion e) {
  329                             throw  new Servic eException (e.getMess age());
  330                    }
  331           }
  332  
  333           pu blic JobLa uncher get JobLaunche r() {
  334                    retu rn jobLaun cher;
  335           }
  336  
  337           pu blic void  setJobLaun cher(JobLa uncher job Launcher)  {
  338                    this .jobLaunch er = jobLa uncher;
  339           }
  340  
  341           pu blic JobLo cator getJ obLocator( ) {
  342                    retu rn jobLoca tor;
  343           }
  344  
  345           pu blic void  setJobLoca tor(JobLoc ator jobLo cator) {
  346                    this .jobLocato r = jobLoc ator;
  347           }
  348  
  349           /* *
  350            *  @return R eturns the  schedulin gService.
  351            * /
  352           pu blic Sched ulingServi ce getSche dulingServ ice() {
  353                    retu rn schedul ingService ;
  354           }
  355  
  356           /* *
  357            *  @param sc hedulingSe rvice
  358            *              The sche dulingServ ice to set .
  359            * /
  360           pu blic void  setSchedul ingService (Schedulin gService s chedulingS ervice) {
  361                    this .schedulin gService =  schedulin gService;
  362           }
  363  
  364           @S uppressWar nings("unc hecked")
  365           pu blic List< BatchJobEx ecution> c onvertResu lts(List r esults) th rows Servi ceExceptio n {
  366                    List <BatchJobE xecution>  jobResults  = new Arr ayList<Bat chJobExecu tion>();
  367                    try  {
  368                             for (i nt i = 0;  i < result s.size();  i++) {
  369                                      BatchJob Execution  result = n ew BatchJo bExecution ();
  370                                      Object[]  objs = (O bject[]) r esults.get (i);
  371                                      result.s etJobName( (String) o bjs[0]);
  372                                      result.s etStartDat e((Date) o bjs[1]);
  373                                      result.s etEndDate( (Date) obj s[2]);
  374                                      result.s etStatus(( String) ob js[3]);
  375                                      if (objs [4] != nul l && ((Str ing) objs[ 4]).equals IgnoreCase (NO_OP)) {
  376                                               result.set ExitStatus (TRANSLATE D_NO_OP_ST ATUS);
  377                                      } else
  378                                               result.set ExitStatus ((String)  objs[4]);
  379                                      result.s etExitMess age((Strin g) objs[5] );
  380                                      String r unBy = (St ring) objs [6];
  381                                      String l ast_name =  (String)  objs[7];
  382                                      String f irst_name  = (String)  objs[8];
  383                                      String m iddle_name  = (String ) objs[9];
  384                                      if (last _name != n ull || fir st_name !=  null) {
  385                                               String nam e = (last_ name == nu ll ? "" :  last_name  + ", ")
  386                                                                + (f irst_name  == null ?  "" : first _name)
  387                                                                + (m iddle_name  == null ?  "" : " "  + middle_n ame);
  388                                               result.set RunBy(name );
  389                                      } else {
  390                                               result.set RunBy(runB y);
  391                                      }
  392                                      result.s etStatisti cs((String ) objs[10] );
  393  
  394                                      jobResul ts.add(res ult);
  395                             }
  396                             return  jobResult s;
  397                    } ca tch (Excep tion e) {
  398                             throw  new Servic eException ("Unable t o getJobRe sults with  job name:  ", e);
  399                    }
  400           }
  401  
  402   }