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