View Javadoc

1   /*
2    * Copyright 2007-2008 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 edu.sampleu.travel.document;
17  
18  import java.util.ArrayList;
19  import java.util.LinkedHashMap;
20  import java.util.List;
21  
22  import javax.persistence.Column;
23  import javax.persistence.Entity;
24  import javax.persistence.FetchType;
25  import javax.persistence.JoinColumn;
26  import javax.persistence.JoinTable;
27  import javax.persistence.ManyToMany;
28  import javax.persistence.Table;
29  import javax.persistence.Transient;
30  
31  import org.kuali.rice.kns.document.SessionDocument;
32  import org.kuali.rice.kns.document.TransactionalDocumentBase;
33  
34  import edu.sampleu.travel.bo.TravelAccount;
35  
36  
37  @Entity
38  @Table(name="TRV_DOC_2")
39  public class TravelDocument2 extends TransactionalDocumentBase implements SessionDocument {
40  
41      @Column(name="traveler")
42      private String traveler;
43      @Column(name="org")
44      private String origin;
45      @Column(name="dest")
46      private String destination;
47      @Column(name="request_trav")
48      private String requestType;
49      @Transient
50      private String accountType;
51  
52      @ManyToMany(fetch = FetchType.EAGER)    // Do not use cascade here or it will try to update the TravelAccounts
53      @JoinTable(name="TRAV_DOC_2_ACCOUNTS", 
54  	           joinColumns={@JoinColumn(name="fdoc_nbr", referencedColumnName="fdoc_nbr", unique=false)},         // Goes with this class: TravelDocument2
55  	           inverseJoinColumns={@JoinColumn(name="acct_num", referencedColumnName="acct_num", unique=false)}   // Goes with that class: TravelAccount
56      )
57      private List<TravelAccount> travelAccounts;
58  
59      public TravelDocument2() {
60          travelAccounts = new ArrayList<TravelAccount>();
61      }
62  
63      @Override
64      protected LinkedHashMap toStringMapper() {
65          LinkedHashMap<String, String> meMap = new LinkedHashMap<String, String>();
66          meMap.put("traveler", getTraveler());
67          meMap.put("origin", getOrigin());
68          meMap.put("destination", getDestination());
69          return meMap;
70      }
71  
72      public String getDestination() {
73          return destination;
74      }
75  
76      public void setDestination(String destination) {
77          this.destination = destination;
78      }
79  
80      public String getOrigin() {
81          return origin;
82      }
83  
84      public void setOrigin(String origin) {
85          this.origin = origin;
86      }
87  
88      public String getTraveler() {
89          return traveler;
90      }
91  
92      public void setTraveler(String traveler) {
93          this.traveler = traveler;
94      }
95  
96      public List<TravelAccount> getTravelAccounts() {
97          return travelAccounts;
98      }
99  
100     public void setTravelAccounts(List<TravelAccount> travelAccounts) {
101         this.travelAccounts = travelAccounts;
102     }
103 
104     public TravelAccount getTravelAccount(int index) {
105         while(travelAccounts.size() - 1 < index) {
106             travelAccounts.add(new TravelAccount());
107         }
108         return travelAccounts.get(index);
109     }
110 
111     public String getRequestType() {
112         return requestType;
113     }
114 
115     public void setRequestType(String requestType) {
116         this.requestType = requestType;
117     }
118 
119     /**
120      * @param accountType the accountType to set
121      */
122     public void setAccountType(String accountType) {
123         this.accountType = accountType;
124     }
125 
126     /**
127      * @return the accountType
128      */
129     public String getAccountType() {
130         return accountType;
131     }
132 
133 }