001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.coa.businessobject;
017    
018    import java.util.LinkedHashMap;
019    
020    import org.apache.ojb.broker.PersistenceBroker;
021    import org.apache.ojb.broker.PersistenceBrokerException;
022    import org.kuali.kfs.gl.businessobject.SufficientFundRebuild;
023    import org.kuali.kfs.sys.businessobject.SystemOptions;
024    import org.kuali.kfs.sys.context.SpringContext;
025    import org.kuali.rice.kns.bo.KualiCode;
026    import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
027    import org.kuali.rice.kns.service.BusinessObjectService;
028    import org.kuali.rice.kns.service.impl.PersistenceStructureServiceImpl;
029    import org.kuali.rice.kns.util.ObjectUtils;
030    
031    /**
032     * 
033     */
034    public class ObjectCode extends PersistableBusinessObjectBase implements KualiCode {
035    
036    
037        static {
038            PersistenceStructureServiceImpl.referenceConversionMap.put(ObjectCode.class, ObjectCodeCurrent.class);
039        }
040    
041        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ObjectCode.class);
042    
043        private static final long serialVersionUID = -965833141452795485L;
044        private Integer universityFiscalYear;
045        private String chartOfAccountsCode;
046        private String financialObjectCode;
047        private String financialObjectCodeName;
048        private String financialObjectCodeShortName;
049        private String historicalFinancialObjectCode;
050        private boolean active;
051        private String financialObjectLevelCode;
052        private String reportsToChartOfAccountsCode;
053        private String reportsToFinancialObjectCode;
054        private String financialObjectTypeCode;
055        private String financialObjectSubTypeCode;
056        private String financialBudgetAggregationCd;
057        private String nextYearFinancialObjectCode;
058        private String finObjMandatoryTrnfrelimCd;
059        private String financialFederalFundedCode;
060            
061        private transient BudgetAggregationCode financialBudgetAggregation;
062        private transient MandatoryTransferEliminationCode finObjMandatoryTrnfrelim;
063        private transient FederalFundedCode financialFederalFunded;
064        private transient SystemOptions universityFiscal;
065        private transient ObjectLevel financialObjectLevel;
066        private transient Chart chartOfAccounts;
067        private transient Chart reportsToChartOfAccounts;
068        private transient ObjectCode reportsToFinancialObject;
069        private transient ObjectType financialObjectType;
070        private transient ObjectSubType financialObjectSubType;
071        
072        /**
073         * Default no-arg constructor.
074         */
075        public ObjectCode() {
076            // initialize the object fiscal year to the current fiscal year
077            // universityFiscalYear = SpringContext.getBean(DateTimeService.class).getCurrentFiscalYear();
078    
079            // construct the referenced objects for the calling of the referencing object
080            this.financialObjectLevel = new ObjectLevel();
081            this.financialObjectType = new ObjectType();
082        }
083    
084        /**
085         * Constructs a ObjectCode.java with the given defaults; this way, it is not necessary to use any deprecated setters.
086         * 
087         * @param fiscalYear
088         * @param chart
089         * @param financialObjectCode - an active object code
090         */
091        public ObjectCode(Integer fiscalYear, String chart, String financialObjectCode) {
092            this.universityFiscalYear = fiscalYear;
093            this.chartOfAccountsCode = chart;
094            this.financialObjectCode = financialObjectCode;
095            this.active = true;
096        }
097    
098        /**
099         * This method is only for use by the framework
100         */
101        public void setUniversityFiscalYear(Integer i) {
102            this.universityFiscalYear = i;
103        }
104    
105        /**
106         * Gets the financialFederalFunded attribute.
107         * 
108         * @return Returns the financialFederalFunded.
109         */
110        public FederalFundedCode getFinancialFederalFunded() {
111            return financialFederalFunded;
112        }
113    
114        /**
115         * Sets the financialFederalFunded attribute value.
116         * 
117         * @param financialFederalFunded The financialFederalFunded to set.
118         * @deprecated
119         */
120        public void setFinancialFederalFunded(FederalFundedCode financialFederalFunded) {
121            this.financialFederalFunded = financialFederalFunded;
122        }
123    
124        /**
125         * Gets the finObjMandatoryTrnfrelim attribute.
126         * 
127         * @return Returns the finObjMandatoryTrnfrelimCd.
128         */
129        public MandatoryTransferEliminationCode getFinObjMandatoryTrnfrelim() {
130            return finObjMandatoryTrnfrelim;
131        }
132    
133    
134        /**
135         * Sets the finObjMandatoryTrnfrelim attribute value.
136         * 
137         * @param finObjMandatoryTrnfrelim The finObjMandatoryTrnfrelim to set.
138         * @deprecated
139         */
140        public void setFinObjMandatoryTrnfrelim(MandatoryTransferEliminationCode finObjMandatoryTrnfrelim) {
141            this.finObjMandatoryTrnfrelim = finObjMandatoryTrnfrelim;
142        }
143    
144        /**
145         * Gets the financialObjectCode attribute.
146         * 
147         * @return Returns the financialObjectCode
148         */
149        public String getFinancialObjectCode() {
150            return financialObjectCode;
151        }
152    
153        /**
154         * Sets the financialObjectCode attribute.
155         * 
156         * @param financialObjectCode The financialObjectCode to set.
157         */
158        public void setFinancialObjectCode(String financialObjectCode) {
159            this.financialObjectCode = financialObjectCode;
160        }
161    
162        /**
163         * Gets the financialObjectCodeName attribute.
164         * 
165         * @return Returns the financialObjectCodeName
166         */
167        public String getFinancialObjectCodeName() {
168            return financialObjectCodeName;
169        }
170    
171        /**
172         * Sets the financialObjectCodeName attribute.
173         * 
174         * @param financialObjectCodeName The financialObjectCodeName to set.
175         */
176        public void setFinancialObjectCodeName(String financialObjectCodeName) {
177            this.financialObjectCodeName = financialObjectCodeName;
178        }
179    
180        /**
181         * Gets the financialObjectCodeShortName attribute.
182         * 
183         * @return Returns the financialObjectCodeShortName
184         */
185        public String getFinancialObjectCodeShortName() {
186            return financialObjectCodeShortName;
187        }
188    
189        /**
190         * Sets the financialObjectCodeShortName attribute.
191         * 
192         * @param financialObjectCodeShortName The financialObjectCodeShortName to set.
193         */
194        public void setFinancialObjectCodeShortName(String financialObjectCodeShortName) {
195            this.financialObjectCodeShortName = financialObjectCodeShortName;
196        }
197    
198        /**
199         * Gets the historicalFinancialObjectCode attribute.
200         * 
201         * @return Returns the historicalFinancialObjectCode
202         */
203        public String getHistoricalFinancialObjectCode() {
204            return historicalFinancialObjectCode;
205        }
206    
207        /**
208         * Sets the historicalFinancialObjectCode attribute.
209         * 
210         * @param historicalFinancialObjectCode The historicalFinancialObjectCode to set.
211         */
212        public void setHistoricalFinancialObjectCode(String historicalFinancialObjectCode) {
213            this.historicalFinancialObjectCode = historicalFinancialObjectCode;
214        }
215    
216        /**
217         * Gets the financialObjectActiveCode attribute.
218         * 
219         * @return Returns the financialObjectActiveCode
220         */
221        public boolean isFinancialObjectActiveCode() {
222            return active;
223        }
224    
225        /**
226         * Sets the financialObjectActiveCode attribute.
227         * 
228         * @param financialObjectActiveCode The financialObjectActiveCode to set.
229         */
230        public void setFinancialObjectActiveCode(boolean active) {
231            this.active = active;
232        }
233    
234        /**
235         * Gets the financialBudgetAggregationCd attribute.
236         * 
237         * @return Returns the financialBudgetAggregationCd
238         */
239        /*
240         * public BudgetAggregationCode getFinancialBudgetAggregation() { return financialBudgetAggregation; }
241         */
242    
243        /**
244         * Sets the financialBudgetAggregationCd attribute.
245         * 
246         * @param financialBudgetAggregationCd The financialBudgetAggregationCd to set.
247         * @deprecated
248         */
249        /*
250         * public void setFinancialBudgetAggregation(BudgetAggregationCode financialBudgetAggregationCd) {
251         * this.financialBudgetAggregation = financialBudgetAggregationCd; }
252         */
253    
254        /**
255         * Gets the universityFiscal attribute.
256         * 
257         * @return Returns the universityFiscal
258         */
259        public SystemOptions getUniversityFiscal() {
260            return universityFiscal;
261        }
262    
263        /**
264         * Sets the universityFiscal attribute.
265         * 
266         * @param universityFiscal The universityFiscal to set.
267         * @deprecated
268         */
269        public void setUniversityFiscal(SystemOptions universityFiscal) {
270            this.universityFiscal = universityFiscal;
271        }
272    
273        /**
274         * Gets the financialObjectLevel attribute.
275         * 
276         * @return Returns the financialObjectLevel
277         */
278        public ObjectLevel getFinancialObjectLevel() {
279            return financialObjectLevel;
280        }
281    
282        /**
283         * Sets the financialObjectLevel attribute.
284         * 
285         * @param financialObjectLevel The financialObjectLevel to set.
286         * @deprecated
287         */
288        public void setFinancialObjectLevel(ObjectLevel financialObjectLevel) {
289            this.financialObjectLevel = financialObjectLevel;
290        }
291    
292        /**
293         * Gets the chartOfAccounts attribute.
294         * 
295         * @return Returns the chartOfAccounts
296         */
297        public Chart getChartOfAccounts() {
298            return chartOfAccounts;
299        }
300    
301        /**
302         * Sets the chartOfAccounts attribute.
303         * 
304         * @param chartOfAccounts The chartOfAccounts to set.
305         * @deprecated
306         */
307        public void setChartOfAccounts(Chart chartOfAccounts) {
308            this.chartOfAccounts = chartOfAccounts;
309        }
310    
311        /**
312         * Gets the reportsToChartOfAccounts attribute.
313         * 
314         * @return Returns the reportsToChartOfAccounts
315         */
316        public Chart getReportsToChartOfAccounts() {
317            return reportsToChartOfAccounts;
318        }
319    
320        /**
321         * Sets the reportsToChartOfAccounts attribute.
322         * 
323         * @param reportsToChartOfAccounts The reportsToChartOfAccounts to set.
324         * @deprecated
325         */
326        public void setReportsToChartOfAccounts(Chart reportsToChartOfAccounts) {
327            this.reportsToChartOfAccounts = reportsToChartOfAccounts;
328        }
329    
330        /**
331         * Gets the reportsToFinancialObject attribute.
332         * 
333         * @return Returns the reportsToFinancialObject
334         */
335        public ObjectCode getReportsToFinancialObject() {
336            return reportsToFinancialObject;
337        }
338    
339        /**
340         * Sets the reportsToFinancialObject attribute.
341         * 
342         * @param reportsToFinancialObject The reportsToFinancialObject to set.
343         * @deprecated
344         */
345        public void setReportsToFinancialObject(ObjectCode reportsToFinancialObject) {
346            this.reportsToFinancialObject = reportsToFinancialObject;
347        }
348    
349        /**
350         * Gets the financialObjectType attribute.
351         * 
352         * @return Returns the financialObjectType
353         */
354        public ObjectType getFinancialObjectType() {
355            return financialObjectType;
356        }
357    
358        /**
359         * Sets the financialObjectType attribute.
360         * 
361         * @param financialObjectType The financialObjectType to set.
362         * @deprecated
363         */
364        public void setFinancialObjectType(ObjectType financialObjectType) {
365            this.financialObjectType = financialObjectType;
366        }
367    
368        /**
369         * Gets the financialObjectSubType attribute.
370         * 
371         * @return Returns the financialObjectSubType
372         */
373        public ObjectSubType getFinancialObjectSubType() {
374            return financialObjectSubType;
375        }
376    
377        /**
378         * Sets the financialObjectSubType attribute.
379         * 
380         * @param financialObjectSubType The financialObjectSubType to set.
381         * @deprecated
382         */
383        public void setFinancialObjectSubType(ObjectSubType financialObjectSubType) {
384            this.financialObjectSubType = financialObjectSubType;
385        }
386    
387        /**
388         */
389        public void setChartOfAccountsCode(String string) {
390            this.chartOfAccountsCode = string;
391        }
392    
393        /**
394         * 
395         */
396        public String getChartOfAccountsCode() {
397            return this.chartOfAccountsCode;
398        }
399    
400        /**
401         * 
402         */
403        public Integer getUniversityFiscalYear() {
404            return this.universityFiscalYear;
405        }
406    
407        /**
408         * @return Returns the financialBudgetAggregationCd.
409         */
410        public String getFinancialBudgetAggregationCd() {
411            return financialBudgetAggregationCd;
412        }
413    
414        /**
415         * @param financialBudgetAggregationCd The financialBudgetAggregationCd to set.
416         */
417        public void setFinancialBudgetAggregationCd(String financialBudgetAggregationCd) {
418            this.financialBudgetAggregationCd = financialBudgetAggregationCd;
419        }
420    
421        /**
422         * @return Returns the financialObjectLevelCode.
423         */
424        public String getFinancialObjectLevelCode() {
425            return financialObjectLevelCode;
426        }
427    
428        /**
429         * @param financialObjectLevelCode The financialObjectLevelCode to set.
430         */
431        public void setFinancialObjectLevelCode(String financialObjectLevelCode) {
432            this.financialObjectLevelCode = financialObjectLevelCode;
433        }
434    
435        /**
436         * @return Returns the financialObjectSubTypeCode.
437         */
438        public String getFinancialObjectSubTypeCode() {
439            return financialObjectSubTypeCode;
440        }
441    
442        /**
443         * @param financialObjectSubTypeCode The financialObjectSubTypeCode to set.
444         */
445        public void setFinancialObjectSubTypeCode(String financialObjectSubTypeCode) {
446            this.financialObjectSubTypeCode = financialObjectSubTypeCode;
447        }
448    
449        /**
450         * @return Returns the financialObjectTypeCode.
451         */
452        public String getFinancialObjectTypeCode() {
453            return financialObjectTypeCode;
454        }
455    
456        /**
457         * @param financialObjectTypeCode The financialObjectTypeCode to set.
458         */
459        public void setFinancialObjectTypeCode(String financialObjectTypeCode) {
460            this.financialObjectTypeCode = financialObjectTypeCode;
461        }
462    
463        /**
464         * @return Returns the nextYearFinancialObjectCode.
465         */
466        public String getNextYearFinancialObjectCode() {
467            return nextYearFinancialObjectCode;
468        }
469    
470        /**
471         * @param nextYearFinancialObjectCode The nextYearFinancialObjectCode to set.
472         */
473        public void setNextYearFinancialObjectCode(String nextYearFinancialObjectCode) {
474            this.nextYearFinancialObjectCode = nextYearFinancialObjectCode;
475        }
476    
477        /**
478         * @return Returns the reportsToChartOfAccountsCode.
479         */
480        public String getReportsToChartOfAccountsCode() {
481            return reportsToChartOfAccountsCode;
482        }
483    
484        /**
485         * @param reportsToChartOfAccountsCode The reportsToChartOfAccountsCode to set.
486         */
487        public void setReportsToChartOfAccountsCode(String reportsToChartOfAccountsCode) {
488            this.reportsToChartOfAccountsCode = reportsToChartOfAccountsCode;
489        }
490    
491        /**
492         * @return Returns the reportsToFinancialObjectCode.
493         */
494        public String getReportsToFinancialObjectCode() {
495            return reportsToFinancialObjectCode;
496        }
497    
498        /**
499         * @param reportsToFinancialObjectCode The reportsToFinancialObjectCode to set.
500         */
501        public void setReportsToFinancialObjectCode(String reportsToFinancialObjectCode) {
502            this.reportsToFinancialObjectCode = reportsToFinancialObjectCode;
503        }
504    
505        /**
506         * @return Returns the financialFederalFundedCode.
507         */
508        public String getFinancialFederalFundedCode() {
509            return financialFederalFundedCode;
510        }
511    
512        /**
513         * @param financialFederalFundedCode The financialFederalFundedCode to set.
514         */
515        public void setFinancialFederalFundedCode(String financialFederalFundedCode) {
516            this.financialFederalFundedCode = financialFederalFundedCode;
517        }
518    
519        /**
520         * @return Returns the finObjMandatoryTrnfrelimCd.
521         */
522        public String getFinObjMandatoryTrnfrelimCd() {
523            return finObjMandatoryTrnfrelimCd;
524        }
525    
526        /**
527         * @param finObjMandatoryTrnfrelimCd The finObjMandatoryTrnfrelimCd to set.
528         */
529        public void setFinObjMandatoryTrnfrelimCd(String finObjMandatoryTrnfrelimCd) {
530            this.finObjMandatoryTrnfrelimCd = finObjMandatoryTrnfrelimCd;
531        }
532    
533        public BudgetAggregationCode getFinancialBudgetAggregation() {
534            return financialBudgetAggregation;
535        }
536    
537        public void setFinancialBudgetAggregation(BudgetAggregationCode financialBudgetAggregation) {
538            this.financialBudgetAggregation = financialBudgetAggregation;
539        }
540    
541        /**
542         * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
543         */
544        protected LinkedHashMap<String, String> toStringMapper() {
545    
546            LinkedHashMap<String, String> m = new LinkedHashMap<String, String>();
547            m.put("chartOfAccountsCode", this.chartOfAccountsCode);
548            m.put("financialObjectCode", this.financialObjectCode);
549    
550            return m;
551        }
552    
553        @Override
554        public void beforeUpdate(PersistenceBroker persistenceBroker) throws PersistenceBrokerException {
555            super.beforeUpdate(persistenceBroker);
556            try {
557                // KULCOA-549: update the sufficient funds table
558                // get the current data from the database
559                BusinessObjectService boService = SpringContext.getBean(BusinessObjectService.class);
560                ObjectCode originalObjectCode = (ObjectCode) boService.retrieve(this);
561    
562                if (originalObjectCode != null) {
563                    if (!originalObjectCode.getFinancialObjectLevelCode().equals(getFinancialObjectLevelCode())) {
564                        SufficientFundRebuild sfr = new SufficientFundRebuild();
565                        sfr.setAccountFinancialObjectTypeCode(SufficientFundRebuild.REBUILD_OBJECT);
566                        sfr.setChartOfAccountsCode(originalObjectCode.getChartOfAccountsCode());
567                        sfr.setAccountNumberFinancialObjectCode(originalObjectCode.getFinancialObjectLevelCode());
568                        if (boService.retrieve(sfr) == null) {
569                            persistenceBroker.store(sfr);
570                        }
571                        sfr = new SufficientFundRebuild();
572                        sfr.setAccountFinancialObjectTypeCode(SufficientFundRebuild.REBUILD_OBJECT);
573                        sfr.setChartOfAccountsCode(getChartOfAccountsCode());
574                        sfr.setAccountNumberFinancialObjectCode(getFinancialObjectLevelCode());
575                        if (boService.retrieve(sfr) == null) {
576                            persistenceBroker.store(sfr);
577                        }
578                    }
579                }
580            }
581            catch (Exception ex) {
582                LOG.error("Problem updating sufficient funds rebuild table: ", ex);
583            }
584        }
585    
586        public boolean isActive() {
587            return this.active;
588        }
589    
590        public void setActive(boolean a) {
591            this.active = a;
592        }
593    
594        public void setCode(String code) {
595            this.chartOfAccountsCode = code;
596        }
597    
598        public void setName(String name) {
599            this.financialObjectCodeName = name;
600        }
601    
602        public String getCode() {
603            return this.financialObjectCode;
604        }
605    
606        public String getName() {
607            return this.financialObjectCodeName;
608        }
609    
610        /**
611         * Determines if this object code reports to itself
612         * @return true if the object code reports to itself, false otherwise
613         */
614        public boolean isReportingToSelf() {
615            return ObjectUtils.nullSafeEquals(this.getChartOfAccountsCode(), this.getReportsToChartOfAccountsCode()) && ObjectUtils.nullSafeEquals(this.getFinancialObjectCode(), this.getReportsToFinancialObjectCode());
616        }
617    }