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