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.util.List;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.ole.coa.businessobject.AccountGlobalDetail;
22 import org.kuali.ole.sys.OLEKeyConstants;
23 import org.kuali.ole.sys.document.validation.impl.KfsMaintenanceDocumentRuleBase;
24 import org.kuali.rice.krad.util.GlobalVariables;
25
26
27
28
29 public class GlobalDocumentRuleBase extends KfsMaintenanceDocumentRuleBase {
30
31
32
33
34 public GlobalDocumentRuleBase() {
35 super();
36 }
37
38
39
40
41
42
43
44
45 protected boolean checkOnlyOneChartErrorWrapper(List<AccountGlobalDetail> accountGlobalDetails) {
46 CheckOnlyOneChartResult result = checkOnlyOneChart(accountGlobalDetails);
47 if (!result.success) {
48 putFieldError("accountGlobalDetails[" + result.firstLineNumber + "].chartOfAccountsCode", OLEKeyConstants.ERROR_DOCUMENT_GLOBAL_ACCOUNT_ONE_CHART_ONLY);
49 putFieldError("accountGlobalDetails[" + result.failedLineNumber + "].chartOfAccountsCode", OLEKeyConstants.ERROR_DOCUMENT_GLOBAL_ACCOUNT_ONE_CHART_ONLY);
50 }
51 return result.success;
52 }
53
54
55
56
57
58
59
60
61
62
63 protected CheckOnlyOneChartResult checkOnlyOneChart(List<AccountGlobalDetail> accountGlobalDetails) {
64
65 if (accountGlobalDetails == null) {
66 return new CheckOnlyOneChartResult(true);
67 }
68 if (accountGlobalDetails.isEmpty()) {
69 return new CheckOnlyOneChartResult(true);
70 }
71
72
73 int compareLineNumber = 0;
74 int firstChartLineNumber = 0;
75 String firstChart = "";
76 for (AccountGlobalDetail account : accountGlobalDetails) {
77 if (StringUtils.isBlank(firstChart)) {
78 if (StringUtils.isNotBlank(account.getChartOfAccountsCode())) {
79 firstChart = account.getChartOfAccountsCode();
80 firstChartLineNumber = compareLineNumber;
81 }
82 }
83 else {
84 if (StringUtils.isNotBlank(account.getChartOfAccountsCode())) {
85 if (!firstChart.equalsIgnoreCase(account.getChartOfAccountsCode())) {
86 return new CheckOnlyOneChartResult(false, firstChartLineNumber, compareLineNumber);
87 }
88 }
89 }
90 compareLineNumber++;
91 }
92 return new CheckOnlyOneChartResult(true);
93 }
94
95
96
97
98 protected class CheckOnlyOneChartResult {
99
100 public int firstLineNumber;
101 public int failedLineNumber;
102 public boolean success;
103
104
105
106
107 public CheckOnlyOneChartResult() {
108 firstLineNumber = -1;
109 failedLineNumber = -1;
110 success = true;
111 }
112
113
114
115
116
117
118 public CheckOnlyOneChartResult(boolean success) {
119 this();
120 this.success = success;
121 }
122
123
124
125
126
127
128
129
130 public CheckOnlyOneChartResult(boolean success, int firstLineNumber, int failedLineNumber) {
131 this.success = success;
132 this.firstLineNumber = firstLineNumber;
133 this.failedLineNumber = failedLineNumber;
134 }
135
136 }
137
138
139
140
141
142
143
144
145
146 protected boolean checkOnlyOneChartAddLineErrorWrapper(AccountGlobalDetail newAccountLine, List<AccountGlobalDetail> accountGlobalDetails) {
147 boolean success = checkOnlyOneChartAddLine(newAccountLine, accountGlobalDetails);
148 if (!success) {
149
150
151
152
153
154
155
156 GlobalVariables.getMessageMap().putError("chartOfAccountsCode", OLEKeyConstants.ERROR_DOCUMENT_GLOBAL_ACCOUNT_ONE_CHART_ONLY_ADDNEW);
157 }
158 return success;
159 }
160
161
162
163
164
165
166
167
168
169
170 protected boolean checkOnlyOneChartAddLine(AccountGlobalDetail newAccountLine, List<AccountGlobalDetail> accountGlobalDetails) {
171 if (newAccountLine == null || accountGlobalDetails == null) {
172 return true;
173 }
174 if (accountGlobalDetails.isEmpty()) {
175 return true;
176 }
177 String newChart = newAccountLine.getChartOfAccountsCode();
178 if (StringUtils.isBlank(newChart)) {
179 return true;
180 }
181 for (AccountGlobalDetail account : accountGlobalDetails) {
182 if (StringUtils.isNotBlank(account.getChartOfAccountsCode())) {
183 if (!newChart.equalsIgnoreCase(account.getChartOfAccountsCode())) {
184 return false;
185 }
186 }
187 }
188 return true;
189 }
190
191 }