View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
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.ole.sys.batch;
17  
18  import java.sql.Timestamp;
19  import java.util.Calendar;
20  import java.util.Date;
21  
22  import org.kuali.ole.sys.OLEConstants;
23  import org.kuali.ole.sys.service.impl.OleParameterConstants;
24  import org.kuali.rice.kns.lookup.LookupResultsService;
25  
26  public class PurgeOldLookupResultsStep extends AbstractStep {
27      private LookupResultsService lookupResultsService;
28  
29      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurgeOldLookupResultsStep.class);
30  
31      /**
32       * @see org.kuali.ole.sys.batch.Step#execute(java.lang.String, java.util.Date)
33       */
34      public boolean execute(String jobName, Date jobRunDate) {
35          try {
36              LOG.info("executing PurgeOldLookupResultsStep");
37  
38              String maxAgeInSecondsStr = getParameterService().getParameterValueAsString(OleParameterConstants.NERVOUS_SYSTEM_LOOKUP.class, OLEConstants.SystemGroupParameterNames.MULTIPLE_VALUE_LOOKUP_RESULTS_EXPIRATION_AGE);
39              int maxAgeInSeconds = Integer.parseInt(maxAgeInSecondsStr);
40  
41              Calendar expirationCal = getDateTimeService().getCurrentCalendar();
42              expirationCal.add(Calendar.SECOND, -maxAgeInSeconds);
43              Timestamp expirationDate = new Timestamp(expirationCal.getTime().getTime());
44  
45              lookupResultsService.deleteOldLookupResults(expirationDate);
46              lookupResultsService.deleteOldSelectedObjectIds(expirationDate);
47              return true;
48          }
49          catch (Exception e) {
50              LOG.error("error occured trying to purge old lookup results: ", e);
51              return false;
52          }
53      }
54  
55      public LookupResultsService getLookupResultsService() {
56          return lookupResultsService;
57      }
58  
59      public void setLookupResultsService(LookupResultsService lookupResultsService) {
60          this.lookupResultsService = lookupResultsService;
61      }
62  
63  
64  }