Coverage Report - org.kuali.rice.krad.datadictionary.LookupDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
LookupDefinition
0%
0/108
0%
0/42
1.581
 
 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.krad.datadictionary;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.core.api.config.property.ConfigurationService;
 21  
 import org.kuali.rice.krad.datadictionary.exception.DuplicateEntryException;
 22  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 23  
 import org.kuali.rice.krad.util.KRADConstants;
 24  
 
 25  
 import java.util.ArrayList;
 26  
 import java.util.LinkedHashMap;
 27  
 import java.util.List;
 28  
 import java.util.Map;
 29  
 
 30  
 /**
 31  
  * Contains lookup-related information relating to the parent BusinessObject.
 32  
  * <p/>
 33  
  * The lookup element is used to specify the rules for "looking up"
 34  
  * a business object.  These specifications define the following:
 35  
  * How to specify the search criteria used to locate a set of business objects
 36  
  * How to display the search results
 37  
  * <p/>
 38  
  * DD: See LookupDefinition.java
 39  
  * <p/>
 40  
  * JSTL: The lookup element is a Map which is accessed using
 41  
  * a key of "lookup".  This map contains the following keys:
 42  
  * lookupableID (String, optional)
 43  
  * title (String)
 44  
  * menubar (String, optional)
 45  
  * defaultSort (Map, optional)
 46  
  * lookupFields (Map)
 47  
  * resultFields (Map)
 48  
  * resultSetLimit (String, optional)
 49  
  * <p/>
 50  
  * See LookupMapBuilder.java
 51  
  * <p/>
 52  
  * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process.
 53  
  */
 54  
 public class LookupDefinition extends DataDictionaryDefinitionBase {
 55  
     private static final long serialVersionUID = 6733008572890721359L;
 56  
 
 57  
     protected String lookupableID;
 58  
     protected String title;
 59  
     protected String menubar;
 60  
     protected SortDefinition defaultSort;
 61  
 
 62  0
     protected List<FieldDefinition> lookupFields = new ArrayList<FieldDefinition>();
 63  0
     protected Map<String, FieldDefinition> lookupFieldMap = new LinkedHashMap<String, FieldDefinition>();
 64  0
     protected List<FieldDefinition> resultFields = new ArrayList<FieldDefinition>();
 65  0
     protected Map<String, FieldDefinition> resultFieldMap = new LinkedHashMap<String, FieldDefinition>();
 66  
 
 67  0
     protected Integer resultSetLimit = null;
 68  
 
 69  
     protected String extraButtonSource;
 70  
     protected String extraButtonParams;
 71  
 
 72  
     protected String searchIconOverride;
 73  
 
 74  
     protected int numOfColumns;
 75  
 
 76  
     protected HelpDefinition helpDefinition;
 77  
     protected String helpUrl;
 78  
 
 79  0
     protected boolean translateCodes = false;
 80  0
     protected boolean disableSearchButtons = false;
 81  
 
 82  0
     public LookupDefinition() {
 83  0
     }
 84  
 
 85  
     /**
 86  
      * The lookupableID element identifies the name of the Spring bean which
 87  
      * will be used to obtain the lookupable helper service for the business object.
 88  
      * For example, the Balance.xml file has a lookupableId = "glBalanceLookupable".
 89  
      * The KualiSpringBeansGL.xml file determines that the helper service will be an
 90  
      * instance of BalanceLookupableHelperServiceImpl.
 91  
      * <p/>
 92  
      * If this field is omitted, the default bean id used will be kualiLookupable which uses
 93  
      * the KualiLookupableHelperServiceImpl helper service.
 94  
      */
 95  
     public void setLookupableID(String lookupableID) {
 96  0
         if (lookupableID == null) {
 97  0
             throw new IllegalArgumentException("invalid (null) lookupableID");
 98  
         }
 99  
 
 100  0
         this.lookupableID = lookupableID;
 101  0
     }
 102  
 
 103  
     /**
 104  
      * @return custom lookupable id
 105  
      */
 106  
     public String getLookupableID() {
 107  0
         return this.lookupableID;
 108  
     }
 109  
 
 110  
     /**
 111  
      * @return title
 112  
      */
 113  
     public String getTitle() {
 114  0
         return title;
 115  
     }
 116  
 
 117  
     /**
 118  
      * Sets title to the given value.
 119  
      *
 120  
      * @param title
 121  
      * @throws IllegalArgumentException if the given title is blank
 122  
      */
 123  
     public void setTitle(String title) {
 124  0
         if (StringUtils.isBlank(title)) {
 125  0
             throw new IllegalArgumentException("invalid (blank) title");
 126  
         }
 127  0
         this.title = title;
 128  0
     }
 129  
 
 130  
     /**
 131  
      * @return true if this instance has a menubar
 132  
      */
 133  
     public boolean hasMenubar() {
 134  0
         return (menubar != null);
 135  
     }
 136  
 
 137  
     /**
 138  
      * @return menubar
 139  
      */
 140  
     public String getMenubar() {
 141  0
         return menubar;
 142  
     }
 143  
 
 144  
     /**
 145  
      * The menubar element is used to add additional html code
 146  
      * to the header line on the lookup screen.
 147  
      * <p/>
 148  
      * For example, Account.xml uses this element to
 149  
      * add the "create new global" button to the Account Lookup header.
 150  
      *
 151  
      * @throws IllegalArgumentException if the given menubar is blank
 152  
      */
 153  
     public void setMenubar(String menubar) {
 154  0
         if (StringUtils.isBlank(menubar)) {
 155  0
             throw new IllegalArgumentException("invalid (blank) menubar");
 156  
         }
 157  
         // TODO: catch exception if service locator call fails
 158  0
         ConfigurationService kualiConfigurationservice = KRADServiceLocator.getKualiConfigurationService();
 159  0
         this.menubar = menubar.replace("${kr.externalizable.images.url}",
 160  
                 kualiConfigurationservice.getPropertyString(KRADConstants.EXTERNALIZABLE_IMAGES_URL_KEY)).replace("${externalizable.images.url}",
 161  
                 kualiConfigurationservice.getPropertyString(KRADConstants.APPLICATION_EXTERNALIZABLE_IMAGES_URL_KEY));
 162  0
         this.menubar = this.menubar.replace("${application.url}", kualiConfigurationservice.getPropertyString(
 163  
                 KRADConstants.APPLICATION_URL_KEY));
 164  0
     }
 165  
 
 166  
 
 167  
     /**
 168  
      * @return true if this instance has a default sort defined
 169  
      */
 170  
     public boolean hasDefaultSort() {
 171  0
         return (defaultSort != null);
 172  
     }
 173  
 
 174  
     /**
 175  
      * @return defaultSort
 176  
      */
 177  
     public SortDefinition getDefaultSort() {
 178  0
         return defaultSort;
 179  
     }
 180  
 
 181  
     /**
 182  
      * The defaultSort element specifies the sequence in which the
 183  
      * lookup search results should be displayed.  It contains an
 184  
      * ascending/descending indicator and a list of attribute names.
 185  
      * <p/>
 186  
      * DD: See SortDefinition.java
 187  
      * <p/>
 188  
      * JSTL: defaultSort is a Map with the following keys:
 189  
      * sortAscending (boolean String)
 190  
      * sortAttributes (Map)
 191  
      * <p/>
 192  
      * By the time JSTL export occurs, the optional attributeName from the defaultSort
 193  
      * tag will have been converted into the first contained sortAttribute
 194  
      * <p/>
 195  
      * See LookupMapBuilder.java
 196  
      *
 197  
      * @throws IllegalArgumentException if the given defaultSort is blank
 198  
      */
 199  
     public void setDefaultSort(SortDefinition defaultSort) {
 200  0
         if (defaultSort == null) {
 201  0
             throw new IllegalArgumentException("invalid (null) defaultSort");
 202  
         }
 203  0
         this.defaultSort = defaultSort;
 204  0
     }
 205  
 
 206  
     /**
 207  
      * @return List of attributeNames of all lookupField FieldDefinitions associated with this LookupDefinition, in the order in
 208  
      *         which they were added
 209  
      */
 210  
     public List getLookupFieldNames() {
 211  0
         List fieldNames = new ArrayList();
 212  0
         fieldNames.addAll(this.lookupFieldMap.keySet());
 213  
 
 214  0
         return fieldNames;
 215  
     }
 216  
 
 217  
     /**
 218  
      * @return Collection of all lookupField FieldDefinitions associated with this LookupDefinition, in the order in which they were
 219  
      *         added
 220  
      */
 221  
     public List<FieldDefinition> getLookupFields() {
 222  0
         return lookupFields;
 223  
     }
 224  
 
 225  
     /**
 226  
      * @param fieldName
 227  
      * @return FieldDefinition associated with the named lookup field, or null if there is none
 228  
      */
 229  
     public FieldDefinition getLookupField(String attributeName) {
 230  0
         return lookupFieldMap.get(attributeName);
 231  
     }
 232  
 
 233  
     /**
 234  
      * @return List of attributeNames of all resultField FieldDefinitions associated with this LookupDefinition, in the order in
 235  
      *         which they were added
 236  
      */
 237  
     public List<String> getResultFieldNames() {
 238  0
         List<String> fieldNames = new ArrayList<String>();
 239  0
         fieldNames.addAll(resultFieldMap.keySet());
 240  
 
 241  0
         return fieldNames;
 242  
     }
 243  
 
 244  
     /**
 245  
      * @return Collection of all resultField FieldDefinitions associated with this LookupDefinition, in the order in which they were
 246  
      *         added
 247  
      */
 248  
     public List<FieldDefinition> getResultFields() {
 249  0
         return resultFields;
 250  
     }
 251  
 
 252  
 
 253  
     /**
 254  
      * @param fieldName
 255  
      * @return FieldDefinition associated with the named result field, or null if there is none
 256  
      */
 257  
     public FieldDefinition getResultField(String attributeName) {
 258  0
         return resultFieldMap.get(attributeName);
 259  
     }
 260  
 
 261  
     /**
 262  
      * The resultSetLimit element specifies the maximum number of records that will be listed
 263  
      * as a result of the lookup search.
 264  
      */
 265  
     public void setResultSetLimit(Integer resultSetLimit) {
 266  0
         this.resultSetLimit = resultSetLimit;
 267  0
     }
 268  
 
 269  
     /**
 270  
      * @return true if this instance has a result set limit
 271  
      */
 272  
     public boolean hasResultSetLimit() {
 273  0
         return (resultSetLimit != null);
 274  
     }
 275  
 
 276  
 
 277  
     /**
 278  
      * The resultSetLimit element specifies the maximum number of records that will be listed
 279  
      * as a result of the lookup search.
 280  
      */
 281  
     public Integer getResultSetLimit() {
 282  0
         return resultSetLimit;
 283  
     }
 284  
 
 285  
     /**
 286  
      * Directly validate simple fields, call completeValidation on Definition fields.
 287  
      *
 288  
      * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
 289  
      */
 290  
     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
 291  0
         if (hasDefaultSort()) {
 292  0
             defaultSort.completeValidation(rootBusinessObjectClass, null);
 293  
         }
 294  
 
 295  0
         for (FieldDefinition lookupField : lookupFields) {
 296  0
             lookupField.completeValidation(rootBusinessObjectClass, null);
 297  
         }
 298  
 
 299  0
         for (FieldDefinition resultField : resultFields) {
 300  0
             resultField.completeValidation(rootBusinessObjectClass, null);
 301  
         }
 302  0
     }
 303  
 
 304  
     /**
 305  
      * @return true if this instance has extraButtonSource
 306  
      */
 307  
     public boolean hasExtraButtonSource() {
 308  0
         return extraButtonSource != null;
 309  
     }
 310  
 
 311  
     /**
 312  
      * @return extraButtonSource
 313  
      */
 314  
     public String getExtraButtonSource() {
 315  0
         return extraButtonSource;
 316  
     }
 317  
 
 318  
     /**
 319  
      * The extraButton element is used to define additional buttons which will
 320  
      * appear on the lookup screen next to the Search and Clear buttons.
 321  
      * You can define the image source and additional html parameters for
 322  
      * each button.
 323  
      * <p/>
 324  
      * The extraButtonSource element defines the location of an image file
 325  
      * to use for the extra button.
 326  
      *
 327  
      * @throws IllegalArgumentException if the given source is blank
 328  
      */
 329  
     public void setExtraButtonSource(String extraButtonSource) {
 330  0
         if (StringUtils.isBlank(extraButtonSource)) {
 331  0
             throw new IllegalArgumentException("invalid (blank) button source");
 332  
         }
 333  0
         this.extraButtonSource = extraButtonSource;
 334  0
     }
 335  
 
 336  
     /**
 337  
      * @return true if this instance has extraButtonParams
 338  
      */
 339  
     public boolean hasExtraButtonParams() {
 340  0
         return extraButtonParams != null;
 341  
     }
 342  
 
 343  
     /**
 344  
      * @return extraButtonParams
 345  
      */
 346  
     public String getExtraButtonParams() {
 347  0
         return extraButtonParams;
 348  
     }
 349  
 
 350  
     /**
 351  
      * The extraButton element is used to define additional buttons which will
 352  
      * appear on the lookup screen next to the Search and Clear buttons.
 353  
      * You can define the image source and additional html parameters for
 354  
      * each button.
 355  
      * <p/>
 356  
      * The extraButtonParams contains extra HTML parameters that be associated
 357  
      * with the button.
 358  
      */
 359  
     public void setExtraButtonParams(String extraButtonParams) {
 360  0
         this.extraButtonParams = extraButtonParams;
 361  0
     }
 362  
 
 363  
 
 364  
     /**
 365  
      * @return true if this instance has an alternate icon to use for lookup icon
 366  
      */
 367  
     public boolean hasSearchIconOverride() {
 368  0
         return searchIconOverride != null;
 369  
     }
 370  
 
 371  
     /**
 372  
      * @return search icon override url
 373  
      */
 374  
     public String getSearchIconOverride() {
 375  0
         return searchIconOverride;
 376  
     }
 377  
 
 378  
     /**
 379  
      * The searchIconOverride element is used to define alternative icons
 380  
      * appear on the lookup screen next to the Search and Clear buttons.
 381  
      * You can define the image source.
 382  
      *
 383  
      * @throws IllegalArgumentException if the given source is blank
 384  
      */
 385  
     public void setSearchIconOverride(String searchIconOverride) {
 386  0
         if (StringUtils.isBlank(searchIconOverride)) {
 387  0
             throw new IllegalArgumentException("invalid (blank) search icon override");
 388  
         }
 389  0
         this.searchIconOverride = searchIconOverride;
 390  0
     }
 391  
 
 392  
 
 393  
     public String toString() {
 394  0
         return "LookupDefinition '" + getTitle() + "'";
 395  
     }
 396  
 
 397  
     /**
 398  
      * The lookupFields element defines the set of fields in which the user
 399  
      * can enter values representing search selection criteria.  A search result
 400  
      * record will be returned only if the criteria entered in all the
 401  
      * lookup fields are met.
 402  
      * <p/>
 403  
      * DD:  See LookupDefinition.java
 404  
      * <p/>
 405  
      * JSTL: lookupFields is a Map which is accessed using a key of "lookupFields".
 406  
      * This map contains the following keys:
 407  
      * attributeName of first lookup field
 408  
      * attributeName of second lookup field
 409  
      * etc.
 410  
      * The corresponding values are lookupField Export Maps.
 411  
      * See LookupMapBuilder.java.
 412  
      * <p/>
 413  
      * The lookupField element defines one lookup search
 414  
      * criterion field.
 415  
      * DD: See LookupDefinition.java.
 416  
      * <p/>
 417  
      * JSTL: lookupField is a Map which is accessed by a key
 418  
      * which is the attributeName of a lookup field.  This map contains
 419  
      * entries with the following keys:
 420  
      * "attributeName" (String)
 421  
      * "required" (boolean String)
 422  
      * <p/>
 423  
      * lookupField attribute definitions:
 424  
      * <p/>
 425  
      * required = true means that the user must enter something
 426  
      * into the search criterion lookup field
 427  
      * forceLookup = this attribute is not used
 428  
      * noLookup = true means that field should not include magnifying glass (i.e. quickfinder)
 429  
      */
 430  
     public void setLookupFields(List<FieldDefinition> lookupFields) {
 431  0
         lookupFieldMap.clear();
 432  0
         for (FieldDefinition lookupField : lookupFields) {
 433  0
             if (lookupField == null) {
 434  0
                 throw new IllegalArgumentException("invalid (null) lookupField");
 435  
             }
 436  0
             String keyName = lookupField.getAttributeName();
 437  0
             if (lookupFieldMap.containsKey(keyName)) {
 438  0
                 throw new DuplicateEntryException("duplicate lookupField entry for attribute '" + keyName + "'");
 439  
             }
 440  
 
 441  0
             lookupFieldMap.put(keyName, lookupField);
 442  0
         }
 443  0
         this.lookupFields = lookupFields;
 444  0
     }
 445  
 
 446  
     /**
 447  
      * The resultFields element specifies the list of fields that are shown as a result
 448  
      * of the lookup search.
 449  
      * <p/>
 450  
      * JSTL: resultFields is a Map which is accesseed by a key of "resultFields".
 451  
      * This map contains entries with the following keys:
 452  
      * attributeName of first result field
 453  
      * attributeName of second result field
 454  
      * etc.
 455  
      * The corresponding values are ExportMap's
 456  
      * <p/>
 457  
      * The ExportMaps are accessed using a key of attributeName.
 458  
      * Each ExportMap contains a single entry as follows:
 459  
      * "attributeName"
 460  
      * The corresponding value is the attributeName of the field.
 461  
      * <p/>
 462  
      * See LookupMapBuilder.java.
 463  
      */
 464  
     public void setResultFields(List<FieldDefinition> resultFields) {
 465  0
         resultFieldMap.clear();
 466  0
         for (FieldDefinition resultField : resultFields) {
 467  0
             if (resultField == null) {
 468  0
                 throw new IllegalArgumentException("invalid (null) resultField");
 469  
             }
 470  
 
 471  0
             String keyName = resultField.getAttributeName();
 472  0
             if (resultFieldMap.containsKey(keyName)) {
 473  0
                 throw new DuplicateEntryException("duplicate resultField entry for attribute '" + keyName + "'");
 474  
             }
 475  
 
 476  0
             resultFieldMap.put(keyName, resultField);
 477  0
         }
 478  0
         this.resultFields = resultFields;
 479  0
     }
 480  
 
 481  
     /**
 482  
      * @return the numOfColumns
 483  
      */
 484  
     public int getNumOfColumns() {
 485  0
         return this.numOfColumns;
 486  
     }
 487  
 
 488  
     /**
 489  
      * @param numOfColumns the numOfColumns to set
 490  
      */
 491  
     public void setNumOfColumns(int numOfColumns) {
 492  0
         this.numOfColumns = numOfColumns;
 493  0
     }
 494  
 
 495  
     /**
 496  
      * @return the helpDefinition
 497  
      */
 498  
     public HelpDefinition getHelpDefinition() {
 499  0
         return this.helpDefinition;
 500  
     }
 501  
 
 502  
     /**
 503  
      * @param helpDefinition the helpDefinition to set
 504  
      */
 505  
     public void setHelpDefinition(HelpDefinition helpDefinition) {
 506  0
         this.helpDefinition = helpDefinition;
 507  0
     }
 508  
 
 509  
     /**
 510  
      * @return the helpUrl
 511  
      */
 512  
     public String getHelpUrl() {
 513  0
         return this.helpUrl;
 514  
     }
 515  
 
 516  
     /**
 517  
      * @param helpUrl the helpUrl to set
 518  
      */
 519  
     public void setHelpUrl(String helpUrl) {
 520  0
         this.helpUrl = helpUrl;
 521  0
     }
 522  
 
 523  
     public boolean isTranslateCodes() {
 524  0
         return this.translateCodes;
 525  
     }
 526  
 
 527  
     public void setTranslateCodes(boolean translateCodes) {
 528  0
         this.translateCodes = translateCodes;
 529  0
     }
 530  
 
 531  
     public boolean isDisableSearchButtons() {
 532  0
         return this.disableSearchButtons;
 533  
     }
 534  
 
 535  
     public void setDisableSearchButtons(boolean disableSearchButtons) {
 536  0
         this.disableSearchButtons = disableSearchButtons;
 537  0
     }
 538  
 
 539  
 }