View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
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.ole.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  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.ole.pdp.PdpPropertyConstants;
27  import org.kuali.ole.pdp.businessobject.ACHBank;
28  import org.kuali.ole.pdp.service.AchBankService;
29  import org.kuali.rice.krad.service.BusinessObjectService;
30  import org.springframework.transaction.annotation.Transactional;
31  
32  @Transactional
33  public class AchBankServiceImpl implements AchBankService {
34      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AchBankServiceImpl.class);
35  
36      private BusinessObjectService businessObjectService;
37  
38      /**
39       * @see org.kuali.ole.pdp.service.AchBankService#getByPrimaryId(java.lang.String)
40       */
41      public ACHBank getByPrimaryId(String bankRoutingNumber) {
42          Map<String, String> fieldKeys = new HashMap<String, String>();
43          fieldKeys.put(PdpPropertyConstants.BANK_ROUTING_NUMBER, bankRoutingNumber);
44  
45          return (ACHBank) businessObjectService.findByPrimaryKey(ACHBank.class, fieldKeys);
46      }
47  
48      /**
49       * @see org.kuali.ole.pdp.service.AchBankService#reloadTable(java.lang.String)
50       */
51      public boolean reloadTable(String filename) {
52          LOG.debug("reloadTable() started");
53          
54          // clear out previous records
55          businessObjectService.deleteMatching(ACHBank.class, new HashMap());
56  
57          BufferedReader inputStream = null;
58          try {
59              inputStream = new BufferedReader(new FileReader(filename));
60  
61              String str = null;
62              while ((str = inputStream.readLine()) != null) {
63                  if (StringUtils.isNotBlank(str)) {
64                      ACHBank ab = new ACHBank(str);
65                      this.businessObjectService.save(ab);
66                  }
67              }
68          }
69          catch (FileNotFoundException fnfe) {
70              LOG.error("reloadTable() File Not Found: " + filename, fnfe);
71              return false;
72          }
73          catch (IOException ie) {
74              LOG.error("reloadTable() Problem reading file:  " + filename, ie);
75              return false;
76          }
77          finally {
78              if (inputStream != null) {
79                  try {
80                      inputStream.close();
81                  }
82                  catch (IOException ie) {
83                      // Not much we can do now
84                  }
85              }
86          }
87          
88          return true;
89      }
90  
91      /**
92       * Sets the businessObjectService attribute value.
93       * 
94       * @param businessObjectService The businessObjectService to set.
95       */
96      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
97          this.businessObjectService = businessObjectService;
98      }
99  
100 }