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 org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.sys.OLEKeyConstants;
20 import org.kuali.ole.sys.OLEPropertyConstants;
21 import org.kuali.ole.sys.businessobject.Bank;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.ole.sys.service.BankService;
24 import org.kuali.rice.kns.service.DataDictionaryService;
25 import org.kuali.rice.krad.document.Document;
26 import org.kuali.rice.krad.util.GlobalVariables;
27 import org.kuali.rice.krad.util.ObjectUtils;
28
29
30
31
32 public class BankCodeValidation {
33 protected static volatile DataDictionaryService dataDictionaryService;
34 protected static volatile BankService bankService;
35
36
37
38
39
40
41
42
43
44
45
46 public static boolean validate(String bankCode, String bankCodeProperty, boolean requireDeposit, boolean requireDisbursement) {
47 String bankCodeLabel = getDataDictionaryService().getAttributeLabel(Bank.class, OLEPropertyConstants.BANK_CODE);
48
49
50 if (!getBankService().isBankSpecificationEnabled()) {
51 return true;
52 }
53
54
55 if (StringUtils.isBlank(bankCode)) {
56 GlobalVariables.getMessageMap().putError(bankCodeProperty, OLEKeyConstants.ERROR_REQUIRED, bankCodeLabel);
57
58 return false;
59 }
60
61 Bank bank = getBankService().getByPrimaryId(bankCode);
62
63 if (ObjectUtils.isNull(bank)) {
64 GlobalVariables.getMessageMap().putError(bankCodeProperty, OLEKeyConstants.ERROR_DOCUMENT_BANKACCMAINT_INVALID_BANK);
65 return false;
66 }
67
68
69 if (requireDeposit && !bank.isBankDepositIndicator()) {
70 GlobalVariables.getMessageMap().putError(bankCodeProperty, OLEKeyConstants.Bank.ERROR_DEPOSIT_NOT_SUPPORTED);
71
72 return false;
73 }
74
75
76 if (requireDisbursement && !bank.isBankDisbursementIndicator()) {
77 GlobalVariables.getMessageMap().putError(bankCodeProperty, OLEKeyConstants.Bank.ERROR_DISBURSEMENT_NOT_SUPPORTED);
78
79 return false;
80 }
81
82 return true;
83 }
84
85
86
87
88
89
90
91
92
93
94
95
96 public static boolean validate(Document document, String bankCode, String bankCodeProperty, boolean requireDeposit, boolean requireDisbursement) {
97 if (document != null && !getBankService().isBankSpecificationEnabledForDocument(document.getClass())) {
98 return true;
99 }
100 return BankCodeValidation.validate(bankCode, bankCodeProperty, requireDeposit, requireDisbursement);
101 }
102
103
104
105
106 protected static DataDictionaryService getDataDictionaryService() {
107 if (dataDictionaryService == null) {
108 dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
109 }
110 return dataDictionaryService;
111 }
112
113
114
115
116 protected static BankService getBankService() {
117 if (bankService == null) {
118 bankService = SpringContext.getBean(BankService.class);
119 }
120 return bankService;
121 }
122 }