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.service.impl; 017 018import java.io.BufferedReader; 019import java.io.FileNotFoundException; 020import java.io.FileReader; 021import java.io.IOException; 022import java.util.HashMap; 023import java.util.Map; 024 025import org.apache.commons.lang.StringUtils; 026import org.kuali.ole.pdp.PdpPropertyConstants; 027import org.kuali.ole.pdp.businessobject.ACHBank; 028import org.kuali.ole.pdp.service.AchBankService; 029import org.kuali.rice.krad.service.BusinessObjectService; 030import org.springframework.transaction.annotation.Transactional; 031 032@Transactional 033public class AchBankServiceImpl implements AchBankService { 034 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AchBankServiceImpl.class); 035 036 private BusinessObjectService businessObjectService; 037 038 /** 039 * @see org.kuali.ole.pdp.service.AchBankService#getByPrimaryId(java.lang.String) 040 */ 041 public ACHBank getByPrimaryId(String bankRoutingNumber) { 042 Map<String, String> fieldKeys = new HashMap<String, String>(); 043 fieldKeys.put(PdpPropertyConstants.BANK_ROUTING_NUMBER, bankRoutingNumber); 044 045 return (ACHBank) businessObjectService.findByPrimaryKey(ACHBank.class, fieldKeys); 046 } 047 048 /** 049 * @see org.kuali.ole.pdp.service.AchBankService#reloadTable(java.lang.String) 050 */ 051 public boolean reloadTable(String filename) { 052 LOG.debug("reloadTable() started"); 053 054 // clear out previous records 055 businessObjectService.deleteMatching(ACHBank.class, new HashMap()); 056 057 BufferedReader inputStream = null; 058 try { 059 inputStream = new BufferedReader(new FileReader(filename)); 060 061 String str = null; 062 while ((str = inputStream.readLine()) != null) { 063 if (StringUtils.isNotBlank(str)) { 064 ACHBank ab = new ACHBank(str); 065 this.businessObjectService.save(ab); 066 } 067 } 068 } 069 catch (FileNotFoundException fnfe) { 070 LOG.error("reloadTable() File Not Found: " + filename, fnfe); 071 return false; 072 } 073 catch (IOException ie) { 074 LOG.error("reloadTable() Problem reading file: " + filename, ie); 075 return false; 076 } 077 finally { 078 if (inputStream != null) { 079 try { 080 inputStream.close(); 081 } 082 catch (IOException ie) { 083 // Not much we can do now 084 } 085 } 086 } 087 088 return true; 089 } 090 091 /** 092 * Sets the businessObjectService attribute value. 093 * 094 * @param businessObjectService The businessObjectService to set. 095 */ 096 public void setBusinessObjectService(BusinessObjectService businessObjectService) { 097 this.businessObjectService = businessObjectService; 098 } 099 100}