1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.document.validation.impl;
17
18 import java.sql.Date;
19 import java.sql.Timestamp;
20 import java.util.Calendar;
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.commons.lang.time.DateUtils;
28 import org.kuali.ole.coa.businessobject.Account;
29 import org.kuali.ole.coa.businessobject.AccountGlobal;
30 import org.kuali.ole.coa.businessobject.AccountGlobalDetail;
31 import org.kuali.ole.coa.businessobject.SubFundGroup;
32 import org.kuali.ole.coa.service.OrganizationService;
33 import org.kuali.ole.coa.service.SubFundGroupService;
34 import org.kuali.ole.sys.OLEConstants;
35 import org.kuali.ole.sys.OLEKeyConstants;
36 import org.kuali.ole.sys.context.SpringContext;
37 import org.kuali.rice.kim.api.identity.Person;
38 import org.kuali.rice.kns.document.MaintenanceDocument;
39 import org.kuali.rice.kns.service.DictionaryValidationService;
40 import org.kuali.rice.krad.bo.PersistableBusinessObject;
41 import org.kuali.rice.krad.service.BusinessObjectService;
42 import org.kuali.rice.krad.util.GlobalVariables;
43 import org.kuali.rice.krad.util.ObjectUtils;
44
45
46
47
48 public class AccountGlobalRule extends GlobalDocumentRuleBase {
49 protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountGlobalRule.class);
50
51
52 @Deprecated
53 protected static final String GENERAL_FUND_CD = "GF";
54 @Deprecated
55 protected static final String SUB_FUND_GROUP_MEDICAL_PRACTICE_FUNDS = "MPRACT";
56
57 protected AccountGlobal newAccountGlobal;
58 protected Timestamp today;
59
60
61
62
63
64
65 @Override
66 public void setupConvenienceObjects() {
67
68
69 newAccountGlobal = (AccountGlobal) super.getNewBo();
70 today = getDateTimeService().getCurrentTimestamp();
71 today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime());
72 }
73
74
75
76
77
78
79
80
81 @Override
82 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
83
84 LOG.info("processCustomSaveDocumentBusinessRules called");
85 setupConvenienceObjects();
86
87 checkEmptyValues();
88 checkGeneralRules(document);
89 checkOrganizationValidity(newAccountGlobal);
90 checkContractsAndGrants();
91 checkExpirationDate(document);
92 checkOnlyOneChartErrorWrapper(newAccountGlobal.getAccountGlobalDetails());
93
94
95
96
97 return true;
98 }
99
100
101
102
103
104
105
106 @Override
107 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
108
109 LOG.info("processCustomRouteDocumentBusinessRules called");
110 setupConvenienceObjects();
111
112
113 boolean success = true;
114
115 success &= checkEmptyValues();
116 success &= checkGeneralRules(document);
117 success &= checkContractsAndGrants();
118 success &= checkExpirationDate(document);
119 success &= checkAccountDetails(document, newAccountGlobal.getAccountGlobalDetails());
120
121
122
123 return success;
124 }
125
126
127
128
129
130
131
132
133
134 public boolean checkAccountDetails(MaintenanceDocument document, List<AccountGlobalDetail> details) {
135 boolean success = true;
136
137
138 if (details.size() == 0) {
139
140 putFieldError(OLEConstants.MAINTENANCE_ADD_PREFIX + "accountGlobalDetails.accountNumber", OLEKeyConstants.ERROR_DOCUMENT_GLOBAL_ACCOUNT_NO_ACCOUNTS);
141
142 success = false;
143 }
144 else {
145
146 int index = 0;
147 for (AccountGlobalDetail dtl : details) {
148 String errorPath = MAINTAINABLE_ERROR_PREFIX + "accountGlobalDetails[" + index + "]";
149 GlobalVariables.getMessageMap().addToErrorPath(errorPath);
150 success &= checkAccountDetails(dtl);
151 GlobalVariables.getMessageMap().removeFromErrorPath(errorPath);
152 index++;
153 }
154 success &= checkOnlyOneChartErrorWrapper(details);
155 }
156
157 return success;
158 }
159
160
161
162
163
164
165
166 public boolean checkAccountDetails(AccountGlobalDetail dtl) {
167 boolean success = true;
168 int originalErrorCount = GlobalVariables.getMessageMap().getErrorCount();
169 getDictionaryValidationService().validateBusinessObject(dtl);
170 if (StringUtils.isNotBlank(dtl.getAccountNumber()) && StringUtils.isNotBlank(dtl.getChartOfAccountsCode())) {
171 dtl.refreshReferenceObject("account");
172 if (ObjectUtils.isNull(dtl.getAccount())) {
173 GlobalVariables.getMessageMap().putError("accountNumber", OLEKeyConstants.ERROR_DOCUMENT_GLOBAL_ACCOUNT_INVALID_ACCOUNT, new String[] { dtl.getChartOfAccountsCode(), dtl.getAccountNumber() });
174 }
175 }
176 success &= GlobalVariables.getMessageMap().getErrorCount() == originalErrorCount;
177
178 return success;
179 }
180
181
182
183
184
185
186 protected boolean checkEmptyValues() {
187
188 LOG.info("checkEmptyValues called");
189
190 boolean success = true;
191
192
193
194 success &= checkForPartiallyFilledOutReferenceForeignKeys("continuationAccount");
195 success &= checkForPartiallyFilledOutReferenceForeignKeys("incomeStreamAccount");
196
197 return success;
198 }
199
200
201
202
203
204
205
206
207 protected boolean checkGeneralRules(MaintenanceDocument maintenanceDocument) {
208
209 LOG.info("checkGeneralRules called");
210 Person fiscalOfficer = newAccountGlobal.getAccountFiscalOfficerUser();
211 Person accountManager = newAccountGlobal.getAccountManagerUser();
212 Person accountSupervisor = newAccountGlobal.getAccountSupervisoryUser();
213
214 boolean success = true;
215
216 if (!StringUtils.isBlank(newAccountGlobal.getAccountFiscalOfficerSystemIdentifier()) && (ObjectUtils.isNull(fiscalOfficer) || StringUtils.isBlank(fiscalOfficer.getPrincipalId()) || !getDocumentHelperService().getDocumentAuthorizer(maintenanceDocument).isAuthorized(maintenanceDocument, OLEConstants.PermissionNames.SERVE_AS_FISCAL_OFFICER.namespace, OLEConstants.PermissionNames.SERVE_AS_FISCAL_OFFICER.name, fiscalOfficer.getPrincipalId()))) {
217 final String fiscalOfficerName = fiscalOfficer != null ? fiscalOfficer.getName() : newAccountGlobal.getAccountFiscalOfficerSystemIdentifier();
218 super.putFieldError("accountFiscalOfficerUser.principalName", OLEKeyConstants.ERROR_USER_MISSING_PERMISSION, new String[] {fiscalOfficerName, OLEConstants.PermissionNames.SERVE_AS_FISCAL_OFFICER.namespace, OLEConstants.PermissionNames.SERVE_AS_FISCAL_OFFICER.name});
219 success = false;
220 }
221 if (!StringUtils.isBlank(newAccountGlobal.getAccountsSupervisorySystemsIdentifier()) && (ObjectUtils.isNull(accountSupervisor) || StringUtils.isBlank(accountSupervisor.getPrincipalId()) || !getDocumentHelperService().getDocumentAuthorizer(maintenanceDocument).isAuthorized(maintenanceDocument, OLEConstants.PermissionNames.SERVE_AS_ACCOUNT_SUPERVISOR.namespace, OLEConstants.PermissionNames.SERVE_AS_ACCOUNT_SUPERVISOR.name, accountSupervisor.getPrincipalId()))) {
222 final String accountSupervisorName = accountSupervisor != null ? accountSupervisor.getName() : newAccountGlobal.getAccountsSupervisorySystemsIdentifier();
223 super.putFieldError("accountSupervisoryUser.principalName", OLEKeyConstants.ERROR_USER_MISSING_PERMISSION, new String[] {accountSupervisorName, OLEConstants.PermissionNames.SERVE_AS_ACCOUNT_SUPERVISOR.namespace, OLEConstants.PermissionNames.SERVE_AS_ACCOUNT_SUPERVISOR.name});
224 success = false;
225 }
226 if (!StringUtils.isBlank(newAccountGlobal.getAccountManagerSystemIdentifier()) && (ObjectUtils.isNull(accountManager) || StringUtils.isBlank(accountManager.getPrincipalId()) || !getDocumentHelperService().getDocumentAuthorizer(maintenanceDocument).isAuthorized(maintenanceDocument, OLEConstants.PermissionNames.SERVE_AS_ACCOUNT_MANAGER.namespace, OLEConstants.PermissionNames.SERVE_AS_ACCOUNT_MANAGER.name, accountManager.getPrincipalId()))) {
227 final String accountManagerName = accountManager != null ? accountManager.getName() : newAccountGlobal.getAccountManagerSystemIdentifier();
228 super.putFieldError("accountManagerUser.principalName", OLEKeyConstants.ERROR_USER_MISSING_PERMISSION, new String[] {accountManagerName, OLEConstants.PermissionNames.SERVE_AS_ACCOUNT_MANAGER.namespace, OLEConstants.PermissionNames.SERVE_AS_ACCOUNT_MANAGER.name});
229 success = false;
230 }
231
232
233 if (isSupervisorSameAsFiscalOfficer(newAccountGlobal)) {
234 success &= false;
235 putFieldError("accountsSupervisorySystemsIdentifier", OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_SUPER_CANNOT_BE_FISCAL_OFFICER);
236 }
237 if (isSupervisorSameAsManager(newAccountGlobal)) {
238 success &= false;
239 putFieldError("accountManagerSystemIdentifier", OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_SUPER_CANNOT_BE_ACCT_MGR);
240 }
241
242
243 if (isContinuationAccountExpired(newAccountGlobal)) {
244 success &= false;
245 putFieldError("continuationAccountNumber", OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCOUNT_EXPIRED_CONTINUATION);
246 }
247
248
249
250 if (!isSupervisorSameAsFiscalOfficer(newAccountGlobal) && !isSupervisorSameAsManager(newAccountGlobal)) {
251 success &= checkAllAccountUsers(newAccountGlobal, fiscalOfficer, accountManager, accountSupervisor);
252 }
253
254 return success;
255 }
256
257
258
259
260
261
262
263
264
265
266
267 protected boolean checkAllAccountUsers(AccountGlobal doc, Person newFiscalOfficer, Person newManager, Person newSupervisor) {
268 boolean success = true;
269
270 if (LOG.isDebugEnabled()) {
271 LOG.debug("newSupervisor: " + newSupervisor);
272 LOG.debug("newFiscalOfficer: " + newFiscalOfficer);
273 LOG.debug("newManager: " + newManager);
274 }
275
276
277 if (newSupervisor != null || newFiscalOfficer != null || newManager != null) {
278
279 int index = 0;
280 for (AccountGlobalDetail detail : doc.getAccountGlobalDetails()) {
281 success &= checkAccountUsers(detail, newFiscalOfficer, newManager, newSupervisor, index);
282 index++;
283 }
284 }
285
286 return success;
287 }
288
289
290
291
292
293
294
295
296
297
298
299
300 protected boolean checkAccountUsers(AccountGlobalDetail detail, Person newFiscalOfficer, Person newManager, Person newSupervisor, int index) {
301 boolean success = true;
302
303
304 if (newSupervisor != null || newFiscalOfficer != null || newManager != null) {
305
306 detail.refreshReferenceObject("account");
307 Account account = detail.getAccount();
308 if (ObjectUtils.isNotNull(account)){
309 if (LOG.isDebugEnabled()) {
310 LOG.debug("old-Supervisor: " + account.getAccountSupervisoryUser());
311 LOG.debug("old-FiscalOfficer: " + account.getAccountFiscalOfficerUser());
312 LOG.debug("old-Manager: " + account.getAccountManagerUser());
313 }
314
315 if (newSupervisor != null && newSupervisor.getPrincipalId() != null) {
316 if (areTwoUsersTheSame(newSupervisor, account.getAccountFiscalOfficerUser())) {
317 success = false;
318 putFieldError("accountGlobalDetails[" + index + "].accountNumber", OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_SUPER_CANNOT_EQUAL_EXISTING_FISCAL_OFFICER, new String[] { account.getAccountFiscalOfficerUser().getPrincipalName(), "Fiscal Officer", detail.getAccountNumber() });
319 }
320 if (areTwoUsersTheSame(newSupervisor, account.getAccountManagerUser())) {
321 success = false;
322 putFieldError("accountGlobalDetails[" + index + "].accountNumber", OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_SUPER_CANNOT_EQUAL_EXISTING_ACCT_MGR, new String[] { account.getAccountManagerUser().getPrincipalName(), "Account Manager", detail.getAccountNumber() });
323 }
324 }
325 if (newManager != null && newManager.getPrincipalId() != null) {
326 if (areTwoUsersTheSame(newManager, account.getAccountSupervisoryUser())) {
327 success = false;
328 putFieldError("accountGlobalDetails[" + index + "].accountNumber", OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_MGR_CANNOT_EQUAL_EXISTING_ACCT_SUPERVISOR, new String[] { account.getAccountSupervisoryUser().getPrincipalName(), "Account Supervisor", detail.getAccountNumber() });
329 }
330 }
331 if (newFiscalOfficer != null && newFiscalOfficer.getPrincipalId() != null) {
332 if (areTwoUsersTheSame(newFiscalOfficer, account.getAccountSupervisoryUser())) {
333 success = false;
334 putFieldError("accountGlobalDetails[" + index + "].accountNumber", OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_FISCAL_OFFICER_CANNOT_EQUAL_EXISTING_ACCT_SUPERVISOR, new String[] { account.getAccountSupervisoryUser().getPrincipalName(), "Account Supervisor", detail.getAccountNumber() });
335 }
336 }
337 }
338 else {
339 LOG.warn("AccountGlobalDetail object has null account object:" + detail.getChartOfAccountsCode() + "-" + detail.getAccountNumber());
340 }
341 }
342
343 return success;
344 }
345
346
347
348
349
350
351
352
353 protected boolean isSupervisorSameAsFiscalOfficer(AccountGlobal accountGlobals) {
354 return areTwoUsersTheSame(accountGlobals.getAccountSupervisoryUser(), accountGlobals.getAccountFiscalOfficerUser());
355 }
356
357
358
359
360
361
362
363
364 protected boolean isSupervisorSameAsManager(AccountGlobal accountGlobals) {
365 return areTwoUsersTheSame(accountGlobals.getAccountSupervisoryUser(), accountGlobals.getAccountManagerUser());
366 }
367
368
369
370
371
372
373
374
375 protected boolean areTwoUsersTheSame(Person user1, Person user2) {
376 if (ObjectUtils.isNull(user1) || user1.getPrincipalId() == null ) {
377 return false;
378 }
379 if (ObjectUtils.isNull(user2) || user2.getPrincipalId() == null ) {
380 return false;
381 }
382 return user1.getPrincipalId().equals(user2.getPrincipalId());
383 }
384
385
386
387
388
389
390
391
392 protected boolean checkExpirationDate(MaintenanceDocument maintenanceDocument) {
393 LOG.info("checkExpirationDate called");
394
395 boolean success = true;
396 Date newExpDate = newAccountGlobal.getAccountExpirationDate();
397
398
399
400 if (ObjectUtils.isNotNull(newExpDate)) {
401 if (ObjectUtils.isNotNull(newAccountGlobal.getSubFundGroup())) {
402 if (!SpringContext.getBean(SubFundGroupService.class).isForContractsAndGrants(newAccountGlobal.getSubFundGroup())) {
403 if (!newExpDate.after(today) && !newExpDate.equals(today)) {
404 putGlobalError(OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
405 success &= false;
406 }
407 }
408 }
409 }
410
411
412 success &= checkContinuationAccount(maintenanceDocument, newExpDate);
413
414 for (AccountGlobalDetail detail : newAccountGlobal.getAccountGlobalDetails()) {
415 success &= checkExpirationDate(maintenanceDocument, detail);
416 }
417 return success;
418 }
419
420
421
422
423
424
425
426
427 protected boolean checkExpirationDate(MaintenanceDocument maintenanceDocument, AccountGlobalDetail detail) {
428 boolean success = true;
429 Date newExpDate = newAccountGlobal.getAccountExpirationDate();
430
431
432 Account account = (Account) SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class, detail.getPrimaryKeys());
433 if (ObjectUtils.isNotNull(account)) {
434 Date oldExpDate = account.getAccountExpirationDate();
435
436
437
438
439 if (isUpdatedExpirationDateInvalid(account, newAccountGlobal)) {
440 putFieldError("accountExpirationDate", OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
441 success &= false;
442 }
443
444
445
446 if (ObjectUtils.isNotNull(newExpDate) && ObjectUtils.isNull(newAccountGlobal.getSubFundGroup())) {
447 if (ObjectUtils.isNotNull(account.getSubFundGroup())) {
448 if (!account.isForContractsAndGrants()) {
449 if (!newExpDate.after(today) && !newExpDate.equals(today)) {
450 putGlobalError(OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
451 success &= false;
452 }
453 }
454 }
455 }
456
457 Date effectiveDate = account.getAccountEffectiveDate();
458 if (ObjectUtils.isNotNull(effectiveDate) && ObjectUtils.isNotNull(newExpDate)) {
459 if (newExpDate.before(effectiveDate)) {
460 putGlobalError(OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_CANNOT_BE_BEFORE_EFFECTIVE_DATE);
461 success &= false;
462 }
463 }
464 }
465
466 return success;
467 }
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488 protected boolean isUpdatedExpirationDateInvalid(Account oldAccount, AccountGlobal newAccountGlobal) {
489
490 Date oldExpDate = oldAccount.getAccountExpirationDate();
491 Date newExpDate = newAccountGlobal.getAccountExpirationDate();
492
493
494
495
496 boolean expDateHasChanged = false;
497
498
499
500 if (ObjectUtils.isNull(oldExpDate) && ObjectUtils.isNotNull(newExpDate)) {
501 expDateHasChanged = true;
502 }
503
504
505 else if (ObjectUtils.isNotNull(oldExpDate) && ObjectUtils.isNotNull(newExpDate)) {
506 if (!oldExpDate.equals(newExpDate)) {
507 expDateHasChanged = true;
508 }
509 }
510
511
512 if (!expDateHasChanged) {
513 return false;
514 }
515
516
517 SubFundGroup subFundGroup = newAccountGlobal.getSubFundGroup();
518 if (ObjectUtils.isNull(subFundGroup)) {
519 return false;
520 }
521
522
523 String fundGroupCode = newAccountGlobal.getSubFundGroup().getFundGroupCode().trim();
524
525
526
527 if (SpringContext.getBean(SubFundGroupService.class).isForContractsAndGrants(newAccountGlobal.getSubFundGroup())) {
528 return false;
529 }
530
531
532
533
534 if (newExpDate.equals(today) || newExpDate.after(today)) {
535 return false;
536 }
537 else
538 return true;
539 }
540
541
542
543
544
545
546
547
548 protected boolean isContinuationAccountExpired(AccountGlobal accountGlobals) {
549
550 boolean result = false;
551
552 String chartCode = accountGlobals.getContinuationFinChrtOfAcctCd();
553 String accountNumber = accountGlobals.getContinuationAccountNumber();
554
555
556
557 if (StringUtils.isBlank(chartCode) || StringUtils.isBlank(accountNumber)) {
558 return result;
559 }
560
561
562 Account continuation = null;
563 Map<String,String> pkMap = new HashMap<String,String>();
564 pkMap.put("chartOfAccountsCode", chartCode);
565 pkMap.put("accountNumber", accountNumber);
566 continuation = (Account) super.getBoService().findByPrimaryKey(Account.class, pkMap);
567
568
569 if (ObjectUtils.isNull(continuation)) {
570 return result;
571 }
572
573
574
575 result = continuation.isExpired();
576
577 return result;
578 }
579
580
581
582
583
584
585 protected boolean checkContractsAndGrants() {
586
587 LOG.info("checkContractsAndGrants called");
588
589 boolean success = true;
590
591
592
593 success &= checkCgIncomeStreamRequired(newAccountGlobal);
594
595 return success;
596 }
597
598
599
600
601
602
603
604 protected boolean checkCgIncomeStreamRequired(AccountGlobal accountGlobals) {
605
606 boolean result = true;
607 boolean required = false;
608
609
610 if (ObjectUtils.isNull(accountGlobals.getSubFundGroup())) {
611 return result;
612 }
613
614
615 String subFundGroupCode = accountGlobals.getSubFundGroupCode().trim();
616 String fundGroupCode = accountGlobals.getSubFundGroup().getFundGroupCode().trim();
617
618
619 if (SpringContext.getBean(SubFundGroupService.class).isForContractsAndGrants(accountGlobals.getSubFundGroup())) {
620 required = true;
621 }
622
623
624 else if (GENERAL_FUND_CD.equalsIgnoreCase(fundGroupCode)) {
625
626 if (!SUB_FUND_GROUP_MEDICAL_PRACTICE_FUNDS.equalsIgnoreCase(subFundGroupCode)) {
627 required = true;
628 }
629 }
630
631
632 if (!required) {
633 return result;
634 }
635
636
637 result &= checkEmptyBOField("incomeStreamAccountNumber", accountGlobals.getIncomeStreamAccountNumber(), "When Fund Group is CG or GF, Income Stream Account Number");
638 result &= checkEmptyBOField("incomeStreamFinancialCoaCode", accountGlobals.getIncomeStreamFinancialCoaCode(), "When Fund Group is CG or GF, Income Stream Chart Of Accounts Code");
639
640
641 if (result == false) {
642 return result;
643 }
644
645
646 DictionaryValidationService dvService = super.getDictionaryValidationService();
647 boolean referenceExists = dvService.validateReferenceExists(accountGlobals, "incomeStreamAccount");
648 if (!referenceExists) {
649 putFieldError("incomeStreamAccount", OLEKeyConstants.ERROR_EXISTENCE, "Income Stream Account: " + accountGlobals.getIncomeStreamFinancialCoaCode() + "-" + accountGlobals.getIncomeStreamAccountNumber());
650 result &= false;
651 }
652
653 return result;
654 }
655
656
657
658
659
660
661
662
663 @Override
664 public boolean processCustomAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) {
665 AccountGlobalDetail detail = (AccountGlobalDetail) bo;
666 boolean success = true;
667
668 success &= checkAccountDetails(detail);
669 success &= checkExpirationDate(document, detail);
670 success &= checkOnlyOneChartAddLineErrorWrapper(detail, newAccountGlobal.getAccountGlobalDetails());
671
672 return success;
673 }
674
675
676
677
678
679
680
681
682 protected boolean checkContinuationAccount(MaintenanceDocument document, Date newExpDate) {
683 LOG.info("checkContinuationAccount called");
684
685 boolean result = true;
686 boolean continuationAccountIsValid = true;
687
688
689 if (ObjectUtils.isNotNull(newExpDate)) {
690 if (!checkEmptyValue(newAccountGlobal.getContinuationAccountNumber())) {
691 putFieldError("continuationAccountNumber", OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_CONTINUATION_ACCT_REQD_IF_EXP_DATE_COMPLETED);
692 continuationAccountIsValid = false;
693 }
694 if (!checkEmptyValue(newAccountGlobal.getContinuationFinChrtOfAcctCd())) {
695 putFieldError("continuationFinChrtOfAcctCd", OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_CONTINUATION_FINCODE_REQD_IF_EXP_DATE_COMPLETED);
696 continuationAccountIsValid = false;
697 }
698 }
699
700
701 if (continuationAccountIsValid && ObjectUtils.isNotNull(newAccountGlobal.getContinuationAccountNumber()) && ObjectUtils.isNotNull(newAccountGlobal.getContinuationFinChrtOfAcctCd())) {
702
703 DictionaryValidationService dvService = super.getDictionaryValidationService();
704 boolean referenceExists = dvService.validateReferenceExists(newAccountGlobal, "continuationAccount");
705 if (!referenceExists) {
706 putFieldError("continuationAccountNumber", OLEKeyConstants.ERROR_EXISTENCE, "Continuation Account: " + newAccountGlobal.getContinuationFinChrtOfAcctCd() + "-" + newAccountGlobal.getContinuationAccountNumber());
707 continuationAccountIsValid = false;
708 }
709 }
710
711 if (continuationAccountIsValid) {
712 result = true;
713 }
714 else {
715 List<AccountGlobalDetail> gAcctDetails = newAccountGlobal.getAccountGlobalDetails();
716 for (AccountGlobalDetail detail : gAcctDetails) {
717 if (null != detail.getAccountNumber() && null != newAccountGlobal.getContinuationAccountNumber()) {
718 result &= detail.getAccountNumber().equals(newAccountGlobal.getContinuationAccountNumber());
719 result &= detail.getChartOfAccountsCode().equals(newAccountGlobal.getContinuationFinChrtOfAcctCd());
720 }
721 }
722 }
723
724 return result;
725 }
726
727
728
729
730
731
732
733 protected boolean checkOrganizationValidity( AccountGlobal acctGlobal ) {
734 boolean result = true;
735
736
737 if ( StringUtils.isNotBlank( acctGlobal.getOrganizationCode() ) ) {
738
739 HashSet<String> charts = new HashSet<String>(10);
740 for ( AccountGlobalDetail acct : acctGlobal.getAccountGlobalDetails() ) {
741 charts.add( acct.getChartOfAccountsCode() );
742 }
743 OrganizationService orgService = SpringContext.getBean(OrganizationService.class);
744
745 for ( String chartCode : charts ) {
746 if ( StringUtils.isNotBlank(chartCode) ) {
747 if ( null == orgService.getByPrimaryIdWithCaching( chartCode, acctGlobal.getOrganizationCode() ) ) {
748 result = false;
749 putFieldError("organizationCode", OLEKeyConstants.ERROR_DOCUMENT_GLOBAL_ACCOUNT_INVALID_ORG, new String[] { chartCode, acctGlobal.getOrganizationCode() } );
750 break;
751 }
752 }
753 }
754 }
755
756 return result;
757 }
758 }
759