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.kuali.rice.core.api.util.type.KualiPercent;
19  import org.kuali.rice.kim.api.identity.Person;
20  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
21  import org.kuali.rice.krad.bo.DataObjectBase;
22  import org.kuali.rice.krad.data.provider.annotation.Description;
23  import org.kuali.rice.krad.data.provider.annotation.ForceUppercase;
24  import org.kuali.rice.krad.data.provider.annotation.InheritProperties;
25  import org.kuali.rice.krad.data.provider.annotation.InheritProperty;
26  import org.kuali.rice.krad.data.provider.annotation.KeyValuesFinderClass;
27  import org.kuali.rice.krad.data.provider.annotation.Label;
28  import org.kuali.rice.krad.data.provider.annotation.Relationship;
29  import org.kuali.rice.krad.data.provider.annotation.UifAutoCreateViewType;
30  import org.kuali.rice.krad.data.provider.annotation.UifAutoCreateViews;
31  import org.kuali.rice.krad.data.provider.annotation.UifDisplayHint;
32  import org.kuali.rice.krad.data.provider.annotation.UifDisplayHintType;
33  import org.kuali.rice.krad.data.provider.annotation.UifDisplayHints;
34  import org.kuali.rice.krad.data.provider.annotation.UifValidCharactersConstraintBeanName;
35  import org.kuali.rice.krad.demo.travel.options.AccountTypeKeyValues;
36  
37  import javax.persistence.CascadeType;
38  import javax.persistence.Column;
39  import javax.persistence.Entity;
40  import javax.persistence.FetchType;
41  import javax.persistence.Id;
42  import javax.persistence.ManyToOne;
43  import javax.persistence.OneToMany;
44  import javax.persistence.PrimaryKeyJoinColumn;
45  import javax.persistence.Table;
46  import javax.persistence.Temporal;
47  import javax.persistence.TemporalType;
48  import javax.persistence.Transient;
49  import javax.validation.constraints.Size;
50  import java.io.Serializable;
51  import java.util.ArrayList;
52  import java.util.Date;
53  import java.util.List;
54  
55  @Entity
56  @Table(name="TRV_ACCT")
57  @UifAutoCreateViews({UifAutoCreateViewType.INQUIRY,UifAutoCreateViewType.LOOKUP})
58  public class TravelAccount extends DataObjectBase implements Serializable {
59  	private static final long serialVersionUID = -7739303391609093875L;
60  
61  	@Id
62  	@Column(name="ACCT_NUM",length=10)
63  	@Label("Travel Account Number")
64  	@Description("Unique identifier for account")
65  	@UifValidCharactersConstraintBeanName("AlphaNumericPatternConstraint")
66  	private String number;
67  
68  	@Column(name="ACCT_NAME",length=40)
69  	@Label("Travel Account Name")
70  	@ForceUppercase
71  	private String name;
72  
73  
74      @Column(name="ACCT_TYPE",length=3)
75      @Label("Travel Account Type Code")
76      @Description("Type code grouping for account")
77      @KeyValuesFinderClass(AccountTypeKeyValues.class)
78      @UifDisplayHints({
79      	@UifDisplayHint(UifDisplayHintType.RADIO),
80      	@UifDisplayHint(UifDisplayHintType.NO_LOOKUP_RESULT),
81      	@UifDisplayHint(UifDisplayHintType.NO_INQUIRY)})
82      protected String accountTypeCode;
83  
84      @ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.REFRESH})
85      @PrimaryKeyJoinColumn(name="ACCT_TYPE", referencedColumnName = "ACCT_TYPE")
86      @InheritProperty(name="codeAndDescription",displayHints=@UifDisplayHints(@UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA)))
87      private TravelAccountType accountType;
88  
89      @Column(name="SUBSIDIZED_PCT",length=5,precision=2)
90      @UifDisplayHints(@UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA))
91  	private KualiPercent subsidizedPercent;
92  
93  	@Temporal(TemporalType.TIMESTAMP)
94  	@Column(name="CREATE_DT")
95  	@Label("Date Created")
96  	private Date createDate;
97  
98      @Column(name="ACCT_FO_ID",length=40)
99      @Size(max=40)
100     @UifDisplayHints({@UifDisplayHint(UifDisplayHintType.HIDDEN),
101     	@UifDisplayHint(value=UifDisplayHintType.SECTION,id="fo",label="Fiscal Officer User ID")})
102 	private String foId;
103 
104     @Relationship(foreignKeyFields="foId")
105     @Transient
106     @InheritProperties({
107     		@InheritProperty(name="principalName",label=@Label("Fiscal Officer")),
108     		@InheritProperty(name="name",label=@Label("Fiscal Officer Name"),displayHints=@UifDisplayHints(@UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA)))
109     })
110 	private Person fiscalOfficer;
111 
112     @OneToMany(fetch=FetchType.EAGER, orphanRemoval=true, cascade= {CascadeType.ALL}, mappedBy = "account")
113     protected List<TravelSubAccount> subAccounts;
114 
115     public String getName() {
116         return name;
117     }
118 
119     public void setName(String name) {
120         this.name = name;
121     }
122 
123     public String getNumber() {
124         return number;
125     }
126 
127     public void setNumber(String number) {
128         this.number = number;
129     }
130 
131     public Person getFiscalOfficer() {
132     	fiscalOfficer = KimApiServiceLocator.getPersonService().updatePersonIfNecessary(foId, fiscalOfficer);
133         return fiscalOfficer;
134     }
135 
136     public String getFoId() {
137         return foId;
138     }
139 
140     public void setFoId(String foId) {
141         this.foId = foId;
142     }
143 
144     public KualiPercent getSubsidizedPercent() {
145         return this.subsidizedPercent;
146     }
147 
148     public void setSubsidizedPercent(KualiPercent subsidizedPercent) {
149         this.subsidizedPercent = subsidizedPercent;
150     }
151 
152     public void setCreateDate(Date createDate) {
153         this.createDate = createDate;
154     }
155 
156 	public Date getCreateDate() {
157         return this.createDate;
158     }
159 
160 	public TravelAccountType getAccountType() {
161 		return accountType;
162 	}
163 
164 	public void setAccountType(TravelAccountType accountType) {
165 		this.accountType = accountType;
166 	}
167 
168 	public String getAccountTypeCode() {
169 		return accountTypeCode;
170 	}
171 
172 	public void setAccountTypeCode(String accountTypeCode) {
173 		this.accountTypeCode = accountTypeCode;
174 	}
175 
176 	public List<TravelSubAccount> getSubAccounts() {
177         if(subAccounts == null) {
178             subAccounts = new ArrayList<TravelSubAccount>();
179         }
180 		return subAccounts;
181 	}
182 
183 	public void setSubAccounts(List<TravelSubAccount> subAccounts) {
184 		this.subAccounts = subAccounts;
185 	}
186 
187 }