Coverage Report - org.kuali.rice.kns.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.kns.datadictionary;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.core.api.config.property.ConfigurationService;
 21  
 import org.kuali.rice.kns.datadictionary.exception.DuplicateEntryException;
 22  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 23  
 import org.kuali.rice.kns.util.KNSConstants;
 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 = KNSServiceLocator.getKualiConfigurationService();
 159  0
         this.menubar = menubar.replace("${kr.externalizable.images.url}",
 160  
                 kualiConfigurationservice.getPropertyString(KNSConstants.EXTERNALIZABLE_IMAGES_URL_KEY)).replace("${externalizable.images.url}",
 161  
                 kualiConfigurationservice.getPropertyString(KNSConstants.APPLICATION_EXTERNALIZABLE_IMAGES_URL_KEY));
 162  0
         this.menubar = this.menubar.replace("${application.url}", kualiConfigurationservice.getPropertyString(KNSConstants.APPLICATION_URL_KEY));
 163  0
     }
 164  
 
 165  
 
 166  
     /**
 167  
      * @return true if this instance has a default sort defined
 168  
      */
 169  
     public boolean hasDefaultSort() {
 170  0
         return (defaultSort != null);
 171  
     }
 172  
 
 173  
     /**
 174  
      * @return defaultSort
 175  
      */
 176  
     public SortDefinition getDefaultSort() {
 177  0
         return defaultSort;
 178  
     }
 179  
 
 180  
     /**
 181  
      * The defaultSort element specifies the sequence in which the
 182  
      * lookup search results should be displayed.  It contains an
 183  
      * ascending/descending indicator and a list of attribute names.
 184  
      * <p/>
 185  
      * DD: See SortDefinition.java
 186  
      * <p/>
 187  
      * JSTL: defaultSort is a Map with the following keys:
 188  
      * sortAscending (boolean String)
 189  
      * sortAttributes (Map)
 190  
      * <p/>
 191  
      * By the time JSTL export occurs, the optional attributeName from the defaultSort
 192  
      * tag will have been converted into the first contained sortAttribute
 193  
      * <p/>
 194  
      * See LookupMapBuilder.java
 195  
      *
 196  
      * @throws IllegalArgumentException if the given defaultSort is blank
 197  
      */
 198  
     public void setDefaultSort(SortDefinition defaultSort) {
 199  0
         if (defaultSort == null) {
 200  0
             throw new IllegalArgumentException("invalid (null) defaultSort");
 201  
         }
 202  0
         this.defaultSort = defaultSort;
 203  0
     }
 204  
 
 205  
     /**
 206  
      * @return List of attributeNames of all lookupField FieldDefinitions associated with this LookupDefinition, in the order in
 207  
      *         which they were added
 208  
      */
 209  
     public List getLookupFieldNames() {
 210  0
         List fieldNames = new ArrayList();
 211  0
         fieldNames.addAll(this.lookupFieldMap.keySet());
 212  
 
 213  0
         return fieldNames;
 214  
     }
 215  
 
 216  
     /**
 217  
      * @return Collection of all lookupField FieldDefinitions associated with this LookupDefinition, in the order in which they were
 218  
      *         added
 219  
      */
 220  
     public List<FieldDefinition> getLookupFields() {
 221  0
         return lookupFields;
 222  
     }
 223  
 
 224  
     /**
 225  
      * @param fieldName
 226  
      * @return FieldDefinition associated with the named lookup field, or null if there is none
 227  
      */
 228  
     public FieldDefinition getLookupField(String attributeName) {
 229  0
         return lookupFieldMap.get(attributeName);
 230  
     }
 231  
 
 232  
     /**
 233  
      * @return List of attributeNames of all resultField FieldDefinitions associated with this LookupDefinition, in the order in
 234  
      *         which they were added
 235  
      */
 236  
     public List<String> getResultFieldNames() {
 237  0
         List<String> fieldNames = new ArrayList<String>();
 238  0
         fieldNames.addAll(resultFieldMap.keySet());
 239  
 
 240  0
         return fieldNames;
 241  
     }
 242  
 
 243  
     /**
 244  
      * @return Collection of all resultField FieldDefinitions associated with this LookupDefinition, in the order in which they were
 245  
      *         added
 246  
      */
 247  
     public List<FieldDefinition> getResultFields() {
 248  0
         return resultFields;
 249  
     }
 250  
 
 251  
 
 252  
     /**
 253  
      * @param fieldName
 254  
      * @return FieldDefinition associated with the named result field, or null if there is none
 255  
      */
 256  
     public FieldDefinition getResultField(String attributeName) {
 257  0
         return resultFieldMap.get(attributeName);
 258  
     }
 259  
 
 260  
     /**
 261  
      * The resultSetLimit element specifies the maximum number of records that will be listed
 262  
      * as a result of the lookup search.
 263  
      */
 264  
     public void setResultSetLimit(Integer resultSetLimit) {
 265  0
         this.resultSetLimit = resultSetLimit;
 266  0
     }
 267  
 
 268  
     /**
 269  
      * @return true if this instance has a result set limit
 270  
      */
 271  
     public boolean hasResultSetLimit() {
 272  0
         return (resultSetLimit != null);
 273  
     }
 274  
 
 275  
 
 276  
     /**
 277  
      * The resultSetLimit element specifies the maximum number of records that will be listed
 278  
      * as a result of the lookup search.
 279  
      */
 280  
     public Integer getResultSetLimit() {
 281  0
         return resultSetLimit;
 282  
     }
 283  
 
 284  
     /**
 285  
      * Directly validate simple fields, call completeValidation on Definition fields.
 286  
      *
 287  
      * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
 288  
      */
 289  
     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
 290  0
         if (hasDefaultSort()) {
 291  0
             defaultSort.completeValidation(rootBusinessObjectClass, null);
 292  
         }
 293  
 
 294  0
         for (FieldDefinition lookupField : lookupFields) {
 295  0
             lookupField.completeValidation(rootBusinessObjectClass, null);
 296  
         }
 297  
 
 298  0
         for (FieldDefinition resultField : resultFields) {
 299  0
             resultField.completeValidation(rootBusinessObjectClass, null);
 300  
         }
 301  0
     }
 302  
 
 303  
     /**
 304  
      * @return true if this instance has extraButtonSource
 305  
      */
 306  
     public boolean hasExtraButtonSource() {
 307  0
         return extraButtonSource != null;
 308  
     }
 309  
 
 310  
     /**
 311  
      * @return extraButtonSource
 312  
      */
 313  
     public String getExtraButtonSource() {
 314  0
         return extraButtonSource;
 315  
     }
 316  
 
 317  
     /**
 318  
      * The extraButton element is used to define additional buttons which will
 319  
      * appear on the lookup screen next to the Search and Clear buttons.
 320  
      * You can define the image source and additional html parameters for
 321  
      * each button.
 322  
      * <p/>
 323  
      * The extraButtonSource element defines the location of an image file
 324  
      * to use for the extra button.
 325  
      *
 326  
      * @throws IllegalArgumentException if the given source is blank
 327  
      */
 328  
     public void setExtraButtonSource(String extraButtonSource) {
 329  0
         if (StringUtils.isBlank(extraButtonSource)) {
 330  0
             throw new IllegalArgumentException("invalid (blank) button source");
 331  
         }
 332  0
         this.extraButtonSource = extraButtonSource;
 333  0
     }
 334  
 
 335  
     /**
 336  
      * @return true if this instance has extraButtonParams
 337  
      */
 338  
     public boolean hasExtraButtonParams() {
 339  0
         return extraButtonParams != null;
 340  
     }
 341  
 
 342  
     /**
 343  
      * @return extraButtonParams
 344  
      */
 345  
     public String getExtraButtonParams() {
 346  0
         return extraButtonParams;
 347  
     }
 348  
 
 349  
     /**
 350  
      * The extraButton element is used to define additional buttons which will
 351  
      * appear on the lookup screen next to the Search and Clear buttons.
 352  
      * You can define the image source and additional html parameters for
 353  
      * each button.
 354  
      * <p/>
 355  
      * The extraButtonParams contains extra HTML parameters that be associated
 356  
      * with the button.
 357  
      */
 358  
     public void setExtraButtonParams(String extraButtonParams) {
 359  0
         this.extraButtonParams = extraButtonParams;
 360  0
     }
 361  
 
 362  
 
 363  
     /**
 364  
      * @return true if this instance has an alternate icon to use for lookup icon
 365  
      */
 366  
     public boolean hasSearchIconOverride() {
 367  0
         return searchIconOverride != null;
 368  
     }
 369  
 
 370  
     /**
 371  
      * @return search icon override url
 372  
      */
 373  
     public String getSearchIconOverride() {
 374  0
         return searchIconOverride;
 375  
     }
 376  
 
 377  
     /**
 378  
      * The searchIconOverride element is used to define alternative icons
 379  
      * appear on the lookup screen next to the Search and Clear buttons.
 380  
      * You can define the image source.
 381  
      *
 382  
      * @throws IllegalArgumentException if the given source is blank
 383  
      */
 384  
     public void setSearchIconOverride(String searchIconOverride) {
 385  0
         if (StringUtils.isBlank(searchIconOverride)) {
 386  0
             throw new IllegalArgumentException("invalid (blank) search icon override");
 387  
         }
 388  0
         this.searchIconOverride = searchIconOverride;
 389  0
     }
 390  
 
 391  
 
 392  
     public String toString() {
 393  0
         return "LookupDefinition '" + getTitle() + "'";
 394  
     }
 395  
 
 396  
     /**
 397  
      * The lookupFields element defines the set of fields in which the user
 398  
      * can enter values representing search selection criteria.  A search result
 399  
      * record will be returned only if the criteria entered in all the
 400  
      * lookup fields are met.
 401  
      * <p/>
 402  
      * DD:  See LookupDefinition.java
 403  
      * <p/>
 404  
      * JSTL: lookupFields is a Map which is accessed using a key of "lookupFields".
 405  
      * This map contains the following keys:
 406  
      * attributeName of first lookup field
 407  
      * attributeName of second lookup field
 408  
      * etc.
 409  
      * The corresponding values are lookupField Export Maps.
 410  
      * See LookupMapBuilder.java.
 411  
      * <p/>
 412  
      * The lookupField element defines one lookup search
 413  
      * criterion field.
 414  
      * DD: See LookupDefinition.java.
 415  
      * <p/>
 416  
      * JSTL: lookupField is a Map which is accessed by a key
 417  
      * which is the attributeName of a lookup field.  This map contains
 418  
      * entries with the following keys:
 419  
      * "attributeName" (String)
 420  
      * "required" (boolean String)
 421  
      * <p/>
 422  
      * lookupField attribute definitions:
 423  
      * <p/>
 424  
      * required = true means that the user must enter something
 425  
      * into the search criterion lookup field
 426  
      * forceLookup = this attribute is not used
 427  
      * noLookup = true means that field should not include magnifying glass (i.e. quickfinder)
 428  
      */
 429  
     public void setLookupFields(List<FieldDefinition> lookupFields) {
 430  0
         lookupFieldMap.clear();
 431  0
         for (FieldDefinition lookupField : lookupFields) {
 432  0
             if (lookupField == null) {
 433  0
                 throw new IllegalArgumentException("invalid (null) lookupField");
 434  
             }
 435  0
             String keyName = lookupField.getAttributeName();
 436  0
             if (lookupFieldMap.containsKey(keyName)) {
 437  0
                 throw new DuplicateEntryException("duplicate lookupField entry for attribute '" + keyName + "'");
 438  
             }
 439  
 
 440  0
             lookupFieldMap.put(keyName, lookupField);
 441  0
         }
 442  0
         this.lookupFields = lookupFields;
 443  0
     }
 444  
 
 445  
     /**
 446  
      * The resultFields element specifies the list of fields that are shown as a result
 447  
      * of the lookup search.
 448  
      * <p/>
 449  
      * JSTL: resultFields is a Map which is accesseed by a key of "resultFields".
 450  
      * This map contains entries with the following keys:
 451  
      * attributeName of first result field
 452  
      * attributeName of second result field
 453  
      * etc.
 454  
      * The corresponding values are ExportMap's
 455  
      * <p/>
 456  
      * The ExportMaps are accessed using a key of attributeName.
 457  
      * Each ExportMap contains a single entry as follows:
 458  
      * "attributeName"
 459  
      * The corresponding value is the attributeName of the field.
 460  
      * <p/>
 461  
      * See LookupMapBuilder.java.
 462  
      */
 463  
     public void setResultFields(List<FieldDefinition> resultFields) {
 464  0
         resultFieldMap.clear();
 465  0
         for (FieldDefinition resultField : resultFields) {
 466  0
             if (resultField == null) {
 467  0
                 throw new IllegalArgumentException("invalid (null) resultField");
 468  
             }
 469  
 
 470  0
             String keyName = resultField.getAttributeName();
 471  0
             if (resultFieldMap.containsKey(keyName)) {
 472  0
                 throw new DuplicateEntryException("duplicate resultField entry for attribute '" + keyName + "'");
 473  
             }
 474  
 
 475  0
             resultFieldMap.put(keyName, resultField);
 476  0
         }
 477  0
         this.resultFields = resultFields;
 478  0
     }
 479  
 
 480  
     /**
 481  
      * @return the numOfColumns
 482  
      */
 483  
     public int getNumOfColumns() {
 484  0
         return this.numOfColumns;
 485  
     }
 486  
 
 487  
     /**
 488  
      * @param numOfColumns the numOfColumns to set
 489  
      */
 490  
     public void setNumOfColumns(int numOfColumns) {
 491  0
         this.numOfColumns = numOfColumns;
 492  0
     }
 493  
 
 494  
     /**
 495  
      * @return the helpDefinition
 496  
      */
 497  
     public HelpDefinition getHelpDefinition() {
 498  0
         return this.helpDefinition;
 499  
     }
 500  
 
 501  
     /**
 502  
      * @param helpDefinition the helpDefinition to set
 503  
      */
 504  
     public void setHelpDefinition(HelpDefinition helpDefinition) {
 505  0
         this.helpDefinition = helpDefinition;
 506  0
     }
 507  
 
 508  
     /**
 509  
      * @return the helpUrl
 510  
      */
 511  
     public String getHelpUrl() {
 512  0
         return this.helpUrl;
 513  
     }
 514  
 
 515  
     /**
 516  
      * @param helpUrl the helpUrl to set
 517  
      */
 518  
     public void setHelpUrl(String helpUrl) {
 519  0
         this.helpUrl = helpUrl;
 520  0
     }
 521  
 
 522  
     public boolean isTranslateCodes() {
 523  0
         return this.translateCodes;
 524  
     }
 525  
 
 526  
     public void setTranslateCodes(boolean translateCodes) {
 527  0
         this.translateCodes = translateCodes;
 528  0
     }
 529  
 
 530  
     public boolean isDisableSearchButtons() {
 531  0
         return this.disableSearchButtons;
 532  
     }
 533  
 
 534  
     public void setDisableSearchButtons(boolean disableSearchButtons) {
 535  0
         this.disableSearchButtons = disableSearchButtons;
 536  0
     }
 537  
 
 538  
 }