01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.pdp.service.impl;
17:
18: import java.io.BufferedReader;
19: import java.io.FileNotFoundException;
20: import java.io.FileReader;
21: import java.io.IOException;
22:
23: import org.kuali.module.pdp.bo.AchBank;
24: import org.kuali.module.pdp.dao.AchBankDao;
25: import org.kuali.module.pdp.service.AchBankService;
26: import org.springframework.transaction.annotation.Transactional;
27:
28: @Transactional
29: public class AchBankServiceImpl implements AchBankService {
30: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
31: .getLogger(AchBankServiceImpl.class);
32:
33: private AchBankDao achBankDao;
34:
35: /**
36: * @see org.kuali.module.pdp.service.AchBankService#save(org.kuali.module.pdp.bo.AchBank)
37: */
38: public void save(AchBank ab) {
39: LOG.debug("save() started");
40:
41: achBankDao.save(ab);
42: }
43:
44: /**
45: * @see org.kuali.module.pdp.service.AchBankService#reloadTable(java.lang.String)
46: */
47: public boolean reloadTable(String filename) {
48: LOG.debug("reloadTable() started");
49:
50: BufferedReader inputStream = null;
51:
52: try {
53: inputStream = new BufferedReader(new FileReader(filename));
54:
55: String str = null;
56: while ((str = inputStream.readLine()) != null) {
57: String bankRoutingNumber = getField(str, 1, 9);
58:
59: AchBank tableBank = achBankDao
60: .getBank(bankRoutingNumber);
61: AchBank ab = new AchBank(str);
62: if (tableBank != null) {
63: ab.setVersionNumber(tableBank.getVersionNumber());
64: }
65: achBankDao.save(ab);
66: }
67: } catch (FileNotFoundException fnfe) {
68: LOG
69: .error("reloadTable() File Not Found: " + filename,
70: fnfe);
71: return false;
72: } catch (IOException ie) {
73: LOG.error("reloadTable() Problem reading file: "
74: + filename, ie);
75: return false;
76: } finally {
77: if (inputStream != null) {
78: try {
79: inputStream.close();
80: } catch (IOException ie) {
81: // Not much we can do now
82: }
83: }
84: }
85: return true;
86: }
87:
88: private String getField(String data, int startChar, int length) {
89: return data.substring(startChar - 1, startChar + length - 1)
90: .trim();
91: }
92:
93: public void setAchBankDao(AchBankDao abd) {
94: achBankDao = abd;
95: }
96: }
|