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 org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.coa.businessobject.Account;
20 import org.kuali.ole.coa.service.AccountService;
21 import org.kuali.ole.sys.OLEKeyConstants;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.rice.core.api.config.property.ConfigurationService;
24 import org.kuali.rice.kns.document.MaintenanceDocument;
25 import org.kuali.rice.kns.rules.PromptBeforeValidationBase;
26 import org.kuali.rice.krad.document.Document;
27 import org.kuali.rice.krad.util.ObjectUtils;
28
29
30
31
32 public class MaintenancePreRulesBase extends PromptBeforeValidationBase {
33
34 protected ConfigurationService configService;
35 protected AccountService accountService;
36
37
38
39
40
41
42 public MaintenancePreRulesBase() {
43
44
45
46
47
48
49 setAccountService(SpringContext.getBean(AccountService.class));
50 setConfigService(SpringContext.getBean(ConfigurationService.class));
51 }
52
53 public void setAccountService(AccountService accountService) {
54 this.accountService = accountService;
55 }
56
57 public void setConfigService(ConfigurationService configService) {
58 this.configService = configService;
59 }
60
61
62
63
64
65
66
67 @Override
68 public boolean doPrompts(Document document) {
69 MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
70 return doCustomPreRules(maintenanceDocument);
71 }
72
73
74
75
76
77
78
79 protected boolean doCustomPreRules(MaintenanceDocument maintenanceDocument) {
80 return true;
81 }
82
83
84
85
86
87
88
89
90
91
92
93 protected Account checkForContinuationAccount(String accName, String chart, String accountNumber, String accountName, boolean allowExpiredAccount) {
94 Account result = checkForContinuationAccount(accName, chart, accountNumber, accountName);
95 if (!allowExpiredAccount) {
96 if (result.isExpired()) {
97 return null;
98 }
99 }
100 return result;
101 }
102
103
104
105
106
107
108
109
110
111
112 protected Account checkForContinuationAccount(String accName, String chart, String accountNumber, String accountName) {
113 if (LOG.isDebugEnabled()) {
114 LOG.debug("entering checkForContinuationAccounts(" + accountNumber + ")");
115 }
116 if (StringUtils.isBlank(accountNumber) || StringUtils.isBlank(chart))
117 return null;
118
119 Account account = accountService.getByPrimaryId(chart, accountNumber);
120
121 if (ObjectUtils.isNotNull(account) && !account.isExpired()) {
122 return null;
123 }
124
125 boolean useContinuationAccount = true;
126
127 while (ObjectUtils.isNotNull(account) && account.isExpired() && useContinuationAccount) {
128 if (LOG.isDebugEnabled()) {
129 LOG.debug("Expired account: " + accountNumber);
130 }
131 String continuationAccountNumber = account.getContinuationAccountNumber();
132
133 useContinuationAccount = askOrAnalyzeYesNoQuestion("ContinuationAccount" + accName + accountNumber, buildContinuationConfirmationQuestion(accName, accountNumber, continuationAccountNumber));
134 if (useContinuationAccount) {
135 String continuationChart = account.getContinuationFinChrtOfAcctCd();
136 account = accountService.getByPrimaryId(continuationChart, continuationAccountNumber);
137
138 if (ObjectUtils.isNotNull(account)) {
139 accountNumber = account.getAccountNumber();
140 }
141
142 if (LOG.isDebugEnabled()) {
143 LOG.debug("Selected continuation account: " + account);
144 }
145 }
146 }
147 return account;
148
149 }
150
151
152
153
154
155
156
157
158
159
160 protected String buildContinuationConfirmationQuestion(String accName, String expiredAccount, String continuationAccount) {
161 String result = configService.getPropertyValueAsString(OLEKeyConstants.QUESTION_CONTINUATION_ACCOUNT_SELECTION);
162 result = StringUtils.replace(result, "{0}", accName);
163 result = StringUtils.replace(result, "{1}", expiredAccount);
164 result = StringUtils.replace(result, "{2}", continuationAccount);
165 return result;
166 }
167
168 public AccountService getAccountService() {
169 return accountService;
170 }
171
172 public ConfigurationService getConfigService() {
173 return configService;
174 }
175
176 }