View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.pdp.service.impl;
20  
21  import java.io.BufferedReader;
22  import java.io.FileNotFoundException;
23  import java.io.FileReader;
24  import java.io.IOException;
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  import org.apache.commons.lang.StringUtils;
29  import org.kuali.kfs.pdp.PdpPropertyConstants;
30  import org.kuali.kfs.pdp.businessobject.ACHBank;
31  import org.kuali.kfs.pdp.service.AchBankService;
32  import org.kuali.rice.krad.service.BusinessObjectService;
33  import org.springframework.transaction.annotation.Transactional;
34  
35  @Transactional
36  public class AchBankServiceImpl implements AchBankService {
37      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AchBankServiceImpl.class);
38  
39      private BusinessObjectService businessObjectService;
40  
41      /**
42       * @see org.kuali.kfs.pdp.service.AchBankService#getByPrimaryId(java.lang.String)
43       */
44      public ACHBank getByPrimaryId(String bankRoutingNumber) {
45          Map<String, String> fieldKeys = new HashMap<String, String>();
46          fieldKeys.put(PdpPropertyConstants.BANK_ROUTING_NUMBER, bankRoutingNumber);
47  
48          return (ACHBank) businessObjectService.findByPrimaryKey(ACHBank.class, fieldKeys);
49      }
50  
51      /**
52       * @see org.kuali.kfs.pdp.service.AchBankService#reloadTable(java.lang.String)
53       */
54      public boolean reloadTable(String filename) {
55          LOG.debug("reloadTable() started");
56          
57          // clear out previous records
58          businessObjectService.deleteMatching(ACHBank.class, new HashMap());
59  
60          BufferedReader inputStream = null;
61          try {
62              inputStream = new BufferedReader(new FileReader(filename));
63  
64              String str = null;
65              while ((str = inputStream.readLine()) != null) {
66                  if (StringUtils.isNotBlank(str)) {
67                      ACHBank ab = new ACHBank(str);
68                      this.businessObjectService.save(ab);
69                  }
70              }
71          }
72          catch (FileNotFoundException fnfe) {
73              LOG.error("reloadTable() File Not Found: " + filename, fnfe);
74              return false;
75          }
76          catch (IOException ie) {
77              LOG.error("reloadTable() Problem reading file:  " + filename, ie);
78              return false;
79          }
80          finally {
81              if (inputStream != null) {
82                  try {
83                      inputStream.close();
84                  }
85                  catch (IOException ie) {
86                      // Not much we can do now
87                  }
88              }
89          }
90          
91          return true;
92      }
93  
94      /**
95       * Sets the businessObjectService attribute value.
96       * 
97       * @param businessObjectService The businessObjectService to set.
98       */
99      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
100         this.businessObjectService = businessObjectService;
101     }
102 
103 }