View Javadoc
1   /*
2    * Copyright 2007-2008 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.Date;
20  
21  import org.apache.commons.lang.time.DateUtils;
22  import org.kuali.ole.sys.OLEConstants;
23  import org.kuali.rice.krad.service.SessionDocumentService;
24  
25  public class PurgeSessionDocumentsStep extends AbstractStep {
26      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurgeSessionDocumentsStep.class);
27  
28      protected SessionDocumentService sessionDocumentService;
29  
30      /**
31       * @see org.kuali.ole.sys.batch.Step#execute(java.lang.String, java.util.Date)
32       */
33      public boolean execute(String jobName, Date jobRunDate) {
34          try {
35              LOG.info("executing PurgeSessionDocumentsStep");
36              String maxAgeInDaysStr = parameterService.getParameterValueAsString(PurgeSessionDocumentsStep.class, OLEConstants.SystemGroupParameterNames.NUMBER_OF_DAYS_SINCE_LAST_UPDATE);
37              int maxAgeInDays = Integer.parseInt(maxAgeInDaysStr);
38  
39              Timestamp expirationDate = new Timestamp(DateUtils.addDays(getDateTimeService().getCurrentDate(), -maxAgeInDays).getTime());
40  
41              sessionDocumentService.purgeAllSessionDocuments(expirationDate);
42              return true;
43          }
44          catch (Exception e) {
45              LOG.error("error occured trying to purge session document from DB: ", e);
46          }
47          return false;
48      }
49  
50      public void setSessionDocumentService(SessionDocumentService sessionDocumentService) {
51          this.sessionDocumentService = sessionDocumentService;
52      }
53  
54  
55  }