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