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.coa.service.impl;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.kfs.coa.businessobject.A21SubAccount;
020 import org.kuali.kfs.coa.businessobject.Account;
021 import org.kuali.kfs.coa.dataaccess.A21SubAccountDao;
022 import org.kuali.kfs.coa.service.A21SubAccountService;
023 import org.kuali.kfs.coa.service.AccountService;
024 import org.kuali.kfs.sys.KFSConstants;
025 import org.kuali.kfs.sys.service.NonTransactional;
026 import org.kuali.rice.kns.util.ObjectUtils;
027
028 /**
029 * This class is the default implementation of the A21SubAccountService
030 */
031
032 @NonTransactional
033 public class A21SubAccountServiceImpl implements A21SubAccountService {
034
035 private A21SubAccountDao a21SubAccountDao;
036 private AccountService accountService;
037
038 /**
039 * @see org.kuali.kfs.coa.service.A21SubAccountService#getByPrimaryKey(java.lang.String, java.lang.String, java.lang.String)
040 */
041 public A21SubAccount getByPrimaryKey(String chartOfAccountsCode, String accountNumber, String subAccountNumber) {
042 return a21SubAccountDao.getByPrimaryKey(chartOfAccountsCode, accountNumber, subAccountNumber);
043 }
044
045 /**
046 * @see org.kuali.kfs.coa.service.A21SubAccountService#buildCgIcrAccount(java.lang.String, java.lang.String, java.lang.String,
047 * java.lang.String)
048 */
049 public A21SubAccount buildCgIcrAccount(String chartOfAccountsCode, String accountNumber, String subAccountNumber, String subAccountTypeCode) {
050 if (StringUtils.isEmpty(chartOfAccountsCode) || StringUtils.isEmpty(accountNumber) || StringUtils.equals(subAccountTypeCode, KFSConstants.SubAccountType.COST_SHARE)) {
051 return null;
052 }
053
054 A21SubAccount a21SubAccount = new A21SubAccount();
055 a21SubAccount.setSubAccountNumber(subAccountNumber);
056 a21SubAccount.setSubAccountTypeCode(subAccountTypeCode);
057
058 this.populateCgIcrAccount(a21SubAccount, chartOfAccountsCode, accountNumber);
059
060 return a21SubAccount;
061 }
062
063 /**
064 * @see org.kuali.kfs.coa.service.A21SubAccountService#populateCgIcrAccount(org.kuali.kfs.coa.businessobject.A21SubAccount,
065 * java.lang.String, java.lang.String)
066 */
067 public void populateCgIcrAccount(A21SubAccount a21SubAccount, String chartOfAccountsCode, String accountNumber) {
068 Account account = accountService.getByPrimaryIdWithCaching(chartOfAccountsCode, accountNumber);
069
070 if (ObjectUtils.isNotNull(account) && ObjectUtils.isNotNull(a21SubAccount) && !StringUtils.equals(a21SubAccount.getSubAccountTypeCode(), KFSConstants.SubAccountType.COST_SHARE)) {
071 a21SubAccount.setChartOfAccountsCode(account.getChartOfAccountsCode());
072 a21SubAccount.setAccountNumber(account.getAccountNumber());
073 a21SubAccount.setFinancialIcrSeriesIdentifier(account.getFinancialIcrSeriesIdentifier());
074
075 a21SubAccount.setIndirectCostRcvyFinCoaCode(account.getIndirectCostRcvyFinCoaCode());
076 a21SubAccount.setIndirectCostRecoveryAcctNbr(account.getIndirectCostRecoveryAcctNbr());
077 a21SubAccount.setIndirectCostRecoveryTypeCode(account.getAcctIndirectCostRcvyTypeCd());
078
079 a21SubAccount.setOffCampusCode(account.isAccountOffCampusIndicator());
080 }
081 }
082
083 /**
084 * @param subAccountDao The a21SubAccountDao to set.
085 */
086 public void setA21SubAccountDao(A21SubAccountDao subAccountDao) {
087 this.a21SubAccountDao = subAccountDao;
088 }
089
090 /**
091 * Sets the accountService attribute value.
092 *
093 * @param accountService The accountService to set.
094 */
095 public void setAccountService(AccountService accountService) {
096 this.accountService = accountService;
097 }
098 }