001/* 002 * Copyright 2007 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 */ 016package org.kuali.ole.pdp.businessobject; 017 018import java.util.HashMap; 019import java.util.Map; 020 021import org.apache.commons.lang.StringUtils; 022import org.kuali.ole.sys.OLEConstants; 023import org.kuali.ole.sys.context.SpringContext; 024import org.kuali.rice.core.api.mo.common.active.MutableInactivatable; 025import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 026import org.kuali.rice.krad.service.KualiModuleService; 027import org.kuali.rice.krad.service.ModuleService; 028import org.kuali.rice.location.api.LocationConstants; 029import org.kuali.rice.location.framework.postalcode.PostalCodeEbo; 030import org.kuali.rice.location.framework.state.StateEbo; 031 032public class ACHBank extends PersistableBusinessObjectBase implements MutableInactivatable { 033 034 protected String bankRoutingNumber; 035 protected String bankOfficeCode; 036 protected String bankServiceNumber; 037 protected String bankTypeCode; 038 protected String bankNewRoutingNumber; 039 protected String bankName; 040 protected String bankStreetAddress; 041 protected String bankCityName; 042 protected String bankStateCode; 043 protected String bankZipCode; 044 protected String bankPhoneAreaCode; 045 protected String bankPhonePrefixNumber; 046 protected String bankPhoneSuffixNumber; 047 protected String bankInstitutionStatusCode; 048 protected String bankDataViewCode; 049 protected boolean active; 050 051 protected StateEbo bankState; 052 protected PostalCodeEbo postalCode; 053 054 /** 055 * Default constructor. 056 */ 057 public ACHBank() { 058 059 } 060 061 /** 062 * This constructor takes a line of data from https://www.fededirectory.frb.org/FedACHdir.txt and populates the object 063 * 064 * @param fileData 065 */ 066 public ACHBank(String fileData) { 067 // 074914274O0710003011020207000000000UNITED COMMERCE BANK 211 SOUTH COLLEGE AVENUE BLOOMINGTON IN474040000812336226511 068 // Routing Number 9 1-9 The institution's routing number 069 // Office Code 1 10 Main office or branch O=main B=branch 070 // Servicing FRB Number 9 11-19 Servicing Fed's main office routing number 071 // Record Type Code 1 20 The code indicating the ABA number to be used to route or send ACH items to the RFI 072 // 0 = Institution is a Federal Reserve Bank 073 // 1 = Send items to customer routing number 074 // 2 = Send items to customer using new routing number field 075 // Change Date 6 21-26 Date of last change to CRF information (MMDDYY) 076 // New Routing Number 9 27-35 Institution's new routing number resulting from a merger or renumber 077 // Customer Name 36 36-71 Commonly used abbreviated name 078 // Address 36 72-107 Delivery address 079 // City 20 108-127 City name in the delivery address 080 // State Code 2 128-129 State code of the state in the delivery address 081 // Zipcode 5 130-134 Zip code in the delivery address 082 // Zipcode Extension 4 135-138 Zip code extension in the delivery address 083 // Telephone Area Code 3 139-141 Area code of the CRF contact telephone number 084 // Telephone Prefix Number 3 142-144 Prefix of the CRF contact telephone number 085 // Telephone Suffix Number 4 145-148 Suffix of the CRF contact telephone number 086 // Institution Status Code 1 149 Code is based on the customers receiver code 087 // 1=Receives Gov/Comm 088 // Data View Code 1 150 1=Current view 089 // Filler 5 151-155 Spaces 090 091 setBankRoutingNumber(getField(fileData, 1, 9)); 092 setBankOfficeCode(getField(fileData, 10, 1)); 093 setBankServiceNumber(getField(fileData, 11, 9)); 094 setBankTypeCode(getField(fileData, 20, 1)); 095 setBankNewRoutingNumber(getField(fileData, 27, 9)); 096 setBankName(getField(fileData, 36, 36)); 097 setBankStreetAddress(getField(fileData, 72, 36)); 098 setBankCityName(getField(fileData, 108, 20)); 099 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}