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


001:        /*
002:         * Copyright 2006-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.financial.rules;
017:
018:        import java.util.HashMap;
019:        import java.util.Map;
020:
021:        import org.apache.commons.lang.StringUtils;
022:        import org.kuali.core.document.MaintenanceDocument;
023:        import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
024:        import org.kuali.core.util.ObjectUtils;
025:        import org.kuali.kfs.KFSKeyConstants;
026:        import org.kuali.module.chart.bo.Account;
027:        import org.kuali.module.chart.bo.SubAccount;
028:        import org.kuali.module.chart.bo.SubObjCd;
029:        import org.kuali.module.financial.bo.CreditCardVendor;
030:
031:        /**
032:         * This class represents business rules for the credit card vendor maintenance document
033:         */
034:        public class CreditCardVendorRule extends MaintenanceDocumentRuleBase {
035:
036:            private CreditCardVendor newCreditCardVendor;
037:
038:            /**
039:             *  Sets up a CreditCardVendor convenience objects to make sure all possible sub-objects are populated
040:             * 
041:             * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
042:             */
043:            public void setupConvenienceObjects() {
044:
045:                newCreditCardVendor = (CreditCardVendor) super .getNewBo();
046:            }
047:
048:            /**
049:             * Return true if rules for processing a save for the credit card maintenance document are are valid.
050:             * 
051:             * @param document maintenance document
052:             * @return true credit card vendor number is valid
053:             * 
054:             * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
055:             */
056:            protected boolean processCustomSaveDocumentBusinessRules(
057:                    MaintenanceDocument document) {
058:                // default to success
059:                boolean success = true;
060:                setupConvenienceObjects();
061:
062:                // check valid Credit Card Vendor Number (numeric, minimum length)
063:                success &= checkCreditCardVendorNumber();
064:
065:                return success;
066:            }
067:
068:            /**
069:             * Returns value from processCustomRouteDocumentBusinessRules(document)
070:             * 
071:             * @param document maintenance document
072:             * @return value from processCustomRouteDocumentBusinessRules(document)
073:             * 
074:             * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomApproveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
075:             */
076:            protected boolean processCustomApproveDocumentBusinessRules(
077:                    MaintenanceDocument document) {
078:
079:                return processCustomRouteDocumentBusinessRules(document);
080:            }
081:
082:            /**
083:             * Returns true credit card vendor maintenance document is routed successfully
084:             * 
085:             * @param document submitted credit card maintenance document
086:             * @return true if credit card vendor number, income/expense account numbers, income/expense sub-account numbers, and income/expense sub-object codes are valid
087:             * 
088:             * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
089:             */
090:            protected boolean processCustomRouteDocumentBusinessRules(
091:                    MaintenanceDocument document) {
092:                // default to success
093:                boolean success = true;
094:
095:                setupConvenienceObjects();
096:
097:                // check valid Credit Card Vendor Number (numeric, minimum length)
098:                success &= checkCreditCardVendorNumber();
099:
100:                // check Income Account Number business rule
101:                if (newCreditCardVendor.getIncomeAccountNumber() != null) {
102:                    success &= checkExistingActiveAccount(newCreditCardVendor
103:                            .getIncomeAccountNumber(), "incomeAccountNumber",
104:                            "Income Account Number");
105:                }
106:
107:                // check Expense Account Number business rule
108:                if (newCreditCardVendor.getExpenseAccountNumber() != null) {
109:                    success &= checkExistingActiveAccount(newCreditCardVendor
110:                            .getExpenseAccountNumber(), "expenseAccountNumber",
111:                            "Expense Account Number");
112:                }
113:
114:                // check Income Sub-Account business rule
115:                if (newCreditCardVendor.getIncomeSubAccountNumber() != null) {
116:
117:                    // check required fields to validate Sub-Account
118:                    if (checkRequiredSubAccount("Income")) {
119:                        SubAccount existenceSubAccount = checkExistenceSubAccount("Income");
120:
121:                        // check existence of Sub-Account
122:                        if (existenceSubAccount == null) {
123:                            putFieldError(
124:                                    "incomeSubAccountNumber",
125:                                    KFSKeyConstants.ERROR_CCV_INVALIDSUBACCOUNT,
126:                                    "Income Sub-Account Number, "
127:                                            + newCreditCardVendor
128:                                                    .getIncomeSubAccountNumber());
129:                        } else
130:
131:                        // check the Sub-Account is active
132:                        if (!existenceSubAccount.isSubAccountActiveIndicator()) {
133:                            putFieldError("incomeSubAccountNumber",
134:                                    KFSKeyConstants.ERROR_INACTIVE,
135:                                    "Income Sub-Account");
136:                        }
137:                    }
138:                }
139:
140:                // check Expense Sub-Account business rule
141:                if (newCreditCardVendor.getExpenseSubAccountNumber() != null) {
142:                    if (checkRequiredSubAccount("Expense")) {
143:
144:                        // check existence of Sub-Account
145:                        SubAccount existenceSubAccount = checkExistenceSubAccount("Expense");
146:                        if (existenceSubAccount == null) {
147:                            putFieldError(
148:                                    "expenseSubAccountNumber",
149:                                    KFSKeyConstants.ERROR_CCV_INVALIDSUBACCOUNT,
150:                                    "Expense Sub-Account Number, "
151:                                            + newCreditCardVendor
152:                                                    .getExpenseSubAccountNumber());
153:
154:                        } else
155:
156:                        // check the Sub-Account is active
157:                        if (!existenceSubAccount.isSubAccountActiveIndicator()) {
158:                            putFieldError("expenseSubAccountNumber",
159:                                    KFSKeyConstants.ERROR_INACTIVE,
160:                                    "Expense Sub-Account");
161:                        }
162:                    }
163:                }
164:
165:                // check Income Sub-Object Code business rule
166:                if (newCreditCardVendor.getIncomeFinancialSubObjectCode() != null) {
167:                    if (checkRequiredSubObjectCode("Income")) {
168:
169:                        // check existence of Sub-Object
170:                        SubObjCd existenceSubObj = checkExistenceSubObj("Income");
171:                        if (existenceSubObj == null) {
172:                            putFieldError(
173:                                    "incomeFinancialSubObjectCode",
174:                                    KFSKeyConstants.ERROR_CCV_INVALIDSUBOBJECT,
175:                                    "Income Sub-Object Code, "
176:                                            + newCreditCardVendor
177:                                                    .getIncomeFinancialSubObjectCode());
178:                        } else
179:                        // check the Sub-Object is active
180:                        if (!existenceSubObj
181:                                .isFinancialSubObjectActiveIndicator()) {
182:                            putFieldError("incomeFinancialSubObjectCode",
183:                                    KFSKeyConstants.ERROR_INACTIVE,
184:                                    "Income Sub-Object");
185:                        }
186:
187:                    }
188:                }
189:
190:                // check Expense Sub-Object Code business rule
191:                if (newCreditCardVendor.getExpenseFinancialSubObjectCode() != null) {
192:                    if (checkRequiredSubObjectCode("Expense")) {
193:
194:                        // check existence of Sub-Object
195:                        SubObjCd existenceSubObj = checkExistenceSubObj("Expense");
196:                        if (existenceSubObj == null) {
197:                            putFieldError(
198:                                    "expenseFinancialSubObjectCode",
199:                                    KFSKeyConstants.ERROR_CCV_INVALIDSUBOBJECT,
200:                                    "Expense Sub-Object Code, "
201:                                            + newCreditCardVendor
202:                                                    .getExpenseFinancialSubObjectCode());
203:                        } else
204:                        // check the Sub-Object is active
205:                        if (!existenceSubObj
206:                                .isFinancialSubObjectActiveIndicator()) {
207:                            putFieldError("expenseFinancialSubObjectCode",
208:                                    KFSKeyConstants.ERROR_INACTIVE,
209:                                    "Expense Sub-Object");
210:                        }
211:                    }
212:                }
213:
214:                return success;
215:            }
216:
217:            /**
218:             * Returns true if credit card vendor number is valid (i.e. numeric and at least 5 digits)
219:             * 
220:             * @return true if credit card vendor number is valid (i.e. numeric and at least 5 digits)
221:             */
222:            private boolean checkCreditCardVendorNumber() {
223:                String ccvNumber = newCreditCardVendor
224:                        .getFinancialDocumentCreditCardVendorNumber();
225:
226:                if (ccvNumber == null) {
227:                    return false;
228:                } else if (!StringUtils.isNumeric(ccvNumber)) {
229:                    putFieldError("financialDocumentCreditCardVendorNumber",
230:                            KFSKeyConstants.ERROR_NUMERIC,
231:                            "Vendor Credit Card Number");
232:                    return false;
233:                } else if (ccvNumber.length() < 5) {
234:                    String errorMessage[] = null;
235:                    errorMessage = new String[] { "Vendor Credit Card Number",
236:                            "5" };
237:                    putFieldError("financialDocumentCreditCardVendorNumber",
238:                            KFSKeyConstants.ERROR_MIN_LENGTH, errorMessage);
239:                    return false;
240:                }
241:
242:                return true;
243:            }
244:
245:            /**
246:             * Returns true if account is active (i.e. exists and is not expired or closed)
247:             * 
248:             * @param accountNumber account number
249:             * @param fieldName field name to place error for
250:             * @param errorMessage error message to display
251:             * @return true if account is active (i.e. exists and is not expired or closed)
252:             */
253:            private boolean checkExistingActiveAccount(String accountNumber,
254:                    String fieldName, String errorMessage) {
255:                boolean result = false;
256:                Account account;
257:                Map pkMap = new HashMap();
258:                pkMap.put("accountNumber", accountNumber);
259:                account = (Account) super .getBoService().findByPrimaryKey(
260:                        Account.class, pkMap);
261:
262:                // if the object doesnt exist, then we cant continue, so exit
263:                if (ObjectUtils.isNull(account)) {
264:                    putFieldError(fieldName, KFSKeyConstants.ERROR_EXISTENCE,
265:                            errorMessage);
266:                    return result;
267:                }
268:
269:                // check whether expired or not
270:                if (account.isExpired()) {
271:                    putFieldError(fieldName, KFSKeyConstants.ERROR_EXPIRED,
272:                            errorMessage);
273:                    return result;
274:                }
275:
276:                // check whether closed or not
277:                if (account.isAccountClosedIndicator()) {
278:                    putFieldError(fieldName, KFSKeyConstants.ERROR_CLOSED,
279:                            errorMessage);
280:                    return result;
281:                }
282:
283:                return true;
284:            }
285:
286:            /**
287:             * Returns true if income/expense financial chart of accounts code and account number exist. Income or expense is determined by
288:             * the "Income" value or the "Expense" value passed in to the method as a string
289:             * 
290:             * @param string determines whether or not to check income or expense sub account information (valid values include "Income" or "Expense")
291:             * @return true if corresponding sub account values exist
292:             */
293:            private boolean checkRequiredSubAccount(String string) {
294:                boolean returnVal = true;
295:                if (string.equals("Income")) {
296:                    if (newCreditCardVendor
297:                            .getIncomeFinancialChartOfAccountsCode() == null) {
298:                        putFieldError(
299:                                "incomeFinancialChartOfAccountsCode",
300:                                KFSKeyConstants.ERROR_CCV_INCOME_SUBACCOUNT_REQUIRED,
301:                                "Income Chart");
302:                        returnVal = false;
303:                    }
304:
305:                    if (newCreditCardVendor.getIncomeAccountNumber() == null) {
306:                        putFieldError(
307:                                "incomeAccountNumber",
308:                                KFSKeyConstants.ERROR_CCV_INCOME_SUBACCOUNT_REQUIRED,
309:                                "Income Account Number");
310:                        returnVal = false;
311:                    }
312:                }
313:
314:                if (string.equals("Expense")) {
315:                    if (newCreditCardVendor
316:                            .getExpenseFinancialChartOfAccountsCode() == null) {
317:                        putFieldError(
318:                                "expenseFinancialChartOfAccountsCode",
319:                                KFSKeyConstants.ERROR_CCV_EXPENSE_SUBACCOUNT_REQUIRED,
320:                                "Expense Chart");
321:                        returnVal = false;
322:                    }
323:
324:                    if (newCreditCardVendor.getExpenseAccountNumber() == null) {
325:                        putFieldError(
326:                                "expenseAccountNumber",
327:                                KFSKeyConstants.ERROR_CCV_EXPENSE_SUBACCOUNT_REQUIRED,
328:                                "Expense Account Number");
329:                        returnVal = false;
330:                    }
331:                }
332:
333:                return returnVal;
334:            }
335:
336:            /**
337:             * Returns a SubAccount object if SubAccount object exists for "Income" or "Expense"
338:             * 
339:             * @param string determines whether or not to retrieve a income or expense sub account (valid values include "Income" or "Expense")
340:             * @return SubAccount Income/Expense SubAccount object
341:             */
342:            private SubAccount checkExistenceSubAccount(String string) {
343:
344:                SubAccount subAccount = null;
345:
346:                if (string.equals("Income")) {
347:                    Map pkMap = new HashMap();
348:                    pkMap.put("chartOfAccountsCode", newCreditCardVendor
349:                            .getIncomeFinancialChartOfAccountsCode());
350:                    pkMap.put("accountNumber", newCreditCardVendor
351:                            .getIncomeAccountNumber());
352:                    pkMap.put("subAccountNumber", newCreditCardVendor
353:                            .getIncomeSubAccountNumber());
354:                    subAccount = (SubAccount) super .getBoService()
355:                            .findByPrimaryKey(SubAccount.class, pkMap);
356:                }
357:
358:                if (string.equals("Expense")) {
359:                    Map pkMap = new HashMap();
360:                    pkMap.put("chartOfAccountsCode", newCreditCardVendor
361:                            .getExpenseFinancialChartOfAccountsCode());
362:                    pkMap.put("accountNumber", newCreditCardVendor
363:                            .getExpenseAccountNumber());
364:                    pkMap.put("subAccountNumber", newCreditCardVendor
365:                            .getExpenseSubAccountNumber());
366:                    subAccount = (SubAccount) super .getBoService()
367:                            .findByPrimaryKey(SubAccount.class, pkMap);
368:                }
369:
370:                return subAccount;
371:            }
372:
373:            /**
374:             * Returns a true sub-object code exists for "Income" or "Expense"
375:             * 
376:             * @param string determines whether or not to check for an income or expense sub-object code (valid values include "Income" or "Expense")
377:             * @return true if income/expense chart of account code, account number, and financial object code exist
378:             */
379:            private boolean checkRequiredSubObjectCode(String string) {
380:
381:                boolean returnVal = true;
382:                if (string.equals("Income")) {
383:                    if (newCreditCardVendor
384:                            .getIncomeFinancialChartOfAccountsCode() == null) {
385:                        putFieldError(
386:                                "incomeFinancialChartOfAccountsCode",
387:                                KFSKeyConstants.ERROR_CCV_INCOME_SUBOBJ_REQUIRED,
388:                                "Income Chart");
389:                        returnVal = false;
390:                    }
391:
392:                    if (newCreditCardVendor.getIncomeAccountNumber() == null) {
393:                        putFieldError(
394:                                "incomeAccountNumber",
395:                                KFSKeyConstants.ERROR_CCV_INCOME_SUBOBJ_REQUIRED,
396:                                "Income Account Number");
397:                        returnVal = false;
398:                    }
399:
400:                    if (newCreditCardVendor.getIncomeFinancialObjectCode() == null) {
401:                        putFieldError(
402:                                "incomeFinancialObjectCode",
403:                                KFSKeyConstants.ERROR_CCV_INCOME_SUBOBJ_REQUIRED,
404:                                "Income Object Code");
405:                        returnVal = false;
406:                    }
407:
408:                }
409:
410:                if (string.equals("Expense")) {
411:                    if (newCreditCardVendor
412:                            .getExpenseFinancialChartOfAccountsCode() == null) {
413:                        putFieldError(
414:                                "expenseFinancialChartOfAccountsCode",
415:                                KFSKeyConstants.ERROR_CCV_EXPENSE_SUBOBJ_REQUIRED,
416:                                "Expense Chart");
417:                        returnVal = false;
418:                    }
419:
420:                    if (newCreditCardVendor.getExpenseAccountNumber() == null) {
421:                        putFieldError(
422:                                "expenseAccountNumber",
423:                                KFSKeyConstants.ERROR_CCV_EXPENSE_SUBOBJ_REQUIRED,
424:                                "Expense Account Number");
425:                        returnVal = false;
426:                    }
427:
428:                    if (newCreditCardVendor.getExpenseFinancialObjectCode() == null) {
429:                        putFieldError(
430:                                "expenseFinancialObjectCode",
431:                                KFSKeyConstants.ERROR_CCV_EXPENSE_SUBOBJ_REQUIRED,
432:                                "Expense Object Code");
433:                        returnVal = false;
434:                    }
435:
436:                }
437:
438:                return returnVal;
439:            }
440:
441:            /**
442:             * Returns a SubObjCd object if SubObjCd object exists for "Income" or "Expense"
443:             * 
444:             * @param string determines whether or not to retrieve a income or expense sub object (valid values include "Income" or "Expense")
445:             * @return SubAccount Income/Expense SubObjCd object
446:             */
447:            private SubObjCd checkExistenceSubObj(String string) {
448:
449:                SubObjCd subObjCd = null;
450:
451:                if (string.equals("Income")) {
452:                    Map pkMap = new HashMap();
453:                    pkMap.put("chartOfAccountsCode", newCreditCardVendor
454:                            .getIncomeFinancialChartOfAccountsCode());
455:                    pkMap.put("accountNumber", newCreditCardVendor
456:                            .getIncomeAccountNumber());
457:                    pkMap.put("financialObjectCode", newCreditCardVendor
458:                            .getIncomeFinancialObjectCode());
459:                    pkMap.put("financialSubObjectCode", newCreditCardVendor
460:                            .getIncomeFinancialSubObjectCode());
461:                    subObjCd = (SubObjCd) super .getBoService()
462:                            .findByPrimaryKey(SubObjCd.class, pkMap);
463:                }
464:
465:                if (string.equals("Expense")) {
466:                    Map pkMap = new HashMap();
467:                    pkMap.put("chartOfAccountsCode", newCreditCardVendor
468:                            .getExpenseFinancialChartOfAccountsCode());
469:                    pkMap.put("accountNumber", newCreditCardVendor
470:                            .getExpenseAccountNumber());
471:                    pkMap.put("financialObjectCode", newCreditCardVendor
472:                            .getExpenseFinancialObjectCode());
473:                    pkMap.put("financialSubObjectCode", newCreditCardVendor
474:                            .getExpenseFinancialSubObjectCode());
475:                    subObjCd = (SubObjCd) super .getBoService()
476:                            .findByPrimaryKey(SubObjCd.class, pkMap);
477:                }
478:
479:                return subObjCd;
480:            }
481:
482:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.