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.coa.businessobject;
20  
21  import java.util.LinkedHashMap;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.kuali.kfs.gl.businessobject.SufficientFundRebuild;
25  import org.kuali.kfs.sys.KFSConstants;
26  import org.kuali.kfs.sys.businessobject.FiscalYearBasedBusinessObject;
27  import org.kuali.kfs.sys.businessobject.SystemOptions;
28  import org.kuali.kfs.sys.context.SpringContext;
29  import org.kuali.rice.krad.bo.KualiCode;
30  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
31  import org.kuali.rice.krad.service.BusinessObjectService;
32  import org.kuali.rice.krad.service.impl.PersistenceStructureServiceImpl;
33  
34  /**
35   * 
36   */
37  public class ObjectCode extends PersistableBusinessObjectBase implements KualiCode, FiscalYearBasedBusinessObject {
38  
39  
40      static {
41          PersistenceStructureServiceImpl.referenceConversionMap.put(ObjectCode.class, ObjectCodeCurrent.class);
42      }
43  
44      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ObjectCode.class);
45  
46      public static final String CACHE_NAME = KFSConstants.APPLICATION_NAMESPACE_CODE + "/" + "ObjectCode";
47      
48      private static final long serialVersionUID = -965833141452795485L;
49      protected Integer universityFiscalYear;
50      protected String chartOfAccountsCode;
51      protected String financialObjectCode;
52      protected String financialObjectCodeName;
53      protected String financialObjectCodeShortName;
54      protected String historicalFinancialObjectCode;
55      protected boolean active;
56      protected String financialObjectLevelCode;
57      protected String reportsToChartOfAccountsCode;
58      protected String reportsToFinancialObjectCode;
59      protected String financialObjectTypeCode;
60      protected String financialObjectSubTypeCode;
61      protected String financialBudgetAggregationCd;
62      protected String nextYearFinancialObjectCode;
63      protected String finObjMandatoryTrnfrelimCd;
64      protected String financialFederalFundedCode;
65          
66      protected transient BudgetAggregationCode financialBudgetAggregation;
67      protected transient MandatoryTransferEliminationCode finObjMandatoryTrnfrelim;
68      protected transient FederalFundedCode financialFederalFunded;
69      protected transient SystemOptions universityFiscal;
70      protected transient ObjectLevel financialObjectLevel;
71      protected transient Chart chartOfAccounts;
72      protected transient Chart reportsToChartOfAccounts;
73      protected transient ObjectCode reportsToFinancialObject;
74      protected transient ObjectType financialObjectType;
75      protected transient ObjectSubType financialObjectSubType;
76      
77      /**
78       * Default no-arg constructor.
79       */
80      public ObjectCode() {
81          // initialize the object fiscal year to the current fiscal year
82          // universityFiscalYear = SpringContext.getBean(DateTimeService.class).getCurrentFiscalYear();
83  
84          // construct the referenced objects for the calling of the referencing object
85          this.financialObjectLevel = new ObjectLevel();
86          this.financialObjectType = new ObjectType();
87      }
88  
89      /**
90       * Constructs a ObjectCode.java with the given defaults; this way, it is not necessary to use any deprecated setters.
91       * 
92       * @param fiscalYear
93       * @param chart
94       * @param financialObjectCode - an active object code
95       */
96      public ObjectCode(Integer fiscalYear, String chart, String financialObjectCode) {
97          this.universityFiscalYear = fiscalYear;
98          this.chartOfAccountsCode = chart;
99          this.financialObjectCode = financialObjectCode;
100         this.active = true;
101     }
102 
103     /**
104      * This method is only for use by the framework
105      */
106     public void setUniversityFiscalYear(Integer i) {
107         this.universityFiscalYear = i;
108     }
109 
110     /**
111      * Gets the financialFederalFunded attribute.
112      * 
113      * @return Returns the financialFederalFunded.
114      */
115     public FederalFundedCode getFinancialFederalFunded() {
116         return financialFederalFunded;
117     }
118 
119     /**
120      * Sets the financialFederalFunded attribute value.
121      * 
122      * @param financialFederalFunded The financialFederalFunded to set.
123      * @deprecated
124      */
125     public void setFinancialFederalFunded(FederalFundedCode financialFederalFunded) {
126         this.financialFederalFunded = financialFederalFunded;
127     }
128 
129     /**
130      * Gets the finObjMandatoryTrnfrelim attribute.
131      * 
132      * @return Returns the finObjMandatoryTrnfrelimCd.
133      */
134     public MandatoryTransferEliminationCode getFinObjMandatoryTrnfrelim() {
135         return finObjMandatoryTrnfrelim;
136     }
137 
138 
139     /**
140      * Sets the finObjMandatoryTrnfrelim attribute value.
141      * 
142      * @param finObjMandatoryTrnfrelim The finObjMandatoryTrnfrelim to set.
143      * @deprecated
144      */
145     public void setFinObjMandatoryTrnfrelim(MandatoryTransferEliminationCode finObjMandatoryTrnfrelim) {
146         this.finObjMandatoryTrnfrelim = finObjMandatoryTrnfrelim;
147     }
148 
149     /**
150      * Gets the financialObjectCode attribute.
151      * 
152      * @return Returns the financialObjectCode
153      */
154     public String getFinancialObjectCode() {
155         return financialObjectCode;
156     }
157 
158     /**
159      * Sets the financialObjectCode attribute.
160      * 
161      * @param financialObjectCode The financialObjectCode to set.
162      */
163     public void setFinancialObjectCode(String financialObjectCode) {
164         this.financialObjectCode = financialObjectCode;
165     }
166 
167     /**
168      * Gets the financialObjectCodeName attribute.
169      * 
170      * @return Returns the financialObjectCodeName
171      */
172     public String getFinancialObjectCodeName() {
173         return financialObjectCodeName;
174     }
175 
176     /**
177      * Sets the financialObjectCodeName attribute.
178      * 
179      * @param financialObjectCodeName The financialObjectCodeName to set.
180      */
181     public void setFinancialObjectCodeName(String financialObjectCodeName) {
182         this.financialObjectCodeName = financialObjectCodeName;
183     }
184 
185     /**
186      * Gets the financialObjectCodeShortName attribute.
187      * 
188      * @return Returns the financialObjectCodeShortName
189      */
190     public String getFinancialObjectCodeShortName() {
191         return financialObjectCodeShortName;
192     }
193 
194     /**
195      * Sets the financialObjectCodeShortName attribute.
196      * 
197      * @param financialObjectCodeShortName The financialObjectCodeShortName to set.
198      */
199     public void setFinancialObjectCodeShortName(String financialObjectCodeShortName) {
200         this.financialObjectCodeShortName = financialObjectCodeShortName;
201     }
202 
203     /**
204      * Gets the historicalFinancialObjectCode attribute.
205      * 
206      * @return Returns the historicalFinancialObjectCode
207      */
208     public String getHistoricalFinancialObjectCode() {
209         return historicalFinancialObjectCode;
210     }
211 
212     /**
213      * Sets the historicalFinancialObjectCode attribute.
214      * 
215      * @param historicalFinancialObjectCode The historicalFinancialObjectCode to set.
216      */
217     public void setHistoricalFinancialObjectCode(String historicalFinancialObjectCode) {
218         this.historicalFinancialObjectCode = historicalFinancialObjectCode;
219     }
220 
221     /**
222      * Gets the financialObjectActiveCode attribute.
223      * 
224      * @return Returns the financialObjectActiveCode
225      */
226     public boolean isFinancialObjectActiveCode() {
227         return active;
228     }
229 
230     /**
231      * Sets the financialObjectActiveCode attribute.
232      * 
233      * @param financialObjectActiveCode The financialObjectActiveCode to set.
234      */
235     public void setFinancialObjectActiveCode(boolean active) {
236         this.active = active;
237     }
238 
239     /**
240      * Gets the financialBudgetAggregationCd attribute.
241      * 
242      * @return Returns the financialBudgetAggregationCd
243      */
244     /*
245      * public BudgetAggregationCode getFinancialBudgetAggregation() { return financialBudgetAggregation; }
246      */
247 
248     /**
249      * Sets the financialBudgetAggregationCd attribute.
250      * 
251      * @param financialBudgetAggregationCd The financialBudgetAggregationCd to set.
252      * @deprecated
253      */
254     /*
255      * public void setFinancialBudgetAggregation(BudgetAggregationCode financialBudgetAggregationCd) {
256      * this.financialBudgetAggregation = financialBudgetAggregationCd; }
257      */
258 
259     /**
260      * Gets the universityFiscal attribute.
261      * 
262      * @return Returns the universityFiscal
263      */
264     public SystemOptions getUniversityFiscal() {
265         return universityFiscal;
266     }
267 
268     /**
269      * Sets the universityFiscal attribute.
270      * 
271      * @param universityFiscal The universityFiscal to set.
272      * @deprecated
273      */
274     public void setUniversityFiscal(SystemOptions universityFiscal) {
275         this.universityFiscal = universityFiscal;
276     }
277 
278     /**
279      * Gets the financialObjectLevel attribute.
280      * 
281      * @return Returns the financialObjectLevel
282      */
283     public ObjectLevel getFinancialObjectLevel() {
284         return financialObjectLevel;
285     }
286 
287     /**
288      * Sets the financialObjectLevel attribute.
289      * 
290      * @param financialObjectLevel The financialObjectLevel to set.
291      * @deprecated
292      */
293     public void setFinancialObjectLevel(ObjectLevel financialObjectLevel) {
294         this.financialObjectLevel = financialObjectLevel;
295     }
296 
297     /**
298      * Gets the chartOfAccounts attribute.
299      * 
300      * @return Returns the chartOfAccounts
301      */
302     public Chart getChartOfAccounts() {
303         return chartOfAccounts;
304     }
305 
306     /**
307      * Sets the chartOfAccounts attribute.
308      * 
309      * @param chartOfAccounts The chartOfAccounts to set.
310      * @deprecated
311      */
312     public void setChartOfAccounts(Chart chartOfAccounts) {
313         this.chartOfAccounts = chartOfAccounts;
314     }
315 
316     /**
317      * Gets the reportsToChartOfAccounts attribute.
318      * 
319      * @return Returns the reportsToChartOfAccounts
320      */
321     public Chart getReportsToChartOfAccounts() {
322         return reportsToChartOfAccounts;
323     }
324 
325     /**
326      * Sets the reportsToChartOfAccounts attribute.
327      * 
328      * @param reportsToChartOfAccounts The reportsToChartOfAccounts to set.
329      * @deprecated
330      */
331     public void setReportsToChartOfAccounts(Chart reportsToChartOfAccounts) {
332         this.reportsToChartOfAccounts = reportsToChartOfAccounts;
333     }
334 
335     /**
336      * Gets the reportsToFinancialObject attribute.
337      * 
338      * @return Returns the reportsToFinancialObject
339      */
340     public ObjectCode getReportsToFinancialObject() {
341         return reportsToFinancialObject;
342     }
343 
344     /**
345      * Sets the reportsToFinancialObject attribute.
346      * 
347      * @param reportsToFinancialObject The reportsToFinancialObject to set.
348      * @deprecated
349      */
350     public void setReportsToFinancialObject(ObjectCode reportsToFinancialObject) {
351         this.reportsToFinancialObject = reportsToFinancialObject;
352     }
353 
354     /**
355      * Gets the financialObjectType attribute.
356      * 
357      * @return Returns the financialObjectType
358      */
359     public ObjectType getFinancialObjectType() {
360         return financialObjectType;
361     }
362 
363     /**
364      * Sets the financialObjectType attribute.
365      * 
366      * @param financialObjectType The financialObjectType to set.
367      * @deprecated
368      */
369     public void setFinancialObjectType(ObjectType financialObjectType) {
370         this.financialObjectType = financialObjectType;
371     }
372 
373     /**
374      * Gets the financialObjectSubType attribute.
375      * 
376      * @return Returns the financialObjectSubType
377      */
378     public ObjectSubType getFinancialObjectSubType() {
379         return financialObjectSubType;
380     }
381 
382     /**
383      * Sets the financialObjectSubType attribute.
384      * 
385      * @param financialObjectSubType The financialObjectSubType to set.
386      * @deprecated
387      */
388     public void setFinancialObjectSubType(ObjectSubType financialObjectSubType) {
389         this.financialObjectSubType = financialObjectSubType;
390     }
391 
392     /**
393      */
394     public void setChartOfAccountsCode(String string) {
395         this.chartOfAccountsCode = string;
396     }
397 
398     /**
399      * 
400      */
401     public String getChartOfAccountsCode() {
402         return this.chartOfAccountsCode;
403     }
404 
405     /**
406      * 
407      */
408     public Integer getUniversityFiscalYear() {
409         return this.universityFiscalYear;
410     }
411 
412     /**
413      * @return Returns the financialBudgetAggregationCd.
414      */
415     public String getFinancialBudgetAggregationCd() {
416         return financialBudgetAggregationCd;
417     }
418 
419     /**
420      * @param financialBudgetAggregationCd The financialBudgetAggregationCd to set.
421      */
422     public void setFinancialBudgetAggregationCd(String financialBudgetAggregationCd) {
423         this.financialBudgetAggregationCd = financialBudgetAggregationCd;
424     }
425 
426     /**
427      * @return Returns the financialObjectLevelCode.
428      */
429     public String getFinancialObjectLevelCode() {
430         return financialObjectLevelCode;
431     }
432 
433     /**
434      * @param financialObjectLevelCode The financialObjectLevelCode to set.
435      */
436     public void setFinancialObjectLevelCode(String financialObjectLevelCode) {
437         this.financialObjectLevelCode = financialObjectLevelCode;
438     }
439 
440     /**
441      * @return Returns the financialObjectSubTypeCode.
442      */
443     public String getFinancialObjectSubTypeCode() {
444         return financialObjectSubTypeCode;
445     }
446 
447     /**
448      * @param financialObjectSubTypeCode The financialObjectSubTypeCode to set.
449      */
450     public void setFinancialObjectSubTypeCode(String financialObjectSubTypeCode) {
451         this.financialObjectSubTypeCode = financialObjectSubTypeCode;
452     }
453 
454     /**
455      * @return Returns the financialObjectTypeCode.
456      */
457     public String getFinancialObjectTypeCode() {
458         return financialObjectTypeCode;
459     }
460 
461     /**
462      * @param financialObjectTypeCode The financialObjectTypeCode to set.
463      */
464     public void setFinancialObjectTypeCode(String financialObjectTypeCode) {
465         this.financialObjectTypeCode = financialObjectTypeCode;
466     }
467 
468     /**
469      * @return Returns the nextYearFinancialObjectCode.
470      */
471     public String getNextYearFinancialObjectCode() {
472         return nextYearFinancialObjectCode;
473     }
474 
475     /**
476      * @param nextYearFinancialObjectCode The nextYearFinancialObjectCode to set.
477      */
478     public void setNextYearFinancialObjectCode(String nextYearFinancialObjectCode) {
479         this.nextYearFinancialObjectCode = nextYearFinancialObjectCode;
480     }
481 
482     /**
483      * @return Returns the reportsToChartOfAccountsCode.
484      */
485     public String getReportsToChartOfAccountsCode() {
486         return reportsToChartOfAccountsCode;
487     }
488 
489     /**
490      * @param reportsToChartOfAccountsCode The reportsToChartOfAccountsCode to set.
491      */
492     public void setReportsToChartOfAccountsCode(String reportsToChartOfAccountsCode) {
493         this.reportsToChartOfAccountsCode = reportsToChartOfAccountsCode;
494     }
495 
496     /**
497      * @return Returns the reportsToFinancialObjectCode.
498      */
499     public String getReportsToFinancialObjectCode() {
500         return reportsToFinancialObjectCode;
501     }
502 
503     /**
504      * @param reportsToFinancialObjectCode The reportsToFinancialObjectCode to set.
505      */
506     public void setReportsToFinancialObjectCode(String reportsToFinancialObjectCode) {
507         this.reportsToFinancialObjectCode = reportsToFinancialObjectCode;
508     }
509 
510     /**
511      * @return Returns the financialFederalFundedCode.
512      */
513     public String getFinancialFederalFundedCode() {
514         return financialFederalFundedCode;
515     }
516 
517     /**
518      * @param financialFederalFundedCode The financialFederalFundedCode to set.
519      */
520     public void setFinancialFederalFundedCode(String financialFederalFundedCode) {
521         this.financialFederalFundedCode = financialFederalFundedCode;
522     }
523 
524     /**
525      * @return Returns the finObjMandatoryTrnfrelimCd.
526      */
527     public String getFinObjMandatoryTrnfrelimCd() {
528         return finObjMandatoryTrnfrelimCd;
529     }
530 
531     /**
532      * @param finObjMandatoryTrnfrelimCd The finObjMandatoryTrnfrelimCd to set.
533      */
534     public void setFinObjMandatoryTrnfrelimCd(String finObjMandatoryTrnfrelimCd) {
535         this.finObjMandatoryTrnfrelimCd = finObjMandatoryTrnfrelimCd;
536     }
537 
538     public BudgetAggregationCode getFinancialBudgetAggregation() {
539         return financialBudgetAggregation;
540     }
541 
542     public void setFinancialBudgetAggregation(BudgetAggregationCode financialBudgetAggregation) {
543         this.financialBudgetAggregation = financialBudgetAggregation;
544     }
545 
546     /**
547      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
548      */
549     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
550 
551         LinkedHashMap<String, String> m = new LinkedHashMap<String, String>();
552         m.put("chartOfAccountsCode", this.chartOfAccountsCode);
553         m.put("financialObjectCode", this.financialObjectCode);
554 
555         return m;
556     }
557 
558     protected static BusinessObjectService businessObjectService;
559     
560     protected BusinessObjectService getBusinessObjectService() {
561         if ( businessObjectService == null ) {
562             businessObjectService = SpringContext.getBean(BusinessObjectService.class);
563         }
564         return businessObjectService;
565     }
566     
567     @Override protected void preUpdate() {
568         // TODO Auto-generated method stub
569         super.preUpdate();
570         try {
571             // KULCOA-549: update the sufficient funds table
572             // get the current data from the database
573             ObjectCode originalObjectCode = (ObjectCode) getBusinessObjectService().retrieve(this);
574 
575             if (originalObjectCode != null) {
576                 if (!originalObjectCode.getFinancialObjectLevelCode().equals(getFinancialObjectLevelCode())) {
577                     SufficientFundRebuild sfr = new SufficientFundRebuild();
578                     sfr.setAccountFinancialObjectTypeCode(SufficientFundRebuild.REBUILD_OBJECT);
579                     sfr.setChartOfAccountsCode(originalObjectCode.getChartOfAccountsCode());
580                     sfr.setAccountNumberFinancialObjectCode(originalObjectCode.getFinancialObjectLevelCode());
581                     if (getBusinessObjectService().retrieve(sfr) == null) {
582                         getBusinessObjectService().save(sfr);
583                     }
584                     sfr = new SufficientFundRebuild();
585                     sfr.setAccountFinancialObjectTypeCode(SufficientFundRebuild.REBUILD_OBJECT);
586                     sfr.setChartOfAccountsCode(getChartOfAccountsCode());
587                     sfr.setAccountNumberFinancialObjectCode(getFinancialObjectLevelCode());
588                     if (getBusinessObjectService().retrieve(sfr) == null) {
589                         getBusinessObjectService().save(sfr);
590                     }
591                 }
592             }
593         } catch (Exception ex) {
594             LOG.error("Problem updating sufficient funds rebuild table: ", ex);
595         }
596     }
597 
598     public boolean isActive() {
599         return this.active;
600     }
601 
602     public void setActive(boolean a) {
603         this.active = a;
604     }
605 
606     public void setCode(String code) {
607         this.chartOfAccountsCode = code;
608     }
609 
610     public void setName(String name) {
611         this.financialObjectCodeName = name;
612     }
613 
614     public String getCode() {
615         return this.financialObjectCode;
616     }
617 
618     public String getName() {
619         return this.financialObjectCodeName;
620     }
621 
622     /**
623      * Determines if this object code reports to itself
624      * @return true if the object code reports to itself, false otherwise
625      */
626     public boolean isReportingToSelf() {
627         return StringUtils.equals(this.getChartOfAccountsCode(), this.getReportsToChartOfAccountsCode()) && StringUtils.equals(this.getFinancialObjectCode(), this.getReportsToFinancialObjectCode());
628     }
629 }