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.util.ArrayList;
20  import java.util.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.apache.commons.lang.builder.EqualsBuilder;
26  import org.apache.log4j.Logger;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.ole.vnd.document.service.VendorService;
29  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
30  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
31  import org.kuali.rice.krad.service.KualiModuleService;
32  import org.kuali.rice.krad.service.ModuleService;
33  import org.kuali.rice.krad.util.ObjectUtils;
34  import org.kuali.rice.location.api.LocationConstants;
35  import org.kuali.rice.location.framework.country.CountryEbo;
36  import org.kuali.rice.location.framework.state.StateEbo;
37  
38  /**
39   * Address to be associated with a particular Vendor.
40   */
41  public class VendorAddress extends PersistableBusinessObjectBase implements VendorRoutingComparable, MutableInactivatable {
42      private static final Logger LOG = Logger.getLogger(VendorAddress.class);
43  
44      protected Integer vendorAddressGeneratedIdentifier;
45      protected Integer vendorHeaderGeneratedIdentifier;
46      protected Integer vendorDetailAssignedIdentifier;
47      protected String vendorAddressTypeCode;
48      protected String vendorLine1Address;
49      protected String vendorLine2Address;
50      protected String vendorCityName;
51      protected String vendorStateCode;
52      protected String vendorZipCode;
53      protected String vendorCountryCode;
54      protected String vendorAttentionName;
55      protected String vendorAddressInternationalProvinceName;
56      protected String vendorAddressEmailAddress;
57      protected String vendorBusinessToBusinessUrlAddress;
58      protected String vendorFaxNumber;
59      protected boolean vendorDefaultAddressIndicator;
60      protected String vendorAddressNote;
61      protected boolean active;
62  
63  
64      protected List<VendorDefaultAddress> vendorDefaultAddresses;
65  
66  
67      protected VendorDetail vendorDetail;
68  
69  
70      protected AddressType vendorAddressType;
71      protected StateEbo vendorState;
72      protected CountryEbo vendorCountry;
73  
74  
75       /**
76       * Default constructor.
77       */
78      public VendorAddress() {
79          vendorDefaultAddresses = new ArrayList<VendorDefaultAddress>();
80      }
81  
82      public Integer getVendorAddressGeneratedIdentifier() {
83          return vendorAddressGeneratedIdentifier;
84      }
85  
86      public void setVendorAddressGeneratedIdentifier(Integer vendorAddressGeneratedIdentifier) {
87          this.vendorAddressGeneratedIdentifier = vendorAddressGeneratedIdentifier;
88      }
89  
90      public Integer getVendorHeaderGeneratedIdentifier() {
91          return vendorHeaderGeneratedIdentifier;
92      }
93  
94      public void setVendorHeaderGeneratedIdentifier(Integer vendorHeaderGeneratedIdentifier) {
95          this.vendorHeaderGeneratedIdentifier = vendorHeaderGeneratedIdentifier;
96      }
97  
98      public Integer getVendorDetailAssignedIdentifier() {
99          return vendorDetailAssignedIdentifier;
100     }
101 
102     public void setVendorDetailAssignedIdentifier(Integer vendorDetailAssignedIdentifier) {
103         this.vendorDetailAssignedIdentifier = vendorDetailAssignedIdentifier;
104     }
105 
106     public String getVendorAddressInternationalProvinceName() {
107         return vendorAddressInternationalProvinceName;
108     }
109 
110     public void setVendorAddressInternationalProvinceName(String vendorAddressInternationalProvinceName) {
111         this.vendorAddressInternationalProvinceName = vendorAddressInternationalProvinceName;
112     }
113 
114     public String getVendorAddressEmailAddress() {
115         return vendorAddressEmailAddress;
116     }
117 
118     public void setVendorAddressEmailAddress(String vendorAddressEmailAddress) {
119         this.vendorAddressEmailAddress = vendorAddressEmailAddress;
120     }
121 
122     public String getVendorAddressTypeCode() {
123         return vendorAddressTypeCode;
124     }
125 
126     public void setVendorAddressTypeCode(String vendorAddressTypeCode) {
127         this.vendorAddressTypeCode = vendorAddressTypeCode;
128     }
129 
130     public String getVendorLine1Address() {
131         return vendorLine1Address;
132     }
133 
134     public void setVendorLine1Address(String vendorLine1Address) {
135         this.vendorLine1Address = vendorLine1Address;
136     }
137 
138     public String getVendorLine2Address() {
139         return vendorLine2Address;
140     }
141 
142     public void setVendorLine2Address(String vendorLine2Address) {
143         this.vendorLine2Address = vendorLine2Address;
144     }
145 
146     public String getVendorCityName() {
147         return vendorCityName;
148     }
149 
150     public void setVendorCityName(String vendorCityName) {
151         this.vendorCityName = vendorCityName;
152     }
153 
154     public String getVendorStateCode() {
155         return vendorStateCode;
156     }
157 
158     public void setVendorStateCode(String vendorStateCode) {
159         this.vendorStateCode = vendorStateCode;
160     }
161 
162     public String getVendorZipCode() {
163         return vendorZipCode;
164     }
165 
166     public void setVendorZipCode(String vendorZipCode) {
167         this.vendorZipCode = vendorZipCode;
168     }
169 
170     public String getVendorCountryCode() {
171         return vendorCountryCode;
172     }
173 
174     public void setVendorCountryCode(String vendorCountryCode) {
175         this.vendorCountryCode = vendorCountryCode;
176     }
177 
178     public String getVendorAttentionName() {
179         return vendorAttentionName;
180     }
181 
182     public void setVendorAttentionName(String vendorAttentionName) {
183         this.vendorAttentionName = vendorAttentionName;
184     }
185 
186     public String getVendorBusinessToBusinessUrlAddress() {
187         return vendorBusinessToBusinessUrlAddress;
188     }
189 
190     public void setVendorBusinessToBusinessUrlAddress(String vendorBusinessToBusinessUrlAddress) {
191         this.vendorBusinessToBusinessUrlAddress = vendorBusinessToBusinessUrlAddress;
192     }
193 
194     public VendorDetail getVendorDetail() {
195         return vendorDetail;
196     }
197 
198     /**
199      * Sets the vendorDetail attribute.
200      *
201      * @param vendorDetail The vendorDetail to set.
202      * @deprecated
203      */
204     @Deprecated
205     public void setVendorDetail(VendorDetail vendorDetail) {
206         this.vendorDetail = vendorDetail;
207     }
208 
209     public AddressType getVendorAddressType() {
210         return vendorAddressType;
211     }
212 
213     /**
214      * Sets the vendorAddressType attribute.
215      *
216      * @param vendorAddressType The vendorAddressType to set.
217      * @deprecated
218      */
219     @Deprecated
220     public void setVendorAddressType(AddressType vendorAddressType) {
221         this.vendorAddressType = vendorAddressType;
222     }
223 
224     public StateEbo getVendorState() {
225         if ( StringUtils.isBlank(vendorStateCode) || StringUtils.isBlank(vendorCountryCode ) ) {
226             vendorState = null;
227         } else {
228             if ( ObjectUtils.isNull(vendorState) || !StringUtils.equals( vendorState.getCode(),vendorStateCode) || !StringUtils.equals(vendorState.getCountryCode(), vendorCountryCode ) ) {
229                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(StateEbo.class);
230                 if ( moduleService != null ) {
231                     Map<String,Object> keys = new HashMap<String, Object>(2);
232                     keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, vendorCountryCode);
233                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, vendorStateCode);
234                     vendorState = moduleService.getExternalizableBusinessObject(StateEbo.class, keys);
235                 } else {
236                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
237                 }
238             }
239         }
240         return vendorState;
241     }
242 
243     /**
244      * Sets the vendorState attribute.
245      *
246      * @param vendorState The vendorState to set.
247      * @deprecated
248      */
249     @Deprecated
250     public void setVendorState(StateEbo vendorState) {
251         this.vendorState = vendorState;
252     }
253 
254     public CountryEbo getVendorCountry() {
255         if ( StringUtils.isBlank(vendorCountryCode) ) {
256             vendorCountry = null;
257         } else {
258             if ( vendorCountry == null || !StringUtils.equals( vendorCountry.getCode(),vendorCountryCode) ) {
259                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CountryEbo.class);
260                 if ( moduleService != null ) {
261                     Map<String,Object> keys = new HashMap<String, Object>(1);
262                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, vendorCountryCode);
263                     vendorCountry = moduleService.getExternalizableBusinessObject(CountryEbo.class, keys);
264                 } else {
265                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
266                 }
267             }
268         }
269         return vendorCountry;
270     }
271 
272     /**
273      * Sets the vendorCountry attribute.
274      *
275      * @param vendorCountry The vendorCountry to set.
276      * @deprecated
277      */
278     @Deprecated
279     public void setVendorCountry(CountryEbo vendorCountry) {
280         this.vendorCountry = vendorCountry;
281     }
282 
283     /**
284      * Gets the vendorFaxNumber attribute.
285      *
286      * @return Returns the vendorFaxNumber.
287      */
288     public String getVendorFaxNumber() {
289         return vendorFaxNumber;
290     }
291 
292     /**
293      * Sets the vendorFaxNumber attribute value.
294      *
295      * @param vendorFaxNumber The vendorFaxNumber to set.
296      */
297     public void setVendorFaxNumber(String vendorFaxNumber) {
298         this.vendorFaxNumber = vendorFaxNumber;
299     }
300 
301     /**
302      * Gets the vendorDefaultAddressIndicator attribute.
303      *
304      * @return Returns the vendorDefaultAddressIndicator.
305      */
306     public boolean isVendorDefaultAddressIndicator() {
307         return vendorDefaultAddressIndicator;
308     }
309 
310     /**
311      * Sets the vendorDefaultAddressIndicator attribute value.
312      *
313      * @param vendorDefaultAddressIndicator The vendorDefaultAddressIndicator to set.
314      */
315     public void setVendorDefaultAddressIndicator(boolean vendorDefaultAddressIndicator) {
316         this.vendorDefaultAddressIndicator = vendorDefaultAddressIndicator;
317     }
318 
319     @Override
320     public boolean isActive() {
321         return active;
322     }
323 
324     @Override
325     public void setActive(boolean active) {
326         this.active = active;
327     }
328 
329     public List<VendorDefaultAddress> getVendorDefaultAddresses() {
330         return vendorDefaultAddresses;
331     }
332 
333     public void setVendorDefaultAddresses(List<VendorDefaultAddress> vendorDefaultAddresses) {
334         this.vendorDefaultAddresses = vendorDefaultAddresses;
335     }
336 
337     /**
338      * @see org.kuali.ole.vnd.document.routing.VendorRoutingComparable#isEqualForRouting(java.lang.Object)
339      */
340     @Override
341     public boolean isEqualForRouting(Object toCompare) {
342         LOG.debug("Entering isEqualForRouting.");
343         if ((ObjectUtils.isNull(toCompare)) || !(toCompare instanceof VendorAddress)) {
344             LOG.debug("Exiting isEqualForRouting");
345             return false;
346         }
347         else {
348             VendorAddress va = (VendorAddress) toCompare;
349             boolean eq = new EqualsBuilder().append(this.getVendorAddressGeneratedIdentifier(), va.getVendorAddressGeneratedIdentifier()).append(this.getVendorHeaderGeneratedIdentifier(), va.getVendorHeaderGeneratedIdentifier()).append(this.getVendorDetailAssignedIdentifier(), va.getVendorDetailAssignedIdentifier()).append(this.getVendorAddressTypeCode(), va.getVendorAddressTypeCode()).append(this.getVendorLine1Address(), va.getVendorLine1Address()).append(this.getVendorLine2Address(), va.getVendorLine2Address()).append(this.getVendorCityName(), va.getVendorCityName()).append(this.getVendorStateCode(), va.getVendorStateCode()).append(this.getVendorZipCode(), va.getVendorZipCode()).append(this.getVendorCountryCode(), va.getVendorCountryCode()).append(this.getVendorAttentionName(), va.getVendorAttentionName()).append(this.getVendorAddressInternationalProvinceName(), va.getVendorAddressInternationalProvinceName()).append(this.getVendorAddressEmailAddress(),
350                     va.getVendorAddressEmailAddress()).append(this.getVendorBusinessToBusinessUrlAddress(), va.getVendorBusinessToBusinessUrlAddress()).append(this.getVendorFaxNumber(), va.getVendorFaxNumber()).append(this.isVendorDefaultAddressIndicator(), va.isVendorDefaultAddressIndicator()).isEquals();
351             eq &= SpringContext.getBean(VendorService.class).equalMemberLists(this.getVendorDefaultAddresses(), va.getVendorDefaultAddresses());
352             LOG.debug("Exiting isEqualForRouting.");
353             return eq;
354         }
355     }
356 
357     public String getVendorAddressNote() {
358         return vendorAddressNote;
359     }
360 
361     public void setVendorAddressNote(String vendorAddressNote) {
362         this.vendorAddressNote = vendorAddressNote;
363     }
364 
365 
366 
367 
368 
369  }