Source Code Cross Referenced for OriginEntryDaoOjb.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » gl » dao » ojb » 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.dao.ojb 
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.dao.ojb;
017:
018:        import java.math.BigDecimal;
019:        import java.util.ArrayList;
020:        import java.util.Collection;
021:        import java.util.Iterator;
022:        import java.util.List;
023:        import java.util.Map;
024:
025:        import org.apache.ojb.broker.query.Criteria;
026:        import org.apache.ojb.broker.query.QueryByCriteria;
027:        import org.apache.ojb.broker.query.QueryFactory;
028:        import org.apache.ojb.broker.query.ReportQueryByCriteria;
029:        import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
030:        import org.kuali.core.util.KualiDecimal;
031:        import org.kuali.core.util.TransactionalServiceUtils;
032:        import org.kuali.kfs.KFSConstants;
033:        import org.kuali.kfs.KFSPropertyConstants;
034:        import org.kuali.module.gl.bo.OriginEntry;
035:        import org.kuali.module.gl.bo.OriginEntryFull;
036:        import org.kuali.module.gl.bo.OriginEntryGroup;
037:        import org.kuali.module.gl.dao.OriginEntryDao;
038:
039:        /**
040:         * An OJB implementation of the OriginEntryDao
041:         */
042:        public class OriginEntryDaoOjb extends PlatformAwareDaoBaseOjb
043:                implements  OriginEntryDao {
044:            private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
045:                    .getLogger(OriginEntryDaoOjb.class);
046:
047:            private static final String ENTRY_GROUP_ID = "entryGroupId";
048:            private static final String ENTRY_ID = "entryId";
049:            private static final String FINANCIAL_BALANCE_TYPE_CODE = "financialBalanceTypeCode";
050:            private static final String CHART_OF_ACCOUNTS_CODE = "chartOfAccountsCode";
051:            private static final String ACCOUNT_NUMBER = "accountNumber";
052:            private static final String SUB_ACCOUNT_NUMBER = "subAccountNumber";
053:            private static final String FINANCIAL_DOCUMENT_TYPE_CODE = "financialDocumentTypeCode";
054:            private static final String FINANCIAL_SYSTEM_ORIGINATION_CODE = "financialSystemOriginationCode";
055:            private static final String FINANCIAL_DOCUMENT_REVERSAL_DATE = "financialDocumentReversalDate";
056:            private static final String UNIVERSITY_FISCAL_PERIOD_CODE = "universityFiscalPeriodCode";
057:            private static final String UNIVERSITY_FISCAL_YEAR = "universityFiscalYear";
058:            private static final String FINANCIAL_OBJECT_CODE = "financialObjectCode";
059:            private static final String FINANCIAL_SUB_OBJECT_CODE = "financialSubObjectCode";
060:            private static final String FINANCIAL_OBJECT_TYPE_CODE = "financialObjectTypeCode";
061:            private static final String TRANSACTION_LEDGER_ENTRY_SEQUENCE_NUMBER = "transactionLedgerEntrySequenceNumber";
062:            private static final String TRANSACTION_LEDGER_ENTRY_DESCRIPTION = "transactionLedgerEntryDescription";
063:            private static final String TRANSACTION_LEDGER_ENTRY_AMOUNT = "transactionLedgerEntryAmount";
064:            private static final String TRANSACTION_DEBIT_CREDIT_CODE = "transactionDebitCreditCode";
065:
066:            private Class entryClass;
067:
068:            /**
069:             * Sets the class of the origin entries this class deals with.  This makes this particular
070:             * class very flexible; instances of it can deal with OriginEntryLites as well as they deal
071:             * with OriginEntryFulls.
072:             * 
073:             * @param entryClass the class of OriginEntries this instance will use for OJB operations
074:             */
075:            public void setEntryClass(Class entryClass) {
076:                this .entryClass = entryClass;
077:            }
078:
079:            /**
080:             * Gets the entryClass attribute.
081:             * 
082:             * @return Returns the entryClass.
083:             */
084:            public Class getEntryClass() {
085:                return entryClass;
086:            }
087:
088:            /**
089:             * Constructs a OriginEntryDaoOjb instance
090:             */
091:            public OriginEntryDaoOjb() {
092:                super ();
093:            }
094:
095:            /**
096:             * Get the total amount of transactions in a group
097:             * @param the id of the origin entry group to total
098:             * @param isCredit whether the total should be of credits or not
099:             * @return the sum of all queried origin entries
100:             * @see org.kuali.module.gl.dao.OriginEntryDao#getGroupTotal(java.lang.Integer, boolean)
101:             */
102:            public KualiDecimal getGroupTotal(Integer groupId, boolean isCredit) {
103:                LOG.debug("getGroupTotal() started");
104:
105:                Criteria crit = new Criteria();
106:                crit.addEqualTo(OriginEntryDaoOjb.ENTRY_GROUP_ID, groupId);
107:                if (isCredit) {
108:                    crit.addEqualTo(
109:                            OriginEntryDaoOjb.TRANSACTION_DEBIT_CREDIT_CODE,
110:                            KFSConstants.GL_CREDIT_CODE);
111:                } else {
112:                    crit.addNotEqualTo(
113:                            OriginEntryDaoOjb.TRANSACTION_DEBIT_CREDIT_CODE,
114:                            KFSConstants.GL_CREDIT_CODE);
115:                }
116:
117:                ReportQueryByCriteria q = QueryFactory.newReportQuery(
118:                        entryClass, crit);
119:                q.setAttributes(new String[] { "SUM("
120:                        + OriginEntryDaoOjb.TRANSACTION_LEDGER_ENTRY_AMOUNT
121:                        + ")" });
122:
123:                Iterator i = getPersistenceBrokerTemplate()
124:                        .getReportQueryIteratorByQuery(q);
125:                if (i.hasNext()) {
126:                    Object[] data = (Object[]) TransactionalServiceUtils
127:                            .retrieveFirstAndExhaustIterator(i);
128:                    return (KualiDecimal) data[0];
129:                } else {
130:                    return null;
131:                }
132:            }
133:
134:            /**
135:             * Counts the number of entries in a group
136:             * @param the id of an origin entry group
137:             * @return the count of the entries in that group
138:             * @see org.kuali.module.gl.dao.OriginEntryDao#getGroupCount(java.lang.Integer)
139:             */
140:            public Integer getGroupCount(Integer groupId) {
141:                LOG.debug("getGroupCount() started");
142:
143:                Criteria crit = new Criteria();
144:                crit.addEqualTo(OriginEntryDaoOjb.ENTRY_GROUP_ID, groupId);
145:
146:                ReportQueryByCriteria q = QueryFactory.newReportQuery(
147:                        entryClass, crit);
148:                q.setAttributes(new String[] { "count(*)" });
149:
150:                Iterator i = getPersistenceBrokerTemplate()
151:                        .getReportQueryIteratorByQuery(q);
152:                if (i.hasNext()) {
153:                    Object[] data = (Object[]) TransactionalServiceUtils
154:                            .retrieveFirstAndExhaustIterator(i);
155:
156:                    if (data[0] instanceof  BigDecimal) {
157:                        return ((BigDecimal) data[0]).intValue();
158:                    } else {
159:                        return ((Long) data[0]).intValue();
160:                    }
161:                } else {
162:                    return null;
163:                }
164:            }
165:
166:            /**
167:             * Counts of rows of all the origin entry groups
168:             * 
169:             * @return iterator of Object[] {[BigDecimal id,BigDecimal count]}
170:             * @see org.kuali.module.gl.dao.OriginEntryDao#getGroupCounts()
171:             */
172:            public Iterator getGroupCounts() {
173:                LOG.debug("getGroupCounts() started");
174:
175:                Criteria crit = new Criteria();
176:
177:                ReportQueryByCriteria q = QueryFactory.newReportQuery(
178:                        entryClass, crit);
179:                q.setAttributes(new String[] { ENTRY_GROUP_ID, "count(*)" });
180:                q.addGroupBy(ENTRY_GROUP_ID);
181:
182:                return getPersistenceBrokerTemplate()
183:                        .getReportQueryIteratorByQuery(q);
184:            }
185:
186:            /**
187:             * Delete an entry from the database
188:             * @param oe the entry to delete
189:             * @see org.kuali.module.gl.dao.OriginEntryDao#deleteEntry(org.kuali.module.gl.bo.OriginEntry)
190:             */
191:            public void deleteEntry(OriginEntry oe) {
192:                LOG.debug("deleteEntry() started");
193:
194:                getPersistenceBrokerTemplate().delete(oe);
195:            }
196:
197:            /**
198:             * Return an iterator of keys of all documents referenced by origin entries in a given group
199:             * 
200:             * @param oeg Group the origin entry group to find entries in, by origin entry
201:             * @return Iterator of java.lang.Object[] with report data about all of the distinct document numbers/type code/origination code combinations of origin entries in the group
202:             * @see org.kuali.module.gl.dao.OriginEntryDao#getDocumentsByGroup(org.kuali.module.gl.bo.OriginEntryGroup)
203:             */
204:            public Iterator getDocumentsByGroup(OriginEntryGroup oeg) {
205:                LOG.debug("getDocumentsByGroup() started");
206:
207:                Criteria criteria = new Criteria();
208:                criteria.addEqualTo(ENTRY_GROUP_ID, oeg.getId());
209:
210:                ReportQueryByCriteria q = QueryFactory.newReportQuery(
211:                        entryClass, criteria);
212:                q.setAttributes(new String[] {
213:                        KFSPropertyConstants.DOCUMENT_NUMBER,
214:                        "financialDocumentTypeCode",
215:                        "financialSystemOriginationCode" });
216:
217:                q.setDistinct(true);
218:
219:                return getPersistenceBrokerTemplate()
220:                        .getReportQueryIteratorByQuery(q);
221:            }
222:
223:            /**
224:             * Iterator of entries that match criteria
225:             * 
226:             * @param searchCriteria Map of field, value pairs
227:             * @return collection of entries
228:             * @see org.kuali.module.gl.dao.OriginEntryDao#getMatchingEntries(java.util.Map)
229:             */
230:            public Iterator<OriginEntryFull> getMatchingEntries(
231:                    Map searchCriteria) {
232:                LOG.debug("getMatchingEntries() started");
233:
234:                Criteria criteria = new Criteria();
235:                for (Iterator iter = searchCriteria.keySet().iterator(); iter
236:                        .hasNext();) {
237:                    String element = (String) iter.next();
238:                    criteria.addEqualTo(element, searchCriteria.get(element));
239:                }
240:
241:                QueryByCriteria qbc = QueryFactory.newQuery(entryClass,
242:                        criteria);
243:                qbc.addOrderByAscending(ENTRY_GROUP_ID);
244:                return getPersistenceBrokerTemplate().getIteratorByQuery(qbc);
245:            }
246:
247:            /**
248:             * Get bad balance entries
249:             * 
250:             * @param groups a Collection of groups to remove bad entries in
251:             * @return an Iterator of no good, won't use, bad balance entries
252:             * @see org.kuali.module.gl.dao.OriginEntryDao#getBadBalanceEntries(java.util.Collection)
253:             */
254:            public Iterator<OriginEntryFull> getBadBalanceEntries(
255:                    Collection groups) {
256:                LOG.debug("getBadBalanceEntries() started");
257:
258:                if (groups.size() <= 0) {
259:                    return null;
260:                }
261:
262:                Collection ids = new ArrayList();
263:                for (Iterator iter = groups.iterator(); iter.hasNext();) {
264:                    OriginEntryGroup element = (OriginEntryGroup) iter.next();
265:                    ids.add(element.getId());
266:                }
267:
268:                Criteria crit1 = new Criteria();
269:                crit1.addIn(ENTRY_GROUP_ID, ids);
270:
271:                Criteria crit2 = new Criteria();
272:                crit2.addIsNull(FINANCIAL_BALANCE_TYPE_CODE);
273:
274:                Criteria crit3 = new Criteria();
275:                crit3.addEqualTo(FINANCIAL_BALANCE_TYPE_CODE, "  ");
276:
277:                crit2.addOrCriteria(crit3);
278:
279:                crit1.addAndCriteria(crit2);
280:
281:                QueryByCriteria qbc = QueryFactory.newQuery(entryClass, crit1);
282:                qbc.addOrderByAscending(UNIVERSITY_FISCAL_YEAR);
283:                qbc.addOrderByAscending(CHART_OF_ACCOUNTS_CODE);
284:                qbc.addOrderByAscending(ACCOUNT_NUMBER);
285:                qbc.addOrderByAscending(FINANCIAL_OBJECT_CODE);
286:                qbc.addOrderByAscending(FINANCIAL_OBJECT_TYPE_CODE);
287:                qbc.addOrderByAscending(FINANCIAL_BALANCE_TYPE_CODE);
288:                qbc.addOrderByAscending(UNIVERSITY_FISCAL_PERIOD_CODE);
289:                qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE);
290:                qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE);
291:                qbc.addOrderByAscending(KFSPropertyConstants.DOCUMENT_NUMBER);
292:
293:                return getPersistenceBrokerTemplate().getIteratorByQuery(qbc);
294:            }
295:
296:            /**
297:             * This method is special because of the order by. It is used in the scrubber. The getMatchingEntries wouldn't work because of
298:             * the required order by.
299:             * 
300:             * @param OriginEntryGroup the originEntryGroup that holds the origin entries to find
301:             * @param sort the sort order to sort entries by, defined in OriginEntryDao
302:             * 
303:             * @return an Iterator of whichever flavor of OriginEntries this instance uses
304:             */
305:            public <T> Iterator<T> getEntriesByGroup(OriginEntryGroup oeg,
306:                    int sort) {
307:                LOG.debug("getEntriesByGroup() started");
308:
309:                // clear cache because the GLCP document class saves to the origin entry table and
310:                // reads from it (via this method) in the same transaction. If the clearCache line is
311:                // deleted, then the references to OriginEntries returned by this method will be null.
312:                getPersistenceBrokerTemplate().clearCache();
313:
314:                Criteria criteria = new Criteria();
315:                criteria.addEqualTo(ENTRY_GROUP_ID, oeg.getId());
316:
317:                QueryByCriteria qbc = QueryFactory.newQuery(entryClass,
318:                        criteria);
319:
320:                if (sort == OriginEntryDao.SORT_DOCUMENT) {
321:                    qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE);
322:                    qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE);
323:                    qbc
324:                            .addOrderByAscending(KFSPropertyConstants.DOCUMENT_NUMBER);
325:                    qbc.addOrderByAscending(CHART_OF_ACCOUNTS_CODE);
326:                    qbc.addOrderByAscending(ACCOUNT_NUMBER);
327:                    qbc.addOrderByAscending(SUB_ACCOUNT_NUMBER);
328:                    qbc.addOrderByAscending(FINANCIAL_BALANCE_TYPE_CODE);
329:                    qbc.addOrderByAscending(FINANCIAL_DOCUMENT_REVERSAL_DATE);
330:                    qbc.addOrderByAscending(UNIVERSITY_FISCAL_PERIOD_CODE);
331:                    qbc.addOrderByAscending(UNIVERSITY_FISCAL_YEAR);
332:                    // The above order by fields are required by the scrubber process. Adding these
333:                    // fields makes the data in the exact same order as the COBOL scrubber.
334:                    qbc.addOrderByAscending(FINANCIAL_OBJECT_CODE);
335:                    qbc.addOrderByAscending(FINANCIAL_SUB_OBJECT_CODE);
336:                    qbc.addOrderByAscending(FINANCIAL_BALANCE_TYPE_CODE);
337:                    qbc.addOrderByAscending(FINANCIAL_OBJECT_TYPE_CODE);
338:                    qbc.addOrderByAscending(UNIVERSITY_FISCAL_PERIOD_CODE);
339:                    qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE);
340:                    qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE);
341:                    qbc
342:                            .addOrderByAscending(KFSPropertyConstants.DOCUMENT_NUMBER);
343:                    qbc
344:                            .addOrderByAscending(TRANSACTION_LEDGER_ENTRY_SEQUENCE_NUMBER);
345:                    qbc
346:                            .addOrderByAscending(TRANSACTION_LEDGER_ENTRY_DESCRIPTION);
347:                    qbc.addOrderByAscending(TRANSACTION_LEDGER_ENTRY_AMOUNT);
348:                    qbc.addOrderByAscending(TRANSACTION_DEBIT_CREDIT_CODE);
349:                } else if (sort == OriginEntryDao.SORT_REPORT) {
350:                    qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE);
351:                    qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE);
352:                    qbc
353:                            .addOrderByAscending(KFSPropertyConstants.DOCUMENT_NUMBER);
354:                    qbc.addOrderByAscending(TRANSACTION_DEBIT_CREDIT_CODE);
355:                    qbc.addOrderByAscending(CHART_OF_ACCOUNTS_CODE);
356:                    qbc.addOrderByAscending(ACCOUNT_NUMBER);
357:                    qbc.addOrderByAscending(FINANCIAL_OBJECT_CODE);
358:                } else if (sort == OriginEntryDao.SORT_LISTING_REPORT) {
359:                    qbc.addOrderByAscending(UNIVERSITY_FISCAL_YEAR);
360:                    qbc.addOrderByAscending(CHART_OF_ACCOUNTS_CODE);
361:                    qbc.addOrderByAscending(ACCOUNT_NUMBER);
362:                    qbc.addOrderByAscending(FINANCIAL_OBJECT_CODE);
363:                    qbc.addOrderByAscending(FINANCIAL_OBJECT_TYPE_CODE);
364:                    qbc.addOrderByAscending(FINANCIAL_BALANCE_TYPE_CODE);
365:                    qbc.addOrderByAscending(UNIVERSITY_FISCAL_PERIOD_CODE);
366:                    qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE);
367:                    qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE);
368:                    qbc
369:                            .addOrderByAscending(KFSPropertyConstants.DOCUMENT_NUMBER);
370:                    qbc
371:                            .addOrderByAscending(TRANSACTION_LEDGER_ENTRY_DESCRIPTION);
372:                } else {
373:                    qbc.addOrderByAscending(CHART_OF_ACCOUNTS_CODE);
374:                    qbc.addOrderByAscending(ACCOUNT_NUMBER);
375:                    qbc.addOrderByAscending(SUB_ACCOUNT_NUMBER);
376:                    qbc.addOrderByAscending(FINANCIAL_OBJECT_CODE);
377:                    qbc.addOrderByAscending(FINANCIAL_OBJECT_TYPE_CODE);
378:                    qbc.addOrderByAscending(UNIVERSITY_FISCAL_PERIOD_CODE);
379:                    qbc.addOrderByAscending(FINANCIAL_DOCUMENT_TYPE_CODE);
380:                    qbc.addOrderByAscending(FINANCIAL_SYSTEM_ORIGINATION_CODE);
381:                    qbc
382:                            .addOrderByAscending(KFSPropertyConstants.DOCUMENT_NUMBER);
383:                    qbc
384:                            .addOrderByAscending(TRANSACTION_LEDGER_ENTRY_DESCRIPTION);
385:                }
386:
387:                return getPersistenceBrokerTemplate().getIteratorByQuery(qbc);
388:            }
389:
390:            /**
391:             * This method should only be used in unit tests. It loads all the gl_origin_entry_t rows in memory into a collection. This
392:             * won't work for production because there would be too many rows to load into memory.
393:             * 
394:             * @return a collection of OriginEntryFulls
395:             */
396:            public Collection<OriginEntryFull> testingGetAllEntries() {
397:                LOG.debug("testingGetAllEntries() started");
398:
399:                Criteria criteria = new Criteria();
400:                QueryByCriteria qbc = QueryFactory.newQuery(entryClass,
401:                        criteria);
402:                qbc.addOrderByAscending(ENTRY_GROUP_ID);
403:                qbc.addOrderByAscending(ENTRY_ID);
404:                return getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
405:            }
406:
407:            /**
408:             * Saves an origin entry to the database
409:             * 
410:             * @param entry the entry to save.
411:             */
412:            public void saveOriginEntry(OriginEntry entry) {
413:                LOG.debug("saveOriginEntry() started");
414:
415:                if ((entry != null)
416:                        && (entry.getTransactionLedgerEntryDescription() != null)
417:                        && (entry.getTransactionLedgerEntryDescription()
418:                                .length() > 40)) {
419:                    entry.setTransactionLedgerEntryDescription(entry
420:                            .getTransactionLedgerEntryDescription().substring(
421:                                    0, 40));
422:                }
423:                getPersistenceBrokerTemplate().store(entry);
424:            }
425:
426:            /**
427:             * Delete entries matching searchCriteria search criteria.
428:             * 
429:             * @param searchCriteria a map of criteria to use as keys for building a query
430:             */
431:            public void deleteMatchingEntries(Map searchCriteria) {
432:                LOG.debug("deleteMatchingEntries() started");
433:
434:                Criteria criteria = new Criteria();
435:                for (Iterator iter = searchCriteria.keySet().iterator(); iter
436:                        .hasNext();) {
437:                    String element = (String) iter.next();
438:                    criteria.addEqualTo(element, searchCriteria.get(element));
439:                }
440:
441:                QueryByCriteria qbc = QueryFactory.newQuery(entryClass,
442:                        criteria);
443:                getPersistenceBrokerTemplate().deleteByQuery(qbc);
444:
445:                // This is required because deleteByQuery leaves the cache alone so future queries
446:                // could return origin entries that don't exist. Clearing the cache makes OJB
447:                // go back to the database for everything to make sure valid data is returned.
448:                getPersistenceBrokerTemplate().clearCache();
449:            }
450:
451:            /**
452:             * Delete all the groups in the list. This will delete the entries. The OriginEntryGroupDao has a method to delete the groups,
453:             * and one has to use both to really delete the whole group
454:             * 
455:             * @param groups a Collection of Origin Entry Groups to delete entries in
456:             * @see org.kuali.module.gl.dao.OriginEntryDao#deleteGroups(java.util.Collection)
457:             */
458:            public void deleteGroups(Collection<OriginEntryGroup> groups) {
459:                LOG.debug("deleteGroups() started");
460:
461:                if (groups == null || groups.size() <= 0) {
462:                    return;
463:                }
464:
465:                List ids = new ArrayList();
466:                for (Iterator iter = groups.iterator(); iter.hasNext();) {
467:                    OriginEntryGroup element = (OriginEntryGroup) iter.next();
468:                    ids.add(element.getId());
469:                }
470:
471:                Criteria criteria = new Criteria();
472:                criteria.addIn(ENTRY_GROUP_ID, ids);
473:
474:                QueryByCriteria qbc = QueryFactory.newQuery(entryClass,
475:                        criteria);
476:                getPersistenceBrokerTemplate().deleteByQuery(qbc);
477:
478:                // This is required because deleteByQuery leaves the cache alone so future queries
479:                // could return origin entries that don't exist. Clearing the cache makes OJB
480:                // go back to the database for everything to make sure valid data is returned.
481:                getPersistenceBrokerTemplate().clearCache();
482:            }
483:
484:            /**
485:             * Collection of entries that match criteria
486:             * 
487:             * @param searchCriteria Map of field, value pairs
488:             * @return collection of entries
489:             * @see org.kuali.module.gl.dao.OriginEntryDao#getMatchingEntriesByCollection(java.util.Map)
490:             */
491:            public Collection<OriginEntryFull> getMatchingEntriesByCollection(
492:                    Map searchCriteria) {
493:                LOG.debug("getMatchingEntries() started");
494:
495:                Criteria criteria = new Criteria();
496:                for (Iterator iter = searchCriteria.keySet().iterator(); iter
497:                        .hasNext();) {
498:                    String element = (String) iter.next();
499:                    criteria.addEqualTo(element, searchCriteria.get(element));
500:                }
501:
502:                QueryByCriteria qbc = QueryFactory.newQuery(entryClass,
503:                        criteria);
504:                qbc.addOrderByAscending(ENTRY_GROUP_ID);
505:                return getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
506:            }
507:
508:            /**
509:             * get the summarized information of the entries that belong to the entry groups with the given group ids
510:             * 
511:             * @param groupIdList the ids of origin entry groups
512:             * @return a set of summarized information of the entries within the specified groups
513:             * @see org.kuali.module.gl.dao.OriginEntryDao#getSummaryByGroupId(java.util.List)
514:             */
515:            public Iterator getSummaryByGroupId(Collection groupIdList) {
516:                LOG.debug("getSummaryByGroupId() started");
517:
518:                if (groupIdList == null || groupIdList.size() <= 0) {
519:                    return null;
520:                }
521:
522:                Collection ids = new ArrayList();
523:                for (Iterator iter = groupIdList.iterator(); iter.hasNext();) {
524:                    OriginEntryGroup element = (OriginEntryGroup) iter.next();
525:                    ids.add(element.getId());
526:                }
527:
528:                Criteria criteria = new Criteria();
529:                criteria.addIn(KFSPropertyConstants.ENTRY_GROUP_ID, ids);
530:
531:                ReportQueryByCriteria query = QueryFactory.newReportQuery(
532:                        entryClass, criteria);
533:
534:                String attributeList[] = {
535:                        KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
536:                        KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE,
537:                        KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE,
538:                        KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE,
539:                        KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE,
540:                        "sum("
541:                                + KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT
542:                                + ")", "count(*)" };
543:
544:                String groupList[] = {
545:                        KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
546:                        KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE,
547:                        KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE,
548:                        KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE,
549:                        KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE };
550:
551:                query.setAttributes(attributeList);
552:                query.addGroupBy(groupList);
553:
554:                // add the sorting criteria
555:                for (int i = 0; i < groupList.length; i++) {
556:                    query.addOrderByAscending(groupList[i]);
557:                }
558:
559:                return getPersistenceBrokerTemplate()
560:                        .getReportQueryIteratorByQuery(query);
561:            }
562:
563:            /**
564:             * Fetches an entry for the given entryId, or returns a newly created on
565:             * 
566:             * @param entryId an entry id to find an entry for
567:             * @return the entry for the given entry id, or a newly created entry
568:             * @see org.kuali.module.gl.dao.OriginEntryDao#getExactMatchingEntry(java.lang.Integer)
569:             */
570:            public OriginEntryFull getExactMatchingEntry(Integer entryId) {
571:                LOG.debug("getMatchingEntries() started");
572:                OriginEntryFull oe = new OriginEntryFull();
573:                // in case of no matching entry
574:                try {
575:                    oe = (OriginEntryFull) getPersistenceBrokerTemplate()
576:                            .getObjectById(entryClass, entryId);
577:
578:                } catch (Exception e) {
579:                }
580:
581:                return oe;
582:            }
583:
584:            /**
585:             * get the summarized information of poster input entries that belong to the entry groups with the given group id list
586:             * 
587:             * @param groups the origin entry groups
588:             * @return a set of summarized information of poster input entries within the specified groups
589:             * @see org.kuali.module.gl.dao.OriginEntryDao#getPosterOutputSummaryByGroupId(java.util.Collection)
590:             */
591:            public Iterator getPosterOutputSummaryByGroupId(Collection groups) {
592:                LOG.debug("getPosterInputSummaryByGroupId() started");
593:
594:                if (groups == null || groups.size() <= 0) {
595:                    return null;
596:                }
597:
598:                Collection ids = new ArrayList();
599:                for (Iterator iter = groups.iterator(); iter.hasNext();) {
600:                    OriginEntryGroup element = (OriginEntryGroup) iter.next();
601:                    ids.add(element.getId());
602:                }
603:
604:                Criteria criteria = new Criteria();
605:                criteria.addIn(KFSPropertyConstants.ENTRY_GROUP_ID, ids);
606:                String fundGroupCode = KFSPropertyConstants.ACCOUNT + "."
607:                        + KFSPropertyConstants.SUB_FUND_GROUP + "."
608:                        + KFSPropertyConstants.FUND_GROUP_CODE;
609:
610:                ReportQueryByCriteria query = QueryFactory.newReportQuery(
611:                        entryClass, criteria);
612:
613:                String attributeList[] = {
614:                        KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE,
615:                        KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
616:                        KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE,
617:                        fundGroupCode,
618:                        KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE,
619:                        KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE,
620:                        "sum("
621:                                + KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT
622:                                + ")" };
623:
624:                String groupList[] = {
625:                        KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE,
626:                        KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
627:                        KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE,
628:                        fundGroupCode,
629:                        KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE,
630:                        KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE };
631:
632:                query.setAttributes(attributeList);
633:                query.addGroupBy(groupList);
634:
635:                // add the sorting criteria
636:                for (int i = 0; i < groupList.length; i++) {
637:                    query.addOrderByAscending(groupList[i]);
638:                }
639:
640:                return getPersistenceBrokerTemplate()
641:                        .getReportQueryIteratorByQuery(query);
642:            }
643:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.