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.Iterator;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.kuali.ole.gl.Constant;
26 import org.kuali.ole.gl.OJBUtility;
27 import org.kuali.ole.gl.batch.service.EncumbranceCalculator;
28 import org.kuali.ole.gl.businessobject.Encumbrance;
29 import org.kuali.ole.gl.businessobject.inquiry.EncumbranceInquirableImpl;
30 import org.kuali.ole.gl.service.EncumbranceService;
31 import org.kuali.ole.sys.OLEConstants;
32 import org.kuali.ole.sys.OLEKeyConstants;
33 import org.kuali.ole.sys.OLEPropertyConstants;
34 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
35 import org.kuali.rice.kns.lookup.HtmlData;
36 import org.kuali.rice.krad.bo.BusinessObject;
37 import org.kuali.rice.krad.exception.ValidationException;
38 import org.kuali.rice.krad.util.GlobalVariables;
39
40
41
42
43 public class EncumbranceLookupableHelperServiceImpl extends AbstractGeneralLedgerLookupableHelperServiceImpl {
44
45 private EncumbranceCalculator postEncumbrance;
46 private EncumbranceService encumbranceService;
47
48
49
50
51
52
53
54
55 @Override
56 public HtmlData getInquiryUrl(BusinessObject businessObject, String propertyName) {
57 return (new EncumbranceInquirableImpl()).getInquiryUrl(businessObject, propertyName);
58 }
59
60
61
62
63
64
65 @Override
66 public void validateSearchParameters(Map fieldValues) {
67 super.validateSearchParameters(fieldValues);
68
69 String valueFiscalYear = (String) fieldValues.get(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR);
70 if (!StringUtils.isEmpty(valueFiscalYear)) {
71 try {
72 int year = Integer.parseInt(valueFiscalYear);
73 }
74 catch (NumberFormatException e) {
75 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, OLEKeyConstants.ERROR_CUSTOM, new String[] { OLEKeyConstants.PendingEntryLookupableImpl.FISCAL_YEAR_FOUR_DIGIT });
76 throw new ValidationException("errors in search criteria");
77 }
78 }
79
80 if (!allRequiredsForAccountSearch(fieldValues) && !allRequiredsForDocumentSearch(fieldValues)) {
81 GlobalVariables.getMessageMap().putError("universityFiscalYear", OLEKeyConstants.ERROR_GL_LOOKUP_ENCUMBRANCE_NON_MATCHING_REQUIRED_FIELDS, new String[] {});
82 throw new ValidationException("errors in search criteria");
83 }
84 }
85
86
87
88
89
90
91 protected boolean allRequiredsForAccountSearch(Map fieldValues) {
92 final String fiscalYearAsString = (String)fieldValues.get("universityFiscalYear");
93 final String chartOfAccountsCode = (String)fieldValues.get("chartOfAccountsCode");
94 final String accountNumber = (String)fieldValues.get("accountNumber");
95 return !StringUtils.isBlank(fiscalYearAsString) && !StringUtils.isBlank(chartOfAccountsCode) && !StringUtils.isBlank(accountNumber);
96 }
97
98
99
100
101
102
103 protected boolean allRequiredsForDocumentSearch(Map fieldValues) {
104 final String fiscalYearAsString = (String)fieldValues.get("universityFiscalYear");
105 final String documentNumber = (String)fieldValues.get("documentNumber");
106 return !StringUtils.isBlank(fiscalYearAsString) && !StringUtils.isBlank(documentNumber);
107 }
108
109
110
111
112
113
114
115 @Override
116 public List getSearchResults(Map fieldValues) {
117 setBackLocation((String) fieldValues.get(OLEConstants.BACK_LOCATION));
118 setDocFormKey((String) fieldValues.get(OLEConstants.DOC_FORM_KEY));
119
120
121 String pendingEntryOption = this.getSelectedPendingEntryOption(fieldValues);
122
123 final String zeroEncumbranceOption = getSelectedZeroEncumbranceOption(fieldValues);
124 final boolean includeZeroEncumbrances = (StringUtils.isBlank(zeroEncumbranceOption) || zeroEncumbranceOption.equals(Constant.ZERO_ENCUMBRANCE_INCLUDE));
125
126
127 Iterator encumbranceIterator = encumbranceService.findOpenEncumbrance(fieldValues, includeZeroEncumbrances);
128 Collection searchResultsCollection = this.buildEncumbranceCollection(encumbranceIterator);
129
130
131 updateByPendingLedgerEntry(searchResultsCollection, fieldValues, pendingEntryOption, false, false);
132
133
134 Integer recordCount = encumbranceService.getOpenEncumbranceRecordCount(fieldValues, includeZeroEncumbrances);
135 Long actualSize = OJBUtility.getResultActualSize(searchResultsCollection, recordCount, fieldValues, new Encumbrance());
136
137 return this.buildSearchResultList(searchResultsCollection, actualSize);
138 }
139
140
141
142
143
144
145
146
147
148
149
150
151 @Override
152 protected void updateEntryCollection(Collection entryCollection, Map fieldValues, boolean isApproved, boolean isConsolidated, boolean isCostShareInclusive) {
153
154
155 Map pendingEntryFieldValues = BusinessObjectFieldConverter.convertToTransactionFieldValues(fieldValues);
156
157
158 Iterator pendingEntryIterator = getGeneralLedgerPendingEntryService().findPendingLedgerEntriesForEncumbrance(pendingEntryFieldValues, isApproved);
159 while (pendingEntryIterator.hasNext()) {
160 GeneralLedgerPendingEntry pendingEntry = (GeneralLedgerPendingEntry) pendingEntryIterator.next();
161 Encumbrance encumbrance = postEncumbrance.findEncumbrance(entryCollection, pendingEntry);
162 postEncumbrance.updateEncumbrance(pendingEntry, encumbrance);
163 }
164 }
165
166
167
168
169
170
171 private Collection buildEncumbranceCollection(Iterator iterator) {
172 Collection encumbranceCollection = new ArrayList();
173
174 while (iterator.hasNext()) {
175 Encumbrance encumrbance = (Encumbrance) iterator.next();
176 encumbranceCollection.add(encumrbance);
177 }
178 return encumbranceCollection;
179 }
180
181
182
183
184
185
186 protected String getSelectedZeroEncumbranceOption(Map fieldValues) {
187 return (String)fieldValues.remove(Constant.ZERO_ENCUMBRANCE_OPTION);
188 }
189
190
191
192
193
194
195 public void setPostEncumbrance(EncumbranceCalculator postEncumbrance) {
196 this.postEncumbrance = postEncumbrance;
197 }
198
199
200
201
202
203
204 public void setEncumbranceService(EncumbranceService encumbranceService) {
205 this.encumbranceService = encumbranceService;
206 }
207 }