001    /**
002     * Copyright 2005-2014 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 edu.sampleu.travel.document;
017    
018    import edu.sampleu.travel.bo.TravelAccount;
019    import org.kuali.rice.krad.document.SessionDocument;
020    import org.kuali.rice.krad.document.TransactionalDocumentBase;
021    
022    import javax.persistence.*;
023    import java.util.ArrayList;
024    import java.util.List;
025    
026    
027    @Entity
028    @Table(name="TRV_DOC_2")
029    public class TravelDocument2 extends TransactionalDocumentBase implements SessionDocument {
030    
031        @Column(name="traveler")
032        private String traveler;
033        @Column(name="org")
034        private String origin;
035        @Column(name="dest")
036        private String destination;
037        @Column(name="request_trav")
038        private String requestType;
039        @Transient
040        private String accountType;
041    
042        @ManyToMany(fetch = FetchType.EAGER)    // Do not use cascade here or it will try to update the TravelAccounts
043        @JoinTable(name="TRAV_DOC_2_ACCOUNTS", 
044                       joinColumns={@JoinColumn(name="fdoc_nbr", referencedColumnName="fdoc_nbr", unique=false)},         // Goes with this class: TravelDocument2
045                       inverseJoinColumns={@JoinColumn(name="acct_num", referencedColumnName="acct_num", unique=false)}   // Goes with that class: TravelAccount
046        )
047        private List<TravelAccount> travelAccounts;
048    
049        public TravelDocument2() {
050            travelAccounts = new ArrayList<TravelAccount>();
051        }
052    
053        public String getDestination() {
054            return destination;
055        }
056    
057        public void setDestination(String destination) {
058            this.destination = destination;
059        }
060    
061        public String getOrigin() {
062            return origin;
063        }
064    
065        public void setOrigin(String origin) {
066            this.origin = origin;
067        }
068    
069        public String getTraveler() {
070            return traveler;
071        }
072    
073        public void setTraveler(String traveler) {
074            this.traveler = traveler;
075        }
076    
077        public List<TravelAccount> getTravelAccounts() {
078            return travelAccounts;
079        }
080    
081        public void setTravelAccounts(List<TravelAccount> travelAccounts) {
082            this.travelAccounts = travelAccounts;
083        }
084    
085        public TravelAccount getTravelAccount(int index) {
086            while(travelAccounts.size() - 1 < index) {
087                travelAccounts.add(new TravelAccount());
088            }
089            return travelAccounts.get(index);
090        }
091    
092        public String getRequestType() {
093            return requestType;
094        }
095    
096        public void setRequestType(String requestType) {
097            this.requestType = requestType;
098        }
099    
100        /**
101         * @param accountType the accountType to set
102         */
103        public void setAccountType(String accountType) {
104            this.accountType = accountType;
105        }
106    
107        /**
108         * @return the accountType
109         */
110        public String getAccountType() {
111            return accountType;
112        }
113    
114    }