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 import org.kuali.kfs.sys.KFSConstants;
023 import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
024 import org.kuali.rice.kns.lookup.LookupResultsService;
025
026 public class PurgeOldLookupResultsStep extends AbstractStep {
027 private LookupResultsService lookupResultsService;
028
029 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurgeOldLookupResultsStep.class);
030
031 /**
032 * @see org.kuali.kfs.sys.batch.Step#execute(java.lang.String, java.util.Date)
033 */
034 public boolean execute(String jobName, Date jobRunDate) {
035 try {
036 LOG.info("executing PurgeOldLookupResultsStep");
037
038 String maxAgeInSecondsStr = getParameterService().getParameterValue(KfsParameterConstants.NERVOUS_SYSTEM_LOOKUP.class, KFSConstants.SystemGroupParameterNames.MULTIPLE_VALUE_LOOKUP_RESULTS_EXPIRATION_AGE);
039 int maxAgeInSeconds = Integer.parseInt(maxAgeInSecondsStr);
040
041 Calendar expirationCal = getDateTimeService().getCurrentCalendar();
042 expirationCal.add(Calendar.SECOND, -maxAgeInSeconds);
043 Timestamp expirationDate = new Timestamp(expirationCal.getTime().getTime());
044
045 lookupResultsService.deleteOldLookupResults(expirationDate);
046 lookupResultsService.deleteOldSelectedObjectIds(expirationDate);
047 return true;
048 }
049 catch (Exception e) {
050 LOG.error("error occured trying to purge old lookup results: ", e);
051 return false;
052 }
053 }
054
055 public LookupResultsService getLookupResultsService() {
056 return lookupResultsService;
057 }
058
059 public void setLookupResultsService(LookupResultsService lookupResultsService) {
060 this.lookupResultsService = lookupResultsService;
061 }
062
063
064 }