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.batch.service.CacheService;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.rice.kns.document.MaintenanceDocument;
29 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
30 import org.kuali.rice.krad.bo.BusinessObject;
31 import org.kuali.rice.krad.bo.PersistableBusinessObject;
32 import org.kuali.rice.krad.util.ObjectUtils;
33
34
35
36
37 public class FinancialSystemMaintainable extends KualiMaintainableImpl {
38 private static final Logger LOG = Logger.getLogger(FinancialSystemMaintainable.class);
39
40
41
42
43 public FinancialSystemMaintainable() {
44 super();
45 }
46
47
48
49
50
51
52 public FinancialSystemMaintainable(PersistableBusinessObject businessObject) {
53 super(businessObject);
54 }
55
56
57
58
59
60
61
62 protected boolean answerSplitNodeQuestion(String nodeName) throws UnsupportedOperationException {
63 throw new UnsupportedOperationException("FinancialSystemMaintainable does not implement the answerSplitNodeQuestion method. Node name specified was: " + nodeName);
64
65 }
66
67
68
69
70 @Override
71 protected void refreshReferences(String referencesToRefresh) {
72
73 if (!SpringContext.getBean(AccountService.class).accountsCanCrossCharts()) {
74 populateChartOfAccountsCodeFields();
75 }
76
77 super.refreshReferences(referencesToRefresh);
78 }
79
80
81
82
83 @Override
84
85 public void processBeforeAddLine(String colName, Class colClass, BusinessObject bo) {
86
87 super.processBeforeAddLine(colName, colClass, bo);
88
89
90 if (!SpringContext.getBean(AccountService.class).accountsCanCrossCharts()) {
91 populateChartOfAccountsCodeFields();
92 }
93 }
94
95
96
97
98 @Override
99 public void processAfterPost(MaintenanceDocument document, Map<String, String[]> parameters) {
100 super.processAfterPost(document, parameters);
101
102
103 if (!SpringContext.getBean(AccountService.class).accountsCanCrossCharts()) {
104 populateChartOfAccountsCodeFields();
105 }
106 }
107
108
109
110
111
112 protected void populateChartOfAccountsCodeFields() {
113 AccountService acctService = SpringContext.getBean(AccountService.class);
114 AccountPersistenceStructureService apsService = SpringContext.getBean(AccountPersistenceStructureService.class);
115
116
117 PersistableBusinessObject bo = getBusinessObject();
118 Iterator<Map.Entry<String, String>> chartAccountPairs = apsService.listChartCodeAccountNumberPairs(bo).entrySet().iterator();
119 while (chartAccountPairs.hasNext()) {
120 Map.Entry<String, String> entry = chartAccountPairs.next();
121 String coaCodeName = entry.getKey();
122 String acctNumName = entry.getValue();
123 String accountNumber = (String)ObjectUtils.getPropertyValue(bo, acctNumName);
124 String coaCode = null;
125 Account account = acctService.getUniqueAccountForAccountNumber(accountNumber);
126 if (ObjectUtils.isNotNull(account)) {
127 coaCode = account.getChartOfAccountsCode();
128 }
129 try {
130 ObjectUtils.setObjectProperty(bo, coaCodeName, coaCode);
131 }
132 catch (Exception e) {
133 LOG.error("Error in setting property value for " + coaCodeName,e);
134 }
135 }
136
137
138 Iterator<Map.Entry<String, Class>> accountColls = apsService.listCollectionAccountFields(bo).entrySet().iterator();
139 while (accountColls.hasNext()) {
140 Map.Entry<String, Class> entry = accountColls.next();
141 String accountCollName = entry.getKey();
142 PersistableBusinessObject newAccount = getNewCollectionLine(accountCollName);
143
144
145
146 String accountNumber = (String)ObjectUtils.getPropertyValue(newAccount, OLEPropertyConstants.ACCOUNT_NUMBER);
147 String coaCode = null;
148 Account account = acctService.getUniqueAccountForAccountNumber(accountNumber);
149 if (ObjectUtils.isNotNull(account)) {
150 coaCode = account.getChartOfAccountsCode();
151 try {
152 ObjectUtils.setObjectProperty(newAccount, OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, coaCode);
153 }
154 catch (Exception e) {
155 LOG.error("Error in setting chartOfAccountsCode property value in account collection " + accountCollName,e);
156 }
157 }
158 }
159 }
160
161 @Override
162 public void saveBusinessObject() {
163 super.saveBusinessObject();
164
165 SpringContext.getBean(CacheService.class).clearKfsBusinessObjectCache(getBoClass());
166 }
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 }