View Javadoc
1   /*
2    * Copyright 2005 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.module.cg.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.OLEConstants;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
26  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
27  import org.kuali.rice.krad.service.KualiModuleService;
28  import org.kuali.rice.krad.service.ModuleService;
29  import org.kuali.rice.location.api.LocationConstants;
30  import org.kuali.rice.location.framework.country.CountryEbo;
31  import org.kuali.rice.location.framework.state.StateEbo;
32  
33  /**
34   * Subcontractors are vendors involved with an awarded {@link Proposal}.
35   */
36  public class SubContractor extends PersistableBusinessObjectBase implements MutableInactivatable {
37  
38      protected String subcontractorNumber;
39      protected String subcontractorName;
40      protected String subcontractorAddressLine1;
41      protected String subcontractorAddressLine2;
42      protected String subcontractorCity;
43      protected String subcontractorStateCode;
44      protected String subcontractorZipCode;
45      protected String subcontractorCountryCode;
46      protected boolean active;
47  
48      protected StateEbo subcontractorState;
49      protected CountryEbo subcontractorCountry;
50  
51      public static final String CACHE_NAME = OLEConstants.APPLICATION_NAMESPACE_CODE + "/" + "SubContractor";
52      /**
53       * Default no-arg constructor.
54       */
55      public SubContractor() {
56      }
57  
58      /**
59       * Gets the subcontractorNumber attribute.
60       *
61       * @return Returns the subcontractorNumber
62       */
63      public String getSubcontractorNumber() {
64          return subcontractorNumber;
65      }
66  
67      /**
68       * Sets the subcontractorNumber attribute.
69       *
70       * @param subcontractorNumber The subcontractorNumber to set.
71       */
72      public void setSubcontractorNumber(String subcontractorNumber) {
73          this.subcontractorNumber = subcontractorNumber;
74      }
75  
76      /**
77       * Gets the subcontractorName attribute.
78       *
79       * @return Returns the subcontractorName
80       */
81      public String getSubcontractorName() {
82          return subcontractorName;
83      }
84  
85      /**
86       * Sets the subcontractorName attribute.
87       *
88       * @param subcontractorName The subcontractorName to set.
89       */
90      public void setSubcontractorName(String subcontractorName) {
91          this.subcontractorName = subcontractorName;
92      }
93  
94      /**
95       * Gets the subcontractorAddressLine1 attribute.
96       *
97       * @return Returns the subcontractorAddressLine1
98       */
99      public String getSubcontractorAddressLine1() {
100         return subcontractorAddressLine1;
101     }
102 
103     /**
104      * Sets the subcontractorAddressLine1 attribute.
105      *
106      * @param subcontractorAddressLine1 The subcontractorAddressLine1 to set.
107      */
108     public void setSubcontractorAddressLine1(String subcontractorAddressLine1) {
109         this.subcontractorAddressLine1 = subcontractorAddressLine1;
110     }
111 
112     /**
113      * Gets the subcontractorAddressLine2 attribute.
114      *
115      * @return Returns the subcontractorAddressLine2
116      */
117     public String getSubcontractorAddressLine2() {
118         return subcontractorAddressLine2;
119     }
120 
121     /**
122      * Sets the subcontractorAddressLine2 attribute.
123      *
124      * @param subcontractorAddressLine2 The subcontractorAddressLine2 to set.
125      */
126     public void setSubcontractorAddressLine2(String subcontractorAddressLine2) {
127         this.subcontractorAddressLine2 = subcontractorAddressLine2;
128     }
129 
130     /**
131      * Gets the subcontractorCity attribute.
132      *
133      * @return Returns the subcontractorCity
134      */
135     public String getSubcontractorCity() {
136         return subcontractorCity;
137     }
138 
139     /**
140      * Sets the subcontractorCity attribute.
141      *
142      * @param subcontractorCity The subcontractorCity to set.
143      */
144     public void setSubcontractorCity(String subcontractorCity) {
145         this.subcontractorCity = subcontractorCity;
146     }
147 
148     /**
149      * Gets the subcontractorStateCode attribute.
150      *
151      * @return Returns the subcontractorStateCode.
152      */
153     public String getSubcontractorStateCode() {
154         return subcontractorStateCode;
155     }
156 
157     /**
158      * Sets the subcontractorStateCode attribute value.
159      *
160      * @param subcontractorStateCode The subcontractorStateCode to set.
161      */
162     public void setSubcontractorStateCode(String subcontractorStateCode) {
163         this.subcontractorStateCode = subcontractorStateCode;
164     }
165 
166     /**
167      * Gets the subcontractorZipCode attribute.
168      *
169      * @return Returns the subcontractorZipCode
170      */
171     public String getSubcontractorZipCode() {
172         return subcontractorZipCode;
173     }
174 
175     /**
176      * Sets the subcontractorZipCode attribute.
177      *
178      * @param subcontractorZipCode The subcontractorZipCode to set.
179      */
180     public void setSubcontractorZipCode(String subcontractorZipCode) {
181         this.subcontractorZipCode = subcontractorZipCode;
182     }
183 
184     /**
185      * Gets the subcontractorCountryCode attribute.
186      *
187      * @return Returns the subcontractorCountryCode
188      */
189     public String getSubcontractorCountryCode() {
190         return subcontractorCountryCode;
191     }
192 
193     /**
194      * Sets the subcontractorCountryCode attribute.
195      *
196      * @param subcontractorCountryCode The subcontractorCountryCode to set.
197      */
198     public void setSubcontractorCountryCode(String subcontractorCountryCode) {
199         this.subcontractorCountryCode = subcontractorCountryCode;
200     }
201 
202     /**
203      * Gets the active attribute.
204      *
205      * @return Returns the active.
206      */
207     @Override
208     public boolean isActive() {
209         return active;
210     }
211 
212     /**
213      * Sets the active attribute value.
214      *
215      * @param active The active to set.
216      */
217     @Override
218     public void setActive(boolean active) {
219         this.active = active;
220     }
221 
222     /**
223      * Gets the {@link Country} in which the subcontractor is located.
224      *
225      * @return the {@link Country} in which the subcontractor is located.
226      */
227     public CountryEbo getSubcontractorCountry() {
228         if ( StringUtils.isBlank(subcontractorCountryCode) ) {
229             subcontractorCountry = null;
230         } else {
231             if ( subcontractorCountry == null || !StringUtils.equals( subcontractorCountry.getCode(), subcontractorCountryCode) ) {
232                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CountryEbo.class);
233                 if ( moduleService != null ) {
234                     Map<String,Object> keys = new HashMap<String, Object>(1);
235                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, subcontractorCountryCode);
236                     subcontractorCountry = moduleService.getExternalizableBusinessObject(CountryEbo.class, keys);
237                 } else {
238                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
239                 }
240             }
241         }
242         return subcontractorCountry;
243     }
244 
245     /**
246      * Sets the {@link Country} in which the subcontractor is located.
247      *
248      * @param country the {@link Country} in which the subcontractor is located.
249      */
250     public void setSubcontractorCountry(CountryEbo country) {
251         this.subcontractorCountry = country;
252     }
253 
254     /**
255      * Gets the {@link State} in which the subcontractor is located.
256      *
257      * @return the {@link State} in which the subcontractor is located.
258      */
259     public StateEbo getSubcontractorState() {
260         if ( StringUtils.isBlank(subcontractorCountryCode) || StringUtils.isBlank(OLEConstants.COUNTRY_CODE_UNITED_STATES ) ) {
261             subcontractorState = null;
262         } else {
263             if ( subcontractorState == null || !StringUtils.equals( subcontractorState.getCode(),subcontractorCountryCode) || !StringUtils.equals(subcontractorState.getCountryCode(), OLEConstants.COUNTRY_CODE_UNITED_STATES ) ) {
264                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(StateEbo.class);
265                 if ( moduleService != null ) {
266                     Map<String,Object> keys = new HashMap<String, Object>(2);
267                     keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, OLEConstants.COUNTRY_CODE_UNITED_STATES);/*RICE20_REFACTORME*/
268                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, subcontractorCountryCode);
269                     subcontractorState = moduleService.getExternalizableBusinessObject(StateEbo.class, keys);
270                 } else {
271                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
272                 }
273             }
274         }
275 
276         return subcontractorState;
277     }
278 
279 
280     /**
281      * Sets the {@link State} in which the subcontractor is located.
282      *
283      * @param state the {@link State} in which the subcontractor is located.
284      */
285     public void setSubcontractorState(StateEbo state) {
286         this.subcontractorState = state;
287     }
288 
289 }