01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.kfs.batch;
17:
18: import java.sql.Timestamp;
19: import java.util.Calendar;
20:
21: import org.kuali.core.lookup.LookupResultsService;
22: import org.kuali.kfs.KFSConstants;
23: import org.kuali.kfs.service.impl.ParameterConstants;
24:
25: public class PurgeOldLookupResultsStep extends AbstractStep {
26: private LookupResultsService lookupResultsService;
27:
28: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
29: .getLogger(PurgeOldLookupResultsStep.class);
30:
31: public boolean execute(String jobName) {
32: try {
33: LOG.info("executing PurgeOldLookupResultsStep");
34:
35: String maxAgeInSecondsStr = getParameterService()
36: .getParameterValue(
37: ParameterConstants.NERVOUS_SYSTEM_LOOKUP.class,
38: KFSConstants.SystemGroupParameterNames.MULTIPLE_VALUE_LOOKUP_RESULTS_EXPIRATION_AGE);
39: int maxAgeInSeconds = Integer.parseInt(maxAgeInSecondsStr);
40:
41: Calendar expirationCal = getDateTimeService()
42: .getCurrentCalendar();
43: expirationCal.add(Calendar.SECOND, -maxAgeInSeconds);
44: Timestamp expirationDate = new Timestamp(expirationCal
45: .getTime().getTime());
46:
47: lookupResultsService.deleteOldLookupResults(expirationDate);
48: lookupResultsService
49: .deleteOldSelectedObjectIds(expirationDate);
50: return true;
51: } catch (Exception e) {
52: LOG
53: .error(
54: "error occured trying to purge old lookup results: ",
55: e);
56: return false;
57: }
58: }
59:
60: public LookupResultsService getLookupResultsService() {
61: return lookupResultsService;
62: }
63:
64: public void setLookupResultsService(
65: LookupResultsService lookupResultsService) {
66: this.lookupResultsService = lookupResultsService;
67: }
68:
69: }
|