1 package org.kuali.ole.batch.impl;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.batch.bo.OLEBatchProcessJobDetailsBo;
7 import org.kuali.ole.batch.document.OLEBatchProcessDefinitionDocument;
8 import org.kuali.ole.sys.batch.AbstractStep;
9 import org.kuali.ole.sys.batch.service.SchedulerService;
10 import org.kuali.rice.krad.service.KRADServiceLocator;
11
12 import java.util.Date;
13 import java.util.HashMap;
14 import java.util.Map;
15
16
17
18
19
20
21
22
23 public class OLEBatchProcessAdhocStep extends AbstractStep {
24 private static final Logger LOG = Logger.getLogger(OLEBatchProcessAdhocStep.class);
25
26 @Override
27 public boolean execute(String jobName, Date jobRunDate) throws InterruptedException {
28 String jobId = StringUtils.substringAfter(jobName, SchedulerService.SCHEDULED_GROUP + "." + OLEConstants.OLEBatchProcess.ADHOC_BATCH_JOB);
29 if (StringUtils.isEmpty(jobId)) return true;
30 return executeBatch(jobId);
31 }
32
33
34
35
36
37
38
39
40
41
42 private boolean executeBatch(String jobName) {
43 try {
44 OLEBatchProcessJobDetailsBo jobBo = readJobRecord(jobName);
45 Map<String, String> prcsMap = new HashMap<String, String>();
46 prcsMap.put("bat_prcs_id", jobBo.getBatchProcessId());
47 OLEBatchProcessDefinitionDocument processDef = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEBatchProcessDefinitionDocument.class, prcsMap);
48 LOG.info("Executing Batch process type :: " + jobBo.getBatchProcessType());
49 OLEBatchProcess process = BatchProcessFactory.createProcess(jobBo.getBatchProcessType());
50 process.process(processDef, jobBo);
51 } catch (Exception e) {
52 LOG.error("Error while running Batch Process Step::OLEBatchProcessAdhocStep", e);
53
54 }
55 return true;
56 }
57
58
59
60
61
62
63
64 private OLEBatchProcessJobDetailsBo readJobRecord(String jobId) {
65 try {
66 Thread.sleep(2000);
67 } catch (InterruptedException e) {
68 LOG.error("Error while running Batch Process Step::", e);
69 }
70 Map<String, String> jobMap = new HashMap<String, String>();
71 jobMap.put("job_id", jobId);
72 OLEBatchProcessJobDetailsBo jobDetailsBo = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEBatchProcessJobDetailsBo.class, jobMap);
73 return jobDetailsBo;
74
75
76
77 }
78 }