Coverage Report - org.kuali.rice.kew.bo.lookup.DocSearchCriteriaDTOLookupableHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocSearchCriteriaDTOLookupableHelperServiceImpl
0%
0/547
0%
0/398
13.5
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * Lookupable helper class for new doc search
 90  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
          * @see org.kuali.rice.kew.bo.lookup.DocumentRouteHeaderValueLookupableHelperService#setDateTimeService(org.kuali.rice.kns.service.DateTimeService)
 104  
          */
 105  
         public void setDateTimeService(DateTimeService dateTimeService) {
 106  0
                 this.dateTimeService = dateTimeService;
 107  0
         }
 108  
 
 109  
         /**
 110  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#performLookup(org.kuali.rice.kns.web.struts.form.LookupForm, java.util.Collection, boolean)
 111  
          */
 112  
         @Override
 113  
         public Collection performLookup(LookupForm lookupForm,
 114  
                         Collection resultTable, boolean bounded) {
 115  
 
 116  
                 //TODO: ideally implement KNS updates to make this not require code from the parent
 117  
 
 118  0
             Map<String,String[]> parameters = this.getParameters();
 119  
 
 120  0
             DocSearchCriteriaDTO criteria = null;
 121  0
             if(savedSearch) {
 122  
                     //TODO: set the criteria on this from below method instead of this (so we're not calling out twice for the same object)
 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  
                                         // merge the message maps
 155  0
                                         GlobalVariables.getMessageMap().merge(workflowServiceError.getMessageMap());
 156  
                                 }else{
 157  
                                         //TODO: can we add something to this to get it to highlight the right field too?  Maybe in arg1
 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  
             // check various warning conditions
 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  
 //            for (DocumentSearchResult documentSearchResult : result) {
 187  0
                         displayList = result;//.getResultContainers();
 188  
 //                }
 189  
 
 190  
                 //####BEGIN COPIED CODE#########
 191  0
         setBackLocation((String) lookupForm.getFieldsForLookup().get(KNSConstants.BACK_LOCATION));
 192  0
         setDocFormKey((String) lookupForm.getFieldsForLookup().get(KNSConstants.DOC_FORM_KEY));
 193  
 
 194  
 //###COMENTED OUT
 195  
 //                  Collection displayList;
 196  
 //        // call search method to get results
 197  
 //        if (bounded) {
 198  
 //            displayList = getSearchResults(lookupForm.getFieldsForLookup());
 199  
 //        }
 200  
 //        else {
 201  
 //            displayList = getSearchResultsUnbounded(lookupForm.getFieldsForLookup());
 202  
 //        }
 203  
 //##COMENTED OUT
 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  
         // iterate through result list and wrap rows with return url and action urls
 214  
 
 215  
 //COMMENTING THIS OUT FOR NOW
 216  
 //        for (Iterator iter = displayList.iterator(); iter.hasNext();) {
 217  
 //            BusinessObject element = (BusinessObject) iter.next();
 218  
 //                if(element instanceof PersistableBusinessObject){
 219  
 //                lookupForm.setLookupObjectId(((PersistableBusinessObject)element).getObjectId());
 220  
 //            }
 221  0
         DocumentRouteHeaderEBO element = new DocSearchCriteriaDTO();
 222  
         //TODO: additional BORestrictions through generator or component to lock down per document?
 223  0
             BusinessObjectRestrictions businessObjectRestrictions = getBusinessObjectAuthorizationService().getLookupResultRestrictions(element, user);
 224  
 
 225  
 //          String actionUrls = getActionUrls(element, pkNames, businessObjectRestrictions);
 226  
 //ADDED (4 lines)
 227  0
         for (DocumentSearchResult documentSearchResult : result) {
 228  
 
 229  
 
 230  
 
 231  
 
 232  
 
 233  0
                 DocumentSearchResult docSearchResult = (DocumentSearchResult)documentSearchResult;
 234  
 //TODO: where to get these from?
 235  
 //                HtmlData returnUrl = new AnchorHtmlData();
 236  0
                 String actionUrls = "";
 237  
 
 238  
 //ADDED (3)
 239  0
             List<? extends Column> origColumns = components.getColumns();//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  
 //            for (Iterator iterator = columns.iterator(); iterator.hasNext();) {
 245  
 
 246  
 //                Column col = (Column) iterator.next();
 247  
 //ADDED 3
 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  
                               //means we didn't find an indexed value for this, this seems bad but happens a lot we should research why
 258  0
                               keyValue = new KeyValueSort();
 259  
 //                              System.out.println("column: "+col.getPropertyName()+"has an empty KeyValue, this should never happen");
 260  
                       }
 261  
 
 262  
                       //Set values from keyvalue on column
 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  
                                       //TODO: find a better place for this
 270  0
                                       labelMessageKey = "Route Log";
 271  
                               } else {
 272  
                                       //TODO: change this to an enum (or another dd property)
 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_DOCUMENT_ID)) {
 282  0
                                         ((DocSearchCriteriaDTO)element).setDocumentId(col.getPropertyValue());
 283  
                                 }
 284  
 
 285  0
                     Formatter formatter = col.getFormatter();
 286  
 
 287  
                 // pick off result column from result list, do formatting
 288  0
                 String propValue = KNSConstants.EMPTY_STRING;
 289  
 //                Object prop = ObjectUtils.getPropertyValue(element, col.getPropertyName());
 290  
 //ADDED
 291  0
                 Object prop=keyValue.getSortValue();
 292  
 
 293  
                 // set comparator and formatter based on property type
 294  0
                 Class propClass = propertyTypes.get(propertyName);
 295  0
                 if ( propClass == null ) {
 296  
                     try {
 297  
                             //ADDED 3
 298  0
                             if(prop!=null) {
 299  0
                                     propertyTypes.put(propertyName, prop.getClass());
 300  0
                                     propClass = prop.getClass();
 301  
                             }
 302  
 
 303  
                             //propClass = ObjectUtils.getPropertyType( element, col.getPropertyName(), getPersistenceStructureService() );
 304  
 //                            propertyTypes.put( col.getPropertyName(), propClass );
 305  0
                     } catch (Exception e) {
 306  
 //                        throw new RuntimeException("Cannot access PropertyType for property " + "'" + col.getPropertyName() + "' " + " on an instance of '" + element.getClass().getName() + "'.", e);
 307  0
                     }
 308  
                 }
 309  
 
 310  
 
 311  
                 //TODO: check exisiting formatter here, ideally we should be getting this formatter from col.getFormatter in most cases
 312  
                 // formatters
 313  0
                 if (prop != null) {
 314  0
                     if (formatter == null) {
 315  
                         // for Booleans, always use BooleanFormatter
 316  0
                         if (prop instanceof Boolean) {
 317  0
                             formatter = new BooleanFormatter();
 318  
                         }
 319  
 
 320  
                         // for Dates, always use DateFormatter
 321  0
                         if (prop instanceof Date) {
 322  0
                             formatter = new DateFormatter();
 323  
                         }
 324  
                         //#ADDED 3
 325  0
                         if (prop instanceof Timestamp) {
 326  0
                             formatter = new TimestampAMPMFormatter();
 327  
                         }
 328  
 
 329  
                         // for collection, use the list formatter if a formatter hasn't been defined yet
 330  0
                         if (prop instanceof Collection && formatter == null) {
 331  0
                             formatter = new CollectionFormatter();
 332  
                         }
 333  
                     }
 334  0
                     if (formatter != null) {
 335  
                         //hack for Currency values as big decimal
 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  
                 // comparator
 349  0
                 col.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass));
 350  0
                 col.setValueComparator(CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass));
 351  
 
 352  
                 //TODO: can we call into a method in the result processor to get this (or set something on the criteria)
 353  
 //                propValue = maskValueIfNecessary(element.getClass(), col.getPropertyName(), propValue, businessObjectRestrictions);
 354  
 
 355  0
                 col.setPropertyValue(propValue);
 356  
 
 357  0
                 if (StringUtils.isNotBlank(propValue)) {
 358  
 //                    col.setColumnAnchor(getInquiryUrl(element, col.getPropertyName()));
 359  
 //ADDED (3 lines)
 360  0
                         AnchorHtmlData anchor = new AnchorHtmlData(KNSConstants.EMPTY_STRING, KNSConstants.EMPTY_STRING);
 361  
                         //TODO: change to grab URL from config variable
 362  0
                         if(StringUtils.isNotEmpty(keyValue.getValue()) && StringUtils.equals("documentId", 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  
                                         // KULRICE-3035: Append the doc search's returnLocation parameter to the superuser page URL.
 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=\"", "documentId=")+"documentId="+keyValue.getUserDisplayValue() + returnLoc);
 383  
                                 }
 384  0
                         col.setMaxLength(100); //for now force this
 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); //for now force this
 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); //for now force this
 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  
             // because of concerns of the BO being cached in session on the ResultRow,
 417  
             // let's only attach it when needed (currently in the case of export)
 418  0
             if (getBusinessObjectDictionaryService().isExportable(getBusinessObjectClass())) {
 419  
                     //                    row.setBusinessObject(element);
 420  
             }
 421  
 
 422  
             //            boolean rowReturnable = isResultReturnable(element);
 423  
             //ADDED
 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  
                 //####END COPIED CODE#########
 437  
         }
 438  
 
 439  
 
 440  
 
 441  
 
 442  
 
 443  
         /**
 444  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getInquiryUrl(org.kuali.rice.kns.bo.BusinessObject, java.lang.String)
 445  
          */
 446  
         @Override
 447  
         public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) {
 448  
                 //FIXME: ctk - make sure and check that it's ok to do this here.  I may move this out to the doc search processor
 449  0
                 if(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_ID.equals(propertyName)) {
 450  
 
 451  0
                         AnchorHtmlData link = new AnchorHtmlData();
 452  0
                         DocumentRouteHeaderValue doc = (DocumentRouteHeaderValue)bo;
 453  
                         //if !superuser
 454  0
                         String documentId = doc.getDocumentId();
 455  0
                         link.setDisplayText(documentId+"");
 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.DOCUMENT_ID_PARAMETER + "=" + documentId;
 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  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#setRows()
 472  
          */
 473  
         @Override
 474  
         protected void setRows() {
 475  0
             this.setRows(new HashMap<String,String[]>(), null);
 476  0
         }
 477  
 
 478  
 
 479  
         /**
 480  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#setRows()
 481  
          */
 482  
         protected void setRows(Map fieldValues, String docTypeName) {
 483  
                 // TODO chris - this method should call the criteria processor adapter which will
 484  
                 //call the criteria processor (either standard or custom) and massage the data into the proper format
 485  
                 //this is called by setbo in super(which is called by form) so should be called when the page needs refreshing
 486  
 
 487  
                 //TODO: move over code that checks for doctype (actually should that be in the refresh, since that's where the doc type will be coming back to?)
 488  
 
 489  
 
 490  
                 //###START LOOKUP ROW CODE Not sure if we need these but they may be valuable for eventually forcing all standard field customization in the xml
 491  0
                 if (getRows() == null) {
 492  0
                     super.setRows();
 493  
                 }
 494  0
                 List<Row> lookupRows = new ArrayList<Row>();
 495  
                 //copy the current rows
 496  0
                 for (Row row : getRows()) {
 497  0
                         lookupRows.add(row);
 498  
                 }
 499  
                 //clear out
 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  
                 //TODO: This should probably be moved into spring injection since it's a constant
 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  
                 //call get rows
 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  
                 // TODO chris - this method should call the criteria processor adapter which will
 569  
                 //call the criteria processor (either standard or custom) and massage the data into the proper format
 570  
                 //this is called by setbo in super(which is called by form) so should be called when the page needs refreshing
 571  
 
 572  
                 //TODO: move over code that checks for doctype (actually should that be in the refresh, since that's where the doc type will be coming back to?)
 573  0
                if (getRows() == null) {
 574  0
                     super.setRows();
 575  
                 }
 576  0
                List<Row> lookupRows = new ArrayList<Row>();
 577  
                 //copy the current rows
 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  
                 //TODO: This should probably be moved into spring injection since it's a constant
 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  
                 //call get rows
 623  0
                 List<Row> rows = documentLookupCriteriaProcessorKEWAdapter.getRows(docType, super.getRows(), detailed, superSearch);
 624  
 
 625  0
                 super.getRows().addAll(rows);
 626  
 
 627  
                 //Set field values from DocSearchCriteria
 628  0
                 if(StringUtils.isNotEmpty(docTypeName)) {
 629  0
                     for (Row row : super.getRows()) {
 630  0
                         for (Field field : row.getFields()) {
 631  
                             //if from date, strip off prefix
 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  
                             //We don't need to set field if it was already empty
 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  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#performClear()
 656  
          */
 657  
         @Override
 658  
         public void performClear(LookupForm lookupForm) {
 659  
                 //Map<String,String[]> fieldsToClear = new HashMap<String,String[]>();
 660  
 
 661  
                 //for (Row row : this.getRows()) {
 662  
                 //        for (Field field : row.getFields()) {
 663  
                 //                String[] propertyValue = {};
 664  
                 //                if(!Field.MULTI_VALUE_FIELD_TYPES.contains(field.getFieldType())) {
 665  
                 //                        propertyValue = new String[]{field.getPropertyValue()};
 666  
                 //                } else {
 667  
                 //                        propertyValue = field.getPropertyValues();
 668  
                 //                }
 669  
                 //                fieldsToClear.put(field.getPropertyName(), propertyValue);
 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  
                 //TODO: also check if standard here (maybe from object if use criteria)
 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  
                     // Retrieve the detailed/superuser search statuses.
 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  
                 // Repopulate the fields indicating detailed/superuser search status.
 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  
          * retrieve a document type. This is not a case sensitive search so "TravelRequest" == "Travelrequest"
 734  
          *
 735  
          * @param docTypeName
 736  
          * @return
 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  
                     // Return the first valid doc type.
 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  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getSupplementalMenuBar()
 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  
                 // Add the detailed-search-toggling button.
 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  
                 // Add the superuser-search-toggling button.
 786  0
                 suppMenuBar.append("&nbsp;").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  
                 // Add the "clear saved searches" button.
 790  0
                 suppMenuBar.append("&nbsp;").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  
 //     * This method is called by performLookup method to generate supplemental action urls.
 805  
 //     * It calls the method getCustomActionUrls to get html data, calls getMaintenanceUrl to get the actual html tag,
 806  
 //     * and returns a formatted/concatenated string of action urls.
 807  
 //     *
 808  
 //     * @see org.kuali.core.lookup.LookupableHelperService#getActionUrls(org.kuali.core.bo.BusinessObject)
 809  
 //     */
 810  
 //    public String getSupplementalActionUrls(List<HtmlData> htmlDataList) {
 811  
 //        StringBuffer actions = new StringBuffer();
 812  
 //
 813  
 //        for(HtmlData htmlData: htmlDataList){
 814  
 //                actions.append(getMaintenanceUrl(businessObject, htmlData, pkNames, businessObjectRestrictions));
 815  
 //            if(htmlData.getChildUrlDataList()!=null){
 816  
 //                    if(htmlData.getChildUrlDataList().size()>0){
 817  
 //                    actions.append(ACTION_URLS_CHILDREN_STARTER);
 818  
 //                            for(HtmlData childURLData: htmlData.getChildUrlDataList()){
 819  
 //                                actions.append(getMaintenanceUrl(businessObject, childURLData, pkNames, businessObjectRestrictions));
 820  
 //                            actions.append(ACTION_URLS_CHILDREN_SEPARATOR);
 821  
 //                            }
 822  
 //                            if(actions.toString().endsWith(ACTION_URLS_CHILDREN_SEPARATOR))
 823  
 //                                    actions.delete(actions.length()-ACTION_URLS_CHILDREN_SEPARATOR.length(), actions.length());
 824  
 //                    actions.append(ACTION_URLS_CHILDREN_END);
 825  
 //                    }
 826  
 //            }
 827  
 //                actions.append(ACTION_URLS_SEPARATOR);
 828  
 //        }
 829  
 //        if(actions.toString().endsWith(ACTION_URLS_SEPARATOR))
 830  
 //                actions.delete(actions.length()-ACTION_URLS_SEPARATOR.length(), actions.length());
 831  
 //        return actions.toString();
 832  
 //    }
 833  
 
 834  
         /**
 835  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#shouldDisplayHeaderNonMaintActions()
 836  
          */
 837  
         @Override
 838  
         public boolean shouldDisplayHeaderNonMaintActions() {
 839  0
                 return this.processor.shouldDisplayHeaderNonMaintActions();
 840  
         }
 841  
 
 842  
 
 843  
         /**
 844  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#shouldDisplayLookupCriteria()
 845  
          */
 846  
         @Override
 847  
         public boolean shouldDisplayLookupCriteria() {
 848  0
                 return this.processor.shouldDisplayLookupCriteria();
 849  
         }
 850  
 
 851  
 
 852  
         /**
 853  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#checkForAdditionalFields(java.util.Map)
 854  
          */
 855  
         @Override
 856  
         public boolean checkForAdditionalFields(Map fieldValues) {
 857  
                 // TODO chris - THIS METHOD NEEDS JAVADOCS
 858  
 //                return super.checkForAdditionalFields(fieldValues);
 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  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#validateSearchParameters(java.util.Map)
 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  
                                         // merge the message maps
 910  0
                                         GlobalVariables.getMessageMap().merge(workflowServiceError.getMessageMap());
 911  
                                 }else{
 912  
                                         //TODO: can we add something to this to get it to highlight the right field too?  Maybe in arg1
 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  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#performCustomAction(boolean)
 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  
                 // Determine if there are any properties embedded in the methodToCall parameter, and retrieve them if so.
 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  
                 //String[] methodToCallArray = ((String[])this.getParameters().get(KNSConstants.DISPATCH_REQUEST_PARAMETER + ".customLookupableMethodCall"));
 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  
                                 // Retrieve the isAdvancedSearch property, if present.
 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  
                                 // Retrieve the superUserSearch property, if present.
 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  
                                 // Retrieve and act upon the resetSavedSearch property, if present and set to true.
 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  
                                 // If any of the above properties were found, reset the rows in a manner similar to KualiLookupAction.refresh, but with
 987  
                                 // enough modifications to prevent any changed isAdvancedSearch or superUserSearch values from being overridden again.
 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  
                                                                         //multi value, set to values
 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  
                                                                             //multi value, set to values
 1025  0
                                                                             field.setPropertyValues((String[])this.getParameters().get(field.getPropertyName()));
 1026  
                                                                     }
 1027  
                                                                     //FIXME: any reason this is inside this "if" instead of the outer one, like above - this seems inconsistent
 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  
                                 // Finally, return false to prevent the search from being performed and to skip the other custom processing below.
 1038  0
                                 return false;
 1039  
                                 }
 1040  
 
 1041  
                         }
 1042  
                 } // End of methodToCall parameter retrieval.
 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  
                                 //if we're ignoring errors and we got an error just return, no reason to continue.  Also set false to indicate not to perform lookup
 1057  0
                                 return false;
 1058  
                         }
 1059  
                         //TODO: is there a better way to override a single field value?
 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  
                 //put the doc type from the criteria in the map to send to setRows and then call setRows
 1085  0
                 String docTypeName = criteria.getDocTypeFullName();
 1086  
 
 1087  
 
 1088  0
                 setRows(fieldValues,docTypeName);
 1089  
 
 1090  
                 //set field values (besides search atts) here
 1091  
 //                fieldValues.put("docTypeFullName", docTypeName);
 1092  
 //                fieldValues.put("fromDateCreated", criteria.getFromDateCreated());
 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  
                             //may be on the root of the criteria object, try looking there:
 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  
 //                                                        e.printStackTrace();
 1127  
                                                         //hmm what to do here, we should be able to find everything either in the search atts or at the base as far as I know.
 1128  0
                                                 }
 1129  0
                                                 if(fieldValue!=null) {
 1130  0
                                                         field.setPropertyValue(fieldValue);
 1131  
                                                 }
 1132  
 
 1133  
                     }
 1134  
                 }
 1135  0
             }
 1136  0
         }
 1137  
         //indicate to subsequent actions (search in this case) that a saved search was just populated
 1138  0
         savedSearch=true;
 1139  
 
 1140  0
         return true;
 1141  
         }
 1142  
 
 1143  
         /**
 1144  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getExtraField()
 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  
     @Override
 1235  
     public List<Row> getRows() {
 1236  
         if(StringUtils.isEmpty(docTypeName)) {
 1237  
             super.performClear(lookupForm);
 1238  
         } else {
 1239  
             DocSearchCriteriaDTO docCriteria = DocumentLookupCriteriaBuilder.populateCriteria(fieldsToClear);
 1240  
             //TODO: Chris - (2 stage clear) set the isOnlyDocTypeFilled, to true if only doc type coming in (besides hidden) and false otherwise)
 1241  
             docCriteria = getValidDocumentType(docTypeName).getDocumentSearchGenerator().clearSearch(docCriteria);
 1242  
         }
 1243  
 
 1244  
         return super.getRows();
 1245  
     }
 1246  
         */
 1247  
 
 1248  
 }