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.util.Calendar;
19: import java.util.GregorianCalendar;
20: import java.util.Iterator;
21:
22: import org.apache.log4j.Logger;
23: import org.kuali.core.bo.DocumentHeader;
24: import org.kuali.core.service.DocumentService;
25:
26: import edu.iu.uis.eden.exception.WorkflowException;
27:
28: /**
29: * This class loads documents that have been final a parameterized number of days and purges the xml document contents.
30: */
31: public class PurgeDocumentContentsStep extends AbstractStep {
32: private static Logger LOG = Logger
33: .getLogger(PurgeDocumentContentsStep.class);
34: private DocumentService documentService;
35:
36: /**
37: * @see org.kuali.kfs.batch.Step#performStep()
38: */
39: public boolean execute(String jobName) {
40: int numberOfDaysFinal = Integer.parseInt(getParameterService()
41: .getParameterValue(getClass(), "NUMBER_OF_DAYS_FINAL"));
42: Calendar financialDocumentFinalCalendar = getDateTimeService()
43: .getCurrentCalendar();
44: financialDocumentFinalCalendar.add(
45: GregorianCalendar.DAY_OF_YEAR, -numberOfDaysFinal);
46: String currentDocumentNumber = null;
47: try {
48: Iterator finalDocumentHeaderItr = documentService
49: .getFinalDocumentHeadersByDate(
50: financialDocumentFinalCalendar.getTime())
51: .iterator();
52: while (finalDocumentHeaderItr.hasNext()) {
53: DocumentHeader finalDocumentHeader = (DocumentHeader) finalDocumentHeaderItr
54: .next();
55: currentDocumentNumber = finalDocumentHeader
56: .getDocumentNumber();
57: setFinalDocumentDocumentContent(finalDocumentHeader);
58: }
59: } catch (WorkflowException we) {
60: throw new RuntimeException(
61: "caught exception while executing "
62: + getClass().getName()
63: + " doc id may have been "
64: + currentDocumentNumber, we);
65: }
66: return true;
67: }
68:
69: public void setFinalDocumentDocumentContent(
70: DocumentHeader finalDocumentHeader)
71: throws WorkflowException {
72: // Added the special XML content flag here which indicates to the KEW engine not to execute searchable attribute indexing.
73: // This allows for us to clear the content without worrying about losing our search capabilities
74: finalDocumentHeader
75: .getWorkflowDocument()
76: .setApplicationContent(
77: "<final><doNotExecuteSearchableAttributeIndexing/></final>");
78: finalDocumentHeader.getWorkflowDocument().saveRoutingData();
79: }
80:
81: /**
82: * Sets the documentService attribute value. For use by Spring.
83: *
84: * @param documentService The documentService to set.
85: */
86: public void setDocumentService(DocumentService documentService) {
87: this.documentService = documentService;
88: }
89: }
|