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.sys.businessobject;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
25  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
26  import org.kuali.rice.krad.service.KualiModuleService;
27  import org.kuali.rice.krad.service.ModuleService;
28  import org.kuali.rice.location.api.LocationConstants;
29  import org.kuali.rice.location.framework.campus.CampusEbo;
30  import org.kuali.rice.location.framework.country.CountryEbo;
31  import org.kuali.rice.location.framework.postalcode.PostalCodeEbo;
32  import org.kuali.rice.location.framework.state.StateEbo;
33  
34  /**
35   * 
36   */
37  public class Building extends PersistableBusinessObjectBase implements MutableInactivatable {
38  
39      protected String campusCode;
40      protected String buildingCode;
41      protected String buildingName;
42      protected String buildingStreetAddress;
43      protected String buildingAddressCityName;
44      protected String buildingAddressStateCode;
45      protected String buildingAddressZipCode;
46      protected String alternateBuildingCode;
47      protected boolean active;
48      protected String buildingAddressCountryCode;
49  
50      protected CampusEbo campus;
51      protected StateEbo buildingAddressState;
52      protected PostalCodeEbo buildingAddressZip;
53      protected CountryEbo buildingAddressCountry;
54  
55      /**
56       * Gets the campusCode attribute.
57       * 
58       * @return Returns the campusCode
59       */
60      public String getCampusCode() {
61          return campusCode;
62      }
63  
64      /**
65       * Sets the campusCode attribute.
66       * 
67       * @param campusCode The campusCode to set.
68       */
69      public void setCampusCode(String campusCode) {
70          this.campusCode = campusCode;
71      }
72  
73  
74      /**
75       * Gets the buildingCode attribute.
76       * 
77       * @return Returns the buildingCode
78       */
79      public String getBuildingCode() {
80          return buildingCode;
81      }
82  
83      /**
84       * Sets the buildingCode attribute.
85       * 
86       * @param buildingCode The buildingCode to set.
87       */
88      public void setBuildingCode(String buildingCode) {
89          this.buildingCode = buildingCode;
90      }
91  
92  
93      /**
94       * Gets the buildingName attribute.
95       * 
96       * @return Returns the buildingName
97       */
98      public String getBuildingName() {
99          return buildingName;
100     }
101 
102     /**
103      * Sets the buildingName attribute.
104      * 
105      * @param buildingName The buildingName to set.
106      */
107     public void setBuildingName(String buildingName) {
108         this.buildingName = buildingName;
109     }
110 
111     /**
112      * Gets the campus attribute.
113      * 
114      * @return Returns the campus.
115      */
116     public CampusEbo getCampus() {
117         if ( StringUtils.isBlank(campusCode) ) {
118             campus = null;
119         } else {
120             if ( campus == null || !StringUtils.equals( campus.getCode(),campusCode) ) {
121                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CampusEbo.class);
122                 if ( moduleService != null ) {
123                     Map<String,Object> keys = new HashMap<String, Object>(1);
124                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, campusCode);
125                     campus = moduleService.getExternalizableBusinessObject(CampusEbo.class, keys);
126                 } else {
127                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
128                 }
129             }
130         }
131         return campus;
132     }
133 
134     /**
135      * Sets the campus attribute value.
136      * 
137      * @param campus The campus to set.
138      */
139     public void setCampus(CampusEbo campus) {
140         this.campus = campus;
141     }
142 
143     /**
144      * Gets the alternateBuildingCode attribute.
145      * 
146      * @return Returns the alternateBuildingCode.
147      */
148     public String getAlternateBuildingCode() {
149         return alternateBuildingCode;
150     }
151 
152     /**
153      * Sets the alternateBuildingCode attribute value.
154      * 
155      * @param alternateBuildingCode The alternateBuildingCode to set.
156      */
157     public void setAlternateBuildingCode(String alternateBuildingCode) {
158         this.alternateBuildingCode = alternateBuildingCode;
159     }
160 
161     /**
162      * Gets the buildingAddressCityName attribute.
163      * 
164      * @return Returns the buildingAddressCityName.
165      */
166     public String getBuildingAddressCityName() {
167         return buildingAddressCityName;
168     }
169 
170     /**
171      * Sets the buildingAddressCityName attribute value.
172      * 
173      * @param buildingAddressCityName The buildingAddressCityName to set.
174      */
175     public void setBuildingAddressCityName(String buildingAddressCityName) {
176         this.buildingAddressCityName = buildingAddressCityName;
177     }
178 
179     /**
180      * Gets the buildingAddressStateCode attribute.
181      * 
182      * @return Returns the buildingAddressStateCode.
183      */
184     public String getBuildingAddressStateCode() {
185         return buildingAddressStateCode;
186     }
187 
188     /**
189      * Sets the buildingAddressStateCode attribute value.
190      * 
191      * @param buildingAddressStateCode The buildingAddressStateCode to set.
192      */
193     public void setBuildingAddressStateCode(String buildingAddressStateCode) {
194         this.buildingAddressStateCode = buildingAddressStateCode;
195     }
196 
197     /**
198      * Gets the buildingAddressZipCode attribute.
199      * 
200      * @return Returns the buildingAddressZipCode.
201      */
202     public String getBuildingAddressZipCode() {
203         return buildingAddressZipCode;
204     }
205 
206     /**
207      * Sets the buildingAddressZipCode attribute value.
208      * 
209      * @param buildingAddressZipCode The buildingAddressZipCode to set.
210      */
211     public void setBuildingAddressZipCode(String buildingAddressZipCode) {
212         this.buildingAddressZipCode = buildingAddressZipCode;
213     }
214 
215     /**
216      * Gets the buildingStreetAddress attribute.
217      * 
218      * @return Returns the buildingStreetAddress.
219      */
220     public String getBuildingStreetAddress() {
221         return buildingStreetAddress;
222     }
223 
224     /**
225      * Sets the buildingStreetAddress attribute value.
226      * 
227      * @param buildingStreetAddress The buildingStreetAddress to set.
228      */
229     public void setBuildingStreetAddress(String buildingStreetAddress) {
230         this.buildingStreetAddress = buildingStreetAddress;
231     }
232 
233     /**
234      * Gets the active attribute. 
235      * @return Returns the active.
236      */
237     @Override
238     public boolean isActive() {
239         return active;
240     }
241 
242     /**
243      * Sets the active attribute value.
244      * @param active The active to set.
245      */
246     @Override
247     public void setActive(boolean active) {
248         this.active = active;
249     }
250 
251     /**
252      * Gets the buildingAddressState attribute.
253      * 
254      * @return Returns the buildingAddressState.
255      */
256     public StateEbo getBuildingAddressState() {
257         if ( StringUtils.isBlank(buildingAddressStateCode) || StringUtils.isBlank(buildingAddressCountryCode ) ) {
258             buildingAddressState = null;
259         } else {
260             if ( buildingAddressState == null || !StringUtils.equals( buildingAddressState.getCode(),buildingAddressStateCode) || !StringUtils.equals(buildingAddressState.getCountryCode(), buildingAddressCountryCode ) ) {
261                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(StateEbo.class);
262                 if ( moduleService != null ) {
263                     Map<String,Object> keys = new HashMap<String, Object>(2);
264                     keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, buildingAddressCountryCode);
265                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, buildingAddressStateCode);
266                     buildingAddressState = moduleService.getExternalizableBusinessObject(StateEbo.class, keys);
267                 } else {
268                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
269                 }
270             }
271         }
272         return buildingAddressState;
273     }
274 
275     /**
276      * Sets the buildingAddressState attribute value.
277      * 
278      * @param buildingAddressState The buildingAddressState to set.
279      * @deprecated
280      */
281     public void setBuildingAddressState(StateEbo buildingAddressState) {
282         this.buildingAddressState = buildingAddressState;
283     }
284 
285     /**
286      * Gets the buildingAddressZip attribute.
287      * 
288      * @return Returns the buildingAddressZip.
289      */
290     public PostalCodeEbo getBuildingAddressZip() {
291         if ( StringUtils.isBlank(buildingAddressZipCode) || StringUtils.isBlank(buildingAddressCountryCode) ) {
292             buildingAddressZip = null;
293         } else {
294             if ( buildingAddressZip == null || !StringUtils.equals( buildingAddressZip.getCode(),buildingAddressZipCode) || !StringUtils.equals(buildingAddressZip.getCountryCode(), buildingAddressCountryCode ) ) {
295                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(PostalCodeEbo.class);
296                 if ( moduleService != null ) {
297                     Map<String,Object> keys = new HashMap<String, Object>(2);
298                     keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, buildingAddressCountryCode);
299                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, buildingAddressZipCode);
300                     buildingAddressZip = moduleService.getExternalizableBusinessObject(PostalCodeEbo.class, keys);
301                 } else {
302                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
303                 }
304             }
305         }
306         return buildingAddressZip;
307     }
308 
309     /**
310      * Sets the buildingAddressZip attribute value.
311      * 
312      * @param buildingAddressZip The buildingAddressZip to set.
313      * @deprecated
314      */
315     public void setBuildingAddressZip(PostalCodeEbo buildingAddressZip) {
316         this.buildingAddressZip = buildingAddressZip;
317     }
318     
319     /**
320      * Gets the buildingAddressCountryCode attribute. 
321      * @return Returns the buildingAddressCountryCode.
322      */
323     public String getBuildingAddressCountryCode() {
324         return buildingAddressCountryCode;
325     }
326 
327     /**
328      * Sets the buildingAddressCountryCode attribute value.
329      * @param buildingAddressCountryCode The buildingAddressCountryCode to set.
330      */
331     public void setBuildingAddressCountryCode(String buildingAddressCountryCode) {
332         this.buildingAddressCountryCode = buildingAddressCountryCode;
333     }
334 
335     /**
336      * Gets the buildingAddressCountry attribute. 
337      * @return Returns the buildingAddressCountry.
338      */
339     public CountryEbo getBuildingAddressCountry() {
340         if ( StringUtils.isBlank(buildingAddressCountryCode) ) {
341             buildingAddressCountry = null;
342         } else {
343             if ( buildingAddressCountry == null || !StringUtils.equals( buildingAddressCountry.getCode(),buildingAddressCountryCode) ) {
344                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CountryEbo.class);
345                 if ( moduleService != null ) {
346                     Map<String,Object> keys = new HashMap<String, Object>(1);
347                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, buildingAddressCountryCode);
348                     buildingAddressCountry = moduleService.getExternalizableBusinessObject(CountryEbo.class, keys);
349                 } else {
350                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
351                 }
352             }
353         }
354         return buildingAddressCountry;
355     }
356 
357     /**
358      * Sets the buildingAddressCountry attribute value.
359      * @param buildingAddressCountry The buildingAddressCountry to set.
360      */
361     public void setBuildingAddressCountry(CountryEbo buildingAddressCountry) {
362         this.buildingAddressCountry = buildingAddressCountry;
363     }
364 
365 }