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