001    /*
002     * Copyright 2011 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 org.kuali.kfs.module.ar.businessobject;
017    
018    import java.sql.Date;
019    import java.util.LinkedHashMap;
020    
021    import org.apache.ojb.broker.PersistenceBroker;
022    import org.apache.ojb.broker.PersistenceBrokerException;
023    import org.kuali.kfs.module.ar.document.service.CustomerAddressService;
024    import org.kuali.rice.kns.bo.Country;
025    import org.kuali.kfs.sys.context.SpringContext;
026    import org.kuali.rice.kns.service.CountryService;
027    import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
028    
029    /**
030     * @author Kuali Nervous System Team (kualidev@oncourse.iu.edu)
031     */
032    public class CustomerAddress extends PersistableBusinessObjectBase implements Comparable<CustomerAddress> {
033    
034        private String customerNumber;
035        private Integer customerAddressIdentifier;
036        private String customerAddressName;
037        private String customerLine1StreetAddress;
038        private String customerLine2StreetAddress;
039        private String customerCityName;
040        private String customerStateCode;
041        private String customerZipCode;
042        private String customerCountryCode;
043        private String customerAddressInternationalProvinceName;
044        private String customerInternationalMailCode;
045        private String customerEmailAddress;
046        private String customerAddressTypeCode;
047        private Date customerAddressEndDate;
048    
049        private CustomerAddressType customerAddressType;
050        private Customer customer;
051        private Country customerCountry;
052    
053        /**
054         * Default constructor.
055         */
056        public CustomerAddress() {
057    
058        }
059    
060        /**
061         * Gets the customerNumber attribute.
062         * 
063         * @return Returns the customerNumber
064         */
065        public String getCustomerNumber() {
066            return customerNumber;
067        }
068    
069        /**
070         * Sets the customerNumber attribute.
071         * 
072         * @param customerNumber The customerNumber to set.
073         */
074        public void setCustomerNumber(String customerNumber) {
075            this.customerNumber = customerNumber;
076        }
077    
078    
079        /**
080         * Gets the customerAddressIdentifier attribute.
081         * 
082         * @return Returns the customerAddressIdentifier
083         */
084        public Integer getCustomerAddressIdentifier() {
085            return customerAddressIdentifier;
086        }
087    
088        /**
089         * Sets the customerAddressIdentifier attribute.
090         * 
091         * @param customerAddressIdentifier The customerAddressIdentifier to set.
092         */
093        public void setCustomerAddressIdentifier(Integer customerAddressIdentifier) {
094            this.customerAddressIdentifier = customerAddressIdentifier;
095        }
096    
097    
098        /**
099         * Gets the customerAddressName attribute.
100         * 
101         * @return Returns the customerAddressName
102         */
103        public String getCustomerAddressName() {
104            return customerAddressName;
105        }
106    
107        /**
108         * Sets the customerAddressName attribute.
109         * 
110         * @param customerAddressName The customerAddressName to set.
111         */
112        public void setCustomerAddressName(String customerAddressName) {
113            this.customerAddressName = customerAddressName;
114        }
115    
116    
117        /**
118         * Gets the customerLine1StreetAddress attribute.
119         * 
120         * @return Returns the customerLine1StreetAddress
121         */
122        public String getCustomerLine1StreetAddress() {
123            return customerLine1StreetAddress;
124        }
125    
126        /**
127         * Sets the customerLine1StreetAddress attribute.
128         * 
129         * @param customerLine1StreetAddress The customerLine1StreetAddress to set.
130         */
131        public void setCustomerLine1StreetAddress(String customerLine1StreetAddress) {
132            this.customerLine1StreetAddress = customerLine1StreetAddress;
133        }
134    
135    
136        /**
137         * Gets the customerLine2StreetAddress attribute.
138         * 
139         * @return Returns the customerLine2StreetAddress
140         */
141        public String getCustomerLine2StreetAddress() {
142            return customerLine2StreetAddress;
143        }
144    
145        /**
146         * Sets the customerLine2StreetAddress attribute.
147         * 
148         * @param customerLine2StreetAddress The customerLine2StreetAddress to set.
149         */
150        public void setCustomerLine2StreetAddress(String customerLine2StreetAddress) {
151            this.customerLine2StreetAddress = customerLine2StreetAddress;
152        }
153    
154    
155        /**
156         * Gets the customerCityName attribute.
157         * 
158         * @return Returns the customerCityName
159         */
160        public String getCustomerCityName() {
161            return customerCityName;
162        }
163    
164        /**
165         * Sets the customerCityName attribute.
166         * 
167         * @param customerCityName The customerCityName to set.
168         */
169        public void setCustomerCityName(String customerCityName) {
170            this.customerCityName = customerCityName;
171        }
172    
173    
174        /**
175         * Gets the customerStateCode attribute.
176         * 
177         * @return Returns the customerStateCode
178         */
179        public String getCustomerStateCode() {
180            return customerStateCode;
181        }
182    
183        /**
184         * Sets the customerStateCode attribute.
185         * 
186         * @param customerStateCode The customerStateCode to set.
187         */
188        public void setCustomerStateCode(String customerStateCode) {
189            this.customerStateCode = customerStateCode;
190        }
191    
192    
193        /**
194         * Gets the customerZipCode attribute.
195         * 
196         * @return Returns the customerZipCode
197         */
198        public String getCustomerZipCode() {
199            return customerZipCode;
200        }
201    
202        /**
203         * Sets the customerZipCode attribute.
204         * 
205         * @param customerZipCode The customerZipCode to set.
206         */
207        public void setCustomerZipCode(String customerZipCode) {
208            this.customerZipCode = customerZipCode;
209        }
210    
211        /**
212         * Gets the customerAddressInternationalProvinceName attribute.
213         * 
214         * @return Returns the customerAddressInternationalProvinceName.
215         */
216        public String getCustomerAddressInternationalProvinceName() {
217            return customerAddressInternationalProvinceName;
218        }
219    
220        /**
221         * Sets the customerAddressInternationalProvinceName attribute value.
222         * 
223         * @param customerAddressInternationalProvinceName The customerAddressInternationalProvinceName to set.
224         */
225        public void setCustomerAddressInternationalProvinceName(String customerAddressInternationalProvinceName) {
226            this.customerAddressInternationalProvinceName = customerAddressInternationalProvinceName;
227        }
228    
229        /**
230         * Gets the customerCountryCode attribute.
231         * 
232         * @return Returns the customerCountryCode.
233         */
234        public String getCustomerCountryCode() {
235            return customerCountryCode;
236        }
237    
238        /**
239         * Sets the customerCountryCode attribute value.
240         * 
241         * @param customerCountryCode The customerCountryCode to set.
242         */
243        public void setCustomerCountryCode(String customerCountryCode) {
244            this.customerCountryCode = customerCountryCode;
245        }
246    
247        /**
248         * Gets the customerInternationalMailCode attribute.
249         * 
250         * @return Returns the customerInternationalMailCode
251         */
252        public String getCustomerInternationalMailCode() {
253            return customerInternationalMailCode;
254        }
255    
256        /**
257         * Sets the customerInternationalMailCode attribute.
258         * 
259         * @param customerInternationalMailCode The customerInternationalMailCode to set.
260         */
261        public void setCustomerInternationalMailCode(String customerInternationalMailCode) {
262            this.customerInternationalMailCode = customerInternationalMailCode;
263        }
264    
265        /**
266         * Gets the customerEmailAddress attribute.
267         * 
268         * @return Returns the customerEmailAddress
269         */
270        public String getCustomerEmailAddress() {
271            return customerEmailAddress;
272        }
273    
274        /**
275         * Sets the customerEmailAddress attribute.
276         * 
277         * @param customerEmailAddress The customerEmailAddress to set.
278         */
279        public void setCustomerEmailAddress(String customerEmailAddress) {
280            this.customerEmailAddress = customerEmailAddress;
281        }
282    
283    
284        /**
285         * Gets the customerAddressTypeCode attribute.
286         * 
287         * @return Returns the customerAddressTypeCode
288         */
289        public String getCustomerAddressTypeCode() {
290            return customerAddressTypeCode;
291        }
292    
293        /**
294         * Sets the customerAddressTypeCode attribute.
295         * 
296         * @param customerAddressTypeCode The customerAddressTypeCode to set.
297         */
298        public void setCustomerAddressTypeCode(String customerAddressTypeCode) {
299            this.customerAddressTypeCode = customerAddressTypeCode;
300        }
301    
302    
303        /**
304         * Gets the customerAddressEndDate attribute.
305         * 
306         * @return Returns the customerAddressEndDate
307         */
308        public Date getCustomerAddressEndDate() {
309            return customerAddressEndDate;
310        }
311    
312        /**
313         * Sets the customerAddressEndDate attribute.
314         * 
315         * @param customerAddressEndDate The customerAddressEndDate to set.
316         */
317        public void setCustomerAddressEndDate(Date customerAddressEndDate) {
318            this.customerAddressEndDate = customerAddressEndDate;
319        }
320    
321        /**
322         * Gets the customerAddressType attribute.
323         * 
324         * @return Returns the customerAddressType
325         */
326        public CustomerAddressType getCustomerAddressType() {
327            return customerAddressType;
328        }
329    
330        /**
331         * Sets the customerAddressType attribute.
332         * 
333         * @param customerAddressType The customerAddressType to set.
334         * @deprecated
335         */
336        public void setCustomerAddressType(CustomerAddressType customerAddressType) {
337            this.customerAddressType = customerAddressType;
338        }
339    
340        /**
341         * Gets the customer attribute.
342         * 
343         * @return Returns the customer.
344         */
345        public Customer getCustomer() {
346            return customer;
347        }
348    
349        /**
350         * Sets the customer attribute value.
351         * 
352         * @param customer The customer to set.
353         * @deprecated
354         */
355        public void setCustomer(Customer customer) {
356            this.customer = customer;
357        }
358    
359        /**
360         * Gets the customerCountry attribute.
361         * 
362         * @return Returns the customerCountry.
363         */
364        public Country getCustomerCountry() {
365            customerCountry = SpringContext.getBean(CountryService.class).getByPrimaryIdIfNecessary(customerCountryCode, customerCountry);
366            return customerCountry;
367        }
368    
369        /**
370         * Sets the customerCountry attribute value.
371         * 
372         * @param customerCountry The customerCountry to set.
373         * @deprecated
374         */
375        public void setCustomerCountry(Country customerCountry) {
376            this.customerCountry = customerCountry;
377        }
378    
379        /**
380         * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
381         */
382        @SuppressWarnings("unchecked")
383        protected LinkedHashMap toStringMapper() {
384            LinkedHashMap m = new LinkedHashMap();
385            m.put("customerNumber", this.customerNumber);
386            if (this.customerAddressIdentifier != null) {
387                m.put("customerAddressIdentifier", this.customerAddressIdentifier.toString());
388            }
389            return m;
390        }
391    
392    
393        /**
394         * @see java.lang.Comparable#compareTo(java.lang.Object)
395         */
396        public int compareTo(CustomerAddress address) {
397            if (this.getCustomerNumber() != null && address.getCustomerNumber() != null && !this.getCustomerNumber().equalsIgnoreCase(address.getCustomerNumber())) {
398                return -1;
399            }
400            if (this.getCustomerAddressName() != null && address.getCustomerAddressName() != null && !this.getCustomerAddressName().equalsIgnoreCase(address.getCustomerAddressName())) {
401                return -1;
402            }
403            if (this.getCustomerLine1StreetAddress() != null && address.getCustomerLine1StreetAddress() != null && !this.getCustomerLine1StreetAddress().equalsIgnoreCase(address.getCustomerLine1StreetAddress())) {
404                return -1;
405            }
406            if (this.getCustomerLine2StreetAddress() != null && address.getCustomerLine2StreetAddress() != null && !this.getCustomerLine2StreetAddress().equalsIgnoreCase(address.getCustomerLine2StreetAddress())
407                || (this.getCustomerLine2StreetAddress() == null && address.getCustomerLine2StreetAddress() != null) || (this.getCustomerLine2StreetAddress() != null && address.getCustomerLine2StreetAddress() == null)) {
408                return -1;
409            }
410            if (this.getCustomerCityName() != null && address.getCustomerCityName() != null && !this.getCustomerCityName().equalsIgnoreCase(address.getCustomerCityName())) {
411                return -1;
412            }
413            if (this.getCustomerStateCode() != null && address.getCustomerStateCode() != null && !this.getCustomerStateCode().equalsIgnoreCase(address.getCustomerStateCode())
414                || (this.getCustomerStateCode() == null && address.getCustomerStateCode() != null) || (this.getCustomerStateCode() != null && address.getCustomerStateCode() == null)) {
415                return -1;
416            }
417            if (this.getCustomerZipCode() != null && address.getCustomerZipCode() != null && !this.getCustomerZipCode().equalsIgnoreCase(address.getCustomerZipCode())
418                || (this.getCustomerZipCode() == null && address.getCustomerZipCode() != null) || (this.getCustomerZipCode() != null && address.getCustomerZipCode() == null)) {
419                return -1;
420            }
421            if (this.getCustomerCountryCode() != null && address.getCustomerCountryCode() != null && !this.getCustomerCountryCode().equalsIgnoreCase(address.getCustomerCountryCode())) {
422                return -1;
423            }
424            if (this.getCustomerAddressInternationalProvinceName() != null && address.getCustomerAddressInternationalProvinceName() != null && !this.getCustomerAddressInternationalProvinceName().equalsIgnoreCase(address.getCustomerAddressInternationalProvinceName())
425                || (this.getCustomerAddressInternationalProvinceName() == null && address.getCustomerAddressInternationalProvinceName() != null) || (this.getCustomerAddressInternationalProvinceName() != null && address.getCustomerAddressInternationalProvinceName() == null)) {
426                return -1;
427            }
428            if (this.getCustomerEmailAddress() != null && address.getCustomerEmailAddress() != null && !this.getCustomerEmailAddress().equalsIgnoreCase(address.getCustomerEmailAddress())
429                || (this.getCustomerEmailAddress() == null && address.getCustomerEmailAddress() != null) || (this.getCustomerEmailAddress() != null && address.getCustomerEmailAddress() == null)) {
430                return -1;
431            }
432            if (this.getCustomerAddressTypeCode() != null && address.getCustomerAddressTypeCode() != null && !this.getCustomerAddressTypeCode().equalsIgnoreCase(address.getCustomerAddressTypeCode())
433                || (this.getCustomerAddressTypeCode() == null && address.getCustomerAddressTypeCode() != null) || (this.getCustomerAddressTypeCode() != null && address.getCustomerAddressTypeCode() == null)) {
434                return -1;
435            }
436            if (this.getCustomerAddressIdentifier() != null && address.getCustomerAddressIdentifier() != null && this.getCustomerAddressIdentifier().compareTo(address.getCustomerAddressIdentifier())!= 0
437                || (this.getCustomerAddressIdentifier() == null && address.getCustomerAddressIdentifier() != null) || (this.getCustomerAddressIdentifier() != null && address.getCustomerAddressIdentifier() == null)) {
438                return -1;
439            }
440            return 0;
441        }
442    
443        @Override
444        public void beforeInsert(PersistenceBroker persistenceBroker) throws PersistenceBrokerException {
445            super.beforeInsert(persistenceBroker);
446            CustomerAddressService customerAddressService = SpringContext.getBean(CustomerAddressService.class);
447            int customerAddressIdentifier = customerAddressService.getNextCustomerAddressIdentifier();
448            this.setCustomerAddressIdentifier(customerAddressIdentifier);
449        }
450    
451    }