001 /*
002 * Copyright 2011 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 */
016 package org.kuali.kfs.sys.batch;
017
018 import java.sql.Timestamp;
019 import java.util.Calendar;
020 import java.util.Date;
021
022
023 import org.kuali.kfs.sys.KFSConstants;
024 import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
025 import org.kuali.rice.kns.service.SessionDocumentService;
026
027 public class PurgeSessionDocumentsStep extends AbstractStep {
028 private SessionDocumentService sessionDocumentService;
029
030
031 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurgeSessionDocumentsStep.class);
032
033 /**
034 * @see org.kuali.kfs.sys.batch.Step#execute(java.lang.String, java.util.Date)
035 */
036 public boolean execute(String jobName, Date jobRunDate) {
037 try {
038 LOG.info("executing PurgeSessionDocumentsStep");
039 String maxAgeInDaysStr = getParameterService().getParameterValue(PurgeSessionDocumentsStep.class, KFSConstants.SystemGroupParameterNames.NUMBER_OF_DAYS_SINCE_LAST_UPDATE);
040 int maxAgeInDays = Integer.parseInt(maxAgeInDaysStr);
041
042 Calendar expirationCal = getDateTimeService().getCurrentCalendar();
043 expirationCal.add(Calendar.DATE, -maxAgeInDays);
044 Timestamp expirationDate = new Timestamp(expirationCal.getTime().getTime());
045
046 sessionDocumentService.purgeAllSessionDocuments(expirationDate);
047 return true;
048 }
049 catch (Exception e) {
050 LOG.error("error occured trying to purge session document from DB: ", e);
051 return false;
052 }
053 }
054
055 /**
056 * Gets the sessionDocumentService attribute.
057 * @return Returns the sessionDocumentService.
058 */
059 public SessionDocumentService getSessionDocumentService() {
060 return sessionDocumentService;
061 }
062
063 /**
064 * Sets the sessionDocumentService attribute value.
065 * @param sessionDocumentService The sessionDocumentService to set.
066 */
067 public void setSessionDocumentService(SessionDocumentService sessionDocumentService) {
068 this.sessionDocumentService = sessionDocumentService;
069 }
070
071
072 }