1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.validation.impl;
17
18 import java.util.Collection;
19 import java.util.Collections;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.ole.sys.OLEKeyConstants;
23 import org.kuali.ole.sys.OLEPropertyConstants;
24 import org.kuali.ole.sys.businessobject.Bank;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.ole.sys.service.BankService;
27 import org.kuali.rice.kns.document.MaintenanceDocument;
28 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
29
30
31
32
33 public class BankRule extends MaintenanceDocumentRuleBase {
34 protected Bank oldBank;
35 protected Bank newBank;
36
37
38
39
40 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
41
42 boolean valid = true;
43
44 valid &= checkPartiallyFilledOutReferences();
45 valid &= validateFieldsForBankOffsetEntries();
46 valid &= validateBankAccountNumber();
47
48 return valid;
49 }
50
51
52
53
54
55
56 public void setupConvenienceObjects() {
57 oldBank = (Bank) super.getOldBo();
58 newBank = (Bank) super.getNewBo();
59 }
60
61
62
63
64
65
66 protected boolean checkPartiallyFilledOutReferences() {
67 boolean valid = true;
68
69 valid &= checkForPartiallyFilledOutReferenceForeignKeys(OLEPropertyConstants.CASH_OFFSET_ACCOUNT);
70 valid &= checkForPartiallyFilledOutReferenceForeignKeys(OLEPropertyConstants.CASH_OFFSET_OBJECT);
71
72 return valid;
73 }
74
75
76
77
78
79
80
81 protected boolean validateFieldsForBankOffsetEntries() {
82 boolean valid = true;
83
84 if (SpringContext.getBean(BankService.class).isBankSpecificationEnabled()) {
85
86 if (StringUtils.isBlank(newBank.getCashOffsetAccountNumber())) {
87 putFieldError(OLEPropertyConstants.CASH_OFFSET_ACCOUNT_NUMBER, OLEKeyConstants.Bank.ERROR_MISSING_CASH_ACCOUNT_NUMBER);
88 valid = false;
89 }
90
91 if (StringUtils.isBlank(newBank.getCashOffsetObjectCode())) {
92 putFieldError(OLEPropertyConstants.CASH_OFFSET_OBJECT_CODE, OLEKeyConstants.Bank.ERROR_MISSING_CASH_OBJECT_CODE);
93 valid = false;
94 }
95 }
96
97 return valid;
98 }
99
100
101
102
103
104
105 protected boolean validateBankAccountNumber() {
106
107
108 if ( StringUtils.isNotBlank(newBank.getBankAccountNumber() )
109 && (oldBank == null ||
110 !StringUtils.equals(oldBank.getBankAccountNumber(), newBank.getBankAccountNumber())) ) {
111 @SuppressWarnings("rawtypes")
112 Collection existingBanks = getBoService().findMatching(Bank.class, Collections.singletonMap(OLEPropertyConstants.BANK_ACCOUNT_NUMBER, newBank.getBankAccountNumber()));
113 if ( existingBanks != null && !existingBanks.isEmpty() ) {
114 putFieldError(OLEPropertyConstants.BANK_ACCOUNT_NUMBER, OLEKeyConstants.Bank.ERROR_ACCOUNT_NUMBER_NOT_UNIQUE);
115 return false;
116 }
117 }
118 return true;
119 }
120 }