1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.service.impl;
17
18 import java.io.BufferedOutputStream;
19 import java.io.BufferedReader;
20 import java.io.File;
21 import java.io.FileNotFoundException;
22 import java.io.FileReader;
23 import java.io.IOException;
24 import java.io.PrintStream;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Map;
31
32 import org.kuali.ole.gl.GeneralLedgerConstants;
33 import org.kuali.ole.gl.batch.service.impl.OriginEntryFileIterator;
34 import org.kuali.ole.gl.businessobject.LedgerEntryForReporting;
35 import org.kuali.ole.gl.businessobject.LedgerEntryHolder;
36 import org.kuali.ole.gl.businessobject.OriginEntryFull;
37 import org.kuali.ole.gl.businessobject.PosterOutputSummaryEntry;
38 import org.kuali.ole.gl.service.OriginEntryGroupService;
39 import org.kuali.ole.gl.service.OriginEntryService;
40 import org.kuali.ole.sys.OLEConstants;
41 import org.kuali.ole.sys.Message;
42 import org.kuali.rice.core.api.datetime.DateTimeService;
43 import org.kuali.rice.core.api.util.type.KualiDecimal;
44 import org.springframework.transaction.annotation.Transactional;
45
46
47
48
49 @Transactional
50 public class OriginEntryServiceImpl implements OriginEntryService {
51 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OriginEntryServiceImpl.class);
52
53 private static final String ENTRY_GROUP_ID = "entryGroupId";
54 private static final String FINANCIAL_DOCUMENT_TYPE_CODE = "financialDocumentTypeCode";
55 private static final String FINANCIAL_SYSTEM_ORIGINATION_CODE = "financialSystemOriginationCode";
56
57 private OriginEntryGroupService originEntryGroupService;
58
59 private DateTimeService dateTimeService;
60 private String batchFileDirectoryName;
61
62
63
64
65
66 public void setOriginEntryGroupService(OriginEntryGroupService originEntryGroupService) {
67 this.originEntryGroupService = originEntryGroupService;
68 }
69
70
71
72
73 public OriginEntryServiceImpl() {
74 super();
75 }
76
77 public void createEntry(OriginEntryFull originEntry, PrintStream ps) {
78 LOG.debug("createEntry() with PrintStream started");
79
80 try {
81 ps.printf("%s\n", originEntry.getLine());
82 } catch (Exception e) {
83 throw new RuntimeException(e.toString());
84 }
85
86 }
87
88
89
90
91
92
93
94
95
96 public LedgerEntryHolder getSummaryByGroupId(Collection groupIdList) {
97 LOG.debug("getSummaryByGroupId() started");
98
99 LedgerEntryHolder ledgerEntryHolder = new LedgerEntryHolder();
100
101 if (groupIdList.size() == 0) {
102 return ledgerEntryHolder;
103 }
104
105 return ledgerEntryHolder;
106 }
107
108
109
110
111
112
113
114 public static LedgerEntryForReporting buildLedgerEntry(Object[] entrySummary) {
115
116 Object oFiscalYear = entrySummary[0];
117 Object oPeriodCode = entrySummary[1];
118 Object oBalanceType = entrySummary[2];
119 Object oOriginCode = entrySummary[3];
120 Object oDebitCreditCode = entrySummary[4];
121 Object oAmount = entrySummary[5];
122 Object oCount = entrySummary[6];
123
124 Integer fiscalYear = oFiscalYear != null ? new Integer(oFiscalYear.toString()) : null;
125 String periodCode = oPeriodCode != null ? oPeriodCode.toString() : GeneralLedgerConstants.getSpaceUniversityFiscalPeriodCode();
126 String balanceType = oBalanceType != null ? oBalanceType.toString() : GeneralLedgerConstants.getSpaceBalanceTypeCode();
127 String originCode = oOriginCode != null ? oOriginCode.toString() : GeneralLedgerConstants.getSpaceFinancialSystemOriginationCode();
128 String debitCreditCode = oDebitCreditCode != null ? oDebitCreditCode.toString() : GeneralLedgerConstants.getSpaceDebitCreditCode();
129 KualiDecimal amount = oAmount != null ? new KualiDecimal(oAmount.toString()) : KualiDecimal.ZERO;
130 int count = oCount != null ? Integer.parseInt(oCount.toString()) : 0;
131
132
133 LedgerEntryForReporting ledgerEntry = new LedgerEntryForReporting(fiscalYear, periodCode, balanceType, originCode);
134 if (OLEConstants.GL_CREDIT_CODE.equals(debitCreditCode)) {
135 ledgerEntry.setCreditAmount(amount);
136 ledgerEntry.setCreditCount(count);
137 }
138 else if (OLEConstants.GL_DEBIT_CODE.equals(debitCreditCode)) {
139 ledgerEntry.setDebitAmount(amount);
140 ledgerEntry.setDebitCount(count);
141 }
142 else {
143 ledgerEntry.setNoDCAmount(amount);
144 ledgerEntry.setNoDCCount(count);
145 }
146 ledgerEntry.setRecordCount(count);
147
148 return ledgerEntry;
149 }
150
151
152
153
154
155
156
157
158
159 public void flatFile(Iterator<OriginEntryFull> entries, BufferedOutputStream bw) {
160 try {
161 while (entries.hasNext()) {
162 OriginEntryFull e = entries.next();
163 bw.write((e.getLine() + "\n").getBytes());
164 }
165 }
166 catch (IOException e) {
167 LOG.error("flatFile() Error writing to file", e);
168 throw new RuntimeException("Error writing to file: " + e.getMessage());
169 }
170 }
171
172 public Map getEntriesByGroupIdWithPath(String fileNameWithPath, List<OriginEntryFull> originEntryList) {
173
174 FileReader INPUT_GLE_FILE = null;
175 BufferedReader INPUT_GLE_FILE_br;
176 try {
177 INPUT_GLE_FILE = new FileReader(fileNameWithPath);
178 } catch (FileNotFoundException e) {
179 throw new RuntimeException(e);
180 }
181 INPUT_GLE_FILE_br = new BufferedReader(INPUT_GLE_FILE);
182
183 boolean loadError = false;
184
185 Map returnMessageMap = getEntriesByBufferedReader(INPUT_GLE_FILE_br, originEntryList);
186
187 try{
188 INPUT_GLE_FILE_br.close();
189 INPUT_GLE_FILE.close();
190 } catch (IOException e) {
191 throw new RuntimeException(e);
192 }
193
194 return returnMessageMap;
195 }
196
197 public Map getEntriesByBufferedReader(BufferedReader inputBufferedReader, List<OriginEntryFull> originEntryList) {
198 String line;
199 int lineNumber = 0;
200 Map returnMessageMap = new HashMap();
201 try {
202 List<Message> tmperrors = new ArrayList();
203 while ((line = inputBufferedReader.readLine()) != null) {
204 lineNumber++;
205 OriginEntryFull originEntry = new OriginEntryFull();
206 tmperrors = originEntry.setFromTextFileForBatch(line, lineNumber);
207 originEntry.setEntryId(lineNumber);
208 if (tmperrors.size() > 0){
209 returnMessageMap.put(new Integer(lineNumber), tmperrors);
210 } else {
211 originEntryList.add(originEntry);
212 }
213 }
214 } catch (IOException e) {
215 throw new RuntimeException(e);
216 }
217
218 return returnMessageMap;
219
220
221 }
222
223
224
225
226
227
228
229
230
231
232 public Map<String, PosterOutputSummaryEntry> getPosterOutputSummaryByGroupId(Collection groupIdList) {
233 LOG.debug("getPosterOutputSummaryByGroupId() started");
234
235 Map<String, PosterOutputSummaryEntry> output = new HashMap<String, PosterOutputSummaryEntry>();
236
237 if (groupIdList.size() == 0) {
238 return output;
239 }
240
241 return output;
242 }
243
244 public Integer getGroupCount(String fileNameWithPath){
245 File file = new File(fileNameWithPath);
246 Iterator<OriginEntryFull> fileIterator = new OriginEntryFileIterator(file);
247 int count = 0;
248
249 while(fileIterator.hasNext()){
250 count++;
251 fileIterator.next();
252 }
253 return count;
254 }
255
256 public void setDateTimeService(DateTimeService dateTimeService) {
257 this.dateTimeService = dateTimeService;
258 }
259
260 public void setBatchFileDirectoryName(String batchFileDirectoryName) {
261 this.batchFileDirectoryName = batchFileDirectoryName;
262 }
263 }