Source Code Cross Referenced for OrganizationReversionGlobalRule.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » chart » 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.chart.rules 
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.chart.rules;
017:
018:        import java.util.Iterator;
019:
020:        import org.apache.commons.lang.StringUtils;
021:        import org.kuali.core.bo.PersistableBusinessObject;
022:        import org.kuali.core.document.MaintenanceDocument;
023:        import org.kuali.core.util.GlobalVariables;
024:        import org.kuali.core.util.ObjectUtils;
025:        import org.kuali.core.web.ui.KeyLabelPair;
026:        import org.kuali.kfs.KFSConstants;
027:        import org.kuali.kfs.KFSKeyConstants;
028:        import org.kuali.kfs.context.SpringContext;
029:        import org.kuali.module.chart.bo.ObjectCode;
030:        import org.kuali.module.chart.bo.OrganizationReversionGlobal;
031:        import org.kuali.module.chart.bo.OrganizationReversionGlobalDetail;
032:        import org.kuali.module.chart.bo.OrganizationReversionGlobalOrganization;
033:        import org.kuali.module.chart.lookup.keyvalues.OrganizationReversionCodeValuesFinder;
034:        import org.kuali.module.chart.maintenance.OrganizationReversionGlobalMaintainableImpl;
035:        import org.kuali.module.chart.service.ObjectCodeService;
036:        import org.kuali.module.chart.service.OrganizationReversionService;
037:
038:        /**
039:         * 
040:         * This class implements the business rules for {@link OrganizationReversionGlobal}
041:         */
042:        public class OrganizationReversionGlobalRule extends
043:                GlobalDocumentRuleBase {
044:            private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
045:                    .getLogger(OrganizationReversionGlobalRule.class);
046:            private OrganizationReversionGlobal globalOrganizationReversion;
047:            private OrganizationReversionService organizationReversionService;
048:            private ObjectCodeService objectCodeService;
049:
050:            /**
051:             * 
052:             * Constructs a OrganizationReversionGlobalRule
053:             * Pseudo-injects services 
054:             */
055:            public OrganizationReversionGlobalRule() {
056:                super ();
057:                setOrganizationReversionService(SpringContext
058:                        .getBean(OrganizationReversionService.class));
059:                setObjectCodeService(SpringContext
060:                        .getBean(ObjectCodeService.class));
061:            }
062:
063:            /**
064:             * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
065:             * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
066:             * all sub-objects from the DB by their primary keys, if available.
067:             * 
068:             * @param document - the maintenanceDocument being evaluated
069:             * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
070:             */
071:            @Override
072:            public void setupConvenienceObjects() {
073:                this .globalOrganizationReversion = (OrganizationReversionGlobal) super 
074:                        .getNewBo();
075:                for (OrganizationReversionGlobalDetail detail : this .globalOrganizationReversion
076:                        .getOrganizationReversionGlobalDetails()) {
077:                    detail.refreshNonUpdateableReferences();
078:                }
079:                for (OrganizationReversionGlobalOrganization org : this .globalOrganizationReversion
080:                        .getOrganizationReversionGlobalOrganizations()) {
081:                    org.refreshNonUpdateableReferences();
082:                }
083:            }
084:
085:            /**
086:             * Calls the basic rules check on document save:
087:             * <ul>
088:             * <li>{@link OrganizationReversionGlobalRule#checkSimpleRules(OrganizationReversionGlobal)}</li>
089:             * </ul>
090:             * Does not fail on rules failure
091:             * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
092:             */
093:            @Override
094:            protected boolean processCustomSaveDocumentBusinessRules(
095:                    MaintenanceDocument document) {
096:                checkSimpleRules(getGlobalOrganizationReversion());
097:                return true; // always return true on save
098:            }
099:
100:            /**
101:             * Calls the basic rules check on document approval:
102:             * <ul>
103:             * <li>{@link OrganizationReversionGlobalRule#checkSimpleRules(OrganizationReversionGlobal)}</li>
104:             * </ul>
105:             * Fails on rules failure
106:             * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomApproveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
107:             */
108:            @Override
109:            protected boolean processCustomApproveDocumentBusinessRules(
110:                    MaintenanceDocument document) {
111:                return checkSimpleRules(getGlobalOrganizationReversion());
112:            }
113:
114:            /**
115:             * Calls the basic rules check on document routing:
116:             * <ul>
117:             * <li>{@link OrganizationReversionGlobalRule#checkSimpleRules(OrganizationReversionGlobal)}</li>
118:             * </ul>
119:             * Fails on rules failure
120:             * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
121:             */
122:            @Override
123:            protected boolean processCustomRouteDocumentBusinessRules(
124:                    MaintenanceDocument document) {
125:                return checkSimpleRules(getGlobalOrganizationReversion());
126:            }
127:
128:            /**
129:             * This performs rules checks whenever a new {@link OrganizationReversionGlobalDetail} or {@link OrganizationReversionGlobalOrganization} is added
130:             * <p>
131:             * This includes:
132:             * <ul>
133:             * <li>{@link OrganizationReversionGlobalRule#checkDetailObjectCodeValidity(OrganizationReversionGlobal, OrganizationReversionGlobalDetail)}</li>
134:             * <li>{@link OrganizationReversionGlobalRule#checkDetailObjectReversionCodeValidity(OrganizationReversionGlobalDetail)}</li>
135:             * <li>ensure that the chart of accounts code and organization codes for {@link OrganizationReversionGlobalOrganization} are not empty values</li>
136:             * <li>{@link OrganizationReversionGlobalRule#checkAllObjectCodesForValidity(OrganizationReversionGlobal, OrganizationReversionGlobalOrganization)}</li>
137:             * <li>{@link OrganizationReversionGlobalRule#checkOrganizationChartValidity(OrganizationReversionGlobalOrganization)</li>
138:             * <li>{@link OrganizationReversionGlobalRule#checkOrganizationValidity(OrganizationReversionGlobalOrganization)</li>
139:             * <li>{@link OrganizationReversionGlobalRule#checkOrganizationReversionForOrganizationExists(OrganizationReversionGlobal, OrganizationReversionGlobalOrganization)</li>
140:             * <li>{@link OrganizationReversionGlobalRule#checkOrganizationIsNotAmongOrgRevOrganizations(OrganizationReversionGlobal, OrganizationReversionGlobalOrganization)</li>
141:             * </ul>
142:             * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomAddCollectionLineBusinessRules(org.kuali.core.document.MaintenanceDocument,
143:             *      java.lang.String, org.kuali.core.bo.PersistableBusinessObject)
144:             */
145:            @Override
146:            public boolean processCustomAddCollectionLineBusinessRules(
147:                    MaintenanceDocument document, String collectionName,
148:                    PersistableBusinessObject line) {
149:                boolean success = true;
150:                OrganizationReversionGlobal globalOrgRev = (OrganizationReversionGlobal) ((OrganizationReversionGlobalMaintainableImpl) document
151:                        .getNewMaintainableObject()).getBusinessObject();
152:                if (line instanceof  OrganizationReversionGlobalDetail) {
153:                    OrganizationReversionGlobalDetail detail = (OrganizationReversionGlobalDetail) line;
154:                    success &= checkDetailObjectCodeValidity(globalOrgRev,
155:                            detail);
156:                    success &= checkDetailObjectReversionCodeValidity(detail);
157:                } else if (line instanceof  OrganizationReversionGlobalOrganization) {
158:                    OrganizationReversionGlobalOrganization org = (OrganizationReversionGlobalOrganization) line;
159:                    if (!checkEmptyValue(org.getChartOfAccountsCode())) {
160:                        GlobalVariables.getErrorMap().putError(
161:                                "chartOfAccountsCode",
162:                                KFSKeyConstants.ERROR_REQUIRED,
163:                                "Chart of Accounts Code");
164:                    }
165:                    if (!checkEmptyValue(org.getOrganizationCode())) {
166:                        GlobalVariables.getErrorMap().putError(
167:                                "organizationCode",
168:                                KFSKeyConstants.ERROR_REQUIRED,
169:                                "Organization Code");
170:                    }
171:                    if (success) {
172:                        success &= checkAllObjectCodesForValidity(globalOrgRev,
173:                                org);
174:                        success &= checkOrganizationChartValidity(org);
175:                        success &= checkOrganizationValidity(org);
176:                        success &= checkOrganizationReversionForOrganizationExists(
177:                                globalOrgRev, org);
178:                        success &= checkOrganizationIsNotAmongOrgRevOrganizations(
179:                                globalOrgRev, org);
180:                    }
181:                }
182:                return success;
183:            }
184:
185:            /**
186:             * Convenient convenience method to test all the simple rules in one go. Including:
187:             * <ul>
188:             * <li>{@link OrganizationReversionGlobalRule#checkBudgetReversionAccountPair(OrganizationReversionGlobal)}</li>
189:             * <li>{@link OrganizationReversionGlobalRule#checkCashReversionAccountPair(OrganizationReversionGlobal)}</li>
190:             * <li>{@link OrganizationReversionGlobalRule#areAllDetailsValid(OrganizationReversionGlobal)}</li>
191:             * <li>{@link OrganizationReversionGlobalRule#areAllOrganizationsValid(OrganizationReversionGlobal)</li>
192:             * </ul>
193:             * @param globalOrgRev the global organization reversion to check
194:             * @return true if the new global organization reversion passes all tests, false if it deviates even a tiny little bit
195:             */
196:            public boolean checkSimpleRules(
197:                    OrganizationReversionGlobal globalOrgRev) {
198:                boolean success = true;
199:
200:                success &= checkBudgetReversionAccountPair(globalOrgRev);
201:                success &= checkCashReversionAccountPair(globalOrgRev);
202:
203:                success &= areAllDetailsValid(globalOrgRev);
204:                success &= areAllOrganizationsValid(globalOrgRev);
205:
206:                return success;
207:            }
208:
209:            /**
210:             * This method makes sure that if one part of the Budget Reversion Chart/Account pair is specified, both are specified, or an
211:             * error is thrown.
212:             * 
213:             * @param globalOrgRev the Global Organization Reversion to check
214:             * @return true if budget reversion chart/account pair is specified correctly, false if otherwise
215:             */
216:            public boolean checkBudgetReversionAccountPair(
217:                    OrganizationReversionGlobal globalOrgRev) {
218:                boolean success = true;
219:                if ((!StringUtils.isBlank(globalOrgRev
220:                        .getBudgetReversionChartOfAccountsCode()) && StringUtils
221:                        .isBlank(globalOrgRev.getBudgetReversionAccountNumber()))
222:                        || (StringUtils.isBlank(globalOrgRev
223:                                .getBudgetReversionChartOfAccountsCode()) && !StringUtils
224:                                .isBlank(globalOrgRev
225:                                        .getBudgetReversionAccountNumber()))) {
226:                    success = false;
227:                    GlobalVariables
228:                            .getErrorMap()
229:                            .putError(
230:                                    MAINTAINABLE_ERROR_PREFIX
231:                                            + "budgetReversionChartOfAccountsCode",
232:                                    KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_BUDGET_REVERSION_INCOMPLETE,
233:                                    new String[] {});
234:                }
235:                return success;
236:            }
237:
238:            /**
239:             * This method makes sure that if one part of the Cash Reversion Chart/Account pair is specified, both are specified, or an
240:             * error is thrown.
241:             * 
242:             * @param globalOrgRev the Global Organization Reversion to check
243:             * @return true if cash reversion chart/account pair is specified correctly, false if otherwise
244:             */
245:            public boolean checkCashReversionAccountPair(
246:                    OrganizationReversionGlobal globalOrgRev) {
247:                boolean success = true;
248:                if ((!StringUtils.isBlank(globalOrgRev
249:                        .getCashReversionFinancialChartOfAccountsCode()) && StringUtils
250:                        .isBlank(globalOrgRev.getCashReversionAccountNumber()))
251:                        || (StringUtils
252:                                .isBlank(globalOrgRev
253:                                        .getCashReversionFinancialChartOfAccountsCode()) && !StringUtils
254:                                .isBlank(globalOrgRev
255:                                        .getCashReversionAccountNumber()))) {
256:                    success = false;
257:                    GlobalVariables
258:                            .getErrorMap()
259:                            .putError(
260:                                    MAINTAINABLE_ERROR_PREFIX
261:                                            + "cashReversionFinancialChartOfAccountsCode",
262:                                    KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_CASH_REVERSION_INCOMPLETE,
263:                                    new String[] {});
264:                }
265:                return success;
266:            }
267:
268:            /**
269:             * Tests if all of the {@link OrganizationReversionGlobalDetail} objects associated with the given global organization reversion are
270:             * valid.
271:             * 
272:             * @param globalOrgRev the global organization reversion to check
273:             * @return true if valid, false otherwise
274:             */
275:            public boolean areAllDetailsValid(
276:                    OrganizationReversionGlobal globalOrgRev) {
277:                boolean success = true;
278:                for (int i = 0; i < globalOrgRev
279:                        .getOrganizationReversionGlobalDetails().size(); i++) {
280:                    OrganizationReversionGlobalDetail detail = globalOrgRev
281:                            .getOrganizationReversionGlobalDetails().get(i);
282:
283:                    String errorPath = MAINTAINABLE_ERROR_PREFIX
284:                            + "organizationReversionGlobalDetails[" + i + "]";
285:                    GlobalVariables.getErrorMap().addToErrorPath(errorPath);
286:
287:                    success &= this 
288:                            .checkDetailObjectCodeAndReversionCodeBothPresentOrNot(detail);
289:                    if (!StringUtils.isBlank(detail
290:                            .getOrganizationReversionObjectCode())
291:                            && !StringUtils.isBlank(detail
292:                                    .getOrganizationReversionCode())) {
293:                        success &= this 
294:                                .checkDetailOrgReversionCategoryValidity(detail);
295:                        success &= this .checkDetailObjectCodeValidity(
296:                                globalOrgRev, detail);
297:                        success &= this 
298:                                .checkDetailObjectReversionCodeValidity(detail);
299:                    }
300:                    GlobalVariables.getErrorMap()
301:                            .removeFromErrorPath(errorPath);
302:                }
303:                return success;
304:            }
305:
306:            /**
307:             * For a detail record, checks whether the object code and the organization reversion code are both filled in/selected
308:             * or both blank.
309:             * 
310:             * @param detail OrganizationReversionGlobalDetail to check
311:             * @return @return true if both filled in or both blank, false if otherwise
312:             */
313:            protected boolean checkDetailObjectCodeAndReversionCodeBothPresentOrNot(
314:                    OrganizationReversionGlobalDetail detail) {
315:                // both blank, or both filled in, so isBlank must return the same result for both of the values
316:                boolean success = StringUtils.isBlank(detail
317:                        .getOrganizationReversionObjectCode()) == StringUtils
318:                        .isBlank(detail.getOrganizationReversionCode());
319:                if (!success) {
320:                    if (StringUtils.isBlank(detail
321:                            .getOrganizationReversionObjectCode())) {
322:                        GlobalVariables
323:                                .getErrorMap()
324:                                .putError(
325:                                        "organizationReversionObjectCode",
326:                                        KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_OBJECT_CODE_IS_BLANK_WHEN_ORG_REVERSION_CODE_IS_NOT);
327:                    }
328:                    if (StringUtils.isBlank(detail
329:                            .getOrganizationReversionCode())) {
330:                        GlobalVariables
331:                                .getErrorMap()
332:                                .putError(
333:                                        "organizationReversionCode",
334:                                        KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_ORG_REVERSION_CODE_IS_BLANK_WHEN_OBJECT_CODE_IS_NOT);
335:                    }
336:
337:                }
338:                return success;
339:            }
340:
341:            /**
342:             * Tests if the Organization Reversion Category existed in the database and was active.
343:             * 
344:             * @param detail OrganizationReversionGlobalDetail to check
345:             * @return true if the category is valid, false if otherwise
346:             */
347:            public boolean checkDetailOrgReversionCategoryValidity(
348:                    OrganizationReversionGlobalDetail detail) {
349:                boolean success = true;
350:                if (StringUtils.isBlank(detail
351:                        .getOrganizationReversionCategoryCode())) {
352:                    success = false;
353:                    GlobalVariables.getErrorMap().putError(
354:                            "organizationReversionCategoryCode",
355:                            KFSKeyConstants.ERROR_REQUIRED, new String[] {});
356:                } else {
357:                    detail
358:                            .refreshReferenceObject("organizationReversionCategory");
359:                    if (detail.getOrganizationReversionCategory() == null
360:                            || !detail
361:                                    .getOrganizationReversionCategory()
362:                                    .isOrganizationReversionCategoryActiveIndicator()) {
363:                        success = false;
364:                        GlobalVariables
365:                                .getErrorMap()
366:                                .putError(
367:                                        "organizationReversionCategoryCode",
368:                                        KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_INVALID_ORG_REVERSION_CATEGORY,
369:                                        new String[] { detail
370:                                                .getOrganizationReversionCategoryCode() });
371:                    }
372:                }
373:                return success;
374:            }
375:
376:            /**
377:             * For each organization, tests if the object code in the detail exists in the system and is active
378:             * 
379:             * @param detail the OrganizationReversionGlobalDetail to check
380:             * @return true if it is valid, false if otherwise
381:             */
382:            public boolean checkDetailObjectCodeValidity(
383:                    OrganizationReversionGlobal globalOrgRev,
384:                    OrganizationReversionGlobalDetail detail) {
385:                boolean success = true;
386:                for (OrganizationReversionGlobalOrganization org : globalOrgRev
387:                        .getOrganizationReversionGlobalOrganizations()) {
388:                    if (!validObjectCode(
389:                            globalOrgRev.getUniversityFiscalYear(), org
390:                                    .getChartOfAccountsCode(), detail
391:                                    .getOrganizationReversionObjectCode())) {
392:                        success = false;
393:                        GlobalVariables
394:                                .getErrorMap()
395:                                .putError(
396:                                        "organizationReversionObjectCode",
397:                                        KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_OBJECT_CODE_INVALID,
398:                                        new String[] {
399:                                                globalOrgRev
400:                                                        .getUniversityFiscalYear()
401:                                                        .toString(),
402:                                                org.getChartOfAccountsCode(),
403:                                                detail
404:                                                        .getOrganizationReversionObjectCode(),
405:                                                org.getChartOfAccountsCode(),
406:                                                org.getOrganizationCode() });
407:                    }
408:                }
409:                return success;
410:            }
411:
412:            /**
413:             * This method loops through each of the OrganizationReversionGlobalDetail objects, checking that the entered object codes for
414:             * each of them are compatible with the OrganizationReversionGlobalOrganization specified.
415:             * 
416:             * @param globalOrgRev the global organization reversion to check
417:             * @param org the OrganizationReversionGlobalOrganization with a new chart to check against all of the object codes
418:             * @return true if there are no conflicts, false if otherwise
419:             */
420:            public boolean checkAllObjectCodesForValidity(
421:                    OrganizationReversionGlobal globalOrgRev,
422:                    OrganizationReversionGlobalOrganization org) {
423:                boolean success = true;
424:                for (OrganizationReversionGlobalDetail detail : globalOrgRev
425:                        .getOrganizationReversionGlobalDetails()) {
426:                    if (!validObjectCode(
427:                            globalOrgRev.getUniversityFiscalYear(), org
428:                                    .getChartOfAccountsCode(), detail
429:                                    .getOrganizationReversionObjectCode())) {
430:                        success = false;
431:                        GlobalVariables
432:                                .getErrorMap()
433:                                .putError(
434:                                        "organizationCode",
435:                                        KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_OBJECT_CODE_INVALID,
436:                                        new String[] {
437:                                                globalOrgRev
438:                                                        .getUniversityFiscalYear()
439:                                                        .toString(),
440:                                                org.getChartOfAccountsCode(),
441:                                                detail
442:                                                        .getOrganizationReversionObjectCode(),
443:                                                org.getChartOfAccountsCode(),
444:                                                org.getOrganizationCode() });
445:                    }
446:                }
447:                return success;
448:            }
449:
450:            /**
451:             * This method checks if an object code with the given primary key fields exists in the database.
452:             * 
453:             * @param universityFiscalYear the university fiscal year of the object code
454:             * @param chartOfAccountsCode the chart of accounts code of the object code
455:             * @param objectCode the object code itself
456:             * @return true if it exists (or was not filled in to begin with), false if otherwise
457:             */
458:            public boolean validObjectCode(Integer universityFiscalYear,
459:                    String chartOfAccountsCode, String objectCode) {
460:                if (!StringUtils.isBlank(objectCode)
461:                        && universityFiscalYear != null
462:                        && !StringUtils.isBlank(chartOfAccountsCode)) {
463:                    ObjectCode objCode = objectCodeService.getByPrimaryId(
464:                            universityFiscalYear, chartOfAccountsCode,
465:                            objectCode);
466:                    return (ObjectUtils.isNotNull(objCode));
467:                } else {
468:                    return true; // blank object code? well, it's not required...and thus, it's a valid choice
469:                }
470:            }
471:
472:            /**
473:             * Tests if the object reversion code is a valid code.
474:             * 
475:             * @param detail the OrganizationReversionGlobalDetail to check
476:             * @return true if it the detail is valid, false if otherwise
477:             */
478:            public boolean checkDetailObjectReversionCodeValidity(
479:                    OrganizationReversionGlobalDetail detail) {
480:                boolean success = true;
481:                if (!StringUtils.isBlank(detail.getOrganizationReversionCode())) {
482:                    boolean foundInList = false;
483:                    // TODO Dude!! The *only* place that the org reversion code values are defined
484:                    // is in the lookup class, so I've got to use a web-based class to actually
485:                    // search through the values. Is that right good & healthy?
486:                    for (Object kvPairObj : new OrganizationReversionCodeValuesFinder()
487:                            .getKeyValues()) {
488:                        KeyLabelPair kvPair = (KeyLabelPair) kvPairObj;
489:                        if (kvPair.getKey().toString().equals(
490:                                detail.getOrganizationReversionCode())) {
491:                            foundInList = true;
492:                            break;
493:                        }
494:                    }
495:                    if (!foundInList) {
496:                        success = false; // we've failed to find the code in the list...FAILED!
497:                        GlobalVariables
498:                                .getErrorMap()
499:                                .putError(
500:                                        "organizationReversionCode",
501:                                        KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_INVALID_ORG_REVERSION_CODE,
502:                                        new String[] { detail
503:                                                .getOrganizationReversionCode() });
504:                    }
505:                }
506:                return success;
507:            }
508:
509:            /**
510:             * This method tests if all the OrganizationReversionGlobalOrganization objects associated with the given global organization
511:             * reversion pass all of their tests.
512:             * 
513:             * @param globalOrgRev the global organization reversion to check
514:             * @return true if valid, false otherwise
515:             */
516:            public boolean areAllOrganizationsValid(
517:                    OrganizationReversionGlobal globalOrgRev) {
518:                boolean success = true;
519:                if (globalOrgRev.getOrganizationReversionGlobalOrganizations()
520:                        .size() == 0) {
521:                    putFieldError(
522:                            KFSConstants.MAINTENANCE_ADD_PREFIX
523:                                    + "organizationReversionGlobalOrganizations.organizationCode",
524:                            KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_NO_ORGANIZATIONS);
525:                } else {
526:                    for (int i = 0; i < globalOrgRev
527:                            .getOrganizationReversionGlobalOrganizations()
528:                            .size(); i++) {
529:                        OrganizationReversionGlobalOrganization org = globalOrgRev
530:                                .getOrganizationReversionGlobalOrganizations()
531:                                .get(i);
532:                        String errorPath = MAINTAINABLE_ERROR_PREFIX
533:                                + "organizationReversionGlobalOrganizations["
534:                                + i + "]";
535:                        GlobalVariables.getErrorMap().addToErrorPath(errorPath);
536:                        success &= checkAllObjectCodesForValidity(globalOrgRev,
537:                                org);
538:                        success &= checkOrganizationValidity(org);
539:                        success &= checkOrganizationChartValidity(org);
540:                        success &= checkOrganizationReversionForOrganizationExists(
541:                                globalOrgRev, org);
542:                        GlobalVariables.getErrorMap().removeFromErrorPath(
543:                                errorPath);
544:                    }
545:                }
546:                return success;
547:            }
548:
549:            /**
550:             * Tests if the the organization of the given OrganizationReversionGlobalOrganization is within the chart of the global
551:             * organization reversion as a whole.
552:             * 
553:             * @param globalOrgRev the global organization reversion that is currently being validated.
554:             * @param org the OrganizationReversionGlobalOrganization to check
555:             * @return true if valid, false otherwise
556:             */
557:            public boolean checkOrganizationChartValidity(
558:                    OrganizationReversionGlobalOrganization org) {
559:                boolean success = true;
560:                if (StringUtils.isBlank(org.getChartOfAccountsCode())) {
561:                    if (!StringUtils.isBlank(org.getOrganizationCode())) {
562:                        success = false;
563:                        GlobalVariables.getErrorMap()
564:                                .putError("chartOfAccountsCode",
565:                                        KFSKeyConstants.ERROR_REQUIRED,
566:                                        new String[] {});
567:                    }
568:                } else {
569:                    org.setChartOfAccountsCode(org.getChartOfAccountsCode()
570:                            .toUpperCase());
571:                    org.refreshReferenceObject("chartOfAccounts");
572:                    if (org.getChartOfAccounts() == null) {
573:                        success = false;
574:                        GlobalVariables
575:                                .getErrorMap()
576:                                .putError(
577:                                        "chartOfAccountsCode",
578:                                        KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_INVALID_CHART,
579:                                        new String[] { org
580:                                                .getChartOfAccountsCode() });
581:                    }
582:                }
583:                return success;
584:            }
585:
586:            /**
587:             * Tests if the given OrganizationReversionGlobalOrganization's Organization is active and within the system.
588:             * 
589:             * @param org the OrganizationReversionGlobalOrganization to check
590:             * @return true if valid, false otherwise
591:             */
592:            public boolean checkOrganizationValidity(
593:                    OrganizationReversionGlobalOrganization org) {
594:                boolean success = true;
595:                if (StringUtils.isBlank(org.getOrganizationCode())) {
596:                    if (!StringUtils.isBlank(org.getChartOfAccountsCode())) {
597:                        success = false;
598:                        GlobalVariables.getErrorMap()
599:                                .putError("organizationCode",
600:                                        KFSKeyConstants.ERROR_REQUIRED,
601:                                        new String[] {});
602:                    }
603:                } else if (!StringUtils.isBlank(org.getChartOfAccountsCode())) {
604:                    org.refreshReferenceObject("organization");
605:                    if (org.getOrganization() == null) {
606:                        success = false;
607:                        GlobalVariables
608:                                .getErrorMap()
609:                                .putError(
610:                                        "organizationCode",
611:                                        KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_INVALID_ORGANIZATION,
612:                                        new String[] {
613:                                                org.getChartOfAccountsCode(),
614:                                                org.getOrganizationCode() });
615:                    }
616:                }
617:                return success;
618:            }
619:
620:            /**
621:             * Checks that an organization reversion for the given organization reversion change and organization reversion change
622:             * organization exist.
623:             * 
624:             * @param globalOrgRev global Organization Reversion to check
625:             * @param org organization within that Global Organization Reversion to check specifically
626:             * @return true if organization reversion for organization exists, false if otherwise
627:             */
628:            public boolean checkOrganizationReversionForOrganizationExists(
629:                    OrganizationReversionGlobal globalOrgRev,
630:                    OrganizationReversionGlobalOrganization org) {
631:                boolean success = true;
632:                if (globalOrgRev.getUniversityFiscalYear() != null) {
633:                    if (organizationReversionService.getByPrimaryId(
634:                            globalOrgRev.getUniversityFiscalYear(), org
635:                                    .getChartOfAccountsCode(), org
636:                                    .getOrganizationCode()) == null) {
637:                        success = false;
638:                        GlobalVariables
639:                                .getErrorMap()
640:                                .putError(
641:                                        "organizationCode",
642:                                        KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_NO_ORG_REVERSION,
643:                                        new String[] {
644:                                                globalOrgRev
645:                                                        .getUniversityFiscalYear()
646:                                                        .toString(),
647:                                                org.getChartOfAccountsCode(),
648:                                                org.getOrganizationCode() });
649:                    }
650:                }
651:                return success;
652:            }
653:
654:            /**
655:             * This method checks if a newly added organization is already among the organizations already listed. WARNING: only use on add
656:             * line rules; there's no good way to use this method when testing the entire document.
657:             * 
658:             * @param globalOrgRev the global Organization Reversion to check
659:             * @param orgRevOrg the newly adding organization reversion change organization
660:             * @return true if organization should be added as it is not currently in the collection, false if otherwise
661:             */
662:            public boolean checkOrganizationIsNotAmongOrgRevOrganizations(
663:                    OrganizationReversionGlobal globalOrgRev,
664:                    OrganizationReversionGlobalOrganization orgRevOrg) {
665:                boolean success = true;
666:                Iterator<OrganizationReversionGlobalOrganization> iter = globalOrgRev
667:                        .getOrganizationReversionGlobalOrganizations()
668:                        .iterator();
669:                while (iter.hasNext() && success) {
670:                    OrganizationReversionGlobalOrganization currOrg = iter
671:                            .next();
672:                    if (areContainingSameOrganizations(currOrg, orgRevOrg)) {
673:                        success = false;
674:                        GlobalVariables
675:                                .getErrorMap()
676:                                .putError(
677:                                        "organizationCode",
678:                                        KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ORG_REVERSION_DUPLICATE_ORGS,
679:                                        new String[] {
680:                                                orgRevOrg
681:                                                        .getChartOfAccountsCode(),
682:                                                orgRevOrg.getOrganizationCode() });
683:                    }
684:                }
685:                return success;
686:            }
687:
688:            /**
689:             * This method tests if two OrganizationReversionGlobalOrganization objects are holding the same underlying Organization.
690:             * 
691:             * @param orgRevOrgA the first OrganizationReversionGlobalOrganization to check
692:             * @param orgRevOrgB the second OrganizationReversionGlobalOrganization to check
693:             * @return true if they share the organization, false if otherwise
694:             */
695:            public static boolean areContainingSameOrganizations(
696:                    OrganizationReversionGlobalOrganization orgRevOrgA,
697:                    OrganizationReversionGlobalOrganization orgRevOrgB) {
698:                boolean containingSame = false;
699:                if (orgRevOrgA.getChartOfAccountsCode() != null
700:                        && orgRevOrgB.getChartOfAccountsCode() != null
701:                        && orgRevOrgA.getOrganizationCode() != null
702:                        && orgRevOrgB.getOrganizationCode() != null) {
703:                    containingSame = (orgRevOrgA.getChartOfAccountsCode()
704:                            .equals(orgRevOrgB.getChartOfAccountsCode()) && orgRevOrgA
705:                            .getOrganizationCode().equals(
706:                                    orgRevOrgB.getOrganizationCode()));
707:                }
708:                return containingSame;
709:            }
710:
711:            public void setOrganizationReversionService(
712:                    OrganizationReversionService organizationReversionService) {
713:                this .organizationReversionService = organizationReversionService;
714:            }
715:
716:            public void setObjectCodeService(ObjectCodeService objectCodeService) {
717:                this .objectCodeService = objectCodeService;
718:            }
719:
720:            private OrganizationReversionGlobal getGlobalOrganizationReversion() {
721:                return this.globalOrganizationReversion;
722:            }
723:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.