View Javadoc

1   /*
2    * Copyright 2006 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.coa.service.impl;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.coa.businessobject.A21IndirectCostRecoveryAccount;
23  import org.kuali.ole.coa.businessobject.A21SubAccount;
24  import org.kuali.ole.coa.businessobject.Account;
25  import org.kuali.ole.coa.businessobject.IndirectCostRecoveryAccount;
26  import org.kuali.ole.coa.dataaccess.A21SubAccountDao;
27  import org.kuali.ole.coa.service.A21SubAccountService;
28  import org.kuali.ole.coa.service.AccountService;
29  import org.kuali.ole.sys.OLEConstants;
30  import org.kuali.ole.sys.OLEPropertyConstants;
31  import org.kuali.ole.sys.context.SpringContext;
32  import org.kuali.ole.sys.service.NonTransactional;
33  import org.kuali.rice.krad.service.BusinessObjectService;
34  import org.kuali.rice.krad.util.ObjectUtils;
35  
36  /**
37   * This class is the default implementation of the A21SubAccountService
38   */
39  
40  @NonTransactional
41  public class A21SubAccountServiceImpl implements A21SubAccountService {
42  
43      private A21SubAccountDao a21SubAccountDao;
44      private AccountService accountService;
45  
46      /**
47       * @see org.kuali.ole.coa.service.A21SubAccountService#getByPrimaryKey(java.lang.String, java.lang.String, java.lang.String)
48       */
49      public A21SubAccount getByPrimaryKey(String chartOfAccountsCode, String accountNumber, String subAccountNumber) {
50          Map<String, Object> keys = new HashMap<String, Object>();
51          keys.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
52          keys.put(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
53          keys.put(OLEPropertyConstants.SUB_ACCOUNT_NUMBER, subAccountNumber);
54          return (A21SubAccount) SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(A21SubAccount.class, keys);
55      }
56  
57      /**
58       * @see org.kuali.ole.coa.service.A21SubAccountService#buildCgIcrAccount(java.lang.String, java.lang.String, java.lang.String,
59       *      java.lang.String)
60       */
61      public A21SubAccount buildCgIcrAccount(String chartOfAccountsCode, String accountNumber, String subAccountNumber, String subAccountTypeCode) {
62          if (StringUtils.isEmpty(chartOfAccountsCode) || StringUtils.isEmpty(accountNumber) || StringUtils.equals(subAccountTypeCode, OLEConstants.SubAccountType.COST_SHARE)) {
63              return null;
64          }
65  
66          A21SubAccount a21SubAccount = new A21SubAccount();
67          a21SubAccount.setSubAccountNumber(subAccountNumber);
68          a21SubAccount.setSubAccountTypeCode(subAccountTypeCode);
69  
70          this.populateCgIcrAccount(a21SubAccount, chartOfAccountsCode, accountNumber);
71  
72          return a21SubAccount;
73      }
74  
75      /**
76       * @see org.kuali.ole.coa.service.A21SubAccountService#populateCgIcrAccount(org.kuali.ole.coa.businessobject.A21SubAccount,
77       *      java.lang.String, java.lang.String)
78       */
79      public void populateCgIcrAccount(A21SubAccount a21SubAccount, String chartOfAccountsCode, String accountNumber) {
80          Account account = accountService.getByPrimaryIdWithCaching(chartOfAccountsCode, accountNumber);
81  
82          if (ObjectUtils.isNotNull(account) && ObjectUtils.isNotNull(a21SubAccount) && !StringUtils.equals(a21SubAccount.getSubAccountTypeCode(), OLEConstants.SubAccountType.COST_SHARE)) {
83              a21SubAccount.setChartOfAccountsCode(account.getChartOfAccountsCode());
84              a21SubAccount.setAccountNumber(account.getAccountNumber());
85              a21SubAccount.setFinancialIcrSeriesIdentifier(StringUtils.defaultString(account.getFinancialIcrSeriesIdentifier()));
86  
87              //deactivate old ICR lists
88              for (A21IndirectCostRecoveryAccount a21Icr : a21SubAccount.getA21IndirectCostRecoveryAccounts()){
89                  a21Icr.setActive(false);
90              }
91              //add new lists from account
92              for (IndirectCostRecoveryAccount icrAccount : account.getActiveIndirectCostRecoveryAccounts()){
93                  a21SubAccount.getA21IndirectCostRecoveryAccounts().add(A21IndirectCostRecoveryAccount.copyICRAccount(icrAccount));
94              }
95              a21SubAccount.setIndirectCostRecoveryTypeCode(account.getAcctIndirectCostRcvyTypeCd());
96              a21SubAccount.setOffCampusCode(account.isAccountOffCampusIndicator());
97          }
98      }
99  
100     /**
101      * @param subAccountDao The a21SubAccountDao to set.
102      */
103     public void setA21SubAccountDao(A21SubAccountDao subAccountDao) {
104         this.a21SubAccountDao = subAccountDao;
105     }
106 
107     /**
108      * Sets the accountService attribute value.
109      * 
110      * @param accountService The accountService to set.
111      */
112     public void setAccountService(AccountService accountService) {
113         this.accountService = accountService;
114     }
115 }