1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.bo.lookup; |
18 | |
|
19 | |
import org.apache.commons.beanutils.PropertyUtils; |
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
22 | |
import org.kuali.rice.core.api.datetime.DateTimeService; |
23 | |
import org.kuali.rice.core.api.search.SearchOperator; |
24 | |
import org.kuali.rice.core.util.KeyValue; |
25 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
26 | |
import org.kuali.rice.core.util.type.KualiDecimal; |
27 | |
import org.kuali.rice.core.util.type.KualiPercent; |
28 | |
import org.kuali.rice.core.web.format.BooleanFormatter; |
29 | |
import org.kuali.rice.core.web.format.CollectionFormatter; |
30 | |
import org.kuali.rice.core.web.format.DateFormatter; |
31 | |
import org.kuali.rice.core.web.format.Formatter; |
32 | |
import org.kuali.rice.core.web.format.TimestampAMPMFormatter; |
33 | |
import org.kuali.rice.kew.docsearch.DocSearchCriteriaDTO; |
34 | |
import org.kuali.rice.kew.docsearch.DocumentLookupCriteriaBuilder; |
35 | |
import org.kuali.rice.kew.docsearch.DocumentLookupCriteriaProcessor; |
36 | |
import org.kuali.rice.kew.docsearch.DocumentLookupCriteriaProcessorKEWAdapter; |
37 | |
import org.kuali.rice.kew.docsearch.DocumentRouteHeaderEBO; |
38 | |
import org.kuali.rice.kew.docsearch.DocumentSearchGenerator; |
39 | |
import org.kuali.rice.kew.docsearch.DocumentSearchResult; |
40 | |
import org.kuali.rice.kew.docsearch.DocumentSearchResultComponents; |
41 | |
import org.kuali.rice.kew.docsearch.SavedSearchResult; |
42 | |
import org.kuali.rice.kew.docsearch.SearchAttributeCriteriaComponent; |
43 | |
import org.kuali.rice.kew.docsearch.StandardDocumentSearchCriteriaProcessor; |
44 | |
import org.kuali.rice.kew.docsearch.service.DocumentSearchService; |
45 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
46 | |
import org.kuali.rice.kew.exception.WorkflowServiceError; |
47 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
48 | |
import org.kuali.rice.kew.lookup.valuefinder.SavedSearchValuesFinder; |
49 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
50 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
51 | |
import org.kuali.rice.kew.util.KEWConstants; |
52 | |
import org.kuali.rice.kew.util.KEWPropertyConstants; |
53 | |
import org.kuali.rice.kew.web.KeyValueSort; |
54 | |
import org.kuali.rice.kim.bo.Person; |
55 | |
import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions; |
56 | |
import org.kuali.rice.kns.lookup.HtmlData; |
57 | |
import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; |
58 | |
import org.kuali.rice.kns.util.FieldUtils; |
59 | |
import org.kuali.rice.kns.web.comparator.CellComparatorHelper; |
60 | |
import org.kuali.rice.kns.web.struts.form.LookupForm; |
61 | |
import org.kuali.rice.kns.web.ui.Column; |
62 | |
import org.kuali.rice.kns.web.ui.Field; |
63 | |
import org.kuali.rice.kns.web.ui.ResultRow; |
64 | |
import org.kuali.rice.kns.web.ui.Row; |
65 | |
import org.kuali.rice.krad.bo.BusinessObject; |
66 | |
import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; |
67 | |
import org.kuali.rice.krad.exception.ValidationException; |
68 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
69 | |
import org.kuali.rice.krad.util.GlobalVariables; |
70 | |
import org.kuali.rice.krad.util.KRADConstants; |
71 | |
import org.kuali.rice.krad.util.MessageMap; |
72 | |
import org.kuali.rice.krad.util.ObjectUtils; |
73 | |
import org.kuali.rice.krad.util.UrlFactory; |
74 | |
|
75 | |
import java.lang.reflect.InvocationTargetException; |
76 | |
import java.math.BigDecimal; |
77 | |
import java.sql.Date; |
78 | |
import java.sql.Timestamp; |
79 | |
import java.util.ArrayList; |
80 | |
import java.util.Collection; |
81 | |
import java.util.HashMap; |
82 | |
import java.util.List; |
83 | |
import java.util.Map; |
84 | |
import java.util.Properties; |
85 | |
import java.util.regex.Matcher; |
86 | |
import java.util.regex.Pattern; |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | 0 | public class DocSearchCriteriaDTOLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl { |
94 | |
|
95 | |
private static final long serialVersionUID = -5162419674659967408L; |
96 | |
DateTimeService dateTimeService; |
97 | |
DocumentLookupCriteriaProcessor processor; |
98 | 0 | boolean savedSearch = false; |
99 | 0 | private static final Pattern HREF_PATTERN = Pattern.compile("<a href=\"([^\"]+)\""); |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
public void setDateTimeService(DateTimeService dateTimeService) { |
105 | 0 | this.dateTimeService = dateTimeService; |
106 | 0 | } |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
@Override |
112 | |
public Collection performLookup(LookupForm lookupForm, |
113 | |
Collection resultTable, boolean bounded) { |
114 | |
|
115 | |
|
116 | |
|
117 | 0 | Map<String,String[]> parameters = this.getParameters(); |
118 | |
|
119 | 0 | DocSearchCriteriaDTO criteria = null; |
120 | 0 | if(savedSearch) { |
121 | |
|
122 | 0 | DocumentSearchService docSearchService = KEWServiceLocator.getDocumentSearchService(); |
123 | |
|
124 | 0 | String savedSearchName = ((String[])getParameters().get("savedSearchName"))[0]; |
125 | 0 | SavedSearchResult savedSearchResult = null; |
126 | 0 | if(StringUtils.isNotEmpty(savedSearchName)) { |
127 | 0 | savedSearchResult = docSearchService.getSavedSearchResults(GlobalVariables.getUserSession().getPrincipalId(), savedSearchName); |
128 | |
} |
129 | 0 | if(savedSearchResult!=null){ |
130 | 0 | criteria = savedSearchResult.getDocSearchCriteriaDTO(); |
131 | |
} |
132 | 0 | savedSearch=false; |
133 | 0 | } else { |
134 | 0 | Map<String,String[]> fixedParameters = new HashMap<String,String[]>(); |
135 | 0 | Map<String,String> changedDateFields = preprocessDateFields(lookupForm.getFieldsForLookup()); |
136 | 0 | fixedParameters.putAll(this.getParameters()); |
137 | 0 | for (Map.Entry<String,String> prop : changedDateFields.entrySet()) { |
138 | 0 | fixedParameters.remove(prop.getKey()); |
139 | 0 | fixedParameters.put(prop.getKey(), new String[]{prop.getValue()}); |
140 | |
} |
141 | 0 | criteria = DocumentLookupCriteriaBuilder.populateCriteria(fixedParameters); |
142 | |
|
143 | |
} |
144 | |
|
145 | 0 | Collection<DocumentSearchResult> displayList=null; |
146 | |
|
147 | 0 | DocumentSearchResultComponents components = null; |
148 | |
try { |
149 | 0 | components = KEWServiceLocator.getDocumentSearchService().getList(GlobalVariables.getUserSession().getPrincipalId(), criteria); |
150 | 0 | } catch (WorkflowServiceErrorException wsee) { |
151 | 0 | for (WorkflowServiceError workflowServiceError : (List<WorkflowServiceError>)wsee.getServiceErrors()) { |
152 | 0 | if(workflowServiceError.getMessageMap() != null && workflowServiceError.getMessageMap().hasErrors()){ |
153 | |
|
154 | 0 | GlobalVariables.getMessageMap().merge(workflowServiceError.getMessageMap()); |
155 | |
}else{ |
156 | |
|
157 | 0 | GlobalVariables.getMessageMap().putError(workflowServiceError.getMessage(), RiceKeyConstants.ERROR_CUSTOM, workflowServiceError.getMessage()); |
158 | |
} |
159 | |
}; |
160 | 0 | } |
161 | |
|
162 | 0 | if(!GlobalVariables.getMessageMap().hasNoErrors()) { |
163 | 0 | throw new ValidationException("error with doc search"); |
164 | |
} |
165 | |
|
166 | |
|
167 | |
|
168 | 0 | if (criteria.isOverThreshold() && criteria.getSecurityFilteredRows() > 0) { |
169 | 0 | GlobalVariables.getMessageMap().putWarning(KRADConstants.GLOBAL_MESSAGES, "docsearch.DocumentSearchService.exceededThresholdAndSecurityFiltered", String.valueOf(components.getSearchResults().size()), String.valueOf(criteria.getSecurityFilteredRows())); |
170 | 0 | } else if (criteria.getSecurityFilteredRows() > 0) { |
171 | 0 | GlobalVariables.getMessageMap().putWarning(KRADConstants.GLOBAL_MESSAGES, "docsearch.DocumentSearchService.securityFiltered", String.valueOf(criteria.getSecurityFilteredRows())); |
172 | 0 | } else if (criteria.isOverThreshold()) { |
173 | 0 | GlobalVariables.getMessageMap().putWarning(KRADConstants.GLOBAL_MESSAGES,"docsearch.DocumentSearchService.exceededThreshold", String.valueOf(components.getSearchResults().size())); |
174 | |
} |
175 | |
|
176 | 0 | for (Row row : this.getRows()) { |
177 | 0 | for (Field field : row.getFields()) { |
178 | 0 | if(StringUtils.equals(field.getPropertyName(),"fromDateCreated") && StringUtils.isEmpty(field.getPropertyValue())) { |
179 | 0 | field.setPropertyValue(criteria.getFromDateCreated()); |
180 | |
} |
181 | |
} |
182 | |
} |
183 | |
|
184 | 0 | List<DocumentSearchResult> result = components.getSearchResults(); |
185 | |
|
186 | 0 | displayList = result; |
187 | |
|
188 | |
|
189 | |
|
190 | 0 | setBackLocation((String) lookupForm.getFieldsForLookup().get(KRADConstants.BACK_LOCATION)); |
191 | 0 | setDocFormKey((String) lookupForm.getFieldsForLookup().get(KRADConstants.DOC_FORM_KEY)); |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | 0 | HashMap<String,Class> propertyTypes = new HashMap<String, Class>(); |
205 | |
|
206 | 0 | boolean hasReturnableRow = false; |
207 | |
|
208 | 0 | List returnKeys = getReturnKeys(); |
209 | 0 | List pkNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(getBusinessObjectClass()); |
210 | 0 | Person user = GlobalVariables.getUserSession().getPerson(); |
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | 0 | DocumentRouteHeaderEBO element = new DocSearchCriteriaDTO(); |
221 | |
|
222 | 0 | BusinessObjectRestrictions businessObjectRestrictions = getBusinessObjectAuthorizationService().getLookupResultRestrictions(element, user); |
223 | |
|
224 | |
|
225 | |
|
226 | 0 | for (DocumentSearchResult documentSearchResult : result) { |
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | 0 | DocumentSearchResult docSearchResult = (DocumentSearchResult)documentSearchResult; |
233 | |
|
234 | |
|
235 | 0 | String actionUrls = ""; |
236 | |
|
237 | |
|
238 | 0 | List<? extends Column> origColumns = components.getColumns(); |
239 | 0 | List<Column> newColumns = new ArrayList<Column>(); |
240 | 0 | List<KeyValueSort> keyValues = docSearchResult.getResultContainers(); |
241 | 0 | for (int i = 0; i < origColumns.size(); i++) { |
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | 0 | Column col = (Column) origColumns.get(i); |
248 | 0 | KeyValueSort keyValue = null; |
249 | 0 | for (KeyValueSort keyValueFromList : keyValues) { |
250 | 0 | if(StringUtils.equals(col.getPropertyName(), keyValueFromList.getKey())) { |
251 | 0 | keyValue = keyValueFromList; |
252 | 0 | break; |
253 | |
} |
254 | |
} |
255 | 0 | if(keyValue==null) { |
256 | |
|
257 | 0 | keyValue = new KeyValueSort(); |
258 | |
|
259 | |
} |
260 | |
|
261 | |
|
262 | 0 | col.setPropertyValue(keyValue.getUserDisplayValue()); |
263 | |
|
264 | 0 | String propertyName = col.getPropertyName(); |
265 | 0 | if(StringUtils.isEmpty(col.getColumnTitle())) { |
266 | |
String labelMessageKey; |
267 | 0 | if(StringUtils.equals(propertyName,KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_LOG)) { |
268 | |
|
269 | 0 | labelMessageKey = "Route Log"; |
270 | |
} else { |
271 | |
|
272 | 0 | propertyName=(StringUtils.equals(propertyName,"docTypeLabel"))?"docTypeFullName":propertyName; |
273 | 0 | propertyName=(StringUtils.equals(propertyName,"docRouteStatusCodeDesc"))?"docRouteStatus":propertyName; |
274 | 0 | propertyName=(StringUtils.equals(propertyName,"documentTitle"))?"docTitle":propertyName; |
275 | 0 | labelMessageKey = getDataDictionaryService().getAttributeLabel(DocSearchCriteriaDTO.class,propertyName); |
276 | |
} |
277 | 0 | col.setColumnTitle(labelMessageKey); |
278 | |
} |
279 | |
|
280 | 0 | if(StringUtils.equals(propertyName, KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_ID)) { |
281 | 0 | ((DocSearchCriteriaDTO)element).setDocumentId(col.getPropertyValue()); |
282 | |
} |
283 | |
|
284 | 0 | Formatter formatter = col.getFormatter(); |
285 | |
|
286 | |
|
287 | 0 | String propValue = KRADConstants.EMPTY_STRING; |
288 | |
|
289 | |
|
290 | 0 | Object prop=keyValue.getSortValue(); |
291 | |
|
292 | |
|
293 | 0 | Class propClass = propertyTypes.get(propertyName); |
294 | 0 | if ( propClass == null ) { |
295 | |
try { |
296 | |
|
297 | 0 | if(prop!=null) { |
298 | 0 | propertyTypes.put(propertyName, prop.getClass()); |
299 | 0 | propClass = prop.getClass(); |
300 | |
} |
301 | |
|
302 | |
|
303 | |
|
304 | 0 | } catch (Exception e) { |
305 | |
|
306 | 0 | } |
307 | |
} |
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | 0 | if (prop != null) { |
313 | 0 | if (formatter == null) { |
314 | |
|
315 | 0 | if (prop instanceof Boolean) { |
316 | 0 | formatter = new BooleanFormatter(); |
317 | |
} |
318 | |
|
319 | |
|
320 | 0 | if (prop instanceof Date) { |
321 | 0 | formatter = new DateFormatter(); |
322 | |
} |
323 | |
|
324 | 0 | if (prop instanceof Timestamp) { |
325 | 0 | formatter = new TimestampAMPMFormatter(); |
326 | |
} |
327 | |
|
328 | |
|
329 | 0 | if (prop instanceof Collection && formatter == null) { |
330 | 0 | formatter = new CollectionFormatter(); |
331 | |
} |
332 | |
} |
333 | 0 | if (formatter != null) { |
334 | |
|
335 | 0 | if (prop instanceof BigDecimal && formatter.getImplementationClass().equals("org.kuali.rice.krad.web.format.CurrencyFormatter")) { |
336 | 0 | prop = new KualiDecimal((BigDecimal)prop); |
337 | 0 | } else if (prop instanceof BigDecimal && formatter.getImplementationClass().equals("org.kuali.rice.krad.web.format.PercentageFormatter")) { |
338 | 0 | prop = new KualiPercent((BigDecimal)prop); |
339 | |
} |
340 | 0 | propValue = (String) formatter.format(prop); |
341 | |
} |
342 | |
else { |
343 | 0 | propValue = prop.toString(); |
344 | |
} |
345 | |
} |
346 | |
|
347 | |
|
348 | 0 | col.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass)); |
349 | 0 | col.setValueComparator(CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass)); |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | 0 | col.setPropertyValue(propValue); |
355 | |
|
356 | 0 | if (StringUtils.isNotBlank(propValue)) { |
357 | |
|
358 | |
|
359 | 0 | HtmlData.AnchorHtmlData anchor = new HtmlData.AnchorHtmlData(KRADConstants.EMPTY_STRING, KRADConstants.EMPTY_STRING); |
360 | |
|
361 | 0 | if(StringUtils.isNotEmpty(keyValue.getValue()) && StringUtils.equals("documentId", keyValue.getKey())) { |
362 | 0 | String target = StringUtils.substringBetween(keyValue.getValue(), "target=\"", "\""); |
363 | 0 | if (target == null) { |
364 | 0 | target = "_self"; |
365 | |
} |
366 | 0 | anchor.setTarget(target.trim()); |
367 | 0 | if(!DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equals(criteria.getSuperUserSearch())) { |
368 | 0 | anchor.setHref(".."+KEWConstants.WEBAPP_DIRECTORY+"/"+StringUtils.substringBetween(keyValue.getValue(), "<a href=\"", "docId=")+"docId="+keyValue.getUserDisplayValue()); |
369 | |
} else { |
370 | |
|
371 | 0 | String returnLoc = ""; |
372 | 0 | if (this.getParameters().containsKey(KRADConstants.RETURN_LOCATION_PARAMETER)) { |
373 | 0 | returnLoc = (new StringBuilder()).append("&").append(KRADConstants.RETURN_LOCATION_PARAMETER).append("=").append( |
374 | |
((String[])this.getParameters().get(KRADConstants.RETURN_LOCATION_PARAMETER))[0]).toString(); |
375 | |
} |
376 | 0 | else if (StringUtils.isNotBlank(this.getBackLocation())) { |
377 | 0 | returnLoc = (new StringBuilder()).append("&").append(KRADConstants.RETURN_LOCATION_PARAMETER).append("=").append( |
378 | |
this.getBackLocation()).toString(); |
379 | |
} |
380 | |
|
381 | 0 | anchor.setHref(".."+KEWConstants.WEBAPP_DIRECTORY+"/"+StringUtils.substringBetween(keyValue.getValue(), "<a href=\"", "documentId=")+"documentId="+keyValue.getUserDisplayValue() + returnLoc); |
382 | |
} |
383 | 0 | col.setMaxLength(100); |
384 | 0 | } else if(StringUtils.isNotEmpty(keyValue.getValue()) && StringUtils.equals(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_LOG, keyValue.getKey())) { |
385 | 0 | Matcher hrefMatcher = HREF_PATTERN.matcher(keyValue.getValue()); |
386 | 0 | String matchedURL = ""; |
387 | 0 | if (hrefMatcher.find()) { |
388 | 0 | matchedURL = hrefMatcher.group(1); |
389 | |
} |
390 | 0 | anchor.setHref(".."+KEWConstants.WEBAPP_DIRECTORY+"/"+matchedURL); |
391 | 0 | String target = StringUtils.substringBetween(keyValue.getValue(), "target=\"", "\""); |
392 | 0 | if (target == null) { |
393 | 0 | target = "_self"; |
394 | |
} |
395 | 0 | anchor.setTarget(target.trim()); |
396 | 0 | col.setMaxLength(100); |
397 | 0 | keyValue.setValue(keyValue.getUserDisplayValue()); |
398 | 0 | col.setEscapeXMLValue(false); |
399 | 0 | } else if (StringUtils.isNotEmpty(keyValue.getValue()) && StringUtils.equals(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_INITIATOR, keyValue.getKey())) { |
400 | 0 | anchor.setHref(StringUtils.substringBetween(keyValue.getValue(), "<a href=\"", "\" target=\"_blank\"")); |
401 | 0 | col.setMaxLength(100); |
402 | |
} |
403 | |
|
404 | 0 | col.setColumnAnchor(anchor); |
405 | |
|
406 | |
} |
407 | 0 | Column newCol = (Column)ObjectUtils.deepCopy(col); |
408 | 0 | newColumns.add(newCol); |
409 | |
|
410 | |
} |
411 | |
|
412 | 0 | HtmlData returnUrl = getReturnUrl(element, lookupForm, returnKeys, businessObjectRestrictions); |
413 | 0 | ResultRow row = new ResultRow(newColumns, returnUrl.constructCompleteHtmlTag(), actionUrls); |
414 | 0 | row.setRowId(returnUrl.getName()); |
415 | |
|
416 | |
|
417 | 0 | if (getBusinessObjectDictionaryService().isExportable(getBusinessObjectClass())) { |
418 | |
|
419 | |
} |
420 | |
|
421 | |
|
422 | |
|
423 | 0 | boolean rowReturnable = true; |
424 | 0 | row.setRowReturnable(rowReturnable); |
425 | 0 | if (rowReturnable) { |
426 | 0 | hasReturnableRow = true; |
427 | |
} |
428 | 0 | resultTable.add(row); |
429 | 0 | } |
430 | |
|
431 | |
|
432 | 0 | lookupForm.setHasReturnableRow(hasReturnableRow); |
433 | |
|
434 | 0 | return displayList; |
435 | |
|
436 | |
} |
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
@Override |
446 | |
public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) { |
447 | |
|
448 | 0 | if(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_ID.equals(propertyName)) { |
449 | |
|
450 | 0 | HtmlData.AnchorHtmlData link = new HtmlData.AnchorHtmlData(); |
451 | 0 | DocumentRouteHeaderValue doc = (DocumentRouteHeaderValue)bo; |
452 | |
|
453 | 0 | String documentId = doc.getDocumentId(); |
454 | 0 | link.setDisplayText(documentId+""); |
455 | |
|
456 | 0 | String href = ConfigContext.getCurrentContextConfig().getKRBaseURL()+"/"+ KEWConstants.APP_CODE + "/" + |
457 | |
KEWConstants.DOC_HANDLER_REDIRECT_PAGE + "?" + KEWConstants.COMMAND_PARAMETER + "=" + |
458 | |
KEWConstants.DOCSEARCH_COMMAND + "&" + KEWConstants.DOCUMENT_ID_PARAMETER + "=" + documentId; |
459 | |
|
460 | 0 | link.setHref(href); |
461 | |
|
462 | 0 | return link; |
463 | |
} |
464 | |
|
465 | 0 | return super.getInquiryUrl(bo, propertyName); |
466 | |
} |
467 | |
|
468 | |
|
469 | |
|
470 | |
|
471 | |
|
472 | |
@Override |
473 | |
protected void setRows() { |
474 | 0 | this.setRows(new HashMap<String,String[]>(), null); |
475 | 0 | } |
476 | |
|
477 | |
|
478 | |
|
479 | |
|
480 | |
|
481 | |
protected void setRows(Map fieldValues, String docTypeName) { |
482 | |
|
483 | |
|
484 | |
|
485 | |
|
486 | |
|
487 | |
|
488 | |
|
489 | |
|
490 | 0 | if (getRows() == null) { |
491 | 0 | super.setRows(); |
492 | |
} |
493 | 0 | List<Row> lookupRows = new ArrayList<Row>(); |
494 | |
|
495 | 0 | for (Row row : getRows()) { |
496 | 0 | lookupRows.add(row); |
497 | |
} |
498 | |
|
499 | 0 | getRows().clear(); |
500 | |
|
501 | 0 | processor = new DocumentLookupCriteriaProcessorKEWAdapter(); |
502 | |
|
503 | |
|
504 | 0 | DocumentType docType = null; |
505 | |
|
506 | 0 | if(StringUtils.isNotEmpty(docTypeName)) { |
507 | 0 | docType = getValidDocumentType((String)docTypeName); |
508 | |
} |
509 | |
|
510 | 0 | DocumentLookupCriteriaProcessorKEWAdapter documentLookupCriteriaProcessorKEWAdapter = (DocumentLookupCriteriaProcessorKEWAdapter)processor; |
511 | 0 | if(processor != null && documentLookupCriteriaProcessorKEWAdapter.getCriteriaProcessor()!=null) { |
512 | 0 | if(docType==null) { |
513 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(new StandardDocumentSearchCriteriaProcessor()); |
514 | 0 | } else if(!StringUtils.equals(docTypeName, documentLookupCriteriaProcessorKEWAdapter.getCriteriaProcessor().getDocSearchCriteriaDTO().getDocTypeFullName())){ |
515 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(docType.getDocumentSearchCriteriaProcessor()); |
516 | |
} |
517 | |
} else { |
518 | 0 | if(docType==null) { |
519 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(new StandardDocumentSearchCriteriaProcessor()); |
520 | |
} else { |
521 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(docType.getDocumentSearchCriteriaProcessor()); |
522 | |
} |
523 | |
} |
524 | |
|
525 | 0 | documentLookupCriteriaProcessorKEWAdapter.setDataDictionaryService(getDataDictionaryService()); |
526 | |
|
527 | 0 | boolean detailed=false; |
528 | 0 | if(this.getParameters().containsKey("isAdvancedSearch")) { |
529 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("isAdvancedSearch"))[0]); |
530 | 0 | } else if(fieldValues.containsKey("isAdvancedSearch")) { |
531 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String) fieldValues.get("isAdvancedSearch")); |
532 | |
} |
533 | |
|
534 | 0 | boolean superSearch=false; |
535 | 0 | if(this.getParameters().containsKey(("superUserSearch"))) { |
536 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("superUserSearch"))[0]); |
537 | 0 | } else if(fieldValues.containsKey("superUserSearch")) { |
538 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String)fieldValues.get("superUserSearch")); |
539 | |
} |
540 | |
|
541 | |
|
542 | 0 | List<Row> rows = processor.getRows(docType,lookupRows, detailed, superSearch); |
543 | |
|
544 | 0 | BusinessObjectEntry boe = (BusinessObjectEntry) KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(this.getBusinessObjectClass().getName()); |
545 | 0 | int numCols = boe.getLookupDefinition().getNumOfColumns(); |
546 | 0 | if(numCols == 0) { |
547 | 0 | numCols = KRADConstants.DEFAULT_NUM_OF_COLUMNS; |
548 | |
} |
549 | |
|
550 | 0 | super.getRows().addAll(FieldUtils.wrapFields(this.getFields(rows), numCols)); |
551 | |
|
552 | 0 | } |
553 | |
|
554 | |
private List<Field> getFields(List<Row> rows){ |
555 | 0 | List<Field> rList = new ArrayList<Field>(); |
556 | |
|
557 | 0 | for(Row r: rows){ |
558 | 0 | for(Field f: r.getFields()){ |
559 | 0 | rList.add(f); |
560 | |
} |
561 | |
} |
562 | |
|
563 | 0 | return rList; |
564 | |
} |
565 | |
|
566 | |
private void setRowsAfterClear(DocSearchCriteriaDTO searchCriteria, Map<String,String[]> fieldValues) { |
567 | |
|
568 | |
|
569 | |
|
570 | |
|
571 | |
|
572 | 0 | if (getRows() == null) { |
573 | 0 | super.setRows(); |
574 | |
} |
575 | 0 | List<Row> lookupRows = new ArrayList<Row>(); |
576 | |
|
577 | 0 | for (Row row : getRows()) { |
578 | 0 | lookupRows.add(row); |
579 | |
} |
580 | 0 | super.getRows().clear(); |
581 | |
|
582 | 0 | processor = new DocumentLookupCriteriaProcessorKEWAdapter(); |
583 | |
|
584 | 0 | String docTypeName = searchCriteria.getDocTypeFullName(); |
585 | 0 | DocumentType docType = null; |
586 | |
|
587 | 0 | if(StringUtils.isNotEmpty(docTypeName)) { |
588 | 0 | docType = getValidDocumentType(docTypeName); |
589 | |
} |
590 | |
|
591 | 0 | DocumentLookupCriteriaProcessorKEWAdapter documentLookupCriteriaProcessorKEWAdapter = (DocumentLookupCriteriaProcessorKEWAdapter)processor; |
592 | 0 | if(processor != null && documentLookupCriteriaProcessorKEWAdapter.getCriteriaProcessor()!=null) { |
593 | 0 | if(docType==null) { |
594 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(new StandardDocumentSearchCriteriaProcessor()); |
595 | 0 | } else if(!StringUtils.equals(docTypeName, documentLookupCriteriaProcessorKEWAdapter.getCriteriaProcessor().getDocSearchCriteriaDTO().getDocTypeFullName())){ |
596 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(docType.getDocumentSearchCriteriaProcessor()); |
597 | |
} |
598 | |
} else { |
599 | 0 | if(docType==null) { |
600 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(new StandardDocumentSearchCriteriaProcessor()); |
601 | |
} else { |
602 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(docType.getDocumentSearchCriteriaProcessor()); |
603 | |
} |
604 | |
} |
605 | |
|
606 | 0 | documentLookupCriteriaProcessorKEWAdapter.setDataDictionaryService(getDataDictionaryService()); |
607 | |
|
608 | 0 | boolean detailed=false; |
609 | 0 | if(this.getParameters().containsKey("isAdvancedSearch")) { |
610 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("isAdvancedSearch"))[0]); |
611 | 0 | } else if(fieldValues.containsKey("isAdvancedSearch")) { |
612 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String) fieldValues.get("isAdvancedSearch")[0]); |
613 | |
} |
614 | |
|
615 | 0 | boolean superSearch=false; |
616 | 0 | if(this.getParameters().containsKey(("superUserSearch"))) { |
617 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("superUserSearch"))[0]); |
618 | 0 | } else if(fieldValues.containsKey("superUserSearch")) { |
619 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String)fieldValues.get("superUserSearch")[0]); |
620 | |
} |
621 | |
|
622 | 0 | List<Row> rows = documentLookupCriteriaProcessorKEWAdapter.getRows(docType, super.getRows(), detailed, superSearch); |
623 | |
|
624 | 0 | super.getRows().addAll(rows); |
625 | |
|
626 | |
|
627 | 0 | if(StringUtils.isNotEmpty(docTypeName)) { |
628 | 0 | for (Row row : super.getRows()) { |
629 | 0 | for (Field field : row.getFields()) { |
630 | |
|
631 | 0 | String propertyName = null; |
632 | 0 | if(field.getPropertyName().startsWith(KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { |
633 | 0 | propertyName = StringUtils.remove(field.getPropertyName(), KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX); |
634 | |
} else { |
635 | 0 | propertyName = field.getPropertyName(); |
636 | |
} |
637 | |
|
638 | 0 | if (fieldValues.get(propertyName) != null) { |
639 | 0 | Object value = this.getDocSearchCriteriaDTOFieldValue(searchCriteria, field.getPropertyName()); |
640 | 0 | if (value instanceof String |
641 | |
&& StringUtils.isNotEmpty((String)value)) { |
642 | 0 | field.setPropertyValue(value); |
643 | 0 | } else if (value instanceof List){ |
644 | 0 | field.setPropertyValues((String[])((List)value).toArray()); |
645 | |
} |
646 | |
} |
647 | 0 | } |
648 | |
} |
649 | |
} |
650 | 0 | } |
651 | |
|
652 | |
|
653 | |
|
654 | |
|
655 | |
|
656 | |
@Override |
657 | |
public void performClear(LookupForm lookupForm) { |
658 | |
|
659 | |
|
660 | |
|
661 | |
|
662 | |
|
663 | |
|
664 | |
|
665 | |
|
666 | |
|
667 | |
|
668 | |
|
669 | |
|
670 | |
|
671 | |
|
672 | 0 | Map<String,String[]> fixedParameters = new HashMap<String,String[]>(); |
673 | 0 | Map<String,String> changedDateFields = preprocessDateFields(lookupForm.getFieldsForLookup()); |
674 | 0 | fixedParameters.putAll(this.getParameters()); |
675 | 0 | for (Map.Entry<String,String> prop : changedDateFields.entrySet()) { |
676 | 0 | fixedParameters.remove(prop.getKey()); |
677 | 0 | fixedParameters.put(prop.getKey(), new String[]{prop.getValue()}); |
678 | |
} |
679 | |
|
680 | 0 | String docTypeName = fixedParameters.get("docTypeFullName")[0]; |
681 | |
|
682 | 0 | DocumentType docType = getValidDocumentType(docTypeName); |
683 | |
|
684 | 0 | if(docType == null) { |
685 | 0 | super.performClear(lookupForm); |
686 | |
|
687 | |
|
688 | 0 | boolean detailed=false; |
689 | 0 | if(this.getParameters().containsKey("isAdvancedSearch")) { |
690 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("isAdvancedSearch"))[0]); |
691 | 0 | } else if(fixedParameters.containsKey("isAdvancedSearch")) { |
692 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String) fixedParameters.get("isAdvancedSearch")[0]); |
693 | |
} |
694 | |
|
695 | 0 | boolean superSearch=false; |
696 | 0 | if(this.getParameters().containsKey(("superUserSearch"))) { |
697 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("superUserSearch"))[0]); |
698 | 0 | } else if(fixedParameters.containsKey("superUserSearch")) { |
699 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String) fixedParameters.get("superUserSearch")[0]); |
700 | |
} |
701 | |
|
702 | |
|
703 | 0 | int fieldsRepopulated = 0; |
704 | 0 | List<Row> rows = super.getRows(); |
705 | 0 | int index = rows.size() - 1; |
706 | 0 | while (index >= 0 && fieldsRepopulated < 2) { |
707 | 0 | for (Field tempField : rows.get(index).getFields()) { |
708 | 0 | if ("isAdvancedSearch".equals(tempField.getPropertyName())) { |
709 | 0 | tempField.setPropertyValue(detailed?"YES":"NO"); |
710 | 0 | fieldsRepopulated++; |
711 | |
} |
712 | 0 | else if ("superUserSearch".equals(tempField.getPropertyName())) { |
713 | 0 | tempField.setPropertyValue(superSearch?"YES":"NO"); |
714 | 0 | fieldsRepopulated++; |
715 | |
} |
716 | |
} |
717 | 0 | index--; |
718 | |
} |
719 | 0 | } else { |
720 | 0 | DocSearchCriteriaDTO docCriteria = DocumentLookupCriteriaBuilder.populateCriteria(fixedParameters); |
721 | 0 | docCriteria = docType.getDocumentSearchGenerator().clearSearch(docCriteria); |
722 | 0 | if (docCriteria == null) { |
723 | 0 | docCriteria = new DocSearchCriteriaDTO(); |
724 | |
} |
725 | |
|
726 | 0 | this.setRowsAfterClear(docCriteria, fixedParameters); |
727 | |
} |
728 | |
|
729 | 0 | } |
730 | |
|
731 | |
|
732 | |
|
733 | |
|
734 | |
|
735 | |
|
736 | |
|
737 | |
private static DocumentType getValidDocumentType(String docTypeName) { |
738 | 0 | if (StringUtils.isNotEmpty(docTypeName)) { |
739 | 0 | DocumentType dTypeCriteria = new DocumentType(); |
740 | 0 | dTypeCriteria.setName(docTypeName.trim()); |
741 | 0 | dTypeCriteria.setActive(true); |
742 | 0 | Collection<DocumentType> docTypeList = KEWServiceLocator.getDocumentTypeService().find(dTypeCriteria, null, false); |
743 | |
|
744 | |
|
745 | 0 | DocumentType firstDocumentType = null; |
746 | 0 | if(docTypeList != null){ |
747 | 0 | for(DocumentType dType: docTypeList){ |
748 | 0 | if (firstDocumentType == null) { |
749 | 0 | firstDocumentType = dType; |
750 | |
} |
751 | 0 | if (StringUtils.equals(docTypeName.toUpperCase(), dType.getName().toUpperCase())) { |
752 | 0 | return dType; |
753 | |
} |
754 | |
} |
755 | 0 | return firstDocumentType; |
756 | |
} |
757 | |
} |
758 | |
|
759 | 0 | return null; |
760 | |
} |
761 | |
|
762 | |
|
763 | |
|
764 | |
|
765 | |
|
766 | |
@Override |
767 | |
public String getSupplementalMenuBar() { |
768 | 0 | boolean detailed = false; |
769 | 0 | if(this.getParameters().containsKey("isAdvancedSearch")) { |
770 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("isAdvancedSearch"))[0]); |
771 | |
} |
772 | |
|
773 | 0 | boolean superSearch = false; |
774 | 0 | if(this.getParameters().containsKey("superUserSearch")) { |
775 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("superUserSearch"))[0]); |
776 | |
} |
777 | |
|
778 | 0 | StringBuilder suppMenuBar = new StringBuilder(); |
779 | |
|
780 | |
|
781 | 0 | suppMenuBar.append("<input type=\"image\" name=\"methodToCall.customLookupableMethodCall.(((").append(detailed ? "NO" : DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING).append("))).((`").append(superSearch ? DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING : "NO").append( |
782 | |
"`))\" class=\"tinybutton\" src=\"..").append(KEWConstants.WEBAPP_DIRECTORY).append(detailed ? "/images/tinybutton-basicsearch.gif\" alt=\"basic search\" title=\"basic search\" />" : "/images/tinybutton-detailedsearch.gif\" alt=\"detailed search\" title=\"detailed search\" />"); |
783 | |
|
784 | |
|
785 | 0 | suppMenuBar.append(" ").append("<input type=\"image\" name=\"methodToCall.customLookupableMethodCall.(((").append((!detailed && superSearch) ? "NO" : DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING).append("))).((`").append(superSearch ? "NO" : DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING).append( |
786 | |
"`))\" class=\"tinybutton\" src=\"..").append(KEWConstants.WEBAPP_DIRECTORY).append(superSearch ? "/images/tinybutton-nonsupusearch.gif\" alt=\"non-superuser search\" title=\"non-superuser search\" />" : "/images/tinybutton-superusersearch.gif\" alt=\"superuser search\" title=\"superuser search\" />"); |
787 | |
|
788 | |
|
789 | 0 | suppMenuBar.append(" ").append("<input type=\"image\" name=\"methodToCall.customLookupableMethodCall.(([true]))\" class=\"tinybutton\" src=\"..").append(KEWConstants.WEBAPP_DIRECTORY).append("/images/tinybutton-clearsavedsearch.gif\" alt=\"clear saved searches\" title=\"clear saved searches\" />"); |
790 | |
|
791 | 0 | Properties parameters = new Properties(); |
792 | 0 | parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, this.getBusinessObjectClass().getName()); |
793 | 0 | this.getParameters().keySet(); |
794 | 0 | for (Object parameter : this.getParameters().keySet()) { |
795 | 0 | parameters.put(parameter, this.getParameters().get(parameter)); |
796 | |
} |
797 | |
|
798 | 0 | UrlFactory.parameterizeUrl(KRADConstants.LOOKUP_ACTION, parameters); |
799 | 0 | return suppMenuBar.toString(); |
800 | |
} |
801 | |
|
802 | |
|
803 | |
|
804 | |
|
805 | |
|
806 | |
|
807 | |
|
808 | |
|
809 | |
|
810 | |
|
811 | |
|
812 | |
|
813 | |
|
814 | |
|
815 | |
|
816 | |
|
817 | |
|
818 | |
|
819 | |
|
820 | |
|
821 | |
|
822 | |
|
823 | |
|
824 | |
|
825 | |
|
826 | |
|
827 | |
|
828 | |
|
829 | |
|
830 | |
|
831 | |
|
832 | |
|
833 | |
|
834 | |
|
835 | |
|
836 | |
@Override |
837 | |
public boolean shouldDisplayHeaderNonMaintActions() { |
838 | 0 | return this.processor.shouldDisplayHeaderNonMaintActions(); |
839 | |
} |
840 | |
|
841 | |
|
842 | |
|
843 | |
|
844 | |
|
845 | |
@Override |
846 | |
public boolean shouldDisplayLookupCriteria() { |
847 | 0 | return this.processor.shouldDisplayLookupCriteria(); |
848 | |
} |
849 | |
|
850 | |
|
851 | |
|
852 | |
|
853 | |
|
854 | |
@Override |
855 | |
public boolean checkForAdditionalFields(Map fieldValues) { |
856 | |
|
857 | |
|
858 | 0 | String docTypeName = null; |
859 | 0 | if(this.getParameters().get("docTypeFullName")!=null) { |
860 | 0 | docTypeName = ((String[])this.getParameters().get("docTypeFullName"))[0]; |
861 | |
} |
862 | 0 | else if(fieldValues.get("docTypeFullName")!=null) { |
863 | 0 | docTypeName = (String)fieldValues.get("docTypeFullName"); |
864 | |
} |
865 | 0 | if(!StringUtils.isEmpty(docTypeName)) { |
866 | 0 | DocumentType dType = getValidDocumentType(docTypeName); |
867 | |
|
868 | 0 | DocSearchCriteriaDTO criteria = DocumentLookupCriteriaBuilder.populateCriteria(getParameters()); |
869 | 0 | if (dType != null) { |
870 | 0 | MessageMap messages = getValidDocumentType(dType.getName()).getDocumentSearchGenerator().getMessageMap(criteria); |
871 | 0 | if (messages != null |
872 | |
&& messages.hasMessages()) { |
873 | 0 | GlobalVariables.mergeErrorMap(messages); |
874 | |
} |
875 | 0 | setRows(fieldValues,dType.getName()); |
876 | 0 | return true; |
877 | |
} |
878 | |
} |
879 | |
|
880 | 0 | setRows(fieldValues, docTypeName); |
881 | |
|
882 | 0 | return true; |
883 | |
} |
884 | |
|
885 | |
|
886 | |
|
887 | |
|
888 | |
@Override |
889 | |
public void validateSearchParameters(Map fieldValues) { |
890 | 0 | super.validateSearchParameters(fieldValues); |
891 | 0 | DocumentSearchService docSearchService = KEWServiceLocator.getDocumentSearchService(); |
892 | 0 | DocSearchCriteriaDTO criteria = DocumentLookupCriteriaBuilder.populateCriteria(getParameters()); |
893 | 0 | DocumentType docType = null; |
894 | 0 | if(StringUtils.isNotEmpty(criteria.getDocTypeFullName())) { |
895 | 0 | docType = getValidDocumentType((String)criteria.getDocTypeFullName()); |
896 | |
} |
897 | 0 | DocumentSearchGenerator generator=null; |
898 | 0 | if(docType!=null) { |
899 | 0 | generator = docType.getDocumentSearchGenerator(); |
900 | |
} else { |
901 | 0 | generator = KEWServiceLocator.getDocumentSearchService().getStandardDocumentSearchGenerator(); |
902 | |
} |
903 | |
try { |
904 | 0 | docSearchService.validateDocumentSearchCriteria(generator, criteria); |
905 | 0 | } catch (WorkflowServiceErrorException wsee) { |
906 | 0 | for (WorkflowServiceError workflowServiceError : (List<WorkflowServiceError>)wsee.getServiceErrors()) { |
907 | 0 | if(workflowServiceError.getMessageMap() != null && workflowServiceError.getMessageMap().hasErrors()){ |
908 | |
|
909 | 0 | GlobalVariables.getMessageMap().merge(workflowServiceError.getMessageMap()); |
910 | |
}else{ |
911 | |
|
912 | 0 | GlobalVariables.getMessageMap().putError(workflowServiceError.getMessage(), RiceKeyConstants.ERROR_CUSTOM, workflowServiceError.getMessage()); |
913 | |
} |
914 | |
}; |
915 | 0 | } |
916 | 0 | if(!GlobalVariables.getMessageMap().hasNoErrors()) { |
917 | 0 | throw new ValidationException("errors in search criteria"); |
918 | |
} |
919 | |
|
920 | 0 | } |
921 | |
|
922 | |
|
923 | |
|
924 | |
|
925 | |
|
926 | |
@Override |
927 | |
public boolean performCustomAction(boolean ignoreErrors) { |
928 | 0 | DocumentSearchService docSearchService = KEWServiceLocator.getDocumentSearchService(); |
929 | |
|
930 | 0 | Map<String,String> fieldValues = new HashMap<String,String>(); |
931 | 0 | Map<String,String[]> multFieldValues = new HashMap<String,String[]>(); |
932 | |
|
933 | |
|
934 | 0 | String[] methodToCallArray = ((String[])this.getParameters().get( |
935 | |
KRADConstants.DISPATCH_REQUEST_PARAMETER + ".customLookupableMethodCall")); |
936 | 0 | if (methodToCallArray == null) { |
937 | 0 | for (String parameter: new ArrayList<String>(this.getParameters().keySet())) { |
938 | 0 | String[] parameterSplit = StringUtils.split(parameter, "."); |
939 | 0 | String parameterValue = ""; |
940 | 0 | if (StringUtils.contains(parameter, KRADConstants.DISPATCH_REQUEST_PARAMETER + ".customLookupableMethodCall.")) { |
941 | 0 | if (parameter.trim().endsWith(".x")) { |
942 | 0 | parameterValue = StringUtils.substringBetween(parameter, KRADConstants.DISPATCH_REQUEST_PARAMETER + ".customLookupableMethodCall.", ".x"); |
943 | 0 | } else if (parameter.trim().endsWith(".y")) { |
944 | 0 | parameterValue = StringUtils.substringBetween(parameter, KRADConstants.DISPATCH_REQUEST_PARAMETER + ".customLookupableMethodCall.", ".y"); |
945 | |
} |
946 | 0 | if (StringUtils.isNotEmpty(parameterValue)) { |
947 | 0 | methodToCallArray = new String[]{ parameterValue }; |
948 | 0 | break; |
949 | |
} |
950 | |
} |
951 | 0 | } |
952 | |
} |
953 | |
|
954 | 0 | if (ObjectUtils.isNotNull(methodToCallArray) && methodToCallArray.length > 0) { |
955 | 0 | String methodToCallVal = methodToCallArray[0]; |
956 | 0 | if (StringUtils.isNotBlank(methodToCallVal)) { |
957 | 0 | boolean resetRows = false; |
958 | |
|
959 | 0 | String advancedSearchVal = StringUtils.substringBetween(methodToCallVal, KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL); |
960 | 0 | if (StringUtils.isNotBlank(advancedSearchVal)) { |
961 | 0 | if (this.getParameters().containsKey("isAdvancedSearch")) { |
962 | 0 | ((String[]) this.getParameters().get("isAdvancedSearch"))[0] = advancedSearchVal; |
963 | |
} |
964 | |
else { |
965 | 0 | fieldValues.put("isAdvancedSearch", advancedSearchVal); |
966 | |
} |
967 | 0 | resetRows = true; |
968 | |
} |
969 | |
|
970 | 0 | String superUserSearchVal = StringUtils.substringBetween(methodToCallVal, KRADConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL); |
971 | 0 | if (StringUtils.isNotBlank(superUserSearchVal)) { |
972 | 0 | if (this.getParameters().containsKey("superUserSearch")) { |
973 | 0 | ((String[]) this.getParameters().get("superUserSearch"))[0] = superUserSearchVal; |
974 | |
} else { |
975 | 0 | fieldValues.put("superUserSearch", superUserSearchVal); |
976 | |
} |
977 | 0 | resetRows = true; |
978 | |
} |
979 | |
|
980 | 0 | String resetSavedSearchVal = StringUtils.substringBetween(methodToCallVal, KRADConstants.METHOD_TO_CALL_PARM4_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM4_RIGHT_DEL); |
981 | 0 | if (Boolean.parseBoolean(resetSavedSearchVal)) { |
982 | 0 | docSearchService.clearNamedSearches(GlobalVariables.getUserSession().getPrincipalId()); |
983 | 0 | resetRows = true; |
984 | |
} |
985 | |
|
986 | |
|
987 | |
|
988 | 0 | if (resetRows) { |
989 | 0 | Map<String,String> values = new HashMap<String,String>(); |
990 | 0 | for (Field tempField : getFields(this.getRows())) { |
991 | 0 | values.put(tempField.getPropertyName(), tempField.getPropertyValue()); |
992 | |
} |
993 | |
|
994 | 0 | for (Row row : this.getRows()) { |
995 | 0 | for (Field field : row.getFields()) { |
996 | 0 | if (field.getPropertyName() != null && !field.getPropertyName().equals("")) { |
997 | 0 | if (this.getParameters().get(field.getPropertyName()) != null) { |
998 | 0 | if(!Field.MULTI_VALUE_FIELD_TYPES.contains(field.getFieldType())) { |
999 | 0 | field.setPropertyValue(((String[])this.getParameters().get(field.getPropertyName()))[0]); |
1000 | |
} else { |
1001 | |
|
1002 | 0 | field.setPropertyValues((String[])this.getParameters().get(field.getPropertyName())); |
1003 | |
} |
1004 | |
} |
1005 | |
} |
1006 | 0 | else if (values.get(field.getPropertyName()) != null) { |
1007 | 0 | field.setPropertyValue(values.get(field.getPropertyName())); |
1008 | |
} |
1009 | |
|
1010 | 0 | applyFieldAuthorizationsFromNestedLookups(field); |
1011 | |
|
1012 | 0 | fieldValues.put(field.getPropertyName(), field.getPropertyValue()); |
1013 | |
} |
1014 | |
} |
1015 | |
|
1016 | 0 | if (checkForAdditionalFields(fieldValues)) { |
1017 | 0 | for (Row row : this.getRows()) { |
1018 | 0 | for (Field field : row.getFields()) { |
1019 | 0 | if (field.getPropertyName() != null && !field.getPropertyName().equals("")) { |
1020 | 0 | if (this.getParameters().get(field.getPropertyName()) != null) { |
1021 | 0 | if(!Field.MULTI_VALUE_FIELD_TYPES.contains(field.getFieldType())) { |
1022 | 0 | field.setPropertyValue(((String[])this.getParameters().get(field.getPropertyName()))[0]); |
1023 | |
} else { |
1024 | |
|
1025 | 0 | field.setPropertyValues((String[])this.getParameters().get(field.getPropertyName())); |
1026 | |
} |
1027 | |
|
1028 | 0 | fieldValues.put(field.getPropertyName(), ((String[])this.getParameters().get(field.getPropertyName()))[0]); |
1029 | |
} |
1030 | 0 | else if (values.get(field.getPropertyName()) != null) { |
1031 | 0 | field.setPropertyValue(values.get(field.getPropertyName())); |
1032 | |
} |
1033 | |
} |
1034 | |
} |
1035 | |
} |
1036 | |
} |
1037 | |
|
1038 | 0 | return false; |
1039 | |
} |
1040 | |
|
1041 | |
} |
1042 | |
} |
1043 | |
|
1044 | 0 | String[] resetSavedSearch = ((String[])getParameters().get("resetSavedSearch")); |
1045 | 0 | if(resetSavedSearch!=null) { |
1046 | 0 | docSearchService.clearNamedSearches(GlobalVariables.getUserSession().getPrincipalId()); |
1047 | 0 | setRows(fieldValues,""); |
1048 | 0 | return false; |
1049 | |
} |
1050 | |
|
1051 | 0 | String savedSearchName = ((String[])getParameters().get("savedSearchName"))[0]; |
1052 | 0 | if(StringUtils.isEmpty(savedSearchName)||"*ignore*".equals(savedSearchName)) { |
1053 | 0 | if(!ignoreErrors) { |
1054 | 0 | GlobalVariables.getMessageMap().putError("savedSearchName", RiceKeyConstants.ERROR_CUSTOM, "You must select a saved search"); |
1055 | |
} else { |
1056 | |
|
1057 | 0 | return false; |
1058 | |
} |
1059 | |
|
1060 | 0 | List<Row> rows = this.getRows(); |
1061 | 0 | for (Row row : rows) { |
1062 | 0 | List<Field> fields = row.getFields(); |
1063 | 0 | for (Field field : fields) { |
1064 | 0 | if(StringUtils.equals(field.getPropertyName(), "savedSearchName")) { |
1065 | 0 | field.setPropertyValue(""); |
1066 | 0 | break; |
1067 | |
} |
1068 | |
} |
1069 | 0 | } |
1070 | |
} |
1071 | 0 | if (!GlobalVariables.getMessageMap().hasNoErrors()) { |
1072 | 0 | throw new ValidationException("errors in search criteria"); |
1073 | |
} |
1074 | |
|
1075 | |
|
1076 | 0 | SavedSearchResult savedSearchResult = null; |
1077 | 0 | if(StringUtils.isNotEmpty(savedSearchName)) { |
1078 | 0 | savedSearchResult = docSearchService.getSavedSearchResults(GlobalVariables.getUserSession().getPrincipalId(), savedSearchName); |
1079 | |
} |
1080 | 0 | DocSearchCriteriaDTO criteria=null; |
1081 | 0 | if(savedSearchResult!=null){ |
1082 | 0 | criteria = savedSearchResult.getDocSearchCriteriaDTO(); |
1083 | |
} |
1084 | |
|
1085 | 0 | String docTypeName = criteria.getDocTypeFullName(); |
1086 | |
|
1087 | |
|
1088 | 0 | setRows(fieldValues,docTypeName); |
1089 | |
|
1090 | |
|
1091 | |
|
1092 | |
|
1093 | 0 | fieldValues.put("savedSearchName", ""); |
1094 | |
|
1095 | |
|
1096 | 0 | for (SearchAttributeCriteriaComponent searchAtt : criteria.getSearchableAttributes()) { |
1097 | 0 | if(!searchAtt.isCanHoldMultipleValues()) { |
1098 | 0 | fieldValues.put(searchAtt.getSavedKey(), searchAtt.getValue()); |
1099 | |
} else { |
1100 | 0 | List<String> values = searchAtt.getValues(); |
1101 | 0 | String[] arrayValues = {}; |
1102 | 0 | arrayValues = values.toArray(arrayValues); |
1103 | 0 | multFieldValues.put(searchAtt.getSavedKey(), arrayValues); |
1104 | 0 | } |
1105 | |
|
1106 | |
} |
1107 | 0 | Object fieldValue = null; |
1108 | 0 | for (Row row2 : getRows()) { |
1109 | 0 | Row row = (Row) row2; |
1110 | 0 | for (Field field2 : row.getFields()) { |
1111 | 0 | Field field = (Field) field2; |
1112 | 0 | if (field.getPropertyName() != null && !field.getPropertyName().equals("")) { |
1113 | 0 | if (fieldValues.get(field.getPropertyName()) != null) { |
1114 | 0 | field.setPropertyValue(fieldValues.get(field.getPropertyName())); |
1115 | 0 | } else if(multFieldValues.get(field.getPropertyName())!=null){ |
1116 | 0 | field.setPropertyValues(multFieldValues.get(field.getPropertyName())); |
1117 | |
} else { |
1118 | |
|
1119 | |
try { |
1120 | 0 | fieldValue = PropertyUtils.getProperty(criteria, field.getPropertyName()); |
1121 | 0 | } catch (IllegalAccessException e) { |
1122 | 0 | e.printStackTrace(); |
1123 | 0 | } catch (InvocationTargetException e) { |
1124 | 0 | e.printStackTrace(); |
1125 | 0 | } catch (NoSuchMethodException e) { |
1126 | |
|
1127 | |
|
1128 | 0 | } |
1129 | 0 | if(fieldValue!=null) { |
1130 | 0 | field.setPropertyValue(fieldValue); |
1131 | |
} |
1132 | |
|
1133 | |
} |
1134 | |
} |
1135 | 0 | } |
1136 | 0 | } |
1137 | |
|
1138 | 0 | savedSearch=true; |
1139 | |
|
1140 | 0 | return true; |
1141 | |
} |
1142 | |
|
1143 | |
|
1144 | |
|
1145 | |
|
1146 | |
@Override |
1147 | |
public Field getExtraField() { |
1148 | 0 | SavedSearchValuesFinder savedSearchValuesFinder = new SavedSearchValuesFinder(); |
1149 | 0 | List<KeyValue> savedSearchValues = savedSearchValuesFinder.getKeyValues(); |
1150 | |
|
1151 | 0 | Field savedSearch = new Field(); |
1152 | 0 | savedSearch.setPropertyName("savedSearchName"); |
1153 | 0 | savedSearch.setFieldType(Field.DROPDOWN_SCRIPT); |
1154 | 0 | savedSearch.setScript("customLookupChanged()"); |
1155 | 0 | savedSearch.setFieldValidValues(savedSearchValues); |
1156 | 0 | savedSearch.setFieldLabel("Saved Searches"); |
1157 | 0 | return savedSearch; |
1158 | |
|
1159 | |
} |
1160 | |
|
1161 | |
private Object getDocSearchCriteriaDTOFieldValue (DocSearchCriteriaDTO searchCriteria, String fieldName) { |
1162 | 0 | Class<?> clazz = searchCriteria.getClass(); |
1163 | 0 | String propertyName = fieldName; |
1164 | 0 | if(fieldName.startsWith(KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { |
1165 | 0 | propertyName = StringUtils.remove(fieldName, KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX); |
1166 | |
} |
1167 | |
try { |
1168 | 0 | String methodName = new StringBuffer("get").append(propertyName.toUpperCase().charAt(0)).append(propertyName.substring(1)).toString(); |
1169 | 0 | java.lang.reflect.Method method = clazz.getMethod(methodName); |
1170 | 0 | return method.invoke(searchCriteria); |
1171 | 0 | } catch (SecurityException e) { |
1172 | 0 | return null; |
1173 | 0 | } catch (IllegalArgumentException e) { |
1174 | 0 | return null; |
1175 | 0 | } catch (IllegalAccessException e) { |
1176 | 0 | return null; |
1177 | 0 | } catch (InvocationTargetException e) { |
1178 | 0 | return null; |
1179 | 0 | } catch (NoSuchMethodException e) { |
1180 | 0 | return getSearchableAttributeFieldValue(searchCriteria, fieldName); |
1181 | |
} |
1182 | |
} |
1183 | |
|
1184 | |
private Object getSearchableAttributeFieldValue(DocSearchCriteriaDTO searchCriteria, String fieldName) { |
1185 | 0 | Object valueToReturn = null; |
1186 | 0 | String propertyName = fieldName; |
1187 | 0 | boolean isDateTime = false; |
1188 | 0 | if(fieldName.startsWith(KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { |
1189 | 0 | propertyName = StringUtils.remove(fieldName, KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX); |
1190 | |
} |
1191 | 0 | if (searchCriteria.getSearchableAttributes() != null) { |
1192 | 0 | for (SearchAttributeCriteriaComponent sa : searchCriteria.getSearchableAttributes()) { |
1193 | 0 | if (StringUtils.equals(propertyName, sa.getFormKey())) { |
1194 | 0 | if (StringUtils.equals(sa.getSearchableAttributeValue().getOjbConcreteClass(), "org.kuali.rice.kew.docsearch.SearchableAttributeDateTimeValue")) { |
1195 | 0 | isDateTime = true; |
1196 | |
} |
1197 | 0 | if (sa.isCanHoldMultipleValues()) { |
1198 | 0 | valueToReturn = sa.getValues(); |
1199 | |
} else { |
1200 | 0 | valueToReturn = sa.getValue(); |
1201 | |
} |
1202 | 0 | break; |
1203 | |
} |
1204 | |
} |
1205 | |
} |
1206 | |
|
1207 | 0 | if (valueToReturn != null |
1208 | |
&& valueToReturn instanceof String |
1209 | |
&& isDateTime) { |
1210 | 0 | if(fieldName.startsWith(KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { |
1211 | 0 | if (StringUtils.contains((String)valueToReturn, SearchOperator.BETWEEN.op())) { |
1212 | 0 | valueToReturn = StringUtils.split((String)valueToReturn, SearchOperator.BETWEEN.op())[0]; |
1213 | 0 | } else if (StringUtils.contains((String)valueToReturn, SearchOperator.GREATER_THAN_EQUAL.op())) { |
1214 | 0 | valueToReturn = StringUtils.split((String)valueToReturn, SearchOperator.GREATER_THAN_EQUAL.op())[0]; |
1215 | |
} else { |
1216 | 0 | valueToReturn = null; |
1217 | |
} |
1218 | |
} else { |
1219 | 0 | if (StringUtils.contains((String)valueToReturn, SearchOperator.BETWEEN.op())) { |
1220 | 0 | valueToReturn = StringUtils.split((String)valueToReturn, SearchOperator.BETWEEN.op())[1]; |
1221 | 0 | } else if (StringUtils.contains((String)valueToReturn, SearchOperator.GREATER_THAN_EQUAL.op())) { |
1222 | 0 | valueToReturn = null; |
1223 | 0 | } else if (StringUtils.contains((String)valueToReturn, SearchOperator.LESS_THAN_EQUAL.op())) { |
1224 | 0 | valueToReturn = StringUtils.split((String)valueToReturn, SearchOperator.LESS_THAN_EQUAL.op())[0]; |
1225 | |
} |
1226 | |
|
1227 | |
} |
1228 | |
} |
1229 | |
|
1230 | 0 | return valueToReturn; |
1231 | |
} |
1232 | |
|
1233 | |
|
1234 | |
|
1235 | |
|
1236 | |
|
1237 | |
|
1238 | |
|
1239 | |
|
1240 | |
|
1241 | |
|
1242 | |
|
1243 | |
|
1244 | |
|
1245 | |
|
1246 | |
|
1247 | |
|
1248 | |
} |