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.util.Calendar;
19  import java.util.Date;
20  
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.rice.krad.service.AttachmentService;
23  
24  
25  /**
26   * This class is the batch step used to delete pending attachments that have not yet been associated with a document. When
27   * attachments are attached to docs in an "initiated" state, the attachment is not considered to be linked with the doc in the
28   * persistence layer, and so it becomes a "pending" attachment (i.e. pending persistence). When docs are saved (or submitted, etc.),
29   * pending attachments become permanently persisted to the document and are no longer pending. Pending attachments may have become
30   * orphaned from the document (because the doc has not been saved), and so these orphaned attachments must be deleted. This job uses
31   * the file's last modified time to determine which pending attachments should be deleted. If the modified time is older than the
32   * SYSTEM parameter "pendingAssignmentMaxAge", then it will be deleted.
33   * 
34   * @see org.kuali.rice.krad.service.impl.AttachmentServiceImpl
35   * @see OLEConstants.SystemGroupParameterNames#PURGE_PENDING_ATTACHMENTS_STEP_MAX_AGE
36   */
37  public class PurgePendingAttachmentsStep extends AbstractStep {
38  
39      private AttachmentService attachmentService;
40  
41      /**
42       * Deletes all pending attachments that are older than a configured time (see class description)
43       * 
44       * @see org.kuali.ole.sys.batch.Step#execute(String, Date)
45       */
46      public boolean execute(String jobName, Date jobRunDate) {
47          Calendar calendar = getDateTimeService().getCurrentCalendar();
48          String maxAgeInSecondsStr = getParameterService().getParameterValueAsString(PurgePendingAttachmentsStep.class, OLEConstants.SystemGroupParameterNames.PURGE_PENDING_ATTACHMENTS_STEP_MAX_AGE);
49          int maxAgeInSeconds = Integer.parseInt(maxAgeInSecondsStr);
50          calendar.add(Calendar.SECOND, -maxAgeInSeconds);
51          getAttachmentService().deletePendingAttachmentsModifiedBefore(calendar.getTimeInMillis());
52          return true;
53      }
54  
55      /**
56       * Gets the attachmentService attribute.
57       * 
58       * @return Returns the attachmentService.
59       */
60      public AttachmentService getAttachmentService() {
61          return attachmentService;
62      }
63  
64      /**
65       * Sets the attachmentService attribute value.
66       * 
67       * @param attachmentService The attachmentService to set.
68       */
69      public void setAttachmentService(AttachmentService attachmentService) {
70          this.attachmentService = attachmentService;
71      }
72  }