001: /**********************************************************************************
002: * $URL$
003: * $Id$
004: **********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005 The Regents of the University of Michigan, Trustees of Indiana University,
007: * Board of Trustees of the Leland Stanford, Jr., University, and The MIT Corporation
008: *
009: * Licensed under the Educational Community License Version 1.0 (the "License");
010: * By obtaining, using and/or copying this Original Work, you agree that you have read,
011: * understand, and will comply with the terms and conditions of the Educational Community License.
012: * You may obtain a copy of the License at:
013: *
014: * http://cvs.sakaiproject.org/licenses/license_1_0.html
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
017: * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
018: * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
019: * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
020: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
021: *
022: **********************************************************************************/package org.sakaiproject.component.app.scheduler;
023:
024: import java.util.ArrayList;
025: import java.util.Calendar;
026: import java.util.Date;
027: import java.util.Iterator;
028: import java.util.List;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.quartz.JobExecutionContext;
033: import org.quartz.Trigger;
034: import org.quartz.TriggerListener;
035:
036: public class GlobalTriggerListener implements TriggerListener {
037:
038: private List triggerEvents = new ArrayList();
039: private List todaysTriggerEvents = new ArrayList();
040: private boolean isViewAllSelected = false;
041:
042: private static final Log LOG = LogFactory
043: .getLog(GlobalTriggerListener.class);
044:
045: public String getName() {
046: return "GlobalTriggerListener";
047: }
048:
049: public void triggerFired(Trigger trigger,
050: JobExecutionContext jobExecutionContext) {
051: TriggerEvent te = new TriggerEvent();
052: te.setEventType(TriggerEvent.TRIGGER_FIRED);
053: te.setJobName(jobExecutionContext.getJobDetail().getName());
054: te.setTime(new Date());
055: triggerEvents.add(0, te);
056: }
057:
058: public boolean vetoJobExecution(Trigger trigger,
059: JobExecutionContext jobExecutionContext) {
060: return false;
061: }
062:
063: public void triggerMisfired(Trigger trigger) {
064: }
065:
066: public void triggerComplete(Trigger trigger,
067: JobExecutionContext jobExecutionContext,
068: int triggerInstructionCode) {
069: TriggerEvent te = new TriggerEvent();
070: te.setEventType(TriggerEvent.TRIGGER_COMPLETE);
071: te.setJobName(jobExecutionContext.getJobDetail().getName());
072: te.setTime(new Date());
073: triggerEvents.add(0, te);
074: }
075:
076: /**
077: * @return Returns the triggerEvents.
078: */
079: public List getTriggerEvents() {
080: if (isViewAllSelected) {
081: return triggerEvents;
082: } else {
083: todaysTriggerEvents = new ArrayList();
084: Calendar cal = Calendar.getInstance();
085: cal.set(Calendar.HOUR_OF_DAY, 0);
086: cal.set(Calendar.MINUTE, 0);
087: cal.set(Calendar.SECOND, 0);
088:
089: Date midnightToday = new Date(cal.getTimeInMillis());
090:
091: for (Iterator i = triggerEvents.iterator(); i.hasNext();) {
092: TriggerEvent te = (TriggerEvent) i.next();
093: if (te.getTime().after(midnightToday)) {
094: todaysTriggerEvents.add(te);
095: }
096: }
097: return todaysTriggerEvents;
098: }
099: }
100:
101: /**
102: * @param triggerEvents The triggerEvents to set.
103: */
104: public void setTriggerEvents(List triggerEvents) {
105: this .triggerEvents = triggerEvents;
106: }
107:
108: /**
109: * @return Returns the isViewAllSelected.
110: */
111: public boolean getIsViewAllSelected() {
112: return isViewAllSelected;
113: }
114:
115: /**
116: * @param isViewAllSelected The isViewAllSelected to set.
117: */
118: public void setIsViewAllSelected(boolean isViewAllSelected) {
119: this .isViewAllSelected = isViewAllSelected;
120: }
121:
122: public String processSelect() {
123: isViewAllSelected = !isViewAllSelected;
124: return null;
125: }
126: }
|