1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.businessobject.lookup;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.kuali.ole.gl.Constant;
27 import org.kuali.ole.gl.businessobject.inquiry.EntryInquirableImpl;
28 import org.kuali.ole.gl.businessobject.inquiry.InquirableFinancialDocument;
29 import org.kuali.ole.sys.OLEConstants;
30 import org.kuali.ole.sys.OLEKeyConstants;
31 import org.kuali.ole.sys.OLEPropertyConstants;
32 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
33 import org.kuali.ole.sys.businessobject.UniversityDate;
34 import org.kuali.ole.sys.context.SpringContext;
35 import org.kuali.ole.sys.service.GeneralLedgerPendingEntryService;
36 import org.kuali.ole.sys.service.UniversityDateService;
37 import org.kuali.ole.sys.service.impl.OleParameterConstants;
38 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
39 import org.kuali.rice.kns.lookup.HtmlData;
40 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
41 import org.kuali.rice.krad.bo.BusinessObject;
42 import org.kuali.rice.krad.exception.ValidationException;
43 import org.kuali.rice.krad.lookup.CollectionIncomplete;
44 import org.kuali.rice.krad.util.BeanPropertyComparator;
45 import org.kuali.rice.krad.util.GlobalVariables;
46 import org.kuali.rice.krad.util.KRADConstants;
47
48
49
50
51 public class PendingEntryLookupableHelperServiceImpl extends AbstractGeneralLedgerLookupableHelperServiceImpl {
52 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PendingEntryLookupableHelperServiceImpl.class);
53
54 private GeneralLedgerPendingEntryService generalLedgerPendingEntryService;
55 private ParameterService parameterService;
56
57 private final static String UNIVERSITY_FISCAL_YEAR = "universityFiscalYear";
58 private final static String UNIVERSITY_FISCAL_PERIOD_CODE = "universityFiscalPeriodCode";
59
60
61
62
63
64
65
66
67
68 @Override
69 public HtmlData getInquiryUrl(BusinessObject businessObject, String propertyName) {
70 if (OLEPropertyConstants.DOCUMENT_NUMBER.equals(propertyName) && businessObject instanceof GeneralLedgerPendingEntry) {
71 GeneralLedgerPendingEntry pendingEntry = (GeneralLedgerPendingEntry) businessObject;
72 return new AnchorHtmlData(new InquirableFinancialDocument().getInquirableDocumentUrl(pendingEntry), KRADConstants.EMPTY_STRING, "view pending entry "+pendingEntry.toString());
73 }
74 return (new EntryInquirableImpl()).getInquiryUrl(businessObject, propertyName);
75
76 }
77
78
79
80
81
82
83
84 @Override
85 public void validateSearchParameters(Map fieldValues) {
86 super.validateSearchParameters(fieldValues);
87
88 String valueFiscalYear = (String) fieldValues.get(UNIVERSITY_FISCAL_YEAR);
89 if (!StringUtils.isEmpty(valueFiscalYear)) {
90 try {
91 int year = Integer.parseInt(valueFiscalYear);
92 }
93 catch (NumberFormatException e) {
94 GlobalVariables.getMessageMap().putError(UNIVERSITY_FISCAL_YEAR, OLEKeyConstants.ERROR_CUSTOM, new String[] { OLEKeyConstants.PendingEntryLookupableImpl.FISCAL_YEAR_FOUR_DIGIT });
95 throw new ValidationException("errors in search criteria");
96 }
97 }
98
99 if (!allRequiredsForAccountSearch(fieldValues) && !allRequiredsForDocumentSearch(fieldValues)) {
100 GlobalVariables.getMessageMap().putError("universityFiscalYear", OLEKeyConstants.ERROR_GL_LOOKUP_PENDING_ENTRY_NON_MATCHING_REQUIRED_FIELDS, new String[] {});
101 throw new ValidationException("errors in search criteria");
102 }
103 }
104
105
106
107
108
109
110 protected boolean allRequiredsForAccountSearch(Map fieldValues) {
111 final String fiscalYearAsString = (String)fieldValues.get("universityFiscalYear");
112 final String chartOfAccountsCode = (String)fieldValues.get("chartOfAccountsCode");
113 final String accountNumber = (String)fieldValues.get("accountNumber");
114 final String fiscalPeriodCode = (String)fieldValues.get("universityFiscalPeriodCode");
115 return !StringUtils.isBlank(fiscalYearAsString) && !StringUtils.isBlank(chartOfAccountsCode) && !StringUtils.isBlank(accountNumber) && !StringUtils.isBlank(fiscalPeriodCode);
116 }
117
118
119
120
121
122
123 protected boolean allRequiredsForDocumentSearch(Map fieldValues) {
124 final String fiscalYearAsString = (String)fieldValues.get("universityFiscalYear");
125 final String documentNumber = (String)fieldValues.get("documentNumber");
126 return !StringUtils.isBlank(fiscalYearAsString) && !StringUtils.isBlank(documentNumber);
127 }
128
129
130
131
132
133
134
135
136 @Override
137 public List getSearchResults(Map fieldValues) {
138 setBackLocation((String) fieldValues.get(OLEConstants.BACK_LOCATION));
139 setDocFormKey((String) fieldValues.get(OLEConstants.DOC_FORM_KEY));
140
141 boolean isApproved = fieldValues.containsKey(Constant.PENDING_ENTRY_OPTION) && Constant.APPROVED_PENDING_ENTRY.equals(fieldValues.get(Constant.PENDING_ENTRY_OPTION));
142 Collection searchResultsCollection = generalLedgerPendingEntryService.findPendingEntries(fieldValues, isApproved);
143
144
145 List searchResults = (List) searchResultsCollection;
146 List defaultSortColumns = getDefaultSortColumns();
147 if (defaultSortColumns.size() > 0) {
148 Collections.sort(searchResults, new BeanPropertyComparator(defaultSortColumns, true));
149 }
150
151
152 String limitConfig = parameterService.getParameterValueAsString(OleParameterConstants.NERVOUS_SYSTEM_LOOKUP.class, OLEConstants.LOOKUP_RESULTS_LIMIT_URL_KEY);
153 Integer limit = null;
154 if (limitConfig != null) {
155 limit = Integer.valueOf(limitConfig);
156 }
157
158 Long collectionCount = new Long(searchResults.size());
159 Long actualCountIfTruncated = new Long(0);
160
161
162 if (limit != null) {
163 if (collectionCount >= limit.intValue()) {
164 actualCountIfTruncated = collectionCount;
165 for (int i = collectionCount.intValue() - 1; i >= limit; i--) {
166 searchResults.remove(i);
167 }
168 }
169 }
170
171 UniversityDate currentUniversityDate = SpringContext.getBean(UniversityDateService.class).getCurrentUniversityDate();
172 String currentFiscalPeriodCode = currentUniversityDate.getUniversityFiscalAccountingPeriod();
173 Integer currentFiscalYear = currentUniversityDate.getUniversityFiscalYear();
174
175 String fiscalPeriodFromForm = null;
176 if (fieldValues.containsKey(UNIVERSITY_FISCAL_PERIOD_CODE)) {
177 fiscalPeriodFromForm = (String) fieldValues.get(UNIVERSITY_FISCAL_PERIOD_CODE);
178 }
179
180 String fiscalYearFromForm = null;
181 if (fieldValues.containsKey(UNIVERSITY_FISCAL_YEAR)) {
182 fiscalYearFromForm = (String) fieldValues.get(UNIVERSITY_FISCAL_YEAR);
183 }
184
185 for (Iterator i = searchResults.iterator(); i.hasNext();) {
186 GeneralLedgerPendingEntry glpe = (GeneralLedgerPendingEntry) i.next();
187
188 if (currentFiscalPeriodCode.equals(fiscalPeriodFromForm) && null == glpe.getUniversityFiscalPeriodCode()) {
189 glpe.setUniversityFiscalPeriodCode(currentFiscalPeriodCode);
190 }
191
192 if (currentFiscalYear.toString().equals(fiscalYearFromForm) && null == glpe.getUniversityFiscalYear()) {
193 glpe.setUniversityFiscalYear(currentFiscalYear);
194 }
195 }
196
197 return new CollectionIncomplete(searchResults, actualCountIfTruncated);
198 }
199
200
201
202
203
204
205
206
207 private Collection buildSearchResults(Iterator iterator, String periodCode) {
208 Collection collection = new ArrayList();
209
210 while (iterator.hasNext()) {
211 GeneralLedgerPendingEntry pendingEntry = (GeneralLedgerPendingEntry) iterator.next();
212 pendingEntry.setUniversityFiscalPeriodCode(periodCode);
213 collection.add(pendingEntry);
214 }
215
216 return new CollectionIncomplete(collection, new Long(collection.size()));
217 }
218
219
220 @Override
221 protected void updateEntryCollection(Collection entryCollection, Map fieldValues, boolean isApproved, boolean isConsolidated, boolean isCostShareInclusive) {
222
223
224 }
225
226
227
228
229
230
231 @Override
232 public void setGeneralLedgerPendingEntryService(GeneralLedgerPendingEntryService generalLedgerPendingEntryService) {
233 this.generalLedgerPendingEntryService = generalLedgerPendingEntryService;
234 }
235
236 @Override
237 public void setParameterService(ParameterService parameterService) {
238 this.parameterService = parameterService;
239 }
240
241 }