Coverage Report - org.kuali.rice.kns.lookup.KualiLookupableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiLookupableImpl
0%
0/70
0%
0/4
1.068
 
 1  
 /**
 2  
  * Copyright 2005-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  
 package org.kuali.rice.kns.lookup;
 17  
 
 18  
 import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
 19  
 import org.kuali.rice.kns.web.struts.form.LookupForm;
 20  
 import org.kuali.rice.kns.web.ui.Field;
 21  
 import org.kuali.rice.kns.web.ui.ResultRow;
 22  
 import org.kuali.rice.krad.bo.BusinessObject;
 23  
 import org.kuali.rice.krad.service.BusinessObjectDictionaryService;
 24  
 import org.kuali.rice.krad.service.DataDictionaryService;
 25  
 import org.kuali.rice.krad.util.KRADConstants;
 26  
 import org.kuali.rice.krad.util.UrlFactory;
 27  
 import org.springframework.transaction.annotation.Transactional;
 28  
 
 29  
 import java.util.Collection;
 30  
 import java.util.List;
 31  
 import java.util.Map;
 32  
 import java.util.Properties;
 33  
 
 34  
 /**
 35  
  * Kuali lookup implementation. Implements methods necessary to render the lookup and provides search and return methods.
 36  
  */
 37  
 @Transactional
 38  
 public class KualiLookupableImpl implements Lookupable {
 39  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiLookupableImpl.class);
 40  0
     protected static final String[] IGNORE_LIST = { KRADConstants.DOC_FORM_KEY, KRADConstants.BACK_LOCATION };
 41  
 
 42  
     protected Class businessObjectClass;
 43  
     protected LookupableHelperService lookupableHelperService;
 44  0
     protected String extraOnLoad = ""; // This is supposed to be a javascript function.
 45  
 
 46  
     /**
 47  
      * Default constructor initializes services from spring
 48  
      */
 49  0
     public KualiLookupableImpl() {
 50  0
     }
 51  
 
 52  
     /**
 53  
      * Sets the business object class for the lookup instance, then rows can be set for search render.
 54  
      *
 55  
      * @param boClass Class for the lookup business object
 56  
      */
 57  
     public void setBusinessObjectClass(Class boClass) {
 58  0
         if (boClass == null) {
 59  0
             throw new RuntimeException("Business object class is null.");
 60  
         }
 61  
 
 62  0
         this.businessObjectClass = boClass;
 63  
 
 64  
         // next line initializes the helper to return correct values for getRow();
 65  0
         getLookupableHelperService().setBusinessObjectClass(boClass);
 66  0
     }
 67  
 
 68  
     /**
 69  
      * Initializes the lookup with the given Map of parameters.
 70  
      *
 71  
      * @param parameters
 72  
      */
 73  
     public void setParameters(Map parameters) {
 74  0
         getLookupableHelperService().setParameters(parameters);
 75  0
     }
 76  
 
 77  
     /**
 78  
      * @return Returns the parameters passed to this lookup
 79  
      */
 80  
     public Map getParameters() {
 81  0
         return getLookupableHelperService().getParameters();
 82  
     }
 83  
 
 84  
     /**
 85  
      * Constructs the list of columns for the search results. All properties for the column objects come from the DataDictionary.
 86  
      */
 87  
     public List getColumns() {
 88  0
         return getLookupableHelperService().getColumns();
 89  
     }
 90  
 
 91  
     /**
 92  
      * Checks that any required search fields have value.
 93  
      *
 94  
      * @see Lookupable#validateSearchParameters(java.util.Map)
 95  
      */
 96  
     public void validateSearchParameters(Map fieldValues) {
 97  0
         getLookupableHelperService().validateSearchParameters(fieldValues);
 98  0
     }
 99  
 
 100  
     /**
 101  
      * Uses Lookup Service to provide a basic unbounded search.
 102  
      *
 103  
      * @param fieldValues - Map containing prop name keys and search values
 104  
      *
 105  
      * @return List found business objects
 106  
      */
 107  
     public List<BusinessObject> getSearchResultsUnbounded(Map<String, String> fieldValues) {
 108  0
         return getLookupableHelperService().getSearchResultsUnbounded(fieldValues);
 109  
     }
 110  
 
 111  
     /**
 112  
      * Uses Lookup Service to provide a basic search.
 113  
      *
 114  
      * @param fieldValues - Map containing prop name keys and search values
 115  
      *
 116  
      * @return List found business objects
 117  
      */
 118  
     public List<BusinessObject> getSearchResults(Map<String, String> fieldValues) {
 119  0
         return getLookupableHelperService().getSearchResults(fieldValues);
 120  
     }
 121  
 
 122  
     /**
 123  
      * @return the return url for each result row.
 124  
      */
 125  
     public HtmlData getReturnUrl(BusinessObject bo, Map fieldConversions, String lookupImpl, BusinessObjectRestrictions businessObjectRestrictions) {
 126  0
         return getLookupableHelperService().getReturnUrl(bo, fieldConversions, lookupImpl, getReturnKeys(), businessObjectRestrictions);
 127  
     }
 128  
 
 129  
     /**
 130  
      * @see Lookupable#getCreateNewUrl()
 131  
      */
 132  
     public String getCreateNewUrl() {
 133  0
         String url = "";
 134  
 
 135  0
         if (getLookupableHelperService().allowsMaintenanceNewOrCopyAction()) {
 136  0
             Properties parameters = new Properties();
 137  0
             parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
 138  0
             parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, this.businessObjectClass.getName());
 139  
 
 140  0
             url = UrlFactory.parameterizeUrl(KRADConstants.MAINTENANCE_ACTION, parameters);
 141  0
             url = "<a title=\"Create a new record\" href=\"" + url + "\"><img src=\"images/tinybutton-createnew.gif\" alt=\"create new\" width=\"70\" height=\"15\"/></a>";
 142  
         }
 143  
 
 144  0
         return url;
 145  
     }
 146  
 
 147  
 
 148  
     /**
 149  
      * @see Lookupable#getHtmlMenuBar()
 150  
      */
 151  
     public String getHtmlMenuBar() {
 152  0
         return getBusinessObjectDictionaryService().getLookupMenuBar(getBusinessObjectClass());
 153  
     }
 154  
 
 155  
     /**
 156  
      * @see Lookupable#getSupplementalMenuBar()
 157  
      */
 158  
     public String getSupplementalMenuBar() {
 159  0
         return getLookupableHelperService().getSupplementalMenuBar();
 160  
     }
 161  
 
 162  
     /**
 163  
      * @see Lookupable#getRows()
 164  
      */
 165  
     public List getRows() {
 166  0
         return getLookupableHelperService().getRows();
 167  
     }
 168  
 
 169  
     /**
 170  
      * @see Lookupable#getTitle()
 171  
      */
 172  
     public String getTitle() {
 173  0
         return getLookupableHelperService().getTitle();
 174  
     }
 175  
 
 176  
     /**
 177  
      * @see Lookupable#getReturnLocation()
 178  
      */
 179  
     public String getReturnLocation() {
 180  0
         return getLookupableHelperService().getReturnLocation();
 181  
     }
 182  
 
 183  
     /**
 184  
      * @return Returns the dataObjectClass.
 185  
      */
 186  
     public Class getBusinessObjectClass() {
 187  0
         return businessObjectClass;
 188  
     }
 189  
 
 190  
     /**
 191  
      * @return a List of the names of fields which are marked in data dictionary as return fields.
 192  
      */
 193  
     public List getReturnKeys() {
 194  0
         return getLookupableHelperService().getReturnKeys();
 195  
     }
 196  
 
 197  
 
 198  
     /**
 199  
      * @see Lookupable#getExtraButtonSource()
 200  
      */
 201  
     public String getExtraButtonSource() {
 202  0
         return getBusinessObjectDictionaryService().getExtraButtonSource(getBusinessObjectClass());
 203  
     }
 204  
 
 205  
     /**
 206  
      * @see Lookupable#getExtraButtonParams()
 207  
      */
 208  
     public String getExtraButtonParams() {
 209  0
         return getBusinessObjectDictionaryService().getExtraButtonParams(getBusinessObjectClass());
 210  
     }
 211  
 
 212  
     /**
 213  
      * @return property names that will be used to sort on by default
 214  
      */
 215  
     public List getDefaultSortColumns() {
 216  0
         return getLookupableHelperService().getDefaultSortColumns();
 217  
     }
 218  
 
 219  
     /**
 220  
      * @see Lookupable#checkForAdditionalFields(java.util.Map)
 221  
      */
 222  
     public boolean checkForAdditionalFields(Map fieldValues) {
 223  0
         return getLookupableHelperService().checkForAdditionalFields(fieldValues);
 224  
     }
 225  
 
 226  
     /**
 227  
      * @return Returns the backLocation.
 228  
      */
 229  
     public String getBackLocation() {
 230  0
         return getLookupableHelperService().getBackLocation();
 231  
     }
 232  
 
 233  
     /**
 234  
      * @param backLocation The backLocation to set.
 235  
      */
 236  
     public void setBackLocation(String backLocation) {
 237  0
         getLookupableHelperService().setBackLocation(backLocation);
 238  0
     }
 239  
 
 240  
     /**
 241  
      * @return Returns the docFormKey.
 242  
      */
 243  
     public String getDocFormKey() {
 244  0
         return getLookupableHelperService().getDocFormKey();
 245  
     }
 246  
 
 247  
     /**
 248  
      * // this method is public because unit tests depend upon it
 249  
      * @param docFormKey The docFormKey to set.
 250  
      */
 251  
     public void setDocFormKey(String docFormKey) {
 252  0
         getLookupableHelperService().setDocFormKey(docFormKey);
 253  0
     }
 254  
 
 255  
     /**
 256  
      * @return Returns the businessObjectDictionaryService.
 257  
      */
 258  
     protected BusinessObjectDictionaryService getBusinessObjectDictionaryService() {
 259  0
         return getLookupableHelperService().getBusinessObjectDictionaryService();
 260  
     }
 261  
 
 262  
     /**
 263  
      * @see Lookupable#setFieldConversions(java.util.Map)
 264  
      */
 265  
     public void setFieldConversions(Map fieldConversions) {
 266  0
         getLookupableHelperService().setFieldConversions(fieldConversions);
 267  0
     }
 268  
 
 269  
     /**
 270  
      * @return Returns the dataDictionaryService.
 271  
      */
 272  
     protected DataDictionaryService getDataDictionaryService() {
 273  0
         return getLookupableHelperService().getDataDictionaryService();
 274  
     }
 275  
 
 276  
 
 277  
     /**
 278  
      * Sets the readOnlyFieldsList attribute value.
 279  
      *
 280  
      * @param readOnlyFieldsList The readOnlyFieldsList to set.
 281  
      */
 282  
     public void setReadOnlyFieldsList(List<String> readOnlyFieldsList) {
 283  0
         getLookupableHelperService().setReadOnlyFieldsList(readOnlyFieldsList);
 284  0
     }
 285  
 
 286  
 
 287  
     public LookupableHelperService getLookupableHelperService() {
 288  0
         return lookupableHelperService;
 289  
     }
 290  
 
 291  
 
 292  
     /**
 293  
      * Sets the lookupableHelperService attribute value.
 294  
      * @param lookupableHelperService The lookupableHelperService to set.
 295  
      */
 296  
     public void setLookupableHelperService(LookupableHelperService lookupableHelperService) {
 297  0
         this.lookupableHelperService = lookupableHelperService;
 298  0
     }
 299  
 
 300  
     /**
 301  
      * Performs a lookup that can only return one row.
 302  
      * @see Lookupable#performLookup(org.kuali.rice.krad.web.struts.form.LookupForm, java.util.List, boolean)
 303  
      */
 304  
     public Collection performLookup(LookupForm lookupForm, List<ResultRow> resultTable, boolean bounded) {
 305  0
         return getLookupableHelperService().performLookup(lookupForm, resultTable, bounded);
 306  
     }
 307  
 
 308  
 
 309  
     public boolean isSearchUsingOnlyPrimaryKeyValues() {
 310  0
         return getLookupableHelperService().isSearchUsingOnlyPrimaryKeyValues();
 311  
     }
 312  
 
 313  
 
 314  
     public String getPrimaryKeyFieldLabels() {
 315  0
         return getLookupableHelperService().getPrimaryKeyFieldLabels();
 316  
     }
 317  
 
 318  
     /**
 319  
      * calls the lookup helper service to do "clear" behaviors
 320  
      *
 321  
      * @see Lookupable#performClear()
 322  
      */
 323  
     public void performClear(LookupForm lookupForm) {
 324  0
          getLookupableHelperService().performClear(lookupForm);
 325  0
     }
 326  
 
 327  
     /**
 328  
      * calls the lookup helper service to check if non maintenance actions should be displayed
 329  
      *
 330  
      * @see Lookupable#shouldDisplayHeaderNonMaintActions()
 331  
      */
 332  
     public boolean shouldDisplayHeaderNonMaintActions() {
 333  0
         return getLookupableHelperService().shouldDisplayHeaderNonMaintActions();
 334  
     }
 335  
 
 336  
     /**
 337  
      * calls the lookup helper service to check if criteria should be displayed
 338  
      *
 339  
      * @see Lookupable#shouldDisplayLookupCriteria()
 340  
      */
 341  
     public boolean shouldDisplayLookupCriteria() {
 342  0
         return getLookupableHelperService().shouldDisplayLookupCriteria();
 343  
     }
 344  
 
 345  
     protected String getCreateNewUrl(String url){
 346  0
         return "<a title=\"Create a new record\" href=\"" + url + "\"><img src=\"images/tinybutton-createnew.gif\" alt=\"create new\" width=\"70\" height=\"15\"/></a>";
 347  
     }
 348  
 
 349  
     /**
 350  
      * @see Lookupable#performCustomAction(boolean)
 351  
      */
 352  
     public boolean performCustomAction(boolean ignoreErrors) {
 353  0
         return getLookupableHelperService().performCustomAction(ignoreErrors);
 354  
     }
 355  
 
 356  
     /**
 357  
      * This overridden method ...
 358  
      *
 359  
      * @see Lookupable#getExtraField()
 360  
      */
 361  
     public Field getExtraField() {
 362  0
         return getLookupableHelperService().getExtraField();
 363  
     }
 364  
 
 365  
     /**
 366  
      * This overridden method ...
 367  
      *
 368  
      * @see Lookupable#applyFieldAuthorizationsFromNestedLookups(org.kuali.rice.krad.web.ui.Field)
 369  
      */
 370  
     public void applyFieldAuthorizationsFromNestedLookups(Field field) {
 371  0
         getLookupableHelperService().applyFieldAuthorizationsFromNestedLookups(field);
 372  0
     }
 373  
 
 374  
     /**
 375  
      * This overridden method returns the extraOnLoad variable. The
 376  
      * varible is currently accessed in page.tag and is called in the onLoad.
 377  
      * it allows us to inject javascript onload.
 378  
      *
 379  
      * @see Lookupable#getExtraOnLoad()
 380  
      */
 381  
     public String getExtraOnLoad() {
 382  0
         return extraOnLoad;
 383  
     }
 384  
 
 385  
     /**
 386  
      * @param extraOnLoad the extraOnLoad to set
 387  
      */
 388  
     public void setExtraOnLoad(String extraOnLoad) {
 389  0
         this.extraOnLoad = extraOnLoad;
 390  0
     }
 391  
 
 392  
     /**
 393  
      * @see Lookupable#applyConditionalLogicForFieldDisplay()
 394  
      */
 395  
     public void applyConditionalLogicForFieldDisplay() {
 396  0
         getLookupableHelperService().applyConditionalLogicForFieldDisplay();
 397  0
     }
 398  
 
 399  
 }