001 /*
002 * Copyright 2011 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 */
016 package org.kuali.kfs.pdp.service.impl;
017
018 import java.io.BufferedReader;
019 import java.io.FileNotFoundException;
020 import java.io.FileReader;
021 import java.io.IOException;
022 import java.util.HashMap;
023 import java.util.Map;
024
025 import org.apache.commons.lang.StringUtils;
026 import org.kuali.kfs.pdp.PdpPropertyConstants;
027 import org.kuali.kfs.pdp.businessobject.ACHBank;
028 import org.kuali.kfs.pdp.service.AchBankService;
029 import org.kuali.rice.kns.service.BusinessObjectService;
030 import org.springframework.transaction.annotation.Transactional;
031
032 @Transactional
033 public 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.kfs.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.kfs.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 }