View Javadoc
1   /*
2    * Copyright 2008-2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Purap account history grouping
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      // non-key attributes
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       * Gets the chartOfAccountsCode attribute.
68       *
69       * @return Returns the chartOfAccountsCode
70       */
71      public String getChartOfAccountsCode() {
72          return chartOfAccountsCode;
73      }
74  
75      /**
76       * Sets the chartOfAccountsCode attribute.
77       *
78       * @param chartOfAccountsCode The chartOfAccountsCode to set.
79       */
80      public void setChartOfAccountsCode(String chartOfAccountsCode) {
81          this.chartOfAccountsCode = chartOfAccountsCode;
82      }
83  
84      /**
85       * Gets the accountNumber attribute.
86       *
87       * @return Returns the accountNumber
88       */
89      public String getAccountNumber() {
90          return accountNumber;
91      }
92  
93      /**
94       * Sets the accountNumber attribute.
95       *
96       * @param accountNumber The accountNumber to set.
97       */
98      public void setAccountNumber(String accountNumber) {
99          this.accountNumber = accountNumber;
100     }
101 
102     /**
103      * Gets the subAccountNumber attribute.
104      *
105      * @return Returns the subAccountNumber
106      */
107     public String getSubAccountNumber() {
108         return subAccountNumber;
109     }
110 
111     /**
112      * Sets the subAccountNumber attribute.
113      *
114      * @param subAccountNumber The subAccountNumber to set.
115      */
116     public void setSubAccountNumber(String subAccountNumber) {
117         this.subAccountNumber = subAccountNumber;
118     }
119 
120     /**
121      * Gets the financialObjectCode attribute.
122      *
123      * @return Returns the financialObjectCode
124      */
125     public String getFinancialObjectCode() {
126         return financialObjectCode;
127     }
128 
129     /**
130      * Sets the financialObjectCode attribute.
131      *
132      * @param financialObjectCode The financialObjectCode to set.
133      */
134     public void setFinancialObjectCode(String financialObjectCode) {
135         this.financialObjectCode = financialObjectCode;
136     }
137 
138     /**
139      * Gets the financialSubObjectCode attribute.
140      *
141      * @return Returns the financialSubObjectCode
142      */
143     public String getFinancialSubObjectCode() {
144         return financialSubObjectCode;
145     }
146 
147     /**
148      * Sets the financialSubObjectCode attribute.
149      *
150      * @param financialSubObjectCode The financialSubObjectCode to set.
151      */
152     public void setFinancialSubObjectCode(String financialSubObjectCode) {
153         this.financialSubObjectCode = financialSubObjectCode;
154     }
155 
156 
157     /**
158      * Gets the postingYear attribute.
159      *
160      * @return Returns the postingYear.
161      */
162     public Integer getPostingYear() {
163         return postingYear;
164     }
165 
166 
167     /**
168      * Sets the postingYear attribute value.
169      *
170      * @param postingYear The postingYear to set.
171      */
172     public void setPostingYear(Integer postingYear) {
173         this.postingYear = postingYear;
174     }
175 
176 
177     /**
178      * Gets the postingPeriodCode attribute.
179      *
180      * @return Returns the postingPeriodCode.
181      */
182     public String getPostingPeriodCode() {
183         return postingPeriodCode;
184     }
185 
186 
187     /**
188      * Sets the postingPeriodCode attribute value.
189      *
190      * @param postingPeriodCode The postingPeriodCode to set.
191      */
192     public void setPostingPeriodCode(String postingPeriodCode) {
193         this.postingPeriodCode = postingPeriodCode;
194     }
195 
196 
197     /**
198      * Overridden so that group by statement can be easily implemented.
199      * <li>DO NOT REMOVE this method, it is critical to reconciliation process</li>
200      *
201      * @see java.lang.Object#equals(java.lang.Object)
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      * Overridden so that group by statement can be easily implemented.
241      * <li>DO NOT REMOVE this method, it is critical to reconciliation process</li>
242      *
243      * @see java.lang.Object#hashCode(java.lang.Object)
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      * Gets the absAmout attribute.
263      *
264      * @return Returns the absAmout
265      */
266 
267     public KualiDecimal getAmount() {
268         return amount;
269     }
270 
271     /**
272      * Sets the amount attribute.
273      *
274      * @param amount The amount to set.
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      * Gets the itemIdentifier attribute.
288      *
289      * @return Returns the itemIdentifier.
290      */
291     public Integer getItemIdentifier() {
292         return itemIdentifier;
293     }
294 
295     /**
296      * Sets the itemIdentifier attribute value.
297      *
298      * @param itemIdentifier The itemIdentifier to set.
299      */
300     public void setItemIdentifier(Integer itemIdentifier) {
301         this.itemIdentifier = itemIdentifier;
302     }
303 
304     /**
305      * This method will combine multiple Purap account entries for the same account line group.
306      *
307      * @param entry PurApAccountingLineBase
308      */
309     public void combineEntry(PurApAccountingLineBase newEntry) {
310         this.sourceEntries.add(newEntry);
311         this.amount = this.amount.add(newEntry.getAmount());
312     }
313 
314     /**
315      * Gets the changeAmount attribute.
316      *
317      * @return Returns the changeAmount.
318      */
319     public KualiDecimal getChangeAmount() {
320         return changeAmount;
321     }
322 
323     /**
324      * Sets the changeAmount attribute value.
325      *
326      * @param changeAmount The changeAmount to set.
327      */
328     public void setChangeAmount(KualiDecimal changeAmount) {
329         this.changeAmount = changeAmount;
330     }
331 
332 
333     /**
334      * Gets the projectCode attribute.
335      *
336      * @return Returns the projectCode.
337      */
338     public String getProjectCode() {
339         return projectCode;
340     }
341 
342     /**
343      * Sets the projectCode attribute value.
344      *
345      * @param projectCode The projectCode to set.
346      */
347     public void setProjectCode(String projectCode) {
348         this.projectCode = projectCode;
349     }
350 
351     /**
352      * Gets the organizationReferenceId attribute.
353      *
354      * @return Returns the organizationReferenceId.
355      */
356     public String getOrganizationReferenceId() {
357         return organizationReferenceId;
358     }
359 
360     /**
361      * Sets the organizationReferenceId attribute value.
362      *
363      * @param organizationReferenceId The organizationReferenceId to set.
364      */
365     public void setOrganizationReferenceId(String organizationReferenceId) {
366         this.organizationReferenceId = organizationReferenceId;
367     }
368 
369 
370     /**
371      * Gets the accountLinePercent attribute.
372      *
373      * @return Returns the accountLinePercent.
374      */
375     public BigDecimal getAccountLinePercent() {
376         return accountLinePercent;
377     }
378 
379     /**
380      * Sets the accountLinePercent attribute value.
381      *
382      * @param accountLinePercent The accountLinePercent to set.
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 }