1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
38
39
40 @NonTransactional
41 public class A21SubAccountServiceImpl implements A21SubAccountService {
42
43 private A21SubAccountDao a21SubAccountDao;
44 private AccountService accountService;
45
46
47
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
59
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
77
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
88 for (A21IndirectCostRecoveryAccount a21Icr : a21SubAccount.getA21IndirectCostRecoveryAccounts()){
89 a21Icr.setActive(false);
90 }
91
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
102
103 public void setA21SubAccountDao(A21SubAccountDao subAccountDao) {
104 this.a21SubAccountDao = subAccountDao;
105 }
106
107
108
109
110
111
112 public void setAccountService(AccountService accountService) {
113 this.accountService = accountService;
114 }
115 }