1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging.web;
17
18 import org.apache.struts.action.ActionForm;
19 import org.apache.struts.action.ActionForward;
20 import org.apache.struts.action.ActionMapping;
21 import org.apache.struts.action.ActionMessages;
22 import org.kuali.rice.ksb.messaging.PersistedMessageBO;
23 import org.kuali.rice.ksb.messaging.quartz.MessageServiceExecutorJob;
24 import org.kuali.rice.ksb.service.KSBServiceLocator;
25 import org.kuali.rice.ksb.util.KSBConstants;
26 import org.quartz.JobDetail;
27 import org.quartz.Trigger;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import java.util.ArrayList;
32 import java.util.List;
33
34
35
36
37
38
39
40
41 public class QuartzQueueAction extends KSBAction {
42
43 private static final String RENDER_LIST_OVERRIDE = "_renderlistoverride";
44
45 @Override
46 public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm form) throws Exception {
47 if ("moveToRouteQueue".equals(request.getParameter("methodToCall")) && request.getAttribute(RENDER_LIST_OVERRIDE) == null) {
48 return null;
49 }
50
51 List<QuartzQueueForm> jobs = new ArrayList<QuartzQueueForm>();
52 String[] jobGroups = KSBServiceLocator.getScheduler().getJobGroupNames();
53 for (int i = 0; i < jobGroups.length; i++) {
54 String jobGroup = KSBServiceLocator.getScheduler().getJobGroupNames()[i];
55 String[] jobNames = KSBServiceLocator.getScheduler().getJobNames(jobGroup);
56 for (int j = 0; j < jobNames.length; j++) {
57 JobDetail job = KSBServiceLocator.getScheduler().getJobDetail(jobNames[j], jobGroup);
58 Trigger trigger = KSBServiceLocator.getScheduler().getTriggersOfJob(job.getName(), job.getGroup())[0];
59 jobs.add(new QuartzQueueForm(job, trigger));
60 }
61 }
62 request.setAttribute("jobs", jobs);
63 return null;
64 }
65
66 @Override
67 public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request,
68 HttpServletResponse response) throws Exception {
69 return mapping.findForward("joblisting");
70 }
71
72 public ActionForward moveToRouteQueue(ActionMapping mapping, ActionForm form, HttpServletRequest request,
73 HttpServletResponse response) throws Exception {
74
75 QuartzQueueForm quartzForm = (QuartzQueueForm)form;
76
77 JobDetail job = KSBServiceLocator.getScheduler().getJobDetail(quartzForm.getJobName(), quartzForm.getJobGroup());
78 PersistedMessageBO message = (PersistedMessageBO)job.getJobDataMap().get(MessageServiceExecutorJob.MESSAGE_KEY);
79 if(message != null){
80 message.setQueueStatus(KSBConstants.ROUTE_QUEUE_EXCEPTION);
81
82 KSBServiceLocator.getMessageQueueService().save(message);
83 KSBServiceLocator.getScheduler().deleteJob(quartzForm.getJobName(), quartzForm.getJobGroup());
84 }
85 request.setAttribute(RENDER_LIST_OVERRIDE, new Object());
86 establishRequiredState(request, form);
87 return mapping.findForward("joblisting");
88 }
89
90
91 }