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

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


001:        /*
002:         * Copyright 2005-2007 The Kuali Foundation.
003:         * 
004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         * http://www.opensource.org/licenses/ecl1.php
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.kuali.module.chart.service.impl;
017:
018:        import java.sql.Date;
019:        import java.util.Calendar;
020:        import java.util.Collection;
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:        import java.util.Map;
024:        import java.util.Set;
025:        import java.util.TreeSet;
026:
027:        import org.kuali.core.service.BusinessObjectService;
028:        import org.kuali.core.util.spring.Cached;
029:        import org.kuali.kfs.KFSConstants;
030:        import org.kuali.kfs.KFSPropertyConstants;
031:        import org.kuali.module.chart.bo.AccountingPeriod;
032:        import org.kuali.module.chart.service.AccountingPeriodService;
033:        import org.springframework.transaction.annotation.Transactional;
034:
035:        /**
036:         * This service implementation is the default implementation of the AccountingPeriod service that is delivered with Kuali.
037:         */
038:        @Transactional
039:        public class AccountingPeriodServiceImpl implements 
040:                AccountingPeriodService {
041:            // member data
042:            private BusinessObjectService businessObjectService;
043:
044:            protected static final Set _invalidPeriodCodes = new TreeSet();
045:
046:            static {
047:                _invalidPeriodCodes.add("13");
048:                _invalidPeriodCodes.add("AB");
049:                _invalidPeriodCodes.add("BB");
050:                _invalidPeriodCodes.add("CB");
051:            }
052:
053:            /**
054:             * The default implementation.
055:             * 
056:             * @see org.kuali.module.chart.service.AccountingPeriodService#getAllAccountingPeriods()
057:             */
058:            public Collection getAllAccountingPeriods() {
059:                return businessObjectService.findAll(AccountingPeriod.class);
060:            }
061:
062:            /**
063:             * Implements by choosing only accounting periods that have a status that is open ("O").
064:             * 
065:             * @see org.kuali.module.chart.service.AccountingPeriodService#getOpenAccountingPeriods()
066:             */
067:            @Cached
068:            public Collection getOpenAccountingPeriods() {
069:                HashMap map = new HashMap();
070:                map.put(KFSConstants.ACCOUNTING_PERIOD_STATUS_CODE_FIELD,
071:                        KFSConstants.ACCOUNTING_PERIOD_STATUS_OPEN);
072:
073:                return businessObjectService
074:                        .findMatchingOrderBy(
075:                                AccountingPeriod.class,
076:                                map,
077:                                KFSPropertyConstants.ACCTING_PERIOD_UNIV_FISCAL_PERIOD_END_DATE,
078:                                true);
079:            }
080:
081:            /**
082:             * This method is a helper method to easily grab an accounting period by looking up it's period and fiscal year
083:             * 
084:             * @param periodCode
085:             * @param fiscalYear
086:             * @return an accounting period
087:             */
088:            public AccountingPeriod getByPeriod(String periodCode,
089:                    Integer fiscalYear) {
090:                // build up the hashmap to find the accounting period
091:                Map keys = new HashMap();
092:                keys.put("universityFiscalPeriodCode", periodCode);
093:                keys.put("universityFiscalYear", fiscalYear);
094:                AccountingPeriod acctPeriod = (AccountingPeriod) getBusinessObjectService()
095:                        .findByPrimaryKey(AccountingPeriod.class, keys);
096:                return acctPeriod;
097:            }
098:
099:            /**
100:             * This method is a helper method to get the current period.
101:             * 
102:             * @see org.kuali.module.chart.service.AccountingPeriodService#getByDate(java.sql.Date)
103:             */
104:            public AccountingPeriod getByDate(Date date) {
105:                // first we need to figure out the last day for a given date
106:                java.util.Date myDate = new java.util.Date(date.getTime());
107:                Calendar cal = Calendar.getInstance();
108:                cal.setTime(myDate);
109:                // get the current month
110:                int month = cal.get(Calendar.MONTH);
111:                cal.set(Calendar.MONTH, month + 1);
112:                cal.set(Calendar.DAY_OF_MONTH, 1);
113:                // this should roll us back to the last day of the month for the previous month
114:                cal.add(Calendar.DAY_OF_MONTH, -1);
115:                Date lookupDate = new Date(cal.getTimeInMillis());
116:                Map keys = new HashMap();
117:                keys.put("universityFiscalPeriodEndDate", lookupDate);
118:                Collection coll = getBusinessObjectService().findMatching(
119:                        AccountingPeriod.class, keys);
120:                if (coll.size() == 1) {
121:                    Iterator iter = coll.iterator();
122:                    AccountingPeriod period = (AccountingPeriod) iter.next();
123:                    return period;
124:                } else {
125:                    Iterator iter = coll.iterator();
126:                    while (iter.hasNext()) {
127:                        AccountingPeriod period = (AccountingPeriod) iter
128:                                .next();
129:                        if (!isInvalidPeriodCode(period)) {
130:                            return period;
131:                        }
132:                    }
133:                }
134:                return null;
135:            }
136:
137:            /**
138:             * 
139:             * This checks to see if the period code is empty or invalid ("13", "AB", "BB", "CB")
140:             * @param period
141:             * @return
142:             */
143:            private boolean isInvalidPeriodCode(AccountingPeriod period) {
144:                String periodCode = period.getUniversityFiscalPeriodCode();
145:                if (periodCode == null) {
146:                    throw new IllegalArgumentException(
147:                            "invalid (null) universityFiscalPeriodCode ("
148:                                    + periodCode + ")for" + period);
149:                }
150:                return _invalidPeriodCodes.contains(periodCode);
151:            }
152:
153:            /**
154:             * @see org.kuali.module.chart.service.AccountingPeriodService#compareAccountingPeriodsByDate(org.kuali.module.chart.bo.AccountingPeriod,
155:             *      org.kuali.module.chart.bo.AccountingPeriod)
156:             */
157:            public int compareAccountingPeriodsByDate(
158:                    AccountingPeriod tweedleDee, AccountingPeriod tweedleDum) {
159:                // note the lack of defensive programming here. If you send a null accounting
160:                // period...then chances are, you deserve the NPE that you receive
161:                Date tweedleDeeClose = tweedleDee
162:                        .getUniversityFiscalPeriodEndDate();
163:                Date tweedleDumClose = tweedleDum
164:                        .getUniversityFiscalPeriodEndDate();
165:
166:                return tweedleDeeClose.compareTo(tweedleDumClose);
167:            }
168:
169:            /**
170:             * This method retrieves an instance of the businessObjectService.
171:             * 
172:             * @return
173:             */
174:            public BusinessObjectService getBusinessObjectService() {
175:                return businessObjectService;
176:            }
177:
178:            /**
179:             * This method sets the instance of the businessObjectService.
180:             * 
181:             * @param businessObjectService
182:             */
183:            public void setBusinessObjectService(
184:                    BusinessObjectService businessObjectService) {
185:                this.businessObjectService = businessObjectService;
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.