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  package org.kuali.ole.sys.businessobject;
17  
18  import java.io.Serializable;
19  import java.util.HashMap;
20  import java.util.Map;
21  import javax.persistence.Column;
22  import javax.persistence.Convert;
23  import javax.persistence.Entity;
24  import javax.persistence.Id;
25  import javax.persistence.IdClass;
26  import javax.persistence.Table;
27  import javax.persistence.Transient;
28  import org.apache.commons.lang.StringUtils;
29  import org.apache.commons.lang.builder.CompareToBuilder;
30  import org.apache.commons.lang.builder.EqualsBuilder;
31  import org.apache.commons.lang.builder.HashCodeBuilder;
32  import org.apache.commons.lang.builder.ToStringBuilder;
33  import org.kuali.ole.sys.context.SpringContext;
34  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
35  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
36  import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
37  import org.kuali.rice.krad.service.KualiModuleService;
38  import org.kuali.rice.krad.service.ModuleService;
39  import org.kuali.rice.location.api.LocationConstants;
40  import org.kuali.rice.location.framework.campus.CampusEbo;
41  import org.kuali.rice.location.framework.country.CountryEbo;
42  import org.kuali.rice.location.framework.postalcode.PostalCodeEbo;
43  import org.kuali.rice.location.framework.state.StateEbo;
44  
45  /**
46   * 
47   */
48  @Entity
49  @Table(name = "SH_BUILDING_T")
50  @IdClass(Building.BuildingId.class)
51  public class Building extends PersistableBusinessObjectBase implements MutableInactivatable {
52  
53      @Id
54      @Column(name = "CAMPUS_CD")
55      protected String campusCode;
56  
57      @Id
58      @Column(name = "BLDG_CD")
59      protected String buildingCode;
60  
61      @Column(name = "BLDG_NM")
62      protected String buildingName;
63  
64      @Column(name = "BLDG_STR_ADDR")
65      protected String buildingStreetAddress;
66  
67      @Column(name = "BLDG_ADDR_CTY_NM")
68      protected String buildingAddressCityName;
69  
70      @Column(name = "BLDG_ADDR_ST_CD")
71      protected String buildingAddressStateCode;
72  
73      @Column(name = "BLDG_ADDR_ZIP_CD")
74      protected String buildingAddressZipCode;
75  
76      @Column(name = "ALTRNT_BLDG_CD")
77      protected String alternateBuildingCode;
78  
79      @Column(name = "ROW_ACTV_IND")
80      @Convert(converter = BooleanYNConverter.class)
81      protected boolean active;
82  
83      @Column(name = "BLDG_ADDR_CNTRY_CD")
84      protected String buildingAddressCountryCode;
85  
86      @Transient
87      protected CampusEbo campus;
88  
89      @Transient
90      protected StateEbo buildingAddressState;
91  
92      @Transient
93      protected PostalCodeEbo buildingAddressZip;
94  
95      @Transient
96      protected CountryEbo buildingAddressCountry;
97  
98      /**
99       * Gets the campusCode attribute.
100      * 
101      * @return Returns the campusCode
102      */
103     public String getCampusCode() {
104         return campusCode;
105     }
106 
107     /**
108      * Sets the campusCode attribute.
109      * 
110      * @param campusCode The campusCode to set.
111      */
112     public void setCampusCode(String campusCode) {
113         this.campusCode = campusCode;
114     }
115 
116     /**
117      * Gets the buildingCode attribute.
118      * 
119      * @return Returns the buildingCode
120      */
121     public String getBuildingCode() {
122         return buildingCode;
123     }
124 
125     /**
126      * Sets the buildingCode attribute.
127      * 
128      * @param buildingCode The buildingCode to set.
129      */
130     public void setBuildingCode(String buildingCode) {
131         this.buildingCode = buildingCode;
132     }
133 
134     /**
135      * Gets the buildingName attribute.
136      * 
137      * @return Returns the buildingName
138      */
139     public String getBuildingName() {
140         return buildingName;
141     }
142 
143     /**
144      * Sets the buildingName attribute.
145      * 
146      * @param buildingName The buildingName to set.
147      */
148     public void setBuildingName(String buildingName) {
149         this.buildingName = buildingName;
150     }
151 
152     /**
153      * Gets the campus attribute.
154      * 
155      * @return Returns the campus.
156      */
157     public CampusEbo getCampus() {
158         if ( StringUtils.isBlank(campusCode) ) {
159             campus = null;
160         } else {
161             if ( campus == null || !StringUtils.equals( campus.getCode(),campusCode) ) {
162                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CampusEbo.class);
163                 if ( moduleService != null ) {
164                     Map<String,Object> keys = new HashMap<String, Object>(1);
165                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, campusCode);
166                     campus = moduleService.getExternalizableBusinessObject(CampusEbo.class, keys);
167                 } else {
168                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
169                 }
170             }
171         }
172         return campus;
173     }
174 
175     /**
176      * Sets the campus attribute value.
177      * 
178      * @param campus The campus to set.
179      */
180     public void setCampus(CampusEbo campus) {
181         this.campus = campus;
182     }
183 
184     /**
185      * Gets the alternateBuildingCode attribute.
186      * 
187      * @return Returns the alternateBuildingCode.
188      */
189     public String getAlternateBuildingCode() {
190         return alternateBuildingCode;
191     }
192 
193     /**
194      * Sets the alternateBuildingCode attribute value.
195      * 
196      * @param alternateBuildingCode The alternateBuildingCode to set.
197      */
198     public void setAlternateBuildingCode(String alternateBuildingCode) {
199         this.alternateBuildingCode = alternateBuildingCode;
200     }
201 
202     /**
203      * Gets the buildingAddressCityName attribute.
204      * 
205      * @return Returns the buildingAddressCityName.
206      */
207     public String getBuildingAddressCityName() {
208         return buildingAddressCityName;
209     }
210 
211     /**
212      * Sets the buildingAddressCityName attribute value.
213      * 
214      * @param buildingAddressCityName The buildingAddressCityName to set.
215      */
216     public void setBuildingAddressCityName(String buildingAddressCityName) {
217         this.buildingAddressCityName = buildingAddressCityName;
218     }
219 
220     /**
221      * Gets the buildingAddressStateCode attribute.
222      * 
223      * @return Returns the buildingAddressStateCode.
224      */
225     public String getBuildingAddressStateCode() {
226         return buildingAddressStateCode;
227     }
228 
229     /**
230      * Sets the buildingAddressStateCode attribute value.
231      * 
232      * @param buildingAddressStateCode The buildingAddressStateCode to set.
233      */
234     public void setBuildingAddressStateCode(String buildingAddressStateCode) {
235         this.buildingAddressStateCode = buildingAddressStateCode;
236     }
237 
238     /**
239      * Gets the buildingAddressZipCode attribute.
240      * 
241      * @return Returns the buildingAddressZipCode.
242      */
243     public String getBuildingAddressZipCode() {
244         return buildingAddressZipCode;
245     }
246 
247     /**
248      * Sets the buildingAddressZipCode attribute value.
249      * 
250      * @param buildingAddressZipCode The buildingAddressZipCode to set.
251      */
252     public void setBuildingAddressZipCode(String buildingAddressZipCode) {
253         this.buildingAddressZipCode = buildingAddressZipCode;
254     }
255 
256     /**
257      * Gets the buildingStreetAddress attribute.
258      * 
259      * @return Returns the buildingStreetAddress.
260      */
261     public String getBuildingStreetAddress() {
262         return buildingStreetAddress;
263     }
264 
265     /**
266      * Sets the buildingStreetAddress attribute value.
267      * 
268      * @param buildingStreetAddress The buildingStreetAddress to set.
269      */
270     public void setBuildingStreetAddress(String buildingStreetAddress) {
271         this.buildingStreetAddress = buildingStreetAddress;
272     }
273 
274     /**
275      * Gets the active attribute. 
276      * @return Returns the active.
277      */
278     @Override
279     public boolean isActive() {
280         return active;
281     }
282 
283     /**
284      * Sets the active attribute value.
285      * @param active The active to set.
286      */
287     @Override
288     public void setActive(boolean active) {
289         this.active = active;
290     }
291 
292     /**
293      * Gets the buildingAddressState attribute.
294      * 
295      * @return Returns the buildingAddressState.
296      */
297     public StateEbo getBuildingAddressState() {
298         if ( StringUtils.isBlank(buildingAddressStateCode) || StringUtils.isBlank(buildingAddressCountryCode ) ) {
299             buildingAddressState = null;
300         } else {
301             if ( buildingAddressState == null || !StringUtils.equals( buildingAddressState.getCode(),buildingAddressStateCode) || !StringUtils.equals(buildingAddressState.getCountryCode(), buildingAddressCountryCode ) ) {
302                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(StateEbo.class);
303                 if ( moduleService != null ) {
304                     Map<String,Object> keys = new HashMap<String, Object>(2);
305                     keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, buildingAddressCountryCode);
306                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, buildingAddressStateCode);
307                     buildingAddressState = moduleService.getExternalizableBusinessObject(StateEbo.class, keys);
308                 } else {
309                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
310                 }
311             }
312         }
313         return buildingAddressState;
314     }
315 
316     /**
317      * Sets the buildingAddressState attribute value.
318      * 
319      * @param buildingAddressState The buildingAddressState to set.
320      * @deprecated
321      */
322     public void setBuildingAddressState(StateEbo buildingAddressState) {
323         this.buildingAddressState = buildingAddressState;
324     }
325 
326     /**
327      * Gets the buildingAddressZip attribute.
328      * 
329      * @return Returns the buildingAddressZip.
330      */
331     public PostalCodeEbo getBuildingAddressZip() {
332         if ( StringUtils.isBlank(buildingAddressZipCode) || StringUtils.isBlank(buildingAddressCountryCode) ) {
333             buildingAddressZip = null;
334         } else {
335             if ( buildingAddressZip == null || !StringUtils.equals( buildingAddressZip.getCode(),buildingAddressZipCode) || !StringUtils.equals(buildingAddressZip.getCountryCode(), buildingAddressCountryCode ) ) {
336                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(PostalCodeEbo.class);
337                 if ( moduleService != null ) {
338                     Map<String,Object> keys = new HashMap<String, Object>(2);
339                     keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, buildingAddressCountryCode);
340                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, buildingAddressZipCode);
341                     buildingAddressZip = moduleService.getExternalizableBusinessObject(PostalCodeEbo.class, keys);
342                 } else {
343                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
344                 }
345             }
346         }
347         return buildingAddressZip;
348     }
349 
350     /**
351      * Sets the buildingAddressZip attribute value.
352      * 
353      * @param buildingAddressZip The buildingAddressZip to set.
354      * @deprecated
355      */
356     public void setBuildingAddressZip(PostalCodeEbo buildingAddressZip) {
357         this.buildingAddressZip = buildingAddressZip;
358     }
359     
360     /**
361      * Gets the buildingAddressCountryCode attribute. 
362      * @return Returns the buildingAddressCountryCode.
363      */
364     public String getBuildingAddressCountryCode() {
365         return buildingAddressCountryCode;
366     }
367 
368     /**
369      * Sets the buildingAddressCountryCode attribute value.
370      * @param buildingAddressCountryCode The buildingAddressCountryCode to set.
371      */
372     public void setBuildingAddressCountryCode(String buildingAddressCountryCode) {
373         this.buildingAddressCountryCode = buildingAddressCountryCode;
374     }
375 
376     /**
377      * Gets the buildingAddressCountry attribute. 
378      * @return Returns the buildingAddressCountry.
379      */
380     public CountryEbo getBuildingAddressCountry() {
381         if ( StringUtils.isBlank(buildingAddressCountryCode) ) {
382             buildingAddressCountry = null;
383         } else {
384             if ( buildingAddressCountry == null || !StringUtils.equals( buildingAddressCountry.getCode(),buildingAddressCountryCode) ) {
385                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CountryEbo.class);
386                 if ( moduleService != null ) {
387                     Map<String,Object> keys = new HashMap<String, Object>(1);
388                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, buildingAddressCountryCode);
389                     buildingAddressCountry = moduleService.getExternalizableBusinessObject(CountryEbo.class, keys);
390                 } else {
391                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
392                 }
393             }
394         }
395         return buildingAddressCountry;
396     }
397 
398     /**
399      * Sets the buildingAddressCountry attribute value.
400      * @param buildingAddressCountry The buildingAddressCountry to set.
401      */
402     public void setBuildingAddressCountry(CountryEbo buildingAddressCountry) {
403         this.buildingAddressCountry = buildingAddressCountry;
404     }
405 
406     public static final class BuildingId implements Serializable, Comparable<BuildingId> {
407 
408         private String campusCode;
409 
410         private String buildingCode;
411 
412         public String getCampusCode() {
413             return this.campusCode;
414         }
415 
416         public void setCampusCode(String campusCode) {
417             this.campusCode = campusCode;
418         }
419 
420         public String getBuildingCode() {
421             return this.buildingCode;
422         }
423 
424         public void setBuildingCode(String buildingCode) {
425             this.buildingCode = buildingCode;
426         }
427 
428         @Override
429         public String toString() {
430             return new ToStringBuilder(this).append("campusCode", this.campusCode).append("buildingCode", this.buildingCode).toString();
431         }
432 
433         @Override
434         public boolean equals(Object other) {
435             if (other == null)
436                 return false;
437             if (other == this)
438                 return true;
439             if (other.getClass() != this.getClass())
440                 return false;
441             final BuildingId rhs = (BuildingId) other;
442             return new EqualsBuilder().append(this.campusCode, rhs.campusCode).append(this.buildingCode, rhs.buildingCode).isEquals();
443         }
444 
445         @Override
446         public int hashCode() {
447             return new HashCodeBuilder(17, 37).append(this.campusCode).append(this.buildingCode).toHashCode();
448         }
449 
450         @Override
451         public int compareTo(BuildingId other) {
452             return new CompareToBuilder().append(this.campusCode, other.campusCode).append(this.buildingCode, other.buildingCode).toComparison();
453         }
454     }
455 }