1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.service.impl;
17
18 import org.apache.commons.lang.builder.EqualsBuilder;
19 import org.apache.commons.lang.builder.HashCodeBuilder;
20 import org.kuali.ole.module.purap.businessobject.PurApAccountingLineBase;
21 import org.kuali.rice.core.api.util.type.KualiDecimal;
22
23 import java.math.BigDecimal;
24 import java.util.ArrayList;
25 import java.util.List;
26
27
28
29
30
31 public class PurapAccountRevisionGroup {
32 protected String chartOfAccountsCode;
33 protected String accountNumber;
34 protected String subAccountNumber;
35 protected String financialObjectCode;
36 protected String financialSubObjectCode;
37 protected Integer postingYear;
38 protected String postingPeriodCode;
39 protected KualiDecimal amount;
40 protected Integer itemIdentifier;
41 private List<PurApAccountingLineBase> sourceEntries = new ArrayList<PurApAccountingLineBase>();
42 private KualiDecimal changeAmount;
43
44 private String projectCode;
45 private String organizationReferenceId;
46 private BigDecimal accountLinePercent;
47
48
49 public PurapAccountRevisionGroup(PurApAccountingLineBase entry) {
50 setChartOfAccountsCode(entry.getChartOfAccountsCode());
51 setAccountNumber(entry.getAccountNumber());
52 setSubAccountNumber(entry.getSubAccountNumber());
53 setFinancialObjectCode(entry.getFinancialObjectCode());
54 setFinancialSubObjectCode(entry.getFinancialSubObjectCode());
55 setItemIdentifier(entry.getItemIdentifier());
56 setPostingYear(entry.getPostingYear());
57 setPostingPeriodCode(entry.getPostingPeriodCode());
58 setProjectCode(entry.getProjectCode());
59 setOrganizationReferenceId(entry.getOrganizationReferenceId());
60 setAccountLinePercent(entry.getAccountLinePercent());
61 this.sourceEntries.add(entry);
62 setAmount(entry.getAmount());
63 }
64
65
66
67
68
69
70
71 public String getChartOfAccountsCode() {
72 return chartOfAccountsCode;
73 }
74
75
76
77
78
79
80 public void setChartOfAccountsCode(String chartOfAccountsCode) {
81 this.chartOfAccountsCode = chartOfAccountsCode;
82 }
83
84
85
86
87
88
89 public String getAccountNumber() {
90 return accountNumber;
91 }
92
93
94
95
96
97
98 public void setAccountNumber(String accountNumber) {
99 this.accountNumber = accountNumber;
100 }
101
102
103
104
105
106
107 public String getSubAccountNumber() {
108 return subAccountNumber;
109 }
110
111
112
113
114
115
116 public void setSubAccountNumber(String subAccountNumber) {
117 this.subAccountNumber = subAccountNumber;
118 }
119
120
121
122
123
124
125 public String getFinancialObjectCode() {
126 return financialObjectCode;
127 }
128
129
130
131
132
133
134 public void setFinancialObjectCode(String financialObjectCode) {
135 this.financialObjectCode = financialObjectCode;
136 }
137
138
139
140
141
142
143 public String getFinancialSubObjectCode() {
144 return financialSubObjectCode;
145 }
146
147
148
149
150
151
152 public void setFinancialSubObjectCode(String financialSubObjectCode) {
153 this.financialSubObjectCode = financialSubObjectCode;
154 }
155
156
157
158
159
160
161
162 public Integer getPostingYear() {
163 return postingYear;
164 }
165
166
167
168
169
170
171
172 public void setPostingYear(Integer postingYear) {
173 this.postingYear = postingYear;
174 }
175
176
177
178
179
180
181
182 public String getPostingPeriodCode() {
183 return postingPeriodCode;
184 }
185
186
187
188
189
190
191
192 public void setPostingPeriodCode(String postingPeriodCode) {
193 this.postingPeriodCode = postingPeriodCode;
194 }
195
196
197
198
199
200
201
202
203 @Override
204 public boolean equals(Object obj) {
205 if (this == obj) {
206 return true;
207 }
208 if (obj == null || !PurapAccountRevisionGroup.class.isAssignableFrom(obj.getClass())) {
209 return false;
210 }
211 PurapAccountRevisionGroup test = (PurapAccountRevisionGroup) obj;
212 EqualsBuilder equalsBuilder = new EqualsBuilder();
213 equalsBuilder.append(this.postingYear, test.getPostingYear());
214 equalsBuilder.append(itemIdentifier, test.getItemIdentifier());
215 equalsBuilder.append(replaceFiller(chartOfAccountsCode), replaceFiller(test.getChartOfAccountsCode()));
216 equalsBuilder.append(replaceFiller(accountNumber), replaceFiller(test.getAccountNumber()));
217 equalsBuilder.append(replaceFiller(subAccountNumber), replaceFiller(test.getSubAccountNumber()));
218 equalsBuilder.append(replaceFiller(financialObjectCode), replaceFiller(test.getFinancialObjectCode()));
219 equalsBuilder.append(replaceFiller(financialSubObjectCode), replaceFiller(test.getFinancialSubObjectCode()));
220 equalsBuilder.append(replaceFiller(postingPeriodCode), replaceFiller(test.getPostingPeriodCode()));
221 equalsBuilder.append(replaceFiller(projectCode), replaceFiller(test.getProjectCode()));
222 equalsBuilder.append(replaceFiller(organizationReferenceId), replaceFiller(test.getOrganizationReferenceId()));
223 return equalsBuilder.isEquals();
224 }
225
226 protected String replaceFiller(String val) {
227 if (val == null) {
228 return "";
229 }
230 char[] charArray = val.trim().toCharArray();
231 for (char c : charArray) {
232 if (c != '-') {
233 return val;
234 }
235 }
236 return "";
237 }
238
239
240
241
242
243
244
245 @Override
246 public int hashCode() {
247 HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(37, 41);
248 hashCodeBuilder.append(this.postingYear);
249 hashCodeBuilder.append(itemIdentifier);
250 hashCodeBuilder.append(replaceFiller(chartOfAccountsCode));
251 hashCodeBuilder.append(replaceFiller(accountNumber));
252 hashCodeBuilder.append(replaceFiller(subAccountNumber));
253 hashCodeBuilder.append(replaceFiller(financialObjectCode));
254 hashCodeBuilder.append(replaceFiller(financialSubObjectCode));
255 hashCodeBuilder.append(replaceFiller(postingPeriodCode));
256 hashCodeBuilder.append(replaceFiller(projectCode));
257 hashCodeBuilder.append(replaceFiller(organizationReferenceId));
258 return hashCodeBuilder.toHashCode();
259 }
260
261
262
263
264
265
266
267 public KualiDecimal getAmount() {
268 return amount;
269 }
270
271
272
273
274
275
276
277 public void setAmount(KualiDecimal absAmount) {
278 this.amount = absAmount;
279 }
280
281 @Override
282 public String toString() {
283 return "" + postingYear + "-" + chartOfAccountsCode + "-" + accountNumber + "-" + replaceFiller(subAccountNumber) + "-" + financialObjectCode + "-" + replaceFiller(financialSubObjectCode) + "-" + postingPeriodCode + "-" + itemIdentifier;
284 }
285
286
287
288
289
290
291 public Integer getItemIdentifier() {
292 return itemIdentifier;
293 }
294
295
296
297
298
299
300 public void setItemIdentifier(Integer itemIdentifier) {
301 this.itemIdentifier = itemIdentifier;
302 }
303
304
305
306
307
308
309 public void combineEntry(PurApAccountingLineBase newEntry) {
310 this.sourceEntries.add(newEntry);
311 this.amount = this.amount.add(newEntry.getAmount());
312 }
313
314
315
316
317
318
319 public KualiDecimal getChangeAmount() {
320 return changeAmount;
321 }
322
323
324
325
326
327
328 public void setChangeAmount(KualiDecimal changeAmount) {
329 this.changeAmount = changeAmount;
330 }
331
332
333
334
335
336
337
338 public String getProjectCode() {
339 return projectCode;
340 }
341
342
343
344
345
346
347 public void setProjectCode(String projectCode) {
348 this.projectCode = projectCode;
349 }
350
351
352
353
354
355
356 public String getOrganizationReferenceId() {
357 return organizationReferenceId;
358 }
359
360
361
362
363
364
365 public void setOrganizationReferenceId(String organizationReferenceId) {
366 this.organizationReferenceId = organizationReferenceId;
367 }
368
369
370
371
372
373
374
375 public BigDecimal getAccountLinePercent() {
376 return accountLinePercent;
377 }
378
379
380
381
382
383
384 public void setAccountLinePercent(BigDecimal accountLinePercent) {
385 this.accountLinePercent = accountLinePercent;
386 }
387
388 public PurApAccountingLineBase buildRevisionRecord(Class<? extends PurApAccountingLineBase> clazz) {
389 PurApAccountingLineBase histRecord = null;
390 try {
391 histRecord = clazz.newInstance();
392 histRecord.setItemIdentifier(this.getItemIdentifier());
393 histRecord.setChartOfAccountsCode(this.getChartOfAccountsCode());
394 histRecord.setAccountNumber(this.getAccountNumber());
395 histRecord.setSubAccountNumber(this.getSubAccountNumber());
396 histRecord.setFinancialObjectCode(this.getFinancialObjectCode());
397 histRecord.setFinancialSubObjectCode(this.getFinancialSubObjectCode());
398 histRecord.setProjectCode(this.getProjectCode());
399 histRecord.setOrganizationReferenceId(this.getOrganizationReferenceId());
400 histRecord.setAmount(this.getChangeAmount());
401 histRecord.setPostingYear(this.getPostingYear());
402 histRecord.setPostingPeriodCode(this.getPostingPeriodCode());
403 histRecord.setAccountLinePercent(this.getAccountLinePercent());
404 } catch (Exception e) {
405 throw new RuntimeException(e);
406 }
407 return histRecord;
408 }
409 }