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.pdp.businessobject;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.sys.OLEConstants;
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.postalcode.PostalCodeEbo;
30  import org.kuali.rice.location.framework.state.StateEbo;
31  
32  public class ACHBank extends PersistableBusinessObjectBase implements MutableInactivatable {
33  
34      protected String bankRoutingNumber;
35      protected String bankOfficeCode;
36      protected String bankServiceNumber;
37      protected String bankTypeCode;
38      protected String bankNewRoutingNumber;
39      protected String bankName;
40      protected String bankStreetAddress;
41      protected String bankCityName;
42      protected String bankStateCode;
43      protected String bankZipCode;
44      protected String bankPhoneAreaCode;
45      protected String bankPhonePrefixNumber;
46      protected String bankPhoneSuffixNumber;
47      protected String bankInstitutionStatusCode;
48      protected String bankDataViewCode;
49      protected boolean active;
50      
51      protected StateEbo bankState;
52      protected PostalCodeEbo postalCode;
53      
54      /**
55       * Default constructor.
56       */
57      public ACHBank() {
58  
59      }
60  
61      /**
62       * This constructor takes a line of data from https://www.fededirectory.frb.org/FedACHdir.txt and populates the object
63       * 
64       * @param fileData
65       */
66      public ACHBank(String fileData) {
67          // 074914274O0710003011020207000000000UNITED COMMERCE BANK 211 SOUTH COLLEGE AVENUE BLOOMINGTON IN474040000812336226511
68          // Routing Number 9 1-9 The institution's routing number
69          // Office Code 1 10 Main office or branch O=main B=branch
70          // Servicing FRB Number 9 11-19 Servicing Fed's main office routing number
71          // Record Type Code 1 20 The code indicating the ABA number to be used to route or send ACH items to the RFI
72          // 0 = Institution is a Federal Reserve Bank
73          // 1 = Send items to customer routing number
74          // 2 = Send items to customer using new routing number field
75          // Change Date 6 21-26 Date of last change to CRF information (MMDDYY)
76          // New Routing Number 9 27-35 Institution's new routing number resulting from a merger or renumber
77          // Customer Name 36 36-71 Commonly used abbreviated name
78          // Address 36 72-107 Delivery address
79          // City 20 108-127 City name in the delivery address
80          // State Code 2 128-129 State code of the state in the delivery address
81          // Zipcode 5 130-134 Zip code in the delivery address
82          // Zipcode Extension 4 135-138 Zip code extension in the delivery address
83          // Telephone Area Code 3 139-141 Area code of the CRF contact telephone number
84          // Telephone Prefix Number 3 142-144 Prefix of the CRF contact telephone number
85          // Telephone Suffix Number 4 145-148 Suffix of the CRF contact telephone number
86          // Institution Status Code 1 149 Code is based on the customers receiver code
87          // 1=Receives Gov/Comm
88          // Data View Code 1 150 1=Current view
89          // Filler 5 151-155 Spaces
90  
91          setBankRoutingNumber(getField(fileData, 1, 9));
92          setBankOfficeCode(getField(fileData, 10, 1));
93          setBankServiceNumber(getField(fileData, 11, 9));
94          setBankTypeCode(getField(fileData, 20, 1));
95          setBankNewRoutingNumber(getField(fileData, 27, 9));
96          setBankName(getField(fileData, 36, 36));
97          setBankStreetAddress(getField(fileData, 72, 36));
98          setBankCityName(getField(fileData, 108, 20));
99          setBankStateCode(getField(fileData, 128, 2));
100         setBankZipCode(getField(fileData, 130, 5));
101         setBankPhoneAreaCode(getField(fileData, 139, 3));
102         setBankPhonePrefixNumber(getField(fileData, 142, 3));
103         setBankPhoneSuffixNumber(getField(fileData, 145, 4));
104         setBankInstitutionStatusCode(getField(fileData, 149, 1));
105         setBankDataViewCode(getField(fileData, 150, 1));
106         setActive(true);
107     }
108 
109     protected String getField(String data, int startChar, int length) {
110         return data.substring(startChar - 1, startChar + length - 1).trim();
111     }
112 
113     /**
114      * Gets the bankRoutingNumber attribute.
115      * 
116      * @return Returns the bankRoutingNumber
117      */
118     public String getBankRoutingNumber() {
119         return bankRoutingNumber;
120     }
121 
122     /**
123      * Sets the bankRoutingNumber attribute.
124      * 
125      * @param bankRoutingNumber The bankRoutingNumber to set.
126      */
127     public void setBankRoutingNumber(String bankRoutingNumber) {
128         this.bankRoutingNumber = bankRoutingNumber;
129     }
130 
131 
132     /**
133      * Gets the bankOfficeCode attribute.
134      * 
135      * @return Returns the bankOfficeCode
136      */
137     public String getBankOfficeCode() {
138         return bankOfficeCode;
139     }
140 
141     /**
142      * Sets the bankOfficeCode attribute.
143      * 
144      * @param bankOfficeCode The bankOfficeCode to set.
145      */
146     public void setBankOfficeCode(String bankOfficeCode) {
147         this.bankOfficeCode = bankOfficeCode;
148     }
149 
150 
151     /**
152      * Gets the bankServiceNumber attribute.
153      * 
154      * @return Returns the bankServiceNumber
155      */
156     public String getBankServiceNumber() {
157         return bankServiceNumber;
158     }
159 
160     /**
161      * Sets the bankServiceNumber attribute.
162      * 
163      * @param bankServiceNumber The bankServiceNumber to set.
164      */
165     public void setBankServiceNumber(String bankServiceNumber) {
166         this.bankServiceNumber = bankServiceNumber;
167     }
168 
169 
170     /**
171      * Gets the bankTypeCode attribute.
172      * 
173      * @return Returns the bankTypeCode
174      */
175     public String getBankTypeCode() {
176         return bankTypeCode;
177     }
178 
179     /**
180      * Sets the bankTypeCode attribute.
181      * 
182      * @param bankTypeCode The bankTypeCode to set.
183      */
184     public void setBankTypeCode(String bankTypeCode) {
185         this.bankTypeCode = bankTypeCode;
186     }
187 
188 
189     /**
190      * Gets the bankNewRoutingNumber attribute.
191      * 
192      * @return Returns the bankNewRoutingNumber
193      */
194     public String getBankNewRoutingNumber() {
195         return bankNewRoutingNumber;
196     }
197 
198     /**
199      * Sets the bankNewRoutingNumber attribute.
200      * 
201      * @param bankNewRoutingNumber The bankNewRoutingNumber to set.
202      */
203     public void setBankNewRoutingNumber(String bankNewRoutingNumber) {
204         this.bankNewRoutingNumber = bankNewRoutingNumber;
205     }
206 
207 
208     /**
209      * Gets the bankName attribute.
210      * 
211      * @return Returns the bankName
212      */
213     public String getBankName() {
214         return bankName;
215     }
216 
217     /**
218      * Sets the bankName attribute.
219      * 
220      * @param bankName The bankName to set.
221      */
222     public void setBankName(String bankName) {
223         this.bankName = bankName;
224     }
225 
226 
227     /**
228      * Gets the bankStreetAddress attribute.
229      * 
230      * @return Returns the bankStreetAddress
231      */
232     public String getBankStreetAddress() {
233         return bankStreetAddress;
234     }
235 
236     /**
237      * Sets the bankStreetAddress attribute.
238      * 
239      * @param bankStreetAddress The bankStreetAddress to set.
240      */
241     public void setBankStreetAddress(String bankStreetAddress) {
242         this.bankStreetAddress = bankStreetAddress;
243     }
244 
245 
246     /**
247      * Gets the bankCityName attribute.
248      * 
249      * @return Returns the bankCityName
250      */
251     public String getBankCityName() {
252         return bankCityName;
253     }
254 
255     /**
256      * Sets the bankCityName attribute.
257      * 
258      * @param bankCityName The bankCityName to set.
259      */
260     public void setBankCityName(String bankCityName) {
261         this.bankCityName = bankCityName;
262     }
263 
264 
265     /**
266      * Gets the bankStateCode attribute.
267      * 
268      * @return Returns the bankStateCode
269      */
270     public String getBankStateCode() {
271         return bankStateCode;
272     }
273 
274     /**
275      * Sets the bankStateCode attribute.
276      * 
277      * @param bankStateCode The bankStateCode to set.
278      */
279     public void setBankStateCode(String bankStateCode) {
280         this.bankStateCode = bankStateCode;
281     }
282 
283 
284     /**
285      * Gets the bankZipCode attribute.
286      * 
287      * @return Returns the bankZipCode
288      */
289     public String getBankZipCode() {
290         return bankZipCode;
291     }
292 
293     /**
294      * Sets the bankZipCode attribute.
295      * 
296      * @param bankZipCode The bankZipCode to set.
297      */
298     public void setBankZipCode(String bankZipCode) {
299         this.bankZipCode = bankZipCode;
300     }
301 
302     /**
303      * Gets the bankPhoneAreaCode attribute.
304      * 
305      * @return Returns the bankPhoneAreaCode
306      */
307     public String getBankPhoneAreaCode() {
308         return bankPhoneAreaCode;
309     }
310 
311     /**
312      * Sets the bankPhoneAreaCode attribute.
313      * 
314      * @param bankPhoneAreaCode The bankPhoneAreaCode to set.
315      */
316     public void setBankPhoneAreaCode(String bankPhoneAreaCode) {
317         this.bankPhoneAreaCode = bankPhoneAreaCode;
318     }
319 
320 
321     /**
322      * Gets the bankPhonePrefixNumber attribute.
323      * 
324      * @return Returns the bankPhonePrefixNumber
325      */
326     public String getBankPhonePrefixNumber() {
327         return bankPhonePrefixNumber;
328     }
329 
330     /**
331      * Sets the bankPhonePrefixNumber attribute.
332      * 
333      * @param bankPhonePrefixNumber The bankPhonePrefixNumber to set.
334      */
335     public void setBankPhonePrefixNumber(String bankPhonePrefixNumber) {
336         this.bankPhonePrefixNumber = bankPhonePrefixNumber;
337     }
338 
339 
340     /**
341      * Gets the bankPhoneSuffixNumber attribute.
342      * 
343      * @return Returns the bankPhoneSuffixNumber
344      */
345     public String getBankPhoneSuffixNumber() {
346         return bankPhoneSuffixNumber;
347     }
348 
349     /**
350      * Sets the bankPhoneSuffixNumber attribute.
351      * 
352      * @param bankPhoneSuffixNumber The bankPhoneSuffixNumber to set.
353      */
354     public void setBankPhoneSuffixNumber(String bankPhoneSuffixNumber) {
355         this.bankPhoneSuffixNumber = bankPhoneSuffixNumber;
356     }
357 
358 
359     /**
360      * Gets the bankInstitutionStatusCode attribute.
361      * 
362      * @return Returns the bankInstitutionStatusCode
363      */
364     public String getBankInstitutionStatusCode() {
365         return bankInstitutionStatusCode;
366     }
367 
368     /**
369      * Sets the bankInstitutionStatusCode attribute.
370      * 
371      * @param bankInstitutionStatusCode The bankInstitutionStatusCode to set.
372      */
373     public void setBankInstitutionStatusCode(String bankInstitutionStatusCode) {
374         this.bankInstitutionStatusCode = bankInstitutionStatusCode;
375     }
376 
377 
378     /**
379      * Gets the bankDataViewCode attribute.
380      * 
381      * @return Returns the bankDataViewCode
382      */
383     public String getBankDataViewCode() {
384         return bankDataViewCode;
385     }
386 
387     /**
388      * Sets the bankDataViewCode attribute.
389      * 
390      * @param bankDataViewCode The bankDataViewCode to set.
391      */
392     public void setBankDataViewCode(String bankDataViewCode) {
393         this.bankDataViewCode = bankDataViewCode;
394     }
395 
396     /**
397      * Gets the bankState attribute.
398      * 
399      * @return Returns the bankState.
400      */
401     public StateEbo getBankState() {
402         if ( StringUtils.isBlank(bankStateCode) || StringUtils.isBlank(OLEConstants.COUNTRY_CODE_UNITED_STATES ) ) {
403             bankState = null;
404         } else {
405             if ( bankState == null || !StringUtils.equals( bankState.getCode(),bankStateCode) || !StringUtils.equals(bankState.getCountryCode(), OLEConstants.COUNTRY_CODE_UNITED_STATES ) ) {
406                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(StateEbo.class);
407                 if ( moduleService != null ) {
408                     Map<String,Object> keys = new HashMap<String, Object>(2);
409                     keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, OLEConstants.COUNTRY_CODE_UNITED_STATES);/*RICE20_REFACTORME*/
410                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, bankStateCode);
411                     bankState = moduleService.getExternalizableBusinessObject(StateEbo.class, keys);
412                 } else {
413                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
414                 }
415             }
416         }
417         return bankState;
418     }
419 
420     /**
421      * Gets the postalCode attribute.
422      * 
423      * @return Returns the postalCode.
424      */
425     public PostalCodeEbo getPostalCode() {
426         if ( StringUtils.isBlank(bankZipCode) || StringUtils.isBlank(OLEConstants.COUNTRY_CODE_UNITED_STATES ) ) {
427             postalCode = null;
428         } else {
429             if ( postalCode == null || !StringUtils.equals( postalCode.getCode(),bankZipCode) || !StringUtils.equals(postalCode.getCountryCode(), OLEConstants.COUNTRY_CODE_UNITED_STATES ) ) {
430                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(PostalCodeEbo.class);
431                 if ( moduleService != null ) {
432                     Map<String,Object> keys = new HashMap<String, Object>(2);
433                     keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, OLEConstants.COUNTRY_CODE_UNITED_STATES);/*RICE20_REFACTORME*/
434                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, bankZipCode);
435                     postalCode = moduleService.getExternalizableBusinessObject(PostalCodeEbo.class, keys);
436                 } else {
437                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
438                 }
439             }
440         }
441         return postalCode;
442     }
443     
444     /**
445      * 
446      * @see org.kuali.rice.core.api.mo.common.active.MutableInactivatable#isActive()
447      */
448     @Override
449     public boolean isActive() {
450         return active;
451     }
452     
453     /**
454      * 
455      * @see org.kuali.rice.core.api.mo.common.active.MutableInactivatable#setActive(boolean)
456      */
457     @Override
458     public void setActive(boolean active) {
459         this.active = active;
460     }
461 }