View Javadoc
1   package org.kuali.ole.batch.controller;
2   
3   import org.apache.commons.io.IOUtils;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.OLEPropertyConstants;
6   import org.kuali.ole.batch.bo.OLEBatchProcessJobDetailsBo;
7   import org.kuali.ole.batch.bo.OLEBatchProcessScheduleBo;
8   import org.kuali.ole.batch.document.OLEBatchProcessDefinitionDocument;
9   import org.kuali.ole.batch.form.OLEBatchProcessJobDetailsForm;
10  import org.kuali.ole.batch.helper.OLEBatchProcessDataHelper;
11  import org.kuali.ole.batch.service.OLEBatchSchedulerService;
12  import org.kuali.ole.sys.batch.BatchFile;
13  import org.kuali.ole.sys.batch.BatchFileUtils;
14  import org.kuali.rice.core.api.config.property.ConfigContext;
15  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
16  import org.kuali.rice.krad.service.BusinessObjectService;
17  import org.kuali.rice.krad.service.KRADServiceLocator;
18  import org.kuali.rice.krad.uif.UifConstants;
19  import org.kuali.rice.krad.uif.UifParameters;
20  import org.kuali.rice.krad.util.GlobalVariables;
21  import org.kuali.rice.krad.web.controller.TransactionalDocumentControllerBase;
22  import org.kuali.rice.krad.web.form.UifFormBase;
23  import org.quartz.CronExpression;
24  import org.springframework.stereotype.Controller;
25  import org.springframework.validation.BindingResult;
26  import org.springframework.web.bind.annotation.ModelAttribute;
27  import org.springframework.web.bind.annotation.RequestMapping;
28  import org.springframework.web.servlet.ModelAndView;
29  
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.http.HttpServletResponse;
32  import java.io.File;
33  import java.io.FileInputStream;
34  import java.io.InputStream;
35  import java.sql.Timestamp;
36  import java.text.ParseException;
37  import java.text.SimpleDateFormat;
38  import java.util.*;
39  
40  /**
41   * Created with IntelliJ IDEA.
42   * User: krishnamohanv
43   * Date: 7/12/13
44   * Time: 5:06 PM
45   * To change this template use File | Settings | File Templates.
46   */
47  
48  
49  @Controller
50  @RequestMapping(value = "/oleBatchProcessJobController")
51  public class OLEBatchProcessJobDetailsController extends TransactionalDocumentControllerBase {
52  
53      private OLEBatchProcessDataHelper oleBatchProcessDataHelper;
54      private BusinessObjectService businessObjectService;
55      private OLEBatchSchedulerService schedulerService;
56      private static HashMap<String, String> batchProcessJobStatusMap = new HashMap<String, String>();
57  
58      public OLEBatchSchedulerService getSchedulerService() {
59          if (schedulerService == null) {
60              schedulerService = GlobalResourceLoader.getService("oleSchedulerService");
61          }
62          return schedulerService;
63      }
64  
65      public BusinessObjectService getBusinessObjectService() {
66          if (businessObjectService == null)
67              businessObjectService = KRADServiceLocator.getBusinessObjectService();
68          return businessObjectService;
69      }
70  
71      private OLEBatchProcessDataHelper getOLEBatchProcessDataHelper() {
72  
73          if (oleBatchProcessDataHelper == null) {
74              oleBatchProcessDataHelper = OLEBatchProcessDataHelper.getInstance();
75          }
76          return oleBatchProcessDataHelper;
77      }
78  
79      @Override
80      protected OLEBatchProcessJobDetailsForm createInitialForm(HttpServletRequest request) {
81          OLEBatchProcessJobDetailsForm oleBatchProcessJobDetailsForm = new OLEBatchProcessJobDetailsForm();
82          GlobalVariables.getUserSession().addObject("formId", oleBatchProcessJobDetailsForm.getFormKey());
83          return oleBatchProcessJobDetailsForm;
84      }
85  
86      @RequestMapping(params = "methodToCall=stopButton")
87      public ModelAndView stopButton(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
88                                     HttpServletRequest request, HttpServletResponse response) throws Exception {
89          OLEBatchProcessJobDetailsForm oLEBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
90          OLEBatchProcessJobDetailsBo jobDetailsBo = getJobBo(oLEBatchProcessJobDetailsForm);
91          batchProcessJobStatusMap.put(jobDetailsBo.getJobId(), OLEConstants.OLEBatchProcess.JOB_STATUS_STOPPED);
92          return getUIFModelAndView(oLEBatchProcessJobDetailsForm);
93      }
94  
95      @RequestMapping(params = "methodToCall=startButton")
96      public ModelAndView restartButton(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
97                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
98          OLEBatchProcessJobDetailsForm oLEBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
99          OLEBatchProcessJobDetailsBo jobDetailsBo = getJobBo(oLEBatchProcessJobDetailsForm);
100         jobDetailsBo.setStatus(OLEConstants.OLEBatchProcess.JOB_STATUS_RUNNING);
101         getBusinessObjectService().save(jobDetailsBo);
102         List<OLEBatchProcessJobDetailsBo> oleBatchProcessJobDetailsBoList = (List<OLEBatchProcessJobDetailsBo>) getBusinessObjectService().findAllOrderBy(OLEBatchProcessJobDetailsBo.class,"jobId",false);
103         oLEBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBoList(oleBatchProcessJobDetailsBoList);
104         getSchedulerService().startJob(jobDetailsBo.getJobId());
105         return getUIFModelAndView(oLEBatchProcessJobDetailsForm);
106     }
107 
108     @RequestMapping(params = "methodToCall=resumeButton")
109     public ModelAndView resumeButton(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
110                                      HttpServletRequest request, HttpServletResponse response) throws Exception {
111         OLEBatchProcessJobDetailsForm oLEBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
112         OLEBatchProcessJobDetailsBo jobDetailsBo = getJobBo(oLEBatchProcessJobDetailsForm);
113         if (jobDetailsBo.getPerCompleted().equalsIgnoreCase(String.format("%.2f", Float.valueOf(100)) + "%")) {
114             jobDetailsBo.setStatus(OLEConstants.OLEBatchProcess.JOB_STATUS_COMPLETED);
115         } else {
116             jobDetailsBo.setStatus(OLEConstants.OLEBatchProcess.JOB_STATUS_RUNNING);
117             getSchedulerService().resumeJob(jobDetailsBo.getJobId());
118         }
119         getBusinessObjectService().save(jobDetailsBo);
120        /* List<OLEBatchProcessJobDetailsBo> oleBatchProcessJobDetailsBoList = (List<OLEBatchProcessJobDetailsBo>) getBusinessObjectService().findAllOrderBy(OLEBatchProcessJobDetailsBo.class,"jobId",false);
121         oLEBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBoList(oleBatchProcessJobDetailsBoList);*/
122         for(OLEBatchProcessJobDetailsBo oleBatchProcessJobDetailsBo:oLEBatchProcessJobDetailsForm.getOleBatchProcessJobDetailsBoList()){
123             if(oleBatchProcessJobDetailsBo.getJobId().equals(jobDetailsBo.getJobId())){
124                 oleBatchProcessJobDetailsBo.setStatus(jobDetailsBo.getStatus());
125                 break;
126             }
127         }
128         return getUIFModelAndView(oLEBatchProcessJobDetailsForm);
129     }
130 
131     @RequestMapping(params = "methodToCall=removeButton")
132     public ModelAndView removeButton(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
133                                      HttpServletRequest request, HttpServletResponse response) throws Exception {
134         OLEBatchProcessJobDetailsForm oLEBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
135         OLEBatchProcessJobDetailsBo jobDetailsBo = getJobBo(oLEBatchProcessJobDetailsForm);
136         getOLEBatchProcessDataHelper().deleteBatchFailureFile(jobDetailsBo.getBatchProcessType(), jobDetailsBo.getJobId() + "_FailureRecord" + "_" + jobDetailsBo.getUploadFileName());
137         jobDetailsBo.setStatus(OLEConstants.OLEBatchProcess.JOB_STATUS_CANCELLED);
138         getBusinessObjectService().save(jobDetailsBo);
139         /*List<OLEBatchProcessJobDetailsBo> oleBatchProcessJobDetailsBoList = (List<OLEBatchProcessJobDetailsBo>) getBusinessObjectService().findAllOrderBy(OLEBatchProcessJobDetailsBo.class,"jobId",false);
140         oLEBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBoList(oleBatchProcessJobDetailsBoList);*/
141         for(OLEBatchProcessJobDetailsBo oleBatchProcessJobDetailsBo:oLEBatchProcessJobDetailsForm.getOleBatchProcessJobDetailsBoList()){
142             if(oleBatchProcessJobDetailsBo.getJobId().equals(jobDetailsBo.getJobId())){
143                 oleBatchProcessJobDetailsBo.setStatus(jobDetailsBo.getStatus());
144                 break;
145             }
146         }
147         getSchedulerService().deleteJob(jobDetailsBo.getJobId());
148         return getUIFModelAndView(oLEBatchProcessJobDetailsForm);
149     }
150 
151     @RequestMapping(params = "methodToCall=pauseButton")
152     public ModelAndView pauseButton(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
153                                     HttpServletRequest request, HttpServletResponse response) throws Exception {
154         OLEBatchProcessJobDetailsForm oLEBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
155         OLEBatchProcessJobDetailsBo jobDetailsBo = getJobBo(oLEBatchProcessJobDetailsForm);
156         if (jobDetailsBo.getPerCompleted().equalsIgnoreCase(String.format("%.2f", Float.valueOf(100)) + "%")) {
157             jobDetailsBo.setStatus(OLEConstants.OLEBatchProcess.JOB_STATUS_COMPLETED);
158         } else {
159             jobDetailsBo.setStatus(OLEConstants.OLEBatchProcess.JOB_STATUS_PAUSED);
160             getSchedulerService().pauseJob(jobDetailsBo.getJobId());
161         }
162         getBusinessObjectService().save(jobDetailsBo);
163         /*List<OLEBatchProcessJobDetailsBo> oleBatchProcessJobDetailsBoList = (List<OLEBatchProcessJobDetailsBo>) getBusinessObjectService().findAllOrderBy(OLEBatchProcessJobDetailsBo.class,"jobId",false);
164         oLEBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBoList(oleBatchProcessJobDetailsBoList);*/
165         for(OLEBatchProcessJobDetailsBo oleBatchProcessJobDetailsBo:oLEBatchProcessJobDetailsForm.getOleBatchProcessJobDetailsBoList()){
166             if(oleBatchProcessJobDetailsBo.getJobId().equals(jobDetailsBo.getJobId())){
167                 oleBatchProcessJobDetailsBo.setStatus(jobDetailsBo.getStatus());
168                 break;
169             }
170         }
171         return getUIFModelAndView(oLEBatchProcessJobDetailsForm);
172     }
173 
174     @RequestMapping(params = "methodToCall=openViewReport")
175     public ModelAndView openViewReport(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
176                                        HttpServletRequest request, HttpServletResponse response) {
177         OLEBatchProcessJobDetailsForm oLEBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
178         OLEBatchProcessJobDetailsBo jobDetailsBo = getJobBo(oLEBatchProcessJobDetailsForm);
179         if (jobDetailsBo.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_EXPORT)) {
180             jobDetailsBo.setUploadFileName(getOLEBatchProcessDataHelper().getExportPathUrl(jobDetailsBo));
181         } else if (jobDetailsBo.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_BIB_IMPORT)) {
182             jobDetailsBo.setBibErrorPath(getOLEBatchProcessDataHelper().getBibPathUrl(jobDetailsBo));
183         } else if (jobDetailsBo.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_DELETE)) {
184             jobDetailsBo.setBatchDeletePath(getOLEBatchProcessDataHelper().getDeletePathUrl(jobDetailsBo));
185         } else if (jobDetailsBo.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.SERIAL_RECORD_IMPORT)) {
186             jobDetailsBo.setSerialCSVErrorPath(getOLEBatchProcessDataHelper().getSerialCSVPathUrl(jobDetailsBo));
187         }
188         List<OLEBatchProcessJobDetailsBo> oleBatchProcessJobDetailsBoList = (List<OLEBatchProcessJobDetailsBo>) getBusinessObjectService().findAllOrderBy(OLEBatchProcessJobDetailsBo.class,"jobId",false);
189         oLEBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBoList(oleBatchProcessJobDetailsBoList);
190         oLEBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBo(jobDetailsBo);
191 
192         return getUIFModelAndView(oLEBatchProcessJobDetailsForm);
193     }
194 
195     @RequestMapping(params = "methodToCall=downLoadFile")
196     public ModelAndView downLoadFile(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
197                                      HttpServletRequest request, HttpServletResponse response) throws Exception {
198 
199         OLEBatchProcessJobDetailsForm oleBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
200 
201         OLEBatchProcessJobDetailsBo jobDetailsBo = getJobBo(oleBatchProcessJobDetailsForm);
202         if (jobDetailsBo != null) {
203             Map map = new HashMap();
204             map.put("batchProcessId", jobDetailsBo.getBatchProcessId());
205             List<OLEBatchProcessDefinitionDocument> oleBatchProcessDefinitionDocumentList = (List<OLEBatchProcessDefinitionDocument>) getBusinessObjectService().findMatching(OLEBatchProcessDefinitionDocument.class, map);
206             if (oleBatchProcessDefinitionDocumentList != null && oleBatchProcessDefinitionDocumentList.size() > 0) {
207                 OLEBatchProcessDefinitionDocument oleBatchProcessDefinitionDocument = oleBatchProcessDefinitionDocumentList.get(0);
208                 File file = null;
209                 if (oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_EXPORT)) {
210                     file = new File(getBatchProcessFilePath(oleBatchProcessDefinitionDocument.getBatchProcessType() , jobDetailsBo.getJobId()) + jobDetailsBo.getJobId() + OLEConstants.OLEBatchProcess.DELETED_BIB_IDS_FILE_NAME);
211                 } else {
212                     file = new File(getBatchProcessFilePath(oleBatchProcessDefinitionDocument.getBatchProcessType() , jobDetailsBo.getJobId()) + jobDetailsBo.getJobId() + "_FailureRecord" + "_" + jobDetailsBo.getUploadFileName());
213                 }
214                 if (!file.exists() || !file.isFile()) {
215                     throw new RuntimeException("Error: non-existent file or directory provided");
216                 }
217                 File containingDirectory = file.getParentFile();
218                 if (!BatchFileUtils.isDirectoryAccessible(containingDirectory.getAbsolutePath())) {
219                     throw new RuntimeException("Error: inaccessible directory provided");
220                 }
221 
222                 BatchFile batchFile = new BatchFile();
223                 batchFile.setFile(file);
224                 response.setContentType("application/octet-stream");
225                 response.setHeader("Content-disposition", "attachment; filename=" + file.getName());
226                 response.setHeader("Expires", "0");
227                 response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
228                 response.setHeader("Pragma", "public");
229                 response.setContentLength((int) file.length());
230 
231                 InputStream fis = new FileInputStream(file);
232                 IOUtils.copy(fis, response.getOutputStream());
233                 response.getOutputStream().flush();
234             }
235         }
236         return null;
237     }
238 
239     @RequestMapping(params = "methodToCall=downLoadErrorAttachmentFile")
240     public ModelAndView downLoadErrorAttachmentFile(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
241                                      HttpServletRequest request, HttpServletResponse response) throws Exception {
242         OLEBatchProcessJobDetailsForm oleBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
243         OLEBatchProcessJobDetailsBo jobDetailsBo = getJobBo(oleBatchProcessJobDetailsForm);
244         if (jobDetailsBo != null) {
245             Map map = new HashMap();
246             map.put("batchProcessId", jobDetailsBo.getBatchProcessId());
247             List<OLEBatchProcessDefinitionDocument> oleBatchProcessDefinitionDocumentList = (List<OLEBatchProcessDefinitionDocument>) getBusinessObjectService().findMatching(OLEBatchProcessDefinitionDocument.class, map);
248             if (oleBatchProcessDefinitionDocumentList != null && oleBatchProcessDefinitionDocumentList.size() > 0) {
249                 OLEBatchProcessDefinitionDocument oleBatchProcessDefinitionDocument = oleBatchProcessDefinitionDocumentList.get(0);
250                 String uploadFileName = jobDetailsBo.getUploadFileName();
251                 String errorFileName = null;
252                 String[] fileNames = uploadFileName.split(",");
253                 errorFileName = fileNames.length == 2 ? fileNames[0]:uploadFileName;
254                 if(errorFileName.endsWith(".mrc")){
255                     errorFileName = errorFileName.replace(".mrc",".txt");
256                 }
257                 else if(errorFileName.endsWith(".INV")){
258                     errorFileName = errorFileName.replace(".INV",".txt");
259                 }
260                 else if(errorFileName.endsWith(".edi")){
261                     errorFileName = errorFileName.replace(".edi",".txt");
262                 }
263                 File file = new File(getBatchProcessFilePath(oleBatchProcessDefinitionDocument.getBatchProcessType() , jobDetailsBo.getJobId()) + jobDetailsBo.getJobId() + "_FailureRecord" + "_" + errorFileName);
264                 if (!file.exists() || !file.isFile()) {
265                     throw new RuntimeException("Error: non-existent file or directory provided");
266                 }
267                 File containingDirectory = file.getParentFile();
268                 if (!BatchFileUtils.isDirectoryAccessible(containingDirectory.getAbsolutePath())) {
269                     throw new RuntimeException("Error: inaccessible directory provided");
270                 }
271                 BatchFile batchFile = new BatchFile();
272                 batchFile.setFile(file);
273                 response.setContentType("application/octet-stream");
274                 response.setHeader("Content-disposition", "attachment; filename=" + file.getName());
275                 response.setHeader("Expires", "0");
276                 response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
277                 response.setHeader("Pragma", "public");
278                 response.setContentLength((int) file.length());
279 
280                 InputStream fis = new FileInputStream(file);
281                 IOUtils.copy(fis, response.getOutputStream());
282                 response.getOutputStream().flush();
283             }
284         }
285         return null;
286     }
287 
288     @RequestMapping(params = "methodToCall=jobDocHandler")
289     public ModelAndView jobDocHandler(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
290                                       HttpServletRequest request, HttpServletResponse response) throws Exception {
291         OLEBatchProcessJobDetailsForm oleBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
292         ModelAndView modelAndView = super.docHandler(oleBatchProcessJobDetailsForm, result, request, response);
293         String documentClass = request.getParameter("documentClass");
294         if (documentClass != null && OLEBatchProcessScheduleBo.class.toString().contains(documentClass)) {
295             List<OLEBatchProcessScheduleBo> oleBatchProcessScheduleBoList = (List<OLEBatchProcessScheduleBo>) getBusinessObjectService().findAll(OLEBatchProcessScheduleBo.class);
296             for (OLEBatchProcessScheduleBo oleBatchProcessScheduleBo : oleBatchProcessScheduleBoList) {
297                 oleBatchProcessScheduleBo.setBatchProfileName(getBatchProcessDocument(oleBatchProcessScheduleBo.getBatchProcessId()).getBatchProcessProfileName());
298             }
299             oleBatchProcessJobDetailsForm.setOleBatchProcessScheduleBoList(oleBatchProcessScheduleBoList);
300             oneTimeDate(oleBatchProcessScheduleBoList);
301         } else {
302             List<OLEBatchProcessJobDetailsBo> oLEBatchProcessJobDetailsBoList = (List<OLEBatchProcessJobDetailsBo>) getBusinessObjectService().findAllOrderBy(OLEBatchProcessJobDetailsBo.class,"jobId",false);
303             oleBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBoList(oLEBatchProcessJobDetailsBoList);
304         }
305         return modelAndView;
306     }
307 
308     private OLEBatchProcessDefinitionDocument getBatchProcessDocument(String batchProcessId) {
309         Map map = new HashMap();
310         map.put("batchProcessId", batchProcessId);
311         OLEBatchProcessDefinitionDocument batchProcessDefinitionDocument = getBusinessObjectService().findByPrimaryKey(OLEBatchProcessDefinitionDocument.class, map);
312         return batchProcessDefinitionDocument;
313     }
314 
315     private String getBatchProcessFilePath(String batchProceesType , String jobId) {
316         String batchProcessLocation = getOLEBatchProcessDataHelper().getBatchProcessFilePath(batchProceesType , jobId);
317         return batchProcessLocation;
318     }
319 
320     /**
321      * Runs the process for the profile selected and takes the scheduled record id as the job name
322      * @param jobName
323      */
324     private void runJobNow(String jobName) {
325         OLEBatchSchedulerService schedulerService = GlobalResourceLoader.getService("oleSchedulerService");
326         try {
327             schedulerService.startJob(jobName);
328         } catch (Exception e) {
329             LOG.error("Error while starting job with job id :: " + jobName);
330         }
331     }
332 
333     private void oneTimeDate(List<OLEBatchProcessScheduleBo> oleBatchProcessScheduleBoList) {
334 
335         try {
336             for (OLEBatchProcessScheduleBo oleBatchProcessScheduleBo : oleBatchProcessScheduleBoList) {
337                 CronExpression exp = new CronExpression(oleBatchProcessScheduleBo.getCronExpression());
338                 Date date = exp.getNextValidTimeAfter(new Date());
339                 if (date != null) {
340                     SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
341                     Timestamp nextRunTime = new Timestamp(date.getTime());
342                     oleBatchProcessScheduleBo.setNextRunTime(nextRunTime);
343                 }
344             }
345         } catch (ParseException e) {
346             LOG.error("Error while validating cron exp::" + oleBatchProcessScheduleBoList.get(0).getCronExpression(), e);
347         }
348 
349 
350     }
351 
352     @RequestMapping(params = "methodToCall=removeScheduleJob")
353     public ModelAndView removeScheduleJob(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
354                                           HttpServletRequest request, HttpServletResponse response) throws Exception {
355         OLEBatchProcessJobDetailsForm oleBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
356         Map map = new HashMap();
357         map.put("scheduleId", request.getParameter("scheduleId"));
358         OLEBatchProcessScheduleBo scheduleBo = getBusinessObjectService().findByPrimaryKey(OLEBatchProcessScheduleBo.class, map);
359         getOLEBatchProcessDataHelper().deleteBatchFailureFile(scheduleBo.getBatchProcessType(), scheduleBo.getScheduleId() + "_Scheduled" + "_" + scheduleBo.getUploadFileName());
360         getBusinessObjectService().delete(scheduleBo);
361         removeJob(scheduleBo.getScheduleId());
362         List<OLEBatchProcessScheduleBo> oleBatchProcessScheduleBoList = (List<OLEBatchProcessScheduleBo>) getBusinessObjectService().findAll(OLEBatchProcessScheduleBo.class);
363         oleBatchProcessJobDetailsForm.setOleBatchProcessScheduleBoList(oleBatchProcessScheduleBoList);
364         return getUIFModelAndView(oleBatchProcessJobDetailsForm);
365     }
366 
367     private void removeJob(String jobName) {
368         OLEBatchSchedulerService schedulerService = GlobalResourceLoader.getService("oleSchedulerService");
369         try {
370             schedulerService.deleteJob(jobName);
371         } catch (Exception e) {
372             LOG.error("Error while removing job with schedule id :: " + jobName);
373         }
374     }
375 
376     private OLEBatchProcessJobDetailsBo getJobBo(OLEBatchProcessJobDetailsForm oleBatchProcessJobDetailsForm) {
377         Map map = new HashMap();
378         map.put("jobId", oleBatchProcessJobDetailsForm.getJobId());
379         OLEBatchProcessJobDetailsBo jobDetailsBo = getBusinessObjectService().findByPrimaryKey(OLEBatchProcessJobDetailsBo.class, map);
380         return jobDetailsBo;
381     }
382 
383     public static HashMap<String, String> getBatchProcessJobStatusMap() {
384         return batchProcessJobStatusMap;
385     }
386 
387     public static void setBatchProcessJobStatusMap(String jobId, String jobStatus) {
388         batchProcessJobStatusMap.put(jobId, jobStatus);
389     }
390 
391     public static void removeStatusFromBatchProcess(String jobId) {
392         if (getBatchProcessJobStatusMap() != null)
393             batchProcessJobStatusMap.remove(jobId);
394     }
395 
396     public static String getBatchProcessJobStatus(String jobId) {
397         String jobStatus = null;
398         if (getBatchProcessJobStatusMap() != null) {
399             jobStatus = batchProcessJobStatusMap.get(jobId);
400             if (jobStatus != null)
401                 return jobStatus;
402             else {
403                 return OLEConstants.OLEBatchProcess.JOB_STATUS_RUNNING;
404             }
405         } else {
406             return OLEConstants.OLEBatchProcess.JOB_STATUS_RUNNING;
407         }
408     }
409 
410     @RequestMapping(params = "methodToCall=search")
411     public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
412                                HttpServletRequest request, HttpServletResponse response) throws Exception {
413         LOG.debug("Entering Batch process job details search");
414         boolean checkFromDate = false;
415         boolean checkToDate = false;
416         OLEBatchProcessJobDetailsForm oleBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
417         oleBatchProcessJobDetailsForm.setSingleJobView(false);
418         if (oleBatchProcessJobDetailsForm.getJobFromDate() != null) {
419             checkFromDate = true;
420         }
421         if (oleBatchProcessJobDetailsForm.getJobToDate() != null) {
422             checkToDate = true;
423         }
424         oleBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBoList(null);
425         List<OLEBatchProcessJobDetailsBo> oLEBatchProcessJobDetailsBoList = (List<OLEBatchProcessJobDetailsBo>) getBusinessObjectService().findAllOrderBy(OLEBatchProcessJobDetailsBo.class, "jobId", false);
426         if (!checkFromDate && !checkToDate) {
427             oleBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBoList(oLEBatchProcessJobDetailsBoList);
428         } else {
429             List<OLEBatchProcessJobDetailsBo> resultList = new ArrayList<>();
430             for (OLEBatchProcessJobDetailsBo oleBatchProcessJobDetailsBo : oLEBatchProcessJobDetailsBoList) {
431                 Date fromDate = oleBatchProcessJobDetailsBo.getCreateTime();
432                 if (checkFromDate && checkToDate) {
433                     Date searchFromDate = oleBatchProcessJobDetailsForm.getJobFromDate();
434                     int subtract = 1;
435                     Calendar calendar = GregorianCalendar.getInstance();
436                     calendar.setTime(oleBatchProcessJobDetailsForm.getJobToDate());
437                     calendar.add(Calendar.DAY_OF_YEAR, subtract);
438                     Date searchToDate = calendar.getTime();
439                     if (fromDate.after(searchFromDate) && fromDate.before(searchToDate)) {
440                         resultList.add(oleBatchProcessJobDetailsBo);
441                     }
442                 } else if (checkFromDate) {
443                     Date searchFromDate = oleBatchProcessJobDetailsForm.getJobFromDate();
444                     if (fromDate.after(searchFromDate)) {
445                         resultList.add(oleBatchProcessJobDetailsBo);
446                     }
447                 } else if (checkToDate) {
448                     int subtract = 1;
449                     Calendar calendar = GregorianCalendar.getInstance();
450                     calendar.setTime(oleBatchProcessJobDetailsForm.getJobToDate());
451                     calendar.add(Calendar.DAY_OF_YEAR, subtract);
452                     Date searchToDate = calendar.getTime();
453                     if (fromDate.before(searchToDate)) {
454                         resultList.add(oleBatchProcessJobDetailsBo);
455                     }
456                 }
457             }
458             oleBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBoList(resultList);
459         }
460 
461         LOG.debug("Leaving Batch process job details search");
462         return getUIFModelAndView(oleBatchProcessJobDetailsForm);
463     }
464 
465     @RequestMapping(params = "methodToCall=clearSearch")
466     public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
467                                     HttpServletRequest request, HttpServletResponse response) {
468         LOG.debug("Entering Batch process job details search");
469         OLEBatchProcessJobDetailsForm oleBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
470         oleBatchProcessJobDetailsForm.setJobFromDate(null);
471         oleBatchProcessJobDetailsForm.setJobToDate(null);
472         LOG.debug("Leaving Batch process job details search");
473         return getUIFModelAndView(oleBatchProcessJobDetailsForm);
474     }
475 
476     @RequestMapping(params = "methodToCall=cancel")
477     public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
478                                HttpServletRequest request, HttpServletResponse response) {
479         String baseUrl = ConfigContext.getCurrentContextConfig().getProperty(OLEPropertyConstants.OLE_URL_BASE);
480         String url = baseUrl + "/portal.do";
481         Properties props = new Properties();
482         props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH);
483         if (org.apache.commons.lang.StringUtils.isNotBlank(form.getReturnFormKey())) {
484             props.put(UifParameters.FORM_KEY, form.getReturnFormKey());
485         }
486         return performRedirect(form, url, props);
487     }
488 
489     @RequestMapping(params = "methodToCall=singleJobDetailView")
490     public ModelAndView singleJobDetailView(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
491                                       HttpServletRequest request, HttpServletResponse response) throws Exception {
492         OLEBatchProcessJobDetailsForm oleBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
493         oleBatchProcessJobDetailsForm.setSingleJobView(true);
494         ModelAndView modelAndView = super.docHandler(oleBatchProcessJobDetailsForm, result, request, response);
495         Map<String,String> parameterMap = new HashMap<>();
496         parameterMap.put("batchProcessId",request.getParameter("batchProcessId"));
497         List<OLEBatchProcessJobDetailsBo> oLEBatchProcessJobDetailsBoList = (List<OLEBatchProcessJobDetailsBo>) getBusinessObjectService().findMatching(OLEBatchProcessJobDetailsBo.class,parameterMap);
498         oleBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBoList(oLEBatchProcessJobDetailsBoList);
499         return modelAndView;
500     }
501 
502     @RequestMapping(params = "methodToCall=refreshSingleJobDetailView")
503     public ModelAndView refreshSingleJobDetailView(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
504                                             HttpServletRequest request, HttpServletResponse response) throws Exception {
505         OLEBatchProcessJobDetailsForm oleBatchProcessJobDetailsForm = (OLEBatchProcessJobDetailsForm) form;
506         oleBatchProcessJobDetailsForm.setSingleJobView(true);
507         Map<String,String> parameterMap = new HashMap<>();
508         parameterMap.put("jobId",oleBatchProcessJobDetailsForm.getJobId());
509         List<OLEBatchProcessJobDetailsBo> oLEBatchProcessJobDetailsBoList = (List<OLEBatchProcessJobDetailsBo>) getBusinessObjectService().findMatching(OLEBatchProcessJobDetailsBo.class,parameterMap);
510         oleBatchProcessJobDetailsForm.setOleBatchProcessJobDetailsBoList(oLEBatchProcessJobDetailsBoList);
511         return getUIFModelAndView(oleBatchProcessJobDetailsForm);
512     }
513 }