Coverage Report - org.kuali.rice.krad.uif.field.AttributeQuery
 
Classes in this File Line Coverage Branch Coverage Complexity
AttributeQuery
0%
0/90
0%
0/22
1.367
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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  
 package org.kuali.rice.krad.uif.field;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.krad.uif.core.BindingInfo;
 20  
 import org.kuali.rice.krad.uif.core.MethodInvokerConfig;
 21  
 
 22  
 import java.io.Serializable;
 23  
 import java.util.ArrayList;
 24  
 import java.util.HashMap;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 
 28  
 /**
 29  
  * Holds configuration for executing a dynamic query on an <code>AttributeField</code> to
 30  
  * pull data for updating the UI
 31  
  *
 32  
  * <p>
 33  
  * There are two types of query types that can be configured and executed. The first is provided
 34  
  * completely by the framework using the <code>LookupService</code> and will perform a query
 35  
  * against the configured dataObjectClassName using the query parameters and return field mapping.
 36  
  * The second type will invoke a method that will perform the query. This can be configured using the
 37  
  * queryMethodToCall (if the method is on the view helper service), or using the queryMethodInvoker if
 38  
  * the method is on another class or object.
 39  
  * </p>
 40  
  *
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  */
 43  
 public class AttributeQuery implements Serializable {
 44  
     private static final long serialVersionUID = -4569905665441735255L;
 45  
 
 46  
     private String dataObjectClassName;
 47  
 
 48  
     private boolean renderNotFoundMessage;
 49  
     private String returnMessageText;
 50  
     private String returnMessageStyleClasses;
 51  
 
 52  
     private Map<String, String> queryFieldMapping;
 53  
     private Map<String, String> returnFieldMapping;
 54  
     private Map<String, String> additionalCriteria;
 55  
 
 56  
     private List<String> sortPropertyNames;
 57  
 
 58  
     private String queryMethodToCall;
 59  
     private List<String> queryMethodArgumentFieldList;
 60  
     private MethodInvokerConfig queryMethodInvokerConfig;
 61  
 
 62  0
     public AttributeQuery() {
 63  0
         renderNotFoundMessage = true;
 64  0
         queryFieldMapping = new HashMap<String, String>();
 65  0
         returnFieldMapping = new HashMap<String, String>();
 66  0
         additionalCriteria = new HashMap<String, String>();
 67  0
         sortPropertyNames = new ArrayList<String>();
 68  0
         queryMethodArgumentFieldList = new ArrayList<String>();
 69  0
     }
 70  
 
 71  
     /**
 72  
      * Adjusts the path on the query field mapping from property to match the binding
 73  
      * path prefix of the given <code>BindingInfo</code>
 74  
      *
 75  
      * @param bindingInfo - binding info instance to copy binding path prefix from
 76  
      */
 77  
     public void updateQueryFieldMapping(BindingInfo bindingInfo) {
 78  0
         Map<String, String> adjustedQueryFieldMapping = new HashMap<String, String>();
 79  0
         for (String toField : getQueryFieldMapping().keySet()) {
 80  0
             String fromFieldPath = getQueryFieldMapping().get(toField);
 81  0
             String adjustedFromFieldPath = bindingInfo.getPropertyAdjustedBindingPath(fromFieldPath);
 82  
 
 83  0
             adjustedQueryFieldMapping.put(toField, adjustedFromFieldPath);
 84  0
         }
 85  
 
 86  0
         this.queryFieldMapping = adjustedQueryFieldMapping;
 87  0
     }
 88  
 
 89  
     /**
 90  
      * Adjusts the path on the return field mapping to property to match the binding
 91  
      * path prefix of the given <code>BindingInfo</code>
 92  
      *
 93  
      * @param bindingInfo - binding info instance to copy binding path prefix from
 94  
      */
 95  
     public void updateReturnFieldMapping(BindingInfo bindingInfo) {
 96  0
         Map<String, String> adjustedReturnFieldMapping = new HashMap<String, String>();
 97  0
         for (String toFieldPath : getReturnFieldMapping().keySet()) {
 98  0
             String adjustedToFieldPath = bindingInfo.getPropertyAdjustedBindingPath(toFieldPath);
 99  
 
 100  0
             adjustedReturnFieldMapping.put(adjustedToFieldPath, getReturnFieldMapping().get(toFieldPath));
 101  0
         }
 102  
 
 103  0
         this.returnFieldMapping = adjustedReturnFieldMapping;
 104  0
     }
 105  
 
 106  
     /**
 107  
      * Adjusts the path on the query method arguments field list to match the binding
 108  
      * path prefix of the given <code>BindingInfo</code>
 109  
      *
 110  
      * @param bindingInfo - binding info instance to copy binding path prefix from
 111  
      */
 112  
     public void updateQueryMethodArgumentFieldList(BindingInfo bindingInfo) {
 113  0
         List<String> adjustedArgumentFieldList = new ArrayList<String>();
 114  0
         for (String argumentFieldPath : getQueryMethodArgumentFieldList()) {
 115  0
             String adjustedFieldPath = bindingInfo.getPropertyAdjustedBindingPath(argumentFieldPath);
 116  0
             adjustedArgumentFieldList.add(adjustedFieldPath);
 117  0
         }
 118  
 
 119  0
         this.queryMethodArgumentFieldList = adjustedArgumentFieldList;
 120  0
     }
 121  
 
 122  
     /**
 123  
      * Builds String for passing the queryFieldMapping Map as a Javascript object
 124  
      * parameter
 125  
      *
 126  
      * @return String js parameter string
 127  
      */
 128  
     public String getQueryFieldMappingJsString() {
 129  0
         String queryFieldMappingJs = "{";
 130  
 
 131  0
         for (String queryField : queryFieldMapping.keySet()) {
 132  0
             if (!StringUtils.equals(queryFieldMappingJs, "{")) {
 133  0
                 queryFieldMappingJs += ",";
 134  
             }
 135  
 
 136  0
             queryFieldMappingJs += "\"" + queryField + "\":\"" + queryFieldMapping.get(queryField) + "\"";
 137  
         }
 138  
 
 139  0
         queryFieldMappingJs += "}";
 140  
 
 141  0
         return queryFieldMappingJs;
 142  
     }
 143  
 
 144  
     /**
 145  
      * Builds String for passing the returnFieldMapping Map as a Javascript object
 146  
      * parameter
 147  
      *
 148  
      * @return String js parameter string
 149  
      */
 150  
     public String getReturnFieldMappingJsString() {
 151  0
         String returnFieldMappingJs = "{";
 152  
 
 153  0
         for (String returnField : returnFieldMapping.keySet()) {
 154  0
             if (!StringUtils.equals(returnFieldMappingJs, "{")) {
 155  0
                 returnFieldMappingJs += ",";
 156  
             }
 157  
 
 158  0
             returnFieldMappingJs += "\"" + returnField + "\":\"" + returnFieldMapping.get(returnField) + "\"";
 159  
         }
 160  
 
 161  0
         returnFieldMappingJs += "}";
 162  
 
 163  0
         return returnFieldMappingJs;
 164  
     }
 165  
 
 166  
     /**
 167  
      * Builds String for passing the queryMethodArgumentFieldList as a Javascript array
 168  
      *
 169  
      * @return String js parameter string
 170  
      */
 171  
     public String getQueryMethodArgumentFieldsJsString() {
 172  0
         String queryMethodArgsJs = "[";
 173  
 
 174  0
         for (String methodArg : queryMethodArgumentFieldList) {
 175  0
             if (!StringUtils.equals(queryMethodArgsJs, "{")) {
 176  0
                 queryMethodArgsJs += ",";
 177  
             }
 178  0
             queryMethodArgsJs += "\"" + methodArg + "\"";
 179  
         }
 180  
 
 181  0
         queryMethodArgsJs += "]";
 182  
 
 183  0
         return queryMethodArgsJs;
 184  
     }
 185  
 
 186  
     /**
 187  
      * Indicates whether this attribute query is configured to invoke a custom
 188  
      * method as opposed to running the general object query. If either the query method
 189  
      * to call is given, or the query method invoker is not null it is assumed the
 190  
      * intention is to call a custom method
 191  
      *
 192  
      * @return boolean true if a custom method is configured, false if not
 193  
      */
 194  
     public boolean hasConfiguredMethod() {
 195  0
         boolean configuredMethod = false;
 196  
 
 197  0
         if (StringUtils.isNotBlank(getQueryMethodToCall())) {
 198  0
             configuredMethod = true;
 199  0
         } else if (getQueryMethodInvokerConfig() != null) {
 200  0
             configuredMethod = true;
 201  
         }
 202  
 
 203  0
         return configuredMethod;
 204  
     }
 205  
 
 206  
     /**
 207  
      * Class name for the data object the query should be performed against
 208  
      *
 209  
      * @return String data object class name
 210  
      */
 211  
     public String getDataObjectClassName() {
 212  0
         return dataObjectClassName;
 213  
     }
 214  
 
 215  
     /**
 216  
      * Setter for the query data object class name
 217  
      *
 218  
      * @param dataObjectClassName
 219  
      */
 220  
     public void setDataObjectClassName(String dataObjectClassName) {
 221  0
         this.dataObjectClassName = dataObjectClassName;
 222  0
     }
 223  
 
 224  
     /**
 225  
      * Configures the query parameters by mapping fields in the view
 226  
      * to properties on the data object class for the query
 227  
      *
 228  
      * <p>
 229  
      * Each map entry configures one parameter for the query, where
 230  
      * the map key is the field name to pull the value from, and the
 231  
      * map value is the property name on the object the parameter should
 232  
      * populate.
 233  
      * </p>
 234  
      *
 235  
      * @return Map<String, String> mapping of query parameters
 236  
      */
 237  
     public Map<String, String> getQueryFieldMapping() {
 238  0
         return queryFieldMapping;
 239  
     }
 240  
 
 241  
     /**
 242  
      * Setter for the query parameter mapping
 243  
      *
 244  
      * @param queryFieldMapping
 245  
      */
 246  
     public void setQueryFieldMapping(Map<String, String> queryFieldMapping) {
 247  0
         this.queryFieldMapping = queryFieldMapping;
 248  0
     }
 249  
 
 250  
     /**
 251  
      * Maps properties from the result object of the query to
 252  
      * fields in the view
 253  
      *
 254  
      * <p>
 255  
      * Each map entry configures one return mapping, where the map
 256  
      * key is the field name for the field to populate, and the map
 257  
      * values is the name of the property on the result object to
 258  
      * pull the value from
 259  
      * </p>
 260  
      *
 261  
      * @return Map<String, String> return field mapping
 262  
      */
 263  
     public Map<String, String> getReturnFieldMapping() {
 264  0
         return returnFieldMapping;
 265  
     }
 266  
 
 267  
     /**
 268  
      * Setter for the return field mapping
 269  
      *
 270  
      * @param returnFieldMapping
 271  
      */
 272  
     public void setReturnFieldMapping(Map<String, String> returnFieldMapping) {
 273  0
         this.returnFieldMapping = returnFieldMapping;
 274  0
     }
 275  
 
 276  
     /**
 277  
      * Fixed criteria that will be appended to the dynamic criteria generated
 278  
      * for the query. Map key gives name of the property the criteria should
 279  
      * apply to, and the map value is the value (literal) for the criteria. Standard
 280  
      * lookup wildcards are allowed
 281  
      *
 282  
      * @return Map<String, String> field name/value pairs for query criteria
 283  
      */
 284  
     public Map<String, String> getAdditionalCriteria() {
 285  0
         return additionalCriteria;
 286  
     }
 287  
 
 288  
     /**
 289  
      * Setter for the query's additional criteria map
 290  
      *
 291  
      * @param additionalCriteria
 292  
      */
 293  
     public void setAdditionalCriteria(Map<String, String> additionalCriteria) {
 294  0
         this.additionalCriteria = additionalCriteria;
 295  0
     }
 296  
 
 297  
     /**
 298  
      * List of property names to sort the query results by. The sort
 299  
      * will be performed on each property in the order they are contained
 300  
      * within the list. Each property must be a valid property of the
 301  
      * return query object (the data object in case of the general query)
 302  
      *
 303  
      * @return List<String> property names
 304  
      */
 305  
     public List<String> getSortPropertyNames() {
 306  0
         return sortPropertyNames;
 307  
     }
 308  
 
 309  
     /**
 310  
      * Setter for the list of property names to sort results by
 311  
      *
 312  
      * @param sortPropertyNames
 313  
      */
 314  
     public void setSortPropertyNames(List<String> sortPropertyNames) {
 315  0
         this.sortPropertyNames = sortPropertyNames;
 316  0
     }
 317  
 
 318  
     /**
 319  
      * Indicates whether a message should be added to the query result
 320  
      * object and displayed when the query return object is null
 321  
      *
 322  
      * @return boolean true if not found message should be added, false otherwise
 323  
      */
 324  
     public boolean isRenderNotFoundMessage() {
 325  0
         return renderNotFoundMessage;
 326  
     }
 327  
 
 328  
     /**
 329  
      * Setter for the render not found message indicator
 330  
      *
 331  
      * @param renderNotFoundMessage
 332  
      */
 333  
     public void setRenderNotFoundMessage(boolean renderNotFoundMessage) {
 334  0
         this.renderNotFoundMessage = renderNotFoundMessage;
 335  0
     }
 336  
 
 337  
     /**
 338  
      * Message text to display along with the query result
 339  
      *
 340  
      * @return String literal message text
 341  
      */
 342  
     public String getReturnMessageText() {
 343  0
         return returnMessageText;
 344  
     }
 345  
 
 346  
     /**
 347  
      * Setter for the return message text
 348  
      *
 349  
      * @param returnMessageText
 350  
      */
 351  
     public void setReturnMessageText(String returnMessageText) {
 352  0
         this.returnMessageText = returnMessageText;
 353  0
     }
 354  
 
 355  
     /**
 356  
      * CSS Style classes that should be applied to the return message.
 357  
      * Multiple style classes should be delimited by a space
 358  
      *
 359  
      * @return String style classes
 360  
      */
 361  
     public String getReturnMessageStyleClasses() {
 362  0
         return returnMessageStyleClasses;
 363  
     }
 364  
 
 365  
     /**
 366  
      * Setter for the return messages style classes
 367  
      *
 368  
      * @param returnMessageStyleClasses
 369  
      */
 370  
     public void setReturnMessageStyleClasses(String returnMessageStyleClasses) {
 371  0
         this.returnMessageStyleClasses = returnMessageStyleClasses;
 372  0
     }
 373  
 
 374  
     /**
 375  
      * Configures the name of the method that should be invoked to perform
 376  
      * the query
 377  
      *
 378  
      * <p>
 379  
      * Should contain only the method name (no parameters or return type). If only
 380  
      * the query method name is configured it is assumed to be on the <code>ViewHelperService</code>
 381  
      * for the contained view.
 382  
      * </p>
 383  
      *
 384  
      * @return String query method name
 385  
      */
 386  
     public String getQueryMethodToCall() {
 387  0
         return queryMethodToCall;
 388  
     }
 389  
 
 390  
     /**
 391  
      * Setter for the query method name
 392  
      *
 393  
      * @param queryMethodToCall
 394  
      */
 395  
     public void setQueryMethodToCall(String queryMethodToCall) {
 396  0
         this.queryMethodToCall = queryMethodToCall;
 397  0
     }
 398  
 
 399  
     /**
 400  
      * List of field names that should be passed as arguments to the query method
 401  
      *
 402  
      * <p>
 403  
      * Each entry in the list maps to a method parameter, in the other contained within
 404  
      * the list. The value for the field within the view will be pulled and passed
 405  
      * to the query method as an argument
 406  
      * </p>
 407  
      *
 408  
      * @return List<String> query method argument list
 409  
      */
 410  
     public List<String> getQueryMethodArgumentFieldList() {
 411  0
         return queryMethodArgumentFieldList;
 412  
     }
 413  
 
 414  
     /**
 415  
      * Setter for the query method argument list
 416  
      *
 417  
      * @param queryMethodArgumentFieldList
 418  
      */
 419  
     public void setQueryMethodArgumentFieldList(List<String> queryMethodArgumentFieldList) {
 420  0
         this.queryMethodArgumentFieldList = queryMethodArgumentFieldList;
 421  0
     }
 422  
 
 423  
     /**
 424  
      * Configures the query method target class/object and method name
 425  
      *
 426  
      * <p>
 427  
      * When the query method is not contained on the <code>ViewHelperService</code>, this
 428  
      * can be configured for declaring the target class/object and method. The target class
 429  
      * can be set in which case a new instance will be created and the given method invoked.
 430  
      * Alternatively, the target object instance for the invocation can be given. Or finally
 431  
      * a static method can be configured
 432  
      * </p>
 433  
      *
 434  
      * @return MethodInvokerConfig query method config
 435  
      */
 436  
     public MethodInvokerConfig getQueryMethodInvokerConfig() {
 437  0
         return queryMethodInvokerConfig;
 438  
     }
 439  
 
 440  
     /**
 441  
      * Setter for the query method config
 442  
      *
 443  
      * @param queryMethodInvokerConfig
 444  
      */
 445  
     public void setQueryMethodInvokerConfig(MethodInvokerConfig queryMethodInvokerConfig) {
 446  0
         this.queryMethodInvokerConfig = queryMethodInvokerConfig;
 447  0
     }
 448  
 }