Source Code Cross Referenced for OriginEntryServiceImpl.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » gl » service » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » org.kuali.module.gl.service.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 The Kuali Foundation.
003:         * 
004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         * http://www.opensource.org/licenses/ecl1.php
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.kuali.module.gl.service.impl;
017:
018:        import java.io.BufferedOutputStream;
019:        import java.io.BufferedReader;
020:        import java.io.BufferedWriter;
021:        import java.io.FileReader;
022:        import java.io.FileWriter;
023:        import java.io.IOException;
024:        import java.sql.Date;
025:        import java.util.ArrayList;
026:        import java.util.Collection;
027:        import java.util.HashMap;
028:        import java.util.Iterator;
029:        import java.util.List;
030:        import java.util.Map;
031:
032:        import org.kuali.core.service.DateTimeService;
033:        import org.kuali.core.util.KualiDecimal;
034:        import org.kuali.kfs.KFSConstants;
035:        import org.kuali.kfs.KFSPropertyConstants;
036:        import org.kuali.module.gl.GLConstants;
037:        import org.kuali.module.gl.bo.OriginEntryFull;
038:        import org.kuali.module.gl.bo.OriginEntryGroup;
039:        import org.kuali.module.gl.bo.Transaction;
040:        import org.kuali.module.gl.dao.OriginEntryDao;
041:        import org.kuali.module.gl.service.OriginEntryGroupService;
042:        import org.kuali.module.gl.service.OriginEntryService;
043:        import org.kuali.module.gl.util.LedgerEntry;
044:        import org.kuali.module.gl.util.LedgerEntryHolder;
045:        import org.kuali.module.gl.util.OriginEntryStatistics;
046:        import org.kuali.module.gl.util.PosterOutputSummaryEntry;
047:        import org.springframework.transaction.annotation.Transactional;
048:
049:        /**
050:         * The base implementation of OriginEntryService
051:         */
052:        @Transactional
053:        public class OriginEntryServiceImpl implements  OriginEntryService {
054:            private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
055:                    .getLogger(OriginEntryServiceImpl.class);
056:
057:            private static final String ENTRY_GROUP_ID = "entryGroupId";
058:            private static final String FINANCIAL_DOCUMENT_TYPE_CODE = "financialDocumentTypeCode";
059:            private static final String FINANCIAL_SYSTEM_ORIGINATION_CODE = "financialSystemOriginationCode";
060:
061:            private OriginEntryDao originEntryDao;
062:            private OriginEntryGroupService originEntryGroupService;
063:
064:            private DateTimeService dateTimeService;
065:
066:            /**
067:             * Sets the originEntryDao attribute
068:             * @param originEntryDao the implementation of OriginEntryDao to set
069:             */
070:            public void setOriginEntryDao(OriginEntryDao originEntryDao) {
071:                this .originEntryDao = originEntryDao;
072:            }
073:
074:            /**
075:             * Sets the originEntryGroupService attribute
076:             * @param originEntryGroupService the implementation of OriginEntryGroupService to set
077:             */
078:            public void setOriginEntryGroupService(
079:                    OriginEntryGroupService originEntryGroupService) {
080:                this .originEntryGroupService = originEntryGroupService;
081:            }
082:
083:            /**
084:             * Constructs a new instance of OriginEntryServiceImpl
085:             */
086:            public OriginEntryServiceImpl() {
087:                super ();
088:            }
089:
090:            /**
091:             * Retrieves teh credit total, debit total, and row count for a given origin entry group.
092:             * @param groupId the id of the group to find statistics for
093:             * @return an OriginEntryStatistics object with the statistics for the group
094:             * @see org.kuali.module.gl.service.OriginEntryService#getStatistics(java.lang.Integer)
095:             */
096:            public OriginEntryStatistics getStatistics(Integer groupId) {
097:                LOG.debug("getStatistics() started");
098:
099:                OriginEntryStatistics oes = new OriginEntryStatistics();
100:
101:                oes.setCreditTotalAmount(originEntryDao.getGroupTotal(groupId,
102:                        true));
103:                oes.setDebitTotalAmount(originEntryDao.getGroupTotal(groupId,
104:                        false));
105:                oes.setRowCount(originEntryDao.getGroupCount(groupId));
106:
107:                return oes;
108:            }
109:
110:            /**
111:             * Creates a new origin entry group with the given parameters and saves copies all of the entries in the given Collection
112:             * of entries into that new group.
113:             * 
114:             * @param date the date that the copied entries should list as their post date
115:             * @param sourceCode the source code of the origin entry group to create
116:             * @param valid whether the new group should be considered valid
117:             * @param process whether the new group should be ready to be processed
118:             * @param scrub whether the new group should be processed by the scrubber
119:             * @param entries a Collection of entries to copy
120:             * @return a new origin entry full of copied entries
121:             * @see org.kuali.module.gl.service.OriginEntryService#copyEntries(java.util.Date, java.lang.String, boolean, boolean, boolean,
122:             *      java.util.Collection)
123:             */
124:            public OriginEntryGroup copyEntries(Date date, String sourceCode,
125:                    boolean valid, boolean process, boolean scrub,
126:                    Collection<OriginEntryFull> entries) {
127:                LOG.debug("copyEntries() started");
128:
129:                OriginEntryGroup newOriginEntryGroup = originEntryGroupService
130:                        .createGroup(date, sourceCode, valid, process, scrub);
131:
132:                // Create new Entries with newOriginEntryGroup
133:                for (OriginEntryFull oe : entries) {
134:                    oe.setEntryGroupId(newOriginEntryGroup.getId());
135:                    createEntry(oe, newOriginEntryGroup);
136:                }
137:
138:                return newOriginEntryGroup;
139:            }
140:
141:            /**
142:             * Creates a new origin entry group with the given parameters and creates copies of all the origin entries in the
143:             * iterator, saving the copies in the new group
144:             * @param date the date that the copied entries should list as their post date
145:             * @param sourceCode the source code of the origin entry group to create
146:             * @param valid whether the new group should be considered valid
147:             * @param process whether the new group should be ready to be processed
148:             * @param scrub whether the new group should be processed by the scrubber
149:             * @param entries a Iterator of entries to copy
150:             * @see org.kuali.module.gl.service.OriginEntryService#copyEntries(java.sql.Date, java.lang.String, boolean, boolean, boolean,
151:             *      java.util.Iterator)
152:             */
153:            public OriginEntryGroup copyEntries(Date date, String sourceCode,
154:                    boolean valid, boolean process, boolean scrub,
155:                    Iterator<OriginEntryFull> entries) {
156:                LOG.debug("copyEntries() started");
157:
158:                OriginEntryGroup newOriginEntryGroup = originEntryGroupService
159:                        .createGroup(date, sourceCode, valid, process, scrub);
160:
161:                // Create new Entries with newOriginEntryGroup
162:                while (entries.hasNext()) {
163:                    OriginEntryFull oe = entries.next();
164:                    oe.setEntryGroupId(newOriginEntryGroup.getId());
165:                    createEntry(oe, newOriginEntryGroup);
166:                }
167:
168:                return newOriginEntryGroup;
169:            }
170:
171:            /**
172:             * Deletes an origin entry (full) from the database
173:             * @param oe the origin entry (full) to delete
174:             * @see org.kuali.module.gl.service.OriginEntryService#delete(org.kuali.module.gl.bo.OriginEntryFull)
175:             */
176:            public void delete(OriginEntryFull oe) {
177:                LOG.debug("deleteEntry() started");
178:
179:                originEntryDao.deleteEntry(oe);
180:            }
181:
182:            /**
183:             * This returns all of distinct primary key sets of documents that created origin entries that exist
184:             * in the given origin entry group.  It returns this information in OriginEntryFull objects
185:             * that just don't have any other information besides the document keys (doc number, doc type code,
186:             * and origination code) filled in.
187:             * @param oeg the group with the origin entries to get the documents of
188:             * @return Collection to qualifying documents
189:             * @see org.kuali.module.gl.service.OriginEntryService#getDocumentsByGroup(org.kuali.module.gl.bo.OriginEntryGroup)
190:             */
191:            public Collection<OriginEntryFull> getDocumentsByGroup(
192:                    OriginEntryGroup oeg) {
193:                LOG.debug("getDocumentsByGroup() started");
194:
195:                Collection<OriginEntryFull> results = new ArrayList<OriginEntryFull>();
196:                Iterator i = originEntryDao.getDocumentsByGroup(oeg);
197:                while (i.hasNext()) {
198:                    Object[] data = (Object[]) i.next();
199:                    OriginEntryFull oe = new OriginEntryFull();
200:                    oe.setDocumentNumber((String) data[0]);
201:                    oe.setFinancialDocumentTypeCode((String) data[1]);
202:                    oe.setFinancialSystemOriginationCode((String) data[2]);
203:                    results.add(oe);
204:                }
205:
206:                return results;
207:            }
208:
209:            /**
210:             * Returns an iterator of all the origin entries in a given group.  Defers to the DAO.
211:             * @param originEntryGroup an origin entry group
212:             * @return an iterator of OriginEntryFull objects in that group
213:             * @see org.kuali.module.gl.service.OriginEntryService#getEntriesByGroup(org.kuali.module.gl.bo.OriginEntryGroup)
214:             */
215:            public Iterator<OriginEntryFull> getEntriesByGroup(
216:                    OriginEntryGroup originEntryGroup) {
217:                LOG.debug("getEntriesByGroup() started");
218:
219:                return originEntryDao.getEntriesByGroup(originEntryGroup,
220:                        OriginEntryDao.SORT_DOCUMENT);
221:            }
222:
223:            /**
224:             * Return all entries for the groups where the balance type is empty. Defers to the DAO.
225:             * 
226:             * @param groups a Collection of groups to look through all the entries of
227:             * @return an Iterator of entries without balance types 
228:             * @see org.kuali.module.gl.service.OriginEntryService#getBadBalanceEntries(java.util.Collection)
229:             */
230:            public Iterator<OriginEntryFull> getBadBalanceEntries(
231:                    Collection groups) {
232:                LOG.debug("getBadBalanceEntries() started");
233:
234:                return originEntryDao.getBadBalanceEntries(groups);
235:            }
236:
237:            /**
238:             * Return all entries for a group sorted by account number.  Defers to the DAO.
239:             * 
240:             * @param oeg an origin entry group to get entries from
241:             * @return an Iterator of origin entries sorted by account number
242:             * @see org.kuali.module.gl.service.OriginEntryService#getEntriesByGroupAccountOrder(org.kuali.module.gl.bo.OriginEntryGroup)
243:             */
244:            public Iterator<OriginEntryFull> getEntriesByGroupAccountOrder(
245:                    OriginEntryGroup oeg) {
246:                LOG.debug("getEntriesByGroupAccountOrder() started");
247:
248:                return originEntryDao.getEntriesByGroup(oeg,
249:                        OriginEntryDao.SORT_ACCOUNT);
250:            }
251:
252:            /**
253:             * Return all entries for a group sorted for display on the pending entry report.  Defers to the DAO.
254:             * 
255:             * @param oeg a origin entry group to get entries from
256:             * @return an Iterator of origin entries sorted in the order needed for an origin entry report
257:             * @see org.kuali.module.gl.service.OriginEntryService#getEntriesByGroupReportOrder(org.kuali.module.gl.bo.OriginEntryGroup)
258:             */
259:            public Iterator<OriginEntryFull> getEntriesByGroupReportOrder(
260:                    OriginEntryGroup oeg) {
261:                LOG.debug("getEntriesByGroupAccountOrder() started");
262:
263:                return originEntryDao.getEntriesByGroup(oeg,
264:                        OriginEntryDao.SORT_REPORT);
265:            }
266:
267:            /**
268:             * Return all entries for a group sorted across the columns in report from left to right.  Defers to the DAO.
269:             * 
270:             * @param oeg an origin entry group to get entries from
271:             * @return an Iterator of origin entries sorted in the proper order
272:             * @see org.kuali.module.gl.service.OriginEntryService#getEntriesByGroupListingReportOrder(org.kuali.module.gl.bo.OriginEntryGroup)
273:             */
274:            public Iterator<OriginEntryFull> getEntriesByGroupListingReportOrder(
275:                    OriginEntryGroup oeg) {
276:                LOG.debug("getEntriesByGroupAccountOrder() started");
277:
278:                return originEntryDao.getEntriesByGroup(oeg,
279:                        OriginEntryDao.SORT_LISTING_REPORT);
280:            }
281:
282:            /**
283:             * Return all the entries for a specific document in a specific group.  Defers to the DAO.
284:             * 
285:             * @param oeg an origin entry group to find entries in
286:             * @param documentNumber the document number of entries to select
287:             * @param documentTypeCode the document type of entries to select
288:             * @param originCode the origination code of entries to select
289:             * @return iterator to all the qualifying entries
290:             * @see org.kuali.module.gl.service.OriginEntryService#getEntriesByDocument(org.kuali.module.gl.bo.OriginEntryGroup,
291:             *      java.lang.String, java.lang.String, java.lang.String)
292:             */
293:            public Iterator<OriginEntryFull> getEntriesByDocument(
294:                    OriginEntryGroup originEntryGroup, String documentNumber,
295:                    String documentTypeCode, String originCode) {
296:                LOG.debug("getEntriesByGroup() started");
297:
298:                Map criteria = new HashMap();
299:                criteria.put(ENTRY_GROUP_ID, originEntryGroup.getId());
300:                criteria.put(KFSPropertyConstants.DOCUMENT_NUMBER,
301:                        documentNumber);
302:                criteria.put(FINANCIAL_DOCUMENT_TYPE_CODE, documentTypeCode);
303:                criteria.put(FINANCIAL_SYSTEM_ORIGINATION_CODE, originCode);
304:
305:                return originEntryDao.getMatchingEntries(criteria);
306:            }
307:
308:            /**
309:             * Given a transaction, creates an origin entry out of the transaction and saves it in the given origin entry group
310:             * @param transaction the transaction to turn into an origin entry
311:             * @param originEntryGroup the group to save the new origin entry in
312:             * @see org.kuali.module.gl.service.OriginEntryService#createEntry(org.kuali.module.gl.bo.Transaction, org.kuali.module.gl.bo.OriginEntryGroup)
313:             */
314:            public void createEntry(Transaction transaction,
315:                    OriginEntryGroup originEntryGroup) {
316:                LOG.debug("createEntry() started");
317:
318:                OriginEntryFull e = new OriginEntryFull(transaction);
319:                e.setGroup(originEntryGroup);
320:
321:                originEntryDao.saveOriginEntry(e);
322:
323:                // add 1 to the rows in the origin entry group, so we can unit test against that
324:                originEntryGroup
325:                        .setRows(originEntryGroup.getRows().intValue() + 1);
326:            }
327:
328:            /**
329:             * Saves the given origin entry full record
330:             * @param entry the origin entry to save
331:             * @see org.kuali.module.gl.service.OriginEntryService#save(org.kuali.module.gl.bo.OriginEntryFull)
332:             */
333:            public void save(OriginEntryFull entry) {
334:                LOG.debug("save() started");
335:
336:                originEntryDao.saveOriginEntry(entry);
337:            }
338:
339:            /**
340:             * Export all origin entries in a group to a flat text file
341:             * 
342:             * @param filename Filename to save the text
343:             * @param groupId Group to save
344:             * @see org.kuali.module.gl.service.OriginEntryService#exportFlatFile(java.lang.String, java.lang.Integer)
345:             */
346:            public void exportFlatFile(String filename, Integer groupId) {
347:                LOG.debug("exportFlatFile() started");
348:
349:                BufferedWriter out = null;
350:                try {
351:                    out = new BufferedWriter(new FileWriter(filename));
352:
353:                    OriginEntryGroup oeg = new OriginEntryGroup();
354:                    oeg.setId(groupId);
355:                    Iterator i = getEntriesByGroup(oeg);
356:                    while (i.hasNext()) {
357:                        OriginEntryFull e = (OriginEntryFull) i.next();
358:                        out.write(e.getLine() + "\n");
359:                    }
360:                } catch (IOException e) {
361:                    LOG.error("exportFlatFile() Error writing to file", e);
362:                } finally {
363:                    if (out != null) {
364:                        try {
365:                            out.close();
366:                        } catch (IOException ie) {
367:                            LOG
368:                                    .error(
369:                                            "exportFlatFile() Error closing file",
370:                                            ie);
371:                        }
372:                    }
373:                }
374:            }
375:
376:            /**
377:             * Creates a new origin entry group, reads all of the origin entries in the file and saves all of them in the group
378:             * 
379:             * @param filename Filename with the text
380:             * @param groupSourceCode Source of the new group
381:             * @param valid Valid flag for new group
382:             * @param processed Process flag for new group
383:             * @param scrub Scrub flag for new group
384:             * @see org.kuali.module.gl.service.OriginEntryService#loadFlatFile(java.lang.String, java.lang.String, boolean, boolean,
385:             *      boolean)
386:             */
387:            public void loadFlatFile(String filename, String groupSourceCode,
388:                    boolean isValid, boolean isProcessed, boolean isScrub) {
389:                LOG.debug("loadFlatFile() started");
390:
391:                java.sql.Date groupDate = new java.sql.Date(dateTimeService
392:                        .getCurrentDate().getTime());
393:                OriginEntryGroup newGroup = originEntryGroupService
394:                        .createGroup(groupDate, groupSourceCode, isValid,
395:                                isProcessed, isScrub);
396:
397:                BufferedReader input = null;
398:                try {
399:                    input = new BufferedReader(new FileReader(filename));
400:                    String line = null;
401:                    while ((line = input.readLine()) != null) {
402:                        OriginEntryFull entry = new OriginEntryFull(line);
403:                        createEntry(entry, newGroup);
404:                    }
405:                } catch (Exception ex) {
406:                    LOG.error("performStep() Error reading file", ex);
407:                    throw new IllegalArgumentException("Error reading file");
408:                } finally {
409:                    try {
410:                        if (input != null) {
411:                            input.close();
412:                        }
413:                    } catch (IOException ex) {
414:                        LOG.error("loadFlatFile() error closing file.", ex);
415:                    }
416:                }
417:            }
418:
419:            /**
420:             * Given a collection of group ids, summarize the entries in each group.
421:             * @param groupIdList a Collection of the ids of origin entry groups to summarize
422:             * @return a LedgerEntryHolder with all of the summarized information
423:             * @see org.kuali.module.gl.service.OriginEntryService#getSummaryByGroupId(Collection)
424:             */
425:            public LedgerEntryHolder getSummaryByGroupId(Collection groupIdList) {
426:                LOG.debug("getSummaryByGroupId() started");
427:
428:                LedgerEntryHolder ledgerEntryHolder = new LedgerEntryHolder();
429:
430:                if (groupIdList.size() == 0) {
431:                    return ledgerEntryHolder;
432:                }
433:
434:                Iterator entrySummaryIterator = originEntryDao
435:                        .getSummaryByGroupId(groupIdList);
436:                while (entrySummaryIterator.hasNext()) {
437:                    Object[] entrySummary = (Object[]) entrySummaryIterator
438:                            .next();
439:                    LedgerEntry ledgerEntry = this 
440:                            .buildLedgerEntry(entrySummary);
441:                    ledgerEntryHolder.insertLedgerEntry(ledgerEntry, true);
442:                }
443:                return ledgerEntryHolder;
444:            }
445:
446:            /**
447:             * Creates or updates a ledger entry with the array of information from the given entry summary object
448:             * 
449:             * @param entrySummary a collection of java.lang.Objects, which is what OJB report queries return
450:             * @return a LedgerEntry holding the given report summarization data
451:             */
452:            public static LedgerEntry buildLedgerEntry(Object[] entrySummary) {
453:                // extract the data from an array and use them to populate a ledger entry
454:                Object oFiscalYear = entrySummary[0];
455:                Object oPeriodCode = entrySummary[1];
456:                Object oBalanceType = entrySummary[2];
457:                Object oOriginCode = entrySummary[3];
458:                Object oDebitCreditCode = entrySummary[4];
459:                Object oAmount = entrySummary[5];
460:                Object oCount = entrySummary[6];
461:
462:                Integer fiscalYear = oFiscalYear != null ? new Integer(
463:                        oFiscalYear.toString()) : null;
464:                String periodCode = oPeriodCode != null ? oPeriodCode
465:                        .toString() : GLConstants
466:                        .getSpaceUniversityFiscalPeriodCode();
467:                String balanceType = oBalanceType != null ? oBalanceType
468:                        .toString() : GLConstants.getSpaceBalanceTypeCode();
469:                String originCode = oOriginCode != null ? oOriginCode
470:                        .toString() : GLConstants
471:                        .getSpaceFinancialSystemOriginationCode();
472:                String debitCreditCode = oDebitCreditCode != null ? oDebitCreditCode
473:                        .toString()
474:                        : GLConstants.getSpaceDebitCreditCode();
475:                KualiDecimal amount = oAmount != null ? new KualiDecimal(
476:                        oAmount.toString()) : KualiDecimal.ZERO;
477:                int count = oCount != null ? Integer
478:                        .parseInt(oCount.toString()) : 0;
479:
480:                // construct a ledger entry with the information fetched from the given array
481:                LedgerEntry ledgerEntry = new LedgerEntry(fiscalYear,
482:                        periodCode, balanceType, originCode);
483:                if (KFSConstants.GL_CREDIT_CODE.equals(debitCreditCode)) {
484:                    ledgerEntry.setCreditAmount(amount);
485:                    ledgerEntry.setCreditCount(count);
486:                } else if (KFSConstants.GL_DEBIT_CODE.equals(debitCreditCode)) {
487:                    ledgerEntry.setDebitAmount(amount);
488:                    ledgerEntry.setDebitCount(count);
489:                } else {
490:                    ledgerEntry.setNoDCAmount(amount);
491:                    ledgerEntry.setNoDCCount(count);
492:                }
493:                ledgerEntry.setRecordCount(count);
494:
495:                return ledgerEntry;
496:            }
497:
498:            /**
499:             * Write all of the origin entries in a group to an output stream
500:             * 
501:             * @param groupId the id of the origin entry group to get entries from
502:             * @param bw the output stream to dump the entries as text to
503:             * @see org.kuali.module.gl.service.OriginEntryService#flatFile(java.lang.Integer, java.io.BufferedOutputStream)
504:             */
505:            public void flatFile(Integer groupId, BufferedOutputStream bw) {
506:                LOG.debug("flatFile() started");
507:                OriginEntryGroup oeg = new OriginEntryGroup();
508:                oeg.setId(groupId);
509:                flatFile(getEntriesByGroup(oeg), bw);
510:            }
511:
512:            /**
513:             * This method writes origin entries into a file format. This particular implementation will use the OriginEntryFull.getLine
514:             * method to generate the text for this file.
515:             * 
516:             * @param entries An iterator of OriginEntries
517:             * @param bw an opened, ready-for-output bufferedOutputStream.
518:             * @see org.kuali.module.gl.service.OriginEntryService#flatFile(java.util.Iterator, java.io.BufferedOutputStream)
519:             */
520:            public void flatFile(Iterator<OriginEntryFull> entries,
521:                    BufferedOutputStream bw) {
522:                try {
523:                    while (entries.hasNext()) {
524:                        OriginEntryFull e = entries.next();
525:                        bw.write((e.getLine() + "\n").getBytes());
526:                    }
527:                } catch (IOException e) {
528:                    LOG.error("flatFile() Error writing to file", e);
529:                    throw new RuntimeException("Error writing to file: "
530:                            + e.getMessage());
531:                }
532:            }
533:
534:            /**
535:             * Finds all origin entries matching certain criteria
536:             * 
537:             * @param searchCriteria the criteria to be used in forming a query
538:             * @return a Collection of qualifying origin entries
539:             * @see org.kuali.module.gl.service.OriginEntryService#getMatchingEntriesByCollection(java.util.Map)
540:             */
541:            public Collection<OriginEntryFull> getMatchingEntriesByCollection(
542:                    Map searchCriteria) {
543:                LOG.debug("getMatchingEntriesByCollection() started");
544:
545:                return originEntryDao
546:                        .getMatchingEntriesByCollection(searchCriteria);
547:            }
548:
549:            /**
550:             * Given the id of an origin entry group, returns a list of all the origin entries in that group (actually uses
551:             * getMatchingEntriesByCollection() to accomplish this).
552:             * @param groupId the id of the group to get all entries from
553:             * @return a List of Origin Entries
554:             * @see org.kuali.module.gl.service.OriginEntryService#getMatchingEntriesByList(java.util.Map)
555:             */
556:            public List<OriginEntryFull> getEntriesByGroupId(Integer groupId) {
557:                if (groupId == null) {
558:                    throw new IllegalArgumentException("Group ID is null");
559:                }
560:                Map<String, Object> searchCriteria = new HashMap<String, Object>();
561:                searchCriteria.put(ENTRY_GROUP_ID, groupId);
562:                Collection<OriginEntryFull> searchResultAsCollection = getMatchingEntriesByCollection(searchCriteria);
563:                if (searchResultAsCollection instanceof  List) {
564:                    return (List<OriginEntryFull>) searchResultAsCollection;
565:                } else {
566:                    return new ArrayList<OriginEntryFull>(
567:                            searchResultAsCollection);
568:                }
569:            }
570:
571:            /**
572:             * Returns the origin entry with the given id.  Defers to the DAO.
573:             * @param entryId the unique id of an origin entry
574:             * @return the origin entry if found, or null otherwise
575:             * @see org.kuali.module.gl.service.OriginEntryService#getExactMatchingEntry(java.lang.Integer)
576:             */
577:            public OriginEntryFull getExactMatchingEntry(Integer entryId) {
578:                LOG.debug("getExactMatchingEntry() started");
579:
580:                return originEntryDao.getExactMatchingEntry(entryId);
581:            }
582:
583:            /**
584:             * get the summarized information of poster input entries that belong to the entry groups with the given group id list
585:             * 
586:             * @param groupIdList the origin entry groups
587:             * @return a map of summarized information of poster input entries within the specified groups
588:             * @see org.kuali.module.gl.service.OriginEntryService#getPosterOutputSummaryByGroupId(java.util.Collection)
589:             */
590:            public Map<String, PosterOutputSummaryEntry> getPosterOutputSummaryByGroupId(
591:                    Collection groupIdList) {
592:                LOG.debug("getPosterOutputSummaryByGroupId() started");
593:
594:                Map<String, PosterOutputSummaryEntry> output = new HashMap<String, PosterOutputSummaryEntry>();
595:
596:                if (groupIdList.size() == 0) {
597:                    return output;
598:                }
599:
600:                Iterator entrySummaryIterator = originEntryDao
601:                        .getPosterOutputSummaryByGroupId(groupIdList);
602:                while (entrySummaryIterator.hasNext()) {
603:                    Object[] entrySummary = (Object[]) entrySummaryIterator
604:                            .next();
605:                    PosterOutputSummaryEntry posterOutputSummaryEntry = new PosterOutputSummaryEntry();
606:                    int indexOfField = 0;
607:
608:                    Object tempEntry = entrySummary[indexOfField++];
609:                    String entry = (tempEntry == null) ? "" : tempEntry
610:                            .toString();
611:                    posterOutputSummaryEntry.setBalanceTypeCode(entry);
612:
613:                    tempEntry = entrySummary[indexOfField++];
614:                    entry = (tempEntry == null) ? null : tempEntry.toString();
615:                    posterOutputSummaryEntry
616:                            .setUniversityFiscalYear(new Integer(entry));
617:
618:                    tempEntry = entrySummary[indexOfField++];
619:                    entry = (tempEntry == null) ? "" : tempEntry.toString();
620:                    posterOutputSummaryEntry.setFiscalPeriodCode(entry);
621:
622:                    tempEntry = entrySummary[indexOfField++];
623:                    entry = (tempEntry == null) ? "" : tempEntry.toString();
624:                    posterOutputSummaryEntry.setFundGroup(entry);
625:
626:                    tempEntry = entrySummary[indexOfField++];
627:                    String objectTypeCode = (tempEntry == null) ? ""
628:                            : tempEntry.toString();
629:                    posterOutputSummaryEntry.setObjectTypeCode(objectTypeCode);
630:
631:                    tempEntry = entrySummary[indexOfField++];
632:                    String debitCreditCode = (tempEntry == null) ? KFSConstants.GL_BUDGET_CODE
633:                            : tempEntry.toString();
634:
635:                    tempEntry = entrySummary[indexOfField];
636:                    entry = (tempEntry == null) ? "0" : tempEntry.toString();
637:                    KualiDecimal amount = new KualiDecimal(entry);
638:
639:                    posterOutputSummaryEntry.setAmount(debitCreditCode,
640:                            objectTypeCode, amount);
641:
642:                    if (output.containsKey(posterOutputSummaryEntry.getKey())) {
643:                        PosterOutputSummaryEntry pose = output
644:                                .get(posterOutputSummaryEntry.getKey());
645:                        pose.add(posterOutputSummaryEntry);
646:                    } else {
647:                        output.put(posterOutputSummaryEntry.getKey(),
648:                                posterOutputSummaryEntry);
649:                    }
650:                }
651:                return output;
652:            }
653:
654:            /**
655:             * Returns the number of origin entries in a group.  Defers to the DAO.
656:             * Get count of transactions in a group
657:             * @param groupId the group to get the count of entries from
658:             * @return a count of entries
659:             * @see org.kuali.module.gl.service.OriginEntryService#getGroupCount(java.lang.Integer)
660:             */
661:            public Integer getGroupCount(Integer groupId) {
662:                return originEntryDao.getGroupCount(groupId);
663:            }
664:
665:            public void setDateTimeService(DateTimeService dateTimeService) {
666:                this.dateTimeService = dateTimeService;
667:            }
668:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.