1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sec.businessobject.lookup;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.ole.coa.service.ObjectTypeService;
25 import org.kuali.ole.gl.GeneralLedgerConstants;
26 import org.kuali.ole.gl.businessobject.AccountBalance;
27 import org.kuali.ole.gl.businessobject.TransientBalanceInquiryAttributes;
28 import org.kuali.ole.gl.businessobject.lookup.AccountBalanceByConsolidationLookupableHelperServiceImpl;
29 import org.kuali.ole.gl.service.AccountBalanceService;
30 import org.kuali.ole.sec.SecKeyConstants;
31 import org.kuali.ole.sec.service.AccessSecurityService;
32 import org.kuali.ole.sec.util.SecUtil;
33 import org.kuali.ole.sys.OLEConstants;
34 import org.kuali.ole.sys.OLEKeyConstants;
35 import org.kuali.ole.sys.OLEPropertyConstants;
36 import org.kuali.ole.sys.context.SpringContext;
37 import org.kuali.rice.core.api.config.property.ConfigurationService;
38 import org.kuali.rice.krad.bo.BusinessObject;
39 import org.kuali.rice.krad.lookup.CollectionIncomplete;
40 import org.kuali.rice.krad.util.GlobalVariables;
41
42
43
44
45
46 public class AccessSecurityAccountBalanceByConsolidationLookupableHelperServiceImpl extends AccountBalanceByConsolidationLookupableHelperServiceImpl {
47 protected AccessSecurityService accessSecurityService;
48 protected ObjectTypeService objectTypeService;
49 protected ConfigurationService kualiConfigurationService;
50
51
52
53
54
55
56
57 @Override
58 public List<? extends BusinessObject> getSearchResults(Map fieldValues) {
59 AccountBalanceByConsolidationLookupableHelperServiceImpl helperServiceImpl = new AccountBalanceByConsolidationLookupableHelperServiceImpl();
60 helperServiceImpl.setAccountBalanceService(SpringContext.getBean(AccountBalanceService.class));
61 List<? extends BusinessObject> results = helperServiceImpl.getSearchResults(fieldValues);
62
63
64 if (results.size() > 7) {
65 List details = results.subList(7, results.size());
66
67 int resultSizeBeforeRestrictions = details.size();
68 accessSecurityService.applySecurityRestrictionsForGLInquiry(details, GlobalVariables.getUserSession().getPerson());
69
70 accessSecurityService.compareListSizeAndAddMessageIfChanged(resultSizeBeforeRestrictions, details, SecKeyConstants.MESSAGE_BALANCE_INQUIRY_RESULTS_RESTRICTED);
71
72
73 if (resultSizeBeforeRestrictions != details.size()) {
74 String subAccountNumber = (String) fieldValues.get(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
75 String fiscalYear = (String) fieldValues.get(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR);
76 Integer universityFiscalYear = new Integer(Integer.parseInt(fiscalYear));
77
78
79 if (OLEConstants.getDashSubAccountNumber().equals(subAccountNumber)) {
80 subAccountNumber = "";
81 }
82
83 TransientBalanceInquiryAttributes dbo = ((AccountBalance) results.get(0)).getDummyBusinessObject();
84
85 List totals = buildAccountBalanceTotals(details, universityFiscalYear, subAccountNumber, dbo);
86 totals.addAll(details);
87
88 return new CollectionIncomplete(totals, new Long(totals.size()));
89 }
90 }
91
92 return results;
93 }
94
95
96
97
98
99
100
101
102
103
104 protected List buildAccountBalanceTotals(List balanceDetails, Integer universityFiscalYear, String subAccountNumber, TransientBalanceInquiryAttributes dbo) {
105 List totals = new ArrayList();
106
107 List incomeObjectTypes = objectTypeService.getBasicIncomeObjectTypes(universityFiscalYear);
108 String incomeTransferObjectType = objectTypeService.getIncomeTransferObjectType(universityFiscalYear);
109 List expenseObjectTypes = objectTypeService.getBasicExpenseObjectTypes(universityFiscalYear);
110 String expenseTransferObjectType = objectTypeService.getExpenseTransferObjectType(universityFiscalYear);
111
112 AccountBalance income = new AccountBalance(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.AccountBalanceService.INCOME));
113 AccountBalance incomeTransfers = new AccountBalance(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.AccountBalanceService.INCOME_FROM_TRANSFERS));
114 AccountBalance incomeTotal = new AccountBalance(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.AccountBalanceService.INCOME_TOTAL));
115 AccountBalance expense = new AccountBalance(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.AccountBalanceService.EXPENSE));
116 AccountBalance expenseTransfers = new AccountBalance(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.AccountBalanceService.EXPENSE_FROM_TRANSFERS));
117 AccountBalance expenseTotal = new AccountBalance(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.AccountBalanceService.EXPENSE_TOTAL));
118 AccountBalance total = new AccountBalance(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.AccountBalanceService.TOTAL));
119
120 totals.add(income);
121 totals.add(incomeTransfers);
122 totals.add(incomeTotal);
123 totals.add(expense);
124 totals.add(expenseTransfers);
125 totals.add(expenseTotal);
126 totals.add(total);
127
128
129 for (Iterator iterator = totals.iterator(); iterator.hasNext();) {
130 AccountBalance totalBalance = (AccountBalance) iterator.next();
131 total.setDummyBusinessObject(dbo);
132 }
133
134 boolean subAccountBlank = StringUtils.isBlank(subAccountNumber);
135
136
137 for (Iterator iterator = balanceDetails.iterator(); iterator.hasNext();) {
138 AccountBalance detail = (AccountBalance) iterator.next();
139 String objectType = detail.getFinancialObject().getFinancialObjectTypeCode();
140
141 if (incomeObjectTypes.contains(objectType)) {
142 String transferExpenseCode = detail.getFinancialObject().getFinancialObjectLevel().getFinancialConsolidationObject().getFinConsolidationObjectCode();
143 if (!subAccountBlank && transferExpenseCode.equals(GeneralLedgerConstants.INCOME_OR_EXPENSE_TRANSFER_CONSOLIDATION_CODE)) {
144 incomeTransfers.add(detail);
145 }
146 else {
147 income.add(detail);
148 }
149
150 incomeTotal.add(detail);
151 }
152
153 if (incomeTransferObjectType.equals(objectType)) {
154 incomeTransfers.add(detail);
155 incomeTotal.add(detail);
156 }
157
158 if (expenseObjectTypes.contains(objectType)) {
159 String transferExpenseCode = detail.getFinancialObject().getFinancialObjectLevel().getFinancialConsolidationObject().getFinConsolidationObjectCode();
160 if (!subAccountBlank && transferExpenseCode.equals(GeneralLedgerConstants.INCOME_OR_EXPENSE_TRANSFER_CONSOLIDATION_CODE)) {
161 expenseTransfers.add(detail);
162 }
163 else {
164 expense.add(detail);
165 }
166
167 expenseTotal.add(detail);
168 }
169
170 if (expenseTransferObjectType.equals(objectType)) {
171 expenseTransfers.add(detail);
172 expenseTransfers.add(detail);
173 }
174 }
175
176
177 income.getDummyBusinessObject().setGenericAmount(income.getAccountLineActualsBalanceAmount().add(income.getAccountLineEncumbranceBalanceAmount()).subtract(income.getCurrentBudgetLineBalanceAmount()));
178 incomeTransfers.getDummyBusinessObject().setGenericAmount(incomeTransfers.getAccountLineActualsBalanceAmount().add(incomeTransfers.getAccountLineEncumbranceBalanceAmount()).subtract(incomeTransfers.getCurrentBudgetLineBalanceAmount()));
179 incomeTotal.getDummyBusinessObject().setGenericAmount(income.getDummyBusinessObject().getGenericAmount().add(incomeTransfers.getDummyBusinessObject().getGenericAmount()));
180
181 expense.getDummyBusinessObject().setGenericAmount(expense.getCurrentBudgetLineBalanceAmount().subtract(expense.getAccountLineActualsBalanceAmount()).subtract(expense.getAccountLineEncumbranceBalanceAmount()));
182 expenseTransfers.getDummyBusinessObject().setGenericAmount(expenseTransfers.getCurrentBudgetLineBalanceAmount().subtract(expenseTransfers.getAccountLineActualsBalanceAmount()).subtract(expenseTransfers.getAccountLineEncumbranceBalanceAmount()));
183 expenseTotal.getDummyBusinessObject().setGenericAmount(expense.getDummyBusinessObject().getGenericAmount().add(expenseTransfers.getDummyBusinessObject().getGenericAmount()));
184
185 total.getDummyBusinessObject().setGenericAmount(incomeTotal.getDummyBusinessObject().getGenericAmount().add(expenseTotal.getDummyBusinessObject().getGenericAmount()));
186
187 return totals;
188 }
189
190
191
192
193
194
195 public void setAccessSecurityService(AccessSecurityService accessSecurityService) {
196 this.accessSecurityService = accessSecurityService;
197 }
198
199
200
201
202
203
204 public void setObjectTypeService(ObjectTypeService objectTypeService) {
205 this.objectTypeService = objectTypeService;
206 }
207
208
209
210
211
212
213 public void setConfigurationService(ConfigurationService kualiConfigurationService) {
214 this.kualiConfigurationService = kualiConfigurationService;
215 }
216
217 }