72. EPMO Open Source Coordination Office Redaction File Detail Report

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

72.1 Files compared

# Location File Last Modified
1 cpss.zip\cpss\src\main\java\gov\va\cpss\service SchedulingService.java Wed Feb 1 21:07:26 2017 UTC
2 cpss.zip\cpss\src\main\java\gov\va\cpss\service SchedulingService.java Mon Feb 6 15:17:46 2017 UTC

72.2 Comparison summary

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

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

72.4 Active regular expressions

No regular expressions were active.

72.5 Comparison detail

  1   package go v.va.cpss. service;
  2  
  3   import sta tic gov.va .cpss.ESAP I.EsapiVal idationTyp e.LOG_FORG ING;
  4   import sta tic gov.va .cpss.ESAP I.EsapiVal idator.val idateStrin gInput;
  5  
  6   import jav a.text.Par seExceptio n;
  7   import jav a.util.Arr ayList;
  8   import jav a.util.Cal endar;
  9   import jav a.util.Dat e;
  10   import jav a.util.Lis t;
  11   import jav a.util.Set ;
  12  
  13   import org .apache.lo g4j.Logger ;
  14   import org .quartz.Cr onExpressi on;
  15   import org .quartz.Jo b;
  16   import org .quartz.Jo bBuilder;
  17   import org .quartz.Jo bDataMap;
  18   import org .quartz.Jo bDetail;
  19   import org .quartz.Jo bKey;
  20   import org .quartz.Sc heduler;
  21   import org .quartz.Sc hedulerExc eption;
  22   import org .quartz.Tr igger;
  23   import org .quartz.Tr iggerKey;
  24   import org .quartz.im pl.matcher s.GroupMat cher;
  25   import org .quartz.im pl.trigger s.CronTrig gerImpl;
  26   import org .quartz.im pl.trigger s.SimpleTr iggerImpl;
  27   import org .springfra mework.bat ch.core.la unch.JobLa uncher;
  28   import org .springfra mework.sch eduling.qu artz.Quart zJobBean;
  29   import org .springfra mework.ste reotype.Se rvice;
  30  
  31   import gov .va.cpss.c ron.CronUt ils;
  32   import gov .va.cpss.m odel.Batch Job;
  33   import gov .va.cpss.m odel.Batch Type;
  34  
  35   /**
  36    * Service  class for  schedulin g activiti es relatin g to batch  jobs.
  37    * 
  38    * @author   DN S      D N S
  39    */
  40   @Service
  41   public cla ss Schedul ingService  {
  42  
  43           pr ivate stat ic final L ogger logg er = Logge r.getLogge r(Scheduli ngService. class.getC anonicalNa me());
  44  
  45           /* *
  46            *  The job g roup for Q uartz Jobs .
  47            * /
  48           pr ivate Stri ng jobGrou p;
  49  
  50           /* *
  51            *  The trigg er group f or Quartz  Jobs.
  52            * /
  53           pr ivate Stri ng trigger Group;
  54  
  55           /* *
  56            *  The Quart z schedule r.
  57            * /
  58           pr ivate Sche duler sche duler;
  59  
  60           /* *
  61            *  The servi ce for man aging batc h jobs.
  62            * /
  63           pr ivate Batc hService b atchServic e;
  64  
  65           /* *
  66            *  Spring Ba tch JobLau ncher for  starting F lowJobs
  67            * /
  68           pr ivate JobL auncher jo bLauncher;
  69  
  70           pu blic Strin g getJobGr oup() {
  71                    retu rn jobGrou p;
  72           }
  73  
  74           pu blic void  setJobGrou p(String j obGroup) {
  75                    this .jobGroup  = jobGroup ;
  76           }
  77  
  78           pu blic Strin g getTrigg erGroup()  {
  79                    retu rn trigger Group;
  80           }
  81  
  82           pu blic void  setTrigger Group(Stri ng trigger Group) {
  83                    this .triggerGr oup = trig gerGroup;
  84           }
  85  
  86           pu blic Sched uler getSc heduler()  {
  87                    retu rn schedul er;
  88           }
  89  
  90           pu blic void  setSchedul er(Schedul er schedul er) {
  91                    this .scheduler  = schedul er;
  92           }
  93  
  94           pu blic Batch Service ge tBatchServ ice() {
  95                    retu rn batchSe rvice;
  96           }
  97  
  98           pu blic void  setBatchSe rvice(Batc hService b atchServic e) {
  99                    this .batchServ ice = batc hService;
  100           }
  101  
  102           pu blic JobLa uncher get JobLaunche r() {
  103                    retu rn jobLaun cher;
  104           }
  105  
  106           pu blic void  setJobLaun cher(JobLa uncher job Launcher)  {
  107                    this .jobLaunch er = jobLa uncher;
  108           }
  109  
  110           /* *
  111            *  Build the  trigger n ame for th e batch jo b. The nam e is simpl y the batc h
  112            *  job name  with Trigg er postfix .
  113            *  
  114            *  @param ba tchJob
  115            *              The batc h job for  which to c reate a tr igger name .
  116            *  @return S tring of t he name of  the trigg er.
  117            * /
  118           pr ivate Stri ng buildTr iggerNameF orJob(Batc hJob batch Job) {
  119                    retu rn batchJo b.getName( ) + "Trigg er";
  120           }
  121  
  122           /* *
  123            *  Save the  specified  batch job  to the dat abase and  update the  Quartz
  124            *  Schedule.
  125            *  
  126            *  @param ba tchJob
  127            *              The batc h job to s ave.
  128            * /
  129           pu blic void  saveBatchJ ob(BatchJo b batchJob ) {
  130                    Batc hType bt =  batchServ ice.getBat chTypeForJ ob(batchJo b);
  131  
  132                    // H andle sche duling bas ed on job  type.
  133                    swit ch (bt.get JobType())  {
  134                    case  DAILY: {
  135                             logger .info("Sav ing " + va lidateStri ngInput(ba tchJob.get Name(), LO G_FORGING)  + ": "
  136                                               + validate StringInpu t(batchJob .getSchedu le(), LOG_ FORGING) +  " "
  137                                               + validate StringInpu t(Integer. toString(b atchJob.ge tTypeId()) , LOG_FORG ING));
  138                             saveBa tchCron(ba tchJob);
  139                             break;
  140                    }
  141                    case  MANUAL: {
  142                             logger .info("Sav ing " + va lidateStri ngInput(ba tchJob.get Name(), LO G_FORGING)  + ": " +  "Manual Ru n" + " "
  143                                               + validate StringInpu t(Integer. toString(b atchJob.ge tTypeId()) , LOG_FORG ING));
  144                             batchJ ob.setSche dule(Batch Type.JobTy pe.MANUAL. getName()) ;
  145                             saveBa tchManual( batchJob);
  146                             break;
  147                    }
  148                    case  SPECIFIED : {
  149                             saveBa tchSpecifi ed(batchJo b);
  150                             break;
  151                    }
  152                    case  UNDEFINED : {
  153                             logger .error("Un able to ha ndle sched ule for UN DEFINED jo b type: "  + bt.getNa me());
  154                             break;
  155                    }
  156                    defa ult: {
  157                             logger .error("Un able to ha ndle sched ule for un recognized  job type:  " + bt.ge tName());
  158                             break;
  159                    }
  160                    }
  161  
  162           }
  163  
  164           /* *
  165            *  Save the  batch job  in the dat abase and  update the  Quartz Sc heduler as  a
  166            *  cron trig gered job.
  167            *  
  168            *  @param ba tchJob
  169            *              The batc h job from  which to  update dat abase and  scheduler.
  170            * /
  171           pu blic void  saveBatchC ron(BatchJ ob batchJo b) {
  172  
  173                    // S ave in DB!
  174                    batc hService.u pdateBatch Job(batchJ ob);
  175  
  176                    // S et the sch edule!
  177                    setB atchCron(b atchJob);
  178           }
  179  
  180           /* *
  181            *  Set the s cheduler w ith the up dated batc h cron tri ggered job .
  182            *  
  183            *  @param ba tchJob
  184            *              The batc h job from  which to  update sch eduler.
  185            * /
  186           pu blic void  setBatchCr on(BatchJo b batchJob ) {
  187  
  188                    try  {
  189                             JobKey  jk = new  JobKey(bat chJob.getN ame(), job Group);
  190  
  191                             @Suppr essWarning s("uncheck ed")
  192                             List<T rigger> tL  = (List<T rigger>) s cheduler.g etTriggers OfJob(jk);
  193  
  194                             // If  the trigge r list is  empty then  create a  new cron t rigger for
  195                             // the  job.
  196                             if (tL .isEmpty() ) {
  197  
  198                                      if (!sch eduler.che ckExists(j k)) {
  199                                               // This is  an unreco verable er ror. The j ob key sho uld
  200                                               // always  exist.
  201                                               logger.err or("setBat chCron - j ob key doe s not exis t! - exiti ng");
  202                                               return;
  203                                      }
  204  
  205                                      CronTrig gerImpl tr igger = ne w CronTrig gerImpl();
  206  
  207                                      TriggerK ey tK = ne w TriggerK ey(buildTr iggerNameF orJob(batc hJob), tri ggerGroup) ;
  208  
  209                                      trigger. setKey(tK) ;
  210  
  211                                      try {
  212                                               checkJobSc hedule(bat chJob);
  213  
  214                                               CronExpres sion cronE xp = new C ronExpress ion(CronUt ils.getCro nExpressio n(batchJob .getSchedu le()));
  215  
  216                                               trigger.se tCronExpre ssion(cron Exp);
  217                                               trigger.se tStartTime (new Date( ));
  218  
  219                                               trigger.se tJobKey(jk );
  220                                               trigger.se tJobName(b atchJob.ge tName());
  221  
  222                                               logger.inf o(trigger. toString() );
  223  
  224                                               Date nextF ireDate =  scheduler. scheduleJo b(trigger) ;
  225  
  226                                               if (nextFi reDate ==  null) {
  227                                                       lo gger.error ("Schedule  of job wa s unsucces sful.");
  228                                               }
  229                                      } catch  (ParseExce ption e) {
  230                                               logger.err or("Parse  error with  Cron Expr ession: "  + e.getMes sage());
  231                                      }
  232  
  233                                      return;
  234                             }
  235  
  236                             // The  trigger f or the job  exists.
  237                             Trigge r t = tL.g et(0);
  238  
  239                             // Upd ate the tr igger depe nding on t he type.
  240                             if (t  instanceof  CronTrigg erImpl) {
  241  
  242                                      CronTrig gerImpl tr igger = (C ronTrigger Impl) t;
  243                                      TriggerK ey tK = tr igger.getK ey();
  244  
  245                                      schedule r.pauseTri gger(tK);
  246  
  247                                      try {
  248                                               CronExpres sion cronE xp = new C ronExpress ion(CronUt ils.getCro nExpressio n(batchJob .getSchedu le()));
  249                                               trigger.se tCronExpre ssion(cron Exp);
  250                                               trigger.se tStartTime (new Date( ));
  251  
  252                                               Date srjDa te = sched uler.resch eduleJob(t K, trigger );
  253                                               if (srjDat e == null)  {
  254                                                       lo gger.error ("Problem  scheduling  job: " +  validateSt ringInput( batchJob.g etName(),  LOG_FORGIN G));
  255                                               }
  256                                      } catch  (ParseExce ption e) {
  257                                               logger.err or(
  258                                                                "Par se error w ith Cron E xpression:  " + valid ateStringI nput(e.get Message(),  LOG_FORGI NG));
  259                                      }
  260  
  261                             } else  if (t ins tanceof Si mpleTrigge rImpl) {
  262  
  263                                      SimpleTr iggerImpl  trigger =  (SimpleTri ggerImpl)  t;
  264                                      TriggerK ey tK = tr igger.getK ey();
  265  
  266                                      schedule r.pauseTri gger(tK);
  267  
  268                                      CronTrig gerImpl ne wTrigger =  new CronT riggerImpl ();
  269                                      newTrigg er.setKey( tK);
  270  
  271                                      try {
  272                                               CronExpres sion cronE xp = new C ronExpress ion(CronUt ils.getCro nExpressio n(batchJob .getSchedu le()));
  273  
  274                                               newTrigger .setCronEx pression(c ronExp);
  275                                               newTrigger .setStartT ime(new Da te());
  276  
  277                                               Date srjDa te = sched uler.resch eduleJob(t K, newTrig ger);
  278                                               if (srjDat e == null)  {
  279                                                       lo gger.error ("Problem  scheduling  job: " +  validateSt ringInput( batchJob.g etName(),  LOG_FORGIN G));
  280                                               }
  281                                      } catch  (ParseExce ption e) {
  282                                               logger.err or("Parse  error with  Cron Expr ession: "  + e.getMes sage());
  283                                      }
  284  
  285                             } else  {
  286                                      logger.e rror("Unkn own trigge r type! -  Exiting!") ;
  287                                      return;
  288                             }
  289  
  290                    } ca tch (Sched ulerExcept ion e) {
  291                             logger .error("Ca ught Excep tion: " +  e.getMessa ge());
  292                    }
  293  
  294           }
  295  
  296           /* *
  297            *  Save the  batch job  in the dat abase and  update the  Quartz Sc heduler as  a
  298            *  simple tr iggered jo b.
  299            *  
  300            *  @param ba tchJob
  301            *              The batc h job from  which to  update dat abase and  scheduler.
  302            * /
  303           pu blic void  saveBatchS pecified(B atchJob ba tchJob) {
  304  
  305                    // S ave in DB!
  306                    batc hService.u pdateBatch Job(batchJ ob);
  307  
  308                    // S et the sch edule!
  309                    setB atchSpecif ied(batchJ ob);
  310           }
  311  
  312           /* *
  313            *  Set the s cheduler w ith the up dated batc h simple t riggered j ob.
  314            *  
  315            *  @param ba tchJob
  316            *              The batc h job from  which to  update sch eduler.
  317            * /
  318           pu blic void  setBatchSp ecified(Ba tchJob bat chJob) {
  319                    try  {
  320  
  321                             JobKey  jk = new  JobKey(bat chJob.getN ame(), job Group);
  322  
  323                             @Suppr essWarning s("uncheck ed")
  324                             List<T rigger> tL  = (List<T rigger>) s cheduler.g etTriggers OfJob(jk);
  325  
  326                             // If  trigger li st is empt y then we  make a new  trigger.
  327                             if (tL .isEmpty() ) {
  328  
  329                                      if (!sch eduler.che ckExists(j k)) {
  330                                               // This is  an unreco verable er ror. The j ob key sho uld
  331                                               // always  exist.
  332                                               logger.err or("setBat chSpecifie d - job ke y does not  exist! -  exiting");
  333                                               return;
  334                                      }
  335  
  336                                      SimpleTr iggerImpl  trigger =  new Simple TriggerImp l();
  337                                      TriggerK ey tK = ne w TriggerK ey(buildTr iggerNameF orJob(batc hJob), tri ggerGroup) ;
  338  
  339                                      checkJob Schedule(b atchJob);
  340  
  341                                      final St ring delim s = ":";
  342                                      String[]  tokens =  batchJob.g etSchedule ().split(d elims);
  343  
  344                                      Calendar  cal = Cal endar.getI nstance();
  345                                      cal.set( Calendar.H OUR_OF_DAY , Integer. parseInt(t okens[0])) ;
  346                                      cal.set( Calendar.M INUTE, Int eger.parse Int(tokens [1]));
  347                                      cal.set( Calendar.S ECOND, Int eger.parse Int(tokens [2]));
  348                                      cal.set( Calendar.M ILLISECOND , 0);
  349                                      Date myS tartTime =  cal.getTi me();
  350  
  351                                      trigger. setKey(tK) ;
  352                                      trigger. setStartTi me(myStart Time);
  353  
  354                                      trigger. setRepeatC ount(0);
  355                                      trigger. setJobKey( jk);
  356                                      trigger. setJobName (batchJob. getName()) ;
  357  
  358                                      trigger. setMisfire Instructio n(
  359                                                       Si mpleTrigge rImpl.MISF IRE_INSTRU CTION_RESC HEDULE_NEX T_WITH_EXI STING_COUN T);
  360  
  361                                      logger.i nfo(trigge r.toString ());
  362  
  363                                      Date nex tFireDate  = schedule r.schedule Job(trigge r);
  364  
  365                                      if (next FireDate = = null) {
  366                                               logger.err or("Proble m scheduli ng job: "  + validate StringInpu t(batchJob .getName() , LOG_FORG ING));
  367                                      }
  368                                      return;
  369                             }
  370  
  371                             Trigge r t = tL.g et(0);
  372                             if (t  instanceof  CronTrigg erImpl) {
  373                                      CronTrig gerImpl tr igger = (C ronTrigger Impl) t;
  374                                      TriggerK ey tK = tr igger.getK ey();
  375  
  376                                      schedule r.pauseTri gger(tK);
  377  
  378                                      final St ring delim s = ":";
  379                                      String[]  tokens =  batchJob.g etSchedule ().split(d elims);
  380  
  381                                      Calendar  cal = Cal endar.getI nstance();
  382                                      cal.set( Calendar.H OUR_OF_DAY , Integer. parseInt(t okens[0])) ;
  383                                      cal.set( Calendar.M INUTE, Int eger.parse Int(tokens [1]));
  384                                      cal.set( Calendar.S ECOND, Int eger.parse Int(tokens [2]));
  385                                      cal.set( Calendar.M ILLISECOND , 0);
  386                                      Date myS tartTime =  cal.getTi me();
  387  
  388                                      SimpleTr iggerImpl  newTrigger  = new Sim pleTrigger Impl();
  389                                      newTrigg er.setKey( tK);
  390                                      newTrigg er.setStar tTime(mySt artTime);
  391                                      newTrigg er.setRepe atCount(0) ;
  392                                      newTrigg er.setMisf ireInstruc tion(
  393                                                       Si mpleTrigge rImpl.MISF IRE_INSTRU CTION_RESC HEDULE_NEX T_WITH_EXI STING_COUN T);
  394  
  395                                      Date srj Date = sch eduler.res cheduleJob (tK, newTr igger);
  396                                      if (srjD ate == nul l) {
  397                                               logger.err or("Proble m scheduli ng job: "  + validate StringInpu t(batchJob .getName() , LOG_FORG ING));
  398                                      }
  399  
  400                             } else  if (t ins tanceof Si mpleTrigge rImpl) {
  401                                      SimpleTr iggerImpl  trigger =  (SimpleTri ggerImpl)  t;
  402                                      TriggerK ey tK = tr igger.getK ey();
  403  
  404                                      schedule r.pauseTri gger(tK);
  405  
  406                                      final St ring delim s = ":";
  407                                      String[]  tokens =  batchJob.g etSchedule ().split(d elims);
  408  
  409                                      Calendar  cal = Cal endar.getI nstance();
  410                                      cal.set( Calendar.H OUR_OF_DAY , Integer. parseInt(t okens[0])) ;
  411                                      cal.set( Calendar.M INUTE, Int eger.parse Int(tokens [1]));
  412                                      cal.set( Calendar.S ECOND, Int eger.parse Int(tokens [2]));
  413                                      cal.set( Calendar.M ILLISECOND , 0);
  414                                      Date myS tartTime =  cal.getTi me();
  415  
  416                                      trigger. setKey(tK) ;
  417                                      trigger. setStartTi me(myStart Time);
  418                                      trigger. setRepeatC ount(0);
  419  
  420                                      trigger. setMisfire Instructio n(
  421                                                       Si mpleTrigge rImpl.MISF IRE_INSTRU CTION_RESC HEDULE_NEX T_WITH_EXI STING_COUN T);
  422  
  423                                      Date srj Date = sch eduler.res cheduleJob (tK, trigg er);
  424                                      if (srjD ate == nul l) {
  425                                               logger.err or("Proble m scheduli ng job: "  + validate StringInpu t(batchJob .getName() , LOG_FORG ING));
  426                                      }
  427  
  428                             } else  {
  429                                      logger.e rror("Unkn own trigge r type! -  Exiting");
  430                                      return;
  431                             }
  432  
  433                    } ca tch (Sched ulerExcept ion e) {
  434                             logger .error("Ca ught Excep tion: " +  e.getMessa ge());
  435                    }
  436  
  437           }
  438  
  439           /* *
  440            *  Save the  batch job  in the dat abase and  update the  Quartz Sc heduler to
  441            *  unschedul e the job  trigger.
  442            *  
  443            *  @param ba tchJob
  444            *              The batc h job from  which to  update dat abase and  scheduler.
  445            * /
  446           pu blic void  saveBatchM anual(Batc hJob batch Job) {
  447  
  448                    // S ave in DB!
  449                    batc hService.u pdateBatch Job(batchJ ob);
  450  
  451                    // S et the sch edule!
  452                    setB atchManual (batchJob) ;
  453           }
  454  
  455           /* *
  456            *  Update th e schedule r to unsch edule the  specified  batch job.
  457            *  
  458            *  @param ba tchJob
  459            *              The batc h job from  which to  update sch eduler.
  460            * /
  461           pu blic void  setBatchMa nual(Batch Job batchJ ob) {
  462  
  463                    try  {
  464                             JobKey  jk = new  JobKey(bat chJob.getN ame(), job Group);
  465  
  466                             @Suppr essWarning s("uncheck ed")
  467                             List<T rigger> tL  = (List<T rigger>) s cheduler.g etTriggers OfJob(jk);
  468  
  469                             if (!t L.isEmpty( )) {
  470  
  471                                      // Turn  off trigge r.
  472                                      Trigger  t = tL.get (0);
  473                                      schedule r.unschedu leJob(t.ge tKey());
  474                             }
  475  
  476                    } ca tch (Sched ulerExcept ion e) {
  477                             logger .error("Ca ught Excep tion: " +  e.getMessa ge());
  478                    }
  479           }
  480  
  481           /* *
  482            *  Check the  job sched ule and sa ve a defau lt value i f invalid.
  483            *  
  484            *  @param ba tchJob
  485            *              The batc h job to c heck.
  486            * /
  487           pr ivate void  checkJobS chedule(Ba tchJob bat chJob) {
  488                    Stri ng schedul e = batchJ ob.getSche dule();
  489                    if ( (schedule  == null) | | schedule .isEmpty() ) {
  490                             schedu le = "23:0 0:00";
  491                             batchJ ob.setSche dule(sched ule);
  492                             logger .warn("Job  '" + batc hJob.getNa me() + "'  schedule w as invalid  so using  default va lue: " + s chedule);
  493                             batchS ervice.upd ateBatchJo b(batchJob );
  494                    }
  495           }
  496  
  497           /* *
  498            *  Forcefull y run the  specified  batch job  by it's ID .
  499            *  
  500            *  @param id
  501            *              The ID o f the batc h job to r un.
  502            * /
  503           pu blic void  runJob(int  id) {
  504  
  505                    // L ook up job  based on  id!
  506                    Batc hJob batch Job = batc hService.g etBatchJob ById(id);
  507  
  508                    if ( batchJob = = null) {
  509                             logger .error("Ba tch job "  + id + " d oes not ex ist.");
  510                    } el se {
  511  
  512                             // For cefully ru n the job  specified  by the id.
  513                             JobKey  jk = new  JobKey(bat chJob.getN ame(), job Group);
  514  
  515                             try {
  516                                      if (sche duler.chec kExists(jk )) {
  517                                               scheduler. triggerJob (jk);
  518                                      } else {
  519                                               logger.err or("Job ke y does not  exist.");
  520                                      }
  521                             } catc h (Schedul erExceptio n e) {
  522                                      logger.e rror("runJ ob excepti on: " + e. getMessage ());
  523                             }
  524                    }
  525           }
  526  
  527           /* *
  528            *  Initializ e the Quar tz Schedul er upon de ployment.
  529            * /
  530           pu blic void  initNotifi cationSche duler() {
  531  
  532                    // C reate jobs  from the  database.
  533                    List <BatchJob>  bjL = bat chService. getBatchJo bList();
  534  
  535                    // S ave a list  of the jo b names to  check if  any old jo bs should  be
  536                    // r emoved.
  537                    List <String> n ameL = new  ArrayList <>();
  538  
  539                    for  (BatchJob  bj : bjL)  {
  540                             try {
  541  
  542                                      // Reset  status fo r job to n ot running  if was fo und to hav e
  543                                      // runni ng state.
  544                                      // This  would indi cate the j ob was une xpected in terrupted  or
  545                                      // ended  in an ear lier run.
  546                                      if (batc hService.s etNotRunni ngById(bj) ) {
  547                                               logger.war n("Last st atus for b atch job ( " + valida teStringIn put(bj.get Name(), LO G_FORGING)
  548                                                                + ")  set to no t running" );
  549                                      }
  550  
  551                                      Class<?>  clazz = C lass.forNa me("gov.va .cpss.job. " + bj.get Name());
  552  
  553                                      if (claz z.newInsta nce() inst anceof Qua rtzJobBean ) {
  554  
  555                                               JobDataMap  map = new  JobDataMa p();
  556                                               map.put("n ame", bj.g etName());
  557  
  558                                               @SuppressW arnings("u nchecked")
  559                                               JobDetail  job = JobB uilder.new Job((Class <? extends  Job>) cla zz).withId entity(bj. getName(),  jobGroup)
  560                                                                .usi ngJobData( map).store Durably(). build();
  561                                               initialize Trigger(bj , job);
  562  
  563                                               nameL.add( bj.getName ());
  564  
  565                                      } else {
  566                                               logger.err or("Invali d Job Clas s: " + val idateStrin gInput(bj. getName(),  LOG_FORGI NG));
  567                                      }
  568  
  569                             } catc h (ClassNo tFoundExce ption e) {
  570                                      logger.e rror("Clas sNotFoundE xception w hen initia lizing job : "
  571                                                       +  validateSt ringInput( bj.getName (), LOG_FO RGING) + " , e: " + e .getMessag e());
  572                             } catc h (Instant iationExce ption e) {
  573                                      logger.e rror("Inst antiationE xception w hen initia lizing job : "
  574                                                       +  validateSt ringInput( bj.getName (), LOG_FO RGING) + " , e: " + e .getMessag e());
  575                             } catc h (Illegal AccessExce ption e) {
  576                                      logger.e rror("Ille galAccessE xception w hen initia lizing job : "
  577                                                       +  validateSt ringInput( bj.getName (), LOG_FO RGING) + " , e: " + e .getMessag e());
  578                             }
  579  
  580                    }
  581  
  582                    if ( !deleteNon existantJo bs(nameL))  {
  583                             logger .warn("Pro blem delet ing nonexi stant jobs ");
  584                    }
  585           }
  586  
  587           /* *
  588            *  Initializ e Quartz J ob Trigger s for the  specified  batch job  and job
  589            *  details.
  590            *  
  591            *  @param bj
  592            *              The batc h job for  which to u pdate the  scheduler.
  593            *  @param jo b
  594            *              The Quar tz job det ails for t he batch j ob.
  595            * /
  596           pr ivate void  initializ eTrigger(B atchJob bj , JobDetai l job) {
  597  
  598                    logg er.info("I nitializin g trigger  for job: "  + job.get Key().getN ame());
  599  
  600                    // H andle trig ger initia lization b ased on ty pe.
  601                    swit ch (bj.get BatchType( ).getJobTy pe()) {
  602                    case  DAILY: {
  603                             logger .info("DAI LY");
  604                             if (cr eateJob(jo b)) {
  605                                      setBatch Cron(bj);
  606                             }
  607                             break;
  608                    }
  609                    case  MANUAL: {
  610                             logger .info("MAN UAL");
  611                             if (cr eateJob(jo b)) {
  612                                      setBatch Manual(bj) ;
  613                             }
  614                             break;
  615                    }
  616                    case  SPECIFIED : {
  617                             logger .info("SPE CIFIED");
  618                             if (cr eateJob(jo b)) {
  619                                      setBatch Specified( bj);
  620                             }
  621                             break;
  622                    }
  623                    case  UNDEFINED : {
  624                             logger .error("Un able to in itialize t rigger for  UNDEFINED  job type:  "
  625                                               + validate StringInpu t(bj.getBa tchType(). getName(),  LOG_FORGI NG));
  626                             break;
  627                    }
  628                    defa ult: {
  629                             logger .error("Un able to in itialize t rigger for  unrecogni zed job ty pe: "
  630                                               + validate StringInpu t(bj.getBa tchType(). getName(),  LOG_FORGI NG));
  631                             break;
  632                    }
  633                    }
  634  
  635           }
  636  
  637           /* *
  638            *  Create th e Quartz J ob in the  scheduler  if it does  not alrea dy exist.
  639            *  
  640            *  @param jo b
  641            *              The job  to create.
  642            *  @return B oolean fla g that ind icates if  successful ly created  job or if  the
  643            *          j ob already  exists.
  644            * /
  645           pr ivate bool ean create Job(JobDet ail job) {
  646                    bool ean succes s = false;
  647                    try  {
  648                             if (!s cheduler.c heckExists (job.getKe y())) {
  649                                      schedule r.addJob(j ob, false) ;
  650                                      logger.i nfo("Job a dded to sc heduler: "  + job.get Key().getN ame());
  651                             } else  {
  652                                      logger.i nfo("Job e xists in s cheduler:  " + job.ge tKey().get Name());
  653                             }
  654                             succes s = true;
  655                    } ca tch (Sched ulerExcept ion e) {
  656                             logger .error("Un able to ad d job to s cheduler:  " + job.ge tKey().get Name() + " , e: " + e .getMessag e());
  657                    }
  658                    retu rn success ;
  659           }
  660  
  661           /* *
  662            *  Delete an y jobs for  the group  that is n ot in the  cpss batch  job table .
  663            *  
  664            *  @param na meL
  665            *              The list  of batch  jobs in th e cpss bat ch job tab le.
  666            * /
  667           pr ivate bool ean delete Nonexistan tJobs(fina l List<Str ing> nameL ) {
  668                    bool ean result  = false;
  669                    Grou pMatcher<J obKey> mat cher = Gro upMatcher. groupEqual s(jobGroup );
  670                    try  {
  671                             Set<Jo bKey> jobK eyS = sche duler.getJ obKeys(mat cher);
  672                             for (J obKey jobK ey : jobKe yS) {
  673                                      // If jo b not foun d then del ete it.
  674                                      if (!nam eL.contain s(jobKey.g etName()))  {
  675                                               logger.inf o("Deletin g old sche duled job  that was n ot in the  batch job  database t able: "
  676                                                                + jo bKey.getNa me());
  677                                               scheduler. deleteJob( jobKey);
  678                                      }
  679                             }
  680                             result  = true;
  681                    } ca tch (Sched ulerExcept ion e) {
  682                             logger .error("Er ror deleti ng nonexis tant jobs:  " + e.get Message()) ;
  683                    }
  684                    retu rn result;
  685           }
  686  
  687   }