1 /*
2 * Copyright 2006 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.gl.document.service;
17
18 import java.io.IOException;
19 import java.io.OutputStream;
20 import java.sql.Date;
21 import java.util.Collection;
22 import java.util.Iterator;
23 import java.util.List;
24
25 import org.kuali.ole.gl.businessobject.CorrectionChangeGroup;
26 import org.kuali.ole.gl.businessobject.OriginEntryFull;
27 import org.kuali.ole.gl.document.CorrectionDocumentUtils;
28 import org.kuali.ole.gl.document.GeneralLedgerCorrectionProcessDocument;
29 import org.kuali.ole.gl.document.web.CorrectionDocumentEntryMetadata;
30 import org.kuali.ole.sys.batch.InitiateDirectory;
31 import org.kuali.rice.kns.web.ui.Column;
32
33 /**
34 * An interface declaring methods needed by the GLCP to function
35 */
36 public interface CorrectionDocumentService extends InitiateDirectory{
37 public final static String CORRECTION_TYPE_MANUAL = "M";
38 public final static String CORRECTION_TYPE_CRITERIA = "C";
39 public final static String CORRECTION_TYPE_REMOVE_GROUP_FROM_PROCESSING = "R";
40
41 public final static String SYSTEM_DATABASE = "D";
42 public final static String SYSTEM_UPLOAD = "U";
43
44 /**
45 * When passed into {@link #retrievePersistedInputOriginEntries(CorrectionDocument, int)} and
46 * {@link #retrievePersistedOutputOriginEntries(CorrectionDocument, int)} as the int parameter, this will signify that there is
47 * no abort threshold (i.e. the methods should return all of the persisted rows, regardless of number of rows.
48 */
49 public final static int UNLIMITED_ABORT_THRESHOLD = CorrectionDocumentUtils.RECORD_COUNT_FUNCTIONALITY_LIMIT_IS_UNLIMITED;
50
51 /**
52 * Returns a specific correction change group for a GLCP document
53 *
54 * @param docId the document id of a GLCP document
55 * @param i the number of the correction group within the document
56 * @return a CorrectionChangeGroup
57 */
58 public CorrectionChangeGroup findByDocumentNumberAndCorrectionChangeGroupNumber(String docId, int i);
59
60 /**
61 * Finds CollectionChange records associated with a given document id and correction change group
62 *
63 * @param docId the document id of a GLCP document
64 * @param i the number of the correction group within the document
65 * @return a List of qualifying CorrectionChange records
66 */
67 public List findByDocumentHeaderIdAndCorrectionGroupNumber(String docId, int i);
68
69 /**
70 * Finds Collection Criteria associated with the given GLCP document and group
71 *
72 * @param docId the document id of a GLCP document
73 * @param i the number of the correction group within the document
74 * @return a List of qualifying CorrectionCriteria
75 */
76 public List findByDocumentNumberAndCorrectionGroupNumber(String docId, int i);
77
78 /**
79 * Retrieves a correction document by the document id
80 *
81 * @param docId the document id of the GLCP to find
82 * @return a CorrectionDocument if found
83 */
84 public GeneralLedgerCorrectionProcessDocument findByCorrectionDocumentHeaderId(String docId);
85
86 /**
87 * Returns metadata to help render columns in the GLCP. Do not modify this list or the contents in this list.
88 *
89 * @param docId the document id of a GLCP document
90 * @return a List of Columns to render
91 */
92 public List<Column> getTableRenderColumnMetadata(String docId);
93
94 /**
95 * This method persists an Iterator of input origin entries for a document that is in the initiated or saved state
96 *
97 * @param document an initiated or saved document
98 * @param entries an Iterator of origin entries
99 */
100 public void persistInputOriginEntriesForInitiatedOrSavedDocument(GeneralLedgerCorrectionProcessDocument document, Iterator<OriginEntryFull> entries);
101
102 /**
103 * Removes input origin entries that were saved to the database associated with the given document
104 *
105 * @param document a GLCP document
106 */
107 public void removePersistedInputOriginEntries(GeneralLedgerCorrectionProcessDocument document);
108
109 /**
110 * Removes input origin entries that were saved to the database associated with the given document
111 *
112 * @param docId the document id of a GLCP document
113 */
114 public void removePersistedInputOriginEntries(String docId);
115
116 /**
117 * Retrieves input origin entries that have been persisted for this document
118 *
119 * @param document the document
120 * @param abortThreshold if the file exceeds this number of rows, then null is returned. {@link UNLIMITED_ABORT_THRESHOLD}
121 * signifies that there is no limit
122 * @return the list, or null if there are too many origin entries
123 * @throws RuntimeException several reasons, primarily relating to underlying persistence layer problems
124 */
125 public List<OriginEntryFull> retrievePersistedInputOriginEntries(GeneralLedgerCorrectionProcessDocument document, int abortThreshold);
126
127 /**
128 * Returns true if the system is storing input origin entries for this class. Note that this does not mean that there's at least
129 * one input origin entry record persisted for this document, but merely returns true if and only if the underlying persistence
130 * mechanism has a record of this document's origin entries. See the docs for the implementations of this method for more
131 * implementation specific details.
132 *
133 * @param document a GLCP document
134 * @return Returns true if system should store origin entries, false otherwise
135 */
136 public boolean areInputOriginEntriesPersisted(GeneralLedgerCorrectionProcessDocument document);
137
138 /**
139 * Writes out the persisted input origin entries in an {@link OutputStream} in a flat file format
140 *
141 * @param document a GLCP document
142 * @param out an open and ready output stream
143 * @throws IOException thrown if errors were encountered writing to the Stream
144 * @throws RuntimeException several reasons, including if the entries are not persisted
145 */
146 public void writePersistedInputOriginEntriesToStream(GeneralLedgerCorrectionProcessDocument document, OutputStream out) throws IOException;
147
148 /**
149 * This method persists an Iterator of input origin entries for a document that is in the initiated or saved state
150 *
151 * @param document an initiated or saved document
152 * @param entries an Iterator of OriginEntries to persist
153 */
154 public void persistOutputOriginEntriesForInitiatedOrSavedDocument(GeneralLedgerCorrectionProcessDocument document, Iterator<OriginEntryFull> entries);
155
156 /**
157 * Removes all output origin entries persisted in the database created by the given document
158 *
159 * @param document a GLCP document
160 */
161 public void removePersistedOutputOriginEntries(GeneralLedgerCorrectionProcessDocument document);
162
163 /**
164 * Removes all output origin entries persisted in the database created by the given document
165 *
166 * @param docId the document id of a GLCP document
167 */
168 public void removePersistedOutputOriginEntries(String docId);
169
170 /**
171 * Retrieves output origin entries that have been persisted for this document
172 *
173 * @param document the document
174 * @param abortThreshold if the file exceeds this number of rows, then null is returned. {@link UNLIMITED_ABORT_THRESHOLD}
175 * signifies that there is no limit
176 * @return the list, or null if there are too many origin entries
177 * @throws RuntimeException several reasons, primarily relating to underlying persistence layer problems
178 */
179 public List<OriginEntryFull> retrievePersistedOutputOriginEntries(GeneralLedgerCorrectionProcessDocument document, int abortThreshold);
180
181 /**
182 * Retrieves input origin entries that have been persisted for this document in an iterator. Implementations of this method may
183 * choose to implement this method in a way that consumes very little memory.
184 *
185 * @param document the document
186 * @return the iterator
187 * @throws RuntimeException several reasons, primarily relating to underlying persistence layer problems
188 */
189 public Iterator<OriginEntryFull> retrievePersistedInputOriginEntriesAsIterator(GeneralLedgerCorrectionProcessDocument document);
190
191 /**
192 * Retrieves output origin entries that have been persisted for this document in an iterator. Implementations of this method may
193 * choose to implement this method in a way that consumes very little memory.
194 *
195 * @param document the document
196 * @return the iterator
197 * @throws RuntimeException several reasons, primarily relating to underlying persistence layer problems
198 */
199 public Iterator<OriginEntryFull> retrievePersistedOutputOriginEntriesAsIterator(GeneralLedgerCorrectionProcessDocument document);
200
201 /**
202 * Returns true if the system is storing output origin entries for this class. Note that this does not mean that there's at
203 * least one output origin entry record persisted for this document, but merely returns true if and only if the underlying
204 * persistence mechanism has a record of this document's origin entries. See the docs for the implementations of this method for
205 * more implementation specific details.
206 *
207 * @param document a GLCP document to query
208 * @return true if origin entries are stored to the system, false otherwise
209 */
210 public boolean areOutputOriginEntriesPersisted(GeneralLedgerCorrectionProcessDocument document);
211
212 /**
213 * Writes out the persisted output origin entries in an {@link OutputStream} in a flat file format\
214 *
215 * @param document a GLCP document
216 * @param out axn open and ready output stream
217 * @throws IOException thrown if IOExceptions occurred in writing the persisted origin entries
218 * @throws RuntimeException several reasons, including if the entries are not persisted
219 */
220 public void writePersistedOutputOriginEntriesToStream(GeneralLedgerCorrectionProcessDocument document, OutputStream out) throws IOException;
221
222 /**
223 * Saves the input and output origin entry groups for a document prior to saving the document
224 *
225 * @param document a GLCP document
226 * @param correctionDocumentEntryMetadata metadata about this GLCP document
227 */
228 public void persistOriginEntryGroupsForDocumentSave(GeneralLedgerCorrectionProcessDocument document, CorrectionDocumentEntryMetadata correctionDocumentEntryMetadata);
229
230 /**
231 * Retrieves all of the documents that were finalized on a certain date
232 *
233 * @param date the date to find GLCP documents finalized on
234 * @return a collection of documents
235 */
236 public Collection<GeneralLedgerCorrectionProcessDocument> getCorrectionDocumentsFinalizedOn(Date date);
237
238 public String generateOutputOriginEntryFileName(String docId);
239
240 public String createOutputFileForProcessing(String docId, java.util.Date today);
241
242 public String getBatchFileDirectoryName();
243
244 public String getGlcpDirectoryName();
245
246 /**
247 * Generate a text report for the given correction document
248 *
249 * @param document GLCP document to report on
250 */
251 public void generateCorrectionReport(GeneralLedgerCorrectionProcessDocument document);
252
253 public void aggregateCorrectionDocumentReports(GeneralLedgerCorrectionProcessDocument document);
254
255 /**
256 * Finds any existing output files for the given document. Used to prevent double-processing.
257 *
258 * @param documentNumber
259 * @return
260 */
261 public String[] findExistingCorrectionOutputFilesForDocument( String documentNumber );
262 }