1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.document;
17
18 import java.util.Map;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.log4j.Logger;
22 import org.kuali.ole.coa.businessobject.A21SubAccount;
23 import org.kuali.ole.coa.businessobject.Account;
24 import org.kuali.ole.coa.businessobject.SubAccount;
25 import org.kuali.ole.coa.service.A21SubAccountService;
26 import org.kuali.ole.coa.service.AccountService;
27 import org.kuali.ole.sys.OLEConstants;
28 import org.kuali.ole.sys.OLEPropertyConstants;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.ole.sys.document.FinancialSystemMaintainable;
31 import org.kuali.rice.kim.api.identity.Person;
32 import org.kuali.rice.kns.document.MaintenanceDocument;
33 import org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions;
34 import org.kuali.rice.krad.bo.PersistableBusinessObject;
35 import org.kuali.rice.krad.util.GlobalVariables;
36 import org.kuali.rice.krad.util.ObjectUtils;
37
38
39
40
41 public class SubAccountMaintainableImpl extends FinancialSystemMaintainable {
42 private static final Logger LOG = Logger.getLogger(SubAccountMaintainableImpl.class);
43
44
45 public static final String[] COA_CODE_NAMES = {
46 OLEPropertyConstants.A21_SUB_ACCOUNT + "." + OLEPropertyConstants.COST_SHARE_SOURCE_CHART_OF_ACCOUNTS_CODE,
47 };
48 public static final String[] ACCOUNT_NUMBER_NAMES = {
49 OLEPropertyConstants.A21_SUB_ACCOUNT + "." + OLEPropertyConstants.COST_SHARE_SOURCE_ACCOUNT_NUMBER,
50 };
51
52
53
54
55
56 @Override
57 public void refresh(String refreshCaller, Map fieldValues, MaintenanceDocument document) {
58 super.refresh(refreshCaller, fieldValues, document);
59
60 Person person = GlobalVariables.getUserSession().getPerson();
61 MaintenanceDocumentRestrictions restrictions = getBusinessObjectAuthorizationService().getMaintenanceDocumentRestrictions(document, person);
62 boolean canEdit = !restrictions.isHiddenSectionId(OLEConstants.SUB_ACCOUNT_EDIT_CG_ICR_SECTION_ID) && !restrictions.isReadOnlySectionId(OLEConstants.SUB_ACCOUNT_EDIT_CG_ICR_SECTION_ID);
63
64
65 if (refreshCaller != null && (refreshCaller.toUpperCase().endsWith(OLEConstants.LOOKUPABLE_SUFFIX.toUpperCase())) && fieldValues.containsKey("document.newMaintainableObject.accountNumber") && canEdit) {
66 SubAccount subAccount = (SubAccount) this.getBusinessObject();
67 this.populateCGIcrFields(subAccount);
68 }
69 }
70
71
72 private void populateCGIcrFields(SubAccount subAccount) {
73 A21SubAccount a21SubAccount = subAccount.getA21SubAccount();
74 String chartOfAccountsCode = subAccount.getChartOfAccountsCode();
75 String accountNumber = subAccount.getAccountNumber();
76
77
78 if (ObjectUtils.isNotNull(a21SubAccount) && (!StringUtils.equals(chartOfAccountsCode, a21SubAccount.getChartOfAccountsCode()) || !StringUtils.equals(accountNumber, a21SubAccount.getAccountNumber()))) {
79 A21SubAccountService a21SubAccountService = SpringContext.getBean(A21SubAccountService.class);
80 a21SubAccountService.populateCgIcrAccount(a21SubAccount, chartOfAccountsCode, accountNumber);
81 }
82 }
83
84
85
86
87
88
89
90
91 @Override
92 protected void populateChartOfAccountsCodeFields() {
93 super.populateChartOfAccountsCodeFields();
94 PersistableBusinessObject bo = getBusinessObject();
95 AccountService acctService = SpringContext.getBean(AccountService.class);
96
97 for (int i=0; i<COA_CODE_NAMES.length; i++) {
98 String coaCodeName = COA_CODE_NAMES[i];
99 String acctNumName = ACCOUNT_NUMBER_NAMES[i];
100 String accountNumber = (String)ObjectUtils.getPropertyValue(bo, acctNumName);
101 String coaCode = null;
102 Account account = acctService.getUniqueAccountForAccountNumber(accountNumber);
103 if (ObjectUtils.isNotNull(account)) {
104 coaCode = account.getChartOfAccountsCode();
105 }
106 try {
107 ObjectUtils.setObjectProperty(bo, coaCodeName, coaCode);
108 }
109 catch (Exception e) {
110 LOG.error("Error in setting property value for " + coaCodeName);
111 }
112 }
113 }
114
115 }