View Javadoc
1   /*
2    * Copyright 2007 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  
17  package org.kuali.ole.vnd.businessobject;
18  
19  import java.io.Serializable;
20  import java.util.LinkedHashMap;
21  import javax.persistence.CascadeType;
22  import javax.persistence.Column;
23  import javax.persistence.Convert;
24  import javax.persistence.Entity;
25  import javax.persistence.FetchType;
26  import javax.persistence.Id;
27  import javax.persistence.IdClass;
28  import javax.persistence.JoinColumn;
29  import javax.persistence.JoinColumns;
30  import javax.persistence.ManyToOne;
31  import javax.persistence.PrimaryKeyJoinColumn;
32  import javax.persistence.Table;
33  import org.apache.commons.lang.builder.CompareToBuilder;
34  import org.apache.commons.lang.builder.EqualsBuilder;
35  import org.apache.commons.lang.builder.HashCodeBuilder;
36  import org.apache.commons.lang.builder.ToStringBuilder;
37  import org.kuali.ole.coa.businessobject.Chart;
38  import org.kuali.ole.coa.businessobject.Organization;
39  import org.kuali.ole.vnd.businessobject.VendorContract;
40  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
41  import org.kuali.rice.core.api.util.type.KualiDecimal;
42  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
43  import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
44  import org.kuali.rice.krad.util.ObjectUtils;
45  
46  /**
47   * A relation between a particular <code>Org</code> and a <code>VendorContract</code> indicating that the Org uses this Vendor
48   * Contract.
49   * 
50   * @see org.kuali.ole.vnd.businessobject.VendorContract
51   * @see org.kuali.ole.coa.businessobject.Org
52   */
53  @Entity
54  @Table(name = "PUR_VNDR_CONTR_ORG_T")
55  @IdClass(VendorContractOrganization.VendorContractOrganizationId.class)
56  public class VendorContractOrganization extends PersistableBusinessObjectBase implements VendorRoutingComparable, MutableInactivatable {
57  
58      @Id
59      @Column(name = "VNDR_CONTR_GNRTD_ID")
60      private Integer vendorContractGeneratedIdentifier;
61  
62      @Id
63      @Column(name = "FIN_COA_CD")
64      private String chartOfAccountsCode;
65  
66      @Id
67      @Column(name = "ORG_CD")
68      private String organizationCode;
69  
70      @Column(name = "VNDR_CTRPO_LMT_AMT")
71      private KualiDecimal vendorContractPurchaseOrderLimitAmount;
72  
73      @Column(name = "VNDR_CONTR_EXCL_IND")
74      @Convert(converter = BooleanYNConverter.class)
75      private boolean vendorContractExcludeIndicator;
76  
77      @Column(name = "DOBJ_MAINT_CD_ACTV_IND")
78      @Convert(converter = BooleanYNConverter.class)
79      private boolean active;
80  
81      @ManyToOne(targetEntity = VendorContract.class, fetch = FetchType.LAZY, cascade = { CascadeType.REFRESH })
82      @JoinColumn(name = "VNDR_CONTR_GNRTD_ID", referencedColumnName = "VNDR_CONTR_GNRTD_ID", insertable = false, updatable = false)
83      private VendorContract vendorContract;
84  
85      @ManyToOne(targetEntity = Organization.class, fetch = FetchType.LAZY, cascade = { CascadeType.REFRESH })
86      /*
87  FIXME: JPA_CONVERSION
88  For compound primary keys, make sure the join columns are in the correct order.
89  */
90      @JoinColumns({ @JoinColumn(name = "FIN_COA_CD", referencedColumnName = "FIN_COA_CD", insertable = false, updatable = false), @JoinColumn(name = "ORG_CD", referencedColumnName = "ORG_CD", insertable = false, updatable = false) })
91      private Organization organization;
92  
93      @ManyToOne(targetEntity = Chart.class, fetch = FetchType.LAZY, cascade = { CascadeType.REFRESH })
94      @JoinColumn(name = "FIN_COA_CD", referencedColumnName = "FIN_COA_CD", insertable = false, updatable = false)
95      private Chart chartOfAccounts;
96  
97      /**
98       * Default constructor.
99       */
100     public VendorContractOrganization() {
101 
102     }
103 
104     public Integer getVendorContractGeneratedIdentifier() {
105 
106         return vendorContractGeneratedIdentifier;
107     }
108 
109     public void setVendorContractGeneratedIdentifier(Integer vendorContractGeneratedIdentifier) {
110         this.vendorContractGeneratedIdentifier = vendorContractGeneratedIdentifier;
111     }
112 
113     public String getChartOfAccountsCode() {
114 
115         return chartOfAccountsCode;
116     }
117 
118     public void setChartOfAccountsCode(String chartOfAccountsCode) {
119         this.chartOfAccountsCode = chartOfAccountsCode;
120     }
121 
122     public String getOrganizationCode() {
123 
124         return organizationCode;
125     }
126 
127     public void setOrganizationCode(String organizationCode) {
128         this.organizationCode = organizationCode;
129     }
130 
131     public KualiDecimal getVendorContractPurchaseOrderLimitAmount() {
132 
133         return vendorContractPurchaseOrderLimitAmount;
134     }
135 
136     public void setVendorContractPurchaseOrderLimitAmount(KualiDecimal vendorContractPurchaseOrderLimitAmount) {
137         this.vendorContractPurchaseOrderLimitAmount = vendorContractPurchaseOrderLimitAmount;
138     }
139 
140     public boolean isVendorContractExcludeIndicator() {
141 
142         return vendorContractExcludeIndicator;
143     }
144 
145     public void setVendorContractExcludeIndicator(boolean vendorContractExcludeIndicator) {
146         this.vendorContractExcludeIndicator = vendorContractExcludeIndicator;
147     }
148 
149     public boolean isActive() {
150 
151         return active;
152     }
153 
154     public void setActive(boolean active) {
155         this.active = active;
156     }
157 
158     public Organization getOrganization() {
159 
160         return organization;
161     }
162 
163     /**
164      * Sets the organization attribute.
165      * 
166      * @param organization The organization to set.
167      * @deprecated
168      */
169     public void setOrganization(Organization organization) {
170         this.organization = organization;
171     }
172 
173     public Chart getChartOfAccounts() {
174 
175         return chartOfAccounts;
176     }
177 
178     /**
179      * Sets the chartOfAccounts attribute.
180      * 
181      * @param chartOfAccounts The chartOfAccounts to set.
182      * @deprecated
183      */
184     public void setChartOfAccounts(Chart chartOfAccounts) {
185         this.chartOfAccounts = chartOfAccounts;
186     }
187 
188     public VendorContract getVendorContract() {
189 
190         return vendorContract;
191     }
192 
193     /**
194      * Sets the vendorContract attribute value.
195      * 
196      * @param vendorContract The vendorContract to set.
197      * @deprecated
198      */
199     public void setVendorContract(VendorContract vendorContract) {
200         this.vendorContract = vendorContract;
201     }
202 
203     /**
204      * @see org.kuali.ole.vnd.document.routing.VendorRoutingComparable#isEqualForRouting(java.lang.Object)
205      */
206     public boolean isEqualForRouting(Object toCompare) {
207         if ((ObjectUtils.isNull(toCompare)) || !(toCompare instanceof VendorContractOrganization)) {
208 
209             return false;
210         }
211         else {
212             VendorContractOrganization vco = (VendorContractOrganization) toCompare;
213 
214             return new EqualsBuilder().append(this.getVendorContractGeneratedIdentifier(), vco.getVendorContractGeneratedIdentifier()).append(this.getChartOfAccountsCode(), vco.getChartOfAccountsCode()).append(this.getOrganizationCode(), vco.getOrganizationCode()).append(this.getVendorContractPurchaseOrderLimitAmount(), vco.getVendorContractPurchaseOrderLimitAmount()).append(this.isVendorContractExcludeIndicator(), vco.isVendorContractExcludeIndicator()).isEquals();
215         }
216     }
217 
218     /**
219      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
220      */
221     protected LinkedHashMap toStringMapper() {
222         LinkedHashMap m = new LinkedHashMap();
223         if (this.vendorContractGeneratedIdentifier != null) {
224             m.put("vendorContractGeneratedIdentifier", this.vendorContractGeneratedIdentifier.toString());
225         }
226         m.put("chartOfAccountsCode", this.chartOfAccountsCode);
227         m.put("organizationCode", this.organizationCode);
228 
229         return m;
230     }
231 
232     public static final class VendorContractOrganizationId implements Serializable, Comparable<VendorContractOrganizationId> {
233 
234         private Integer vendorContractGeneratedIdentifier;
235 
236         private String chartOfAccountsCode;
237 
238         private String organizationCode;
239 
240         public Integer getVendorContractGeneratedIdentifier() {
241             return this.vendorContractGeneratedIdentifier;
242         }
243 
244         public void setVendorContractGeneratedIdentifier(Integer vendorContractGeneratedIdentifier) {
245             this.vendorContractGeneratedIdentifier = vendorContractGeneratedIdentifier;
246         }
247 
248         public String getChartOfAccountsCode() {
249             return this.chartOfAccountsCode;
250         }
251 
252         public void setChartOfAccountsCode(String chartOfAccountsCode) {
253             this.chartOfAccountsCode = chartOfAccountsCode;
254         }
255 
256         public String getOrganizationCode() {
257             return this.organizationCode;
258         }
259 
260         public void setOrganizationCode(String organizationCode) {
261             this.organizationCode = organizationCode;
262         }
263 
264         @Override
265         public String toString() {
266             return new ToStringBuilder(this).append("vendorContractGeneratedIdentifier", this.vendorContractGeneratedIdentifier).append("chartOfAccountsCode", this.chartOfAccountsCode).append("organizationCode", this.organizationCode).toString();
267         }
268 
269         @Override
270         public boolean equals(Object other) {
271             if (other == null)
272                 return false;
273             if (other == this)
274                 return true;
275             if (other.getClass() != this.getClass())
276                 return false;
277             final VendorContractOrganizationId rhs = (VendorContractOrganizationId) other;
278             return new EqualsBuilder().append(this.vendorContractGeneratedIdentifier, rhs.vendorContractGeneratedIdentifier).append(this.chartOfAccountsCode, rhs.chartOfAccountsCode).append(this.organizationCode, rhs.organizationCode).isEquals();
279         }
280 
281         @Override
282         public int hashCode() {
283             return new HashCodeBuilder(17, 37).append(this.vendorContractGeneratedIdentifier).append(this.chartOfAccountsCode).append(this.organizationCode).toHashCode();
284         }
285 
286         @Override
287         public int compareTo(VendorContractOrganizationId other) {
288             return new CompareToBuilder().append(this.vendorContractGeneratedIdentifier, other.vendorContractGeneratedIdentifier).append(this.chartOfAccountsCode, other.chartOfAccountsCode).append(this.organizationCode, other.organizationCode).toComparison();
289         }
290     }
291 }