| 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.datetime.DateTimeService; |
| 22 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
| 23 | |
import org.kuali.rice.core.util.KeyValue; |
| 24 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
| 25 | |
import org.kuali.rice.core.util.type.KualiDecimal; |
| 26 | |
import org.kuali.rice.core.util.type.KualiPercent; |
| 27 | |
import org.kuali.rice.core.web.format.BooleanFormatter; |
| 28 | |
import org.kuali.rice.core.web.format.CollectionFormatter; |
| 29 | |
import org.kuali.rice.core.web.format.DateFormatter; |
| 30 | |
import org.kuali.rice.core.web.format.Formatter; |
| 31 | |
import org.kuali.rice.core.web.format.TimestampAMPMFormatter; |
| 32 | |
import org.kuali.rice.kew.docsearch.DocSearchCriteriaDTO; |
| 33 | |
import org.kuali.rice.kew.docsearch.DocumentLookupCriteriaBuilder; |
| 34 | |
import org.kuali.rice.kew.docsearch.DocumentLookupCriteriaProcessor; |
| 35 | |
import org.kuali.rice.kew.docsearch.DocumentLookupCriteriaProcessorKEWAdapter; |
| 36 | |
import org.kuali.rice.kew.docsearch.DocumentRouteHeaderEBO; |
| 37 | |
import org.kuali.rice.kew.docsearch.DocumentSearchGenerator; |
| 38 | |
import org.kuali.rice.kew.docsearch.DocumentSearchResult; |
| 39 | |
import org.kuali.rice.kew.docsearch.DocumentSearchResultComponents; |
| 40 | |
import org.kuali.rice.kew.docsearch.SavedSearchResult; |
| 41 | |
import org.kuali.rice.kew.docsearch.SearchAttributeCriteriaComponent; |
| 42 | |
import org.kuali.rice.kew.docsearch.StandardDocumentSearchCriteriaProcessor; |
| 43 | |
import org.kuali.rice.kew.docsearch.service.DocumentSearchService; |
| 44 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 45 | |
import org.kuali.rice.kew.exception.WorkflowServiceError; |
| 46 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
| 47 | |
import org.kuali.rice.kew.lookup.valuefinder.SavedSearchValuesFinder; |
| 48 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 49 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 50 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 51 | |
import org.kuali.rice.kew.util.KEWPropertyConstants; |
| 52 | |
import org.kuali.rice.kew.web.KeyValueSort; |
| 53 | |
import org.kuali.rice.kim.bo.Person; |
| 54 | |
import org.kuali.rice.kns.authorization.BusinessObjectRestrictions; |
| 55 | |
import org.kuali.rice.kns.bo.BusinessObject; |
| 56 | |
import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; |
| 57 | |
import org.kuali.rice.kns.exception.ValidationException; |
| 58 | |
import org.kuali.rice.kns.lookup.HtmlData; |
| 59 | |
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; |
| 60 | |
import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; |
| 61 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 62 | |
import org.kuali.rice.kns.util.FieldUtils; |
| 63 | |
import org.kuali.rice.kns.util.GlobalVariables; |
| 64 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 65 | |
import org.kuali.rice.kns.util.MessageMap; |
| 66 | |
import org.kuali.rice.kns.util.ObjectUtils; |
| 67 | |
import org.kuali.rice.kns.util.UrlFactory; |
| 68 | |
import org.kuali.rice.kns.web.comparator.CellComparatorHelper; |
| 69 | |
import org.kuali.rice.kns.web.struts.form.LookupForm; |
| 70 | |
import org.kuali.rice.kns.web.ui.Column; |
| 71 | |
import org.kuali.rice.kns.web.ui.Field; |
| 72 | |
import org.kuali.rice.kns.web.ui.ResultRow; |
| 73 | |
import org.kuali.rice.kns.web.ui.Row; |
| 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 |
| 94 | |
KualiLookupableHelperServiceImpl { |
| 95 | |
|
| 96 | |
private static final long serialVersionUID = -5162419674659967408L; |
| 97 | |
DateTimeService dateTimeService; |
| 98 | |
DocumentLookupCriteriaProcessor processor; |
| 99 | 0 | boolean savedSearch = false; |
| 100 | 0 | private static final Pattern HREF_PATTERN = Pattern.compile("<a href=\"([^\"]+)\""); |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
public void setDateTimeService(DateTimeService dateTimeService) { |
| 106 | 0 | this.dateTimeService = dateTimeService; |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
@Override |
| 113 | |
public Collection performLookup(LookupForm lookupForm, |
| 114 | |
Collection resultTable, boolean bounded) { |
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | 0 | Map<String,String[]> parameters = this.getParameters(); |
| 119 | |
|
| 120 | 0 | DocSearchCriteriaDTO criteria = null; |
| 121 | 0 | if(savedSearch) { |
| 122 | |
|
| 123 | 0 | DocumentSearchService docSearchService = KEWServiceLocator.getDocumentSearchService(); |
| 124 | |
|
| 125 | 0 | String savedSearchName = ((String[])getParameters().get("savedSearchName"))[0]; |
| 126 | 0 | SavedSearchResult savedSearchResult = null; |
| 127 | 0 | if(StringUtils.isNotEmpty(savedSearchName)) { |
| 128 | 0 | savedSearchResult = docSearchService.getSavedSearchResults(GlobalVariables.getUserSession().getPrincipalId(), savedSearchName); |
| 129 | |
} |
| 130 | 0 | if(savedSearchResult!=null){ |
| 131 | 0 | criteria = savedSearchResult.getDocSearchCriteriaDTO(); |
| 132 | |
} |
| 133 | 0 | savedSearch=false; |
| 134 | 0 | } else { |
| 135 | 0 | Map<String,String[]> fixedParameters = new HashMap<String,String[]>(); |
| 136 | 0 | Map<String,String> changedDateFields = preprocessDateFields(lookupForm.getFieldsForLookup()); |
| 137 | 0 | fixedParameters.putAll(this.getParameters()); |
| 138 | 0 | for (Map.Entry<String,String> prop : changedDateFields.entrySet()) { |
| 139 | 0 | fixedParameters.remove(prop.getKey()); |
| 140 | 0 | fixedParameters.put(prop.getKey(), new String[]{prop.getValue()}); |
| 141 | |
} |
| 142 | 0 | criteria = DocumentLookupCriteriaBuilder.populateCriteria(fixedParameters); |
| 143 | |
|
| 144 | |
} |
| 145 | |
|
| 146 | 0 | Collection<DocumentSearchResult> displayList=null; |
| 147 | |
|
| 148 | 0 | DocumentSearchResultComponents components = null; |
| 149 | |
try { |
| 150 | 0 | components = KEWServiceLocator.getDocumentSearchService().getList(GlobalVariables.getUserSession().getPrincipalId(), criteria); |
| 151 | 0 | } catch (WorkflowServiceErrorException wsee) { |
| 152 | 0 | for (WorkflowServiceError workflowServiceError : (List<WorkflowServiceError>)wsee.getServiceErrors()) { |
| 153 | 0 | if(workflowServiceError.getMessageMap() != null && workflowServiceError.getMessageMap().hasErrors()){ |
| 154 | |
|
| 155 | 0 | GlobalVariables.getMessageMap().merge(workflowServiceError.getMessageMap()); |
| 156 | |
}else{ |
| 157 | |
|
| 158 | 0 | GlobalVariables.getMessageMap().putError(workflowServiceError.getMessage(), RiceKeyConstants.ERROR_CUSTOM, workflowServiceError.getMessage()); |
| 159 | |
} |
| 160 | |
}; |
| 161 | 0 | } |
| 162 | |
|
| 163 | 0 | if(!GlobalVariables.getMessageMap().hasNoErrors()) { |
| 164 | 0 | throw new ValidationException("error with doc search"); |
| 165 | |
} |
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | 0 | if (criteria.isOverThreshold() && criteria.getSecurityFilteredRows() > 0) { |
| 170 | 0 | GlobalVariables.getMessageMap().putWarning(KNSConstants.GLOBAL_MESSAGES, "docsearch.DocumentSearchService.exceededThresholdAndSecurityFiltered", String.valueOf(components.getSearchResults().size()), String.valueOf(criteria.getSecurityFilteredRows())); |
| 171 | 0 | } else if (criteria.getSecurityFilteredRows() > 0) { |
| 172 | 0 | GlobalVariables.getMessageMap().putWarning(KNSConstants.GLOBAL_MESSAGES, "docsearch.DocumentSearchService.securityFiltered", String.valueOf(criteria.getSecurityFilteredRows())); |
| 173 | 0 | } else if (criteria.isOverThreshold()) { |
| 174 | 0 | GlobalVariables.getMessageMap().putWarning(KNSConstants.GLOBAL_MESSAGES,"docsearch.DocumentSearchService.exceededThreshold", String.valueOf(components.getSearchResults().size())); |
| 175 | |
} |
| 176 | |
|
| 177 | 0 | for (Row row : this.getRows()) { |
| 178 | 0 | for (Field field : row.getFields()) { |
| 179 | 0 | if(StringUtils.equals(field.getPropertyName(),"fromDateCreated") && StringUtils.isEmpty(field.getPropertyValue())) { |
| 180 | 0 | field.setPropertyValue(criteria.getFromDateCreated()); |
| 181 | |
} |
| 182 | |
} |
| 183 | |
} |
| 184 | |
|
| 185 | 0 | List<DocumentSearchResult> result = components.getSearchResults(); |
| 186 | |
|
| 187 | 0 | displayList = result; |
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | 0 | setBackLocation((String) lookupForm.getFieldsForLookup().get(KNSConstants.BACK_LOCATION)); |
| 192 | 0 | setDocFormKey((String) lookupForm.getFieldsForLookup().get(KNSConstants.DOC_FORM_KEY)); |
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | 0 | HashMap<String,Class> propertyTypes = new HashMap<String, Class>(); |
| 206 | |
|
| 207 | 0 | boolean hasReturnableRow = false; |
| 208 | |
|
| 209 | 0 | List returnKeys = getReturnKeys(); |
| 210 | 0 | List pkNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(getBusinessObjectClass()); |
| 211 | 0 | Person user = GlobalVariables.getUserSession().getPerson(); |
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | 0 | DocumentRouteHeaderEBO element = new DocSearchCriteriaDTO(); |
| 222 | |
|
| 223 | 0 | BusinessObjectRestrictions businessObjectRestrictions = getBusinessObjectAuthorizationService().getLookupResultRestrictions(element, user); |
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | 0 | for (DocumentSearchResult documentSearchResult : result) { |
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | 0 | DocumentSearchResult docSearchResult = (DocumentSearchResult)documentSearchResult; |
| 234 | |
|
| 235 | |
|
| 236 | 0 | String actionUrls = ""; |
| 237 | |
|
| 238 | |
|
| 239 | 0 | List<? extends Column> origColumns = components.getColumns(); |
| 240 | 0 | List<Column> newColumns = new ArrayList<Column>(); |
| 241 | 0 | List<KeyValueSort> keyValues = docSearchResult.getResultContainers(); |
| 242 | 0 | for (int i = 0; i < origColumns.size(); i++) { |
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | 0 | Column col = (Column) origColumns.get(i); |
| 249 | 0 | KeyValueSort keyValue = null; |
| 250 | 0 | for (KeyValueSort keyValueFromList : keyValues) { |
| 251 | 0 | if(StringUtils.equals(col.getPropertyName(), keyValueFromList.getKey())) { |
| 252 | 0 | keyValue = keyValueFromList; |
| 253 | 0 | break; |
| 254 | |
} |
| 255 | |
} |
| 256 | 0 | if(keyValue==null) { |
| 257 | |
|
| 258 | 0 | keyValue = new KeyValueSort(); |
| 259 | |
|
| 260 | |
} |
| 261 | |
|
| 262 | |
|
| 263 | 0 | col.setPropertyValue(keyValue.getUserDisplayValue()); |
| 264 | |
|
| 265 | 0 | String propertyName = col.getPropertyName(); |
| 266 | 0 | if(StringUtils.isEmpty(col.getColumnTitle())) { |
| 267 | |
String labelMessageKey; |
| 268 | 0 | if(StringUtils.equals(propertyName,KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_LOG)) { |
| 269 | |
|
| 270 | 0 | labelMessageKey = "Route Log"; |
| 271 | |
} else { |
| 272 | |
|
| 273 | 0 | propertyName=(StringUtils.equals(propertyName,"docTypeLabel"))?"docTypeFullName":propertyName; |
| 274 | 0 | propertyName=(StringUtils.equals(propertyName,"docRouteStatusCodeDesc"))?"docRouteStatus":propertyName; |
| 275 | 0 | propertyName=(StringUtils.equals(propertyName,"documentTitle"))?"docTitle":propertyName; |
| 276 | 0 | labelMessageKey = getDataDictionaryService().getAttributeLabel(DocSearchCriteriaDTO.class,propertyName); |
| 277 | |
} |
| 278 | 0 | col.setColumnTitle(labelMessageKey); |
| 279 | |
} |
| 280 | |
|
| 281 | 0 | if(StringUtils.equals(propertyName, KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_HEADER_ID)) { |
| 282 | 0 | ((DocSearchCriteriaDTO)element).setRouteHeaderId(col.getPropertyValue()); |
| 283 | |
} |
| 284 | |
|
| 285 | 0 | Formatter formatter = col.getFormatter(); |
| 286 | |
|
| 287 | |
|
| 288 | 0 | String propValue = KNSConstants.EMPTY_STRING; |
| 289 | |
|
| 290 | |
|
| 291 | 0 | Object prop=keyValue.getSortValue(); |
| 292 | |
|
| 293 | |
|
| 294 | 0 | Class propClass = propertyTypes.get(propertyName); |
| 295 | 0 | if ( propClass == null ) { |
| 296 | |
try { |
| 297 | |
|
| 298 | 0 | if(prop!=null) { |
| 299 | 0 | propertyTypes.put(propertyName, prop.getClass()); |
| 300 | 0 | propClass = prop.getClass(); |
| 301 | |
} |
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | 0 | } catch (Exception e) { |
| 306 | |
|
| 307 | 0 | } |
| 308 | |
} |
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | 0 | if (prop != null) { |
| 314 | 0 | if (formatter == null) { |
| 315 | |
|
| 316 | 0 | if (prop instanceof Boolean) { |
| 317 | 0 | formatter = new BooleanFormatter(); |
| 318 | |
} |
| 319 | |
|
| 320 | |
|
| 321 | 0 | if (prop instanceof Date) { |
| 322 | 0 | formatter = new DateFormatter(); |
| 323 | |
} |
| 324 | |
|
| 325 | 0 | if (prop instanceof Timestamp) { |
| 326 | 0 | formatter = new TimestampAMPMFormatter(); |
| 327 | |
} |
| 328 | |
|
| 329 | |
|
| 330 | 0 | if (prop instanceof Collection && formatter == null) { |
| 331 | 0 | formatter = new CollectionFormatter(); |
| 332 | |
} |
| 333 | |
} |
| 334 | 0 | if (formatter != null) { |
| 335 | |
|
| 336 | 0 | if (prop instanceof BigDecimal && formatter.getImplementationClass().equals("org.kuali.rice.kns.web.format.CurrencyFormatter")) { |
| 337 | 0 | prop = new KualiDecimal((BigDecimal)prop); |
| 338 | 0 | } else if (prop instanceof BigDecimal && formatter.getImplementationClass().equals("org.kuali.rice.kns.web.format.PercentageFormatter")) { |
| 339 | 0 | prop = new KualiPercent((BigDecimal)prop); |
| 340 | |
} |
| 341 | 0 | propValue = (String) formatter.format(prop); |
| 342 | |
} |
| 343 | |
else { |
| 344 | 0 | propValue = prop.toString(); |
| 345 | |
} |
| 346 | |
} |
| 347 | |
|
| 348 | |
|
| 349 | 0 | col.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass)); |
| 350 | 0 | col.setValueComparator(CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass)); |
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | 0 | col.setPropertyValue(propValue); |
| 356 | |
|
| 357 | 0 | if (StringUtils.isNotBlank(propValue)) { |
| 358 | |
|
| 359 | |
|
| 360 | 0 | AnchorHtmlData anchor = new AnchorHtmlData(KNSConstants.EMPTY_STRING, KNSConstants.EMPTY_STRING); |
| 361 | |
|
| 362 | 0 | if(StringUtils.isNotEmpty(keyValue.getValue()) && StringUtils.equals("routeHeaderId", keyValue.getKey())) { |
| 363 | 0 | String target = StringUtils.substringBetween(keyValue.getValue(), "target=\"", "\""); |
| 364 | 0 | if (target == null) { |
| 365 | 0 | target = "_self"; |
| 366 | |
} |
| 367 | 0 | anchor.setTarget(target.trim()); |
| 368 | 0 | if(!DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equals(criteria.getSuperUserSearch())) { |
| 369 | 0 | anchor.setHref(".."+KEWConstants.WEBAPP_DIRECTORY+"/"+StringUtils.substringBetween(keyValue.getValue(), "<a href=\"", "docId=")+"docId="+keyValue.getUserDisplayValue()); |
| 370 | |
} else { |
| 371 | |
|
| 372 | 0 | String returnLoc = ""; |
| 373 | 0 | if (this.getParameters().containsKey(KNSConstants.RETURN_LOCATION_PARAMETER)) { |
| 374 | 0 | returnLoc = (new StringBuilder()).append("&").append(KNSConstants.RETURN_LOCATION_PARAMETER).append("=").append( |
| 375 | |
((String[])this.getParameters().get(KNSConstants.RETURN_LOCATION_PARAMETER))[0]).toString(); |
| 376 | |
} |
| 377 | 0 | else if (StringUtils.isNotBlank(this.getBackLocation())) { |
| 378 | 0 | returnLoc = (new StringBuilder()).append("&").append(KNSConstants.RETURN_LOCATION_PARAMETER).append("=").append( |
| 379 | |
this.getBackLocation()).toString(); |
| 380 | |
} |
| 381 | |
|
| 382 | 0 | anchor.setHref(".."+KEWConstants.WEBAPP_DIRECTORY+"/"+StringUtils.substringBetween(keyValue.getValue(), "<a href=\"", "routeHeaderId=")+"routeHeaderId="+keyValue.getUserDisplayValue() + returnLoc); |
| 383 | |
} |
| 384 | 0 | col.setMaxLength(100); |
| 385 | 0 | } else if(StringUtils.isNotEmpty(keyValue.getValue()) && StringUtils.equals(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_LOG, keyValue.getKey())) { |
| 386 | 0 | Matcher hrefMatcher = HREF_PATTERN.matcher(keyValue.getValue()); |
| 387 | 0 | String matchedURL = ""; |
| 388 | 0 | if (hrefMatcher.find()) { |
| 389 | 0 | matchedURL = hrefMatcher.group(1); |
| 390 | |
} |
| 391 | 0 | anchor.setHref(".."+KEWConstants.WEBAPP_DIRECTORY+"/"+matchedURL); |
| 392 | 0 | String target = StringUtils.substringBetween(keyValue.getValue(), "target=\"", "\""); |
| 393 | 0 | if (target == null) { |
| 394 | 0 | target = "_self"; |
| 395 | |
} |
| 396 | 0 | anchor.setTarget(target.trim()); |
| 397 | 0 | col.setMaxLength(100); |
| 398 | 0 | keyValue.setValue(keyValue.getUserDisplayValue()); |
| 399 | 0 | col.setEscapeXMLValue(false); |
| 400 | 0 | } else if (StringUtils.isNotEmpty(keyValue.getValue()) && StringUtils.equals(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_INITIATOR, keyValue.getKey())) { |
| 401 | 0 | anchor.setHref(StringUtils.substringBetween(keyValue.getValue(), "<a href=\"", "\" target=\"_blank\"")); |
| 402 | 0 | col.setMaxLength(100); |
| 403 | |
} |
| 404 | |
|
| 405 | 0 | col.setColumnAnchor(anchor); |
| 406 | |
|
| 407 | |
} |
| 408 | 0 | Column newCol = (Column)ObjectUtils.deepCopy(col); |
| 409 | 0 | newColumns.add(newCol); |
| 410 | |
|
| 411 | |
} |
| 412 | |
|
| 413 | 0 | HtmlData returnUrl = getReturnUrl(element, lookupForm, returnKeys, businessObjectRestrictions); |
| 414 | 0 | ResultRow row = new ResultRow(newColumns, returnUrl.constructCompleteHtmlTag(), actionUrls); |
| 415 | 0 | row.setRowId(returnUrl.getName()); |
| 416 | |
|
| 417 | |
|
| 418 | 0 | if (getBusinessObjectDictionaryService().isExportable(getBusinessObjectClass())) { |
| 419 | |
|
| 420 | |
} |
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | 0 | boolean rowReturnable = true; |
| 425 | 0 | row.setRowReturnable(rowReturnable); |
| 426 | 0 | if (rowReturnable) { |
| 427 | 0 | hasReturnableRow = true; |
| 428 | |
} |
| 429 | 0 | resultTable.add(row); |
| 430 | 0 | } |
| 431 | |
|
| 432 | |
|
| 433 | 0 | lookupForm.setHasReturnableRow(hasReturnableRow); |
| 434 | |
|
| 435 | 0 | return displayList; |
| 436 | |
|
| 437 | |
} |
| 438 | |
|
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
|
| 444 | |
|
| 445 | |
|
| 446 | |
@Override |
| 447 | |
public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) { |
| 448 | |
|
| 449 | 0 | if(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_HEADER_ID.equals(propertyName)) { |
| 450 | |
|
| 451 | 0 | AnchorHtmlData link = new AnchorHtmlData(); |
| 452 | 0 | DocumentRouteHeaderValue doc = (DocumentRouteHeaderValue)bo; |
| 453 | |
|
| 454 | 0 | Long routeHeaderId = doc.getRouteHeaderId(); |
| 455 | 0 | link.setDisplayText(routeHeaderId+""); |
| 456 | |
|
| 457 | 0 | String href = ConfigContext.getCurrentContextConfig().getKRBaseURL()+"/"+ KEWConstants.APP_CODE + "/" + |
| 458 | |
KEWConstants.DOC_HANDLER_REDIRECT_PAGE + "?" + KEWConstants.COMMAND_PARAMETER + "=" + |
| 459 | |
KEWConstants.DOCSEARCH_COMMAND + "&" + KEWConstants.ROUTEHEADER_ID_PARAMETER + "=" + routeHeaderId; |
| 460 | |
|
| 461 | 0 | link.setHref(href); |
| 462 | |
|
| 463 | 0 | return link; |
| 464 | |
} |
| 465 | |
|
| 466 | 0 | return super.getInquiryUrl(bo, propertyName); |
| 467 | |
} |
| 468 | |
|
| 469 | |
|
| 470 | |
|
| 471 | |
|
| 472 | |
|
| 473 | |
@Override |
| 474 | |
protected void setRows() { |
| 475 | 0 | this.setRows(new HashMap<String,String[]>(), null); |
| 476 | 0 | } |
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
|
| 482 | |
protected void setRows(Map fieldValues, String docTypeName) { |
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | 0 | if (getRows() == null) { |
| 492 | 0 | super.setRows(); |
| 493 | |
} |
| 494 | 0 | List<Row> lookupRows = new ArrayList<Row>(); |
| 495 | |
|
| 496 | 0 | for (Row row : getRows()) { |
| 497 | 0 | lookupRows.add(row); |
| 498 | |
} |
| 499 | |
|
| 500 | 0 | getRows().clear(); |
| 501 | |
|
| 502 | 0 | processor = new DocumentLookupCriteriaProcessorKEWAdapter(); |
| 503 | |
|
| 504 | |
|
| 505 | 0 | DocumentType docType = null; |
| 506 | |
|
| 507 | 0 | if(StringUtils.isNotEmpty(docTypeName)) { |
| 508 | 0 | docType = getValidDocumentType((String)docTypeName); |
| 509 | |
} |
| 510 | |
|
| 511 | 0 | DocumentLookupCriteriaProcessorKEWAdapter documentLookupCriteriaProcessorKEWAdapter = (DocumentLookupCriteriaProcessorKEWAdapter)processor; |
| 512 | 0 | if(processor != null && documentLookupCriteriaProcessorKEWAdapter.getCriteriaProcessor()!=null) { |
| 513 | 0 | if(docType==null) { |
| 514 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(new StandardDocumentSearchCriteriaProcessor()); |
| 515 | 0 | } else if(!StringUtils.equals(docTypeName, documentLookupCriteriaProcessorKEWAdapter.getCriteriaProcessor().getDocSearchCriteriaDTO().getDocTypeFullName())){ |
| 516 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(docType.getDocumentSearchCriteriaProcessor()); |
| 517 | |
} |
| 518 | |
} else { |
| 519 | 0 | if(docType==null) { |
| 520 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(new StandardDocumentSearchCriteriaProcessor()); |
| 521 | |
} else { |
| 522 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(docType.getDocumentSearchCriteriaProcessor()); |
| 523 | |
} |
| 524 | |
} |
| 525 | |
|
| 526 | 0 | documentLookupCriteriaProcessorKEWAdapter.setDataDictionaryService(getDataDictionaryService()); |
| 527 | |
|
| 528 | 0 | boolean detailed=false; |
| 529 | 0 | if(this.getParameters().containsKey("isAdvancedSearch")) { |
| 530 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("isAdvancedSearch"))[0]); |
| 531 | 0 | } else if(fieldValues.containsKey("isAdvancedSearch")) { |
| 532 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String) fieldValues.get("isAdvancedSearch")); |
| 533 | |
} |
| 534 | |
|
| 535 | 0 | boolean superSearch=false; |
| 536 | 0 | if(this.getParameters().containsKey(("superUserSearch"))) { |
| 537 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("superUserSearch"))[0]); |
| 538 | 0 | } else if(fieldValues.containsKey("superUserSearch")) { |
| 539 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String)fieldValues.get("superUserSearch")); |
| 540 | |
} |
| 541 | |
|
| 542 | |
|
| 543 | 0 | List<Row> rows = processor.getRows(docType,lookupRows, detailed, superSearch); |
| 544 | |
|
| 545 | 0 | BusinessObjectEntry boe = KNSServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(this.getBusinessObjectClass().getName()); |
| 546 | 0 | int numCols = boe.getLookupDefinition().getNumOfColumns(); |
| 547 | 0 | if(numCols == 0) { |
| 548 | 0 | numCols = KNSConstants.DEFAULT_NUM_OF_COLUMNS; |
| 549 | |
} |
| 550 | |
|
| 551 | 0 | super.getRows().addAll(FieldUtils.wrapFields(this.getFields(rows),numCols )); |
| 552 | |
|
| 553 | 0 | } |
| 554 | |
|
| 555 | |
private List<Field> getFields(List<Row> rows){ |
| 556 | 0 | List<Field> rList = new ArrayList<Field>(); |
| 557 | |
|
| 558 | 0 | for(Row r: rows){ |
| 559 | 0 | for(Field f: r.getFields()){ |
| 560 | 0 | rList.add(f); |
| 561 | |
} |
| 562 | |
} |
| 563 | |
|
| 564 | 0 | return rList; |
| 565 | |
} |
| 566 | |
|
| 567 | |
private void setRowsAfterClear(DocSearchCriteriaDTO searchCriteria, Map<String,String[]> fieldValues) { |
| 568 | |
|
| 569 | |
|
| 570 | |
|
| 571 | |
|
| 572 | |
|
| 573 | 0 | if (getRows() == null) { |
| 574 | 0 | super.setRows(); |
| 575 | |
} |
| 576 | 0 | List<Row> lookupRows = new ArrayList<Row>(); |
| 577 | |
|
| 578 | 0 | for (Row row : getRows()) { |
| 579 | 0 | lookupRows.add(row); |
| 580 | |
} |
| 581 | 0 | super.getRows().clear(); |
| 582 | |
|
| 583 | 0 | processor = new DocumentLookupCriteriaProcessorKEWAdapter(); |
| 584 | |
|
| 585 | 0 | String docTypeName = searchCriteria.getDocTypeFullName(); |
| 586 | 0 | DocumentType docType = null; |
| 587 | |
|
| 588 | 0 | if(StringUtils.isNotEmpty(docTypeName)) { |
| 589 | 0 | docType = getValidDocumentType(docTypeName); |
| 590 | |
} |
| 591 | |
|
| 592 | 0 | DocumentLookupCriteriaProcessorKEWAdapter documentLookupCriteriaProcessorKEWAdapter = (DocumentLookupCriteriaProcessorKEWAdapter)processor; |
| 593 | 0 | if(processor != null && documentLookupCriteriaProcessorKEWAdapter.getCriteriaProcessor()!=null) { |
| 594 | 0 | if(docType==null) { |
| 595 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(new StandardDocumentSearchCriteriaProcessor()); |
| 596 | 0 | } else if(!StringUtils.equals(docTypeName, documentLookupCriteriaProcessorKEWAdapter.getCriteriaProcessor().getDocSearchCriteriaDTO().getDocTypeFullName())){ |
| 597 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(docType.getDocumentSearchCriteriaProcessor()); |
| 598 | |
} |
| 599 | |
} else { |
| 600 | 0 | if(docType==null) { |
| 601 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(new StandardDocumentSearchCriteriaProcessor()); |
| 602 | |
} else { |
| 603 | 0 | documentLookupCriteriaProcessorKEWAdapter.setCriteriaProcessor(docType.getDocumentSearchCriteriaProcessor()); |
| 604 | |
} |
| 605 | |
} |
| 606 | |
|
| 607 | 0 | documentLookupCriteriaProcessorKEWAdapter.setDataDictionaryService(getDataDictionaryService()); |
| 608 | |
|
| 609 | 0 | boolean detailed=false; |
| 610 | 0 | if(this.getParameters().containsKey("isAdvancedSearch")) { |
| 611 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("isAdvancedSearch"))[0]); |
| 612 | 0 | } else if(fieldValues.containsKey("isAdvancedSearch")) { |
| 613 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String) fieldValues.get("isAdvancedSearch")[0]); |
| 614 | |
} |
| 615 | |
|
| 616 | 0 | boolean superSearch=false; |
| 617 | 0 | if(this.getParameters().containsKey(("superUserSearch"))) { |
| 618 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("superUserSearch"))[0]); |
| 619 | 0 | } else if(fieldValues.containsKey("superUserSearch")) { |
| 620 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String)fieldValues.get("superUserSearch")[0]); |
| 621 | |
} |
| 622 | |
|
| 623 | 0 | List<Row> rows = documentLookupCriteriaProcessorKEWAdapter.getRows(docType, super.getRows(), detailed, superSearch); |
| 624 | |
|
| 625 | 0 | super.getRows().addAll(rows); |
| 626 | |
|
| 627 | |
|
| 628 | 0 | if(StringUtils.isNotEmpty(docTypeName)) { |
| 629 | 0 | for (Row row : super.getRows()) { |
| 630 | 0 | for (Field field : row.getFields()) { |
| 631 | |
|
| 632 | 0 | String propertyName = null; |
| 633 | 0 | if(field.getPropertyName().startsWith(KNSConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { |
| 634 | 0 | propertyName = StringUtils.remove(field.getPropertyName(), KNSConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX); |
| 635 | |
} else { |
| 636 | 0 | propertyName = field.getPropertyName(); |
| 637 | |
} |
| 638 | |
|
| 639 | 0 | if (fieldValues.get(propertyName) != null) { |
| 640 | 0 | Object value = this.getDocSearchCriteriaDTOFieldValue(searchCriteria, field.getPropertyName()); |
| 641 | 0 | if (value instanceof String |
| 642 | |
&& StringUtils.isNotEmpty((String)value)) { |
| 643 | 0 | field.setPropertyValue(value); |
| 644 | 0 | } else if (value instanceof List){ |
| 645 | 0 | field.setPropertyValues((String[])((List)value).toArray()); |
| 646 | |
} |
| 647 | |
} |
| 648 | 0 | } |
| 649 | |
} |
| 650 | |
} |
| 651 | 0 | } |
| 652 | |
|
| 653 | |
|
| 654 | |
|
| 655 | |
|
| 656 | |
|
| 657 | |
@Override |
| 658 | |
public void performClear(LookupForm lookupForm) { |
| 659 | |
|
| 660 | |
|
| 661 | |
|
| 662 | |
|
| 663 | |
|
| 664 | |
|
| 665 | |
|
| 666 | |
|
| 667 | |
|
| 668 | |
|
| 669 | |
|
| 670 | |
|
| 671 | |
|
| 672 | |
|
| 673 | 0 | Map<String,String[]> fixedParameters = new HashMap<String,String[]>(); |
| 674 | 0 | Map<String,String> changedDateFields = preprocessDateFields(lookupForm.getFieldsForLookup()); |
| 675 | 0 | fixedParameters.putAll(this.getParameters()); |
| 676 | 0 | for (Map.Entry<String,String> prop : changedDateFields.entrySet()) { |
| 677 | 0 | fixedParameters.remove(prop.getKey()); |
| 678 | 0 | fixedParameters.put(prop.getKey(), new String[]{prop.getValue()}); |
| 679 | |
} |
| 680 | |
|
| 681 | 0 | String docTypeName = fixedParameters.get("docTypeFullName")[0]; |
| 682 | |
|
| 683 | 0 | DocumentType docType = getValidDocumentType(docTypeName); |
| 684 | |
|
| 685 | 0 | if(docType == null) { |
| 686 | 0 | super.performClear(lookupForm); |
| 687 | |
|
| 688 | |
|
| 689 | 0 | boolean detailed=false; |
| 690 | 0 | if(this.getParameters().containsKey("isAdvancedSearch")) { |
| 691 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("isAdvancedSearch"))[0]); |
| 692 | 0 | } else if(fixedParameters.containsKey("isAdvancedSearch")) { |
| 693 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String) fixedParameters.get("isAdvancedSearch")[0]); |
| 694 | |
} |
| 695 | |
|
| 696 | 0 | boolean superSearch=false; |
| 697 | 0 | if(this.getParameters().containsKey(("superUserSearch"))) { |
| 698 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("superUserSearch"))[0]); |
| 699 | 0 | } else if(fixedParameters.containsKey("superUserSearch")) { |
| 700 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase((String) fixedParameters.get("superUserSearch")[0]); |
| 701 | |
} |
| 702 | |
|
| 703 | |
|
| 704 | 0 | int fieldsRepopulated = 0; |
| 705 | 0 | List<Row> rows = super.getRows(); |
| 706 | 0 | int index = rows.size() - 1; |
| 707 | 0 | while (index >= 0 && fieldsRepopulated < 2) { |
| 708 | 0 | for (Field tempField : rows.get(index).getFields()) { |
| 709 | 0 | if ("isAdvancedSearch".equals(tempField.getPropertyName())) { |
| 710 | 0 | tempField.setPropertyValue(detailed?"YES":"NO"); |
| 711 | 0 | fieldsRepopulated++; |
| 712 | |
} |
| 713 | 0 | else if ("superUserSearch".equals(tempField.getPropertyName())) { |
| 714 | 0 | tempField.setPropertyValue(superSearch?"YES":"NO"); |
| 715 | 0 | fieldsRepopulated++; |
| 716 | |
} |
| 717 | |
} |
| 718 | 0 | index--; |
| 719 | |
} |
| 720 | 0 | } else { |
| 721 | 0 | DocSearchCriteriaDTO docCriteria = DocumentLookupCriteriaBuilder.populateCriteria(fixedParameters); |
| 722 | 0 | docCriteria = docType.getDocumentSearchGenerator().clearSearch(docCriteria); |
| 723 | 0 | if (docCriteria == null) { |
| 724 | 0 | docCriteria = new DocSearchCriteriaDTO(); |
| 725 | |
} |
| 726 | |
|
| 727 | 0 | this.setRowsAfterClear(docCriteria, fixedParameters); |
| 728 | |
} |
| 729 | |
|
| 730 | 0 | } |
| 731 | |
|
| 732 | |
|
| 733 | |
|
| 734 | |
|
| 735 | |
|
| 736 | |
|
| 737 | |
|
| 738 | |
private static DocumentType getValidDocumentType(String docTypeName) { |
| 739 | 0 | if (StringUtils.isNotEmpty(docTypeName)) { |
| 740 | 0 | DocumentType dTypeCriteria = new DocumentType(); |
| 741 | 0 | dTypeCriteria.setName(docTypeName.trim()); |
| 742 | 0 | dTypeCriteria.setActive(true); |
| 743 | 0 | Collection<DocumentType> docTypeList = KEWServiceLocator.getDocumentTypeService().find(dTypeCriteria, null, false); |
| 744 | |
|
| 745 | |
|
| 746 | 0 | DocumentType firstDocumentType = null; |
| 747 | 0 | if(docTypeList != null){ |
| 748 | 0 | for(DocumentType dType: docTypeList){ |
| 749 | 0 | if (firstDocumentType == null) { |
| 750 | 0 | firstDocumentType = dType; |
| 751 | |
} |
| 752 | 0 | if (StringUtils.equals(docTypeName.toUpperCase(), dType.getName().toUpperCase())) { |
| 753 | 0 | return dType; |
| 754 | |
} |
| 755 | |
} |
| 756 | 0 | return firstDocumentType; |
| 757 | |
} |
| 758 | |
} |
| 759 | |
|
| 760 | 0 | return null; |
| 761 | |
} |
| 762 | |
|
| 763 | |
|
| 764 | |
|
| 765 | |
|
| 766 | |
|
| 767 | |
@Override |
| 768 | |
public String getSupplementalMenuBar() { |
| 769 | 0 | boolean detailed = false; |
| 770 | 0 | if(this.getParameters().containsKey("isAdvancedSearch")) { |
| 771 | 0 | detailed = DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("isAdvancedSearch"))[0]); |
| 772 | |
} |
| 773 | |
|
| 774 | 0 | boolean superSearch = false; |
| 775 | 0 | if(this.getParameters().containsKey("superUserSearch")) { |
| 776 | 0 | superSearch = DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING.equalsIgnoreCase(((String[])this.getParameters().get("superUserSearch"))[0]); |
| 777 | |
} |
| 778 | |
|
| 779 | 0 | StringBuilder suppMenuBar = new StringBuilder(); |
| 780 | |
|
| 781 | |
|
| 782 | 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( |
| 783 | |
"`))\" 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\" />"); |
| 784 | |
|
| 785 | |
|
| 786 | 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( |
| 787 | |
"`))\" 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\" />"); |
| 788 | |
|
| 789 | |
|
| 790 | 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\" />"); |
| 791 | |
|
| 792 | 0 | Properties parameters = new Properties(); |
| 793 | 0 | parameters.put(KNSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, this.getBusinessObjectClass().getName()); |
| 794 | 0 | this.getParameters().keySet(); |
| 795 | 0 | for (Object parameter : this.getParameters().keySet()) { |
| 796 | 0 | parameters.put(parameter, this.getParameters().get(parameter)); |
| 797 | |
} |
| 798 | |
|
| 799 | 0 | UrlFactory.parameterizeUrl(KNSConstants.LOOKUP_ACTION, parameters); |
| 800 | 0 | return suppMenuBar.toString(); |
| 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 | |
|
| 837 | |
@Override |
| 838 | |
public boolean shouldDisplayHeaderNonMaintActions() { |
| 839 | 0 | return this.processor.shouldDisplayHeaderNonMaintActions(); |
| 840 | |
} |
| 841 | |
|
| 842 | |
|
| 843 | |
|
| 844 | |
|
| 845 | |
|
| 846 | |
@Override |
| 847 | |
public boolean shouldDisplayLookupCriteria() { |
| 848 | 0 | return this.processor.shouldDisplayLookupCriteria(); |
| 849 | |
} |
| 850 | |
|
| 851 | |
|
| 852 | |
|
| 853 | |
|
| 854 | |
|
| 855 | |
@Override |
| 856 | |
public boolean checkForAdditionalFields(Map fieldValues) { |
| 857 | |
|
| 858 | |
|
| 859 | 0 | String docTypeName = null; |
| 860 | 0 | if(this.getParameters().get("docTypeFullName")!=null) { |
| 861 | 0 | docTypeName = ((String[])this.getParameters().get("docTypeFullName"))[0]; |
| 862 | |
} |
| 863 | 0 | else if(fieldValues.get("docTypeFullName")!=null) { |
| 864 | 0 | docTypeName = (String)fieldValues.get("docTypeFullName"); |
| 865 | |
} |
| 866 | 0 | if(!StringUtils.isEmpty(docTypeName)) { |
| 867 | 0 | DocumentType dType = getValidDocumentType(docTypeName); |
| 868 | |
|
| 869 | 0 | DocSearchCriteriaDTO criteria = DocumentLookupCriteriaBuilder.populateCriteria(getParameters()); |
| 870 | 0 | if (dType != null) { |
| 871 | 0 | MessageMap messages = getValidDocumentType(dType.getName()).getDocumentSearchGenerator().getMessageMap(criteria); |
| 872 | 0 | if (messages != null |
| 873 | |
&& messages.hasMessages()) { |
| 874 | 0 | GlobalVariables.mergeErrorMap(messages); |
| 875 | |
} |
| 876 | 0 | setRows(fieldValues,dType.getName()); |
| 877 | 0 | return true; |
| 878 | |
} |
| 879 | |
} |
| 880 | |
|
| 881 | 0 | setRows(fieldValues, docTypeName); |
| 882 | |
|
| 883 | 0 | return true; |
| 884 | |
} |
| 885 | |
|
| 886 | |
|
| 887 | |
|
| 888 | |
|
| 889 | |
@Override |
| 890 | |
public void validateSearchParameters(Map fieldValues) { |
| 891 | 0 | super.validateSearchParameters(fieldValues); |
| 892 | 0 | DocumentSearchService docSearchService = KEWServiceLocator.getDocumentSearchService(); |
| 893 | 0 | DocSearchCriteriaDTO criteria = DocumentLookupCriteriaBuilder.populateCriteria(getParameters()); |
| 894 | 0 | DocumentType docType = null; |
| 895 | 0 | if(StringUtils.isNotEmpty(criteria.getDocTypeFullName())) { |
| 896 | 0 | docType = getValidDocumentType((String)criteria.getDocTypeFullName()); |
| 897 | |
} |
| 898 | 0 | DocumentSearchGenerator generator=null; |
| 899 | 0 | if(docType!=null) { |
| 900 | 0 | generator = docType.getDocumentSearchGenerator(); |
| 901 | |
} else { |
| 902 | 0 | generator = KEWServiceLocator.getDocumentSearchService().getStandardDocumentSearchGenerator(); |
| 903 | |
} |
| 904 | |
try { |
| 905 | 0 | docSearchService.validateDocumentSearchCriteria(generator, criteria); |
| 906 | 0 | } catch (WorkflowServiceErrorException wsee) { |
| 907 | 0 | for (WorkflowServiceError workflowServiceError : (List<WorkflowServiceError>)wsee.getServiceErrors()) { |
| 908 | 0 | if(workflowServiceError.getMessageMap() != null && workflowServiceError.getMessageMap().hasErrors()){ |
| 909 | |
|
| 910 | 0 | GlobalVariables.getMessageMap().merge(workflowServiceError.getMessageMap()); |
| 911 | |
}else{ |
| 912 | |
|
| 913 | 0 | GlobalVariables.getMessageMap().putError(workflowServiceError.getMessage(), RiceKeyConstants.ERROR_CUSTOM, workflowServiceError.getMessage()); |
| 914 | |
} |
| 915 | |
}; |
| 916 | 0 | } |
| 917 | 0 | if(!GlobalVariables.getMessageMap().hasNoErrors()) { |
| 918 | 0 | throw new ValidationException("errors in search criteria"); |
| 919 | |
} |
| 920 | |
|
| 921 | 0 | } |
| 922 | |
|
| 923 | |
|
| 924 | |
|
| 925 | |
|
| 926 | |
|
| 927 | |
@Override |
| 928 | |
public boolean performCustomAction(boolean ignoreErrors) { |
| 929 | 0 | DocumentSearchService docSearchService = KEWServiceLocator.getDocumentSearchService(); |
| 930 | |
|
| 931 | 0 | Map<String,String> fieldValues = new HashMap<String,String>(); |
| 932 | 0 | Map<String,String[]> multFieldValues = new HashMap<String,String[]>(); |
| 933 | |
|
| 934 | |
|
| 935 | 0 | String[] methodToCallArray = ((String[])this.getParameters().get(KNSConstants.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, KNSConstants.DISPATCH_REQUEST_PARAMETER + ".customLookupableMethodCall.")) { |
| 941 | 0 | if (parameter.trim().endsWith(".x")) { |
| 942 | 0 | parameterValue = StringUtils.substringBetween(parameter, KNSConstants.DISPATCH_REQUEST_PARAMETER + ".customLookupableMethodCall.", ".x"); |
| 943 | 0 | } else if (parameter.trim().endsWith(".y")) { |
| 944 | 0 | parameterValue = StringUtils.substringBetween(parameter, KNSConstants.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, KNSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KNSConstants.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, KNSConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, KNSConstants.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, KNSConstants.METHOD_TO_CALL_PARM4_LEFT_DEL, KNSConstants.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(KNSConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { |
| 1165 | 0 | propertyName = StringUtils.remove(fieldName, KNSConstants.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(KNSConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { |
| 1189 | 0 | propertyName = StringUtils.remove(fieldName, KNSConstants.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(KNSConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { |
| 1211 | 0 | if (StringUtils.contains((String)valueToReturn, "..")) { |
| 1212 | 0 | valueToReturn = StringUtils.split((String)valueToReturn, "..")[0]; |
| 1213 | 0 | } else if (StringUtils.contains((String)valueToReturn, ">=")) { |
| 1214 | 0 | valueToReturn = StringUtils.split((String)valueToReturn, ">=")[0]; |
| 1215 | |
} else { |
| 1216 | 0 | valueToReturn = null; |
| 1217 | |
} |
| 1218 | |
} else { |
| 1219 | 0 | if (StringUtils.contains((String)valueToReturn, "..")) { |
| 1220 | 0 | valueToReturn = StringUtils.split((String)valueToReturn, "..")[1]; |
| 1221 | 0 | } else if (StringUtils.contains((String)valueToReturn, ">=")) { |
| 1222 | 0 | valueToReturn = null; |
| 1223 | 0 | } else if (StringUtils.contains((String)valueToReturn, "<=")) { |
| 1224 | 0 | valueToReturn = StringUtils.split((String)valueToReturn, "<=")[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 | |
} |