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.sys.service.impl; 017 018 import java.util.HashMap; 019 import java.util.List; 020 import java.util.Map; 021 022 import org.apache.commons.lang.StringUtils; 023 import org.kuali.kfs.sys.KFSParameterKeyConstants; 024 import org.kuali.kfs.sys.KFSPropertyConstants; 025 import org.kuali.kfs.sys.businessobject.Bank; 026 import org.kuali.kfs.sys.service.BankService; 027 import org.kuali.rice.kns.service.BusinessObjectService; 028 import org.kuali.rice.kns.service.DataDictionaryService; 029 import org.kuali.rice.kns.service.ParameterService; 030 031 /** 032 * Default implementation of the <code>BankService</code> interface. 033 * 034 * @see org.kuali.kfs.fp.service.BankService 035 */ 036 public class BankServiceImpl implements BankService { 037 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BankServiceImpl.class); 038 039 private BusinessObjectService businessObjectService; 040 private DataDictionaryService dataDictionaryService; 041 private ParameterService parameterService; 042 043 /** 044 * @see org.kuali.kfs.fp.service.BankService#getByPrimaryId(java.lang.String) 045 */ 046 public Bank getByPrimaryId(String bankCode) { 047 Map primaryKeys = new HashMap(); 048 primaryKeys.put(KFSPropertyConstants.BANK_CODE, bankCode); 049 050 return (Bank) businessObjectService.findByPrimaryKey(Bank.class, primaryKeys); 051 } 052 053 /** 054 * @see org.kuali.kfs.sys.service.BankService#getDefaultBankByDocType(java.lang.String) 055 */ 056 public Bank getDefaultBankByDocType(String documentTypeCode) { 057 if (parameterService.parameterExists(Bank.class, KFSParameterKeyConstants.DEFAULT_BANK_BY_DOCUMENT_TYPE)) { 058 List<String> parmValues = parameterService.getParameterValues(Bank.class, KFSParameterKeyConstants.DEFAULT_BANK_BY_DOCUMENT_TYPE, documentTypeCode); 059 if (parmValues != null && !parmValues.isEmpty()) { 060 String defaultBankCode = parmValues.get(0); 061 062 Bank defaultBank = this.getByPrimaryId(defaultBankCode); 063 064 // check active status, if not return continuation bank if active 065 if (!defaultBank.isActive() && defaultBank.getContinuationBank() != null && defaultBank.getContinuationBank().isActive()) { 066 return defaultBank.getContinuationBank(); 067 } 068 069 return defaultBank; 070 } 071 } 072 return null; 073 } 074 075 /** 076 * @see org.kuali.kfs.sys.service.BankService#getDefaultBankByDocType(java.lang.Class) 077 */ 078 public Bank getDefaultBankByDocType(Class documentClass) { 079 final String documentTypeCode = getDataDictionaryService().getDocumentTypeNameByClass(documentClass); 080 081 if (StringUtils.isBlank(documentTypeCode)) { 082 throw new RuntimeException("Document type not found for document class: " + documentClass.getName()); 083 } 084 return getDefaultBankByDocType(documentTypeCode); 085 } 086 087 /** 088 * @see org.kuali.kfs.sys.service.BankService#isBankSpecificationEnabled() 089 */ 090 public boolean isBankSpecificationEnabled() { 091 return parameterService.getIndicatorParameter(Bank.class, KFSParameterKeyConstants.ENABLE_BANK_SPECIFICATION_IND); 092 } 093 094 /** 095 * Sets the businessObjectService attribute value. 096 * 097 * @param businessObjectService The businessObjectService to set. 098 */ 099 public void setBusinessObjectService(BusinessObjectService businessObjectService) { 100 this.businessObjectService = businessObjectService; 101 } 102 103 /** 104 * Gets the dataDictionaryService attribute. 105 * @return Returns the dataDictionaryService. 106 */ 107 public DataDictionaryService getDataDictionaryService() { 108 return dataDictionaryService; 109 } 110 111 /** 112 * Sets the dataDictionaryService attribute value. 113 * @param dataDictionaryService The dataDictionaryService to set. 114 */ 115 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) { 116 this.dataDictionaryService = dataDictionaryService; 117 } 118 119 /** 120 * Sets the parameterService attribute value. 121 * 122 * @param parameterService The parameterService to set. 123 */ 124 public void setParameterService(ParameterService parameterService) { 125 this.parameterService = parameterService; 126 } 127 }