001/**
002 * Copyright 2005-2017 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kew.mail;
017
018
019import org.kuali.rice.core.api.lifecycle.Lifecycle;
020import org.kuali.rice.kew.api.exception.WorkflowException;
021import org.kuali.rice.kew.service.KEWServiceLocator;
022import org.kuali.rice.ksb.service.KSBServiceLocator;
023import org.quartz.Scheduler;
024
025
026/**
027 * A {@link Lifecycle} which is initialized on system startup that sets up
028 * the daily and weekly email reminders.
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032public class EmailReminderLifecycle implements Lifecycle {
033
034        private boolean started;
035
036        public boolean isStarted() {
037                return started;
038        }
039
040        public void start() throws Exception {
041                // fetch scheduler here to initialize it outside of a transactional context, otherwise we get weird transaction errors
042            Scheduler scheduler = KSBServiceLocator.getScheduler();
043            if (scheduler == null) {
044                throw new WorkflowException("Failed to locate Quartz Scheduler Service.");
045            }
046            KEWServiceLocator.getActionListEmailService().scheduleBatchEmailReminders();
047            started = true;
048        }
049
050        public void stop() throws Exception {
051                started = false;
052        }
053
054}