View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * action to view messages in quartz and push them into the message queue. 
37   * 
38   * @author Kuali Rice Team (rice.collab@kuali.org)
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  	message.setQueueStatus(KSBConstants.ROUTE_QUEUE_EXCEPTION);
80  	
81  	KSBServiceLocator.getMessageQueueService().save(message);
82  	KSBServiceLocator.getScheduler().deleteJob(quartzForm.getJobName(), quartzForm.getJobGroup());
83  	request.setAttribute(RENDER_LIST_OVERRIDE, new Object());
84  	establishRequiredState(request, form);
85  	return mapping.findForward("joblisting");
86      }
87      
88      
89  }