Source Code Cross Referenced for TaxNumberServiceImpl.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » vendor » 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.vendor.service.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 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.vendor.service.impl;
017:
018:        import java.util.List;
019:
020:        import org.kuali.core.util.ObjectUtils;
021:        import org.kuali.core.web.format.FormatException;
022:        import org.kuali.kfs.KFSKeyConstants;
023:        import org.kuali.kfs.service.ParameterService;
024:        import org.kuali.module.vendor.VendorConstants;
025:        import org.kuali.module.vendor.VendorParameterConstants;
026:        import org.kuali.module.vendor.bo.VendorDetail;
027:        import org.kuali.module.vendor.service.TaxNumberService;
028:
029:        public class TaxNumberServiceImpl implements  TaxNumberService {
030:
031:            public ParameterService parameterService;
032:
033:            public void setParameterService(ParameterService parameterService) {
034:                this .parameterService = parameterService;
035:            }
036:
037:            public static List<String> taxNumberFormats;
038:            public static List<String> feinNumberFormats;
039:            public static List<String> notAllowedTaxNumbers;
040:
041:            public String formatToDefaultFormat(String taxNbr)
042:                    throws FormatException {
043:                String digits = taxNbr.replaceAll("\\D", "");
044:
045:                Integer defaultTaxNumberDigits = new Integer(
046:                        parameterService
047:                                .getParameterValue(
048:                                        VendorDetail.class,
049:                                        VendorParameterConstants.DEFAULT_TAX_NUMBER_DIGITS));
050:
051:                if (digits.length() < defaultTaxNumberDigits) {
052:                    throw new FormatException("Tax number has fewer than "
053:                            + defaultTaxNumberDigits + " digits.",
054:                            KFSKeyConstants.ERROR_CUSTOM, taxNbr);
055:                } else if (digits.length() > defaultTaxNumberDigits) {
056:                    throw new FormatException("Tax number has more than "
057:                            + defaultTaxNumberDigits + " digits.",
058:                            KFSKeyConstants.ERROR_CUSTOM, taxNbr);
059:                } else {
060:                    return digits;
061:                }
062:            }
063:
064:            /**
065:             * A predicate to determine if a String field is all numbers
066:             * 
067:             * @param field A String tax number
068:             * @return True if String is numeric
069:             */
070:            public boolean isStringAllNumbers(String field) {
071:                if (!isStringEmpty(field)) {
072:                    field = field.trim();
073:                    for (int x = 0; x < field.length(); x++) {
074:                        char c = field.charAt(x);
075:                        if (!Character.isDigit(c)) {
076:                            return false;
077:                        }
078:                    }
079:                    return true;
080:                }
081:                return false;
082:            }
083:
084:            /**
085:             * A predicate to determine if a String field is null or empty
086:             * 
087:             * @param field A String tax number
088:             * @return True if String is null or empty
089:             */
090:            public boolean isStringEmpty(String field) {
091:                if (field == null || field.equals("")) {
092:                    return true;
093:                } else {
094:                    return false;
095:                }
096:            }
097:
098:            /**
099:             * A predicate to determine the validity of tax numbers We're using regular expressions stored in the business rules table to
100:             * validate whether the tax number is in the correct format. The regular expressions are : (please update this javadoc comment
101:             * when the regular expressions change) 1. For SSN : (?!000)(?!666)(\d{3})([ \-]?)(?!00)(\d{2})([\-]?)(?!0000)(\d{4}) 2. For
102:             * FEIN : (?!00)(\d{3})([ \-]?)(\d{2})([\-]?)(?!0000)(\d{4})
103:             * 
104:             * @param taxNbr A tax number String (SSN or FEIN)
105:             * @param taxType determines SSN or FEIN tax number type
106:             * @return True if the tax number is known to be in a valid format
107:             */
108:            public boolean isValidTaxNumber(String taxNbr, String taxType) {
109:                String[] ssnFormats = parseSSNFormats();
110:                String[] feinFormats = parseFEINFormats();
111:                Integer defaultTaxNumberDigits = new Integer(parameterService
112:                        .getParameterValue(VendorDetail.class,
113:                                "DEFAULT_TAX_NUMBER_DIGITS"));
114:
115:                if (taxNbr.length() != defaultTaxNumberDigits
116:                        || !isStringAllNumbers(taxNbr)) {
117:                    return false;
118:                }
119:
120:                if (taxType.equals(VendorConstants.TAX_TYPE_SSN)) {
121:
122:                    for (int i = 0; i < ssnFormats.length; i++) {
123:                        if (taxNbr.matches(ssnFormats[i])) {
124:                            return true;
125:                        }
126:                    }
127:                    return false;
128:                } else if (taxType.equals(VendorConstants.TAX_TYPE_FEIN)) {
129:                    for (int i = 0; i < feinFormats.length; i++) {
130:                        if (taxNbr.matches(feinFormats[i])) {
131:                            return true;
132:                        }
133:                    }
134:                    return false;
135:                }
136:
137:                return true;
138:            }
139:
140:            /**
141:             * Someday we'll have to use the rules table instead of using constants. This method will return true if the tax number is an
142:             * allowed tax number and return false if it's not allowed.
143:             * 
144:             * @param taxNbr The tax number to be processed.
145:             * @return boolean true if the tax number is allowed and false otherwise.
146:             */
147:            public boolean isAllowedTaxNumber(String taxNbr) {
148:                String[] notAllowedTaxNumbers = parseNotAllowedTaxNumbers();
149:                for (int i = 0; i < notAllowedTaxNumbers.length; i++) {
150:                    if (taxNbr.matches(notAllowedTaxNumbers[i])) {
151:                        return false;
152:                    }
153:                }
154:                return true;
155:            }
156:
157:            /**
158:             * Splits the set of tax number formats which are returned from the rule service as a semicolon-delimeted String into a String
159:             * array.
160:             * 
161:             * @return A String array of the tax number format regular expressions.
162:             */
163:            public String[] parseSSNFormats() {
164:                if (ObjectUtils.isNull(taxNumberFormats)) {
165:                    taxNumberFormats = parameterService.getParameterValues(
166:                            VendorDetail.class, "TAX_SSN_NUMBER_FORMATS");
167:                }
168:                return taxNumberFormats.toArray(new String[] {});
169:            }
170:
171:            /**
172:             * Splits the set of tax fein number formats which are returned from the rule service as a semicolon-delimeted String into a
173:             * String array.
174:             * 
175:             * @return A String array of the tax fein number format regular expressions.
176:             */
177:            public String[] parseFEINFormats() {
178:                if (ObjectUtils.isNull(feinNumberFormats)) {
179:                    feinNumberFormats = parameterService.getParameterValues(
180:                            VendorDetail.class, "TAX_FEIN_NUMBER_FORMATS");
181:                }
182:                return feinNumberFormats.toArray(new String[] {});
183:            }
184:
185:            /**
186:             * Splits the set of not allowed tax number formats which are returned from the rule service as a semicolon-delimeted String
187:             * into a String array.
188:             * 
189:             * @return A String array of the not allowed tax number format regular expressions.
190:             */
191:            public String[] parseNotAllowedTaxNumbers() {
192:                if (ObjectUtils.isNull(notAllowedTaxNumbers)) {
193:                    notAllowedTaxNumbers = parameterService
194:                            .getParameterValues(
195:                                    VendorDetail.class,
196:                                    VendorParameterConstants.PURAP_NOT_ALLOWED_TAX_NUMBERS);
197:                }
198:                return notAllowedTaxNumbers.toArray(new String[] {});
199:            }
200:
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.