Source Code Cross Referenced for BalanceDaoOjb.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) 


0001:        /*
0002:         * Copyright 2005-2007 The Kuali Foundation.
0003:         * 
0004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
0005:         * you may not use this file except in compliance with the License.
0006:         * You may obtain a copy of the License at
0007:         * 
0008:         * http://www.opensource.org/licenses/ecl1.php
0009:         * 
0010:         * Unless required by applicable law or agreed to in writing, software
0011:         * distributed under the License is distributed on an "AS IS" BASIS,
0012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013:         * See the License for the specific language governing permissions and
0014:         * limitations under the License.
0015:         */
0016:        package org.kuali.module.gl.dao.ojb;
0017:
0018:        import java.util.ArrayList;
0019:        import java.util.Arrays;
0020:        import java.util.Collection;
0021:        import java.util.HashMap;
0022:        import java.util.Iterator;
0023:        import java.util.List;
0024:        import java.util.Map;
0025:        import java.util.TreeMap;
0026:
0027:        import org.apache.commons.lang.StringUtils;
0028:        import org.apache.ojb.broker.query.Criteria;
0029:        import org.apache.ojb.broker.query.Query;
0030:        import org.apache.ojb.broker.query.QueryByCriteria;
0031:        import org.apache.ojb.broker.query.QueryFactory;
0032:        import org.apache.ojb.broker.query.ReportQueryByCriteria;
0033:        import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
0034:        import org.kuali.core.util.KualiDecimal;
0035:        import org.kuali.kfs.KFSConstants;
0036:        import org.kuali.kfs.KFSPropertyConstants;
0037:        import org.kuali.kfs.bo.Options;
0038:        import org.kuali.kfs.context.SpringContext;
0039:        import org.kuali.kfs.service.OptionsService;
0040:        import org.kuali.kfs.service.ParameterEvaluator;
0041:        import org.kuali.kfs.service.ParameterService;
0042:        import org.kuali.module.chart.bo.Account;
0043:        import org.kuali.module.chart.bo.OrganizationReversion;
0044:        import org.kuali.module.chart.service.BalanceTypService;
0045:        import org.kuali.module.chart.service.ObjectTypeService;
0046:        import org.kuali.module.chart.service.SubFundGroupService;
0047:        import org.kuali.module.gl.GLConstants;
0048:        import org.kuali.module.gl.batch.BalanceForwardStep;
0049:        import org.kuali.module.gl.batch.closing.year.service.FilteringBalanceIterator;
0050:        import org.kuali.module.gl.bo.Balance;
0051:        import org.kuali.module.gl.bo.SufficientFundBalances;
0052:        import org.kuali.module.gl.bo.Transaction;
0053:        import org.kuali.module.gl.dao.BalanceDao;
0054:        import org.kuali.module.gl.util.OJBUtility;
0055:
0056:        /**
0057:         * An OJB implementation of BalanceDao
0058:         */
0059:        public class BalanceDaoOjb extends PlatformAwareDaoBaseOjb implements 
0060:                BalanceDao {
0061:            private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
0062:                    .getLogger(BalanceDaoOjb.class);
0063:            private ParameterService parameterService;
0064:            private OptionsService optionsService;
0065:            private BalanceTypService balanceTypService;
0066:
0067:            /**
0068:             * Does a ReportQuery to summarize GL balance data
0069:             * 
0070:             * @param universityFiscalYear the fiscal year of balances to search for
0071:             * @param balanceTypeCodes a list of balance type codes of balances to search for
0072:             * @return iterator of reported on java.lang.Object arrays with the report data
0073:             * @see org.kuali.module.gl.dao.BalanceDao#getGlSummary(int, java.util.List)
0074:             */
0075:            public Iterator getGlSummary(int universityFiscalYear,
0076:                    List<String> balanceTypeCodes) {
0077:                LOG.debug("getGlSummary() started");
0078:
0079:                Criteria c = new Criteria();
0080:                c.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
0081:                        universityFiscalYear);
0082:                c.addIn(KFSPropertyConstants.BALANCE_TYPE_CODE,
0083:                        balanceTypeCodes);
0084:
0085:                String[] attributes = new String[] {
0086:                        "account.subFundGroup.fundGroupCode",
0087:                        "sum(accountLineAnnualBalanceAmount)",
0088:                        "sum(beginningBalanceLineAmount)",
0089:                        "sum(contractsGrantsBeginningBalanceAmount)",
0090:                        "sum(month1Amount)", "sum(month2Amount)",
0091:                        "sum(month3Amount)", "sum(month4Amount)",
0092:                        "sum(month5Amount)", "sum(month6Amount)",
0093:                        "sum(month7Amount)", "sum(month8Amount)",
0094:                        "sum(month9Amount)", "sum(month10Amount)",
0095:                        "sum(month11Amount)", "sum(month12Amount)",
0096:                        "sum(month13Amount)" };
0097:
0098:                String[] groupby = new String[] { "account.subFundGroup.fundGroupCode" };
0099:
0100:                ReportQueryByCriteria query = new ReportQueryByCriteria(
0101:                        Balance.class, c);
0102:
0103:                query.setAttributes(attributes);
0104:                query.addGroupBy(groupby);
0105:                query.addOrderByAscending("account.subFundGroup.fundGroupCode");
0106:
0107:                return getPersistenceBrokerTemplate()
0108:                        .getReportQueryIteratorByQuery(query);
0109:            }
0110:
0111:            /**
0112:             * Queries the database for all the balances for a given fiscal year
0113:             * 
0114:             * @param year the university fiscal year of balances to return
0115:             * @return an iterator over all balances for a given fiscal year
0116:             * @see org.kuali.module.gl.dao.BalanceDao#findBalancesForFiscalYear(java.lang.Integer)
0117:             */
0118:            public Iterator<Balance> findBalancesForFiscalYear(Integer year) {
0119:                LOG.debug("findBalancesForFiscalYear() started");
0120:
0121:                Criteria c = new Criteria();
0122:                c.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
0123:
0124:                QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
0125:                query
0126:                        .addOrderByAscending(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
0127:                query.addOrderByAscending(KFSPropertyConstants.ACCOUNT_NUMBER);
0128:                query
0129:                        .addOrderByAscending(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
0130:                query.addOrderByAscending(KFSPropertyConstants.OBJECT_CODE);
0131:                query.addOrderByAscending(KFSPropertyConstants.SUB_OBJECT_CODE);
0132:                query
0133:                        .addOrderByAscending(KFSPropertyConstants.BALANCE_TYPE_CODE);
0134:                query
0135:                        .addOrderByAscending(KFSPropertyConstants.OBJECT_TYPE_CODE);
0136:
0137:                return getPersistenceBrokerTemplate().getIteratorByQuery(query);
0138:            }
0139:
0140:            /**
0141:             * Saves a balance
0142:             * @param b a balance to save
0143:             * @see org.kuali.module.gl.dao.BalanceDao#save(org.kuali.module.gl.bo.Balance)
0144:             */
0145:            public void save(Balance b) {
0146:                LOG.debug("save() started");
0147:
0148:                getPersistenceBrokerTemplate().store(b);
0149:            }
0150:
0151:            /**
0152:             * Using values from the transaction as keys, lookup the balance the transaction would affect were it posted
0153:             * 
0154:             * @t a transaction to look up the related balance for
0155:             * @return a Balance that the given transaction would affect
0156:             * @see org.kuali.module.gl.dao.BalanceDao#getBalanceByTransaction(org.kuali.module.gl.bo.Transaction)
0157:             */
0158:            public Balance getBalanceByTransaction(Transaction t) {
0159:                LOG.debug("getBalanceByTransaction() started");
0160:
0161:                Criteria crit = new Criteria();
0162:                crit.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, t
0163:                        .getUniversityFiscalYear());
0164:                crit.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, t
0165:                        .getChartOfAccountsCode());
0166:                crit.addEqualTo(KFSPropertyConstants.ACCOUNT_NUMBER, t
0167:                        .getAccountNumber());
0168:                crit.addEqualTo(KFSPropertyConstants.SUB_ACCOUNT_NUMBER, t
0169:                        .getSubAccountNumber());
0170:                crit.addEqualTo(KFSPropertyConstants.OBJECT_CODE, t
0171:                        .getFinancialObjectCode());
0172:                crit.addEqualTo(KFSPropertyConstants.SUB_OBJECT_CODE, t
0173:                        .getFinancialSubObjectCode());
0174:                crit.addEqualTo(KFSPropertyConstants.BALANCE_TYPE_CODE, t
0175:                        .getFinancialBalanceTypeCode());
0176:                crit.addEqualTo(KFSPropertyConstants.OBJECT_TYPE_CODE, t
0177:                        .getFinancialObjectTypeCode());
0178:
0179:                QueryByCriteria qbc = QueryFactory
0180:                        .newQuery(Balance.class, crit);
0181:                return (Balance) getPersistenceBrokerTemplate()
0182:                        .getObjectByQuery(qbc);
0183:            }
0184:
0185:            /**
0186:             * This method adds to the given criteria if the given collection is non-empty. It uses an EQUALS if there is exactly one
0187:             * element in the collection; otherwise, its uses an IN
0188:             * 
0189:             * @param criteria - the criteria that might have a criterion appended
0190:             * @param name - name of the attribute
0191:             * @param collection - the collection to inspect
0192:             */
0193:            private void criteriaBuilder(Criteria criteria, String name,
0194:                    Collection collection) {
0195:                criteriaBuilderHelper(criteria, name, collection, false);
0196:            }
0197:
0198:            /**
0199:             * Similar to criteriaBuilder, this adds a negative criterion (NOT EQUALS, NOT IN)
0200:             * 
0201:             * @param criteria - the criteria that might have a criterion appended
0202:             * @param name - name of the attribute
0203:             * @param collection - the collection to inspect
0204:             */
0205:            private void negatedCriteriaBuilder(Criteria criteria, String name,
0206:                    Collection collection) {
0207:                criteriaBuilderHelper(criteria, name, collection, true);
0208:            }
0209:
0210:            /**
0211:             * This method provides the implementation for the conveniences methods criteriaBuilder & negatedCriteriaBuilder
0212:             * 
0213:             * @param criteria - the criteria that might have a criterion appended
0214:             * @param name - name of the attribute
0215:             * @param collection - the collection to inspect
0216:             * @param negate - the criterion will be negated (NOT EQUALS, NOT IN) when this is true
0217:             */
0218:            private void criteriaBuilderHelper(Criteria criteria, String name,
0219:                    Collection collection, boolean negate) {
0220:                if (collection != null) {
0221:                    int size = collection.size();
0222:                    if (size == 1) {
0223:                        if (negate) {
0224:                            criteria.addNotEqualTo(name, collection.iterator()
0225:                                    .next());
0226:                        } else {
0227:                            criteria.addEqualTo(name, collection.iterator()
0228:                                    .next());
0229:                        }
0230:                    }
0231:                    if (size > 1) {
0232:                        if (negate) {
0233:                            criteria.addNotIn(name, collection);
0234:                        } else {
0235:                            criteria.addIn(name, collection);
0236:
0237:                        }
0238:                    }
0239:                }
0240:
0241:            }
0242:
0243:            /**
0244:             * Build a query based on all the parameters, and return an Iterator of all Balances from the database that qualify
0245:             * 
0246:             * @param account the account of balances to find
0247:             * @param fiscalYear the fiscal year of balances to find
0248:             * @param includedObjectCodes a Collection of object codes found balances should have one of
0249:             * @param excludedObjectCodes a Collection of object codes found balances should not have one of
0250:             * @param objectTypeCodes a Collection of object type codes found balances should have one of
0251:             * @param balanceTypeCodes a Collection of balance type codes found balances should have one of
0252:             * @return an Iterator of Balances
0253:             * @see org.kuali.module.gl.dao.BalanceDao#findBalances(org.kuali.module.chart.bo.Account, java.lang.Integer, java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection)
0254:             */
0255:            public Iterator<Balance> findBalances(Account account,
0256:                    Integer fiscalYear, Collection includedObjectCodes,
0257:                    Collection excludedObjectCodes, Collection objectTypeCodes,
0258:                    Collection balanceTypeCodes) {
0259:                LOG.debug("findBalances() started");
0260:
0261:                Criteria criteria = new Criteria();
0262:
0263:                criteria.addEqualTo(KFSPropertyConstants.ACCOUNT_NUMBER,
0264:                        account.getAccountNumber());
0265:                criteria.addEqualTo(
0266:                        KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, account
0267:                                .getChartOfAccountsCode());
0268:
0269:                criteria
0270:                        .addEqualTo(
0271:                                KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
0272:                                fiscalYear);
0273:
0274:                criteriaBuilder(criteria,
0275:                        GLConstants.ColumnNames.OBJECT_TYPE_CODE,
0276:                        objectTypeCodes);
0277:                criteriaBuilder(criteria,
0278:                        GLConstants.ColumnNames.BALANCE_TYPE_CODE,
0279:                        balanceTypeCodes);
0280:                criteriaBuilder(criteria, GLConstants.ColumnNames.OBJECT_CODE,
0281:                        includedObjectCodes);
0282:                negatedCriteriaBuilder(criteria,
0283:                        GLConstants.ColumnNames.OBJECT_CODE,
0284:                        excludedObjectCodes);
0285:
0286:                ReportQueryByCriteria query = new ReportQueryByCriteria(
0287:                        Balance.class, criteria);
0288:
0289:                // returns an iterator of all matching balances
0290:                Iterator balances = getPersistenceBrokerTemplate()
0291:                        .getIteratorByQuery(query);
0292:                return balances;
0293:            }
0294:
0295:            /**
0296:             * Using the given fieldValues as keys, return all cash balance records
0297:             * 
0298:             * @param fieldValues the input fields and values
0299:             * @param isConsolidated consolidation option is applied or not
0300:             * @return the records of cash balance entries
0301:             * @see org.kuali.module.gl.dao.BalanceDao#findCashBalance(java.util.Map, boolean)
0302:             */
0303:            public Iterator<Balance> findCashBalance(Map fieldValues,
0304:                    boolean isConsolidated) {
0305:                LOG.debug("findCashBalance() started");
0306:
0307:                Query query = this .getCashBalanceQuery(fieldValues,
0308:                        isConsolidated);
0309:                OJBUtility.limitResultSize(query);
0310:                return getPersistenceBrokerTemplate()
0311:                        .getReportQueryIteratorByQuery(query);
0312:            }
0313:
0314:            /**
0315:             * Get the number of detailed cash balance records that would be returned, were we to do a query based on the given fieldValues
0316:             * 
0317:             * @param fieldValues the input fields and values
0318:             * @param isConsolidated consolidation option is applied or not
0319:             * @return the size collection of cash balance entry groups
0320:             * @see org.kuali.module.gl.dao.BalanceDao#getCashBalanceRecordCount(java.util.Map, boolean)
0321:             */
0322:            public Integer getDetailedCashBalanceRecordCount(Map fieldValues) {
0323:                LOG.debug("getDetailedCashBalanceRecordCount() started");
0324:
0325:                Query query = this .getCashBalanceQuery(fieldValues, false);
0326:                return getPersistenceBrokerTemplate().getCount(query);
0327:            }
0328:
0329:            /**
0330:             * Given a map of keys, return all of the report data about qualifying cash balances
0331:             * 
0332:             * @param fieldValues the input fields and values
0333:             * @return the size collection of cash balance entry groups
0334:             * @see org.kuali.module.gl.dao.BalanceDao#getCashBalanceRecordSize(java.util.Map, boolean)
0335:             */
0336:            public Iterator getConsolidatedCashBalanceRecordCount(
0337:                    Map fieldValues) {
0338:                LOG.debug("getCashBalanceRecordCount() started");
0339:
0340:                ReportQueryByCriteria query = this 
0341:                        .getCashBalanceCountQuery(fieldValues);
0342:                return getPersistenceBrokerTemplate()
0343:                        .getReportQueryIteratorByQuery(query);
0344:            }
0345:
0346:            /**
0347:             * Given a map of values, build a query out of those and find all the balances that qualify
0348:             * 
0349:             * @param fieldValues a Map of fieldValues to use as keys in the query
0350:             * @param isConsolidated should the results be consolidated?
0351:             * @return an Iterator of Balances
0352:             * @see org.kuali.module.gl.dao.BalanceDao#findBalance(java.util.Map, boolean)
0353:             */
0354:            public Iterator<Balance> findBalance(Map fieldValues,
0355:                    boolean isConsolidated) {
0356:                LOG.debug("findBalance() started");
0357:
0358:                Query query = this .getBalanceQuery(fieldValues, isConsolidated);
0359:                OJBUtility.limitResultSize(query);
0360:
0361:                if (isConsolidated) {
0362:                    return getPersistenceBrokerTemplate()
0363:                            .getReportQueryIteratorByQuery(query);
0364:                }
0365:                return getPersistenceBrokerTemplate().getIteratorByQuery(query);
0366:            }
0367:
0368:            /**
0369:             * Given a Map of keys to use as a query, if we performed that query as a consolidated query...
0370:             * how many records would we get back?
0371:             * 
0372:             * @param fieldValues a Map of values to use as keys to build the query
0373:             * @return an Iterator of counts...
0374:             * @see org.kuali.module.gl.dao.BalanceDao#getConsolidatedBalanceRecordCount(java.util.Map)
0375:             */
0376:            public Iterator getConsolidatedBalanceRecordCount(Map fieldValues) {
0377:                LOG.debug("getBalanceRecordCount() started");
0378:
0379:                ReportQueryByCriteria query = this 
0380:                        .getBalanceCountQuery(fieldValues);
0381:                return getPersistenceBrokerTemplate()
0382:                        .getReportQueryIteratorByQuery(query);
0383:            }
0384:
0385:            /**
0386:             * Builds a query for cash balances, based on the given field values
0387:             * 
0388:             * @param fieldValues a map of keys to use when building the query
0389:             * @return an OJB ReportQuery to use as the query 
0390:             */
0391:            private ReportQueryByCriteria getCashBalanceCountQuery(
0392:                    Map fieldValues) {
0393:                Criteria criteria = buildCriteriaFromMap(fieldValues,
0394:                        new Balance());
0395:                criteria.addEqualTo(KFSPropertyConstants.BALANCE_TYPE_CODE,
0396:                        KFSConstants.BALANCE_TYPE_ACTUAL);
0397:                criteria.addEqualToField("chart.financialCashObjectCode",
0398:                        KFSPropertyConstants.OBJECT_CODE);
0399:
0400:                ReportQueryByCriteria query = QueryFactory.newReportQuery(
0401:                        Balance.class, criteria);
0402:
0403:                List groupByList = buildGroupByList();
0404:                groupByList.remove(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
0405:                groupByList.remove(KFSPropertyConstants.SUB_OBJECT_CODE);
0406:                groupByList.remove(KFSPropertyConstants.OBJECT_TYPE_CODE);
0407:
0408:                // add the group criteria into the selection statement
0409:                String[] groupBy = (String[]) groupByList
0410:                        .toArray(new String[groupByList.size()]);
0411:                query.addGroupBy(groupBy);
0412:
0413:                // set the selection attributes
0414:                query.setAttributes(new String[] { "count(*)" });
0415:
0416:                return query;
0417:            }
0418:
0419:            /**
0420:             * build the query for cash balance search
0421:             * 
0422:             * @param fieldValues Map of keys to use for the query
0423:             * @param isConsolidated should the results be consolidated?
0424:             * @return the OJB query to perform
0425:             */
0426:            private Query getCashBalanceQuery(Map fieldValues,
0427:                    boolean isConsolidated) {
0428:                Criteria criteria = buildCriteriaFromMap(fieldValues,
0429:                        new Balance());
0430:                criteria.addEqualTo(KFSPropertyConstants.BALANCE_TYPE_CODE,
0431:                        KFSConstants.BALANCE_TYPE_ACTUAL);
0432:                criteria.addEqualToField("chart.financialCashObjectCode",
0433:                        KFSPropertyConstants.OBJECT_CODE);
0434:
0435:                ReportQueryByCriteria query = QueryFactory.newReportQuery(
0436:                        Balance.class, criteria);
0437:                List attributeList = buildAttributeList(false);
0438:                List groupByList = buildGroupByList();
0439:
0440:                // if consolidated, then ignore the following fields
0441:                if (isConsolidated) {
0442:                    attributeList
0443:                            .remove(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
0444:                    groupByList.remove(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
0445:                    attributeList.remove(KFSPropertyConstants.SUB_OBJECT_CODE);
0446:                    groupByList.remove(KFSPropertyConstants.SUB_OBJECT_CODE);
0447:                    attributeList.remove(KFSPropertyConstants.OBJECT_TYPE_CODE);
0448:                    groupByList.remove(KFSPropertyConstants.OBJECT_TYPE_CODE);
0449:                }
0450:
0451:                // add the group criteria into the selection statement
0452:                String[] groupBy = (String[]) groupByList
0453:                        .toArray(new String[groupByList.size()]);
0454:                query.addGroupBy(groupBy);
0455:
0456:                // set the selection attributes
0457:                String[] attributes = (String[]) attributeList
0458:                        .toArray(new String[attributeList.size()]);
0459:                query.setAttributes(attributes);
0460:
0461:                return query;
0462:            }
0463:
0464:            /**
0465:             * build the query for balance search
0466:             * 
0467:             * @param fieldValues Map of keys to use for the query
0468:             * @param isConsolidated should the results be consolidated?
0469:             * @return an OJB query to perform
0470:             */
0471:            private Query getBalanceQuery(Map fieldValues,
0472:                    boolean isConsolidated) {
0473:                LOG.debug("getBalanceQuery(Map, boolean) started");
0474:
0475:                Criteria criteria = buildCriteriaFromMap(fieldValues,
0476:                        new Balance());
0477:                ReportQueryByCriteria query = QueryFactory.newReportQuery(
0478:                        Balance.class, criteria);
0479:
0480:                // if consolidated, then ignore subaccount number and balance type code
0481:                if (isConsolidated) {
0482:                    List attributeList = buildAttributeList(true);
0483:                    List groupByList = buildGroupByList();
0484:
0485:                    // ignore subaccount number, sub object code and object type code
0486:                    attributeList
0487:                            .remove(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
0488:                    groupByList.remove(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
0489:                    attributeList.remove(KFSPropertyConstants.SUB_OBJECT_CODE);
0490:                    groupByList.remove(KFSPropertyConstants.SUB_OBJECT_CODE);
0491:                    attributeList.remove(KFSPropertyConstants.OBJECT_TYPE_CODE);
0492:                    groupByList.remove(KFSPropertyConstants.OBJECT_TYPE_CODE);
0493:
0494:                    // set the selection attributes
0495:                    String[] attributes = (String[]) attributeList
0496:                            .toArray(new String[attributeList.size()]);
0497:                    query.setAttributes(attributes);
0498:
0499:                    // add the group criteria into the selection statement
0500:                    String[] groupBy = (String[]) groupByList
0501:                            .toArray(new String[groupByList.size()]);
0502:                    query.addGroupBy(groupBy);
0503:                }
0504:
0505:                return query;
0506:            }
0507:
0508:            /**
0509:             * build the query for balance search
0510:             * 
0511:             * @param fieldValues Map of keys to use for the query
0512:             * @return an OJB ReportQuery to perform
0513:             */
0514:            private ReportQueryByCriteria getBalanceCountQuery(Map fieldValues) {
0515:                Criteria criteria = buildCriteriaFromMap(fieldValues,
0516:                        new Balance());
0517:                ReportQueryByCriteria query = QueryFactory.newReportQuery(
0518:                        Balance.class, criteria);
0519:
0520:                // set the selection attributes
0521:                query.setAttributes(new String[] { "count(*)" });
0522:
0523:                List groupByList = buildGroupByList();
0524:                groupByList.remove(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
0525:                groupByList.remove(KFSPropertyConstants.SUB_OBJECT_CODE);
0526:                groupByList.remove(KFSPropertyConstants.OBJECT_TYPE_CODE);
0527:
0528:                // add the group criteria into the selection statement
0529:                String[] groupBy = (String[]) groupByList
0530:                        .toArray(new String[groupByList.size()]);
0531:                query.addGroupBy(groupBy);
0532:                return query;
0533:            }
0534:
0535:            /**
0536:             * This method builds the query criteria based on the input field map
0537:             * 
0538:             * @param fieldValues Map of keys to use for the query
0539:             * @param balance this really usen't used in the method 
0540:             * @return a query criteria
0541:             */
0542:            private Criteria buildCriteriaFromMap(Map fieldValues,
0543:                    Balance balance) {
0544:                Map localFieldValues = new HashMap();
0545:                localFieldValues.putAll(fieldValues);
0546:
0547:                Criteria criteria = new Criteria();
0548:
0549:                // handle encumbrance balance type
0550:                String propertyName = KFSPropertyConstants.BALANCE_TYPE_CODE;
0551:                if (localFieldValues.containsKey(propertyName)) {
0552:                    String propertyValue = (String) localFieldValues
0553:                            .get(propertyName);
0554:                    if (KFSConstants.AGGREGATE_ENCUMBRANCE_BALANCE_TYPE_CODE
0555:                            .equals(propertyValue)) {
0556:                        localFieldValues
0557:                                .remove(KFSPropertyConstants.BALANCE_TYPE_CODE);
0558:
0559:                        // the year should be part of the results for both the cash balance and regular balance lookupables
0560:                        String universityFiscalYearStr = (String) localFieldValues
0561:                                .get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
0562:                        Integer universityFiscalYear = new Integer(
0563:                                universityFiscalYearStr);
0564:
0565:                        criteria
0566:                                .addIn(
0567:                                        KFSPropertyConstants.BALANCE_TYPE_CODE,
0568:                                        balanceTypService
0569:                                                .getEncumbranceBalanceTypes(universityFiscalYear));
0570:                    }
0571:                }
0572:
0573:                criteria.addAndCriteria(OJBUtility.buildCriteriaFromMap(
0574:                        localFieldValues, new Balance()));
0575:                return criteria;
0576:            }
0577:
0578:            /**
0579:             * This method builds the atrribute list used by balance searching
0580:             * 
0581:             * @param isExtended should we add the attributes to sum each of the monthly totals?
0582:             * @return List an attribute list
0583:             */
0584:            private List<String> buildAttributeList(boolean isExtended) {
0585:                List attributeList = this .buildGroupByList();
0586:
0587:                attributeList.add("sum(accountLineAnnualBalanceAmount)");
0588:                attributeList.add("sum(beginningBalanceLineAmount)");
0589:                attributeList.add("sum(contractsGrantsBeginningBalanceAmount)");
0590:
0591:                // add the entended elements into the list
0592:                if (isExtended) {
0593:                    attributeList.add("sum(month1Amount)");
0594:                    attributeList.add("sum(month2Amount)");
0595:                    attributeList.add("sum(month3Amount)");
0596:                    attributeList.add("sum(month4Amount)");
0597:                    attributeList.add("sum(month5Amount)");
0598:                    attributeList.add("sum(month6Amount)");
0599:                    attributeList.add("sum(month7Amount)");
0600:                    attributeList.add("sum(month8Amount)");
0601:                    attributeList.add("sum(month9Amount)");
0602:                    attributeList.add("sum(month10Amount)");
0603:                    attributeList.add("sum(month11Amount)");
0604:                    attributeList.add("sum(month12Amount)");
0605:                    attributeList.add("sum(month13Amount)");
0606:                }
0607:                return attributeList;
0608:            }
0609:
0610:            /**
0611:             * This method builds group by attribute list used by balance searching
0612:             * 
0613:             * @return List an group by attribute list
0614:             */
0615:            private List<String> buildGroupByList() {
0616:                List attributeList = new ArrayList();
0617:
0618:                attributeList.add(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
0619:                attributeList.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
0620:                attributeList.add(KFSPropertyConstants.ACCOUNT_NUMBER);
0621:                attributeList.add(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
0622:                attributeList.add(KFSPropertyConstants.BALANCE_TYPE_CODE);
0623:                attributeList.add(KFSPropertyConstants.OBJECT_CODE);
0624:                attributeList.add(KFSPropertyConstants.SUB_OBJECT_CODE);
0625:                attributeList.add(KFSPropertyConstants.OBJECT_TYPE_CODE);
0626:
0627:                return attributeList;
0628:            }
0629:
0630:            /**
0631:             * Whoa!  This method is seemingly not called in the code base right now, and you know what?  You shouldn't call it
0632:             * First of all, we're not even sending in all the primary keys for Balance, and second of all, we're
0633:             * returning a SufficientFundsBalance, which we cast to a Balance, which is *always* going to throw a 
0634:             * ClassCastException.  Don't call this method.  Just...just step away.
0635:             * 
0636:             * @see org.kuali.module.gl.dao.BalanceDao#getBalanceByPrimaryId(java.lang.Integer, java.lang.String, java.lang.String)
0637:             */
0638:            public Balance getBalanceByPrimaryId(Integer universityFiscalYear,
0639:                    String chartOfAccountsCode, String accountNumber) {
0640:                // TODO just kill this
0641:                LOG.debug("getBalanceByPrimaryId() started");
0642:
0643:                Criteria crit = new Criteria();
0644:                crit.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
0645:                        universityFiscalYear);
0646:                crit.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
0647:                        chartOfAccountsCode);
0648:                crit.addEqualTo(KFSPropertyConstants.ACCOUNT_NUMBER,
0649:                        accountNumber);
0650:
0651:                QueryByCriteria qbc = QueryFactory.newQuery(
0652:                        SufficientFundBalances.class, crit);
0653:                return (Balance) getPersistenceBrokerTemplate()
0654:                        .getObjectByQuery(qbc);
0655:            }
0656:
0657:            /**
0658:             * Since SubAccountNumber, SubObjectCode, and ObjectType are all part of the primary key of Balance, you're guaranteed to get one of those
0659:             * records when you call this method.  Let's hope the right one.
0660:             * 
0661:             * @param universityFiscalYear the fiscal year of the CB balance to return
0662:             * @param chartOfAccountsCode the chart of the accounts code of the CB balanes to return
0663:             * @param accountNumber the account number of the CB balance to return
0664:             * @param objectCode the object code of the CB balance to return
0665:             * @return the CB Balance record
0666:             * @see org.kuali.module.gl.dao.BalanceDao#getCurrentBudgetForObjectCode(java.lang.Integer, java.lang.String, java.lang.String,
0667:             *      java.lang.String)
0668:             */
0669:            public Balance getCurrentBudgetForObjectCode(
0670:                    Integer universityFiscalYear, String chartOfAccountsCode,
0671:                    String accountNumber, String objectCode) {
0672:                LOG.debug("getCurrentBudgetForObjectCode() started");
0673:
0674:                Criteria crit = new Criteria();
0675:                crit.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
0676:                        universityFiscalYear);
0677:                crit.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
0678:                        chartOfAccountsCode);
0679:                crit.addEqualTo(KFSPropertyConstants.ACCOUNT_NUMBER,
0680:                        accountNumber);
0681:                crit.addEqualTo(KFSPropertyConstants.OBJECT_CODE, objectCode);
0682:                crit.addEqualTo(KFSPropertyConstants.BALANCE_TYPE_CODE,
0683:                        KFSConstants.BALANCE_TYPE_CURRENT_BUDGET);
0684:
0685:                QueryByCriteria qbc = QueryFactory
0686:                        .newQuery(Balance.class, crit);
0687:                return (Balance) getPersistenceBrokerTemplate()
0688:                        .getObjectByQuery(qbc);
0689:            }
0690:
0691:            /**
0692:             * Find all matching account balances.
0693:             * 
0694:             * @param universityFiscalYear the university fiscal year of balances to return
0695:             * @param chartOfAccountsCode the chart of accounts code of balances to return
0696:             * @param accountNumber the account number of balances to return
0697:             * @return balances sorted by object code
0698:             */
0699:            public Iterator<Balance> findAccountBalances(
0700:                    Integer universityFiscalYear, String chartOfAccountsCode,
0701:                    String accountNumber) {
0702:                LOG.debug("findAccountBalances() started");
0703:                return this .findAccountBalances(universityFiscalYear,
0704:                        chartOfAccountsCode, accountNumber,
0705:                        KFSConstants.SF_TYPE_OBJECT);
0706:            }
0707:
0708:            /**
0709:             * Find all matching account balances. The Sufficient funds code is used to determine the sort of the results.
0710:             * 
0711:             * @param universityFiscalYear the university fiscal year of balances to return
0712:             * @param chartOfAccountsCode the chart of accounts code of balances to return
0713:             * @param accountNumber the account number of balances to return
0714:             * @param sfCode the sufficient funds code, used to sort on
0715:             * @return an Iterator of balances
0716:             */
0717:            public Iterator<Balance> findAccountBalances(
0718:                    Integer universityFiscalYear, String chartOfAccountsCode,
0719:                    String accountNumber, String sfCode) {
0720:                LOG.debug("findAccountBalances() started");
0721:
0722:                Criteria crit = new Criteria();
0723:                crit.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
0724:                        universityFiscalYear);
0725:                crit.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
0726:                        chartOfAccountsCode);
0727:                crit.addEqualTo(KFSPropertyConstants.ACCOUNT_NUMBER,
0728:                        accountNumber);
0729:
0730:                QueryByCriteria qbc = QueryFactory
0731:                        .newQuery(Balance.class, crit);
0732:                if (KFSConstants.SF_TYPE_OBJECT.equals(sfCode)) {
0733:                    qbc.addOrderByAscending(KFSPropertyConstants.OBJECT_CODE);
0734:                } else if (KFSConstants.SF_TYPE_LEVEL.equals(sfCode)) {
0735:                    qbc
0736:                            .addOrderByAscending(GLConstants.BalanceInquiryDrillDowns.OBJECT_LEVEL_CODE);
0737:                } else if (KFSConstants.SF_TYPE_CONSOLIDATION.equals(sfCode)) {
0738:                    qbc
0739:                            .addOrderByAscending(GLConstants.BalanceInquiryDrillDowns.CONSOLIDATION_OBJECT_CODE);
0740:                }
0741:                return getPersistenceBrokerTemplate().getIteratorByQuery(qbc);
0742:            }
0743:
0744:            /**
0745:             * Purge the sufficient funds balance table by year/chart
0746:             * 
0747:             * @param chart the chart of balances to purge
0748:             * @param year the university fiscal year of balances to purge
0749:             */
0750:            public void purgeYearByChart(String chartOfAccountsCode, int year) {
0751:                LOG.debug("purgeYearByChart() started");
0752:
0753:                Criteria criteria = new Criteria();
0754:                criteria.addEqualTo(
0755:                        KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
0756:                        chartOfAccountsCode);
0757:                criteria.addLessThan(
0758:                        KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
0759:                        new Integer(year));
0760:
0761:                getPersistenceBrokerTemplate().deleteByQuery(
0762:                        new QueryByCriteria(Balance.class, criteria));
0763:
0764:                // This is required because if any deleted account balances are in the cache, deleteByQuery doesn't
0765:                // remove them from the cache so a future select will retrieve these deleted account balances from
0766:                // the cache and return them. Clearing the cache forces OJB to go to the database again.
0767:                getPersistenceBrokerTemplate().clearCache();
0768:            }
0769:
0770:            /**
0771:             * Returns the count of balances for a given fiscal year; this method is used for year end job reporting
0772:             * @param year the university fiscal year to count balances for
0773:             * @return an int with the count of balances for that fiscal year
0774:             * @see org.kuali.module.gl.dao.BalanceDao#countBalancesForFiscalYear(java.lang.Integer)
0775:             */
0776:            public int countBalancesForFiscalYear(Integer year) {
0777:                LOG.debug("countBalancesForFiscalYear() started");
0778:
0779:                Criteria c = new Criteria();
0780:                c.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
0781:                QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
0782:
0783:                return getPersistenceBrokerTemplate().getCount(query);
0784:            }
0785:
0786:            /**
0787:             * Finds all of the balances for the fiscal year that should be processed by nominal activity closing
0788:             * 
0789:             * @param year the university fiscal year of balances to find
0790:             * @return an Iterator of Balances to process
0791:             * @see org.kuali.module.gl.dao.BalanceDao#findNominalActivityBalancesForFiscalYear(java.lang.Integer)
0792:             */
0793:            public Iterator<Balance> findNominalActivityBalancesForFiscalYear(
0794:                    Integer year) {
0795:                LOG.debug("findNominalActivityBalancesForFiscalYear() started");
0796:
0797:                Options currentYearOptions = optionsService
0798:                        .getCurrentYearOptions();
0799:
0800:                // generate List of nominal activity object type codes
0801:                ObjectTypeService objectTypeService = SpringContext
0802:                        .getBean(ObjectTypeService.class);
0803:
0804:                Criteria c = new Criteria();
0805:                c.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
0806:                c.addEqualTo(KFSPropertyConstants.BALANCE_TYPE_CODE,
0807:                        currentYearOptions.getActualFinancialBalanceTypeCd());
0808:                c
0809:                        .addIn(
0810:                                KFSPropertyConstants.OBJECT_TYPE_CODE,
0811:                                objectTypeService
0812:                                        .getNominalActivityClosingAllowedObjectTypes(year));
0813:                c.addNotEqualTo("accountLineAnnualBalanceAmount",
0814:                        KualiDecimal.ZERO);
0815:
0816:                QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
0817:                query
0818:                        .addOrderByAscending(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
0819:                query.addOrderByAscending(KFSPropertyConstants.ACCOUNT_NUMBER);
0820:                query
0821:                        .addOrderByAscending(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
0822:                query.addOrderByAscending(KFSPropertyConstants.OBJECT_CODE);
0823:                query.addOrderByAscending(KFSPropertyConstants.SUB_OBJECT_CODE);
0824:                query
0825:                        .addOrderByAscending(KFSPropertyConstants.BALANCE_TYPE_CODE);
0826:                query
0827:                        .addOrderByAscending(KFSPropertyConstants.OBJECT_TYPE_CODE);
0828:
0829:                return getPersistenceBrokerTemplate().getIteratorByQuery(query);
0830:            }
0831:
0832:            /**
0833:             * Returns all of the balances that should be procesed by the BalanceForward year end job under the general rule
0834:             * 
0835:             * @param the university fiscal year to find balances for
0836:             * @return an Iterator of Balances to process
0837:             * @see org.kuali.module.gl.dao.BalanceDao#findCumulativeBalancesToForwardForFiscalYear(java.lang.Integer)
0838:             */
0839:            public Iterator<Balance> findGeneralBalancesToForwardForFiscalYear(
0840:                    Integer year) {
0841:                ObjectTypeService objectTypeService = SpringContext
0842:                        .getBean(ObjectTypeService.class);
0843:
0844:                String[] generalBalanceForwardBalanceTypesArray = parameterService
0845:                        .getParameterValues(
0846:                                BalanceForwardStep.class,
0847:                                GLConstants.BalanceForwardRule.BALANCE_TYPES_TO_ROLL_FORWARD_FOR_BALANCE_SHEET)
0848:                        .toArray(new String[] {});
0849:                List<String> generalBalanceForwardBalanceTypes = new ArrayList<String>();
0850:                for (String bt : generalBalanceForwardBalanceTypesArray) {
0851:                    generalBalanceForwardBalanceTypes.add(bt);
0852:                }
0853:
0854:                Criteria c = new Criteria();
0855:                c.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
0856:                c.addIn(KFSPropertyConstants.BALANCE_TYPE_CODE,
0857:                        generalBalanceForwardBalanceTypes);
0858:                c.addIn(KFSPropertyConstants.OBJECT_TYPE_CODE,
0859:                        objectTypeService
0860:                                .getGeneralForwardBalanceObjectTypes(year));
0861:
0862:                QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
0863:                query
0864:                        .addOrderByAscending(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
0865:                query.addOrderByAscending(KFSPropertyConstants.ACCOUNT_NUMBER);
0866:                query
0867:                        .addOrderByAscending(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
0868:                query.addOrderByAscending(KFSPropertyConstants.OBJECT_CODE);
0869:                query.addOrderByAscending(KFSPropertyConstants.SUB_OBJECT_CODE);
0870:                query
0871:                        .addOrderByAscending(KFSPropertyConstants.BALANCE_TYPE_CODE);
0872:                query
0873:                        .addOrderByAscending(KFSPropertyConstants.OBJECT_TYPE_CODE);
0874:
0875:                Iterator<Balance> balances = getPersistenceBrokerTemplate()
0876:                        .getIteratorByQuery(query);
0877:
0878:                Map<String, FilteringBalanceIterator> balanceIterators = SpringContext
0879:                        .getBeansOfType(FilteringBalanceIterator.class);
0880:                FilteringBalanceIterator filteredBalances = balanceIterators
0881:                        .get("glBalanceTotalNotZeroIterator");
0882:                filteredBalances.setBalancesSource(balances);
0883:
0884:                return filteredBalances;
0885:            }
0886:
0887:            /**
0888:             * Returns all of the balances that should be procesed by the BalanceForward year end job under the active rule
0889:             * 
0890:             * @param the university fiscal year to find balances for
0891:             * @return an Iterator of Balances to process
0892:             * @see org.kuali.module.gl.dao.BalanceDao#findGeneralBalancesToForwardForFiscalYear(java.lang.Integer)
0893:             */
0894:            public Iterator<Balance> findCumulativeBalancesToForwardForFiscalYear(
0895:                    Integer year) {
0896:                ObjectTypeService objectTypeService = SpringContext
0897:                        .getBean(ObjectTypeService.class);
0898:                SubFundGroupService subFundGroupService = SpringContext
0899:                        .getBean(SubFundGroupService.class);
0900:
0901:                final String[] subFundGroupsForCumulativeBalanceForwardingArray = parameterService
0902:                        .getParameterValues(
0903:                                BalanceForwardStep.class,
0904:                                GLConstants.BalanceForwardRule.SUB_FUND_GROUPS_FOR_INCEPTION_TO_DATE_REPORTING)
0905:                        .toArray(new String[] {});
0906:                List<String> subFundGroupsForCumulativeBalanceForwarding = new ArrayList<String>();
0907:                for (String subFundGroup : subFundGroupsForCumulativeBalanceForwardingArray) {
0908:                    subFundGroupsForCumulativeBalanceForwarding
0909:                            .add(subFundGroup);
0910:                }
0911:
0912:                String[] cumulativeBalanceForwardBalanceTypesArray = parameterService
0913:                        .getParameterValues(
0914:                                BalanceForwardStep.class,
0915:                                GLConstants.BalanceForwardRule.BALANCE_TYPES_TO_ROLL_FORWARD_FOR_INCOME_EXPENSE)
0916:                        .toArray(new String[] {});
0917:                List<String> cumulativeBalanceForwardBalanceTypes = new ArrayList<String>();
0918:                for (String bt : cumulativeBalanceForwardBalanceTypesArray) {
0919:                    cumulativeBalanceForwardBalanceTypes.add(bt);
0920:                }
0921:
0922:                Criteria c = new Criteria();
0923:                c.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
0924:                c.addIn(KFSPropertyConstants.BALANCE_TYPE_CODE,
0925:                        cumulativeBalanceForwardBalanceTypes);
0926:                c.addIn(KFSPropertyConstants.OBJECT_TYPE_CODE,
0927:                        objectTypeService
0928:                                .getCumulativeForwardBalanceObjectTypes(year));
0929:
0930:                Criteria forCGCrit = new Criteria();
0931:                if (parameterService
0932:                        .getIndicatorParameter(
0933:                                Account.class,
0934:                                KFSConstants.ChartApcParms.ACCOUNT_FUND_GROUP_DENOTES_CG)) {
0935:                    forCGCrit.addEqualTo(
0936:                            "priorYearAccount.subFundGroup.fundGroupCode",
0937:                            subFundGroupService
0938:                                    .getContractsAndGrantsDenotingValue());
0939:                } else {
0940:                    forCGCrit.addEqualTo("priorYearAccount.subFundGroupCode",
0941:                            subFundGroupService
0942:                                    .getContractsAndGrantsDenotingValue());
0943:                }
0944:
0945:                Criteria subFundGroupCrit = new Criteria();
0946:                subFundGroupCrit.addIn("priorYearAccount.subFundGroupCode",
0947:                        subFundGroupsForCumulativeBalanceForwarding);
0948:                forCGCrit.addOrCriteria(subFundGroupCrit);
0949:                c.addAndCriteria(forCGCrit);
0950:
0951:                QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
0952:                query
0953:                        .addOrderByAscending(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
0954:                query.addOrderByAscending(KFSPropertyConstants.ACCOUNT_NUMBER);
0955:                query
0956:                        .addOrderByAscending(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
0957:                query.addOrderByAscending(KFSPropertyConstants.OBJECT_CODE);
0958:                query.addOrderByAscending(KFSPropertyConstants.SUB_OBJECT_CODE);
0959:                query
0960:                        .addOrderByAscending(KFSPropertyConstants.BALANCE_TYPE_CODE);
0961:                query
0962:                        .addOrderByAscending(KFSPropertyConstants.OBJECT_TYPE_CODE);
0963:
0964:                Iterator<Balance> balances = getPersistenceBrokerTemplate()
0965:                        .getIteratorByQuery(query);
0966:
0967:                Map<String, FilteringBalanceIterator> balanceIterators = SpringContext
0968:                        .getBeansOfType(FilteringBalanceIterator.class);
0969:                FilteringBalanceIterator filteredBalances = balanceIterators
0970:                        .get("glBalanceAnnualAndCGTotalNotZeroIterator");
0971:                filteredBalances.setBalancesSource(balances);
0972:
0973:                return filteredBalances;
0974:            }
0975:
0976:            private static final String PARAMETER_PREFIX = "SELECTION_";
0977:
0978:            /**
0979:             * Returns a list of balances to return for the Organization Reversion year end job to process
0980:             * 
0981:             * @param the university fiscal year to find balances for
0982:             * @param endOfYear if true, use currrent year accounts, otherwise use prior year accounts
0983:             * @return an Iterator of Balances to process
0984:             * @see org.kuali.module.gl.dao.BalanceDao#findOrganizationReversionBalancesForFiscalYear(java.lang.Integer, boolean)
0985:             */
0986:            public Iterator<Balance> findOrganizationReversionBalancesForFiscalYear(
0987:                    Integer year, boolean endOfYear) {
0988:                LOG
0989:                        .debug("findOrganizationReversionBalancesForFiscalYear() started");
0990:                Criteria c = new Criteria();
0991:                c.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
0992:                ParameterService parameterService = SpringContext
0993:                        .getBean(ParameterService.class);
0994:                Map<Integer, String> parsedRules = new TreeMap<Integer, String>();
0995:                int i = 1;
0996:                boolean moreParams = true;
0997:                while (moreParams) {
0998:                    if (parameterService.parameterExists(
0999:                            OrganizationReversion.class, PARAMETER_PREFIX + i)) {
1000:                        ParameterEvaluator parameterEvaluator = parameterService
1001:                                .getParameterEvaluator(
1002:                                        OrganizationReversion.class,
1003:                                        PARAMETER_PREFIX + i);
1004:                        String currentRule = parameterEvaluator.getValue();
1005:                        if (!endOfYear) {
1006:                            currentRule = currentRule.replaceAll("account\\.",
1007:                                    "priorYearAccount.");
1008:                        }
1009:                        if (StringUtils.isNotBlank(currentRule)) {
1010:                            String propertyName = StringUtils.substringBefore(
1011:                                    currentRule, "=");
1012:                            List<String> ruleValues = Arrays.asList(StringUtils
1013:                                    .substringAfter(currentRule, "=")
1014:                                    .split(";"));
1015:                            if (propertyName != null
1016:                                    && propertyName.length() > 0
1017:                                    && ruleValues.size() > 0
1018:                                    && !StringUtils.isBlank(ruleValues.get(0))) {
1019:                                if (parameterEvaluator.constraintIsAllow()) {
1020:                                    c.addIn(propertyName, ruleValues);
1021:                                } else {
1022:                                    c.addNotIn(propertyName, ruleValues);
1023:                                }
1024:                            }
1025:                        }
1026:                    } else {
1027:                        moreParams = false;
1028:                    }
1029:                    i++;
1030:                }
1031:                // we only ever calculate on CB, AC, and encumbrance types, so let's only select those
1032:                Options options = SpringContext.getBean(OptionsService.class)
1033:                        .getOptions(year);
1034:                List organizationReversionBalancesToSelect = new ArrayList();
1035:                organizationReversionBalancesToSelect.add(options
1036:                        .getActualFinancialBalanceTypeCd());
1037:                organizationReversionBalancesToSelect.add(options
1038:                        .getFinObjTypeExpenditureexpCd());
1039:                organizationReversionBalancesToSelect.add(options
1040:                        .getCostShareEncumbranceBalanceTypeCd());
1041:                organizationReversionBalancesToSelect.add(options
1042:                        .getIntrnlEncumFinBalanceTypCd());
1043:                organizationReversionBalancesToSelect
1044:                        .add(KFSConstants.BALANCE_TYPE_CURRENT_BUDGET);
1045:                c.addIn(KFSPropertyConstants.BALANCE_TYPE_CODE,
1046:                        organizationReversionBalancesToSelect);
1047:                QueryByCriteria query = QueryFactory.newQuery(Balance.class, c);
1048:                query
1049:                        .addOrderByAscending(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
1050:                query.addOrderByAscending(KFSPropertyConstants.ACCOUNT_NUMBER);
1051:                query
1052:                        .addOrderByAscending(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
1053:                query.addOrderByAscending(KFSPropertyConstants.OBJECT_CODE);
1054:                query.addOrderByAscending(KFSPropertyConstants.SUB_OBJECT_CODE);
1055:                query
1056:                        .addOrderByAscending(KFSPropertyConstants.BALANCE_TYPE_CODE);
1057:                query
1058:                        .addOrderByAscending(KFSPropertyConstants.OBJECT_TYPE_CODE);
1059:
1060:                return getPersistenceBrokerTemplate().getIteratorByQuery(query);
1061:            }
1062:
1063:            public void setOptionsService(OptionsService optionsService) {
1064:                this .optionsService = optionsService;
1065:            }
1066:
1067:            public void setParameterService(ParameterService parameterService) {
1068:                this .parameterService = parameterService;
1069:            }
1070:
1071:            public void setBalanceTypService(BalanceTypService balanceTypService) {
1072:                this.balanceTypService = balanceTypService;
1073:            }
1074:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.