1 package org.kuali.ole.batch.service;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.deliver.bo.OleBatchJobBo;
5 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
6 import org.kuali.rice.krad.service.KRADServiceLocator;
7 import org.quartz.JobDetail;
8 import org.quartz.impl.StdScheduler;
9 import org.springframework.scheduling.quartz.CronTriggerBean;
10
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14
15
16
17
18
19
20
21
22 public class OleBatchJobService {
23
24 private static final Logger LOG = Logger.getLogger(OleBatchJobService.class);
25 public OleBatchJobService(){
26 addAvailableJobsToScheduler();
27 }
28
29
30
31
32 public void addAvailableJobsToScheduler(){
33
34 Map<String,String> batchMap = new HashMap<String, String>();
35 batchMap.put("jobEnableStatus","true");
36 List<OleBatchJobBo> oleDeliverBatchJobBoList =(List<OleBatchJobBo>) KRADServiceLocator.getBusinessObjectService().findMatching(OleBatchJobBo.class,batchMap);
37 StdScheduler scheduler = (StdScheduler) GlobalResourceLoader.getService("scheduler");
38
39 if(oleDeliverBatchJobBoList.size()>0){
40 for(OleBatchJobBo oleDeliverBatchJobBo:oleDeliverBatchJobBoList){
41
42 try {
43 JobDetail jobDetail = (JobDetail) GlobalResourceLoader.getService(oleDeliverBatchJobBo.getJobTriggerName());
44 CronTriggerBean cronTriggerBean = new CronTriggerBean();
45 cronTriggerBean.setName(oleDeliverBatchJobBo.getJobTriggerName()+"Trigger");
46 cronTriggerBean.setCronExpression(oleDeliverBatchJobBo.getJobCronExpression());
47 cronTriggerBean.setJobName(jobDetail.getName());
48 cronTriggerBean.setJobGroup(jobDetail.getGroup());
49 cronTriggerBean.setJobDetail(jobDetail);
50 try{
51 scheduler.scheduleJob(jobDetail, cronTriggerBean);
52 LOG.info(jobDetail.getName()+" job is scheduled");
53 }
54 catch (Exception e){
55 scheduler.rescheduleJob(oleDeliverBatchJobBo.getJobTriggerName(),jobDetail.getName(),cronTriggerBean);
56 } } catch (Exception e) {
57 LOG.info(e.getMessage()+" : Unable to schedule the job");
58
59 }
60 }
61 }
62
63 }
64 }