Coverage Report - org.kuali.rice.kew.docsearch.xml.StandardGenericXMLSearchableAttribute
 
Classes in this File Line Coverage Branch Coverage Complexity
StandardGenericXMLSearchableAttribute
0%
0/514
0%
0/320
9
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.docsearch.xml;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.core.util.KeyLabelPair;
 21  
 import org.kuali.rice.kew.attribute.XMLAttributeUtils;
 22  
 import org.kuali.rice.kew.docsearch.DocSearchUtils;
 23  
 import org.kuali.rice.kew.docsearch.DocumentSearchContext;
 24  
 import org.kuali.rice.kew.docsearch.SearchableAttributeValue;
 25  
 import org.kuali.rice.kew.exception.WorkflowRuntimeException;
 26  
 import org.kuali.rice.kew.rule.WorkflowAttributeValidationError;
 27  
 import org.kuali.rice.kew.rule.bo.RuleAttribute;
 28  
 import org.kuali.rice.kew.rule.xmlrouting.XPathHelper;
 29  
 import org.kuali.rice.kew.util.Utilities;
 30  
 import org.kuali.rice.kew.util.XmlHelper;
 31  
 import org.kuali.rice.kew.web.session.UserSession;
 32  
 import org.kuali.rice.kew.xml.XmlConstants;
 33  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 34  
 import org.kuali.rice.kns.web.format.Formatter;
 35  
 import org.kuali.rice.kns.web.ui.Field;
 36  
 import org.kuali.rice.kns.web.ui.Row;
 37  
 import org.w3c.dom.*;
 38  
 import org.xml.sax.InputSource;
 39  
 
 40  
 import javax.xml.parsers.DocumentBuilderFactory;
 41  
 import javax.xml.xpath.XPath;
 42  
 import javax.xml.xpath.XPathConstants;
 43  
 import javax.xml.xpath.XPathExpressionException;
 44  
 import java.io.BufferedReader;
 45  
 import java.io.StringReader;
 46  
 import java.util.*;
 47  
 import java.util.regex.Matcher;
 48  
 import java.util.regex.Pattern;
 49  
 
 50  
 
 51  
 /**
 52  
  * implementation of {@link GenericXMLSearchableAttribute}.
 53  
  *
 54  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 55  
  */
 56  0
 public class StandardGenericXMLSearchableAttribute implements GenericXMLSearchableAttribute {
 57  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(StandardGenericXMLSearchableAttribute.class);
 58  
 
 59  
     private static final String FIELD_DEF_E = "fieldDef";
 60  
 
 61  0
         private Map paramMap = new HashMap();
 62  
         private RuleAttribute ruleAttribute;
 63  0
         private List<Row> searchRows = new ArrayList<Row>();
 64  
 
 65  
         public void setRuleAttribute(RuleAttribute ruleAttribute) {
 66  0
                 this.ruleAttribute = ruleAttribute;
 67  0
         }
 68  
 
 69  
         public void setParamMap(Map paramMap) {
 70  0
                 this.paramMap = paramMap;
 71  0
         }
 72  
 
 73  
         public Map getParamMap() {
 74  0
                 return paramMap;
 75  
         }
 76  
 
 77  
         public String getSearchContent(DocumentSearchContext documentSearchContext) {
 78  0
                 XPath xpath = XPathHelper.newXPath();
 79  0
                 String findDocContent = "//searchingConfig/xmlSearchContent";
 80  
                 try {
 81  0
                         Node xmlDocumentContent = (Node) xpath.evaluate(findDocContent, getConfigXML(), XPathConstants.NODE);
 82  0
                         if (xmlDocumentContent != null && xmlDocumentContent.hasChildNodes()) {
 83  
                                 // Custom doc content in the searchingConfig xml.
 84  0
                                 String docContent = "";
 85  0
                                 NodeList customNodes = xmlDocumentContent.getChildNodes();
 86  0
                                 for (int i = 0; i < customNodes.getLength(); i++) {
 87  0
                                         Node childNode = customNodes.item(i);
 88  0
                                         docContent += XmlHelper.writeNode(childNode);
 89  
                                 }
 90  0
                                 String findField = "//searchingConfig/" + FIELD_DEF_E;
 91  0
                                 NodeList nodes = (NodeList) xpath.evaluate(findField, getConfigXML(), XPathConstants.NODESET);
 92  0
                                 if (nodes == null || nodes.getLength() == 0) {
 93  0
                                         return "";
 94  
                                 }
 95  0
                                 for (int i = 0; i < nodes.getLength(); i++) {
 96  0
                                         Node field = nodes.item(i);
 97  0
                                         NamedNodeMap fieldAttributes = field.getAttributes();
 98  0
                                         if (getParamMap() != null && !Utilities.isEmpty((String) getParamMap().get(fieldAttributes.getNamedItem("name").getNodeValue()))) {
 99  0
                                                 docContent = docContent.replaceAll("%" + fieldAttributes.getNamedItem("name").getNodeValue() + "%", (String) getParamMap().get(fieldAttributes.getNamedItem("name").getNodeValue()));
 100  
                                         }
 101  
                                 }
 102  0
                                 return docContent;
 103  
                         } else {
 104  
                                 // Standard doc content if no doc content is found in the searchingConfig xml.
 105  0
                                 StringBuffer documentContent = new StringBuffer("<xmlRouting>");
 106  0
                                 String findField = "//searchingConfig/" + FIELD_DEF_E;
 107  0
                                 NodeList nodes = (NodeList) xpath.evaluate(findField, getConfigXML(), XPathConstants.NODESET);
 108  0
                                 if (nodes == null || nodes.getLength() == 0) {
 109  0
                                         return "";
 110  
                                 }
 111  0
                                 for (int i = 0; i < nodes.getLength(); i++) {
 112  0
                                         Node field = nodes.item(i);
 113  0
                                         NamedNodeMap fieldAttributes = field.getAttributes();
 114  0
                                         if (getParamMap() != null && !Utilities.isEmpty((String) getParamMap().get(fieldAttributes.getNamedItem("name").getNodeValue()))) {
 115  0
                                                 documentContent.append("<field name=\"");
 116  0
                                                 documentContent.append(fieldAttributes.getNamedItem("name").getNodeValue());
 117  0
                                                 documentContent.append("\"><value>");
 118  0
                                                 documentContent.append((String) getParamMap().get(fieldAttributes.getNamedItem("name").getNodeValue()));
 119  0
                                                 documentContent.append("</value></field>");
 120  
                                         }
 121  
                                 }
 122  0
                                 documentContent.append("</xmlRouting>");
 123  0
                                 return documentContent.toString();
 124  
                         }
 125  0
                 } catch (XPathExpressionException e) {
 126  0
                         LOG.error("error in getSearchContent ", e);
 127  0
                         throw new RuntimeException("Error trying to find xml content with xpath expression", e);
 128  0
                 } catch (Exception e) {
 129  0
                         LOG.error("error in getSearchContent attempting to find xml search content", e);
 130  0
                         throw new RuntimeException("Error trying to get xml search content.", e);
 131  
                 }
 132  
         }
 133  
 
 134  
         public List getSearchStorageValues(DocumentSearchContext documentSearchContext) {
 135  0
                 List<SearchableAttributeValue> searchStorageValues = new ArrayList<SearchableAttributeValue>();
 136  
                 Document document;
 137  0
         if (StringUtils.isBlank(documentSearchContext.getDocumentContent())) {
 138  0
             LOG.warn("Empty Document Content found '" + documentSearchContext.getDocumentContent() + "'");
 139  0
             return searchStorageValues;
 140  
         }
 141  
                 try {
 142  0
                         document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
 143  
                                         new InputSource(new BufferedReader(new StringReader(documentSearchContext.getDocumentContent()))));
 144  0
                 } catch (Exception e){
 145  0
                         LOG.error("error parsing docContent: "+documentSearchContext.getDocumentContent(), e);
 146  0
                         throw new RuntimeException("Error trying to parse docContent: "+documentSearchContext.getDocumentContent(), e);
 147  0
                 }
 148  0
                 XPath xpath = XPathHelper.newXPath(document);
 149  0
                 String findField = "//searchingConfig/" + FIELD_DEF_E;
 150  
                 try {
 151  0
                         NodeList nodes = (NodeList) xpath.evaluate(findField, getConfigXML(), XPathConstants.NODESET);
 152  0
             if (nodes == null) {
 153  0
                 LOG.error("Could not find searching configuration (<searchingConfig>) for this XMLSearchAttribute");
 154  
             } else {
 155  
 
 156  0
                             for (int i = 0; i < nodes.getLength(); i++) {
 157  0
                                     Node field = nodes.item(i);
 158  0
                                     NamedNodeMap fieldAttributes = field.getAttributes();
 159  
 
 160  0
                                     String findXpathExpressionPrefix = "//searchingConfig/" + FIELD_DEF_E + "[@name='" + fieldAttributes.getNamedItem("name").getNodeValue() + "']";
 161  0
                                     String findDataTypeXpathExpression = findXpathExpressionPrefix + "/searchDefinition/@dataType";
 162  0
                                     String findXpathExpression = findXpathExpressionPrefix + "/fieldEvaluation/xpathexpression";
 163  0
                                     String fieldDataType = null;
 164  0
                                     String xpathExpression = null;
 165  
                                     try {
 166  0
                         fieldDataType = (String) xpath.evaluate(findDataTypeXpathExpression, getConfigXML(), XPathConstants.STRING);
 167  0
                                             if (Utilities.isEmpty(fieldDataType)) {
 168  0
                                                     fieldDataType = DEFAULT_SEARCHABLE_ATTRIBUTE_TYPE_NAME;
 169  
                                             }
 170  0
                                         xpathExpression = (String) xpath.evaluate(findXpathExpression, getConfigXML(), XPathConstants.STRING);
 171  0
                                             if (!Utilities.isEmpty(xpathExpression)) {
 172  
 
 173  
                             try {
 174  0
                                 NodeList searchValues = (NodeList) xpath.evaluate(xpathExpression, document.getDocumentElement(), XPathConstants.NODESET);
 175  
                               //being that this is the standard xml attribute we will return the key with an empty value
 176  
                                 // so we can find it from a doc search using this key
 177  0
                                 if (searchValues.getLength() == 0) {
 178  0
                                         SearchableAttributeValue searchableValue = this.setupSearchableAttributeValue(fieldDataType, fieldAttributes.getNamedItem("name").getNodeValue(), null);
 179  0
                                         if (searchableValue != null) {
 180  0
                                         searchStorageValues.add(searchableValue);
 181  
                                         }
 182  0
                                 } else {
 183  0
                                         for (int j = 0; j < searchValues.getLength(); j++) {
 184  0
                                         Node searchValue = searchValues.item(j);
 185  0
                                         String value = null;
 186  0
                                         if (searchValue.getFirstChild() != null && (!StringUtils.isEmpty(searchValue.getFirstChild().getNodeValue()))) {
 187  0
                                                 value = searchValue.getFirstChild().getNodeValue();
 188  
                                         }
 189  0
                                             SearchableAttributeValue searchableValue = this.setupSearchableAttributeValue(fieldDataType, fieldAttributes.getNamedItem("name").getNodeValue(), value);
 190  0
                                             if (searchableValue != null) {
 191  0
                                             searchStorageValues.add(searchableValue);
 192  
                                             }
 193  
                                     }
 194  
                                 }
 195  0
                             } catch (XPathExpressionException e) {
 196  
                                 //try for a string being returned from the expression.  This
 197  
                                 //seems like a poor way to determine our expression return type but
 198  
                                 //it's all I can come up with at the moment.
 199  0
                                 String searchValue = (String) xpath.evaluate(xpathExpression, DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
 200  
                                                 new InputSource(new BufferedReader(new StringReader(documentSearchContext.getDocumentContent())))).getDocumentElement(), XPathConstants.STRING);
 201  0
                                 String value = null;
 202  0
                                 if (StringUtils.isNotBlank(searchValue)) {
 203  0
                                     value = searchValue;
 204  
                                 }
 205  0
                                     SearchableAttributeValue searchableValue = this.setupSearchableAttributeValue(fieldDataType, fieldAttributes.getNamedItem("name").getNodeValue(), value);
 206  0
                                     if (searchableValue != null) {
 207  0
                                     searchStorageValues.add(searchableValue);
 208  
                                     }
 209  0
                             }
 210  
                                             }
 211  0
                                     } catch (XPathExpressionException e) {
 212  0
                                             LOG.error("error in isMatch ", e);
 213  0
                                             throw new RuntimeException("Error trying to find xml content with xpath expressions: " + findXpathExpression + " or " + xpathExpression, e);
 214  0
                                     } catch (Exception e){
 215  0
                                             LOG.error("error parsing docContent: "+documentSearchContext.getDocumentContent(), e);
 216  0
                                             throw new RuntimeException("Error trying to parse docContent: "+documentSearchContext.getDocumentContent(), e);
 217  0
                                     }
 218  
                 }
 219  
                         }
 220  0
                 } catch (XPathExpressionException e) {
 221  0
                         LOG.error("error in getSearchStorageValues ", e);
 222  0
                         throw new RuntimeException("Error trying to find xml content with xpath expression: " + findField, e);
 223  0
                 }
 224  0
                 return searchStorageValues;
 225  
         }
 226  
 
 227  
         private SearchableAttributeValue setupSearchableAttributeValue(String dataType,String key,String value) {
 228  0
                 SearchableAttributeValue attValue = DocSearchUtils.getSearchableAttributeValueByDataTypeString(dataType);
 229  0
                 if (attValue == null) {
 230  0
                         String errorMsg = "Cannot find a SearchableAttributeValue associated with the data type '" + dataType + "'";
 231  0
                     LOG.error("setupSearchableAttributeValue() " + errorMsg);
 232  0
                     throw new RuntimeException(errorMsg);
 233  
                 }
 234  0
         value = (value != null) ? value.trim() : null;
 235  0
         if ( (StringUtils.isNotBlank(value)) && (!attValue.isPassesDefaultValidation(value)) ) {
 236  0
             String errorMsg = "SearchableAttributeValue with the data type '" + dataType + "', key '" + key + "', and value '" + value + "' does not pass default validation and cannot be saved to the database";
 237  0
             LOG.error("setupSearchableAttributeValue() " + errorMsg);
 238  0
             throw new RuntimeException(errorMsg);
 239  
         }
 240  0
                 attValue.setSearchableAttributeKey(key);
 241  0
                 attValue.setupAttributeValue(value);
 242  0
             return attValue;
 243  
         }
 244  
 
 245  
         public List<Row> getSearchingRows(DocumentSearchContext documentSearchContext) {
 246  0
                 if (searchRows.isEmpty()) {
 247  0
                         List<SearchableAttributeValue> searchableAttributeValues = DocSearchUtils.getSearchableAttributeValueObjectTypes();
 248  0
                         List<Row> rows = new ArrayList<Row>();
 249  0
                         NodeList fieldNodeList = getConfigXML().getElementsByTagName(FIELD_DEF_E);
 250  0
                         for (int i = 0; i < fieldNodeList.getLength(); i++) {
 251  0
                                 Node field = fieldNodeList.item(i);
 252  0
                                 NamedNodeMap fieldAttributes = field.getAttributes();
 253  
 
 254  0
                                 List<Field> fields = new ArrayList<Field>();
 255  0
                                 boolean isColumnVisible = true;
 256  0
                 boolean hasXPathExpression = false;
 257  0
                                 Field myField = new Field(fieldAttributes.getNamedItem("name").getNodeValue(), fieldAttributes.getNamedItem("title").getNodeValue());
 258  
 
 259  0
                                 String quickfinderService = null;
 260  
                                 // range search details
 261  0
                                 Field rangeLowerBoundField = null;
 262  0
                                 Field rangeUpperBoundField = null;
 263  0
                                 myField.setUpperCase(true); // this defaults us to case insensitive.
 264  0
                                 for (int j = 0; j < field.getChildNodes().getLength(); j++) {
 265  0
                                         Node childNode = field.getChildNodes().item(j);
 266  0
                                         if ("value".equals(childNode.getNodeName())) {
 267  0
                                                 myField.setPropertyValue(childNode.getFirstChild().getNodeValue());
 268  0
                                         } else if ("display".equals(childNode.getNodeName())) {
 269  0
                                                 List<KeyLabelPair> options = new ArrayList<KeyLabelPair>();
 270  0
                         List<String> selectedOptions = new ArrayList<String>();
 271  0
                                                 for (int k = 0; k < childNode.getChildNodes().getLength(); k++) {
 272  0
                                                         Node displayChildNode = childNode.getChildNodes().item(k);
 273  0
                                                         if ("type".equals(displayChildNode.getNodeName())) {
 274  0
                                                                 String typeValue = displayChildNode.getFirstChild().getNodeValue();
 275  0
                                                                 myField.setFieldType(convertTypeToFieldType(typeValue));
 276  0
                                                                 if ("date".equals(typeValue)) {
 277  0
                                                                         myField.setDatePicker(Boolean.TRUE);
 278  0
                                                                         myField.setFieldDataType(DATA_TYPE_DATE);
 279  
                                                                 }
 280  0
                                                         } else if ("meta".equals(displayChildNode.getNodeName())) {
 281  
 
 282  0
                                                         } else if ("values".equals(displayChildNode.getNodeName())) {
 283  0
                                                                 NamedNodeMap valuesAttributes = displayChildNode.getAttributes();
 284  
 //                              this is to allow an empty drop down choice and can probably implemented in a better way
 285  0
                                 if (displayChildNode.getFirstChild() != null) {
 286  0
                                     options.add(new KeyLabelPair(displayChildNode.getFirstChild().getNodeValue(), valuesAttributes.getNamedItem("title").getNodeValue()));
 287  0
                                     if (valuesAttributes.getNamedItem("selected") != null) {
 288  0
                                         selectedOptions.add(displayChildNode.getFirstChild().getNodeValue());
 289  
                                     }
 290  
                                 } else {
 291  0
                                     options.add(new KeyLabelPair("", valuesAttributes.getNamedItem("title").getNodeValue()));
 292  
                                 }
 293  
                                                         }
 294  
                                                 }
 295  0
                                                 if (!options.isEmpty()) {
 296  0
                                                         myField.setFieldValidValues(options);
 297  0
                             if (!selectedOptions.isEmpty()) {
 298  0
                                 if (Field.MULTI_VALUE_FIELD_TYPES.contains(myField.getFieldType())) {
 299  0
                                     String[] newSelectedOptions = new String[selectedOptions.size()];
 300  0
                                     int k = 0;
 301  0
                                     for (String option : selectedOptions)
 302  
                                     {
 303  0
                                         newSelectedOptions[k] = option;
 304  0
                                         k++;
 305  
                                     }
 306  0
                                     myField.setPropertyValues(newSelectedOptions);
 307  0
                                 } else {
 308  0
                                     myField.setPropertyValue((String)selectedOptions.get(0));
 309  
                                 }
 310  
                             }
 311  
                                                 }
 312  0
                                         } else if ("visibility".equals(childNode.getNodeName())) {
 313  0
                                                 parseVisibility(myField, (Element)childNode);
 314  0
                                         } else if ("searchDefinition".equals(childNode.getNodeName())) {
 315  0
                                                 NamedNodeMap searchDefAttributes = childNode.getAttributes();
 316  
                                                 // data type operations
 317  0
                                                 String dataType = (searchDefAttributes.getNamedItem("dataType") == null) ? null : searchDefAttributes.getNamedItem("dataType").getNodeValue();
 318  0
                                                 if (!Utilities.isEmpty(dataType)) {
 319  0
                                                         myField.setFieldDataType(dataType);
 320  
                                                 } else {
 321  
                                                         // no data type means we default to String which disallows range search
 322  0
                                                         myField.setFieldDataType(DEFAULT_SEARCHABLE_ATTRIBUTE_TYPE_NAME);
 323  
                                                 }
 324  0
                                                 if (DATA_TYPE_DATE.equalsIgnoreCase(myField.getFieldDataType())) {
 325  0
                                                         myField.setDatePicker(Boolean.TRUE);
 326  
                                                 }
 327  
                                                 //if () {
 328  
                                                 //    myField.setFormatter((Formatter) formatterClass.newInstance());
 329  
                                                 //}
 330  
 
 331  
                                                 // figure out if this is a range search
 332  0
                                                 myField.setMemberOfRange(isRangeSearchField(searchableAttributeValues, myField.getFieldDataType(), searchDefAttributes, childNode));
 333  0
                                                 if (!myField.isMemberOfRange()) {
 334  0
                                                         Boolean caseSensitive = getBooleanValue(searchDefAttributes, "caseSensitive");
 335  0
                                                         if (caseSensitive == null) {
 336  0
                                                                 caseSensitive = false; // we mimmic the KNS. KNS is case insensitive by default
 337  
                                                         }
 338  0
                                                         myField.setUpperCase(!caseSensitive);
 339  0
                                                 } else {
 340  
                                                     // by now we know we have a range that uses the default values at least
 341  
                                                     // these will be
 342  0
                                                     rangeLowerBoundField = new Field("",DEFAULT_RANGE_SEARCH_LOWER_BOUND_LABEL);
 343  0
                                                     rangeLowerBoundField.setMemberOfRange(true);
 344  0
                                                     rangeUpperBoundField = new Field("",DEFAULT_RANGE_SEARCH_UPPER_BOUND_LABEL);
 345  0
                                                     rangeUpperBoundField.setMemberOfRange(true);
 346  0
                                                     setupBoundFields(childNode, rangeLowerBoundField, rangeUpperBoundField);
 347  
                         }
 348  
 
 349  0
                                                 String formatterClass = (searchDefAttributes.getNamedItem("formatterClass") == null) ? null : searchDefAttributes.getNamedItem("formatterClass").getNodeValue();
 350  0
                                                 if (!StringUtils.isEmpty(formatterClass)) {
 351  
                                                     try {
 352  0
                                                         myField.setFormatter((Formatter)Class.forName(formatterClass).newInstance());
 353  0
                                                     } catch (InstantiationException e) {
 354  0
                                                 LOG.error("Unable to get new instance of formatter class: " + formatterClass);
 355  0
                                                 throw new RuntimeException("Unable to get new instance of formatter class: " + formatterClass);
 356  
                                             }
 357  0
                                             catch (IllegalAccessException e) {
 358  0
                                                 LOG.error("Unable to get new instance of formatter class: " + formatterClass);
 359  0
                                                 throw new RuntimeException("Unable to get new instance of formatter class: " + formatterClass);
 360  0
                                             } catch (ClassNotFoundException e) {
 361  0
                                                 LOG.error("Unable to find formatter class: " + formatterClass);
 362  0
                                 throw new RuntimeException("Unable to find formatter class: " + formatterClass);
 363  0
                             }
 364  
                                                 }
 365  
 
 366  0
                                         } else if ("resultColumn".equals(childNode.getNodeName())) {
 367  0
                                                 NamedNodeMap columnAttributes = childNode.getAttributes();
 368  0
                                                 Node showNode = columnAttributes.getNamedItem("show");
 369  0
                                                 if (showNode != null && showNode.getNodeValue() != null) {
 370  0
                                                         isColumnVisible = Boolean.valueOf(showNode.getNodeValue());
 371  
                                                 }
 372  0
                                                 myField.setColumnVisible(isColumnVisible);
 373  0
                     } else if ("fieldEvaluation".equals(childNode.getNodeName())) {
 374  0
                         for (int k = 0; k < childNode.getChildNodes().getLength(); k++) {
 375  0
                             Node displayChildNode = childNode.getChildNodes().item(k);
 376  0
                             if ("xpathexpression".equals(displayChildNode.getNodeName())) {
 377  0
                                 hasXPathExpression = true;
 378  0
                                 break;
 379  
                             }
 380  
                         }
 381  0
                                         } else if ("lookup".equals(childNode.getNodeName())) {
 382  0
                                                 XMLAttributeUtils.establishFieldLookup(myField, childNode);
 383  
                                         }
 384  
                                 }
 385  0
                 myField.setIndexedForSearch(hasXPathExpression);
 386  
 
 387  0
                                 if (myField.isMemberOfRange()) {
 388  
                                         // we have a ranged search... we need to add the bound fields and NOT the myField object
 389  0
                                         addRangeFields(RANGE_LOWER_BOUND_PROPERTY_PREFIX, rangeLowerBoundField, myField, rows, quickfinderService);
 390  0
                                         addRangeFields(RANGE_UPPER_BOUND_PROPERTY_PREFIX, rangeUpperBoundField, myField, rows, quickfinderService);
 391  
                                 } else {
 392  0
                                         fields.add(myField);
 393  0
                                         if (!myField.getFieldType().equals(Field.HIDDEN)) {
 394  0
                                                 if (myField.isDatePicker()) {
 395  0
                                                         addDatePickerField(fields, myField.getPropertyName());
 396  
                                                 }
 397  
                                         }
 398  0
                                         rows.add(new Row(fields));
 399  
                                 }
 400  
                         }
 401  0
                         searchRows = rows;
 402  
                 }
 403  0
                 return searchRows;
 404  
         }
 405  
 
 406  
     private boolean isRangeSearchField(List<SearchableAttributeValue> searchableAttributeValues, String dataType, NamedNodeMap searchDefAttributes, Node searchDefNode) {
 407  0
         for (SearchableAttributeValue attValue : searchableAttributeValues)
 408  
         {
 409  0
             if (dataType.equalsIgnoreCase(attValue.getAttributeDataType()))
 410  
             {
 411  0
                 return isRangeSearchField(attValue, dataType, searchDefAttributes, searchDefNode);
 412  
             }
 413  
         }
 414  0
         String errorMsg = "Could not find searchable attribute value for data type '" + dataType + "'";
 415  0
         LOG.error("isRangeSearchField(List, String, NamedNodeMap, Node) " + errorMsg);
 416  0
         throw new RuntimeException(errorMsg);
 417  
     }
 418  
 
 419  
     private boolean isRangeSearchField(SearchableAttributeValue searchableAttributeValue, String dataType, NamedNodeMap searchDefAttributes, Node searchDefNode) {
 420  0
         boolean allowRangedSearch = searchableAttributeValue.allowsRangeSearches();
 421  0
         Boolean rangeSearchBoolean = getBooleanValue(searchDefAttributes, "rangeSearch");
 422  0
         boolean rangeSearch = (rangeSearchBoolean != null) && rangeSearchBoolean;
 423  0
         Node rangeDefinition = getPotentialChildNode(searchDefNode, "rangeDefinition");
 424  0
         return ( (allowRangedSearch) && ((rangeDefinition != null) || (rangeSearch)) );
 425  
     }
 426  
 
 427  
     private void setupBoundFields(Node searchDefinitionNode, Field lowerBoundField, Field upperBoundField) {
 428  0
         NamedNodeMap searchDefAttributes = searchDefinitionNode.getAttributes();
 429  0
         Node rangeDefinitionNode = getPotentialChildNode(searchDefinitionNode, "rangeDefinition");
 430  0
         NamedNodeMap rangeDefinitionAttributes = null;
 431  0
         NamedNodeMap lowerBoundNodeAttributes = null;
 432  0
         NamedNodeMap upperBoundNodeAttributes = null;
 433  0
         if (rangeDefinitionNode != null) {
 434  0
             rangeDefinitionAttributes = rangeDefinitionNode.getAttributes();
 435  0
             lowerBoundNodeAttributes = getAttributesForPotentialChildNode(rangeDefinitionNode, "lower");
 436  0
             upperBoundNodeAttributes = getAttributesForPotentialChildNode(rangeDefinitionNode, "upper");
 437  
         }
 438  
         // below methods allow for nullable attribute NamedNodeMaps
 439  0
         setupRangeBoundFieldOverridableSettings(searchDefAttributes, rangeDefinitionAttributes, lowerBoundNodeAttributes, lowerBoundField);
 440  0
         setupRangeBoundFieldOverridableSettings(searchDefAttributes, rangeDefinitionAttributes, upperBoundNodeAttributes, upperBoundField);
 441  0
     }
 442  
 
 443  
         private void addRangeFields(String propertyPrefix, Field rangeBoundField,Field mainField, List<Row> rows,String quickfinderService) {
 444  0
                 List<Field> rangeFields = new ArrayList<Field>();
 445  0
                 rangeBoundField.setColumnVisible(mainField.isColumnVisible());
 446  0
                 rangeBoundField.setFieldDataType(mainField.getFieldDataType());
 447  0
                 rangeBoundField.setFieldHelpUrl(mainField.getFieldHelpUrl());
 448  0
                 rangeBoundField.setFieldType(mainField.getFieldType());
 449  0
         rangeBoundField.setMainFieldLabel(mainField.getFieldLabel());
 450  0
                 rangeBoundField.setFieldValidValues(mainField.getFieldValidValues());
 451  0
                 rangeBoundField.setPropertyName(propertyPrefix + mainField.getPropertyName());
 452  0
                 rangeBoundField.setQuickFinderClassNameImpl(mainField.getQuickFinderClassNameImpl());
 453  
                 //rangeBoundField.setDefaultLookupableName(mainField.getDefaultLookupableName());
 454  0
                 rangeFields.add(rangeBoundField);
 455  0
                 if (!mainField.getFieldType().equals(Field.HIDDEN)) {
 456  
                         // disabling the additional quickfinder field for now, should be included as a single field in the KNS instead of 2 as it was in KEW
 457  
 //                        if (!Utilities.isEmpty(quickfinderService)) {
 458  
 //                                rangeFields.add(new Field("", "", Field.QUICKFINDER, "", "", null, quickfinderService));
 459  
 //                        }
 460  0
                         if (rangeBoundField.isDatePicker()) {
 461  
                                 // variable was set on the bound field
 462  0
                                 if (rangeBoundField.isDatePicker()) {
 463  0
                                         addDatePickerField(rangeFields, rangeBoundField.getPropertyName());
 464  
                                 }
 465  
                         } else {
 466  0
                                 if (mainField.isDatePicker()) {
 467  0
                                         addDatePickerField(rangeFields, rangeBoundField.getPropertyName());
 468  
                                 }
 469  
                         }
 470  
                 }
 471  0
                 rows.add(new Row(rangeFields));
 472  0
         }
 473  
 
 474  
     private void addDatePickerField(List<Field> fields,String propertyName) {
 475  0
         Field Field = new Field(propertyName,"");
 476  0
         Field.setDatePicker(true);
 477  0
                 fields.add(Field);
 478  0
     }
 479  
 
 480  
         private NamedNodeMap getAttributesForPotentialChildNode(Node node, String potentialChildNodeName) {
 481  0
                 Node testNode = getPotentialChildNode(node, potentialChildNodeName);
 482  0
                 return (testNode != null) ? testNode.getAttributes() : null;
 483  
         }
 484  
 
 485  
         private Node getPotentialChildNode(Node node, String childNodeName) {
 486  0
                 if (node != null) {
 487  0
                         for (int k = 0; k < node.getChildNodes().getLength(); k++) {
 488  0
                                 Node testNode = node.getChildNodes().item(k);
 489  0
                                 if (testNode.getNodeName().equals(childNodeName)) {
 490  0
                                         return testNode;
 491  
                                 }
 492  
                         }
 493  
                 }
 494  0
                 return null;
 495  
         }
 496  
 
 497  
         private void setupRangeBoundFieldOverridableSettings(NamedNodeMap searchDefinitionAttributes,NamedNodeMap rangeDefinitionAttributes,NamedNodeMap rangeBoundAttributes,Field boundField) {
 498  0
         String potentialLabel = getPotentialRangeBoundLabelFromAttributes(rangeBoundAttributes);
 499  0
         if (StringUtils.isNotBlank(potentialLabel)) {
 500  0
             boundField.setFieldLabel(potentialLabel);
 501  
         }
 502  0
                 ArrayList<NamedNodeMap> namedNodeMapsByImportance = new ArrayList<NamedNodeMap>();
 503  0
                 namedNodeMapsByImportance.add(rangeBoundAttributes);
 504  0
                 namedNodeMapsByImportance.add(rangeDefinitionAttributes);
 505  0
                 namedNodeMapsByImportance.add(searchDefinitionAttributes);
 506  0
                 Boolean caseSensitive = getBooleanWithPotentialOverrides(namedNodeMapsByImportance, "caseSensitive");
 507  0
                 if (caseSensitive == null) {
 508  0
                         caseSensitive = false; // we mimmic the KNS. KNS is case insensitive by default
 509  
                 }
 510  0
                 boundField.setUpperCase(!caseSensitive);
 511  
                 // TODO: after face-to-face work in december 2008, this was throwing a nullpointerexception for lookups with date pickers
 512  
                 // assuming this code will go away after the document search conversion
 513  0
                 Boolean datePickerBoolean = getBooleanWithPotentialOverrides(namedNodeMapsByImportance, "datePicker");
 514  0
                 if (datePickerBoolean == null) {
 515  0
                         datePickerBoolean = false;
 516  
                 }
 517  0
                 boundField.setDatePicker(datePickerBoolean);
 518  0
                 boundField.setRangeFieldInclusive(getBooleanWithPotentialOverrides(namedNodeMapsByImportance, "inclusive"));
 519  
 
 520  0
         }
 521  
 
 522  
     private String getPotentialRangeBoundLabelFromAttributes(NamedNodeMap rangeBoundAttributes) {
 523  0
         if (rangeBoundAttributes != null) {
 524  0
             String boundLabel = (rangeBoundAttributes.getNamedItem("label") == null) ? null : rangeBoundAttributes.getNamedItem("label").getNodeValue();
 525  0
             if (!Utilities.isEmpty(boundLabel)) {
 526  0
                 return boundLabel;
 527  
             }
 528  
         }
 529  0
         return null;
 530  
     }
 531  
 
 532  
         private Boolean getBooleanWithPotentialOverrides(String attributeName,NamedNodeMap searchDefinitionAttributes,NamedNodeMap rangeDefinitionAttributes,NamedNodeMap rangeBoundAttributes) {
 533  0
                 ArrayList<NamedNodeMap> namedNodeMapsByImportance = new ArrayList<NamedNodeMap>();
 534  0
                 namedNodeMapsByImportance.add(rangeBoundAttributes);
 535  0
                 namedNodeMapsByImportance.add(rangeDefinitionAttributes);
 536  0
                 namedNodeMapsByImportance.add(searchDefinitionAttributes);
 537  0
                 return getBooleanWithPotentialOverrides(namedNodeMapsByImportance, attributeName);
 538  
         }
 539  
 
 540  
         private Boolean getBooleanWithPotentialOverrides(ArrayList<NamedNodeMap> namedNodeMapsByImportance, String attributeName) {
 541  0
         for (NamedNodeMap aNamedNodeMapsByImportance : namedNodeMapsByImportance)
 542  
         {
 543  0
             NamedNodeMap nodeMap = (NamedNodeMap) aNamedNodeMapsByImportance;
 544  0
             Boolean booleanValue = getBooleanValue(nodeMap, attributeName);
 545  0
             if (booleanValue != null)
 546  
             {
 547  0
                 return booleanValue;
 548  
             }
 549  0
         }
 550  0
                 return null;
 551  
         }
 552  
 
 553  
         private Boolean getBooleanValue(NamedNodeMap nodeMap, String attributeName) {
 554  0
                 String nodeValue = getStringValue(nodeMap, attributeName);
 555  0
                 if (nodeValue != null) {
 556  0
                         return Boolean.valueOf(nodeValue);
 557  
                 }
 558  0
                 return null;
 559  
         }
 560  
 
 561  
         private String getStringValue(NamedNodeMap nodeMap, String attributeName) {
 562  0
                 return ( (nodeMap == null) || (nodeMap.getNamedItem(attributeName) == null) || (Utilities.isEmpty(nodeMap.getNamedItem(attributeName).getNodeValue())) ) ? null : nodeMap.getNamedItem(attributeName).getNodeValue();
 563  
         }
 564  
 
 565  
         private void parseVisibility(Field field, Element visibilityElement) {
 566  0
                 for (int vIndex = 0; vIndex < visibilityElement.getChildNodes().getLength(); vIndex++) {
 567  0
                         Node visibilityChildNode = visibilityElement.getChildNodes().item(vIndex);
 568  0
                         if (visibilityChildNode.getNodeType() == Node.ELEMENT_NODE) {
 569  0
                                 boolean visible = true;
 570  0
                                 NamedNodeMap visibilityAttributes = visibilityChildNode.getAttributes();
 571  0
                                 Node visibleNode = visibilityAttributes.getNamedItem("visible");
 572  0
                                 if (visibleNode != null && visibleNode.getNodeValue() != null) {
 573  0
                                         visible = Boolean.valueOf(visibleNode.getNodeValue());
 574  
                                 } else {
 575  0
                                         NodeList visibilityDecls = visibilityChildNode.getChildNodes();
 576  0
                                         for (int vdIndex = 0; vdIndex < visibilityDecls.getLength(); vdIndex++) {
 577  0
                                                 Node visibilityDecl = visibilityDecls.item(vdIndex);
 578  0
                         if (visibilityDecl.getNodeType() == Node.ELEMENT_NODE) {
 579  0
                                 boolean hasIsMemberOfGroupElement = false;
 580  0
                                 String groupName = null;
 581  0
                                 String groupNamespace = null;
 582  0
                                 if (XmlConstants.IS_MEMBER_OF_GROUP.equals(visibilityDecl.getNodeName())) { // Found an "isMemberOfGroup" element.
 583  0
                                         hasIsMemberOfGroupElement = true;
 584  0
                                         groupName = Utilities.substituteConfigParameters(visibilityDecl.getTextContent()).trim();
 585  0
                                         groupNamespace = Utilities.substituteConfigParameters(((Element)visibilityDecl).getAttribute(XmlConstants.NAMESPACE)).trim();
 586  
                                 }
 587  0
                                 else if (XmlConstants.IS_MEMBER_OF_WORKGROUP.equals(visibilityDecl.getNodeName())) { // Found a deprecated "isMemberOfWorkgroup" element.
 588  0
                                         LOG.warn((new StringBuilder()).append("Rule Attribute XML is using deprecated element '").append(
 589  
                                                         XmlConstants.IS_MEMBER_OF_WORKGROUP).append("', please use '").append(XmlConstants.IS_MEMBER_OF_GROUP).append(
 590  
                                                                         "' instead.").toString());
 591  0
                                         hasIsMemberOfGroupElement = true;
 592  0
                                                             String workgroupName = Utilities.substituteConfigParameters(visibilityDecl.getFirstChild().getNodeValue());
 593  0
                                                             groupNamespace = Utilities.parseGroupNamespaceCode(workgroupName);
 594  0
                                                             groupName = Utilities.parseGroupName(workgroupName);
 595  
                                                     }
 596  0
                                                     if (hasIsMemberOfGroupElement) { // Found one of the "isMemberOf..." elements.
 597  0
                                                             UserSession session = UserSession.getAuthenticatedUser();
 598  0
                                                             if (session == null) {
 599  0
                                                                     throw new WorkflowRuntimeException("UserSession is null!  Attempted to render the searchable attribute outside of an established session.");
 600  
                                                             }
 601  0
                                                             visible = KIMServiceLocator.getIdentityManagementService().isMemberOfGroup(session.getPerson().getPrincipalId(), groupNamespace, groupName);
 602  
                                                     }
 603  
                         }
 604  
                                         }
 605  
                                 }
 606  0
                                 String type = visibilityChildNode.getNodeName();
 607  0
                                 if ("field".equals(type) || "fieldAndColumn".equals(type)) {
 608  
                                         // if it's not visible, coerce this field to a hidden type
 609  0
                                         if (!visible) {
 610  0
                                                 field.setFieldType(Field.HIDDEN);
 611  
                                         }
 612  
                                 }
 613  0
                                 if ("column".equals(type) || "fieldAndColumn".equals(type)) {
 614  0
                                         field.setColumnVisible(visible);
 615  
                                 }
 616  
                         }
 617  
 
 618  
                 }
 619  0
         }
 620  
 
 621  
         private String convertTypeToFieldType(String type) {
 622  0
                 if ("text".equals(type)) {
 623  0
                         return Field.TEXT;
 624  0
                 } else if ("select".equals(type)) {
 625  0
                         return Field.DROPDOWN;
 626  0
                 } else if ("radio".equals(type)) {
 627  0
                         return Field.RADIO;
 628  0
                 } else if ("quickfinder".equals(type)) {
 629  0
                         return Field.QUICKFINDER;
 630  0
                 } else if ("hidden".equals(type)) {
 631  0
                         return Field.HIDDEN;
 632  0
                 } else if ("date".equals(type)) {
 633  0
                         return Field.TEXT;
 634  0
         } else if ("multibox".equals(type)) {
 635  0
             return Field.MULTIBOX;
 636  
         }
 637  0
                 throw new IllegalArgumentException("Illegal field type found: " + type);
 638  
         }
 639  
 
 640  
         public List validateUserSearchInputs(Map paramMap, DocumentSearchContext documentSearchContext) {
 641  0
                 this.paramMap = paramMap;
 642  0
                 List<WorkflowAttributeValidationError> errors = new ArrayList<WorkflowAttributeValidationError>();
 643  
 
 644  0
                 XPath xpath = XPathHelper.newXPath();
 645  0
                 String findField = "//searchingConfig/" + FIELD_DEF_E;
 646  
                 try {
 647  0
                         NodeList nodes = (NodeList) xpath.evaluate(findField, getConfigXML(), XPathConstants.NODESET);
 648  0
                         if (nodes == null) {
 649  
                                 // no field definitions is de facto valid
 650  0
                             LOG.warn("Could not find any field definitions (<" + FIELD_DEF_E + ">) or possibly a searching configuration (<searchingConfig>) for this XMLSearchAttribute");
 651  
                         } else {
 652  0
                             for (int i = 0; i < nodes.getLength(); i++) {
 653  0
                                     Node field = nodes.item(i);
 654  0
                                     NamedNodeMap fieldAttributes = field.getAttributes();
 655  0
                                         String fieldDefName = fieldAttributes.getNamedItem("name").getNodeValue();
 656  0
                     String fieldDefTitle = ((fieldAttributes.getNamedItem("title")) != null) ? fieldAttributes.getNamedItem("title").getNodeValue() : "";
 657  
                     // check for range search members in the parameter map
 658  0
                     boolean rangeMemberInSearchParams = false;
 659  0
                     if (getParamMap() != null) {
 660  0
                         Object lowerObj = getParamMap().get(RANGE_LOWER_BOUND_PROPERTY_PREFIX + fieldDefName);
 661  0
                         if ( (lowerObj != null) && (lowerObj instanceof String) ) {
 662  0
                             rangeMemberInSearchParams |= StringUtils.isNotBlank((String) lowerObj);
 663  
                         }
 664  0
                         Object upperObj = getParamMap().get(RANGE_UPPER_BOUND_PROPERTY_PREFIX + fieldDefName);
 665  0
                         if ( (upperObj != null) && (upperObj instanceof String) ) {
 666  0
                             rangeMemberInSearchParams |= StringUtils.isNotBlank((String) upperObj);
 667  
                         }
 668  0
                         Object testObject = getParamMap().get(fieldDefName);
 669  0
                                             if ( (testObject != null) || rangeMemberInSearchParams ) {
 670  
                             // check to see if we need to process this field at all
 671  0
                             if (!rangeMemberInSearchParams) {
 672  0
                                 if (testObject instanceof String) {
 673  0
                                     String stringVariable = (String) testObject;
 674  0
                                     if (StringUtils.isBlank(stringVariable)) {
 675  
                                         // field is not multi value and is empty... skip it
 676  0
                                         continue;
 677  
                                     }
 678  0
                                 } else if (testObject instanceof Collection) {
 679  0
                                     Collection stringVariables = (Collection<String>)testObject;
 680  0
                                     boolean allAreBlank = true;
 681  0
                                     for (Iterator iter = stringVariables.iterator(); iter.hasNext();) {
 682  0
                                         String testString = (String) iter.next();
 683  0
                                         if (StringUtils.isNotBlank(testString)) {
 684  0
                                             allAreBlank = false;
 685  0
                                             break;
 686  
                                         }
 687  0
                                     }
 688  0
                                     if (allAreBlank) {
 689  
                                         // field is multivalue but all values are blank... skip it
 690  0
                                         continue;
 691  
                                     }
 692  0
                                 } else {
 693  0
                                     String errorMessage = "Only String or String[] objects should come from entered parameters of an attribute. Current parameter is '" + testObject.getClass() + "'";
 694  0
                                     LOG.error(errorMessage);
 695  0
                                     throw new RuntimeException(errorMessage);
 696  
                                 }
 697  
                             }
 698  0
                             String findXpathExpressionPrefix = "//searchingConfig/" + FIELD_DEF_E + "[@name='" + fieldDefName + "']";
 699  0
                                                 Node searchDefNode = (Node) xpath.evaluate(findXpathExpressionPrefix + "/searchDefinition", getConfigXML(), XPathConstants.NODE);
 700  0
                                                 NamedNodeMap searchDefAttributes = null;
 701  0
                                             String fieldDataType = null;
 702  0
                                                 if (searchDefNode != null) {
 703  
                                                     // get the data type from the xml
 704  0
                                                         searchDefAttributes = searchDefNode.getAttributes();
 705  0
                                                         if (searchDefAttributes.getNamedItem("dataType") != null) {
 706  0
                                                             fieldDataType = searchDefAttributes.getNamedItem("dataType").getNodeValue();
 707  
                                                         }
 708  
 
 709  
                                                 }
 710  0
                                                 if (Utilities.isEmpty(fieldDataType)) {
 711  0
                                                         fieldDataType = DEFAULT_SEARCHABLE_ATTRIBUTE_TYPE_NAME;
 712  
                                                 }
 713  
                                                 // get the searchable attribute value by using the data type
 714  0
                                                 SearchableAttributeValue attributeValue = DocSearchUtils.getSearchableAttributeValueByDataTypeString(fieldDataType);
 715  0
                                                 if (attributeValue == null) {
 716  0
                                                         String errorMsg = "Cannot find SearchableAttributeValue for field data type '" + fieldDataType + "'";
 717  0
                                                         LOG.error("validateUserSearchInputs() " + errorMsg);
 718  0
                                                         throw new RuntimeException(errorMsg);
 719  
                                                 }
 720  
 
 721  0
                                                 if (rangeMemberInSearchParams) {
 722  0
                                 String lowerBoundFieldDefName = RANGE_LOWER_BOUND_PROPERTY_PREFIX + fieldDefName;
 723  0
                                 String upperBoundFieldDefName = RANGE_UPPER_BOUND_PROPERTY_PREFIX + fieldDefName;
 724  0
                                 String lowerBoundEnteredValue = null;
 725  0
                                 String upperBoundEnteredValue = null;
 726  0
                                 NamedNodeMap lowerBoundRangeAttributes = null;
 727  0
                                 NamedNodeMap upperBoundRangeAttributes = null;
 728  0
                                                         Node rangeDefinitionNode = getPotentialChildNode(searchDefNode, "rangeDefinition");
 729  0
                                                         NamedNodeMap rangeDefinitionAttributes = (rangeDefinitionNode != null) ? rangeDefinitionNode.getAttributes() : null;
 730  0
                                                         lowerBoundEnteredValue = (String) getParamMap().get(lowerBoundFieldDefName);
 731  0
                                                         upperBoundEnteredValue = (String) getParamMap().get(upperBoundFieldDefName);
 732  0
                                                         if (!Utilities.isEmpty(lowerBoundEnteredValue)) {
 733  0
                                     lowerBoundRangeAttributes = getAttributesForPotentialChildNode(rangeDefinitionNode, "lower");
 734  0
                                                                 errors.addAll(performValidation(attributeValue,
 735  
                                                                                 lowerBoundFieldDefName, lowerBoundEnteredValue, constructRangeFieldErrorPrefix(fieldDefTitle,lowerBoundRangeAttributes), findXpathExpressionPrefix));
 736  
                                                         }
 737  0
                                 if (!Utilities.isEmpty(upperBoundEnteredValue)) {
 738  0
                                     upperBoundRangeAttributes = getAttributesForPotentialChildNode(rangeDefinitionNode, "upper");
 739  0
                                                                 errors.addAll(performValidation(attributeValue,
 740  
                                                                                 upperBoundFieldDefName, upperBoundEnteredValue, constructRangeFieldErrorPrefix(fieldDefTitle,upperBoundRangeAttributes), findXpathExpressionPrefix));
 741  
                                                         }
 742  0
                                 if (errors.isEmpty()) {
 743  0
                                     Boolean rangeValid = attributeValue.isRangeValid(lowerBoundEnteredValue, upperBoundEnteredValue);
 744  0
                                     if ( (rangeValid != null) && (!rangeValid) ) {
 745  0
                                         String lowerLabel = getPotentialRangeBoundLabelFromAttributes(lowerBoundRangeAttributes);
 746  0
                                         String upperLabel = getPotentialRangeBoundLabelFromAttributes(upperBoundRangeAttributes);
 747  0
                                         String errorMsg = "The " + fieldDefTitle + " range is incorrect.  The " + (StringUtils.isNotBlank(lowerLabel) ? lowerLabel : DEFAULT_RANGE_SEARCH_LOWER_BOUND_LABEL) + " value entered must come before the " + (StringUtils.isNotBlank(upperLabel) ? upperLabel : DEFAULT_RANGE_SEARCH_UPPER_BOUND_LABEL) + " value";
 748  0
                                         LOG.debug("validateUserSearchInputs() " + errorMsg + " :: field type '" + attributeValue.getAttributeDataType() + "'");
 749  0
                                         errors.add(new WorkflowAttributeValidationError(fieldDefName, errorMsg));
 750  
                                     }
 751  
                                 }
 752  
 
 753  0
                                                 } else {
 754  0
                                 Object enteredValue = getParamMap().get(fieldDefName);
 755  0
                                 if (enteredValue instanceof String) {
 756  0
                                     String stringVariable = (String) enteredValue;
 757  0
                                     errors.addAll(performValidation(attributeValue, fieldDefName, stringVariable, fieldDefTitle, findXpathExpressionPrefix));
 758  0
                                 } else if (enteredValue instanceof Collection) {
 759  0
                                     Collection stringVariables = (Collection<String>)enteredValue;
 760  0
                                     for (Iterator iter = stringVariables.iterator(); iter.hasNext();) {
 761  0
                                         String stringVariable = (String) iter.next();
 762  0
                                         errors.addAll(performValidation(attributeValue, fieldDefName, stringVariable, "One value for " + fieldDefTitle, findXpathExpressionPrefix));
 763  0
                                     }
 764  
 
 765  0
                                 } else {
 766  0
                                     String errorMessage = "Only String or String[] objects should come from entered parameters of an attribute.";
 767  0
                                     LOG.error(errorMessage);
 768  0
                                     throw new RuntimeException(errorMessage);
 769  
                                 }
 770  
                                             }
 771  
                                         } else {
 772  
 //                                            String findValidation = "//searchingConfig/field[@name='" + fieldAttributes.getNamedItem("name").getNodeValue() + "']/validation";
 773  
 //                                            Node validation = (Node) xpath.evaluate(findValidation, getConfigXML(), XPathConstants.NODE);
 774  
 //                                            if (validation != null) {
 775  
 //                                                NamedNodeMap validationAttributes = validation.getAttributes();
 776  
 //                                                Node required = validationAttributes.getNamedItem("required");
 777  
 //                                                if (required != null && "true".equalsIgnoreCase(required.getNodeValue())) {
 778  
 //                                                    errors.add(new WorkflowAttributeValidationError(fieldAttributes.getNamedItem("name").getNodeValue(),fieldAttributes.getNamedItem("title").getNodeValue()+" is required."));
 779  
 //                                                }
 780  
 //                            }
 781  
                                         }
 782  
                     }
 783  
                             }
 784  
             }
 785  0
                 } catch (XPathExpressionException e) {
 786  0
                         LOG.error("error in validateUserSearchInputs ", e);
 787  0
                         throw new RuntimeException("Error trying to find xml content with xpath expression: " + findField, e);
 788  0
                 }
 789  0
                 return errors;
 790  
         }
 791  
 
 792  
     private String constructRangeFieldErrorPrefix(String fieldDefLabel, NamedNodeMap rangeBoundAttributes) {
 793  0
         String potentialLabel = getPotentialRangeBoundLabelFromAttributes(rangeBoundAttributes);
 794  0
         if ( (StringUtils.isNotBlank(potentialLabel)) && (StringUtils.isNotBlank(fieldDefLabel)) ) {
 795  0
             return fieldDefLabel + " " + potentialLabel + " Field";
 796  0
         } else if (StringUtils.isNotBlank(fieldDefLabel)) {
 797  0
             return fieldDefLabel + " Range Field";
 798  0
         } else if (StringUtils.isNotBlank(potentialLabel)) {
 799  0
             return "Range Field " + potentialLabel + " Field";
 800  
         }
 801  0
         return null;
 802  
     }
 803  
 
 804  
         private List<WorkflowAttributeValidationError> performValidation(SearchableAttributeValue attributeValue, String fieldDefName, String enteredValue, String errorMessagePrefix, String findXpathExpressionPrefix) throws XPathExpressionException {
 805  0
                 List<WorkflowAttributeValidationError> errors = new ArrayList<WorkflowAttributeValidationError>();
 806  0
                 XPath xpath = XPathHelper.newXPath();
 807  0
                 if ( attributeValue.allowsWildcards()) {
 808  0
                         enteredValue = enteredValue.replaceAll(SEARCH_WILDCARD_CHARACTER_REGEX_ESCAPED, "");
 809  
                 }
 810  0
                 if (!attributeValue.isPassesDefaultValidation(enteredValue)) {
 811  0
             errorMessagePrefix = (StringUtils.isNotBlank(errorMessagePrefix)) ? errorMessagePrefix : "Field";
 812  0
                         String errorMsg = errorMessagePrefix + " with value '" + enteredValue + "' does not conform to standard validation for field type.";
 813  0
                         LOG.debug("validateUserSearchInputs() " + errorMsg + " :: field type '" + attributeValue.getAttributeDataType() + "'");
 814  0
                         errors.add(new WorkflowAttributeValidationError(fieldDefName, errorMsg));
 815  0
                 } else {
 816  0
                         String findValidation = findXpathExpressionPrefix + "/validation/regex";
 817  0
                         String regex = (String) xpath.evaluate(findValidation, getConfigXML(), XPathConstants.STRING);
 818  0
                         if (!Utilities.isEmpty(regex)) {
 819  0
                                 Pattern pattern = Pattern.compile(regex);
 820  0
                                 Matcher matcher = pattern.matcher(enteredValue);
 821  0
                                 if (!matcher.matches()) {
 822  0
                                         String findErrorMessage = findXpathExpressionPrefix + "/validation/message";
 823  0
                                         String message = (String) xpath.evaluate(findErrorMessage, getConfigXML(), XPathConstants.STRING);
 824  0
                                         errors.add(new WorkflowAttributeValidationError(fieldDefName, message));
 825  
                                 }
 826  
                         }
 827  
                 }
 828  0
                 return errors;
 829  
         }
 830  
 
 831  
         public Element getConfigXML() {
 832  
                 try {
 833  0
                         return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new BufferedReader(new StringReader(ruleAttribute.getXmlConfigData())))).getDocumentElement();
 834  0
                 } catch (Exception e) {
 835  0
                         String ruleAttrStr = (ruleAttribute == null ? null : ruleAttribute.getName());
 836  0
                         LOG.error("error parsing xml data from search attribute: " + ruleAttrStr, e);
 837  0
                         throw new RuntimeException("error parsing xml data from searchable attribute: " + ruleAttrStr, e);
 838  
                 }
 839  
         }
 840  
 }