1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document;
17
18 import java.util.Iterator;
19 import java.util.Map;
20
21 import org.apache.log4j.Logger;
22 import org.kuali.ole.coa.businessobject.Account;
23 import org.kuali.ole.coa.service.AccountPersistenceStructureService;
24 import org.kuali.ole.coa.service.AccountService;
25 import org.kuali.ole.sys.OLEPropertyConstants;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.rice.kns.document.MaintenanceDocument;
28 import org.kuali.rice.kns.maintenance.KualiGlobalMaintainableImpl;
29 import org.kuali.rice.krad.bo.BusinessObject;
30 import org.kuali.rice.krad.bo.PersistableBusinessObject;
31 import org.kuali.rice.krad.util.ObjectUtils;
32
33
34
35
36 public abstract class FinancialSystemGlobalMaintainable extends KualiGlobalMaintainableImpl {
37 private static final Logger LOG = Logger.getLogger(FinancialSystemGlobalMaintainable.class);
38
39 protected boolean answerSplitNodeQuestion(String nodeName) throws UnsupportedOperationException {
40 throw new UnsupportedOperationException("FinancialSystemGlobalMaintainable does not implement the answerSplitNodeQuestion method. Node name specified was: " + nodeName);
41 }
42
43
44
45
46 @Override
47 protected void refreshReferences(String referencesToRefresh) {
48
49 if (!SpringContext.getBean(AccountService.class).accountsCanCrossCharts()) {
50 populateChartOfAccountsCodeFields();
51 }
52
53 super.refreshReferences(referencesToRefresh);
54 }
55
56
57
58
59 @Override
60 public void processBeforeAddLine(String colName, Class colClass, BusinessObject bo) {
61 super.processBeforeAddLine(colName, colClass, bo);
62
63
64 if (!SpringContext.getBean(AccountService.class).accountsCanCrossCharts()) {
65 populateChartOfAccountsCodeFields();
66 }
67 }
68
69
70
71
72 @Override
73 public void processAfterPost(MaintenanceDocument document, Map<String, String[]> parameters) {
74 super.processAfterPost(document, parameters);
75
76
77 if (!SpringContext.getBean(AccountService.class).accountsCanCrossCharts()) {
78 populateChartOfAccountsCodeFields();
79 }
80 }
81
82
83
84
85
86 protected void populateChartOfAccountsCodeFields() {
87 AccountService acctService = SpringContext.getBean(AccountService.class);
88 AccountPersistenceStructureService apsService = SpringContext.getBean(AccountPersistenceStructureService.class);
89
90
91 PersistableBusinessObject bo = getBusinessObject();
92 Iterator<Map.Entry<String, String>> chartAccountPairs = apsService.listChartCodeAccountNumberPairs(bo).entrySet().iterator();
93 while (chartAccountPairs.hasNext()) {
94 Map.Entry<String, String> entry = (Map.Entry<String, String>)chartAccountPairs.next();
95 String coaCodeName = entry.getKey();
96 String acctNumName = entry.getValue();
97 String accountNumber = (String)ObjectUtils.getPropertyValue(bo, acctNumName);
98 String coaCode = null;
99 Account account = acctService.getUniqueAccountForAccountNumber(accountNumber);
100 if (ObjectUtils.isNotNull(account)) {
101 coaCode = account.getChartOfAccountsCode();
102 }
103 try {
104 ObjectUtils.setObjectProperty(bo, coaCodeName, coaCode);
105 }
106 catch (Exception e) {
107 LOG.error("Error in setting property value for " + coaCodeName, e);
108 }
109 }
110
111
112 Iterator<Map.Entry<String, Class>> accountColls = apsService.listCollectionAccountFields(bo).entrySet().iterator();
113 while (accountColls.hasNext()) {
114 Map.Entry<String, Class> entry = (Map.Entry<String, Class>)accountColls.next();
115 String accountCollName = entry.getKey();
116 PersistableBusinessObject newAccount = getNewCollectionLine(accountCollName);
117
118
119
120 String accountNumber = (String)ObjectUtils.getPropertyValue(newAccount, OLEPropertyConstants.ACCOUNT_NUMBER);
121 String coaCode = null;
122 Account account = acctService.getUniqueAccountForAccountNumber(accountNumber);
123 if (ObjectUtils.isNotNull(account)) {
124 coaCode = account.getChartOfAccountsCode();
125 try {
126 ObjectUtils.setObjectProperty(newAccount, OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, coaCode);
127 }
128 catch (Exception e) {
129 LOG.error("Error in setting chartOfAccountsCode property value in account collection " + accountCollName, e);
130 }
131 }
132 }
133 }
134
135 }