001/**
002 * Copyright 2005-2015 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 */
016package org.kuali.rice.krad.demo.travel.dataobject;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.core.api.util.type.KualiPercent;
020import org.kuali.rice.kim.api.identity.Person;
021import org.kuali.rice.kim.api.services.KimApiServiceLocator;
022import org.kuali.rice.krad.bo.DataObjectBase;
023import org.kuali.rice.krad.data.provider.annotation.Description;
024import org.kuali.rice.krad.data.provider.annotation.ForceUppercase;
025import org.kuali.rice.krad.data.provider.annotation.InheritProperties;
026import org.kuali.rice.krad.data.provider.annotation.InheritProperty;
027import org.kuali.rice.krad.data.provider.annotation.KeyValuesFinderClass;
028import org.kuali.rice.krad.data.provider.annotation.Label;
029import org.kuali.rice.krad.data.provider.annotation.Relationship;
030import org.kuali.rice.krad.data.provider.annotation.UifAutoCreateViewType;
031import org.kuali.rice.krad.data.provider.annotation.UifAutoCreateViews;
032import org.kuali.rice.krad.data.provider.annotation.UifDisplayHint;
033import org.kuali.rice.krad.data.provider.annotation.UifDisplayHintType;
034import org.kuali.rice.krad.data.provider.annotation.UifDisplayHints;
035import org.kuali.rice.krad.data.provider.annotation.UifValidCharactersConstraintBeanName;
036import org.kuali.rice.krad.demo.travel.options.AccountTypeKeyValues;
037
038import javax.persistence.CascadeType;
039import javax.persistence.Column;
040import javax.persistence.Entity;
041import javax.persistence.FetchType;
042import javax.persistence.Id;
043import javax.persistence.ManyToOne;
044import javax.persistence.OneToMany;
045import javax.persistence.PrimaryKeyJoinColumn;
046import javax.persistence.Table;
047import javax.persistence.Temporal;
048import javax.persistence.TemporalType;
049import javax.persistence.Transient;
050import javax.validation.constraints.Size;
051import java.io.Serializable;
052import java.util.ArrayList;
053import java.util.Date;
054import java.util.List;
055
056@Entity
057@Table(name="TRV_ACCT")
058@UifAutoCreateViews({UifAutoCreateViewType.INQUIRY,UifAutoCreateViewType.LOOKUP})
059public class TravelAccount extends DataObjectBase implements Serializable {
060        private static final long serialVersionUID = -7739303391609093875L;
061
062        @Id
063        @Column(name="ACCT_NUM",length=10)
064        @Label("Travel Account Number")
065        @Description("Unique identifier for account")
066        @UifValidCharactersConstraintBeanName("AlphaNumericPatternConstraint")
067        private String number;
068
069        @Column(name="ACCT_NAME",length=40)
070        @Label("Travel Account Name")
071        @ForceUppercase
072        private String name;
073
074
075    @Column(name="ACCT_TYPE",length=3)
076    @Label("Travel Account Type Code")
077    @Description("Type code grouping for account")
078    @KeyValuesFinderClass(AccountTypeKeyValues.class)
079    @UifDisplayHints({
080        @UifDisplayHint(UifDisplayHintType.RADIO),
081        @UifDisplayHint(UifDisplayHintType.NO_LOOKUP_RESULT),
082        @UifDisplayHint(UifDisplayHintType.NO_INQUIRY)})
083    protected String accountTypeCode;
084
085    @ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.REFRESH})
086    @PrimaryKeyJoinColumn(name="ACCT_TYPE", referencedColumnName = "ACCT_TYPE")
087    @InheritProperty(name="codeAndDescription",displayHints=@UifDisplayHints(@UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA)))
088    private TravelAccountType accountType;
089
090    @Column(name="SUBSIDIZED_PCT",length=5,precision=2)
091    @UifDisplayHints(@UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA))
092        private KualiPercent subsidizedPercent;
093
094        @Temporal(TemporalType.TIMESTAMP)
095        @Column(name="CREATE_DT")
096        @Label("Date Created")
097        private Date createDate;
098
099    @Column(name="ACCT_FO_ID",length=40)
100    @Size(max=40)
101    @UifDisplayHints({@UifDisplayHint(UifDisplayHintType.HIDDEN), @UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA),
102        @UifDisplayHint(value=UifDisplayHintType.SECTION,id="fo",label="Fiscal Officer User ID")})
103        private String foId;
104
105    @Relationship(foreignKeyFields="foId")
106    @Transient
107    @InheritProperties({
108                @InheritProperty(name="principalName",label=@Label("Fiscal Officer")),
109                @InheritProperty(name="name",label=@Label("Fiscal Officer Name"),displayHints=@UifDisplayHints(@UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA)))
110    })
111        private Person fiscalOfficer;
112
113    @OneToMany(fetch=FetchType.EAGER, orphanRemoval=true, cascade= {CascadeType.ALL}, mappedBy = "account")
114    protected List<TravelSubAccount> subAccounts;
115
116    public String getName() {
117        return name;
118    }
119
120    public void setName(String name) {
121        this.name = name;
122    }
123
124    public String getNumber() {
125        return number;
126    }
127
128    public void setNumber(String number) {
129        this.number = number;
130    }
131
132    public Person getFiscalOfficer() {
133        if ((fiscalOfficer == null) || !StringUtils.equals(fiscalOfficer.getPrincipalId(), getFoId())) {
134            fiscalOfficer = KimApiServiceLocator.getPersonService().getPerson(getFoId());
135
136            if (fiscalOfficer == null) {
137                try {
138                    fiscalOfficer = KimApiServiceLocator.getPersonService().getPersonImplementationClass().newInstance();
139                } catch (Exception e) {
140                    throw new RuntimeException(e);
141                }
142            }
143        }
144
145        return fiscalOfficer;
146    }
147
148    public void setFiscalOfficer(Person fiscalOfficer) {
149        this.fiscalOfficer = fiscalOfficer;
150    }
151
152    public String getFoId() {
153        return foId;
154    }
155
156    public void setFoId(String foId) {
157        this.foId = foId;
158    }
159
160    public KualiPercent getSubsidizedPercent() {
161        return this.subsidizedPercent;
162    }
163
164    public void setSubsidizedPercent(KualiPercent subsidizedPercent) {
165        this.subsidizedPercent = subsidizedPercent;
166    }
167
168    public void setCreateDate(Date createDate) {
169        this.createDate = createDate;
170    }
171
172        public Date getCreateDate() {
173        return this.createDate;
174    }
175
176        public TravelAccountType getAccountType() {
177                return accountType;
178        }
179
180        public void setAccountType(TravelAccountType accountType) {
181                this.accountType = accountType;
182        }
183
184        public String getAccountTypeCode() {
185                return accountTypeCode;
186        }
187
188        public void setAccountTypeCode(String accountTypeCode) {
189                this.accountTypeCode = accountTypeCode;
190        }
191
192        public List<TravelSubAccount> getSubAccounts() {
193        if(subAccounts == null) {
194            subAccounts = new ArrayList<TravelSubAccount>();
195        }
196                return subAccounts;
197        }
198
199        public void setSubAccounts(List<TravelSubAccount> subAccounts) {
200                this.subAccounts = subAccounts;
201        }
202
203}