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.module.endow.businessobject;
017    
018    import java.math.BigDecimal;
019    import java.sql.Date;
020    import java.util.LinkedHashMap;
021    import java.util.List;
022    
023    import org.apache.commons.lang.StringUtils;
024    import org.apache.ojb.broker.PersistenceBroker;
025    import org.apache.ojb.broker.PersistenceBrokerException;
026    import org.kuali.kfs.module.endow.EndowConstants;
027    import org.kuali.kfs.module.endow.EndowPropertyConstants;
028    import org.kuali.kfs.module.endow.document.service.KEMService;
029    import org.kuali.kfs.module.endow.document.service.TicklerService;
030    import org.kuali.kfs.sys.KFSConstants;
031    import org.kuali.kfs.sys.context.SpringContext;
032    import org.kuali.rice.kns.bo.Inactivateable;
033    import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
034    import org.kuali.rice.kns.util.TypedArrayList;
035    
036    /**
037     * Business Object for Security table.
038     */
039    public class Security extends PersistableBusinessObjectBase implements Inactivateable {
040    
041        private String id;
042        private String description;
043        private String tickerSymbol;
044        private String securityClassCode;
045        private String securitySubclassCode;
046        private Date maturityDate;
047        private BigDecimal unitValue;
048        private BigDecimal unitsHeld;
049        private Date valuationDate;
050        private String unitValueSource;
051        private BigDecimal previousUnitValue;
052        private Date previousUnitValueDate;
053        private BigDecimal carryValue;
054        private Date lastTransactionDate;
055        private String incomePayFrequency;
056        private Date incomeNextPayDate;
057        private BigDecimal incomeRate;
058        private Date incomeChangeDate;
059        private Date issueDate;
060        private Date dividendRecordDate;
061        private Date exDividendDate;
062        private Date dividendPayDate;
063        private BigDecimal dividendAmount;
064        private BigDecimal commitmentAmount;
065        private BigDecimal nextFiscalYearDistributionAmount;
066        private BigDecimal securityValueByMarket;
067        private boolean active;
068    
069        // this field is not saved in the db,
070        // it is used so that the user can enter the first 8 chars of the security ID while the ninth
071        // digit is computed using the mod10 method
072        private String userEnteredSecurityIDprefix;
073    
074        // this field is not saved in the database but computed based on Sum of the HLDG _MVAL for all records for the Security in
075        // END_CURR_TAX_LOT_BAL_T
076        private BigDecimal marketValue;
077    
078        private ClassCode classCode;
079        private FrequencyCode frequencyCode;
080        private SubclassCode subclassCode;
081    
082        List<Tickler> ticklers;
083    
084        /**
085         * Constructs a Security.java.
086         */
087        public Security() {
088            super();
089            unitValue = BigDecimal.ONE;
090            unitsHeld = BigDecimal.ZERO;
091            carryValue = BigDecimal.ZERO;
092            ticklers = new TypedArrayList(Tickler.class);
093        }
094    
095        /**
096         * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
097         */
098        @Override
099        protected LinkedHashMap toStringMapper() {
100            LinkedHashMap m = new LinkedHashMap();
101            m.put(EndowPropertyConstants.SECURITY_ID, this.id);
102            return m;
103        }
104    
105        /**
106         * @see org.kuali.rice.kns.bo.Inactivateable#isActive()
107         */
108        public boolean isActive() {
109            return active;
110        }
111    
112        /**
113         * @see org.kuali.rice.kns.bo.Inactivateable#setActive(boolean)
114         */
115        public void setActive(boolean active) {
116            this.active = active;
117        }
118    
119        /**
120         * This method gets carryValue
121         * 
122         * @return carryValue
123         */
124        public BigDecimal getCarryValue() {
125            return carryValue;
126        }
127    
128        /**
129         * This method sets carryValue.
130         * 
131         * @param carryValue
132         */
133        public void setCarryValue(BigDecimal carryValue) {
134            this.carryValue = carryValue;
135        }
136    
137    
138        /**
139         * This method gets the commitmentAmount.
140         * 
141         * @return commitmentAmount
142         */
143        public BigDecimal getCommitmentAmount() {
144            return commitmentAmount;
145        }
146    
147        /**
148         * This method sets the commitmentAmount.
149         * 
150         * @param commitmentAmount
151         */
152        public void setCommitmentAmount(BigDecimal commitmentAmount) {
153            this.commitmentAmount = commitmentAmount;
154        }
155    
156        /**
157         * This method gets the description.
158         * 
159         * @return description
160         */
161        public String getDescription() {
162            return description;
163        }
164    
165        /**
166         * This method sets the description.
167         * 
168         * @param description
169         */
170        public void setDescription(String description) {
171            this.description = description;
172        }
173    
174        /**
175         * This method gets the dividendAmount.
176         * 
177         * @return dividendAmount
178         */
179        public BigDecimal getDividendAmount() {
180            return dividendAmount;
181        }
182    
183        /**
184         * This method sets the dividendAmount.
185         * 
186         * @param dividendAmount
187         */
188        public void setDividendAmount(BigDecimal dividendAmount) {
189            this.dividendAmount = dividendAmount;
190        }
191    
192        /**
193         * This method gets the dividendPayDate
194         * 
195         * @return dividendPayDate
196         */
197        public Date getDividendPayDate() {
198            return dividendPayDate;
199        }
200    
201        /**
202         * This method sets the dividendPayDate.
203         * 
204         * @param dividendPayDate
205         */
206        public void setDividendPayDate(Date dividendPayDate) {
207            this.dividendPayDate = dividendPayDate;
208        }
209    
210        /**
211         * This method gets the dividendRecordDate.
212         * 
213         * @return dividendRecordDate
214         */
215        public Date getDividendRecordDate() {
216            return dividendRecordDate;
217        }
218    
219        /**
220         * This method sets the dividendRecordDate.
221         * 
222         * @param dividendRecordDate
223         */
224        public void setDividendRecordDate(Date dividendRecordDate) {
225            this.dividendRecordDate = dividendRecordDate;
226        }
227    
228        /**
229         * This method gets the exDividendDate.
230         * 
231         * @return exDividendDate
232         */
233        public Date getExDividendDate() {
234            return exDividendDate;
235        }
236    
237        /**
238         * This method sets the exDividendDate.
239         * 
240         * @param exDividendDate
241         */
242        public void setExDividendDate(Date exDividendDate) {
243            this.exDividendDate = exDividendDate;
244        }
245    
246        /**
247         * This method gets the id.
248         * 
249         * @return id
250         */
251        public String getId() {
252            return id;
253        }
254    
255        /**
256         * This method sets the id.
257         * 
258         * @param id
259         */
260        public void setId(String id) {
261            this.id = id;
262        }
263    
264        /**
265         * This method gets the incomeChangeDate.
266         * 
267         * @return incomeChangeDate
268         */
269        public Date getIncomeChangeDate() {
270            return incomeChangeDate;
271        }
272    
273        /**
274         * This method sets the incomeChangeDate.
275         * 
276         * @param incomeChangeDate
277         */
278        public void setIncomeChangeDate(Date incomeChangeDate) {
279            this.incomeChangeDate = incomeChangeDate;
280        }
281    
282        /**
283         * This method gets the incomeNextPayDate
284         * 
285         * @return incomeNextPayDate
286         */
287        public Date getIncomeNextPayDate() {
288            return incomeNextPayDate;
289        }
290    
291        /**
292         * This method sets the incomeNextPayDate
293         * 
294         * @param incomeNextPayDate
295         */
296        public void setIncomeNextPayDate(Date incomeNextPayDate) {
297            this.incomeNextPayDate = incomeNextPayDate;
298        }
299    
300        /**
301         * This method gets the incomePayFrequency.
302         * 
303         * @return incomePayFrequency
304         */
305        public String getIncomePayFrequency() {
306            return incomePayFrequency;
307        }
308    
309        /**
310         * This method sets the incomePayFrequency
311         * 
312         * @param incomePayFrequency
313         */
314        public void setIncomePayFrequency(String incomePayFrequency) {
315            this.incomePayFrequency = incomePayFrequency;
316        }
317    
318        /**
319         * This method gets the incomeRate
320         * 
321         * @return incomeRate
322         */
323        public BigDecimal getIncomeRate() {
324            return incomeRate;
325        }
326    
327        /**
328         * This method sets the incomeRate
329         * 
330         * @param incomeRate
331         */
332        public void setIncomeRate(BigDecimal incomeRate) {
333            this.incomeRate = incomeRate;
334        }
335    
336        /**
337         * This method gets the incomeRate.
338         * 
339         * @return incomeRate
340         */
341        public Date getIssueDate() {
342            return issueDate;
343        }
344    
345        /**
346         * This method sets the incomeRate.
347         * 
348         * @param issueDate
349         */
350        public void setIssueDate(Date issueDate) {
351            this.issueDate = issueDate;
352        }
353    
354        /**
355         * This method gets the lastTransactionDate.
356         * 
357         * @return lastTransactionDate
358         */
359        public Date getLastTransactionDate() {
360            return lastTransactionDate;
361        }
362    
363        /**
364         * This method sets the lastTransactionDate.
365         * 
366         * @param lastTransactionDate
367         */
368        public void setLastTransactionDate(Date lastTransactionDate) {
369            this.lastTransactionDate = lastTransactionDate;
370        }
371    
372        /**
373         * This method gets the maturityDate
374         * 
375         * @return maturityDate
376         */
377        public Date getMaturityDate() {
378            return maturityDate;
379        }
380    
381        /**
382         * This method sets the maturityDate
383         * 
384         * @param maturityDate
385         */
386        public void setMaturityDate(Date maturityDate) {
387            this.maturityDate = maturityDate;
388        }
389    
390        /**
391         * This method gets the securitySubclassCode
392         * 
393         * @return securitySubclassCode
394         */
395        public String getSecuritySubclassCode() {
396            return securitySubclassCode;
397        }
398    
399        /**
400         * This method sets the securitySubclassCode
401         * 
402         * @param subclassCode
403         */
404        public void setSecuritySubclassCode(String subclassCode) {
405            this.securitySubclassCode = subclassCode;
406        }
407    
408        /**
409         * This method gets the tickerSymbol.
410         * 
411         * @return the tickerSymbol
412         */
413        public String getTickerSymbol() {
414            return tickerSymbol;
415        }
416    
417        /**
418         * This method sets the tickerSymbol.
419         * 
420         * @param tickerSymbol
421         */
422        public void setTickerSymbol(String tickerSymbol) {
423            this.tickerSymbol = tickerSymbol;
424        }
425    
426        /**
427         * This method gets the unitsHeld.
428         * 
429         * @return unitsHeld
430         */
431        public BigDecimal getUnitsHeld() {
432            return unitsHeld;
433        }
434    
435        /**
436         * This method sets the unitsHeld.
437         * 
438         * @param unitsHeld
439         */
440        public void setUnitsHeld(BigDecimal unitsHeld) {
441            this.unitsHeld = unitsHeld;
442        }
443    
444        /**
445         * This method gets the unitValue.
446         * 
447         * @return unitValue
448         */
449        public BigDecimal getUnitValue() {
450            return unitValue;
451        }
452    
453        /**
454         * This method sets the unitValue.
455         * 
456         * @param unitValue
457         */
458        public void setUnitValue(BigDecimal unitValue) {
459    
460            if (unitValue != null) {
461                this.unitValue = unitValue.setScale(EndowConstants.Scale.SECURITY_UNIT_VALUE, BigDecimal.ROUND_HALF_UP);
462            }
463            else {
464                this.unitValue = unitValue;
465            }
466        }
467    
468        /**
469         * This method gets the valuationDate.
470         * 
471         * @return valuationDate
472         */
473        public Date getValuationDate() {
474            return valuationDate;
475        }
476    
477        /**
478         * This method sets the valuationDate.
479         * 
480         * @param valuationDate
481         */
482        public void setValuationDate(Date valuationDate) {
483            this.valuationDate = valuationDate;
484        }
485    
486        /**
487         * This method gets the previousUnitValue.
488         * 
489         * @return previousUnitValue
490         */
491        public BigDecimal getPreviousUnitValue() {
492            return previousUnitValue;
493        }
494    
495        /**
496         * This method sets the previousUnitValue.
497         * 
498         * @param previousUnitValue
499         */
500        public void setPreviousUnitValue(BigDecimal previousUnitValue) {
501            this.previousUnitValue = previousUnitValue;
502        }
503    
504        /**
505         * This method gets the previousUnitValueDate.
506         * 
507         * @return previousUnitValueDate
508         */
509        public Date getPreviousUnitValueDate() {
510            return previousUnitValueDate;
511        }
512    
513        /**
514         * This method sets previousUnitValueDate.
515         * 
516         * @param previousUnitValueDate
517         */
518        public void setPreviousUnitValueDate(Date previousUnitValueDate) {
519            this.previousUnitValueDate = previousUnitValueDate;
520        }
521    
522        /**
523         * This method gets the unitValueSource.
524         * 
525         * @return unitValueSource
526         */
527        public String getUnitValueSource() {
528            return unitValueSource;
529        }
530    
531        /**
532         * This method sets the unitValueSource.
533         * 
534         * @param unitValueSource
535         */
536        public void setUnitValueSource(String unitValueSource) {
537            this.unitValueSource = unitValueSource;
538        }
539    
540        /**
541         * This method gets the classCode.
542         * 
543         * @return classCode
544         */
545        public ClassCode getClassCode() {
546            return classCode;
547        }
548    
549        /**
550         * This method sets the classCode.
551         * 
552         * @param classCode
553         */
554        public void setClassCode(ClassCode classCode) {
555            this.classCode = classCode;
556        }
557    
558        /**
559         * This method gets the securityClassCode
560         * 
561         * @return securityClassCode
562         */
563        public String getSecurityClassCode() {
564            return securityClassCode;
565        }
566    
567        /**
568         * This method sets the securityClassCode.
569         * 
570         * @param securityClassCode
571         */
572        public void setSecurityClassCode(String securityClassCode) {
573            this.securityClassCode = securityClassCode;
574        }
575    
576        /**
577         * This method returns the frequencyCode.
578         * 
579         * @return frequencyCode
580         */
581        public FrequencyCode getFrequencyCode() {
582            return frequencyCode;
583        }
584    
585        /**
586         * This method sets the frequencyCode.
587         * 
588         * @param frequencyCode
589         */
590        public void setFrequencyCode(FrequencyCode frequencyCode) {
591            this.frequencyCode = frequencyCode;
592        }
593    
594        /**
595         * This method gets the subclassCode.
596         * 
597         * @return subclassCode
598         */
599        public SubclassCode getSubclassCode() {
600            return subclassCode;
601        }
602    
603        /**
604         * This method sets the subclassCode.
605         * 
606         * @param subclassCode
607         */
608        public void setSubclassCode(SubclassCode subclassCode) {
609            this.subclassCode = subclassCode;
610        }
611    
612        /**
613         * This method gets the user entered security ID prefix (first 8 characters).
614         * 
615         * @return
616         */
617        public String getUserEnteredSecurityIDprefix() {
618            return userEnteredSecurityIDprefix;
619        }
620    
621        /**
622         * This method sets the user entered security ID prefix.
623         * 
624         * @param userEnteredSecurityIDprefix
625         */
626        public void setUserEnteredSecurityIDprefix(String userEnteredSecurityIDprefix) {
627            this.userEnteredSecurityIDprefix = userEnteredSecurityIDprefix;
628        }
629    
630        /**
631         * This method gets the market value of the security.
632         * 
633         * @return marketValue
634         */
635        public BigDecimal getMarketValue() {
636            return marketValue;
637        }
638    
639        /**
640         * This method sete the marketValue for the security.
641         * 
642         * @param marketValue
643         */
644        public void setMarketValue(BigDecimal marketValue) {
645    
646            if (marketValue != null) {
647                this.marketValue = marketValue.setScale(EndowConstants.Scale.SECURITY_MARKET_VALUE, BigDecimal.ROUND_HALF_UP);
648            }
649            else {
650                this.marketValue = marketValue;
651            }
652        }
653    
654        /**
655         * @see org.kuali.rice.kns.bo.PersistableBusinessObjectBase#afterLookup(org.apache.ojb.broker.PersistenceBroker)
656         */
657        @Override
658        public void afterLookup(PersistenceBroker persistenceBroker) throws PersistenceBrokerException {
659    
660            super.afterLookup(persistenceBroker);
661    
662            KEMService kemService = SpringContext.getBean(KEMService.class);
663    
664            // after a lookup is performed for Securities the market values is computed for display and the UserEnteredSecurityIDprefix
665            // is retrieved and set so that we don't get a required field error
666            String securityID = this.getId();
667            BigDecimal marketValue = kemService.getMarketValue(this.id);
668    
669            this.setMarketValue(marketValue);
670            // set user entered security ID prefix based on the security ID so that we don't get a required field error.
671            this.setUserEnteredSecurityIDprefix(securityID.substring(0, securityID.length() - 1));
672    
673        }
674    
675        /**
676         * Gets the nextFiscalYearDistributionAmount.
677         * 
678         * @return nextFiscalYearDistributionAmount
679         */
680        public BigDecimal getNextFiscalYearDistributionAmount() {
681            return nextFiscalYearDistributionAmount;
682        }
683    
684        /**
685         * Sets the nextFiscalYearDistributionAmount.
686         * 
687         * @param nextFiscalYearDistributionAmount
688         */
689        public void setNextFiscalYearDistributionAmount(BigDecimal nextFiscalYearDistributionAmount) {
690            this.nextFiscalYearDistributionAmount = nextFiscalYearDistributionAmount;
691        }
692    
693        /**
694         * Gets the CurrentHolders link text
695         * 
696         * @return the text to be displayed for the current holders link.
697         */
698        public String getCurrentHolders() {
699            return EndowConstants.LOOKUP_LINK;
700        }
701    
702        /**
703         * Gets the HoldersInHistory link text
704         * 
705         * @return the text to be displayed for the holders in history link.
706         */
707        public String getHoldersInHistory() {
708            return EndowConstants.LOOKUP_LINK;
709        }
710    
711        public String getSecurityIdDescription() {
712            String securityID = getId() != null ? getId() : "";
713            String description = getDescription() != null ? getDescription() : "";
714            String securityIdLabel = securityID + " - " + description;
715            return securityIdLabel;
716        }
717    
718        /**
719         * Gets the codeAndDescription text
720         * 
721         * @return the code and description in the form: xx-xxxxxxxxxx
722         */
723        public String getCodeAndDescription() {
724            if (StringUtils.isEmpty(this.getId())) {
725                return KFSConstants.EMPTY_STRING;
726            }
727            return this.getId() + "-" + this.getDescription();
728        }
729    
730        /**
731         * Gets the active ticklers for this Security.
732         * 
733         * @return ticklers
734         */
735        public List<Tickler> getTicklers() {
736            return SpringContext.getBean(TicklerService.class).getSecurityActiveTicklers(this.id);
737        }
738    
739        /**
740         * Sets the ticklers.
741         * 
742         * @param ticklers
743         */
744        public void setTicklers(List<Tickler> ticklers) {
745            this.ticklers = ticklers;
746        }
747    
748        /**
749         * Gets the securityValueByMarket.
750         * 
751         * @return securityValueByMarket
752         */
753        public BigDecimal getSecurityValueByMarket() {
754            return securityValueByMarket;
755        }
756    
757        /**
758         * Sets the securityValueByMarket.
759         * 
760         * @param securityValueByMarket
761         */
762        public void setSecurityValueByMarket(BigDecimal securityValueByMarket) {
763            this.securityValueByMarket = securityValueByMarket;
764        }
765    
766    }