Source Code Cross Referenced for ScrubberValidatorImpl.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » labor » 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.labor.service.impl 
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.labor.service.impl;
017:
018:        import java.util.ArrayList;
019:        import java.util.Calendar;
020:        import java.util.HashMap;
021:        import java.util.List;
022:        import java.util.Map;
023:
024:        import org.kuali.core.service.BusinessObjectService;
025:        import org.kuali.core.service.KualiConfigurationService;
026:        import org.kuali.core.service.PersistenceService;
027:        import org.kuali.core.service.PersistenceStructureService;
028:        import org.kuali.kfs.KFSConstants;
029:        import org.kuali.kfs.KFSKeyConstants;
030:        import org.kuali.kfs.KFSPropertyConstants;
031:        import org.kuali.kfs.bo.GeneralLedgerPendingEntry;
032:        import org.kuali.kfs.context.SpringContext;
033:        import org.kuali.kfs.service.ParameterService;
034:        import org.kuali.kfs.service.impl.ParameterConstants;
035:        import org.kuali.module.chart.bo.Account;
036:        import org.kuali.module.chart.service.AccountService;
037:        import org.kuali.module.chart.service.BalanceTypService;
038:        import org.kuali.module.gl.batch.ScrubberStep;
039:        import org.kuali.module.gl.bo.OriginEntry;
040:        import org.kuali.module.gl.bo.OriginEntryFull;
041:        import org.kuali.module.gl.bo.UniversityDate;
042:        import org.kuali.module.gl.service.OriginEntryLookupService;
043:        import org.kuali.module.gl.service.ScrubberValidator;
044:        import org.kuali.module.gl.util.Message;
045:        import org.kuali.module.gl.util.ObjectHelper;
046:        import org.kuali.module.labor.LaborConstants;
047:        import org.kuali.module.labor.batch.LaborScrubberStep;
048:        import org.kuali.module.labor.bo.LaborObject;
049:        import org.kuali.module.labor.bo.LaborOriginEntry;
050:        import org.springframework.util.StringUtils;
051:
052:        /**
053:         * Service implementation of ScrubberValidator.
054:         */
055:        public class ScrubberValidatorImpl implements  ScrubberValidator {
056:            private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
057:                    .getLogger(ScrubberValidatorImpl.class);
058:
059:            private KualiConfigurationService kualiConfigurationService;
060:            private BusinessObjectService businessObjectService;
061:            private ParameterService parameterService;
062:            private AccountService accountService;
063:            private PersistenceService persistenceService;
064:            private ScrubberValidator scrubberValidator;
065:            private PersistenceStructureService persistenceStructureService;
066:            private ThreadLocal<OriginEntryLookupService> referenceLookup = new ThreadLocal<OriginEntryLookupService>();
067:
068:            /**
069:             * @see org.kuali.module.labor.service.LaborScrubberValidator#validateTransaction(owrg.kuali.module.labor.bo.LaborOriginEntry,
070:             *      org.kuali.module.labor.bo.LaborOriginEntry, org.kuali.module.gl.bo.UniversityDate)
071:             */
072:            public List<Message> validateTransaction(OriginEntry originEntry,
073:                    OriginEntry scrubbedEntry,
074:                    UniversityDate universityRunDate, boolean laborIndicator) {
075:                LOG.debug("validateTransaction() started");
076:                List<Message> errors = new ArrayList<Message>();
077:
078:                LaborOriginEntry laborOriginEntry = (LaborOriginEntry) originEntry;
079:                LaborOriginEntry laborScrubbedEntry = (LaborOriginEntry) scrubbedEntry;
080:
081:                scrubberValidator.setReferenceLookup(referenceLookup.get());
082:
083:                // gl scrubber validation
084:                errors = scrubberValidator.validateTransaction(
085:                        laborOriginEntry, laborScrubbedEntry,
086:                        universityRunDate, laborIndicator);
087:                refreshOriginEntryReferences(laborOriginEntry);
088:                refreshOriginEntryReferences(laborScrubbedEntry);
089:
090:                if (org.apache.commons.lang.StringUtils
091:                        .isBlank(laborOriginEntry.getEmplid())) {
092:                    laborScrubbedEntry.setEmplid(KFSConstants.getDashEmplId());
093:                }
094:
095:                if (org.apache.commons.lang.StringUtils
096:                        .isBlank(laborOriginEntry.getPositionNumber())) {
097:                    laborScrubbedEntry.setPositionNumber(KFSConstants
098:                            .getDashPositionNumber());
099:                }
100:
101:                Message err = null;
102:
103:                err = validatePayrollEndFiscalYear(laborOriginEntry,
104:                        laborScrubbedEntry, universityRunDate);
105:                if (err != null) {
106:                    errors.add(err);
107:                }
108:
109:                err = validatePayrollEndFiscalPeriodCode(laborOriginEntry,
110:                        laborScrubbedEntry, universityRunDate);
111:                if (err != null) {
112:                    errors.add(err);
113:                }
114:
115:                err = validateAccount(laborOriginEntry, laborScrubbedEntry,
116:                        universityRunDate);
117:                if (err != null) {
118:                    errors.add(err);
119:                }
120:
121:                return errors;
122:            }
123:
124:            /**
125:             * This method is for refreshing References of Origin Entry
126:             */
127:            protected void refreshOriginEntryReferences(
128:                    OriginEntryFull originEntry) {
129:                Map<String, Class> referenceClasses = persistenceStructureService
130:                        .listReferenceObjectFields(originEntry.getClass());
131:                for (String reference : referenceClasses.keySet()) {
132:                    if (KFSPropertyConstants.PROJECT.equals(reference)) {
133:                        if (KFSConstants.getDashProjectCode().equals(
134:                                originEntry.getProjectCode())) {
135:                            originEntry.setProject(null);
136:                        } else {
137:                            persistenceService.retrieveReferenceObject(
138:                                    originEntry, reference);
139:                        }
140:                    } else if (KFSPropertyConstants.FINANCIAL_SUB_OBJECT
141:                            .equals(reference)) {
142:                        if (KFSConstants
143:                                .getDashFinancialSubObjectCode()
144:                                .equals(originEntry.getFinancialSubObjectCode())) {
145:                            originEntry.setFinancialSubObject(null);
146:                        } else {
147:                            persistenceService.retrieveReferenceObject(
148:                                    originEntry, reference);
149:                        }
150:                    } else if (KFSPropertyConstants.SUB_ACCOUNT
151:                            .equals(reference)) {
152:                        if (KFSConstants.getDashSubAccountNumber().equals(
153:                                originEntry.getSubAccountNumber())) {
154:                            originEntry.setSubAccount(null);
155:                        } else {
156:                            persistenceService.retrieveReferenceObject(
157:                                    originEntry, reference);
158:                        }
159:                    } else {
160:                        persistenceService.retrieveReferenceObject(originEntry,
161:                                reference);
162:                    }
163:                }
164:            }
165:
166:            /**
167:             * Sets the scrubberValidator attribute value.
168:             * 
169:             * @param sv The scrubberValidator to set.
170:             */
171:            public void setScrubberValidator(ScrubberValidator sv) {
172:                scrubberValidator = sv;
173:            }
174:
175:            /**
176:             * This method is for validation of payrollEndFiscalYear
177:             */
178:            private Message validatePayrollEndFiscalYear(
179:                    LaborOriginEntry laborOriginEntry,
180:                    LaborOriginEntry laborWorkingEntry,
181:                    UniversityDate universityRunDate) {
182:                LOG.debug("validateFiscalYear() started");
183:
184:                if ((laborOriginEntry.getPayrollEndDateFiscalYear() == null)
185:                        || (laborOriginEntry.getUniversityFiscalYear()
186:                                .intValue() == 0)) {
187:                    laborOriginEntry.setUniversityFiscalYear(universityRunDate
188:                            .getUniversityFiscalYear());
189:                    laborWorkingEntry.setUniversityFiscalYear(universityRunDate
190:                            .getUniversityFiscalYear());
191:
192:                    // Retrieve these objects because the fiscal year is the primary key for them
193:                    persistenceService.retrieveReferenceObject(
194:                            laborOriginEntry,
195:                            KFSPropertyConstants.FINANCIAL_SUB_OBJECT);
196:                    persistenceService.retrieveReferenceObject(
197:                            laborOriginEntry,
198:                            KFSPropertyConstants.FINANCIAL_OBJECT);
199:                    persistenceService.retrieveReferenceObject(
200:                            laborOriginEntry,
201:                            KFSPropertyConstants.ACCOUNTING_PERIOD);
202:                    persistenceService.retrieveReferenceObject(
203:                            laborOriginEntry, KFSPropertyConstants.OPTION);
204:                } else {
205:                    laborWorkingEntry.setUniversityFiscalYear(laborOriginEntry
206:                            .getUniversityFiscalYear());
207:                    laborWorkingEntry.setOption(laborOriginEntry.getOption());
208:                }
209:
210:                if (laborOriginEntry.getOption() == null) {
211:                    return new Message(
212:                            kualiConfigurationService
213:                                    .getPropertyString(KFSKeyConstants.ERROR_UNIV_FISCAL_YR_NOT_FOUND)
214:                                    + " ("
215:                                    + laborOriginEntry
216:                                            .getUniversityFiscalYear() + ")",
217:                            Message.TYPE_FATAL);
218:                }
219:                return null;
220:            }
221:
222:            /**
223:             * This method is for validation of PayrollEndFiscalPeriodCode
224:             */
225:            private Message validatePayrollEndFiscalPeriodCode(
226:                    LaborOriginEntry laborOriginEntry,
227:                    LaborOriginEntry laborWorkingEntry,
228:                    UniversityDate universityRunDate) {
229:                LOG.debug("validateUniversityFiscalPeriodCode() started");
230:
231:                if (!StringUtils.hasText(laborOriginEntry
232:                        .getUniversityFiscalPeriodCode())) {
233:                    laborWorkingEntry
234:                            .setUniversityFiscalPeriodCode(universityRunDate
235:                                    .getUniversityFiscalAccountingPeriod());
236:                    laborWorkingEntry.setUniversityFiscalYear(universityRunDate
237:                            .getUniversityFiscalYear());
238:
239:                    // Retrieve these objects because the fiscal year is the primary key for them
240:                    persistenceService.retrieveReferenceObject(
241:                            laborOriginEntry, "financialSubObject");
242:                    persistenceService.retrieveReferenceObject(
243:                            laborOriginEntry, "financialObject");
244:                    persistenceService.retrieveReferenceObject(
245:                            laborOriginEntry, "accountingPeriod");
246:                    persistenceService.retrieveReferenceObject(
247:                            laborOriginEntry, "option");
248:                } else {
249:                    if (laborOriginEntry.getAccountingPeriod() == null) {
250:                        return new Message(
251:                                kualiConfigurationService
252:                                        .getPropertyString(KFSKeyConstants.ERROR_ACCOUNTING_PERIOD_NOT_FOUND)
253:                                        + " ("
254:                                        + laborOriginEntry
255:                                                .getUniversityFiscalPeriodCode()
256:                                        + ")", Message.TYPE_FATAL);
257:                    }
258:                    laborWorkingEntry
259:                            .setUniversityFiscalPeriodCode(laborOriginEntry
260:                                    .getUniversityFiscalPeriodCode());
261:                }
262:
263:                return null;
264:            }
265:
266:            /**
267:             * Sets the persistenceStructureService attribute value.
268:             * 
269:             * @param persistenceStructureService The persistenceStructureService to set.
270:             */
271:            public void setPersistenceStructureService(
272:                    PersistenceStructureService persistenceStructureService) {
273:                this .persistenceStructureService = persistenceStructureService;
274:            }
275:
276:            /**
277:             * Performs Account Validation.
278:             */
279:            private Message validateAccount(LaborOriginEntry laborOriginEntry,
280:                    LaborOriginEntry laborWorkingEntry,
281:                    UniversityDate universityRunDate) {
282:                LOG.debug("validateAccount() started");
283:
284:                Account account = laborOriginEntry.getAccount();
285:                boolean suspenseAccountLogicInd = SpringContext
286:                        .getBean(ParameterService.class)
287:                        .getIndicatorParameter(
288:                                LaborScrubberStep.class,
289:                                LaborConstants.Scrubber.SUSPENSE_ACCOUNT_LOGIC_PARAMETER);
290:                if (account == null) {
291:                    if (suspenseAccountLogicInd) {
292:                        return useSuspenseAccount(laborWorkingEntry);
293:                    }
294:                    return new Message(
295:                            kualiConfigurationService
296:                                    .getPropertyString(KFSKeyConstants.ERROR_ACCOUNT_NOT_FOUND)
297:                                    + "("
298:                                    + laborOriginEntry.getChartOfAccountsCode()
299:                                    + "-"
300:                                    + laborOriginEntry.getAccountNumber()
301:                                    + ")", Message.TYPE_FATAL);
302:                }
303:
304:                // default
305:                laborWorkingEntry.setAccount(account);
306:                laborWorkingEntry.setChartOfAccountsCode(account
307:                        .getChartOfAccountsCode());
308:                laborWorkingEntry.setAccountNumber(account.getAccountNumber());
309:
310:                // no further validation for gl annual doc type
311:                String glAnnualClosingType = SpringContext
312:                        .getBean(ParameterService.class)
313:                        .getParameterValue(
314:                                ParameterConstants.GENERAL_LEDGER_BATCH.class,
315:                                KFSConstants.SystemGroupParameterNames.GL_ANNUAL_CLOSING_DOC_TYPE);
316:                if (glAnnualClosingType.equals(laborOriginEntry
317:                        .getFinancialDocumentTypeCode())) {
318:                    return null;
319:                }
320:
321:                /* Sub-Fund Wage Exclusion */
322:                boolean subfundWageExclusionInd = SpringContext
323:                        .getBean(ParameterService.class)
324:                        .getIndicatorParameter(
325:                                LaborScrubberStep.class,
326:                                LaborConstants.Scrubber.SUBFUND_WAGE_EXCLUSION_PARAMETER);
327:                String[] nonWageSubfundBypassOriginationCodes = SpringContext
328:                        .getBean(ParameterService.class)
329:                        .getParameterValues(
330:                                LaborScrubberStep.class,
331:                                LaborConstants.Scrubber.NON_WAGE_SUB_FUND_BYPASS_ORIGINATIONS)
332:                        .toArray(new String[] {});
333:                if (subfundWageExclusionInd
334:                        && !account.getSubFundGroup()
335:                                .isSubFundGroupWagesIndicator()
336:                        && !ObjectHelper.isOneOf(laborOriginEntry
337:                                .getFinancialSystemOriginationCode(),
338:                                nonWageSubfundBypassOriginationCodes)) {
339:                    if (suspenseAccountLogicInd) {
340:                        return useSuspenseAccount(laborWorkingEntry);
341:                    }
342:
343:                    return new Message("Sub fund does not accept wages.",
344:                            Message.TYPE_FATAL);
345:                }
346:
347:                /* Account Fringe Validation */
348:                boolean accountFringeExclusionInd = SpringContext
349:                        .getBean(ParameterService.class)
350:                        .getIndicatorParameter(
351:                                LaborScrubberStep.class,
352:                                LaborConstants.Scrubber.ACCOUNT_FRINGE_EXCLUSION_PARAMETER);
353:                String[] nonFringeAccountBypassOriginationCodes = SpringContext
354:                        .getBean(ParameterService.class)
355:                        .getParameterValues(
356:                                LaborScrubberStep.class,
357:                                LaborConstants.Scrubber.NON_FRINGE_ACCOUNT_BYPASS_ORIGINATIONS)
358:                        .toArray(new String[] {});
359:                if (accountFringeExclusionInd
360:                        && !ObjectHelper.isOneOf(laborOriginEntry
361:                                .getFinancialSystemOriginationCode(),
362:                                nonFringeAccountBypassOriginationCodes)) {
363:                    return checkAccountFringeIndicator(laborOriginEntry,
364:                            laborWorkingEntry, account, universityRunDate);
365:                }
366:
367:                /* Expired/Closed Validation */
368:                return handleExpiredClosedAccount(
369:                        laborOriginEntry.getAccount(), laborOriginEntry,
370:                        laborWorkingEntry, universityRunDate);
371:            }
372:
373:            /**
374:             * Checks the continuation account system indicator. If on checks whether the account is expired or closed, and if so calls the
375:             * contination logic.
376:             */
377:            private Message handleExpiredClosedAccount(Account account,
378:                    LaborOriginEntry laborOriginEntry,
379:                    LaborOriginEntry laborWorkingEntry,
380:                    UniversityDate universityRunDate) {
381:                boolean continuationAccountLogicInd = SpringContext
382:                        .getBean(ParameterService.class)
383:                        .getIndicatorParameter(
384:                                LaborScrubberStep.class,
385:                                LaborConstants.Scrubber.CONTINUATION_ACCOUNT_LOGIC_PARAMETER);
386:
387:                String[] continuationAccountBypassOriginationCodes = SpringContext
388:                        .getBean(ParameterService.class)
389:                        .getParameterValues(
390:                                LaborScrubberStep.class,
391:                                LaborConstants.Scrubber.CONTINUATION_ACCOUNT_BYPASS_ORIGINATION_CODES)
392:                        .toArray(new String[] {});
393:                String[] continuationAccountBypassBalanceTypeCodes = SpringContext
394:                        .getBean(BalanceTypService.class)
395:                        .getContinuationAccountBypassBalanceTypeCodes(
396:                                universityRunDate.getUniversityFiscalYear())
397:                        .toArray(new String[] {});
398:                String[] continuationAccountBypassDocumentTypeCodes = SpringContext
399:                        .getBean(ParameterService.class)
400:                        .getParameterValues(
401:                                LaborScrubberStep.class,
402:                                LaborConstants.Scrubber.CONTINUATION_ACCOUNT_BYPASS_DOCUMENT_TYPE_CODES)
403:                        .toArray(new String[] {});
404:
405:                Calendar today = Calendar.getInstance();
406:                today.setTime(universityRunDate.getUniversityDate());
407:
408:                long offsetAccountExpirationTime = getAdjustedAccountExpirationDate(account);
409:                if (continuationAccountLogicInd
410:                        && ((account.getAccountExpirationDate() != null && isExpired(
411:                                offsetAccountExpirationTime, today)) || account
412:                                .isAccountClosedIndicator())) {
413:                    // special checks for origination codes that have override ability
414:                    boolean isOverrideOriginCode = ObjectHelper.isOneOf(
415:                            laborOriginEntry
416:                                    .getFinancialSystemOriginationCode(),
417:                            continuationAccountBypassOriginationCodes);
418:                    if (isOverrideOriginCode
419:                            && account.isAccountClosedIndicator()) {
420:                        return new Message(
421:                                kualiConfigurationService
422:                                        .getPropertyString(KFSKeyConstants.ERROR_ORIGIN_CODE_CANNOT_HAVE_CLOSED_ACCOUNT)
423:                                        + " ("
424:                                        + laborOriginEntry.getAccount()
425:                                                .getChartOfAccountsCode()
426:                                        + "-"
427:                                        + laborOriginEntry.getAccountNumber()
428:                                        + ")", Message.TYPE_FATAL);
429:                    }
430:                    if (!account.isAccountClosedIndicator()
431:                            && (isOverrideOriginCode
432:                                    || ObjectHelper
433:                                            .isOneOf(
434:                                                    laborOriginEntry
435:                                                            .getFinancialBalanceTypeCode(),
436:                                                    continuationAccountBypassBalanceTypeCodes) || ObjectHelper
437:                                    .isOneOf(laborOriginEntry
438:                                            .getFinancialDocumentTypeCode()
439:                                            .trim(),
440:                                            continuationAccountBypassDocumentTypeCodes))) {
441:                        return null;
442:                    }
443:
444:                    return continuationAccountLogic(account, laborOriginEntry,
445:                            laborWorkingEntry, today);
446:                }
447:
448:                return null;
449:            }
450:
451:            /**
452:             * Loops through continuation accounts for 10 tries or until it finds an account that is not expired.
453:             */
454:            private Message continuationAccountLogic(
455:                    Account expiredClosedAccount,
456:                    LaborOriginEntry laborOriginEntry,
457:                    LaborOriginEntry laborWorkingEntry, Calendar today) {
458:                String chartCode = expiredClosedAccount
459:                        .getContinuationFinChrtOfAcctCd();
460:                String accountNumber = expiredClosedAccount
461:                        .getContinuationAccountNumber();
462:
463:                List checkedAccountNumbers = new ArrayList();
464:                for (int i = 0; i < 10; ++i) {
465:                    if (checkedAccountNumbers.contains(chartCode
466:                            + accountNumber)) {
467:                        // Something is really wrong with the data because this account has already been evaluated.
468:                        return new Message(
469:                                kualiConfigurationService
470:                                        .getPropertyString(KFSKeyConstants.ERROR_CIRCULAR_DEPENDENCY_IN_CONTINUATION_ACCOUNT_LOGIC),
471:                                Message.TYPE_FATAL);
472:                    }
473:
474:                    if (chartCode == null || accountNumber == null) {
475:                        return new Message(
476:                                kualiConfigurationService
477:                                        .getPropertyString(KFSKeyConstants.ERROR_CONTINUATION_ACCOUNT_NOT_FOUND),
478:                                Message.TYPE_FATAL);
479:                    }
480:
481:                    // Lookup the account
482:                    Account account = accountService.getByPrimaryId(chartCode,
483:                            accountNumber);
484:                    if (account == null) {
485:                        return new Message(
486:                                kualiConfigurationService
487:                                        .getPropertyString(KFSKeyConstants.ERROR_CONTINUATION_ACCOUNT_NOT_FOUND),
488:                                Message.TYPE_FATAL);
489:                    }
490:
491:                    // check account expiration
492:                    long offsetAccountExpirationTime = getAdjustedAccountExpirationDate(account);
493:                    if (account.getAccountExpirationDate() != null
494:                            && isExpired(offsetAccountExpirationTime, today)) {
495:                        chartCode = account.getContinuationFinChrtOfAcctCd();
496:                        accountNumber = account.getContinuationAccountNumber();
497:                    } else {
498:                        laborWorkingEntry.setAccount(account);
499:                        laborWorkingEntry.setAccountNumber(accountNumber);
500:                        laborWorkingEntry.setChartOfAccountsCode(chartCode);
501:
502:                        laborWorkingEntry
503:                                .setTransactionLedgerEntryDescription(kualiConfigurationService
504:                                        .getPropertyString(KFSKeyConstants.MSG_AUTO_FORWARD)
505:                                        + " "
506:                                        + expiredClosedAccount
507:                                                .getChartOfAccountsCode()
508:                                        + expiredClosedAccount
509:                                                .getAccountNumber()
510:                                        + laborOriginEntry
511:                                                .getTransactionLedgerEntryDescription());
512:                        return new Message(
513:                                kualiConfigurationService
514:                                        .getPropertyString(KFSKeyConstants.MSG_ACCOUNT_CLOSED_TO)
515:                                        + " "
516:                                        + laborWorkingEntry
517:                                                .getChartOfAccountsCode()
518:                                        + laborWorkingEntry.getAccountNumber(),
519:                                Message.TYPE_WARNING);
520:                    }
521:
522:                    checkedAccountNumbers.add(chartCode + accountNumber);
523:                }
524:
525:                // We failed to find a valid continuation account.
526:                boolean suspenseAccountLogicInd = SpringContext
527:                        .getBean(ParameterService.class)
528:                        .getIndicatorParameter(
529:                                LaborScrubberStep.class,
530:                                LaborConstants.Scrubber.SUSPENSE_ACCOUNT_LOGIC_PARAMETER);
531:                if (suspenseAccountLogicInd) {
532:                    return useSuspenseAccount(laborWorkingEntry);
533:                } else {
534:                    return new Message(
535:                            kualiConfigurationService
536:                                    .getPropertyString(KFSKeyConstants.ERROR_CONTINUATION_ACCOUNT_LIMIT_REACHED),
537:                            Message.TYPE_FATAL);
538:                }
539:            }
540:
541:            /**
542:             * For fringe transaction types checks if the account accepts fringe benefits. If not, retrieves the alternative account, then
543:             * calls expiration checking on either the alternative account or the account passed in.
544:             */
545:            private Message checkAccountFringeIndicator(
546:                    LaborOriginEntry laborOriginEntry,
547:                    LaborOriginEntry laborWorkingEntry, Account account,
548:                    UniversityDate universityRunDate) {
549:                // check for fringe tranaction type
550:                Map fieldValues = new HashMap();
551:                fieldValues.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
552:                        laborOriginEntry.getUniversityFiscalYear());
553:                fieldValues.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
554:                        laborOriginEntry.getChartOfAccountsCode());
555:                fieldValues.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE,
556:                        laborOriginEntry.getFinancialObjectCode());
557:
558:                LaborObject laborObject = (LaborObject) businessObjectService
559:                        .findByPrimaryKey(LaborObject.class, fieldValues);
560:                boolean isFringeTransaction = laborObject != null
561:                        && org.apache.commons.lang.StringUtils
562:                                .equals(
563:                                        LaborConstants.BenefitExpenseTransfer.LABOR_LEDGER_BENEFIT_CODE,
564:                                        laborObject
565:                                                .getFinancialObjectFringeOrSalaryCode());
566:
567:                // alternative account handling for non fringe accounts
568:                if (isFringeTransaction
569:                        && !account.isAccountsFringesBnftIndicator()) {
570:                    Account altAccount = accountService.getByPrimaryId(
571:                            laborOriginEntry.getAccount()
572:                                    .getReportsToChartOfAccountsCode(),
573:                            laborOriginEntry.getAccount()
574:                                    .getReportsToAccountNumber());
575:                    if (altAccount != null) {
576:                        laborWorkingEntry.setAccount(altAccount);
577:                        laborWorkingEntry.setAccountNumber(altAccount
578:                                .getAccountNumber());
579:                        laborWorkingEntry.setChartOfAccountsCode(altAccount
580:                                .getChartOfAccountsCode());
581:
582:                        return handleExpiredClosedAccount(altAccount,
583:                                laborOriginEntry, laborWorkingEntry,
584:                                universityRunDate);
585:                    }
586:
587:                    // no alt acct, use suspense acct if active
588:                    boolean suspenseAccountLogicInd = SpringContext
589:                            .getBean(ParameterService.class)
590:                            .getIndicatorParameter(
591:                                    LaborScrubberStep.class,
592:                                    LaborConstants.Scrubber.SUSPENSE_ACCOUNT_LOGIC_PARAMETER);
593:                    if (suspenseAccountLogicInd) {
594:                        return useSuspenseAccount(laborWorkingEntry);
595:                    }
596:
597:                    return new Message(
598:                            "No alternative account found for non-fringe Account. ",
599:                            Message.TYPE_FATAL);
600:                }
601:
602:                return handleExpiredClosedAccount(account, laborOriginEntry,
603:                        laborWorkingEntry, universityRunDate);
604:            }
605:
606:            /**
607:             * Adjustment of Account if it is contracts and grants
608:             */
609:            private long getAdjustedAccountExpirationDate(Account account) {
610:                long offsetAccountExpirationTime = 0;
611:
612:                if (account.getAccountExpirationDate() != null) {
613:                    offsetAccountExpirationTime = account
614:                            .getAccountExpirationDate().getTime();
615:
616:                    if (account.isForContractsAndGrants()
617:                            && (!account.isAccountClosedIndicator())) {
618:                        String daysOffset = parameterService
619:                                .getParameterValue(
620:                                        ScrubberStep.class,
621:                                        KFSConstants.SystemGroupParameterNames.GL_SCRUBBER_VALIDATION_DAYS_OFFSET);
622:                        int daysOffsetInt = 3 * 30; // default to 90 days (approximately 3 months)
623:
624:                        if (daysOffset.trim().length() > 0) {
625:                            daysOffsetInt = new Integer(daysOffset).intValue();
626:                        }
627:
628:                        Calendar tempCal = Calendar.getInstance();
629:                        tempCal.setTimeInMillis(offsetAccountExpirationTime);
630:                        tempCal.add(Calendar.DAY_OF_MONTH, daysOffsetInt);
631:                        offsetAccountExpirationTime = tempCal.getTimeInMillis();
632:                    }
633:                }
634:
635:                return offsetAccountExpirationTime;
636:            }
637:
638:            /**
639:             * Checking whether or not the account is expired
640:             */
641:            private boolean isExpired(long offsetAccountExpirationTime,
642:                    Calendar runCalendar) {
643:                Calendar expirationDate = Calendar.getInstance();
644:                expirationDate.setTimeInMillis(offsetAccountExpirationTime);
645:
646:                int expirationYear = expirationDate.get(Calendar.YEAR);
647:                int runYear = runCalendar.get(Calendar.YEAR);
648:                int expirationDoy = expirationDate.get(Calendar.DAY_OF_YEAR);
649:                int runDoy = runCalendar.get(Calendar.DAY_OF_YEAR);
650:
651:                return (expirationYear < runYear)
652:                        || (expirationYear == runYear && expirationDoy < runDoy);
653:            }
654:
655:            /**
656:             * This method changes account to suspenseAccount
657:             */
658:            private Message useSuspenseAccount(LaborOriginEntry workingEntry) {
659:                String suspenseAccountNumber = SpringContext.getBean(
660:                        ParameterService.class).getParameterValue(
661:                        LaborScrubberStep.class,
662:                        LaborConstants.Scrubber.SUSPENSE_ACCOUNT);
663:                String suspenseCOAcode = SpringContext.getBean(
664:                        ParameterService.class).getParameterValue(
665:                        LaborScrubberStep.class,
666:                        LaborConstants.Scrubber.SUSPENSE_CHART);
667:                Account account = accountService.getByPrimaryId(
668:                        suspenseCOAcode, suspenseAccountNumber);
669:
670:                if (account == null) {
671:                    return new Message("Suspense account is Invalid.",
672:                            Message.TYPE_FATAL);
673:                }
674:
675:                workingEntry.setAccount(account);
676:                workingEntry.setAccountNumber(suspenseAccountNumber);
677:                workingEntry.setChartOfAccountsCode(suspenseCOAcode);
678:
679:                return null;
680:            }
681:
682:            /**
683:             * Sets the referenceLookup attribute value.
684:             * 
685:             * @param referenceLookup The referenceLookup to set.
686:             */
687:            public void setReferenceLookup(
688:                    OriginEntryLookupService originEntryLookupService) {
689:                this .referenceLookup.set(originEntryLookupService);
690:            }
691:
692:            public void validateForInquiry(GeneralLedgerPendingEntry entry) {
693:            }
694:
695:            /**
696:             * Sets the parameterService attribute value.
697:             * 
698:             * @param parameterService The parameterService to set.
699:             */
700:            public void setParameterService(ParameterService parameterService) {
701:                this .parameterService = parameterService;
702:            }
703:
704:            /**
705:             * Sets the kualiConfigurationService attribute value.
706:             * 
707:             * @param service The kualiConfigurationService to set.
708:             */
709:            public void setKualiConfigurationService(
710:                    KualiConfigurationService service) {
711:                kualiConfigurationService = service;
712:            }
713:
714:            /**
715:             * Sets the accountService attribute value.
716:             * 
717:             * @param as The accountService to set.
718:             */
719:            public void setAccountService(AccountService as) {
720:                accountService = as;
721:            }
722:
723:            /**
724:             * Sets the persistenceService attribute value.
725:             * 
726:             * @param ps The persistenceService to set.
727:             */
728:            public void setPersistenceService(PersistenceService ps) {
729:                persistenceService = ps;
730:            }
731:
732:            /**
733:             * Sets the businessObjectService attribute value.
734:             * 
735:             * @param businessObjectService The businessObjectService to set.
736:             */
737:            public void setBusinessObjectService(
738:                    BusinessObjectService businessObjectService) {
739:                this.businessObjectService = businessObjectService;
740:            }
741:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.