View Javadoc
1   /**
2    * Copyright 2005-2014 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.rice.krad.demo.travel.dataobject;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.util.type.KualiPercent;
20  import org.kuali.rice.kim.api.identity.Person;
21  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22  import org.kuali.rice.krad.bo.DataObjectBase;
23  import org.kuali.rice.krad.data.provider.annotation.Description;
24  import org.kuali.rice.krad.data.provider.annotation.ForceUppercase;
25  import org.kuali.rice.krad.data.provider.annotation.InheritProperties;
26  import org.kuali.rice.krad.data.provider.annotation.InheritProperty;
27  import org.kuali.rice.krad.data.provider.annotation.KeyValuesFinderClass;
28  import org.kuali.rice.krad.data.provider.annotation.Label;
29  import org.kuali.rice.krad.data.provider.annotation.Relationship;
30  import org.kuali.rice.krad.data.provider.annotation.UifAutoCreateViewType;
31  import org.kuali.rice.krad.data.provider.annotation.UifAutoCreateViews;
32  import org.kuali.rice.krad.data.provider.annotation.UifDisplayHint;
33  import org.kuali.rice.krad.data.provider.annotation.UifDisplayHintType;
34  import org.kuali.rice.krad.data.provider.annotation.UifDisplayHints;
35  import org.kuali.rice.krad.data.provider.annotation.UifValidCharactersConstraintBeanName;
36  import org.kuali.rice.krad.demo.travel.options.AccountTypeKeyValues;
37  
38  import javax.persistence.CascadeType;
39  import javax.persistence.Column;
40  import javax.persistence.Entity;
41  import javax.persistence.FetchType;
42  import javax.persistence.Id;
43  import javax.persistence.ManyToOne;
44  import javax.persistence.OneToMany;
45  import javax.persistence.PrimaryKeyJoinColumn;
46  import javax.persistence.Table;
47  import javax.persistence.Temporal;
48  import javax.persistence.TemporalType;
49  import javax.persistence.Transient;
50  import javax.validation.constraints.Size;
51  import java.io.Serializable;
52  import java.util.ArrayList;
53  import java.util.Date;
54  import java.util.List;
55  
56  @Entity
57  @Table(name="TRV_ACCT")
58  @UifAutoCreateViews({UifAutoCreateViewType.INQUIRY,UifAutoCreateViewType.LOOKUP})
59  public class TravelAccount extends DataObjectBase implements Serializable {
60  	private static final long serialVersionUID = -7739303391609093875L;
61  
62  	@Id
63  	@Column(name="ACCT_NUM",length=10)
64  	@Label("Travel Account Number")
65  	@Description("Unique identifier for account")
66  	@UifValidCharactersConstraintBeanName("AlphaNumericPatternConstraint")
67  	private String number;
68  
69  	@Column(name="ACCT_NAME",length=40)
70  	@Label("Travel Account Name")
71  	@ForceUppercase
72  	private String name;
73  
74  
75      @Column(name="ACCT_TYPE",length=3)
76      @Label("Travel Account Type Code")
77      @Description("Type code grouping for account")
78      @KeyValuesFinderClass(AccountTypeKeyValues.class)
79      @UifDisplayHints({
80      	@UifDisplayHint(UifDisplayHintType.RADIO),
81      	@UifDisplayHint(UifDisplayHintType.NO_LOOKUP_RESULT),
82      	@UifDisplayHint(UifDisplayHintType.NO_INQUIRY)})
83      protected String accountTypeCode;
84  
85      @ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.REFRESH})
86      @PrimaryKeyJoinColumn(name="ACCT_TYPE", referencedColumnName = "ACCT_TYPE")
87      @InheritProperty(name="codeAndDescription",displayHints=@UifDisplayHints(@UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA)))
88      private TravelAccountType accountType;
89  
90      @Column(name="SUBSIDIZED_PCT",length=5,precision=2)
91      @UifDisplayHints(@UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA))
92  	private KualiPercent subsidizedPercent;
93  
94  	@Temporal(TemporalType.TIMESTAMP)
95  	@Column(name="CREATE_DT")
96  	@Label("Date Created")
97  	private Date createDate;
98  
99      @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 }